ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaCPRunScript.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2import sys
3from AnalysisAlgorithmsConfig.CPBaseRunner import CPBaseRunner
4
5
6class AthenaCPRunScript(CPBaseRunner):
7 def __init__(self):
8 super().__init__()
9 self.logger.info("AthenaCPRunScript initialized")
10 self._cfg = None
12 self.configSeq = None
13 self.outputStreams = []
14 # Avoid putting call to parse_args() here! Otherwise it is hard to retrieve the parser infos
15
16 @property
17 def cfg(self):
18 if self._cfg is None:
19 raise ValueError('Service configuration not initialized, use initServiceCfg()')
20 return self._cfg
21
23 # add arguments here
24 derivedGroup = self.parser.add_argument_group('Athena specific arguments')
25 derivedGroup.add_argument('--config-only', dest='config_only',
26 action='store_true', help='Only generate the configuration and save it to a pickle file')
27 derivedGroup.add_argument('--perfmon', dest='perfmon', default='none',
28 help='Run PerfMon to measure the job performance')
29 derivedGroup.add_argument('--pool-file-reading', dest='pool_file_reading',
30 action='store_true', help='Run the job with the POOL-based file reading')
31 derivedGroup.add_argument('--test-mt-dependencies', dest='test_mt_dependencies',
32 type=int, default=None,
33 help='Print out multithreading dependencies, and run with the given number of threads')
34 return
35
36 def makeAlgSequence(self):
37 from AthenaConfiguration.ComponentFactory import CompFactory
38 algSeq = CompFactory.AthSequencer()
39 self.logger.info("Configuring algorithms based on YAML file")
40 configSeq = self.config.configure()
41 self.logger.info("Configuring common services")
42 from AnalysisAlgorithmsConfig.ConfigAccumulator import ConfigAccumulator
43 configAccumulator = ConfigAccumulator(flags=self.flags,
44 algSeq=algSeq,
45 noSystematics=self.args.no_systematics)
46 if not self.args.merge_output_files:
47 configAccumulator.setDefaultHistogramStream('ANALYSIS_HIST')
48 self.logger.info("Configuring algorithms")
49 configSeq.fullConfigure(configAccumulator)
50 self.configSeq = configSeq
51 self.outputStreams = configAccumulator.outputStreams()
52 self.modifyAlgSequence()
53 return configAccumulator.CA
54
55 def initServiceCfg(self):
56 if not self.flags.locked():
57 raise ValueError('Flags must be locked before initializing services')
58 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
59 self._cfg = MainServicesCfg(self.flags)
60
61 def run(self):
62 self.setup()
63
64 # PerfMon
65 from PerfMonComps.PerfMonConfigHelpers import setPerfmonFlagsFromRunArgs
66 setPerfmonFlagsFromRunArgs(self.flags, self.args)
67
68 if self.args.test_mt_dependencies is not None:
69 self.flags.Concurrency.NumThreads = self.args.test_mt_dependencies
70 self.flags.Scheduler.ShowControlFlow = True
71 self.flags.Scheduler.ShowDataDeps = True
72 self.flags.lock()
73 self.printFlags()
74
75 self.initServiceCfg()
76 if self.args.pool_file_reading or self.args.test_mt_dependencies is not None:
77 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
78 self.cfg.merge(PoolReadCfg(self.flags))
79 else:
80 from AthenaRootComps.xAODEventSelectorConfig import xAODReadCfg
81 self.cfg.merge(xAODReadCfg(self.flags))
82 from EventBookkeeperTools.EventBookkeeperToolsConfig import CutFlowSvcCfg
83 self.cfg.merge(CutFlowSvcCfg(self.flags))
84
85 from AthenaConfiguration.ComponentFactory import CompFactory
86 if not self.args.merge_output_files:
87 outputFileHist = f"ANALYSIS_HIST DATAFILE='hist-{self.outputName}.root' OPT='RECREATE'"
88 self.cfg.addService(CompFactory.THistSvc(Output=[outputFileHist]))
89
90 # Make the main analysis configuration
91 self.cfg.merge(self.makeAlgSequence())
92
93 # Every requested output stream gets its own file: the default tree stream ANALYSIS
94 # only if something writes to it, plus e.g. the streams of Output.splitBySelection
95 for stream in self.outputStreams:
96 if stream == 'ANALYSIS_HIST' and not self.args.merge_output_files:
97 continue # declared above
98 suffix = '' if stream == 'ANALYSIS' else '_' + stream.removeprefix('ANALYSIS_')
99 self.cfg.addService(CompFactory.THistSvc(Output=[
100 f"{stream} DATAFILE='{self.outputName}{suffix}.root' OPT='RECREATE'"]))
101
102 # Performance monitoring and profiling:
103 if self.flags.PerfMon.doFastMonMT or self.flags.PerfMon.doFullMonMT:
104 from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
105 self.cfg.merge(PerfMonMTSvcCfg(self.flags))
106
107 self.cfg.printConfig()
108
109 # dump pickle if requested
110 if self.args.config_only:
111 with open("CPRunConfig.pkl", "wb") as f:
112 self.cfg.store(f)
113 sys.exit(0)
114
115 sc = self.cfg.run()
116 sys.exit(sc.isFailure())
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
bool configure(asg::AnaToolHandle< ITrigGlobalEfficiencyCorrectionTool > &tool, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronEffToolsHandles, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronSFToolsHandles, ToolHandleArray< CP::IMuonTriggerScaleFactors > &muonToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonEffToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonSFToolsHandles, const std::string &triggers, const std::map< std::string, std::string > &legsPerTool, unsigned long nToys, bool debug)
Definition merge.py:1