ATLAS Offline Software
Loading...
Searching...
No Matches
python.LumiBlobConversion Namespace Reference

Functions

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

Variables

 read
 pos = endpos

Function Documentation

◆ bConvert()

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

Definition at line 24 of file LumiBlobConversion.py.

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

◆ bConvertList()

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

Definition at line 37 of file LumiBlobConversion.py.

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

◆ blob_read()

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

Definition at line 10 of file LumiBlobConversion.py.

10def blob_read(self, size = -1):
11 if size < 0:
12 endpos = self.size()
13 else:
14 endpos = self.pos + size
15 beginpos = self.pos
16 self.pos = endpos
17 buf = self.startingAddress()
18 buf.SetSize(self.size())
19 return buf[beginpos:endpos]
20
21# add the new functions

◆ unpackBCIDMask()

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

Definition at line 101 of file LumiBlobConversion.py.

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

◆ unpackBCIDValues()

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

Definition at line 181 of file LumiBlobConversion.py.

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

◆ unpackBunches()

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

Definition at line 205 of file LumiBlobConversion.py.

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

◆ unpackBunchGroup()

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

Definition at line 51 of file LumiBlobConversion.py.

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

◆ unpackBunchGroupList()

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

Definition at line 80 of file LumiBlobConversion.py.

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

◆ unpackLiveFraction()

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

Definition at line 269 of file LumiBlobConversion.py.

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

◆ unpackRun1BCIDMask()

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

Definition at line 137 of file LumiBlobConversion.py.

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

◆ unpackRun2BCIDMask()

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

Definition at line 112 of file LumiBlobConversion.py.

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

Variable Documentation

◆ pos

python.LumiBlobConversion.pos = endpos

Definition at line 16 of file LumiBlobConversion.py.

◆ read

python.LumiBlobConversion.read

Definition at line 22 of file LumiBlobConversion.py.