23def main(filenames, nrecords, nskip, channel_map):
25 for filename
in filenames:
29 records = h5_file.get_all_record_ids()
31 if nskip > len(records):
32 print(f
'Requested records to skip {nskip} is greater than number of records {len(records)}. Exiting...')
35 if (nskip+nrecords)>len(records):
38 nrecords=nskip+nrecords
40 records_to_process = []
42 records_to_process = records[nskip:]
44 records_to_process = records[nskip:nrecords]
45 print(f
'Will process {len(records_to_process)} of {len(records)} records.')
50 if channel_map
is not None:
51 if 'TPC' in channel_map:
52 ch_map = detchannelmaps.make_tpc_map(channel_map)
53 elif 'PDS' in channel_map:
54 ch_map = detchannelmaps.make_pds_map(channel_map)
56 with h5py.File(h5_file.get_file_name(),
'r')
as f:
57 record_type = f.attrs[
"record_type"]
58 print(f
'Record type is {record_type}')
60 for r
in records_to_process:
62 print(f
'Processing (Record Number,Sequence Number)=({r[0],r[1]})')
64 src_ids = h5_file.get_source_ids(r)
67 if(sid.subsystem!=daqdataformats.SourceID.Subsystem.kTrigger):
continue
69 frag = h5_file.get_frag(r,sid)
70 if(frag.get_fragment_type()!=daqdataformats.FragmentType.kTriggerPrimitive):
continue
72 print(f
'Fragment (run,trigger,sequence)=({frag.get_run_number()},{frag.get_trigger_number()},{frag.get_sequence_number()})')
74 n_tps = int(frag.get_data_size() / trgdataformats.TriggerPrimitive.sizeof())
76 print(f
'Found {n_tps} TPs in fragment.')
78 for i
in range(n_tps):
79 tp = trgdataformats.TriggerPrimitive(frag.get_data(i*trgdataformats.TriggerPrimitive.sizeof()))
80 if tp.version != trgdataformats.TriggerPrimitive.s_trigger_primitive_version:
81 sys.exit(f
"ERROR: the TP data structure version found in the data ({tp.version}) does not match the version expected by this version of the software ({trgdataformats.TriggerPrimitive.s_trigger_primitive_version}). Please use a version of the software that matches the data.")
85 if ch_map
is not None and (tp.detid==3
or tp.detid==10):
86 plane=ch_map.get_plane_from_offline_channel(tp.channel)
87 apa=ch_map.get_tpc_element_from_offline_channel(tp.channel)
90 trigger=frag.get_trigger_number(),
91 sequence=frag.get_sequence_number(),
92 src_id=frag.get_element_id().id,
93 time_start=tp.time_start,
94 samples_to_peak=tp.samples_to_peak,
95 samples_over_threshold=tp.samples_over_threshold,
99 adc_integral=tp.adc_integral,
100 adc_peak=tp.adc_peak,
109 print(f
'Processed all requested records')