Skip to content

Commit

Permalink
Fix type
Browse files Browse the repository at this point in the history
uint was not well defined and dependent on typedef
in headers. We are now more explicit about it.
  • Loading branch information
sawenzel authored and ktf committed Apr 23, 2020
1 parent a1e2bcc commit 5d34832
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace dataformats
struct MCTruthHeaderElement {
MCTruthHeaderElement() = default; // for ROOT IO

MCTruthHeaderElement(uint i) : index(i) {}
uint index = -1; // the index into the actual MC track storage (-1 if invalid)
MCTruthHeaderElement(uint32_t i) : index(i) {}
uint32_t index = -1; // the index into the actual MC track storage (-1 if invalid)
ClassDefNV(MCTruthHeaderElement, 1);
};

Expand Down Expand Up @@ -91,7 +91,7 @@ class MCTruthContainer
/// e.g. directly on the memory of the incoming message.
std::vector<char> mStreamerData; // buffer used for streaming a flat raw buffer

size_t getSize(uint dataindex) const
size_t getSize(uint32_t dataindex) const
{
// calculate size / number of labels from a difference in pointed indices
const auto size = (dataindex < getIndexedSize() - 1)
Expand Down Expand Up @@ -130,18 +130,18 @@ class MCTruthContainer
};

// access
MCTruthHeaderElement const& getMCTruthHeader(uint dataindex) const { return mHeaderArray[dataindex]; }
MCTruthHeaderElement const& getMCTruthHeader(uint32_t dataindex) const { return mHeaderArray[dataindex]; }
// access the element directly (can be encapsulated better away)... needs proper element index
// which can be obtained from the MCTruthHeader startposition and size
TruthElement const& getElement(uint elementindex) const { return mTruthArray[elementindex]; }
TruthElement const& getElement(uint32_t elementindex) const { return mTruthArray[elementindex]; }
// return the number of original data indexed here
size_t getIndexedSize() const { return mHeaderArray.size(); }
// return the number of elements managed in this container
size_t getNElements() const { return mTruthArray.size(); }

// get individual "view" container for a given data index
// the caller can do modifications on this view (such as sorting)
gsl::span<TruthElement> getLabels(uint dataindex)
gsl::span<TruthElement> getLabels(uint32_t dataindex)
{
if (dataindex >= getIndexedSize()) {
return gsl::span<TruthElement>();
Expand All @@ -151,7 +151,7 @@ class MCTruthContainer

// get individual const "view" container for a given data index
// the caller can't do modifications on this view
gsl::span<const TruthElement> getLabels(uint dataindex) const
gsl::span<const TruthElement> getLabels(uint32_t dataindex) const
{
if (dataindex >= getIndexedSize()) {
return gsl::span<const TruthElement>();
Expand All @@ -167,7 +167,7 @@ class MCTruthContainer

// add element for a particular dataindex
// at the moment only strictly consecutive modes are supported
void addElement(uint dataindex, TruthElement const& element)
void addElement(uint32_t dataindex, TruthElement const& element)
{
if (dataindex < mHeaderArray.size()) {
// look if we have something for this dataindex already
Expand All @@ -193,7 +193,7 @@ class MCTruthContainer
// convenience interface to add multiple labels at once
// can use elements of any assignable type or sub-type
template <typename CompatibleLabel>
void addElements(uint dataindex, gsl::span<CompatibleLabel> elements)
void addElements(uint32_t dataindex, gsl::span<CompatibleLabel> elements)
{
static_assert(std::is_same<TruthElement, CompatibleLabel>::value ||
std::is_assignable<TruthElement, CompatibleLabel>::value ||
Expand All @@ -205,7 +205,7 @@ class MCTruthContainer
}

template <typename CompatibleLabel>
void addElements(uint dataindex, const std::vector<CompatibleLabel>& v)
void addElements(uint32_t dataindex, const std::vector<CompatibleLabel>& v)
{
using B = typename std::remove_const<CompatibleLabel>::type;
auto s = gsl::span<CompatibleLabel>(const_cast<B*>(&v[0]), v.size());
Expand All @@ -216,7 +216,7 @@ class MCTruthContainer
// (at random access position).
// This might be a slow process since data has to be moved internally
// so this function should be used with care.
void addElementRandomAccess(uint dataindex, TruthElement const& element)
void addElementRandomAccess(uint32_t dataindex, TruthElement const& element)
{
if (dataindex >= mHeaderArray.size()) {
// a new dataindex -> push element at back
Expand Down Expand Up @@ -253,7 +253,7 @@ class MCTruthContainer
mTruthArray[lastindex] = element;

// fix headers
for (uint i = dataindex + 1; i < mHeaderArray.size(); ++i) {
for (uint32_t i = dataindex + 1; i < mHeaderArray.size(); ++i) {
auto oldindex = mHeaderArray[i].index;
mHeaderArray[i].index = (oldindex != -1) ? oldindex + 1 : oldindex;
}
Expand All @@ -278,7 +278,7 @@ class MCTruthContainer
std::copy(other.mTruthArray.begin(), other.mTruthArray.end(), std::back_inserter(mTruthArray));

// adjust information of newly attached part
for (uint i = oldheadersize; i < mHeaderArray.size(); ++i) {
for (uint32_t i = oldheadersize; i < mHeaderArray.size(); ++i) {
mHeaderArray[i].index += oldtruthsize;
}
}
Expand Down

0 comments on commit 5d34832

Please sign in to comment.