ATLAS Offline Software
Functions | Variables
python.LumiBlobConversion Namespace Reference

Functions

def blob_read (self, size=-1)
 
def bConvert (b, nbyte=1)
 
def bConvertList (b, nbyte=1, nval=1)
 
def unpackBunchGroup (blob, bgrp=1)
 
def unpackBunchGroupList (blob, bgrp=[1])
 
def unpackBCIDMask (blob, nb1, nb2, nlumi)
 
def unpackRun2BCIDMask (blob, nb1, nb2, nlumi)
 
def unpackRun1BCIDMask (blob, nb1, nb2, nlumi)
 
def unpackBCIDValues (blob, mask=[], normValue=1)
 
def unpackBunches (blob, mask=[])
 
def unpackLiveFraction (trigPayload, priority='high')
 

Variables

 pos
 

Function Documentation

◆ bConvert()

def python.LumiBlobConversion.bConvert (   b,
  nbyte = 1 
)

Definition at line 26 of file LumiBlobConversion.py.

26 def bConvert(b, nbyte=1):
27  # routine to store an unsigned int (1, 2, 4 or 8 byte) in a blob
28  packopt=dict([[1,'B'],[2,'H'],[4,'f'],[8,'d']])
29  if nbyte in packopt:
30  # print 'bConvert - b:[', b[0:nbyte], '] nbyte:', nbyte, ' fmt:', packopt[nbyte], type(b)
31  ival=struct.unpack(packopt[nbyte], b[0:nbyte])
32  else:
33  print('bConvert: Unrecognized pack option')
34  sys.exit()
35 
36  return ival[0]
37 
38 # Optional arguemnt to nval to specify number of values to read

◆ bConvertList()

def python.LumiBlobConversion.bConvertList (   b,
  nbyte = 1,
  nval = 1 
)

Definition at line 39 of file LumiBlobConversion.py.

39 def bConvertList(b, nbyte=1, nval=1):
40  # routine to store an unsigned int (1, 2, 4 or 8 byte) in a blob
41  packopt=dict([[1,'B'],[2,'H'],[4,'f'],[8,'d']])
42  if nbyte in packopt:
43  # print 'bConvert - b:[', b[0:nbyte], '] nbyte:', nbyte, ' fmt:', packopt[nbyte], type(b)
44  fmt = '%d%s' % (nval, packopt[nbyte])
45  ival=struct.unpack(fmt, b[0:nval*nbyte])
46  else:
47  print('bConvertList: Unrecognized pack option')
48  sys.exit()
49 
50  return list(ival)
51 
52 # Unpack bunch group bgrp. By default, bgrp=1 is the physics bunch group.

◆ blob_read()

def python.LumiBlobConversion.blob_read (   self,
  size = -1 
)

Definition at line 12 of file LumiBlobConversion.py.

12 def blob_read(self, size = -1):
13  if size < 0:
14  endpos = self.size()
15  else:
16  endpos = self.pos + size
17  beginpos = self.pos
18  self.pos = endpos
19  buf = self.startingAddress()
20  buf.SetSize(self.size())
21  return buf[beginpos:endpos]
22 
23 # add the new functions
24 getattr(gbl,"coral::Blob").read = blob_read
25 

◆ unpackBCIDMask()

def python.LumiBlobConversion.unpackBCIDMask (   blob,
  nb1,
  nb2,
  nlumi 
)

Definition at line 103 of file LumiBlobConversion.py.

103 def unpackBCIDMask(blob,nb1,nb2,nlumi):
104 
105  bloblength = blob.size()
106 
107  if bloblength == 3564:
108  return unpackRun2BCIDMask(blob,nb1,nb2,nlumi)
109  else:
110  return unpackRun1BCIDMask(blob,nb1,nb2,nlumi)
111 
112 # routine to unpack the BCID mask stored in COOL
113 # This is the run2 version

◆ unpackBCIDValues()

def python.LumiBlobConversion.unpackBCIDValues (   blob,
  mask = [],
  normValue = 1 
)

Definition at line 183 of file LumiBlobConversion.py.

