ATLAS Offline Software
trigbs_findevent.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 """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('-t', '--time', action=StoreTime, nargs='*',
41  help='Nanosecond time stamp (seconds:nanoseconds)')
42 
43  parser.add_argument('-s', '--save', metavar='OUTFILE', nargs='?', action='store', const='trigbs_findevent',
44  help='Save selected events in OUTFILE')
45 
46  parser.add_argument('-v', '--verbose', action='store_true',
47  help='Be verbose')
48 
49  args = parser.parse_args()
50 
51  ofs = None
52  if args.save is not None:
53  ofs = eformat.ostream(core_name=args.save)
54 
55  for f in args.file:
56  ifs = eformat.istream(f)
57  if args.verbose:
58  print('==%s' % f)
59  for e in ifs:
60  found = True
61  if args.globalid is not None and e.global_id() not in args.globalid:
62  found = False
63  if args.lvl1id is not None and e.lvl1_id() not in args.lvl1id:
64  found = False
65  if args.time is not None and (e.bc_time_seconds(),e.bc_time_nanoseconds()) not in args.time:
66  found = False
67  if found:
68  print('%s %s' % (f,fmtEvent(e,args.time is not None)))
69  if ofs:
70  ofs.write(e)
71 
72 if __name__ == '__main__':
73  try:
74  sys.exit(main())
75  except KeyboardInterrupt:
76  sys.exit(1)
trigbs_findevent.fmtEvent
def fmtEvent(e, showTime=False)
Definition: trigbs_findevent.py:16
trigbs_findevent.StoreTime
Definition: trigbs_findevent.py:23
trigbs_findevent.main
def main()
Definition: trigbs_findevent.py:28
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
trigbs_findevent.StoreTime.__call__
def __call__(self, parser, namespace, values, option_string=None)
Definition: trigbs_findevent.py:24