57 args = get_parser().parse_args()
58 logging.basicConfig(stream=sys.stdout,
59 format='%(levelname)-8s %(message)s',
60 level=logging.DEBUG if args.verbose else logging.INFO)
61
62 filenames = get_filenames(args.dirs)
63 logging.info('Merging %d files', len(filenames))
64 logging.info('filenames: %s', filenames)
65
66 ievt = 1
67 dr = EventStorage.pickDataReader(filenames[0])
68 output = eformat.ostream(core_name=args.outBaseName,
69 run_number=dr.runNumber(),
70 trigger_type=dr.triggerType(),
71 detector_mask=dr.detectorMask(),
72 beam_type=dr.beamType(),
73 beam_energy=dr.beamEnergy())
74 output.max_events_per_file(args.nepfOutput)
75
76 for ifile, input_file in enumerate(filenames):
77 logging.info("Opening file %d: %s", ifile+1, input_file)
78 inputFile = eformat.istream([input_file])
79
80 for ievt_in_file, event in enumerate(inputFile):
81 if args.nepfInput > 0 and ievt_in_file >= args.nepfInput:
82 break
83 logging.debug("Reading event with Lvl1 Id = %ld", event.lvl1_id())
84 new_event = eformat.write.FullEventFragment(event)
85 if args.renumber:
86 logging.debug("Rewriting the event with Lvl1 Id = %ld", ievt)
87 new_event.lvl1_id(ievt)
88 new_event.global_id(ievt)
89 for rob in new_event.children():
90 rob.rod_lvl1_id(ievt)
91 rob.checksum_type(0)
92 rob.rod_lvl1_trigger_type(event.lvl1_trigger_type())
93 else:
94 logging.debug("Rewriting the event with unchanged Lvl1 Id")
95
96 output.write(new_event)
97 ievt += 1
98
99 logging.info('Wrote %d events to %d files', ievt-1, 1+((ievt-2)//args.nepfOutput))
100
101