183 def unpackBCIDValues(blob, mask=[], normValue=1):
184 
185  bss, bcidVec, lvec = unpackBunches(blob, mask)
186 
187  if bss>0:
188  if not (len(bcidVec)==len(lvec)):
189  print('unpackBCIDValues - length mismatch: len(bcidVec)=', len(bcidVec), 'len(lvec)=', len(lvec))
190  sys.exit()
191 
192  bLumi=[]
193  for i in range(len(bcidVec)):
194  if bss<4:
195  bLumi.append(lvec[i]*normValue/pow(100,bss))
196  else:
197  bLumi.append(lvec[i])
198 
199  #for i in range(len(bcidVec)):
200  # print 'BCID:', bcidVec[i], 'Raw:', bLumi[i]
201 
202  return bcidVec,bLumi
203 
204  else:
205  return [],[]
206 

◆ unpackBunches()

def python.LumiBlobConversion.unpackBunches (   blob,
  mask = [] 
)

Definition at line 207 of file LumiBlobConversion.py.

207 def unpackBunches(blob,mask=[]):
208  # routine to unpack Intensity/Luminosity info stored in COOL
209  # the mask given as input has to match the quantity to be
210  # unpacked (beam1, beam2, beamsand for B1, B2 intensities and
211  # luminosities, respectively)
212 
213  if blob.size() == 0:
214  return 0,[],[]
215 
216  blobCopy = blob.read()
217  blobCounter = 0
218  try:
219  b = blobCopy[blobCounter:blobCounter+1]
220  blobCounter += 1
221  flag=bConvert(b)
222  bss=(flag%100)/10
223  smod=flag%10
224  # print 'Storage mode for',str, 'is', smod, 'with bss=', bss
225 
226  if smod==2:
227  b = blobCopy[blobCounter:blobCounter+2]
228  blobCounter += 2
229  vlen=bConvert(b, 2)
230  #print 'Bunch vector has length ',vlen
231  bcidVec=[]
232  bcidVec = bConvertList(blobCopy[blobCounter:], 2, vlen)
233  blobCounter += 2*vlen
234  # for i in range(vlen):
235  # valb = blobCopy[blobCounter:blobCounter+2]
236  # blobCounter += 2
237  # val=struct.unpack('H', valb)
238  # bcidVec.append(val)
239 
240  elif smod==0:
241  # Make sure this is a list, and sorted (can pass set for example)
242  bcidVec=list(mask)
243  bcidVec.sort()
244  vlen=len(mask)
245  elif smod==3:
246  print('storage mode 3 not implemented in unpackBunches')
247  sys.exit()
248  elif smod==1:
249  bcidVec=[i for i in range(3564)]
250  vlen=3564
251  else:
252  print('Unknown storage mode ',smod)
253  sys.exit()
254  valueVec=[]
255 
256  valueVec = bConvertList(blobCopy[blobCounter:], bss, vlen)
257 # for i in range(vlen):
258 # valb = blobCopy[blobCounter:blobCounter+bss]
259 # blobCounter += bss
260 # val=bConvert(valb,bss)
261 # valueVec.append(val)
262 
263  return bss,bcidVec,valueVec
264 
265  except RuntimeError as e:
266  print(e)
267  return 0,[],[]
268 
269 # Unpack live fraction into vector keyed by bcid-1
270 # Takes payload of /TRIGGER/LUMI/PerBcidDeadtime folder

◆ unpackBunchGroup()

def python.LumiBlobConversion.unpackBunchGroup (   blob,
  bgrp = 1 
)

Definition at line 53 of file LumiBlobConversion.py.

53 def unpackBunchGroup(blob, bgrp=1):
54  physBG = []
55  if blob.size() == 0: return
56 
57  blobCopy = blob.read()
58  mask = (1 << int(bgrp))
59 
60  ivallist = bConvertList(blobCopy, 1, 3564)
61  for i in range(3564):
62  if ivallist[i] & mask:
63  physBG.append(i)
64 
65 # blobCounter = 0
66 # for i in range(3564):
67 # try:
68 # b = blobCopy[blobCounter:blobCounter+1]
69 # blobCounter += 1
70 # ival = struct.unpack('B', b)
71 # #s = struct.unpack('B', b)
72 # #ival = bConvert(s)
73 # except Exception, e:
74 # print e
75 # ival = 0
76 # if (ival>>1) & 1 == 1:
77 # physBG.append(i)
78 
79  return physBG
80 
81 # Unpack bunch group bgrp. By default, bgrp=1 is the physics bunch group.

