ATLAS Offline Software
BunchDataUtil.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 <cstdint>
13 
15  // Clear vectors
16  this->clear();
17  error.clear();
18 }
19 
20 void
22  m_bunch1Data.clear();
23  m_bunch2Data.clear();
24 }
25 // Access functions
26 unsigned int
28  return m_bunch1Data.size();
29 }
30 unsigned int
32  return m_bunch2Data.size();
33 }
34 const std::vector<unsigned int> &
36  return m_bunch1Data;
37 }
38 const std::vector<unsigned int> &
40  return m_bunch2Data;
41 }
42 
43 int
44 BunchDataUtil::nx1Storage(const cool::Record& rec) {
45  return nx1Storage(rec.attributeList());
46 }
47 
48 int
49 BunchDataUtil::ny1Storage(const cool::Record& rec) {
50  return ny1Storage(rec.attributeList());
51 }
52 
53 int
54 BunchDataUtil::nx2Storage(const cool::Record& rec) {
55  return nx2Storage(rec.attributeList());
56 }
57 
58 int
59 BunchDataUtil::ny2Storage(const cool::Record& rec) {
60  return ny2Storage(rec.attributeList());
61 }
62 
63 int
65 
66  const coral::Blob &blobBC = attrList1["B1BunchIntensities"].data<coral::Blob>();
67  const uint8_t *k=static_cast<const uint8_t*>(blobBC.startingAddress());
68  int x = 1;
69  if (blobBC.size() == 0) {
70  return -1;
71  }
72  unsigned int tmk = *k;
73  x=tmk/10;
74  return x;
75 
76 }
77 
78 int
80  const coral::Blob &blobBC = attrList1["B1BunchIntensities"].data<coral::Blob>();
81  const uint8_t *k=static_cast<const uint8_t*>(blobBC.startingAddress());
82  int x = 1;
83  int y = 1;
84  if (blobBC.size() == 0) {
85  return -1;
86  }
87  unsigned int tmk = *k;
88  x=tmk/10;
89  y=tmk-10*x;
90  return y;
91 }
92 
93 int
95  const coral::Blob &blobBC = attrList1["B2BunchIntensities"].data<coral::Blob>();
96  const uint8_t *k=static_cast<const uint8_t*>(blobBC.startingAddress());
97  int x = 1;
98  if (blobBC.size() == 0) {
99  return -1;
100  }
101  unsigned int tmk = *k;
102  x=tmk/10;
103  return x;
104 }
105 
106 int
108  const coral::Blob &blobBC = attrList1["B2BunchIntensities"].data<coral::Blob>();
109  const uint8_t *k=static_cast<const uint8_t*>(blobBC.startingAddress());
110  int x = 1;
111  int y = 1;
112  if (blobBC.size() == 0) {
113  return -1;
114  }
115  unsigned int tmk = *k;
116  x=tmk/10;
117  y=tmk-10*x;
118  return y;
119 }
120 
121 // Fill value from cool::Record (ie. python)
122 bool
123 BunchDataUtil::setValue(const cool::Record& rec) {
124  return setValue(rec.attributeList());
125 }
126 
127 bool
128 BunchDataUtil::setCollidingBCID1s(std::vector<unsigned int> & p) {
130  return true;
131 }
132 
133 bool
134 BunchDataUtil::setCollidingBCID2s(std::vector<unsigned int> & pp) {
135  m_collidingBCID2s = pp;
136  return true;
137 }
138 
139 // Fill value from AttributeList
140 // Returns false on error
141 bool
143  // First, clear old values
144  this->clear();
145  error.clear();
146 
147  // Check if there is any data
148  if (attrList1["B1BunchIntensities"].isNull()) {
149  error = "BunchCode is NULL!";
150  return false;
151  }
152 
153  cool::Float AI1 = attrList1["B1BunchAverage"].data<cool::Float>();
154  cool::Float AI2 = attrList1["B2BunchAverage"].data<cool::Float>();
155 
156  const coral::Blob &blobBC1 = attrList1["B1BunchIntensities"].data<coral::Blob>();
157  const coral::Blob &blobBC2 = attrList1["B2BunchIntensities"].data<coral::Blob>();
158 
159 
160  std::cout << "Dette skulle vaere beam1 " << std::endl;
161  m_blobUtil.unpack(AI1,blobBC1,m_collidingBCID1s);
162 
163  std::cout << "This should be beam 2 " << std::endl;
164  m_blobUtil.unpack(AI2,blobBC2,m_collidingBCID2s);
165 
166  return true;
167 }
168  /*
169  if (blobBC2.size() == 0 && blobBC1.size() == 0) {
170  std::cout << "0" << std::endl;
171  return false;
172  }
173 
174  // Pointer to blob to allow unpacking from binary
175  const uint8_t *k=static_cast<const uint8_t*>(blobBC1.startingAddress());
176 
177  unsigned int fact = 0;
178  unsigned int x = 1;
179  unsigned int y = 1;
180  unsigned int BCID=0;
181  unsigned int BCIDold=0;
182  float BV = 0;
183  float element = 0;
184  float AB1 = 0;
185  float AB2 = 0;
186 
187  if (blobBC1.size() == 0) {
188  std::cout << "0" << std::endl;
189  return false;
190  }
191 
192  else {
193 
194  unsigned int tmk = *k;
195  x=tmk/10;
196  y=tmk-10*x;
197  fact=int(pow(100,x));
198 
199  k++;
200  // std::cout << "tmk= " << tmk << std::endl;
201  // std::cout << "x= " << x << std::endl;
202  // std::cout << "y= " << y << std::endl;
203  // std::cout << "Size " << blobBC1.size() << std::endl;
204  if (x==1) {
205  if (y==0) {
206  for (unsigned int i =0; i<m_collidingBCID1s.size(); i++) {
207  BCID = m_collidingBCID1s[i];
208 
209  const uint8_t* y10 = (const uint8_t*) k;
210  for (unsigned int j = BCIDold; j <= BCID; j++, y10++) {
211  if (j==BCID) {
212  tmk = *y10;
213  BV = AI1*tmk/fact;
214  m_bunch1Data.push_back(BV);
215  AB1 += BV;
216  }
217  else {
218  m_bunch1Data.push_back(element);
219  }
220  }
221  BCIDold=BCID+1;
222  }
223  for (unsigned int i=BCIDold; i<3564; i++) {
224  m_bunch1Data.push_back(element);
225  }
226  AB1 = AB1/m_collidingBCID1s.size();
227  std::cout << AB1 << std::endl;
228  } //This ends y=0
229  if (y==1) {
230  for (unsigned int i = 0; i < ((blobBC1.size()-1)/x); i++, k++) {
231  tmk = *k;
232  BV = AI1*tmk/fact;
233  m_bunch1Data.push_back(BV);
234  AB1 += BV;
235  }
236  AB1 = AB1/m_bunch1Data.size();
237  std::cout << AB1 << std::endl;
238  } // this ends y=1
239 
240  if (y==2) {
241  const uint16_t* k1 = (const uint16_t*) k;
242  unsigned int len = *k1;
243  k1++;
244  const uint8_t* y12 = (const uint8_t*) (k+2*(len+1));
245  for (unsigned int i = 0; i<len; i++, k1++) {
246  BCID = *k1;
247  for (unsigned int j=BCIDold; j<=(BCID); j++, y12++) {
248  if (j==BCID) {
249  tmk=*y12;
250  BV = AI1*tmk/fact;
251  m_bunch1Data.push_back(BV);
252  AB1 += BV;
253  }
254  else {
255  m_bunch1Data.push_back(element);
256  }
257  }
258  BCIDold=BCID+1;
259  }
260  for (unsigned int i=(BCIDold); i<3564; i++) {
261  m_bunch1Data.push_back(element);
262  }
263  BCIDold=0;
264  AB1 = AB1/m_bunch1Data.size();
265  std::cout << AB1 << std::endl;
266  } // This ends y=2
267  } //This ends x=1
268 
269  if (x==2) {
270  if (y==0) {
271  for (unsigned int i =0; i<m_collidingBCID1s.size(); i++) {
272  BCID = m_collidingBCID1s[i];
273 
274  const uint16_t* y20 = (const uint16_t*) k;
275  for (unsigned int j = BCIDold; j <= BCID; j++, y20++) {
276  if (j==BCID) {
277  tmk = *y20;
278  BV = AI1*tmk/fact;
279  AB1 += BV;
280  m_bunch1Data.push_back(BV);
281  }
282  else {
283  m_bunch1Data.push_back(element);
284  }
285  }
286  BCIDold=BCID+1;
287  }
288  for (unsigned int i=BCIDold; i<3564; i++) {
289  m_bunch1Data.push_back(element);
290  }
291  AB1 = AB1/m_collidingBCID1s.size();
292  std::cout << AB1 << std::endl;
293  } //This ends y=0
294 
295  if (y==1) {
296  const uint16_t* y21 = (const uint16_t*) k;
297  for (unsigned int i=0; i < (blobBC1.size()-1); i++, y21++) {
298  tmk = *y21;
299  BV = AI1*tmk/fact;
300  m_bunch1Data.push_back(BV);
301  AB1 += BV;
302  }
303  AB1 = AB1/m_bunch1Data.size();
304  std::cout << AB1 << std::endl;
305  }
306  if (y==2) {
307  const uint16_t* k2 = (const uint16_t*) k;
308  unsigned int len = *k2;
309  k2++;
310  const uint16_t* y22 = (const uint16_t*) k;
311 
312  for (unsigned int i = 0; i<len; i++, k2++) {
313  BCID = *k2;
314  for (unsigned int j = BCIDold; j <= BCID; j++, y22++) {
315  if (j==BCID) {
316  tmk=*y22;
317  BV=AI1*tmk/fact;
318  m_bunch1Data.push_back(BV);
319  AB1 += BV;
320  }
321  else {
322  m_bunch1Data.push_back(element);
323  }
324  }
325  BCIDold = BCID+1;
326  }
327  for (unsigned int i=BCIDold; i<3564; i++) {
328  m_bunch1Data.push_back(element);
329  }
330  AB1 = AB1/m_bunch1Data.size();
331  std::cout << AB1 << std::endl;
332  } //This ends y=2
333  } //This ends x=2
334 
335  if (x==4) {
336  if (y==0) {
337  for (unsigned int i =0; i<m_collidingBCID1s.size(); i++) {
338  BCID = m_collidingBCID1s[i];
339 
340  const float * y40 = (const float*) k;
341  for (unsigned int j = BCIDold; j <= BCID; j++, y40++) {
342  if (j==BCID) {
343  BV = *y40;
344  m_bunch1Data.push_back(BV);
345  AB1 += BV;
346  }
347  else {
348  m_bunch1Data.push_back(element);
349  }
350  }
351  BCIDold=BCID+1;
352  }
353  for (unsigned int i=BCIDold; i<3564; i++) {
354  m_bunch1Data.push_back(element);
355  }
356  AB1 = AB1/m_bunch1Data.size();
357  std::cout << AB1 << std::endl;
358  } //This ends y=0
359  if (y==1) {
360  const float* y41 = (const float*) k;
361  for (unsigned int i = 0; i < ((blobBC1.size()-1)/x); i++, y41++) {
362  BV = *y41;
363  m_bunch1Data.push_back(BV);
364  AB1 += BV;
365  }
366  AB1 = AB1/m_collidingBCID1s.size();
367  } //This ends y=1
368  if (y==2) {
369  const uint16_t* k4 = (const uint16_t*) k;
370  unsigned int len = *k4;
371  k4++;
372  const float* y42 = (const float*) (k+2*(1+len));
373 
374  for (unsigned int i = 0; i<len; i++, k4++) {
375  BCID = *k4;
376  for (unsigned int j=BCIDold; j<=(BCID); j++, y42++) {
377  if (j==BCID) {
378  BV = *y42;
379  m_bunch1Data.push_back(BV);
380  AB1 += BV;
381  }
382  else {
383  m_bunch1Data.push_back(element);
384  }
385  }
386  BCIDold=BCID+1;
387  }
388  for (unsigned int i=(BCIDold); i<3564; i++) {
389  m_bunch1Data.push_back(element);
390  }
391  AB1 = AB1/m_bunch1Data.size();
392  std::cout << AB1 << std::endl;
393  } //This ends y=2
394  } //This ends x=4
395 }
396 
397 
398  // Decode Beam2 list //////////////////////////
399 
400  const uint8_t *q = static_cast<const uint8_t*>(blobBC2.startingAddress());
401 
402  if (blobBC2.size() == 0) {
403  std::cout << "0" << std::endl;
404  return false;
405  }
406  else {
407  unsigned int tmk = *q;
408  x=tmk/10;
409  y=tmk-10*x;
410  fact=int(pow(100,x));
411  q++;
412  BCID = 0;
413  BCIDold = 0;
414  if (x==1) {
415  if (y==0) {
416  for (unsigned int i =0; i<m_collidingBCID2s.size(); i++) {
417  BCID = m_collidingBCID2s[i];
418 
419  const uint8_t* u10 = (const uint8_t*) q;
420  for (unsigned int j = BCIDold; j <= BCID; j++, u10++) {
421  if (j==BCID) {
422  tmk = *u10;
423  BV = AI2*tmk/fact;
424  m_bunch2Data.push_back(BV);
425  AB2 += BV;
426  }
427  else {
428  m_bunch2Data.push_back(element);
429  }
430  }
431  BCIDold=BCID+1;
432  }
433  for (unsigned int i=BCIDold; i<3564; i++) {
434  m_bunch2Data.push_back(element);
435  }
436  AB2 = AB2/m_collidingBCID2s.size();
437  } //This ends y=0
438 
439  if (y==1) {
440  for (unsigned int i = 0; i < (blobBC2.size()-1)/x; i++, q++) {
441  tmk = *q;
442  BV = AI2*tmk/fact;
443  m_bunch2Data.push_back(BV);
444  AB2 += BV;
445  }
446  AB2 = AB2/((blobBC2.size()-1)/x);
447  } // This ends y=1
448 
449  if (y==2) {
450  const uint16_t* k1 = (const uint16_t*) k;
451  unsigned int len = *k1;
452  k1++;
453  const uint8_t* u12 = (const uint8_t*) (k+2*(len+1));
454  for (unsigned int i = 0; i<len; i++, k1++) {
455  BCID = *k1;
456  for (unsigned int j=BCIDold; j<=(BCID); j++, u12++) {
457  if (j==BCID) {
458  tmk=*u12;
459  BV = AI2*tmk/fact;
460  m_bunch2Data.push_back(BV);
461  AB2 += BV;
462  }
463  else {
464  m_bunch2Data.push_back(element);
465  }
466  }
467  BCIDold=BCID+1;
468  }
469  for (unsigned int i=(BCIDold); i<3564; i++) {
470  m_bunch2Data.push_back(element);
471  }
472  BCIDold=0;
473  AB2 = AB2/len;
474  } // This ends y=2
475 
476  } //This ends x=1
477 
478  if (x==2) {
479  if (y==0) {
480  for (unsigned int i =0; i<m_collidingBCID2s.size(); i++) {
481  BCID = m_collidingBCID2s[i];
482 
483  const uint16_t* u20 = (const uint16_t*) q;
484  for (unsigned int j = BCIDold; j <= BCID; j++, u20++) {
485  if (j==BCID) {
486  tmk = *u20;
487  BV = AI2*tmk/fact;
488  m_bunch2Data.push_back(BV);
489  AB2 += BV;
490  }
491  else {
492  m_bunch2Data.push_back(element);
493  }
494  }
495  BCIDold=BCID+1;
496  }
497  for (unsigned int i=BCIDold; i<3564; i++) {
498  m_bunch2Data.push_back(element);
499  }
500  AB2 = AB2/m_collidingBCID2s.size();
501  } //This ends y=0
502 
503  if (y==1) {
504  const uint16_t* u21 = (const uint16_t*) q;
505 
506  for (unsigned int i = 0; i < ((blobBC2.size()-1)/x); i++, u21++) {
507  tmk = *u21;
508  BV = AI2*tmk/fact;
509  m_bunch2Data.push_back(BV);
510  AB2 += BV;
511  }
512  AB2 = AB2/((blobBC2.size()-1)/x);
513  std::cout << AB2 << std::endl;
514  }
515  if (y==2) {
516  const uint16_t* k2 = (const uint16_t*) q;
517  unsigned int len = *k2;
518  k2++;
519  const uint16_t* u22 = (const uint16_t*) q;
520 
521  for (unsigned int i = 0; i<len; i++, k2++) {
522  BCID = *k2;
523  std::cout << "BCIDnew " << BCID << std::endl;
524  std::cout << "BCIDold " << BCIDold << std::endl;
525  for (unsigned int j = BCIDold; j <= BCID; j++, u22++) {
526  if (j==BCID) {
527  tmk=*u22;
528  BV=AI2*tmk/fact;
529  m_bunch2Data.push_back(BV);
530  AB2 += BV;
531  }
532  else {
533  m_bunch2Data.push_back(element);
534  }
535  }
536  BCIDold = BCID+1;
537  }
538  for (unsigned int i=BCIDold; i<3564; i++) {
539  m_bunch2Data.push_back(element);
540  }
541  AB2 = AB2/len;
542  } //This ends y=2
543  } // This ends x=2
544 
545  if (x==4) {
546  if (y==0) {
547  for (unsigned int i =0; i<m_collidingBCID2s.size(); i++) {
548  BCID = m_collidingBCID2s[i];
549 
550  const float * u40 = (const float*) q;
551  for (unsigned int j = BCIDold; j <= BCID; j++, u40++) {
552  if (j==BCID) {
553  BV = *u40;
554  m_bunch2Data.push_back(BV);
555  AB2 += BV;
556  }
557  else {
558  m_bunch2Data.push_back(element);
559  }
560  }
561  BCIDold=BCID+1;
562  }
563  for (unsigned int i=BCIDold; i<3564; i++) {
564  m_bunch2Data.push_back(element);
565  }
566  AB2 = AB2/m_collidingBCID2s.size();
567  } //This ends y=0
568  if (y==1) {
569  const float* q4 = (const float*) q;
570  for (unsigned int i = 0; i < ((blobBC2.size()-1)/x); i++, q4++) {
571  BV = *q4;
572  m_bunch2Data.push_back(BV);
573  AB2 += BV;
574  }
575  AB2 = AB2/m_bunch2Data.size();
576  } //This ends y=1
577  if (y==2) {
578  const uint16_t* k4 = (const uint16_t*) q;
579  unsigned int len = *k4;
580  k4++;
581  const float* u42 = (const float*) (k+2*(1+len));
582 
583  for (unsigned int i = 0; i<len; i++, k4++) {
584  BCID = *k4;
585  for (unsigned int j=BCIDold; j<=(BCID); j++, u42++) {
586  if (j==BCID) {
587  BV = *u42;
588  AB2 += BV;
589  m_bunch2Data.push_back(BV);
590  }
591  else {
592  m_bunch2Data.push_back(element);
593  }
594  }
595  BCIDold=BCID+1;
596  }
597  for (unsigned int i=(BCIDold); i<3564; i++) {
598  m_bunch2Data.push_back(element);
599  }
600  AB2 = AB2/len;
601  }//This ends y=2
602  }//This ends x=4
603  } // This ends the beam 2 decoding
604 
605 return true;
606 }
607  */
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
BunchDataUtil::setValue
bool setValue(const coral::AttributeList &attrList1)
Definition: BunchDataUtil.cxx:142
BunchDataUtil::ny2Storage
int ny2Storage(const cool::Record &rec)
Definition: BunchDataUtil.cxx:59
BunchDataUtil::nBunch2Data
unsigned int nBunch2Data() const
Definition: BunchDataUtil.cxx:31
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
x
#define x
BunchDataUtil::setCollidingBCID1s
bool setCollidingBCID1s(std::vector< unsigned int > &)
Definition: BunchDataUtil.cxx:128
BunchDataUtil::m_blobUtil
class LumiBlobUtil m_blobUtil
Definition: BunchDataUtil.h:67
BunchDataUtil::m_bunch1Data
std::vector< unsigned int > m_bunch1Data
Definition: BunchDataUtil.h:65
BunchDataUtil::nBunch1Data
unsigned int nBunch1Data() const
Definition: BunchDataUtil.cxx:27
BunchDataUtil::bunch2Data
const std::vector< unsigned int > & bunch2Data() const
Definition: BunchDataUtil.cxx:39
BunchDataUtil::ny1Storage
int ny1Storage(const cool::Record &rec)
Definition: BunchDataUtil.cxx:49
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
BunchDataUtil.h
BunchDataUtil::clear
void clear()
Definition: BunchDataUtil.cxx:21
BunchDataUtil::setCollidingBCID2s
bool setCollidingBCID2s(std::vector< unsigned int > &)
Definition: BunchDataUtil.cxx:134
BunchDataUtil::m_bunch2Data
std::vector< unsigned int > m_bunch2Data
Definition: BunchDataUtil.h:66
BunchDataUtil::BunchDataUtil
BunchDataUtil()
Definition: BunchDataUtil.cxx:14
BunchDataUtil::m_collidingBCID1s
std::vector< unsigned int > m_collidingBCID1s
Definition: BunchDataUtil.h:62
BunchDataUtil::bunch1Data
const std::vector< unsigned int > & bunch1Data() const
Definition: BunchDataUtil.cxx:35
y
#define y
BunchDataUtil::m_collidingBCID2s
std::vector< unsigned int > m_collidingBCID2s
Definition: BunchDataUtil.h:63
BunchDataUtil::nx1Storage
int nx1Storage(const cool::Record &rec)
Definition: BunchDataUtil.cxx:44
LumiBlobUtil::unpack
bool unpack(const cool::Float &ARI, const coral::Blob &blobBC, const std::vector< unsigned int > &PV)
Definition: LumiBlobUtil.cxx:90
BunchDataUtil::nx2Storage
int nx2Storage(const cool::Record &rec)
Definition: BunchDataUtil.cxx:54
error
Definition: IImpactPoint3dEstimator.h:70
fitman.k
k
Definition: fitman.py:528