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