Skip to content

Commit 4e6c9e1

Browse files
pbuehlershahor02
authored andcommitted
Protect for case when list of ranges is empty
1 parent 75f013b commit 4e6c9e1

1 file changed

Lines changed: 32 additions & 18 deletions

File tree

  • DataFormats/Reconstruction/include/ReconstructionDataFormats

DataFormats/Reconstruction/include/ReconstructionDataFormats/BCRange.h

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ struct bcRanges {
106106
// merge overlaping ranges
107107
void merge(bool toForce = false)
108108
{
109+
// return if list of ranges is empty
110+
if (size() == 0) {
111+
return;
112+
}
113+
114+
// is merging required?
109115
if (!isMerged || toForce) {
110116
std::vector<limits> tmpList;
111117
uint64_t ifirst = 0, ilast;
@@ -158,28 +164,36 @@ struct bcRanges {
158164

159165
// keep adding BCs until the required number has been added
160166
auto nToAdd = (uint64_t)(nNotCompBCs * fillFac);
161-
int cnt = 0;
162-
while (nToAdd > 0) {
163-
// add BC at the beginning
164-
if (mbcRangesList[0].first > 1) {
165-
mbcRangesList[0].first--;
166-
nToAdd--;
167-
}
168-
169-
// number of BCs to add in this round
170-
auto nr = mbcRangesList.size();
171-
if (nr > nToAdd) {
172-
nr = nToAdd;
173-
}
174167

175-
// add BC after each range
176-
for (auto ii = 0; ii < nr; ii++) {
177-
if (mbcRangesList[ii].second < nBCs) {
178-
mbcRangesList[ii].second++;
168+
// special case when list of ranges is empty
169+
if (size() == 0) {
170+
uint64_t ifirst = (nBCs - nToAdd) / 2;
171+
uint64_t ilast = ifirst + nToAdd - 1;
172+
add(ifirst, ilast);
173+
} else {
174+
int cnt = 0;
175+
while (nToAdd > 0) {
176+
// add BC at the beginning
177+
if (mbcRangesList[0].first > 1) {
178+
mbcRangesList[0].first--;
179179
nToAdd--;
180180
}
181+
182+
// number of BCs to add in this round
183+
auto nr = size();
184+
if (nr > nToAdd) {
185+
nr = nToAdd;
186+
}
187+
188+
// add BC after each range
189+
for (auto ii = 0; ii < nr; ii++) {
190+
if (mbcRangesList[ii].second < nBCs) {
191+
mbcRangesList[ii].second++;
192+
nToAdd--;
193+
}
194+
}
195+
merge(true);
181196
}
182-
merge(true);
183197
}
184198
isExtended = true;
185199
}

0 commit comments

Comments
 (0)