4 from AthenaCommon.Logging
import logging
5 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
6 from AthenaConfiguration.ComponentFactory
import CompFactory
7 from AthenaConfiguration.Enums
import Format
8 from TrigEDMConfig.TriggerEDM
import recordable
9 from TrigEDMConfig.Utils
import getEDMListFromWriteHandles
10 from libpyeformat_helper
import SourceIdentifier, SubDetector
12 from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig
import eFexByteStreamToolCfg, jFexRoiByteStreamToolCfg, jFexInputByteStreamToolCfg, gFexByteStreamToolCfg, gFexInputByteStreamToolCfg
13 from L1TopoByteStream.L1TopoByteStreamConfig
import L1TopoPhase1ByteStreamToolCfg
14 from TrigT1MuonRecRoiTool.TrigT1MuonRecRoiToolConfig
import RPCRecRoiToolCfg, TGCRecRoiToolCfg
15 from TrigT1MuctpiPhase1.TrigT1MuctpiPhase1Config
import TrigThresholdDecisionToolCfg
17 _log = logging.getLogger(
'TrigT1ResultByteStreamConfig')
21 tool = CompFactory.RoIBResultByteStreamTool(name)
23 if not flags.Trigger.L1.doCTP:
25 tool.CTPModuleId = 0xFF
27 if flags.Trigger.enableL1MuonPhase1
or not flags.Trigger.L1.doMuon:
29 tool.MUCTPIModuleId = 0xFF
31 if not flags.Trigger.enableL1CaloLegacy
or not flags.Trigger.L1.doCalo:
33 tool.JetModuleIds = []
36 if flags.Trigger.EDMVersion == 1
or not flags.Trigger.L1.doTopo:
38 tool.L1TopoModuleIds = []
42 tool.RoIBResultReadKey=
"RoIBResult"
43 tool.RoIBResultWriteKey=
""
46 tool.RoIBResultReadKey=
""
47 tool.RoIBResultWriteKey=
"RoIBResult"
49 acc.setPrivateTools(tool)
54 tool = CompFactory.ExampleL1TriggerByteStreamTool(name)
56 muctpi_robid =
int(SourceIdentifier(SubDetector.TDAQ_MUON_CTP_INTERFACE, muctpi_moduleid))
57 tool.ROBIDs = [muctpi_robid]
60 tool.MuonRoIContainerReadKey=
"LVL1MuonRoIs"
61 tool.MuonRoIContainerWriteKey=
""
62 tool.L1TopoOutputLocID=
""
65 tool.MuonRoIContainerReadKey=
""
66 tool.MuonRoIContainerWriteKey=
recordable(
"LVL1MuonRoIs")
67 acc.setPrivateTools(tool)
72 tool = CompFactory.MuonRoIByteStreamTool(name)
74 muctpi_robid =
int(SourceIdentifier(SubDetector.TDAQ_MUON_CTP_INTERFACE, muctpi_moduleid))
75 tool.ROBIDs = [muctpi_robid]
76 tool.DoTopo = flags.Trigger.L1.doMuonTopoInputs
78 from TrigT1ResultByteStream.TrigT1ResultByteStreamMonitoringConfig
import L1MuonBSConverterMonitoringCfg
82 containerBaseName =
"LVL1MuonRoIs"
84 containerBaseName +
"BCm2",
85 containerBaseName +
"BCm1",
87 containerBaseName +
"BCp1",
88 containerBaseName +
"BCp2",
90 topocontainerBaseName =
"L1MuCTPItoL1TopoLocationFromMuonRoI"
91 topocontainerNames = [
92 topocontainerBaseName +
"-2",
93 topocontainerBaseName +
"-1",
94 topocontainerBaseName,
95 topocontainerBaseName +
"1",
96 topocontainerBaseName +
"2",
100 tool.MuonRoIContainerReadKeys += containerNames
103 tool.MuonRoIContainerWriteKeys += [
recordable(c)
for c
in containerNames]
104 tool.L1TopoOutputLocID += topocontainerNames
110 acc.setPrivateTools(tool)
115 Helper function returning a logic combination of flags deciding
116 whether the RoIBResult decoding/encoding is required in the job
118 if flags.Trigger.L1.doCalo
and flags.Trigger.enableL1CaloLegacy:
121 if flags.Trigger.L1.doMuon
and not flags.Trigger.enableL1MuonPhase1:
124 if flags.Trigger.L1.doTopo:
127 if flags.Trigger.L1.doCTP:
136 maybeMissingRobs = []
141 if not flags.Trigger.doLVL1:
144 flags, name=
"RoIBResultBSDecoderTool", writeBS=
False))
145 decoderTools += [roibResultTool]
147 for module_id
in roibResultTool.L1TopoModuleIds:
148 maybeMissingRobs.append(
int(SourceIdentifier(SubDetector.TDAQ_CALO_TOPO_PROC, module_id)))
149 if flags.Trigger.EDMVersion == 2
and not flags.Trigger.doHLT:
151 for module_id
in roibResultTool.JetModuleIds:
152 maybeMissingRobs.append(
int(SourceIdentifier(SubDetector.TDAQ_CALO_JET_PROC_ROI, module_id)))
153 for module_id
in roibResultTool.EMModuleIds:
154 maybeMissingRobs.append(
int(SourceIdentifier(SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI, module_id)))
159 if flags.Trigger.L1.doMuon
and flags.Trigger.enableL1MuonPhase1
and flags.Trigger.doHLT:
161 flags, name=
"L1MuonBSDecoderTool", writeBS=
False))
162 decoderTools += [muonRoiTool]
167 if flags.Trigger.L1.doCalo
and flags.Trigger.enableL1CaloPhase1:
171 if flags.Trigger.L1.doeFex:
173 if flags.Trigger.doHLT:
191 decodeInputs=flags.Trigger.L1.doCaloInputs
193 decoderTools += [eFexByteStreamTool]
196 if not flags.Trigger.doHLT:
197 maybeMissingRobs += eFexByteStreamTool.ROBIDs
202 if flags.Trigger.L1.dojFex:
204 if flags.Trigger.doHLT:
218 decoderTools += [jFexRoiByteStreamTool]
219 maybeMissingRobs += jFexRoiByteStreamTool.ROBIDs
222 if flags.Trigger.L1.doCaloInputs:
225 'jFexInputBSDecoderTool',
228 decoderTools += [jFexInputByteStreamTool]
229 maybeMissingRobs += jFexInputByteStreamTool.ROBIDs
235 if flags.Trigger.L1.dogFex:
237 if flags.Trigger.doHLT:
243 decoderTools += [gFexByteStreamTool]
244 maybeMissingRobs += gFexByteStreamTool.ROBIDs
247 if flags.Trigger.L1.doCaloInputs:
250 'gFexInputBSDecoderTool',
253 decoderTools += [gFexInputByteStreamTool]
254 maybeMissingRobs += gFexInputByteStreamTool.ROBIDs
259 if flags.Trigger.L1.doTopo
and flags.Trigger.enableL1CaloPhase1
and flags.Trigger.L1.doTopoPhase1:
262 "L1TopoBSDecoderTool",
265 decoderTools += [topoByteStreamTool]
266 maybeMissingRobs += topoByteStreamTool.ROBIDs
268 decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name=
"L1TriggerByteStreamDecoder",
269 DecoderTools=decoderTools,
270 MaybeMissingROBs=
list(
set(maybeMissingRobs)))
272 if flags.Trigger.doHLT
or flags.DQ.Steering.doHLTMon:
273 from TrigT1ResultByteStream.TrigT1ResultByteStreamMonitoringConfig
import L1TriggerByteStreamDecoderMonitoringCfg
276 acc.addEventAlgo(decoderAlg, primary=
True)
279 from TriggerJobOpts.TriggerByteStreamConfig
import ByteStreamReadCfg
281 readBSAcc.getEventAlgo(
'SGInputLoader').Load.add(
282 (
'ByteStreamMetadataContainer',
'InputMetaDataStore+ByteStreamMetadata'))
286 if not flags.Trigger.doHLT:
287 from OutputStreamAthenaPool.OutputStreamConfig
import addToESD, addToAOD
289 _log.info(
'Adding the following output EDM to ItemList: %s', outputEDM)
290 acc.merge(
addToESD(flags, outputEDM))
291 acc.merge(
addToAOD(flags, outputEDM))
297 return acc, outputEDM
306 flags, name=
"RoIBResultBSEncoderTool", writeBS=
True))
307 acc.addPublicTool(roibResultTool)
310 if flags.Trigger.L1.doMuon
and flags.Trigger.enableL1MuonPhase1:
312 flags, name=
"L1MuonBSEncoderTool", writeBS=
True))
313 acc.addPublicTool(muonRoiTool)
322 alg = CompFactory.MuCTPIPhase1ByteStreamAlgo()
323 acc.addEventAlgo(alg)
326 if __name__ ==
'__main__':
327 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
333 parser = argparse.ArgumentParser(prog=
'python -m TrigT1ResultByteStream.TrigT1ResultByteStreamConfig',
334 description=
"""Bytestream decoder athena script.\n\n
335 Example: python -m TrigT1ResultByteStream.TrigT1ResultByteStreamConfig --filesInput "data22*" --evtMax 10 --outputs eTOBs exTOBs """)
336 parser.add_argument(
'--evtMax',type=int,default=-1,help=
"number of events to process (-1 = til end of files)")
337 parser.add_argument(
'--skipEvents',type=int,default=0,help=
"number of events to skip")
338 parser.add_argument(
'--filesInput',nargs=
'+',help=
"input files",required=
True)
339 parser.add_argument(
'--userAlgs',nargs=
'+',help=
"names of user algorithms to add, can specify as Type/Name or just Type",default=[])
340 parser.add_argument(
'--outputLevel',default=
"WARNING",choices={
'INFO',
'WARNING',
'DEBUG',
'VERBOSE'})
341 parser.add_argument(
'--outputHISTFile',default=
"",help=
"if specified, will activate monitoring")
342 parser.add_argument(
'--outputs',nargs=
'+',choices={
"eTOBs",
"exTOBs",
"seTOBs",
"eDataTowers",
"jTOBs",
"jxTOBS",
"jTowers",
"gTOBs",
"gCaloTowers",
"Topo",
"legacy",
"tTowers",
"sCells",
"eEmulatedTowers"},required=
True,
343 help=
"What data to decode and output.")
344 args = parser.parse_args()
346 _log.setLevel(logging.DEBUG)
348 from AthenaCommon
import Constants
349 algLogLevel = getattr(Constants,args.outputLevel)
352 if any([
"data23" in f
for f
in args.filesInput]):
353 flags.IOVDb.GlobalTag =
"CONDBR2-HLTP-2022-02"
354 flags.Trigger.triggerConfig=
'DB'
356 elif any([
"data22" in f
for f
in args.filesInput]):
357 flags.IOVDb.GlobalTag =
"CONDBR2-ES1PA-2022-07"
358 flags.Trigger.triggerConfig=
'DB'
360 flags.Input.Files = [file
for x
in args.filesInput
for file
in glob.glob(x)]
362 from AthenaConfiguration.TestDefaults
import defaultGeometryTags
363 flags.GeoModel.AtlasVersion = defaultGeometryTags.autoconfigure(flags)
365 flags.Exec.OutputLevel = algLogLevel
366 flags.Exec.MaxEvents = args.evtMax
367 flags.Exec.SkipEvents = args.skipEvents
368 flags.Concurrency.NumThreads = 1
369 flags.Concurrency.NumConcurrentEvents = 1
370 flags.Output.HISTFileName = args.outputHISTFile
372 if any([
"data" in f
for f
in args.filesInput]):
374 flags.Output.AODFileName =
"AOD."+(s.split(
"/")[-1]).
split(
'_SFO')[0]+
"pool.root"
376 flags.Output.AODFileName =
'AOD.pool.root'
378 flags.DQ.useTrigger =
False
379 flags.DQ.enableLumiAccess =
False
381 flags.Trigger.enableL1CaloLegacy =
'legacy' in args.outputs
384 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
385 from ByteStreamCnvSvc.ByteStreamConfig
import ByteStreamReadCfg
391 from TrigConfigSvc.TrigConfigSvcCfg
import L1ConfigSvcCfg,generateL1Menu
394 if not any([
"data22" in f
for f
in args.filesInput])
and not any([
"data23" in f
for f
in args.filesInput]):
400 maybeMissingRobs = []
404 auxType = edmType.replace(
'Container',
'AuxContainer')
405 return [f
'{edmType}#{edmName}',
406 f
'{auxType}#{edmName}Aux.']
408 if "eEmulatedTowers" in args.outputs:
410 args.outputs += [
"sCells",
"tTowers"]
413 from LArCabling.LArCablingConfig
import LArOnOffIdMappingCfg
415 from IOVDbSvc.IOVDbSvcConfig
import addFolders
416 acc.merge(
addFolders(flags,
"/LAR/BadChannels/BadChannelsSC",
"LAR",tag=
"LARBadChannelsBadChannelsSC-RUN3-UPD1-00",className=
"CondAttrListCollection"))
417 acc.addCondAlgo(CompFactory.LArBadChannelCondAlg(ReadKey=
"/LAR/BadChannels/BadChannelsSC",isSC=
True,CablingKey=
"LArOnOffIdMapSC"))
419 acc.addEventAlgo( CompFactory.LVL1.eFexTowerBuilder(
"eFexTowerBuilder"), sequenceName=
'AthAlgSeq' )
420 outputEDM +=
addEDM(
'xAOD::eFexTowerContainer', acc.getEventAlgo(
"eFexTowerBuilder").eFexContainerWriteKey)
422 if "sCells" in args.outputs:
423 from L1CaloFEXSim.L1CaloFEXSimCfg
import ReadSCellFromByteStreamCfg
425 outputEDM += [
"CaloCellContainer#SCell"]
427 if "tTowers" in args.outputs:
428 from TriggerJobOpts.TriggerByteStreamConfig
import ByteStreamReadCfg
430 'xAOD::TriggerTowerAuxContainer/xAODTriggerTowersAux.']))
439 if 'legacy' in args.outputs:
441 from AnalysisTriggerAlgs.AnalysisTriggerAlgsConfig
import RoIBResultToxAODCfg
443 acc.merge(xRoIBResultAcc)
446 flags, name=
"RoIBResultBSDecoderTool", writeBS=
False))
447 decoderTools += [roibResultTool]
450 for module_id
in roibResultTool.L1TopoModuleIds:
451 maybeMissingRobs.append(
int(SourceIdentifier(SubDetector.TDAQ_CALO_TOPO_PROC, module_id)))
452 if flags.Trigger.EDMVersion == 2
and not flags.Trigger.doHLT:
454 for module_id
in roibResultTool.JetModuleIds:
455 maybeMissingRobs.append(
int(SourceIdentifier(SubDetector.TDAQ_CALO_JET_PROC_ROI, module_id)))
456 for module_id
in roibResultTool.EMModuleIds:
457 maybeMissingRobs.append(
int(SourceIdentifier(SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI, module_id)))
460 outputEDM +=
addEDM(
'xAOD::JetEtRoI' ,
'LVL1JetEtRoI')
461 outputEDM +=
addEDM(
'xAOD::JetRoIContainer' ,
'LVL1JetRoIs')
462 outputEDM +=
addEDM(
'xAOD::EmTauRoIContainer',
'LVL1EmTauRoIs')
463 outputEDM +=
addEDM(
'xAOD::EnergySumRoI' ,
'LVL1EnergySumRoI')
466 from TriggerJobOpts.TriggerByteStreamConfig
import ByteStreamReadCfg
469 "xAOD::CPMTowerContainer/CPMTowers",
470 "xAOD::CPMTowerAuxContainer/CPMTowersAux.",
471 "xAOD::CPMTowerContainer/CPMTowersOverlap",
472 "xAOD::CPMTowerAuxContainer/CPMTowersOverlapAux.",
474 "xAOD::CPMTobRoIContainer/CPMTobRoIs",
475 "xAOD::CPMTobRoIAuxContainer/CPMTobRoIsAux.",
476 "xAOD::CPMTobRoIContainer/CPMTobRoIsRoIB",
477 "xAOD::CPMTobRoIAuxContainer/CPMTobRoIsRoIBAux.",
479 "xAOD::JEMTobRoIContainer/JEMTobRoIs",
480 "xAOD::JEMTobRoIAuxContainer/JEMTobRoIsAux.",
481 "xAOD::JEMTobRoIContainer/JEMTobRoIsRoIB",
482 "xAOD::JEMTobRoIAuxContainer/JEMTobRoIsRoIBAux.",
486 outputEDM += [item.replace(
'/',
'#')
for item
in type_names]
491 if 'jTOBs' in args.outputs:
493 flags,
'jFexBSDecoder_TOB'))
494 for module_id
in jFexTool.ROBIDs:
495 maybeMissingRobs.append(module_id)
497 decoderTools += [jFexTool]
502 if 'jxTOBs' in args.outputs:
504 flags,
'jFexBSDecoder_xTOB', xTOBs=
True))
505 for module_id
in jFexTool.ROBIDs:
506 maybeMissingRobs.append(module_id)
508 decoderTools += [jFexTool]
513 if 'jTowers' in args.outputs:
515 flags,
'jFexInputBSDecoder'))
516 for module_id
in inputjFexTool.ROBIDs:
517 maybeMissingRobs.append(module_id)
519 decoderTools += [inputjFexTool]
524 if any( [x
in args.outputs
for x
in [
'eTOBs',
'exTOBs',
'eDataTowers']] ):
528 TOBs=
'eTOBs' in args.outputs,
529 xTOBs=
'exTOBs' in args.outputs,
530 decodeInputs=
'eDataTowers' in args.outputs
533 decoderTools += [eFexTool]
536 maybeMissingRobs += eFexTool.ROBIDs
541 if 'gTOBs' in args.outputs:
543 flags,
'gFexBSDecoder'))
544 decoderTools += [gFexTool]
549 if 'gCaloTowers' in args.outputs:
551 flags,
'gFexInputBSDecoder'))
552 decoderTools += [inputgFexTool]
557 if 'Topo' in args.outputs:
559 flags,
"L1TopoBSDecoderTool"))
560 decoderTools += [l1topoBSTool]
562 maybeMissingRobs += l1topoBSTool.ROBIDs
564 if 'seTOBs' in args.outputs:
566 acc.addEventAlgo(CompFactory.LVL1.eTowerMakerFromSuperCells(
'eTowerMakerFromSuperCells'),sequenceName=
'AthAlgSeq')
567 acc.addEventAlgo(CompFactory.LVL1.eFEXDriver(
'eFEXDriver',
568 eFEXSysSimTool = CompFactory.LVL1.eFEXSysSim(
'eFEXSysSimTool')
569 ),sequenceName=
'AthAlgSeq')
570 acc.getEventAlgo(
'eFEXDriver').eFEXSysSimTool.Key_eFexEMOutputContainer =
"L1_eEMRoISim"
571 acc.getEventAlgo(
'eFEXDriver').eFEXSysSimTool.Key_eFexEMxTOBOutputContainer =
"L1_eEMxRoISim"
572 acc.getEventAlgo(
'eFEXDriver').eFEXSysSimTool.Key_eFexTauOutputContainer =
"L1_eTauRoISim"
573 acc.getEventAlgo(
'eFEXDriver').eFEXSysSimTool.Key_eFexTauxTOBOutputContainer =
"L1_eTauxRoISim"
575 decoderAlg = CompFactory.L1TriggerByteStreamDecoderAlg(name=
"L1TriggerByteStreamDecoder",
576 DecoderTools=decoderTools, OutputLevel=algLogLevel, MaybeMissingROBs=
list(
set(maybeMissingRobs)))
578 acc.addEventAlgo(decoderAlg, sequenceName=
'AthAlgSeq')
580 from OutputStreamAthenaPool.OutputStreamConfig
import OutputStreamCfg
582 _log.debug(
'Adding the following output EDM to ItemList: %s', outputEDM)
586 acc.getEventAlgo(
"EventInfoTagBuilder").PropagateInput = (flags.Input.Format != Format.BS)
589 if flags.Exec.MaxEvents==1:
590 acc.getService(
"StoreGateSvc").Dump=
True
591 acc.getService(
"StoreGateSvc").OutputLevel=Constants.INFO
594 for alg
in args.userAlgs: acc.addEventAlgo(CompFactory.getComp(alg.split(
'/')[0])(name=alg.split(
'/')[-1]),sequenceName=
'AthEndSeq')
598 if args.outputHISTFile !=
"":
599 from AthenaMonitoring.AthMonitorCfgHelper
import getDQTHistSvc
601 if "seTOBs" in args.outputs
and "eTOBs" in args.outputs
and "exTOBs" in args.outputs:
602 from TrigT1CaloMonitoring.EfexSimMonitorAlgorithm
import EfexSimMonitoringConfig
609 if acc.run().isFailure():