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