Skip to content

Removed -Wconversion warnings in part of framework #47339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DataFormats/Common/interface/Association.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace edm {
size_t k = i;
if (k >= ref_->size())
throwIndexMapBound();
return reference_type(ref_, k);
return reference_type(ref_, static_cast<typename reference_type::key_type>(k));
}

reference_type get(ProductID id, size_t idx) const { return get(rawIndexOf(id, idx)); }
Expand Down
23 changes: 11 additions & 12 deletions DataFormats/Common/interface/AssociationMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,31 +175,31 @@ namespace edm {
const_iterator find(const key_type& k) const {
if (ref_.key.id() != k.id())
return end();
return find(k.key());
return find(static_cast<index_type>(k.key()));
}
/// erase the element whose key is k
size_type erase(const key_type& k) {
index_type i = k.key();
index_type i = static_cast<index_type>(k.key());
transientMap_.unsafe_erase(i);
return map_.erase(i);
}
/// find element with specified reference key
const result_type& operator[](const key_type& k) const {
helpers::checkRef(ref_.key, k);
return get(k.key()).val;
return get(static_cast<index_type>(k.key())).val;
}

template <typename K>
const result_type& operator[](const K& k) const {
helpers::checkRef(ref_.key, k);
return get(k.key()).val;
return get(static_cast<index_type>(k.key())).val;
}

/// number of associations to a key
size_type numberOfAssociations(const key_type& k) const {
if (ref_.key.id() != k.id())
return 0;
typename map_type::const_iterator f = map_.find(k.key());
auto f = map_.find(static_cast<index_type>(k.key()));
if (f == map_.end())
return 0;
return Tag::size(f->second);
Expand Down Expand Up @@ -252,22 +252,21 @@ namespace edm {
/// transient reference map
mutable internal_transient_map_type transientMap_;
/// find element with index i
const_iterator find(size_type i) const {
typename map_type::const_iterator f = map_.find(i);
const_iterator find(index_type i) const {
auto f = map_.find(i);
if (f == map_.end())
return end();
return const_iterator(this, f);
}
/// return value_typeelement with key i
const value_type& get(size_type i) const {
typename internal_transient_map_type::const_iterator tf = transientMap_.find(i);
const value_type& get(index_type i) const {
auto tf = transientMap_.find(i);
if (tf == transientMap_.end()) {
typename map_type::const_iterator f = map_.find(i);
auto f = map_.find(i);
if (f == map_.end())
Exception::throwThis(edm::errors::InvalidReference, "can't find reference in AssociationMap at position ", i);
value_type v(key_type(ref_.key, i), Tag::val(ref_, f->second));
std::pair<typename internal_transient_map_type::const_iterator, bool> ins =
transientMap_.insert(std::make_pair(i, v));
auto ins = transientMap_.insert(std::make_pair(i, v));
return ins.first->second;
} else {
return tf->second;
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/Common/interface/AssociationVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace edm {
template <typename KeyRefProd, typename CVal, typename KeyRef, typename SizeType, typename KeyReferenceHelper>
inline typename AssociationVector<KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper>::size_type
AssociationVector<KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper>::size() const {
return data_.size();
return static_cast<size_type>(data_.size());
}

template <typename KeyRefProd, typename CVal, typename KeyRef, typename SizeType, typename KeyReferenceHelper>
Expand Down
2 changes: 1 addition & 1 deletion DataFormats/Common/interface/ContainerMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace edm {

template <typename T>
bool ContainerMask<T>::mask(const typename ContainerMaskTraits<T>::value_type* iElement) {
unsigned int index = ContainerMaskTraits<T>::indexFor(iElement, m_prod.product());
auto index = ContainerMaskTraits<T>::indexFor(iElement, m_prod.product());
return this->mask(index);
}

Expand Down
2 changes: 1 addition & 1 deletion DataFormats/Common/interface/ContainerMaskTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace edm {

static size_t size(const T* iContainer) { return iContainer->size(); }
static unsigned int indexFor(const value_type* iElement, const T* iContainer) {
return iElement - &(iContainer->front());
return static_cast<unsigned int>(iElement - &(iContainer->front()));
}

ContainerMaskTraits() = delete;
Expand Down
11 changes: 6 additions & 5 deletions DataFormats/Common/interface/DataFrameContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace edm {
DataFrameContainer() : m_subdetId(0), m_stride(0), m_ids(), m_data() {}

explicit DataFrameContainer(size_t istride, int isubdet = 0, size_t isize = 0)
: m_subdetId(isubdet), m_stride(istride), m_ids(isize), m_data(isize * m_stride) {}
: m_subdetId(isubdet), m_stride(static_cast<size_type>(istride)), m_ids(isize), m_data(isize * m_stride) {}

void swap(DataFrameContainer& rh) {
std::swap(m_subdetId, rh.m_subdetId);
Expand Down Expand Up @@ -126,17 +126,18 @@ namespace edm {

const_IterPair pair(size_t i) const { return const_IterPair(m_ids.begin() + i, m_data.begin() + i * m_stride); }

DataFrame operator[](size_t i) { return DataFrame(*this, i); }
DataFrame operator[](size_t i) { return DataFrame(*this, static_cast<DataFrame::size_type>(i)); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In these cases, wouldn't it be better to change the function parameter type to match what is expected ?
That is,

Suggested change
DataFrame operator[](size_t i) { return DataFrame(*this, static_cast<DataFrame::size_type>(i)); }
DataFrame operator[](DataFrame::size_type i) { return DataFrame(*this, i); }

?


DataFrame operator[](size_t i) const { return DataFrame(*this, i); }
DataFrame operator[](size_t i) const { return DataFrame(*this, static_cast<DataFrame::size_type>(i)); }

/// slow interface
/// The iterator returned can not safely be used across threads
const_iterator find(id_type i) const {
const_IdIter p = std::lower_bound(m_ids.begin(), m_ids.end(), i);
return (p == m_ids.end() || (*p) != i)
? end()
: boost::make_transform_iterator(boost::counting_iterator<int>(p - m_ids.begin()), IterHelp(*this));
: boost::make_transform_iterator(boost::counting_iterator<int>(static_cast<int>(p - m_ids.begin())),
IterHelp(*this));
}

/// The iterator returned can not safely be used across threads
Expand All @@ -153,7 +154,7 @@ namespace edm {

bool empty() const { return m_ids.empty(); }

size_type size() const { return m_ids.size(); }
size_type size() const { return static_cast<size_type>(m_ids.size()); }

data_type operator()(size_t cell, size_t frame) const { return m_data[cell * m_stride + frame]; }

Expand Down
22 changes: 11 additions & 11 deletions DataFormats/Common/interface/DetSetVectorNew.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace edmNew {
void resize(size_type s) {
checkCapacityExausted(s);
m_v.m_data.resize(m_item.offset + s);
m_v.m_dataSize = m_v.m_data.size();
m_v.m_dataSize = static_cast<unsigned int>(m_v.m_data.size());
m_item.size = s;
}

Expand Down Expand Up @@ -329,16 +329,16 @@ namespace edmNew {
expected = false;
nanosleep(nullptr, nullptr);
}
int offset = m_v.m_data.size();
int offset = static_cast<int>(m_v.m_data.size());
if (m_v.onDemand() && full()) {
m_v.m_filling = false;
dstvdetails::throwCapacityExausted();
}
std::move(m_lv.begin(), m_lv.end(), std::back_inserter(m_v.m_data));
m_item.size = m_lv.size();
m_item.size = static_cast<size_type>(m_lv.size());
m_item.offset = offset;

m_v.m_dataSize = m_v.m_data.size();
m_v.m_dataSize = static_cast<unsigned int>(m_v.m_data.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_v.m_dataSize = static_cast<unsigned int>(m_v.m_data.size());
m_v.m_dataSize = static_cast<size_type>(m_v.m_data.size());

?

assert(m_v.m_filling == true);
m_v.m_filling = false;
}
Expand All @@ -355,7 +355,7 @@ namespace edmNew {
void resize(size_type s) { m_lv.resize(s); }

id_type id() const { return m_item.id; }
size_type size() const { return m_lv.size(); }
size_type size() const { return static_cast<size_type>(m_lv.size()); }
bool empty() const { return m_lv.empty(); }

data_type& operator[](size_type i) { return m_lv[i]; }
Expand Down Expand Up @@ -451,7 +451,7 @@ namespace edmNew {
void resize(size_t isize, size_t dsize) {
m_ids.resize(isize);
m_data.resize(dsize);
m_dataSize = m_data.size();
m_dataSize = static_cast<unsigned int>(m_data.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_dataSize = static_cast<unsigned int>(m_data.size());
m_dataSize = static_cast<size_type>(m_data.size());

?

}

void clean() {
Expand All @@ -463,14 +463,14 @@ namespace edmNew {
Item& item = addItem(iid, isize);
m_data.resize(m_data.size() + isize);
std::copy(idata, idata + isize, m_data.begin() + item.offset);
m_dataSize = m_data.size();
m_dataSize = static_cast<unsigned int>(m_data.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_dataSize = static_cast<unsigned int>(m_data.size());
m_dataSize = static_cast<size_type>(m_data.size());

?

return DetSet(*this, item, false);
}
//make space for it
DetSet insert(id_type iid, size_type isize) {
Item& item = addItem(iid, isize);
m_data.resize(m_data.size() + isize);
m_dataSize = m_data.size();
m_dataSize = static_cast<unsigned int>(m_data.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_dataSize = static_cast<unsigned int>(m_data.size());
m_dataSize = static_cast<size_type>(m_data.size());

?

return DetSet(*this, item, false);
}

Expand All @@ -485,7 +485,7 @@ namespace edmNew {
// sanity checks... (shall we throw or assert?)
if ((*p).isValid() && (*p).size > 0 && m_data.size() == (*p).offset + (*p).size) {
m_data.resize((*p).offset);
m_dataSize = m_data.size();
m_dataSize = static_cast<size_type>(m_data.size());
}
m_ids.erase(m_ids.begin() + (p - m_ids.begin()));
}
Expand Down Expand Up @@ -562,7 +562,7 @@ namespace edmNew {

size_type dataSize() const { return onDemand() ? size_type(m_dataSize) : size_type(m_data.size()); }

size_type size() const { return m_ids.size(); }
size_type size() const { return static_cast<size_type>(m_ids.size()); }

//FIXME fast interfaces, not consistent with associative nature of container....

Expand Down Expand Up @@ -718,7 +718,7 @@ namespace edm {

static size_t size(const edmNew::DetSetVector<T>* iContainer) { return iContainer->dataSize(); }
static unsigned int indexFor(const value_type* iElement, const edmNew::DetSetVector<T>* iContainer) {
return iElement - &(iContainer->data().front());
return static_cast<unsigned int>(iElement - &(iContainer->data().front()));
}
};
} // namespace edm
Expand Down
34 changes: 18 additions & 16 deletions DataFormats/Common/interface/HLTGlobalStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ namespace edm {
std::vector<HLTPathStatus> paths_;

public:
using size_type = decltype(paths_)::size_type;

/// Constructor - for n paths
HLTGlobalStatus(const unsigned int n = 0) : paths_(n) {}
HLTGlobalStatus(size_type n = 0) : paths_(n) {}

/// Get number of paths stored
unsigned int size() const { return paths_.size(); }
auto size() const { return paths_.size(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto size() const { return paths_.size(); }
size_type size() const { return paths_.size(); }

?


/// Reset status for all paths
void reset() {
const unsigned int n(size());
for (unsigned int i = 0; i != n; ++i)
const auto n(size());
for (decltype(size()) i = 0; i != n; ++i)
Comment on lines +43 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const auto n(size());
for (decltype(size()) i = 0; i != n; ++i)
const size_type n = size();
for (size_type i = 0; i != n; ++i)

?

paths_[i].reset();
}

Expand All @@ -54,32 +56,32 @@ namespace edm {

// accessors to ith element of paths_

const HLTPathStatus& at(const unsigned int i) const { return paths_.at(i); }
HLTPathStatus& at(const unsigned int i) { return paths_.at(i); }
const HLTPathStatus& operator[](const unsigned int i) const { return paths_[i]; }
HLTPathStatus& operator[](const unsigned int i) { return paths_[i]; }
const HLTPathStatus& at(size_type i) const { return paths_.at(i); }
HLTPathStatus& at(size_type i) { return paths_.at(i); }
const HLTPathStatus& operator[](size_type i) const { return paths_[i]; }
HLTPathStatus& operator[](size_type i) { return paths_[i]; }

/// Was ith path run?
bool wasrun(const unsigned int i) const { return at(i).wasrun(); }
bool wasrun(size_type i) const { return at(i).wasrun(); }
/// Has ith path accepted the event?
bool accept(const unsigned int i) const { return at(i).accept(); }
bool accept(size_type i) const { return at(i).accept(); }
/// Has ith path encountered an error (exception)?
bool error(const unsigned int i) const { return at(i).error(); }
bool error(size_type i) const { return at(i).error(); }

/// Get status of ith path
hlt::HLTState state(const unsigned int i) const { return at(i).state(); }
hlt::HLTState state(size_type i) const { return at(i).state(); }
/// Get index (slot position) of module giving the decision of the ith path
unsigned int index(const unsigned int i) const { return at(i).index(); }
unsigned int index(size_type i) const { return at(i).index(); }
/// Reset the ith path
void reset(const unsigned int i) { at(i).reset(); }
void reset(size_type i) { at(i).reset(); }
/// swap function
void swap(HLTGlobalStatus& other) { paths_.swap(other.paths_); }

private:
/// Global state variable calculated on the fly
bool State(unsigned int icase) const {
bool flags[3] = {false, false, false};
const unsigned int n(size());
const auto n(size());
for (unsigned int i = 0; i != n; ++i) {
const hlt::HLTState s(state(i));
if (s != hlt::Ready) {
Expand All @@ -105,7 +107,7 @@ namespace edm {
text[1] = "1";
text[2] = "0";
text[3] = "e";
const unsigned int n(hlt.size());
const auto n(hlt.size());
for (unsigned int i = 0; i != n; ++i)
ost << text[hlt.state(i)];
return ost;
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/Common/interface/HLTPathStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace edm {

public:
/// constructor
HLTPathStatus(const hlt::HLTState state = hlt::Ready, const unsigned int index = 0) : status_(index * 4 + state) {
HLTPathStatus(const hlt::HLTState state = hlt::Ready, const unsigned int index = 0)
: status_(static_cast<uint16_t>(index * 4 + state)) {
assert(((int)state) < 4);
assert(index < 16384);
}
Expand Down
8 changes: 4 additions & 4 deletions DataFormats/Common/interface/MapOfVectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace edm {
m_keys.reserve(it.size());
m_offsets.reserve(it.size() + 1);
m_offsets.push_back(0);
size_type tot = 0;
size_t tot = 0;
for (typename TheMap::const_iterator p = it.begin(); p != it.end(); ++p)
tot += (*p).second.size();
m_data.reserve(tot);
Expand All @@ -88,10 +88,10 @@ namespace edm {
m_keys.push_back(k);
m_data.resize(m_offsets.back() + v.size());
std::copy(v.begin(), v.end(), m_data.begin() + m_offsets.back());
m_offsets.push_back(m_data.size());
m_offsets.push_back(static_cast<unsigned int>(m_data.size()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_offsets.push_back(static_cast<unsigned int>(m_data.size()));
m_offsets.push_back(static_cast<size_type>(m_data.size()));

?

}

size_type size() const { return m_keys.size(); }
size_type size() const { return static_cast<size_type>(m_keys.size()); }

bool empty() const { return m_keys.empty(); }

Expand All @@ -111,7 +111,7 @@ namespace edm {
key_iterator p = findKey(k);
if (p == m_keys.end())
return emptyRange();
size_type loc = p - m_keys.begin();
auto loc = p - m_keys.begin();
data_iterator b = m_data.begin() + m_offsets[loc];
data_iterator e = m_data.begin() + m_offsets[loc + 1];
return range(b, e);
Expand Down
Loading