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