ATLAS Offline Software
trigbs_mixBSevents.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
4 
5 from __future__ import print_function
6 import eformat
7 import libpyevent_storage as EventStorage
8 import sys
9 import getopt
10 
11 eventsPerFile=500
12 verbose=False
13 
14 def usage():
15  print(" usage: %s [options] <outbasename> <file1> <file2> <file3>" % sys.argv[0])
16  print(" Rewrites events with event ids numbered consequtively from 1")
17  print(" This is mainly used for preparing events from playback partition")
18  print()
19  print(" Options:")
20  print(" -n <number of events per file> : defaults to 500")
21  print(" -v : verbose output")
22  sys.exit(1)
23 
24 try:
25  opts, args = getopt.getopt(sys.argv[1:], "vn:")
26  if len(args)<2:
27  usage()
28 except getopt:
29  usage()
30 
31 for opt,arg in opts:
32  if opt == '-n':
33  eventsPerFile=int(arg)
34  if opt == '-v':
35  verbose=True
36 
37 basename=args[0]
38 files = args[1:]
39 
40 ifile = 0
41 id = 1
42 outnum=1
43 dr=EventStorage.pickDataReader(files[0])
44 numFiles=0
45 output = eformat.ostream(core_name=basename,
46  run_number=dr.runNumber(),
47  trigger_type=dr.triggerType(),
48  detector_mask=dr.detectorMask(),
49  beam_type=dr.beamType(),
50  beam_energy=dr.beamEnergy())
51 output.max_events_per_file(eventsPerFile)
52 
53 for input_file in files:
54  ifile += 1
55  print("Opening file %d: %s" % (ifile, input_file))
56 
57  input = eformat.istream([input_file])
58 
59  for event in input:
60  if verbose:
61  print("Reading event with Lvl1 Id = %ld and rewritting with %ld" % (event.lvl1_id(),id))
62  new_event = eformat.write.FullEventFragment(event)
63  new_event.lvl1_id(id)
64  new_event.global_id(id)
65  for rob in new_event.children():
66  rob.rod_lvl1_id(id)
67  rob.checksum_type(0) #remove checksum
68  rob.rod_lvl1_trigger_type(event.lvl1_trigger_type())
69 
70  output.write(new_event)
71 
72  id+=1
73 
74 print('Wrote %d events to %d files' % ( id-1, 1+((id-1)//eventsPerFile) ))
trigbs_mixBSevents.usage
def usage()
Definition: trigbs_mixBSevents.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25