◆ unpackBunchGroupList()

def python.LumiBlobConversion.unpackBunchGroupList (   blob,
  bgrp = [1] 
)

Definition at line 82 of file LumiBlobConversion.py.

82 def unpackBunchGroupList(blob, bgrp=[1]):
83  physBG = dict()
84  mask = dict()
85 
86  if blob.size() == 0: return
87 
88  blobCopy = blob.read()
89 
90  for id in bgrp:
91  mask[id] = (1 << int(id))
92  physBG[id] = []
93 
94  ivallist = bConvertList(blobCopy, 1, 3564)
95  for i in range(3564):
96  for id in bgrp:
97  if ivallist[i] & mask[id]:
98  physBG[id].append(i)
99 
100  return physBG
101 
102 # Generic routine to unpack BCID mask

◆ unpackLiveFraction()

def python.LumiBlobConversion.unpackLiveFraction (   trigPayload,
  priority = 'high' 
)

Definition at line 271 of file LumiBlobConversion.py.

271 def unpackLiveFraction(trigPayload, priority = 'high'):
272 
273  liveVec = array.array('f', 3564*[0.])
274 
275  if priority == 'high':
276  blob = trigPayload['HighPriority']
277  elif priority == 'low':
278  blob = trigPayload['LowPriority']
279  else:
280  print('unpackLiveFraction - unknown priority requested %s', str(priority))
281  return liveVec
282 
283  bloblength = blob.size()
284 
285  # Due to a bug, the blob was sometimes written at 3654 rather than desired 3564
286  # More bugs, use anything long enough
287  if bloblength < 3*3564: #!= 3*3654 and bloblength != 3*3564:
288  # Corrupt, don't trust anything
289  print('unpackLiveFraction found blob length %d!' % bloblength)
290  return liveVec
291 
292  blobCopy = blob.read()
293  # blobCounter = 0
294 
295  # No counts, no work to do
296  turnCounter = trigPayload['TurnCounter']
297  if not turnCounter > 0:
298  return liveVec
299 
300  # Even if longer blob is present, only care about this range
301 
302  byte = bConvertList(blobCopy, 1, 3*3564)
303 
304  for i in range(3564):
305 
306  busyCounter = byte[3*i] | (byte[3*i+1] << 8) | (byte[3*i+2] << 16)
307 
308  # byte0 = struct.unpack('B', blobCopy[blobCounter:blobCounter+1])
309  # blobCounter += 1
310  # byte1 = struct.unpack('B', blobCopy[blobCounter:blobCounter+1])
311  # blobCounter += 1
312  # byte2 = struct.unpack('B', blobCopy[blobCounter:blobCounter+1])
313  # blobCounter += 1
314  # busyCounter = byte0 | (byte1 << 8) | (byte2 << 16)
315 
316  liveFrac = 1 - float(busyCounter) / turnCounter
317 
318  liveVec[i] = liveFrac
319 
320  # print 'BCID: %d Busy: %d Turn: %d Live: %f' % (i+1, busyCounter, turnCounter, liveFrac)
321 
322  return liveVec
323 

◆ unpackRun1BCIDMask()

def python.LumiBlobConversion.unpackRun1BCIDMask (   blob,
  nb1,
  nb2,
  nlumi 
)

Definition at line 139 of file LumiBlobConversion.py.

