75 logging.basicConfig(stream=sys.stdout,
76 format=
'%(levelname)-8s %(message)s',
77 level=logging.DEBUG
if args.verbose
else logging.INFO)
80 logging.info(
'Reading events from %s and metadata from %s', args.file, args.copyFrom)
82 logging.info(
'Reading events and metadata from %s', args.file)
83 meta_input = args.copyFrom
if args.copyFrom
else args.file
84 reader = EventStorage.pickDataReader(meta_input)
85 input_stream = eformat.istream(args.file)
90 metadata_basic[
'runNumber'] = reader.runNumber()
91 metadata_basic[
'triggerType'] = reader.triggerType()
92 metadata_basic[
'detectorMask'] = reader.detectorMask()
93 metadata_basic[
'beamType'] = reader.beamType()
94 metadata_basic[
'beamEnergy'] = reader.beamEnergy()
95 metadata_extra[
'Stream'] = reader.stream()
96 metadata_extra[
'Project'] = reader.projectTag()
97 metadata_extra[
'LumiBlock'] = reader.lumiblockNumber()
99 logging.debug(
'Input metadata_basic = %s', metadata_basic)
100 logging.debug(
'Input metadata_extra = %s', metadata_extra)
104 metadata_basic[
'runNumber'] = args.runNumber
106 metadata_basic[
'triggerType'] = args.triggerType
107 if args.detectorMask:
108 metadata_basic[
'detectorMask'] = args.detectorMask
110 metadata_basic[
'beamType'] = beam_type_dict[args.beamType]
112 metadata_basic[
'beamEnergy'] = args.beamEnergy
114 metadata_extra[
'Stream'] = args.stream
116 metadata_extra[
'Project'] = args.projectTag
118 metadata_extra[
'LumiBlock'] = args.lumiBlock
120 logging.debug(
'Updated metadata_basic = %s', metadata_basic)
121 logging.debug(
'Updated metadata_extra = %s', metadata_extra)
124 file_name_base = args.outputName
125 if not file_name_base:
127 ptag = metadata_extra[
'Project']
128 runno = metadata_basic[
'runNumber']
129 stream = metadata_extra[
'Stream']
130 lbn = metadata_extra[
'LumiBlock']
133 file_name_list.append(ptag
if ptag
else 'data')
134 file_name_list.append(
'{:08d}'.
format(runno
if runno
else 0))
135 file_name_list.append(stream
if stream
else 'unknown_stream')
136 file_name_list.append(
'lb{:04d}'.
format(lbn
if lbn
else 0))
137 file_name_base =
'.'.
join(file_name_list)
140 metadata_extra_strings = [
'{:s}={:s}'.
format(k,
str(v))
for k, v
in six.iteritems(metadata_extra)]
141 output_stream = eformat.ostream(
142 core_name = file_name_base,
143 run_number = metadata_basic[
'runNumber'],
144 trigger_type = metadata_basic[
'triggerType'],
145 detector_mask = metadata_basic[
'detectorMask'],
146 beam_type = metadata_basic[
'beamType'],
147 beam_energy = metadata_basic[
'beamEnergy'],
148 meta_data_strings = metadata_extra_strings)
150 logging.info(
'Writing file %s', output_stream.current_filename().
replace(
'.writing',
'.data'))
153 nmax = args.numEvents
or -1
154 for event
in input_stream:
156 if nmax >= 0
and ievt > nmax:
158 logging.debug(
'Writing event %d', ievt)
159 output_stream.write(event)