5 Module for creating the rob fragments normally send through the RoIB
6 using the information readout from the ROSs.
7 It can be used either standalone or as a "-Z" plugin to athenaMT/PT.
9 Note that a bunch of information is hardcoded and could change if
10 the data format of the CTP/MUCTPI/L1Calo ROIB fragments change.
12 The payload of the CTP DAQ ROB (0x770000) is as follows:
14 N x CTPdataformat.DAQwordsPerBunch
15 1 x numberExtraPayloadWords
16 This differs from the CTP ROB (0x770001) where only one bunch crossing is saved (N=1).
24 import libpyevent_storage
as EventStorage
25 from TrigByteStreamTools
import CTPfragment
26 from TrigByteStreamTools.CTPfragment
import CTPdataformat
29 """Fills in the L1R from the most appropriate source (L1/ROS or Dummy)."""
31 map=[[eformat.helper.SubDetector.TDAQ_CTP,0,1],
32 [eformat.helper.SubDetector.TDAQ_MUON_CTP_INTERFACE,0,1],
33 [eformat.helper.SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI,136,168],
34 [eformat.helper.SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI,137,169],
35 [eformat.helper.SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI,138,170],
36 [eformat.helper.SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI,139,171],
37 [eformat.helper.SubDetector.TDAQ_CALO_JET_PROC_ROI,140,172],
38 [eformat.helper.SubDetector.TDAQ_CALO_JET_PROC_ROI,141,173]]
40 DaqRobs=[
None]*len(map)
41 L2Robs=[
None]*len(map)
47 if rob.source_id()==eformat.helper.SourceIdentifier(match[0],match[1]):
49 elif rob.source_id()==eformat.helper.SourceIdentifier(match[0],match[2]):
54 if (
not DaqRobs[0])
and (
not L2Robs[0]):
55 logging.warning(
' Plugin "addL1": No DAQ CTP fragment. Event can not be recovered. Event will be skipped. L1 id = %d, Global id = %d ', event.lvl1_id(), event.global_id())
59 new_event=eformat.write.FullEventFragment()
60 new_event.copy_header(event)
62 new_event.append_unchecked(rob)
64 for idx
in range(len(map)):
69 rob=eformat.write.ROBFragment(DaqRobs[idx])
70 rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
72 daq_data = [r
for r
in rob.rod_data()]
76 offset = CTPdataformat.NumberTimeWords + CTPfragment.lvl1AcceptBunch(rob)*CTPdataformat.DAQwordsPerBunch
78 data = daq_data[:CTPdataformat.NumberTimeWords]
80 data += daq_data[offset : offset+CTPdataformat.DAQwordsPerBunch]
82 data += daq_data[-CTPfragment.numberExtraPayloadWords(rob):]
87 if len(DaqRobs[idx].rod_data()) > 0:
88 muctpBC=(DaqRobs[idx].rod_data()[0]>>18)&7
89 for word
in DaqRobs[idx].rod_data()[1:]:
90 if (word>>14)&7==muctpBC
and (word>>26)&1:
91 data+=[(word&0x3fff)|(((word>>17)&0x1ff)<<14)]
94 rob=eformat.write.ROBFragment()
95 rob.copy_header(DaqRobs[idx])
96 rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
100 new_event.append(rob)
102 rob=eformat.write.ROBFragment()
103 rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
104 new_event.append(rob)
106 return new_event.readonly()
109 input = eformat.istream([input_file])
110 dr=EventStorage.pickDataReader(input_file)
111 output = eformat.ostream(core_name=
"subset",
112 run_number=dr.runNumber(),
113 trigger_type=dr.triggerType(),
114 detector_mask=dr.detectorMask(),
115 beam_type=dr.beamType(),
116 beam_energy=dr.beamEnergy())
122 output.write(new_event)
123 tmp_file_name = output.last_filename()
125 os.rename(tmp_file_name,output_file)
129 if __name__ ==
"__main__":
131 print(
'usage: %s <infile> <outfile>' % sys.argv[0])
134 CTPreco(sys.argv[1],sys.argv[2])