139 def unpackRun1BCIDMask(blob,nb1,nb2,nlumi):
140  beam1=[]
141  beam2=[]
142  coll=[]
143  blobCopy = blob.read()
144  beam1 = bConvertList(blobCopy, 2, nb1)
145  beam2 = bConvertList(blobCopy[2*nb1:], 2, nb2)
146  coll = bConvertList(blobCopy[2*(nb1+nb2):], 2, nlumi)
147  #unpackfmt = '%dH' % nb1
148  #list(struct.unpack(unpackfmt, blobCopy[0:(2*nb1)]))
149  #unpackfmt = '%dH' % nb2
150  #beam2 = list(struct.unpack(unpackfmt, blobCopy[(2*nb1):2*(nb1+nb2)]))
151  #unpackfmt = '%dH' % nlumi
152  #coll = list(struct.unpack(unpackfmt, blobCopy[2*(nb1+nb2):2*(nb1+nb2+nlumi)]))
153 
154 # blobCounter = 0
155 # for i in range(nb1):
156 # b = blobCopy[blobCounter:blobCounter+2]
157 # blobCounter += 2
158 # val=struct.unpack('H', b)
159 # beam1.append(val)
160 
161 # for i in range(nb2):
162 # b = blobCopy[blobCounter:blobCounter+2]
163 # blobCounter += 2
164 # val=struct.unpack('H', b)
165 # beam2.append(val)
166 
167 # for i in range(nlumi):
168 # b = blobCopy[blobCounter:blobCounter+2]
169 # blobCounter += 2
170 # val=struct.unpack('H', b)
171 # coll.append(val)
172 
173  return beam1,beam2,coll
174 
175 # routine to unpack values (raw lumi or currents) stored as blob in COOL
176 # blob - COOL blob with per-BCID values
177 # mask - BCID mask appropriate for quantity being unpacked (i.e.: beam1, collisions, ...)
178 # normValue - Normalization value from same COOL folder as BLOB (i.e.: B1BunchAverage)
179 #
180 # Note, the normValue is only used in certain storage modes. If you want to renormalize, do this yourself.
181 # Specifying a different value for the normValue will likely cause unpredictable results.
182 

◆ unpackRun2BCIDMask()

def python.LumiBlobConversion.unpackRun2BCIDMask (   blob,
  nb1,
  nb2,
  nlumi 
)

Definition at line 114 of file LumiBlobConversion.py.

114 def unpackRun2BCIDMask(blob,nb1,nb2,nlumi):
115  beam1=[]
116  beam2=[]
117  coll=[]
118  blobCopy = blob.read()
119  rawData = bConvertList(blobCopy, 1, 3564)
120 
121  for i in range(3564):
122  val = rawData[i]
123  if val & 0x01:
124  beam1.append(i)
125  if val & 0x02:
126  beam2.append(i)
127  if (val & 0x03) == 0x03:
128  coll.append(i)
129 
130  print('unpackRun2BCIDMask found:')
131  print(' Beam1:', beam1)
132  print(' Beam2:', beam2)
133  print(' Coll: ', coll)
134 
135  return beam1,beam2,coll
136 
137 # routine to unpack the BCID mask stored in COOL
138 # This is the run1 version

Variable Documentation

◆ pos

python.LumiBlobConversion.pos

Definition at line 18 of file LumiBlobConversion.py.

python.LumiBlobConversion.unpackLiveFraction
def unpackLiveFraction(trigPayload, priority='high')
Definition: LumiBlobConversion.py:271
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.LumiBlobConversion.bConvertList
def bConvertList(b, nbyte=1, nval=1)
Definition: LumiBlobConversion.py:39
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
python.LumiBlobConversion.unpackBunchGroupList
def unpackBunchGroupList(blob, bgrp=[1])
Definition: LumiBlobConversion.py:82
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.LumiBlobConversion.unpackRun2BCIDMask
def unpackRun2BCIDMask(blob, nb1, nb2, nlumi)
Definition: LumiBlobConversion.py:114
python.LumiBlobConversion.unpackBunchGroup
def unpackBunchGroup(blob, bgrp=1)
Definition: LumiBlobConversion.py:53
python.LumiBlobConversion.blob_read
def blob_read(self, size=-1)
Definition: LumiBlobConversion.py:12
python.LumiBlobConversion.unpackBunches
def unpackBunches(blob, mask=[])
Definition: LumiBlobConversion.py:207
python.LumiBlobConversion.unpackRun1BCIDMask
def unpackRun1BCIDMask(blob, nb1, nb2, nlumi)
Definition: LumiBlobConversion.py:139
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.LumiBlobConversion.unpackBCIDMask
def unpackBCIDMask(blob, nb1, nb2, nlumi)
Definition: LumiBlobConversion.py:103
python.LumiBlobConversion.unpackBCIDValues
def unpackBCIDValues(blob, mask=[], normValue=1)
Definition: LumiBlobConversion.py:183
python.LumiBlobConversion.bConvert
def bConvert(b, nbyte=1)
Definition: LumiBlobConversion.py:26
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
readCCLHist.float
float
Definition: readCCLHist.py:83