ATLAS Offline Software
Loading...
Searching...
No Matches
LumiBlobUtil.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "CoralBase/Blob.h"
7#include "CoralBase/Attribute.h"
8#include <sstream>
9#include <iostream>
10#include <cmath>
11#include <vector>
12#include <cstdint>
13
15 // Clear vectors
16 this->clear();
17 error.clear();
18}
19// The number 3564 is the number of BCID's
20void
24
25// Access functions
26int
27LumiBlobUtil::xvalue(const cool::Record& rec) {
28 return xvalue(rec.attributeList());
29}
30
31int
32LumiBlobUtil::yvalue(const cool::Record& rec) {
33 return yvalue(rec.attributeList());
34}
35
36int
37LumiBlobUtil::xvalue(const coral::AttributeList& attrList1) const {
38 const coral::Blob &blobBC = attrList1["BunchRawInstLum"].data<coral::Blob>();
39 const uint8_t *k=static_cast<const uint8_t*>(blobBC.startingAddress());
40 int x = 1;
41 if (blobBC.size() == 0) {
42 std::cout << "No Blob" << std::endl;
43 return -1;
44 }
45 unsigned int tmk = *k;
46 x=tmk/10;
47 return x;
48}
49
50int
51LumiBlobUtil::yvalue(const coral::AttributeList& attrList1) const {
52
53 const coral::Blob &blobBC = attrList1["BunchRawInstLum"].data<coral::Blob>();
54
55 const uint8_t *k=static_cast<const uint8_t*>(blobBC.startingAddress());
56 int y = 1;
57 int x = 1;
58 if (blobBC.size() == 0) {
59 std::cout << "No Blob" << std::endl;
60 return -1;
61 }
62 unsigned int tmk = *k;
63 x=tmk/10;
64 y=tmk-10*x;
65 return y;
66}
67
68
69const std::vector<double> &
71 return m_bunchLumis;
72}
73
74/*// Fill value from cool::Record (ie. python)
75
76bool
77LumiBlobUtil::setValue(const cool::Record& rec) {
78 return setValue(rec.attributeList());
79}
80
81bool
82LumiBlobUtil::setCollidingBCIDs(std::vector<unsigned int> & p) {
83 m_collidingBCIDs = p;
84 return true;
85}
86*/
87
88bool
89LumiBlobUtil::unpack(const cool::Float &ARI, const coral::Blob &blobBC, const std::vector<unsigned int> &PV) {
90
91 const uint8_t *k=static_cast<const uint8_t*>(blobBC.startingAddress());
92
93 if (blobBC.size() == 0) {
94 std::cout << "No Blob" << std::endl;
95 return false;
96 }
97
98 else {
99 unsigned int tmk = *k; //Used to make sure that the value from the blob is a number
100 unsigned int fact = 0; //Used in calculation of Stored value when x=1 or x=2
101 unsigned int x = 1; //Size of blob values
102 unsigned int y = 1; // Storage modes
103 unsigned int BCID = 0;//Newest BCID number - used for storing the data when y=0 or y=2
104 unsigned int BCIDold = 0; //Last BCID number - used for storing data when y=0 or y=2
105 float BV = 0; //The actual stored value
106 float AB1 = 0; // The avarage value for one LB/timestep
107 double element = 0; // This is allways 0, but makes sure it is a double
108
109 x=tmk/10;
110 y=tmk-x*10;
111 fact=int(pow(100,x));
112 /*
113 std::cout << "From unpack " << std::endl;
114 std::cout << "value of x: " << x << std::endl;
115 std::cout << "value of y: " << y << std::endl;
116 std::cout << "BlobBC.size() " << blobBC.size() << std::endl;
117 std::cout << "Vector.size " << PV.size() << std::endl;
118 */
119 k++;
120
122 if (x==1) {
123 if (y==0) {
124 for (unsigned int i =0; i<PV.size(); i++) {
125 // std::cout << i<< std::endl;
126 BCID = PV[i];
127
128 // std::cout << "BCID " << BCID << std::endl;
129 const uint8_t* y10 = (const uint8_t*) k;
130 for (unsigned int j = BCIDold; j <= BCID; j++, y10++) {
131 if (j==BCID) {
132 tmk = *y10;
133 BV = ARI*tmk/fact;
134 m_bunchLumis.push_back(BV);
135 AB1 += BV;
136 // std::cout << "BV " << BV << std::endl;
137 }
138 else {
139 m_bunchLumis.push_back(element);
140 }
141 }
142 BCIDold=BCID+1;
143 }
144 for (unsigned int i=BCIDold; i<3564; i++) {
145 m_bunchLumis.push_back(element);
146 }
147 AB1 = AB1/PV.size();
148 // std::cout << AB1 << std::endl;
149 } //This ends y=0
150 if (y==1) {
151 const uint8_t* y11 = (const uint8_t*) k;
152 for (unsigned int i = 0; i < ((blobBC.size()-1)/x); i++, y11++) {
153 tmk = *y11;
154 BV = ARI*tmk/fact;
155 m_bunchLumis.push_back(BV);
156 AB1 += BV;
157 }
158 AB1 = AB1/m_bunchLumis.size();
159 // std::cout << AB1 << std::endl;
160 } //This ends y=1
161 if (y==2) {
162 const uint16_t* k1 = reinterpret_cast<const uint16_t*> (k);
163 unsigned int len = *k1;
164 k1++;
165 const uint8_t* y12 = k+2*(len+1);
166 for (unsigned int i = 0; i<len; i++, k1++) {
167 BCID = *k1;
168 for (unsigned int j=BCIDold; j<=(BCID); j++, y12++) {
169 if (j==BCID) {
170 tmk=*y12;
171 BV = ARI*tmk/fact;
172 m_bunchLumis.push_back(BV);
173 AB1 += BV;
174 }
175 else {
176 m_bunchLumis.push_back(element);
177 }
178 }
179 BCIDold=BCID+1;
180 }
181 for (unsigned int i=(BCIDold); i<3564; i++) {
182 m_bunchLumis.push_back(element);
183 }
184 BCIDold=0;
185 if (len > 0) AB1 = AB1/len;
186 } //This ends y=2
187 // std::cout << AB1 << std::endl;
188 } //This ends x=1
189 if (x==2) {
190 if (y==0) {
191 for (unsigned int i =0; i<PV.size(); i++) {
192 BCID = PV[i];
193 const uint16_t* y20 = reinterpret_cast<const uint16_t*> (k);
194 for (unsigned int j = BCIDold; j <= BCID; j++, y20++) {
195 if (j==BCID) {
196 tmk = *y20;
197 BV = ARI*tmk/fact;
198 m_bunchLumis.push_back(BV);
199 AB1 += BV;
200 }
201 else {
202 m_bunchLumis.push_back(element);
203 }
204 }
205 BCIDold=BCID+1;
206 }
207 for (unsigned int i=BCIDold; i<3564; i++) {
208 m_bunchLumis.push_back(element);
209 }
210 AB1 = AB1/PV.size();
211 // std::cout << AB1 << std::endl;
212 }// This ends y=0
213 if (y==1) {
214 const uint16_t* y21 = reinterpret_cast<const uint16_t*> (k);
215 for (unsigned int i = 0; i < ((blobBC.size()-1)/x); i++, y21++) {
216 tmk=*y21;
217 BV = ARI*tmk/fact;
218 m_bunchLumis.push_back(BV);
219 AB1 += BV;
220 }
221 AB1 = AB1/((blobBC.size()-1)/x);
222 // std::cout << AB1 << std::endl;
223 } //This ends y=1
224 if (y==2) {
225 const uint16_t* k2 = reinterpret_cast<const uint16_t*> (k);
226 unsigned int len = *k2;
227 k2++;
228 const uint16_t* y22 = reinterpret_cast<const uint16_t*> (k+2*(len+1));
229 for (unsigned int i = 0; i<len; i++, k2++) {
230 BCID = *k2;
231 for (unsigned int j=BCIDold; j<=(BCID); j++, y22++) {
232 if (j==BCID) {
233 tmk=*y22;
234 BV = ARI*tmk/fact;
235 m_bunchLumis.push_back(BV);
236 AB1 += BV;
237 }
238 else {
239 m_bunchLumis.push_back(element);
240 }
241 }
242 BCIDold=BCID+1;
243 }
244 for (unsigned int i=BCIDold; i<3564; i++) {
245 m_bunchLumis.push_back(element);
246 }
247 if (len > 0) AB1 = AB1/len;
248 } // This ends y=2
249 // std::cout << AB1 << std::endl;
250 } // This ends x=2
251 if (x==4) {
252 if (y==0) {
253 for (unsigned int i =0; i<PV.size(); i++) {
254 BCID = PV[i];
255 union {
256 unsigned int i;
257 float f;
258 } cnv;
259 const unsigned int * y40 = reinterpret_cast<const unsigned int*> (k);
260 for (unsigned int j = BCIDold; j <= BCID; j++, y40++) {
261 if (j==BCID) {
262 cnv.i = *y40;
263 tmk = cnv.f;
264 BV = ARI*tmk/fact;
265 m_bunchLumis.push_back(BV);
266 AB1 += BV;
267 }
268 else {
269 m_bunchLumis.push_back(element);
270 }
271 }
272 BCIDold=BCID+1;
273 }
274 for (unsigned int i=BCIDold; i<3564; i++) {
275 m_bunchLumis.push_back(element);
276 }
277 AB1 = AB1/PV.size();
278 // std::cout << AB1 << std::endl;
279 } //This ends y=0
280 if (y==1) {
281 union {
282 unsigned int i;
283 float f;
284 } cnv;
285 const unsigned int * y41 = reinterpret_cast<const unsigned int*> (k);
286 for (unsigned int i = 0; i < ((blobBC.size()-1)/x); i++, y41++) {
287 cnv.i = *y41;
288 BV = cnv.f;
289 m_bunchLumis.push_back(BV);
290 AB1 += BV;
291 }
292 AB1 = AB1/((blobBC.size()-1)/x);
293 // std::cout << AB1 << std::endl;
294 } //This ends y=1
295 if (y==2) {
296 const uint16_t* k4 = reinterpret_cast<const uint16_t*> (k);
297 unsigned int len = *k4;
298 k4++;
299 union {
300 unsigned int i;
301 float f;
302 } cnv;
303 const unsigned int* y42 = reinterpret_cast<const unsigned int*> (k+2*(1+len));
304 for (unsigned int i = 0; i<len; i++, k4++) {
305 BCID = *k4;
306
307 for (unsigned int j=BCIDold; j<=(BCID); j++, y42++) {
308 if (j==BCID) {
309 cnv.i = *y42;
310 BV = cnv.f;
311 m_bunchLumis.push_back(BV);
312 AB1 += BV;
313 }
314 else {
315 m_bunchLumis.push_back(element);
316 }
317 }
318 BCIDold=BCID+1;
319 }
320 for (unsigned int i=(BCIDold); i<3564; i++) {
321 m_bunchLumis.push_back(element);
322 }
323 if (len > 0) AB1 = AB1/len;
324 }//This ends y=2
325 // std::cout << AB1 << std::endl;
326 } //This ends x=4
327
328 } //This ends else
329 return true;
330} // This ends setValue
#define y
#define x
constexpr int pow(int base, int exp) noexcept
bool unpack(const cool::Float &ARI, const coral::Blob &blobBC, const std::vector< unsigned int > &PV)
const std::vector< double > & bunchLumis() const
int xvalue(const cool::Record &rec)
std::vector< double > m_bunchLumis
int yvalue(const cool::Record &rec)