5 from __future__
import print_function
7 import libpyevent_storage
as EventStorage
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")
20 print(
" -n <number of events per file> : defaults to 500")
21 print(
" -v : verbose output")
25 opts, args = getopt.getopt(sys.argv[1:],
"vn:")
33 eventsPerFile=
int(arg)
43 dr=EventStorage.pickDataReader(files[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)
53 for input_file
in files:
55 print(
"Opening file %d: %s" % (ifile, input_file))
57 input = eformat.istream([input_file])
61 print(
"Reading event with Lvl1 Id = %ld and rewritting with %ld" % (event.lvl1_id(),id))
62 new_event = eformat.write.FullEventFragment(event)
64 new_event.global_id(id)
65 for rob
in new_event.children():
68 rob.rod_lvl1_trigger_type(event.lvl1_trigger_type())
70 output.write(new_event)
74 print(
'Wrote %d events to %d files' % ( id-1, 1+((id-1)//eventsPerFile) ))