ATLAS Offline Software
trigbs_findevent.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 """Find event in FILE(s).
5 
6 If no event identifier(s) are specified on the command line all events are printed.
7 In addition one can save the selected events into a new file.
8 """
9 
10 __author__ = "Frank Winklmeier"
11 
12 import sys
13 import argparse
14 import eformat
15 
16 def fmtEvent(e,showTime=False):
17  if showTime:
18  time = ' time=%d:%d' % (e.bc_time_seconds(),e.bc_time_nanoseconds())
19  else:
20  time = ''
21  return '[run=%d lb=%d l1id=%d gid=%d%s]' % (e.run_no(),e.lumi_block(),e.lvl1_id(),e.global_id(),time)
22 
23 class StoreTime(argparse.Action):
24  def __call__(self, parser, namespace, values, option_string=None):
25  times = [tuple(map(int,v.split(':',1))) for v in values]
26  setattr(namespace, self.dest, times)
27 
28 def main():
29  parser = argparse.ArgumentParser(description=__doc__)
30 
31  parser.add_argument('-f', '--file', metavar='FILE', nargs='*', default=[],
32  help='file name')
33 
34  parser.add_argument('-g', '--globalid', type=int, action='store', nargs='*',
35  help='Global event ID')
36 
37  parser.add_argument('-l', '--lvl1id', type=int, action='store', nargs='*',
38  help='LVL1 ID')
39 
40  parser.add_argument('--lb', type=int, action='store', nargs='*',
41  help='Lumiblock')
42 
43  parser.add_argument('-t', '--time', action=StoreTime, nargs='*',
44  help='Nanosecond time stamp (seconds:nanoseconds)')
45 
46  parser.add_argument('-s', '--save', metavar='OUTFILE', nargs='?', action='store', const='trigbs_findevent',
47  help='Save selected events in OUTFILE')
48 
49  parser.add_argument('-v', '--verbose', action='store_true',
50  help='Be verbose')
51 
52  args = parser.parse_args()
53 
54  ofs = None
55  if args.save is not None:
56  ofs = eformat.ostream(core_name=args.save)
57 
58  for f in args.file:
59  ifs = eformat.istream(f)
60  if args.verbose:
61  print('==%s' % f)
62  for e in ifs:
63  found = True
64  if args.globalid is not None and e.global_id() not in args.globalid:
65  found = False
66  if args.lvl1id is not None and e.lvl1_id() not in args.lvl1id:
67  found = False
68  if args.lb is not None and e.lumi_block() not in args.lb:
69  found = False
70  if args.time is not None and (e.bc_time_seconds(),e.bc_time_nanoseconds()) not in args.time:
71  found = False
72  if found:
73  print('%s %s' % (f,fmtEvent(e,args.time is not None)))
74  if ofs:
75  ofs.write(e)
76 
77 if __name__ == '__main__':
78  try:
79  sys.exit(main())
80  except KeyboardInterrupt:
81  sys.exit(1)
trigbs_findevent.fmtEvent
def fmtEvent(e, showTime=False)
Definition: trigbs_findevent.py:16
trigbs_findevent.StoreTime
Definition: trigbs_findevent.py:23
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
trigbs_findevent.main
def main()
Definition: trigbs_findevent.py:28
trigbs_findevent.StoreTime.__call__
def __call__(self, parser, namespace, values, option_string=None)
Definition: trigbs_findevent.py:24