ATLAS Offline Software
Loading...
Searching...
No Matches
TrigT1ResultByteStreamConfig.py
Go to the documentation of this file.
2# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3#
4from AthenaCommon.Logging import logging
5from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6from AthenaConfiguration.ComponentFactory import CompFactory
7from TrigEDMConfig.TriggerEDM import recordable
8from TrigEDMConfig.Utils import getEDMListFromWriteHandles
9from libpyeformat_helper import SourceIdentifier, SubDetector
10
11from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig import eFexByteStreamToolCfg, jFexRoiByteStreamToolCfg, jFexInputByteStreamToolCfg, gFexByteStreamToolCfg, gFexInputByteStreamToolCfg
12from L1TopoByteStream.L1TopoByteStreamConfig import L1TopoPhase1ByteStreamToolCfg
13from TrigT1MuonRecRoiTool.TrigT1MuonRecRoiToolConfig import RPCRecRoiToolCfg, TGCRecRoiToolCfg
14from TrigT1MuctpiPhase1.TrigT1MuctpiPhase1Config import TrigThresholdDecisionToolCfg
15
16_log = logging.getLogger('TrigT1ResultByteStreamConfig')
17
18def RoIBResultByteStreamToolCfg(flags, name, writeBS=False):
19 acc = ComponentAccumulator()
20 tool = CompFactory.RoIBResultByteStreamTool(name)
21
22 if not flags.Trigger.L1.doCTP or flags.Trigger.CTP.UseEDMxAOD:
23 # disable CTP ByteStream decoding/encoding as part of RoIBResult if doCTP is disabled or if CTPResultByteStreamTool is used instead
24 tool.CTPModuleId = 0xFF
25
26 if flags.Trigger.enableL1MuonPhase1 or not flags.Trigger.L1.doMuon:
27 # disable legacy MUCTPI ByteStream decoding/encoding as part of RoIBResult
28 tool.MUCTPIModuleId = 0xFF
29
30 if not flags.Trigger.enableL1CaloLegacy or not flags.Trigger.L1.doCalo:
31 # disable legacy L1Calo ByteStream decoding/encoding as part of RoIBResult
32 tool.JetModuleIds = []
33 tool.EMModuleIds = []
34
35 if flags.Trigger.EDMVersion == 1 or not flags.Trigger.L1.doTopo:
36 # disable legacy L1Topo ByteStream decoding/encoding as part of RoIBResult
37 tool.L1TopoModuleIds = []
38
39 if writeBS:
40 # write BS == read RDO
41 tool.RoIBResultReadKey="RoIBResult"
42 tool.RoIBResultWriteKey=""
43 else:
44 # read BS == write RDO
45 tool.RoIBResultReadKey=""
46 tool.RoIBResultWriteKey="RoIBResult"
47
48 acc.setPrivateTools(tool)
49 return acc
50
51def CTPResultByteStreamToolCfg(flags, name, writeBS=False):
52 acc = ComponentAccumulator()
53 tool = CompFactory.CTPResultByteStreamTool(name)
54 ctp_robid = int(SourceIdentifier(SubDetector.TDAQ_CTP, 1)) # 0x770001
55 tool.ROBIDs = [ctp_robid]
56
57 if writeBS:
58 # write BS == read RDO
59 tool.CTPResultReadKey="CTPResult"
60 tool.CTPResultWriteKey=""
61 else:
62 # read BS == write RDO
63 tool.CTPResultReadKey=""
64 tool.CTPResultWriteKey="CTPResult"
65
66 acc.setPrivateTools(tool)
67 return acc
68
69def ExampleL1TriggerByteStreamToolCfg(flags, name, writeBS=False):
70 acc = ComponentAccumulator()
71 tool = CompFactory.ExampleL1TriggerByteStreamTool(name)
72 muctpi_moduleid = 0
73 muctpi_robid = int(SourceIdentifier(SubDetector.TDAQ_MUON_CTP_INTERFACE, muctpi_moduleid))
74 tool.ROBIDs = [muctpi_robid]
75 if writeBS:
76 # write BS == read xAOD
77 tool.MuonRoIContainerReadKey="LVL1MuonRoIs"
78 tool.MuonRoIContainerWriteKey=""
79 tool.L1TopoOutputLocID=""
80 else:
81 # read BS == write xAOD
82 tool.MuonRoIContainerReadKey=""
83 tool.MuonRoIContainerWriteKey=recordable("LVL1MuonRoIs")
84 acc.setPrivateTools(tool)
85 return acc
86
87def MuonRoIByteStreamToolCfg(flags, name, writeBS=False, writeDecodedMuonRoIs=True):
88 acc = ComponentAccumulator()
89 tool = CompFactory.MuonRoIByteStreamTool(name)
90 muctpi_moduleid = 0 # No RoIB in Run 3, we always read the DAQ ROB
91 muctpi_robid = int(SourceIdentifier(SubDetector.TDAQ_MUON_CTP_INTERFACE, muctpi_moduleid)) # 0x760000
92 tool.ROBIDs = [muctpi_robid]
93 tool.DoTopo = flags.Trigger.L1.doMuonTopoInputs
94 tool.WriteDecodedMuonRoIs = writeDecodedMuonRoIs
95
96 from TrigT1ResultByteStream.TrigT1ResultByteStreamMonitoringConfig import L1MuonBSConverterMonitoringCfg
97 tool.MonTool = acc.popToolsAndMerge(L1MuonBSConverterMonitoringCfg(flags, name, writeBS))
98
99 # Build container names for each bunch crossing in the maximum readout window (size 5)
100 containerBaseName = "LVL1MuonRoIs"
101 containerNames = [
102 containerBaseName + "BCm2",
103 containerBaseName + "BCm1",
104 containerBaseName,
105 containerBaseName + "BCp1",
106 containerBaseName + "BCp2",
107 ]
108 topocontainerBaseName = "L1MuCTPItoL1TopoLocationFromMuonRoI"
109 topocontainerNames = [
110 topocontainerBaseName + "-2",
111 topocontainerBaseName + "-1",
112 topocontainerBaseName,
113 topocontainerBaseName + "1",
114 topocontainerBaseName + "2",
115 ]
116 if writeBS:
117 # write BS == read xAOD
118 tool.MuonRoIContainerReadKeys += containerNames
119 else:
120 # read BS == write xAOD
121 tool.MuonRoIContainerWriteKeys += [recordable(c) for c in containerNames]
122 tool.L1TopoOutputLocID += topocontainerNames
123
124 tool.RPCRecRoiTool = acc.popToolsAndMerge(RPCRecRoiToolCfg(flags))
125 tool.TGCRecRoiTool = acc.popToolsAndMerge(TGCRecRoiToolCfg(flags))
126 tool.TrigThresholdDecisionTool = acc.popToolsAndMerge(TrigThresholdDecisionToolCfg(flags))
127
128 acc.setPrivateTools(tool)
129 return acc
130
131def doRoIBResult(flags):
132 '''
133 Helper function returning a logic combination of flags deciding
134 whether the RoIBResult decoding/encoding is required in the job
135 '''
136 if flags.Trigger.L1.doCalo and flags.Trigger.enableL1CaloLegacy:
137 # Only needed for legacy (Run-2) L1Calo system
138 return True
139 if flags.Trigger.L1.doMuon and not flags.Trigger.enableL1MuonPhase1:
140 # Only needed for legacy (Run-2) MUCTPI data
141 return True
142 if flags.Trigger.L1.doTopo:
143 # Currently only RoIBResult path implemented for L1Topo
144 return True
145 if flags.Trigger.L1.doCTP and not flags.Trigger.CTP.UseEDMxAOD:
146 # Currently only RoIBResult path implemented for CTP
147 return True
148 # Otherwise don't need RoIBResult
149 return False
150
151def L1TriggerByteStreamDecoderCfg(flags, returnEDM=False):
152 acc = ComponentAccumulator()
153 decoderTools = []
154 maybeMissingRobs = []
155
156
159 if not flags.Trigger.doLVL1: #if we rerun L1, don't decode the original RoIBResult
160 if doRoIBResult(flags):
161 roibResultTool = acc.popToolsAndMerge(RoIBResultByteStreamToolCfg(
162 flags, name="RoIBResultBSDecoderTool", writeBS=False))
163 decoderTools += [roibResultTool]
164 # Always treat L1Topo as "maybe missing" as it was under commissioning in Run 2 and had readout issues in Run 3
165 for module_id in roibResultTool.L1TopoModuleIds:
166 maybeMissingRobs.append(int(SourceIdentifier(SubDetector.TDAQ_CALO_TOPO_PROC, module_id)))
167 if flags.Trigger.EDMVersion == 2 and not flags.Trigger.doHLT:
168 # L1Calo occasional readout errors weren't caught by HLT in 2015 - ignore these in offline reco, see ATR-24493
169 for module_id in roibResultTool.JetModuleIds:
170 maybeMissingRobs.append(int(SourceIdentifier(SubDetector.TDAQ_CALO_JET_PROC_ROI, module_id)))
171 for module_id in roibResultTool.EMModuleIds:
172 maybeMissingRobs.append(int(SourceIdentifier(SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI, module_id)))
173
174 # ########################################
175 # # CTP decoding via CTPResult
176 # ########################################
177 if not flags.Trigger.doLVL1 and flags.Trigger.CTP.UseEDMxAOD:
178 ctpResultTool = acc.popToolsAndMerge(CTPResultByteStreamToolCfg(
179 flags, name="CTPResultBSDecoderTool", writeBS=False))
180 decoderTools += [ctpResultTool]
181
182
185 if flags.Trigger.L1.doMuon and flags.Trigger.enableL1MuonPhase1 and flags.Trigger.doHLT :
186 muonRoiTool = acc.popToolsAndMerge(MuonRoIByteStreamToolCfg(
187 flags, name="L1MuonBSDecoderTool", writeBS=False))
188 decoderTools += [muonRoiTool]
189
190
193 if flags.Trigger.L1.doCalo and flags.Trigger.enableL1CaloPhase1:
194 #--------------------
195 # eFex
196 #--------------------
197 if flags.Trigger.L1.doeFex:
198 # Online case in HLT with TOB decoding only
199 if flags.Trigger.doHLT:
200 eFexByteStreamTool = acc.popToolsAndMerge(eFexByteStreamToolCfg(
201 flags,
202 'eFexBSDecoderTool',
203 writeBS=False,
204 TOBs=True,
205 xTOBs=False,
206 multiSlice=False
207 ))
208 # Reco/monitoring case (either online but downstream from HLT, or at Tier-0) with xTOB, input tower and multi-slice decoding
209 else:
210 eFexByteStreamTool = acc.popToolsAndMerge(eFexByteStreamToolCfg(
211 flags,
212 'eFexBSDecoderTool',
213 writeBS=False,
214 TOBs=False,
215 xTOBs=True,
216 multiSlice=True,
217 decodeInputs=flags.Trigger.L1.doCaloInputs
218 ))
219 decoderTools += [eFexByteStreamTool]
220 # Allow the data to be missing at T0, due to the commissioning of the phase-1 L1Calo in RAW data from 2022
221 # Forbit the data to be missing at Point 1 (2023+)
222 if not flags.Trigger.doHLT:
223 maybeMissingRobs += eFexByteStreamTool.ROBIDs
224
225 #--------------------
226 # jFex
227 #--------------------
228 if flags.Trigger.L1.dojFex:
229 # Online case in HLT with TOB decoding only
230 if flags.Trigger.doHLT:
231 jFexRoiByteStreamTool = acc.popToolsAndMerge(jFexRoiByteStreamToolCfg(
232 flags,
233 'jFexBSDecoderTool',
234 writeBS=False
235 ))
236 # Reco/monitoring case (either online but downstream from HLT, or at Tier-0) with xTOB decoding only
237 else:
238 jFexRoiByteStreamTool = acc.popToolsAndMerge(jFexRoiByteStreamToolCfg(
239 flags,
240 'jFexBSDecoderTool',
241 writeBS=False,
242 xTOBs=True
243 ))
244 decoderTools += [jFexRoiByteStreamTool]
245 maybeMissingRobs += jFexRoiByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Calo (2022)
246
247 # Input towers decoding
248 if flags.Trigger.L1.doCaloInputs:
249 jFexInputByteStreamTool = acc.popToolsAndMerge(jFexInputByteStreamToolCfg(
250 flags,
251 'jFexInputBSDecoderTool',
252 writeBS=False
253 ))
254 decoderTools += [jFexInputByteStreamTool]
255 maybeMissingRobs += jFexInputByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Calo (2022)
256
257
258 #--------------------
259 # gFex
260 #--------------------
261 if flags.Trigger.L1.dogFex:
262 # Online case in HLT with TOB decoding (no 'else' case because gFex doesn't have xTOBs to decode offline)
263 if flags.Trigger.doHLT:
264 gFexByteStreamTool = acc.popToolsAndMerge(gFexByteStreamToolCfg(
265 flags,
266 'gFexBSDecoderTool',
267 writeBS=False
268 ))
269 decoderTools += [gFexByteStreamTool]
270 maybeMissingRobs += gFexByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Calo (2022)
271
272 # Input towers decoding
273 if flags.Trigger.L1.doCaloInputs:
274 gFexInputByteStreamTool = acc.popToolsAndMerge(gFexInputByteStreamToolCfg(
275 flags,
276 'gFexInputBSDecoderTool',
277 writeBS=False
278 ))
279 decoderTools += [gFexInputByteStreamTool]
280 maybeMissingRobs += gFexInputByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Calo (2022)
281
282
285 if flags.Trigger.L1.doTopo and flags.Trigger.enableL1CaloPhase1 and flags.Trigger.L1.doTopoPhase1:
286 topoByteStreamTool = acc.popToolsAndMerge(L1TopoPhase1ByteStreamToolCfg(
287 flags,
288 "L1TopoBSDecoderTool",
289 writeBS=False
290 ))
291 decoderTools += [topoByteStreamTool]
292 maybeMissingRobs += topoByteStreamTool.ROBIDs # Allow the data to be missing during commissioning of the phase-1 L1Topo (2022)
293
294 decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name="L1TriggerByteStreamDecoder",
295 DecoderTools=decoderTools,
296 MaybeMissingROBs=list(set(maybeMissingRobs)))
297
298 if flags.Trigger.doHLT or flags.DQ.Steering.doHLTMon:
299 from TrigT1ResultByteStream.TrigT1ResultByteStreamMonitoringConfig import L1TriggerByteStreamDecoderMonitoringCfg
300 decoderAlg.MonTool = acc.popToolsAndMerge(L1TriggerByteStreamDecoderMonitoringCfg(flags, decoderAlg.getName(), decoderTools))
301
302 acc.addEventAlgo(decoderAlg, primary=True)
303
304 # The decoderAlg needs to load ByteStreamMetadata for the detector mask
305 from TriggerJobOpts.TriggerByteStreamConfig import ByteStreamReadCfg
306 readBSAcc = ByteStreamReadCfg(flags)
307 readBSAcc.getEventAlgo('SGInputLoader').Load.add(
308 ('ByteStreamMetadataContainer', 'InputMetaDataStore+ByteStreamMetadata'))
309 acc.merge(readBSAcc)
310
311 # In reconstruction/monitoring jobs add the decoders' output EDM to the output file
312 if not flags.Trigger.doHLT:
313 from OutputStreamAthenaPool.OutputStreamConfig import addToESD, addToAOD
314 outputEDM = getEDMListFromWriteHandles([tool for tool in decoderAlg.DecoderTools if ('RoIBResult' not in tool.getName() and 'CTPResult' not in tool.getName())])
315 _log.info('Adding the following output EDM to ItemList: %s', outputEDM)
316 acc.merge(addToESD(flags, outputEDM))
317 acc.merge(addToAOD(flags, outputEDM))
318
319 # Return outputEDM as a second object to be used for compatibility with RecExCommon output configuration,
320 # because the above calls to addToESD/addtoAOD are no-op when this fragment is wrapped in RecExCommon.
321 # See discussions in https://gitlab.cern.ch/atlas/athena/-/merge_requests/55891#note_5912844
322 if returnEDM:
323 return acc, outputEDM
324 return acc
325
327 acc = ComponentAccumulator()
328
329 # Legacy encoding via RoIBResult
330 if doRoIBResult(flags):
331 roibResultTool = acc.popToolsAndMerge(RoIBResultByteStreamToolCfg(
332 flags, name="RoIBResultBSEncoderTool", writeBS=True))
333 acc.addPublicTool(roibResultTool)
334
335 # Run-3 L1Muon encoding
336 if flags.Trigger.L1.doMuon and flags.Trigger.enableL1MuonPhase1:
337 muonRoiTool = acc.popToolsAndMerge(MuonRoIByteStreamToolCfg(
338 flags, name="L1MuonBSEncoderTool", writeBS=True))
339 acc.addPublicTool(muonRoiTool)
340
341 # Phase-I CTP encoding
342 if flags.Trigger.CTP.UseEDMxAOD:
343 ctpResultTool = acc.popToolsAndMerge(CTPResultByteStreamToolCfg(
344 flags, name="CTPResultBSEncoderTool", writeBS=True))
345 acc.addPublicTool(ctpResultTool)
346
347 # TODO: Run-3 L1Calo, L1Topo, CTP
348
349 return acc
350
352 #print("MUCTPI DQ DEBUG python include algo")
353 acc = ComponentAccumulator()
354 alg = CompFactory.MuCTPIPhase1ByteStreamAlgo()
355 acc.addEventAlgo(alg)
356 return acc
357
358if __name__ == '__main__':
359 print("Please use: athena TrigT1CaloMonitoring/L1CaloPhase1Monitoring.py\nUse --help to see info about how options/examples for running the command")
360 import sys
361 sys.exit(1)
void print(char *figname, TCanvas *c1)
STL class.
MuonRoIByteStreamToolCfg(flags, name, writeBS=False, writeDecodedMuonRoIs=True)
ExampleL1TriggerByteStreamToolCfg(flags, name, writeBS=False)
RoIBResultByteStreamToolCfg(flags, name, writeBS=False)
CTPResultByteStreamToolCfg(flags, name, writeBS=False)
L1TriggerByteStreamDecoderCfg(flags, returnEDM=False)