28def modify(event):
29 """Fills in the L1R from the most appropriate source (L1/ROS or Dummy)."""
30
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]]
39
40 DaqRobs=[None]*len(map)
41 L2Robs=[None]*len(map)
42
43
44 for rob in event:
45 cnt=0
46 for match in map:
47 if rob.source_id()==eformat.helper.SourceIdentifier(match[0],match[1]):
48 DaqRobs[cnt]=rob
49 elif rob.source_id()==eformat.helper.SourceIdentifier(match[0],match[2]):
50 L2Robs[cnt]=rob
51 cnt+=1
52
53
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())
56 return False
57
58
59 new_event=eformat.write.FullEventFragment()
60 new_event.copy_header(event)
61 for rob in event:
62 new_event.append_unchecked(rob)
63
64 for idx in range(len(map)):
65 if L2Robs[idx]:
66 pass
67 elif DaqRobs[idx]:
68
69 rob=eformat.write.ROBFragment(DaqRobs[idx])
70 rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
71
72 daq_data = [r for r in rob.rod_data()]
73
74 if idx==0:
75
76 offset = CTPdataformat.NumberTimeWords + CTPfragment.lvl1AcceptBunch(rob)*CTPdataformat.DAQwordsPerBunch
77
78 data = daq_data[:CTPdataformat.NumberTimeWords]
79
80 data += daq_data[offset : offset+CTPdataformat.DAQwordsPerBunch]
81
82 data += daq_data[-CTPfragment.numberExtraPayloadWords(rob):]
83 rob.rod_data(data)
84
85 elif idx==1:
86 data=[]
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)]
92
93 if len(data)==0:
94 rob=eformat.write.ROBFragment()
95 rob.copy_header(DaqRobs[idx])
96 rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
97 else:
98 rob.rod_data(data)
99
100 new_event.append(rob)
101 else:
102 rob=eformat.write.ROBFragment()
103 rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
104 new_event.append(rob)
105
106 return new_event.readonly()
107