27def main(filename, nrecords, nskip, print_adc_stats, print_wvfm_samples, det, channel_map):
33 with h5py.File(h5_file.get_file_name(),
'r')
as f:
34 run_number = f.attrs[
"run_number"]
35 op_env = f.attrs[
"operational_environment"]
36 print(f
'Processing file {h5_file.get_file_name()}. run_number={run_number}, operational_environemnt={op_env}')
39 openv_channel_map=
None
41 openv_channel_map=
"PD2HDTPCChannelMap"
42 elif op_env==
"np04hdcoldbox":
43 openv_channel_map=
"HDColdboxTPCChannelMap"
44 elif op_env==
"iceberghd" or op_env==
"iceberg" or op_env==
"icebergvd":
45 openv_channel_map=
"ICEBERGChannelMap"
46 elif op_env==
"np02vd":
47 openv_channel_map=
"PD2VDTPCChannelMap"
49 print(f
'Unknown operational_environment ({op_env}). Will use specified channel-map {channel_map}')
50 openv_channel_map=channel_map
52 if openv_channel_map!=channel_map
and channel_map
is not None:
53 print(f
'Operational environment {op_env} suggests channel map {openv_channel_map}, not {channel_map}.')
54 print(f
'Please correct (or do not specify channel map and use operational environment to select). Exiting...')
57 channel_map=openv_channel_map
58 print(f
'Using channel_map={channel_map}')
61 records = h5_file.get_all_record_ids()
64 if nskip > len(records):
65 print(f
'Requested records to skip {nskip} is greater than number of records {len(records)}. Exiting...')
68 if (nskip+nrecords)>len(records):
71 nrecords=nskip+nrecords
72 records_to_process = []
74 records_to_process = records[nskip:]
76 records_to_process = records[nskip:nrecords]
77 print(f
'Will process {len(records_to_process)} of {len(records)} records.')
80 for r
in records_to_process:
83 record_index =
RecordDataBase(run=run_number,trigger=r[0],sequence=r[1])
84 print(f
'Processing ',record_index)
87 trh = h5_file.get_trh(record_index.trigger,record_index.sequence)
88 n_frags = len(h5_file.get_fragment_dataset_paths(record_index.trigger,record_index.sequence))
96 geo_ids = h5_file.get_geo_ids_for_subdetector(r,detdataformats.DetID.string_to_subdetector(det_type))
102 det_stream = 0xffff & (gid >> 48);
103 det_slot = 0xffff & (gid >> 32);
104 det_crate = 0xffff & (gid >> 16);
105 det_id = 0xffff & gid;
106 subdet = detdataformats.DetID.Subdetector(det_id)
107 det_name = detdataformats.DetID.subdetector_to_string(subdet)
108 print(f
'\tProcessing subdetector {det_name}, '
109 f
'crate {det_crate}, '
111 f
'stream {det_stream}')
114 frag = h5_file.get_frag(r,gid)
117 frag_header = unpacker.get_frh_data(frag)[0]
118 print(
'\t',frag_header)
121 frag_type = frag.get_fragment_type()
122 if frag_type==daqdataformats.FragmentType.kWIBEth:
124 elif frag_type==daqdataformats.FragmentType.kTDEEth:
127 print(f
'\tUnknown fragment type {frag_type}. Continuing...')
130 n_frames = unpacker.get_n_obj(frag)
131 print(f
'Found {n_frames} frames in this fragment.')
135 daq_header_data = unpacker.get_daq_header_data(frag)
136 det_header_data = unpacker.get_det_header_data(frag)
138 for i_deth, deth
in enumerate(det_header_data):
139 print(f
'\t',daq_header_data[i_deth])
142 det_ana_data, det_wvfm_data = unpacker.get_det_data_all(frag)
145 for det_ana
in det_ana_data:
147 print(
'\t\t',det_ana)
149 if print_wvfm_samples:
150 for det_wvfm
in det_wvfm_data:
151 print(f
'\t\tChannel {det_wvfm.channel} waveform:')
152 for i_sample
in range(print_wvfm_samples):
153 ts_str = np.format_float_positional(det_wvfm.timestamps[i_sample])
154 print(f
'\t\t\t {i_sample:>5}: ts={ts_str:<25} val={det_wvfm.adcs[i_sample]}')
159 print(f
'Processed all requested records')