ATLAS Offline Software
NavConverterConfig.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 #
4 
5 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6 from AthenaConfiguration.ComponentFactory import CompFactory
7 # from AthenaCommon.Constants import DEBUG # uncomment for the easy usage while testing with DEBUG
8 from AthenaCommon.Logging import logging
9 log = logging.getLogger("NavConverterConfig")
10 
11 
12 def NavConverterCfg(flags, chainsList = [], runTheChecker = False):
13  """Configures Run 1/2 to Run 3 navigation conversion algorithm for all triggers"""
14  if len(chainsList) == 0:
15  log.info("Chains list is empty, the conversion will happen for all chains, but no validation will be performed")
16  log.info("The later is enabled when an explicit chain list is provided")
17 
18  acc = ComponentAccumulator()
19 
20  if flags.Trigger.EDMVersion >= 3:
21  return acc
22 
23  if not flags.Trigger.doEDMVersionConversion:
24  return acc
25 
26  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg, getRun3NavigationContainerFromInput
27  tdt = acc.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
28 
29  r2ToR3OutputName = getRun3NavigationContainerFromInput(flags)
30 
31  cnvAlg = CompFactory.Run2ToRun3TrigNavConverterV2("TrigRun2ToRun3NavConverter") #, OutputLevel = 2)
32  cnvAlg.TrigDecisionTool = tdt
33  cnvAlg.TrigNavReadKey = ""
34  cnvAlg.TrigConfigSvc = tdt.TrigConfigSvc
35  cnvAlg.OutputNavKey = r2ToR3OutputName
36  from OutputStreamAthenaPool.OutputStreamConfig import addToAOD, addToESD
37  collections = [f"xAOD::TrigCompositeContainer#{r2ToR3OutputName}", f"xAOD::TrigCompositeAuxContainer#{r2ToR3OutputName}Aux."]
38  acc.merge(addToAOD(flags, collections))
39  acc.merge(addToESD(flags, collections))
40 
41  cnvAlg.Rois = ["initialRoI","forID","forID1","forID2","forMS","forSA","forTB","forMT","forCB"]
42 
43  from TrigEDMConfig.TriggerEDM import getTriggerEDMList
44  edm = getTriggerEDMList(flags, "AODCONV")
45 
46  def cleanKey(type, name):
47  return name.replace("HLT_", "", 1).replace(type.replace("::", "__"), "", 1).replace("_", "", 1)
48  types = []
49  for type, keys in edm.items():
50 
51  for key in keys:
52  types.append(type+"#"+cleanKey(type, key))
53 
54  log.info("Assuming these collections are relevant for trigger: %s", " ".join(types))
55  cnvAlg.Collections = types
56  cnvAlg.Chains = chainsList
57  cnvAlg.doCompression = True # set True for compression
58  acc.addEventAlgo(cnvAlg)
59 
60  if runTheChecker:
61  checker = CompFactory.Trig.NavigationTesterAlg(FailOnDifference = False, TrigDecisionTool = tdt) #, OutputLevel = 2)
62  checker.RetrievalToolRun2Nav = CompFactory.Trig.IParticleRetrievalTool()
63 
64  # in conversion job Run2 TDT is setup as default, we need to setup an alternative to access Run 3 format
65  run3tdt = CompFactory.Trig.TrigDecisionTool("Run3TrigDecisionTool",
66  HLTSummary = r2ToR3OutputName,
67  NavigationFormat = 'TrigComposite',
68  AcceptMultipleInstance=True,
69  TrigConfigSvc = tdt.TrigConfigSvc) #, OutputLevel = 2)
70  acc.addPublicTool(run3tdt)
71  checker.RetrievalToolRun3Nav = CompFactory.Trig.R3IParticleRetrievalTool(TrigDecisionTool = run3tdt) #, OutputLevel = 2)
72  checker.Chains = chainsList
73  checker.TrigDecisionToolRun3 = run3tdt
74  checker.TrigDecisionToolRun2 = tdt
75 
76  acc.addEventAlgo(checker)
77 
78  return acc
79 
80 
81 if __name__ == "__main__":
82  # this is only config test, actual tests are in share/testTrigR2... scripts
83  from AthenaConfiguration.AllConfigFlags import initConfigFlags
84  from AthenaConfiguration.TestDefaults import defaultTestFiles
85  flags = initConfigFlags()
86  flags.Input.Files = defaultTestFiles.AOD_RUN2_DATA
87  flags.Trigger.doEDMVersionConversion = True
88  flags.lock()
89 
90  acc = NavConverterCfg(flags)
91  acc.printConfig(withDetails=True, summariseProps=True)
92  acc.wasMerged()
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.TriggerEDM.getTriggerEDMList
def getTriggerEDMList(flags, key, runVersion=-1)
Definition: TriggerEDM.py:149
python.TrigDecisionToolConfig.getRun3NavigationContainerFromInput
def getRun3NavigationContainerFromInput(flags)
Definition: TrigDecisionToolConfig.py:63
python.OutputStreamConfig.addToESD
def addToESD(flags, itemOrList, **kwargs)
Definition: OutputStreamConfig.py:127
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.TriggerInterface.TrigDecisionToolCfg
def TrigDecisionToolCfg(flags)
Definition: TriggerInterface.py:14
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.OutputStreamConfig.addToAOD
def addToAOD(flags, itemOrList, **kwargs)
Definition: OutputStreamConfig.py:142
python.NavConverterConfig.NavConverterCfg
def NavConverterCfg(flags, chainsList=[], runTheChecker=False)
Definition: NavConverterConfig.py:12