ATLAS Offline Software
unpickEI_SPB.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 #
5 
6 import sys
7 import argparse
8 
9 from EventIndexProducer.EIPBof import EIPBof
10 from EventIndexProducer.compressB64 import _fromB64
11 from EventIndexProducer.spbfile import SpbFile
12 import EventIndexProducer.EIconstants as eic
13 
14 
15 def options(argv):
16 
17  parser = argparse.ArgumentParser(description='Unpick Event Index File')
18  parser.add_argument('-e', '--evtnumber',
19  default=0,
20  type=int,
21  help='event number to dump')
22  parser.add_argument('-r', '--runnumber',
23  default=0,
24  type=int,
25  help='run number to dump')
26  parser.add_argument('-m', '--evtmax',
27  default=1,
28  type=int,
29  help='Max number of events to dump')
30  parser.add_argument('--decodeL1trig',
31  action='count',
32  help='decode L1 trigger')
33  parser.add_argument('--decodeL1trig0',
34  action='count',
35  help='decode L1 trigger, remove redundancies')
36  parser.add_argument('--decodeL2trig',
37  action='count',
38  help='decode L2 trigger')
39  parser.add_argument('--decodeEFtrig',
40  action='count',
41  help='decode EF trigger')
42  parser.add_argument('--decodetrig',
43  action='count',
44  help='decode ALL triggers')
45  parser.add_argument('eispbfile',
46  help="EventIndex SPB file")
47 
48  return parser.parse_args()
49 
50 
52 
53  tl = []
54  idx = 0
55  count = ""
56  for k in range(0, len(s)):
57  c = s[k]
58  if c == "!":
59  if len(count) > 0:
60  idx += _fromB64(count)
61  count = ""
62  tl.append(idx)
63  idx += 1
64  else:
65  count += c
66 
67  if (len(count) > 0):
68  idx += _fromB64(count)
69 
70  return (idx, tl)
71 
72 
74 
75  TAV = []
76  TAP = []
77  TBP = []
78 
79  (nbits, tl) = getTriggerList(s)
80  trigLen = nbits // 3
81 
82  for pos in tl:
83  if (pos >= 2*trigLen):
84  TAV.append(pos-2*trigLen)
85  elif (pos >= trigLen):
86  TAP.append(pos-trigLen)
87  else:
88  TBP.append(pos)
89 
90  l1tl = {'TAV': TAV, 'TAP': TAP, 'TBP': TBP}
91 
92  return l1tl
93 
94 
95 def dumpEvent(evt, opt):
96 
97  # similar to print(evt)
98  # just to avoid format changes in protobuf printing
99  # optional fields are checked for existence
100 
101  print('======================================================')
102  print('> eventPB')
103  print('runNumber:', evt.runNumber)
104  print('eventNumber:', evt.eventNumber)
105  print('lumiBlock:', evt.lumiBlock)
106  print('timeStamp:', evt.timeStamp)
107  print('timeStampNSOffset:', evt.timeStampNSOffset)
108  print('bcid:', evt.bcid)
109  if evt.HasField("extendedLevel1ID"):
110  print('extendedLevel1ID:', evt.extendedLevel1ID)
111  print('isSimulation: {}'.format('true' if evt.isSimulation else 'false'))
112  print('isCalibration: {}'.format('true' if evt.isCalibration else 'false'))
113  print('isTestBeam: {}'.format('true' if evt.isTestBeam else 'false'))
114  if evt.HasField("L1PassedTrigMask"):
115  print('L1PassedTrigMask: "{}"'.format(evt.L1PassedTrigMask))
116  if evt.HasField("L2PassedTrigMask"):
117  print('L2PassedTrigMask: "{}"'.format(evt.L2PassedTrigMask))
118  if evt.HasField("EFPassedTrigMask"):
119  print('EFPassedTrigMask: "{}"'.format(evt.EFPassedTrigMask))
120  if evt.HasField("SMK"):
121  print('SMK:', evt.SMK)
122  if evt.HasField("HLTPSK"):
123  print('HLTPSK:', evt.HLTPSK)
124  if evt.HasField("L1PSK"):
125  print('L1PSK:', evt.L1PSK)
126  if evt.HasField("mcEventWeight"):
127  print('mcEventWeight:', evt.mcEventWeight)
128  if evt.HasField("mcChannelNumber"):
129  print('mcChannelNumber:', evt.mcChannelNumber)
130  for tk in evt.eitoken:
131  print('eitoken {')
132  print(' name: "{}"'.format(tk.name))
133  print(' token: "{}"'.format(tk.token))
134  print('}')
135  print()
136 
137  if opt.decodeL1trig and evt.HasField("L1PassedTrigMask"):
138  L1mask = evt.L1PassedTrigMask
139  L1 = getL1TriggerList(L1mask)
140 
141  print('TBP: ', L1['TBP'])
142  print('TAP: ', L1['TAP'])
143  print('TAV: ', L1['TAV'])
144 
145  if opt.decodeL1trig0 and evt.HasField("L1PassedTrigMask"):
146  L1mask = evt.L1PassedTrigMask
147  L1 = getL1TriggerList(L1mask)
148 
149  TAV2 = L1['TAV']
150  TAP2 = [k for k in L1['TAP'] if k not in L1['TAV']]
151  TBP2 = [k for k in L1['TBP'] if k not in L1['TAP']]
152 
153  print('TBP*: ', TBP2)
154  print('TAP*: ', TAP2)
155  print('TAV*: ', TAV2)
156 
157  if opt.decodeL2trig and evt.HasField("L2PassedTrigMask"):
158  L2mask = evt.L2PassedTrigMask
159  if ';' in L2mask:
160  L2mask = L2mask.split(';')
161  L2 = {}
162  nb, L2['PH'] = getTriggerList(L2mask[0])
163  nb, L2['PT'] = getTriggerList(L2mask[1])
164  nb, L2['RS'] = getTriggerList(L2mask[2])
165 
166  print('L2_PH: ', L2['PH'])
167  print('L2_PT: ', L2['PT'])
168  print('L2_RS: ', L2['RS'])
169  else:
170  nb, L2 = getTriggerList(L2mask)
171  print('L2: ', L2)
172 
173  if opt.decodeEFtrig and evt.HasField("EFPassedTrigMask"):
174  EFmask = evt.EFPassedTrigMask
175  if ';' in EFmask:
176  HLTmask = EFmask.split(';')
177  HLT = {}
178  nb, HLT['PH'] = getTriggerList(HLTmask[0])
179  nb, HLT['PT'] = getTriggerList(HLTmask[1])
180  nb, HLT['RS'] = getTriggerList(HLTmask[2])
181 
182  print('PH: ', HLT['PH'])
183  print('PT: ', HLT['PT'])
184  print('RS: ', HLT['RS'])
185  else:
186  nb, HLT = getTriggerList(EFmask)
187  print('HLT: ', HLT)
188 
189 
190 def main():
191 
192  # analyze options
193  opt = options(sys.argv)
194  if opt.decodetrig:
195  opt.decodeL1trig = True
196  opt.decodeL2trig = True
197  opt.decodeEFtrig = True
198 
199  fname = opt.eispbfile
200  try:
201  spbf = SpbFile(fname)
202  info = spbf.getInfo()
203  except Exception as e:
204  print("Error reading SPB file. Please check file: " + str(e))
205  sys.exit(1)
206 
207  print("")
208  print(" version: ", info['version'])
209  print(" #input files: ", info['nfiles'])
210  print(" number of events: ", info['nevents'])
211  print(" StartProcTime: ", info['startProcTime'])
212  print(" EndProcTime: ", info['endProcTime'])
213  print(" TaskID: ", info['taskID'])
214  print(" JobID: ", info['jobID'])
215  print(" InputDsName: ", info['inputDsName'])
216  print(" Includes Provenance: ", info['provenanceRef'])
217  print(" Includes Trigger: ", info['triggerInfo'])
218 
219  for f in info['guids']:
220  print("")
221  print("File {:d}".format(f['fileno']))
222  print(" Events in this file: {:8d}".format(f['nevents']))
223  print(" Unique events in this file: {:8d}".format(f['nuevents']))
224  print(" StartProcTime: {:13d}".format(
225  f['fileStartProcTime']))
226  print(" EndProcTime: {:13d}".format(
227  f['fileEndProcTime']))
228  print(" AMITag: {}".format(f['AMITag']))
229  print(" TrigStream: {}".format(f['trigStream']))
230  print(" ProjName: {}".format(f['projName']))
231  print(" RunEvtRanges: {}".format(f['runevtRanges']))
232  print(" GUID: {}".format(f['guid']))
233 
234  eipbof = EIPBof(spbf.getVersion())
235 
236  print("")
237  print("Summary: (info for {:d} events max)".format(opt.evtmax))
238  print("")
239 
240  nevt_shown = 0
241  while True:
242  (mtype_ver, mlen, msg) = spbf.getMsg()
243  mtype = (mtype_ver & 0x000fff00) >> 8
244  if mtype == eic.EI_PROTO_HEADER:
245  header = eipbof.Header()
246  header.ParseFromString(msg)
247  elif mtype == eic.EI_PROTO_BEGINGUID:
248  beginGUID = eipbof.BeginGUID()
249  beginGUID.ParseFromString(msg)
250  elif mtype == eic.EI_PROTO_ENDGUID:
251  endGUID = eipbof.EndGUID()
252  endGUID.ParseFromString(msg)
253  elif mtype == eic.EI_PROTO_EIEVENT:
254  eventPB = eipbof.EIEvent()
255  eventPB.ParseFromString(msg)
256  if nevt_shown < opt.evtmax:
257  if (opt.evtnumber != 0 and
258  opt.evtnumber != eventPB.eventNumber):
259  continue
260  if (opt.runnumber != 0 and
261  opt.runnumber != eventPB.runNumber):
262  continue
263  dumpEvent(eventPB, opt)
264  nevt_shown += 1
265  else:
266  break
267  elif mtype == eic.EI_PROTO_TRIGGERMENU:
268  triggerMenu = eipbof.TriggerMenu()
269  triggerMenu.ParseFromString(msg)
270  elif mtype == eic.EI_PROTO_TRAILER:
271  trailer = eipbof.Trailer()
272  trailer.ParseFromString(msg)
273  break
274  else:
275  print(mtype)
276  break
277 
278  spbf.close()
279 
280 
281 if __name__ == '__main__':
282  main()
unpickEI_SPB.main
def main()
Definition: unpickEI_SPB.py:190
vtune_athena.format
format
Definition: vtune_athena.py:14
unpickEI_SPB.getL1TriggerList
def getL1TriggerList(s)
Definition: unpickEI_SPB.py:73
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
unpickEI_SPB.options
def options(argv)
Definition: unpickEI_SPB.py:15
unpickEI_SPB.getTriggerList
def getTriggerList(s)
Definition: unpickEI_SPB.py:51
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
unpickEI_SPB.dumpEvent
def dumpEvent(evt, opt)
Definition: unpickEI_SPB.py:95
python.compressB64._fromB64
def _fromB64(s)
Definition: compressB64.py:21