ATLAS Offline Software
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
20 void
22  m_bunchLumis.clear();
23 }
24 
25 // Access functions
26 int
27 LumiBlobUtil::xvalue(const cool::Record& rec) {
28  return xvalue(rec.attributeList());
29 }
30 
31 int
32 LumiBlobUtil::yvalue(const cool::Record& rec) {
33  return yvalue(rec.attributeList());
34 }
35 
36 int
37 LumiBlobUtil::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 
50 int
51 LumiBlobUtil::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 
69 const std::vector<double> &
71  return m_bunchLumis;
72 }
73 
74 /*// Fill value from cool::Record (ie. python)
75 
76 bool
77 LumiBlobUtil::setValue(const cool::Record& rec) {
78  return setValue(rec.attributeList());
79 }
80 
81 bool
82 LumiBlobUtil::setCollidingBCIDs(std::vector<unsigned int> & p) {
83  m_collidingBCIDs = p;
84  return true;
85 }
86 */
87 
88 bool
89 LumiBlobUtil::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  unsigned int len = 0; //calculating the number of luminous bunches when 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  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  } //This ends y=2
187  if (len > 0) AB1 = AB1/len;
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  } // This ends y=2
249  if (len > 0) AB1 = AB1/len;
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  union {
257  unsigned int i;
258  float f;
259  } cnv;
260  const unsigned int * y40 = reinterpret_cast<const unsigned int*> (k);
261  for (unsigned int j = BCIDold; j <= BCID; j++, y40++) {
262  if (j==BCID) {
263  cnv.i = *y40;
264  tmk = cnv.f;
265  BV = ARI*tmk/fact;
266  m_bunchLumis.push_back(BV);
267  AB1 += BV;
268  }
269  else {
270  m_bunchLumis.push_back(element);
271  }
272  }
273  BCIDold=BCID+1;
274  }
275  for (unsigned int i=BCIDold; i<3564; i++) {
276  m_bunchLumis.push_back(element);
277  }
278  AB1 = AB1/PV.size();
279  // std::cout << AB1 << std::endl;
280  } //This ends y=0
281  if (y==1) {
282  union {
283  unsigned int i;
284  float f;
285  } cnv;
286  const unsigned int * y41 = reinterpret_cast<const unsigned int*> (k);
287  for (unsigned int i = 0; i < ((blobBC.size()-1)/x); i++, y41++) {
288  cnv.i = *y41;
289  BV = cnv.f;
290  m_bunchLumis.push_back(BV);
291  AB1 += BV;
292  }
293  AB1 = AB1/((blobBC.size()-1)/x);
294  // std::cout << AB1 << std::endl;
295  } //This ends y=1
296  if (y==2) {
297  const uint16_t* k4 = reinterpret_cast<const uint16_t*> (k);
298  unsigned int len = *k4;
299  k4++;
300  union {
301  unsigned int i;
302  float f;
303  } cnv;
304  const unsigned int* y42 = reinterpret_cast<const unsigned int*> (k+2*(1+len));
305  for (unsigned int i = 0; i<len; i++, k4++) {
306  BCID = *k4;
307 
308  for (unsigned int j=BCIDold; j<=(BCID); j++, y42++) {
309  if (j==BCID) {
310  cnv.i = *y42;
311  BV = cnv.f;
312  m_bunchLumis.push_back(BV);
313  AB1 += BV;
314  }
315  else {
316  m_bunchLumis.push_back(element);
317  }
318  }
319  BCIDold=BCID+1;
320  }
321  for (unsigned int i=(BCIDold); i<3564; i++) {
322  m_bunchLumis.push_back(element);
323  }
324  }//This ends y=2
325  if (len > 0) AB1 = AB1/len;
326  // std::cout << AB1 << std::endl;
327  } //This ends x=4
328 
329  } //This ends else
330  return true;
331 } // This ends setValue
LumiBlobUtil::LumiBlobUtil
LumiBlobUtil()
Definition: LumiBlobUtil.cxx:14
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:558
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
LumiBlobUtil::yvalue
int yvalue(const cool::Record &rec)
Definition: LumiBlobUtil.cxx:32
x
#define x
LumiBlobUtil.h
PixelByteStreamErrors::BCID
@ BCID
Definition: PixelByteStreamErrors.h:13
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
lumiFormat.i
int i
Definition: lumiFormat.py:85
LumiBlobUtil::xvalue
int xvalue(const cool::Record &rec)
Definition: LumiBlobUtil.cxx:27
LumiBlobUtil::bunchLumis
const std::vector< double > & bunchLumis() const
Definition: LumiBlobUtil.cxx:70
hist_file_dump.f
f
Definition: hist_file_dump.py:140
LumiBlobUtil::clear
void clear()
Definition: LumiBlobUtil.cxx:21
y
#define y
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
LumiBlobUtil::unpack
bool unpack(const cool::Float &ARI, const coral::Blob &blobBC, const std::vector< unsigned int > &PV)
Definition: LumiBlobUtil.cxx:89
LumiBlobUtil::m_bunchLumis
std::vector< double > m_bunchLumis
Definition: LumiBlobUtil.h:47
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
error
Definition: IImpactPoint3dEstimator.h:70
fitman.k
k
Definition: fitman.py:528