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 # Avoid putting call to parse_args() here! Otherwise it is hard to retrieve the parser infos
14
15 @property
16 def cfg(self):
17 if self._cfg is None:
18 raise ValueError('Service configuration not initialized, use initServiceCfg()')
19 return self._cfg
20
22 # add arguments here
23 derivedGroup = self.parser.add_argument_group('Athena specific arguments')
24 derivedGroup.add_argument('--config-only', dest='config_only',
25 action='store_true', help='Only generate the configuration and save it to a pickle file')
26 derivedGroup.add_argument('--perfmon', dest='perfmon', default='none',
27 help='Run PerfMon to measure the job performance')
28 derivedGroup.add_argument('--pool-file-reading', dest='pool_file_reading',
29 action='store_true', help='Run the job with the POOL-based file reading')
30 derivedGroup.add_argument('--test-mt-dependencies', dest='test_mt_dependencies',
31 type=int, default=None,
32 help='Print out multithreading dependencies, and run with the given number of threads')
33 return
34
35 def makeAlgSequence(self):
36 from AthenaConfiguration.ComponentFactory import CompFactory
37 algSeq = CompFactory.AthSequencer()
38 self.logger.info("Configuring algorithms based on YAML file")
39 configSeq = self.config.configure()
40 self.logger.info("Configuring common services")
41 from AnalysisAlgorithmsConfig.ConfigAccumulator import ConfigAccumulator
42 configAccumulator = ConfigAccumulator(autoconfigFromFlags=self.flags,
43 algSeq=algSeq,
44 noSystematics=self.args.no_systematics)
45 if not self.args.merge_output_files:
46 configAccumulator.setDefaultHistogramStream('ANALYSIS_HIST')
47 self.logger.info("Configuring algorithms")
48 configSeq.fullConfigure(configAccumulator)
49 self.configSeq = configSeq
50 self.modifyAlgSequence()
51 return configAccumulator.CA
52
53 def initServiceCfg(self):
54 if not self.flags.locked():
55 raise ValueError('Flags must be locked before initializing services')
56 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
57 self._cfg = MainServicesCfg(self.flags)
58
59 def run(self):
60 self.setup()
61
62 # PerfMon
63 from PerfMonComps.PerfMonConfigHelpers import setPerfmonFlagsFromRunArgs
64 setPerfmonFlagsFromRunArgs(self.flags, self.args)
65
66 if self.args.test_mt_dependencies is not None:
67 self.flags.Concurrency.NumThreads = self.args.test_mt_dependencies
68 self.flags.Scheduler.ShowControlFlow = True
69 self.flags.Scheduler.ShowDataDeps = True
70 self.flags.lock()
71 self.printFlags()
72
73 self.initServiceCfg()
74 if self.args.pool_file_reading:
75 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
76 self.cfg.merge(PoolReadCfg(self.flags))
77 else:
78 from AthenaRootComps.xAODEventSelectorConfig import xAODReadCfg
79 self.cfg.merge(xAODReadCfg(self.flags))
80 from EventBookkeeperTools.EventBookkeeperToolsConfig import CutFlowSvcCfg
81 self.cfg.merge(CutFlowSvcCfg(self.flags))
82
83 outputFile = f"ANALYSIS DATAFILE='{self.outputName}.root' OPT='RECREATE'"
84 from AthenaConfiguration.ComponentFactory import CompFactory
85 self.cfg.addService(CompFactory.THistSvc(Output=[outputFile]))
86 if not self.args.merge_output_files:
87 outputFileHist = f"ANALYSIS_HIST DATAFILE='hist-{self.outputName}.root' OPT='RECREATE'"
88 from AthenaConfiguration.ComponentFactory import CompFactory
89 self.cfg.addService(CompFactory.THistSvc(Output=[outputFileHist]))
90
91 # Make the main analysis configuration
92 self.cfg.merge(self.makeAlgSequence())
93
94 # Performance monitoring and profiling:
95 if self.flags.PerfMon.doFastMonMT or self.flags.PerfMon.doFullMonMT:
96 from PerfMonComps.PerfMonCompsConfig import PerfMonMTSvcCfg
97 self.cfg.merge(PerfMonMTSvcCfg(self.flags))
98
99 self.cfg.printConfig()
100
101 # dump pickle if requested
102 if self.args.config_only:
103 with open("CPRunConfig.pkl", "wb") as f:
104 self.cfg.store(f)
105 sys.exit(0)
106
107 sc = self.cfg.run()
108 sys.exit(sc.isFailure())
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