Project
Loading...
Searching...
No Matches
BCRange.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#ifndef ALICEO2_BCRANGE_H
12#define ALICEO2_BCRANGE_H
13
15
16namespace o2
17{
18namespace dataformats
19{
20// .............................................................................
21struct bcRanges {
22
24
25 // members
26 const char* mlistName;
27 std::vector<limits> mbcRangesList;
31
32 public:
33 // constructor
34 bcRanges(const char* label)
35 {
37 reset();
38 }
39
40 // reset list
41 void reset()
42 {
43 isSorted = false;
44 isMerged = false;
45 isExtended = false;
46 mbcRangesList.clear();
47 }
48
49 char status()
50 {
51 return isSorted * (1 << 0) + isMerged * (1 << 1) + isExtended * (1 << 2);
52 }
53
54 // return number of BC ranges in list
55 auto size()
56 {
57 return mbcRangesList.size();
58 }
59
60 // add BC range
62 {
63 mbcRangesList.push_back(limits(first, last));
64 isSorted = false;
65 isMerged = false;
66 isExtended = false;
67 }
68
69 // sort mbcRangesList according to first entries
70 void sort()
71 {
72 std::sort(mbcRangesList.begin(), mbcRangesList.end(), [](limits a, limits b) {
73 return a.first < b.first;
74 });
75 isSorted = true;
76 }
77
78 // get number of BCs not included in ranges
79 template <typename BCs>
81 {
82 // needs to be merged
83 if (!isMerged) {
84 merge();
85 }
86
87 // loop over ranges and count number of BCs not contained in a range
88 uint64_t nNotCompBCs = 0;
89 uint64_t ilast = 1, inext;
90 for (auto iter = mbcRangesList.begin(); iter != mbcRangesList.end(); ++iter) {
91 inext = iter->first;
92 if (iter == mbcRangesList.begin()) {
93 nNotCompBCs += (inext - ilast);
94 } else {
95 nNotCompBCs += (inext - ilast - 1);
96 }
97 ilast = iter->second;
98 }
99 auto bclast = bcs.rawIteratorAt(bcs.size());
100 nNotCompBCs += (bclast.globalIndex() - ilast);
101 LOGF(debug, "Number of BCs not in range of compatible BCs: %i", nNotCompBCs);
102
103 return nNotCompBCs;
104 }
105
106 // merge overlaping ranges
107 void merge(bool toForce = false)
108 {
109 // return if list of ranges is empty
110 if (size() == 0) {
111 return;
112 }
113
114 // is merging required?
115 if (!isMerged || toForce) {
116 std::vector<limits> tmpList;
117 uint64_t ifirst = 0, ilast = 0;
118
119 // apply sorting of the ranges
120 if (!isSorted) {
121 sort();
122 }
123
124 // run over elements of mbcRangesList and merge lines where possible
125 for (auto iter = mbcRangesList.begin(); iter != mbcRangesList.end(); ++iter) {
126 if (iter == mbcRangesList.begin()) {
127 ifirst = iter->first;
128 ilast = iter->second;
129 continue;
130 }
131
132 if (iter->first > (ilast + 1)) {
133 // update tmpList
134 tmpList.push_back(limits(ifirst, ilast));
135 ifirst = iter->first;
136 ilast = iter->second;
137 } else {
138 if (iter->second > ilast) {
139 ilast = iter->second;
140 }
141 }
142 }
143 tmpList.push_back(limits(ifirst, ilast));
144
145 mbcRangesList.clear();
146 mbcRangesList = tmpList;
147 isMerged = true;
148 }
149 }
150
151 // add a factor fillFac of BCs not yet included in the BC ranges
152 template <typename BCs>
153 void compact(BCs bcs, Double_t fillFac, bool toForce = false)
154 {
155 if (!isExtended || toForce) {
156 // apply merging of the ranges
157 if (!isMerged || toForce) {
158 merge(toForce);
159 }
160
161 // find out number of BCs not in a compatible range
162 auto nBCs = bcs.size();
163 auto nNotCompBCs = getnNotCompBCs(bcs);
164
165 // keep adding BCs until the required number has been added
166 auto nToAdd = (uint64_t)(nNotCompBCs * fillFac);
167
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--;
179 nToAdd--;
180 }
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);
196 }
197 }
198 isExtended = true;
199 }
200 }
201
202 // check if the value index is in a range
203 // and return true if this is the case
205 {
206 // make sure that the list is merged
207 merge(false);
208
209 // find the range in which the value index falls
210 auto range = std::find_if(mbcRangesList.begin(), mbcRangesList.end(), [index](limits a) {
211 return (index >= a.first) && (index <= a.second);
212 });
213 return (range != mbcRangesList.end());
214 }
215
216 // get BC range
218 {
219 return mbcRangesList[index];
220 }
221 auto begin()
222 {
223 return mbcRangesList.begin();
224 }
225 auto end()
226 {
227 return mbcRangesList.end();
228 }
229
230 // return list name
231 auto name()
232 {
233 return mlistName;
234 }
235
236 // return the list
237 auto list()
238 {
239 return mbcRangesList;
240 }
241};
242
243// .............................................................................
244} // namespace dataformats
245
246} // namespace o2
247
248#endif // ALICEO2__BCRANGE_H
std::ostringstream debug
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
GLuint index
Definition glcorearb.h:781
GLint first
Definition glcorearb.h:399
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLenum GLint * range
Definition glcorearb.h:1899
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
auto operator[](int index)
Definition BCRange.h:217
bcRanges(const char *label)
Definition BCRange.h:34
void compact(BCs bcs, Double_t fillFac, bool toForce=false)
Definition BCRange.h:153
o2::dataformats::Pair< uint64_t, uint64_t > limits
Definition BCRange.h:23
void add(uint64_t first, uint64_t last)
Definition BCRange.h:61
void merge(bool toForce=false)
Definition BCRange.h:107
const char * mlistName
Definition BCRange.h:26
bool isInRange(uint64_t index)
Definition BCRange.h:204
std::vector< limits > mbcRangesList
Definition BCRange.h:27
uint64_t getnNotCompBCs(BCs bcs)
Definition BCRange.h:80