ATLAS Offline Software
TrigPSCPythonCASetup.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 #
3 # This module is used as a Python bootstrap in athenaHLT for ComponentAccumulator
4 # based configurations. In CA-mode, we always dump the configuraton to JSON and
5 # re-launch ourselves from that file.
6 #
7 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
8 from AthenaConfiguration.ComponentFactory import CompFactory
9 from AthenaConfiguration.ComponentFactory import isComponentAccumulatorCfg
10 from AthenaConfiguration.MainServicesConfig import addMainSequences
11 from AthenaCommon.Logging import logging
12 
13 from TrigCommon import AthHLT
14 from TrigPSC import PscConfig
15 from TrigServices.TriggerUnixStandardSetup import commonServicesCfg
16 
17 import os
18 import sys
19 
20 log = logging.getLogger("athenaHLT")
21 
22 # Ensure we are really in CA-mode:
24  raise RuntimeError("isComponentAccumulatorCfg()==False but trying to run in CA mode")
25 
26 # For standalone testing:
27 if __name__ == "__main__":
28  if len(sys.argv)!=2:
29  print("Syntax: python %s module.cfgFnc" % os.path.basename(sys.argv[0]))
30  sys.exit(1)
31 
32  PscConfig.exitAfterDump = True # no execution for standalone testing
33  PscConfig.optmap = {"MESSAGESVCTYPE" : "TrigMessageSvc",
34  "JOBOPTIONSSVCTYPE" : "TrigConf::JobOptionSvc",
35  "JOBOPTIONSPATH" : sys.argv[1],
36  "PRECOMMAND" : "",
37  "POSTCOMMAND" : ""}
38 
39 
40 def execCommands(cmds, stage):
41  """Helper to execute a command string"""
42  if cmds:
43  log.info("-"*80)
44  log.info("Executing %scommand: %s", stage, cmds)
45  exec(cmds, globals())
46  log.info("-"*80)
47 
48 
49 from TrigPSC.PscDefaultFlags import defaultOnlineFlags
51 
52 # Run pre-command before user CA:
53 execCommands(PscConfig.optmap["PRECOMMAND"], "pre-")
54 
55 # Now clone and use locked flags for services configuration:
56 locked_flags = flags.clone()
57 locked_flags.lock()
58 
59 # Setup sequences and framework services:
60 cfg = ComponentAccumulator(CompFactory.AthSequencer("AthMasterSeq",Sequential=True))
61 cfg.setAppProperty('ExtSvcCreates', False)
62 cfg.setAppProperty("MessageSvcType", PscConfig.optmap["MESSAGESVCTYPE"])
63 cfg.setAppProperty("JobOptionsSvcType", PscConfig.optmap["JOBOPTIONSSVCTYPE"])
64 
65 addMainSequences(locked_flags, cfg)
66 cfg.merge( commonServicesCfg(locked_flags) )
67 
68 # User CA merge (with unlocked flags)
69 cfg.merge( AthHLT.getCACfg(PscConfig.optmap["JOBOPTIONSPATH"])(flags) )
70 
71 # Run post-command after user CA:
72 execCommands(PscConfig.optmap["POSTCOMMAND"], "post-")
73 
74 # Dump and convert job configuration:
75 fname = "HLTJobOptions"
76 with open(f"{fname}.pkl","wb") as f:
77  cfg.store(f)
78 
79 from TrigConfIO.JsonUtils import create_joboptions_json
80 create_joboptions_json(f"{fname}.pkl", f"{fname}.json")
81 
82 # Exit or re-launch:
83 if PscConfig.exitAfterDump:
84  log.info("Configuration dumped to %s.json Exiting...", fname)
85  sys.exit(0)
86 
87 AthHLT.reload_from_json(f"{fname}.json",
88  suppress_args = PscConfig.unparsedArguments)
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.MainServicesConfig.addMainSequences
def addMainSequences(flags, cfg)
Definition: MainServicesConfig.py:192
python.JsonUtils.create_joboptions_json
def create_joboptions_json(pkl_file, json_file, createDBJson=True)
Definition: JsonUtils.py:9
LArG4FSStartPointFilter.exec
exec
Definition: LArG4FSStartPointFilter.py:103
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.JetAnalysisCommon.isComponentAccumulatorCfg
isComponentAccumulatorCfg
Definition: JetAnalysisCommon.py:263
python.TrigPSCPythonCASetup.execCommands
def execCommands(cmds, stage)
Definition: TrigPSCPythonCASetup.py:40
Trk::open
@ open
Definition: BinningType.h:40
python.PscDefaultFlags.defaultOnlineFlags
def defaultOnlineFlags()
Definition: PscDefaultFlags.py:28
python.TriggerUnixStandardSetup.commonServicesCfg
def commonServicesCfg(flags)
Definition: TriggerUnixStandardSetup.py:9