ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.EventLoopCPRunScript.EventLoopCPRunScript Class Reference
Inheritance diagram for python.EventLoopCPRunScript.EventLoopCPRunScript:
Collaboration diagram for python.EventLoopCPRunScript.EventLoopCPRunScript:

Public Member Functions

def __init__ (self)
 
def addCustomArguments (self)
 
def makeAlgSequence (self)
 
def readSamples (self)
 
def moveOutputFiles (self)
 
def driverSubmit (self, driver)
 
def run (self)
 

Public Attributes

 sampleHandler
 
 job
 

Detailed Description

Definition at line 5 of file EventLoopCPRunScript.py.

Constructor & Destructor Documentation

◆ __init__()

def python.EventLoopCPRunScript.EventLoopCPRunScript.__init__ (   self)

Definition at line 6 of file EventLoopCPRunScript.py.

6  def __init__(self):
7  super().__init__()
8  self.logger.info("EventLoopCPRunScript initialized")
9  self.addCustomArguments()
10  # Avoid putting call to parse_args() here! Otherwise it is hard to retrieve the parser infos
11 

Member Function Documentation

◆ addCustomArguments()

def python.EventLoopCPRunScript.EventLoopCPRunScript.addCustomArguments (   self)

Definition at line 12 of file EventLoopCPRunScript.py.

12  def addCustomArguments(self):
13  # add arguments here
14  derivedGroup = self.parser.add_argument_group('EventLoop specific arguments')
15  derivedGroup.add_argument('--direct-driver', dest='direct_driver',
16  action='store_true', help='Run the job with the direct driver')
17  derivedGroup.add_argument('--work-dir', dest='work_dir', nargs='?', const='workDir', default=None,
18  help='The work directory for the EL job. defaults to "workDir".')
19  derivedGroup.add_argument('--merge-output-files', dest='merge_output_files', action='store_true', help='Merge the output histogram and n-tuple files into a single file.')
20 
21  expertGroup = self.parser.add_argument_group('Experts arguments')
22  expertGroup.add_argument('--run-perf-stat', dest='run_perf_stat', action='store_true', help='Run xAOD::PerfStats to get input branch access data. This is mostly useful for AMG experts wanting to understand branch access patterns.')
23  expertGroup.add_argument('--algorithm-timers', dest='algorithm_timers', action='store_true', help='Enable algorithm timers. This is mostly useful for AMG experts wanting to understand tool performance.')
24  expertGroup.add_argument('--algorithm-memory-monitoring', dest='algorithm_memory_monitoring', action='store_true', help='Enable algorithm memory monitoring. This is mostly useful for AMG experts wanting to understand tool memory usage. Note that this is imperfect and may in cases assign memory to the wrong algorithm.')
25  return
26 

◆ driverSubmit()

def python.EventLoopCPRunScript.EventLoopCPRunScript.driverSubmit (   self,
  driver 
)
Important if you want to run code after submitting the job, with external driver e.g., ExecDriver.
Assistant function to call driver submit. Move the submission to a child process to avoid the main process being terminated.
Directly calling external driver submission will not return controls to the main process, the main thread will be terminated.

Definition at line 83 of file EventLoopCPRunScript.py.

83  def driverSubmit(self, driver):
84  '''
85  Important if you want to run code after submitting the job, with external driver e.g., ExecDriver.
86  Assistant function to call driver submit. Move the submission to a child process to avoid the main process being terminated.
87  Directly calling external driver submission will not return controls to the main process, the main thread will be terminated.
88  '''
89  if (pid := os.fork()) == 0: # child process
90  name = self.args.work_dir if self.args.work_dir else 'workDir'
91  driver.submit(self.job, name)
92  exit(0)
93  else:
94  os.waitpid(pid, 0) # parent waits for child process to finish
95  return
96 

◆ makeAlgSequence()

def python.EventLoopCPRunScript.EventLoopCPRunScript.makeAlgSequence (   self)

Definition at line 27 of file EventLoopCPRunScript.py.

27  def makeAlgSequence(self):
28  from AnaAlgorithm.AlgSequence import AlgSequence
29  from AnalysisAlgorithmsConfig.ConfigAccumulator import ConfigAccumulator
30  algSeq = AlgSequence()
31  self.logger.info("Configuring algorithms based on YAML file")
32  configSeq = self.config.configure()
33  self.logger.info("Configuring common services")
34  configAccumulator = ConfigAccumulator(flags=self.flags,
35  algSeq=algSeq,
36  noSystematics=self.args.no_systematics)
37  self.logger.info("Configuring algorithms")
38  configSeq.fullConfigure(configAccumulator)
39  return algSeq
40 

◆ moveOutputFiles()

def python.EventLoopCPRunScript.EventLoopCPRunScript.moveOutputFiles (   self)

Definition at line 50 of file EventLoopCPRunScript.py.

50  def moveOutputFiles(self):
51  from pathlib import Path
52  import shutil
53  self.logger.info("Moving the analysis root file and the hist file to the top level.")
54  workDir = Path(self.args.work_dir) if self.args.work_dir else Path('workDir')
55  rootfileSymlink = (workDir / 'data-ANALYSIS' / f'{self.outputName}.root')
56  rootfilePath = rootfileSymlink.resolve()
57  histfileSymlink = (workDir / f'hist-{self.outputName}.root')
58  histfilePath = histfileSymlink.resolve()
59  currentDir = Path.cwd()
60  # move ntuple file if it exists
61  if rootfilePath.exists():
62  self.logger.info(f"Moving {rootfilePath} to {currentDir / f'{self.outputName}.root'}")
63  if rootfileSymlink.is_symlink(): # The check is needed to avoid FileNotFoundError if using direct driver
64  rootfileSymlink.unlink()
65  shutil.move(str(rootfilePath), str(currentDir / f"{self.outputName}.root"))
66  else:
67  self.logger.warning(f"Root file {rootfilePath} does not exist or merging is enabled, skipping move.")
68  #move histogram file if it exists
69  if histfilePath.exists():
70  self.logger.info(f"Moving {histfilePath} to {currentDir / f'hist-{self.outputName}.root'}")
71  if histfileSymlink.is_symlink(): # The check is needed to avoid FileNotFoundError if using direct driver
72  histfileSymlink.unlink()
73  shutil.move(str(histfilePath), str(currentDir / f"hist-{self.outputName}.root"))
74  else:
75  self.logger.warning(f"Histogram file {histfilePath} does not exist or merging, skipping move.")
76 
77  newHistFile = currentDir / f"hist-{self.outputName}.root"
78  # rename merged hist-ntuple to output_name.root
79  if self.args.merge_output_files and newHistFile.exists():
80  self.logger.info(f"renmaing the hist-{self.outputName}.root to {self.outputName}.root")
81  newHistFile.rename(currentDir / f"{self.outputName}.root")
82 

◆ readSamples()

def python.EventLoopCPRunScript.EventLoopCPRunScript.readSamples (   self)

Definition at line 41 of file EventLoopCPRunScript.py.

41  def readSamples(self):
42  import ROOT
43  self.sampleHandler = ROOT.SH.SampleHandler()
44  sampleFiles = ROOT.SH.SampleLocal(f"{self.outputName}")
45  self.logger.info("Adding files to the sample handler")
46  for file in self.inputList:
47  sampleFiles.add(file)
48  self.sampleHandler.add(sampleFiles)
49 

◆ run()

def python.EventLoopCPRunScript.EventLoopCPRunScript.run (   self)

Definition at line 97 of file EventLoopCPRunScript.py.

97  def run(self):
98  self.setup()
99  # importing ROOT has a long upfront time, so we do it here
100  import ROOT
101  ROOT.xAOD.Init().ignore()
102  self.readSamples()
103  self.flags.lock()
104  self.printFlags()
105 
106  self.job = ROOT.EL.Job()
107  self.job.sampleHandler(self.sampleHandler)
108  self.job.options().setDouble(ROOT.EL.Job.optFilesPerWorker, 100)
109  self.job.options().setDouble(ROOT.EL.Job.optMaxEvents, self.flags.Exec.MaxEvents)
110  self.job.options().setString(ROOT.EL.Job.optSubmitDirMode, 'unique-link')
111  self.job.options().setDouble(ROOT.EL.Job.optSkipEvents, self.flags.Exec.SkipEvents)
112 
113  for alg in self.makeAlgSequence():
114  self.job.algsAdd(alg)
115  if self.args.merge_output_files:
116  self.job.options().setString(ROOT.EL.Job.optStreamAliases, "ANALYSIS=" + ROOT.EL.Job.histogramStreamName)
117  else:
118  self.job.outputAdd(ROOT.EL.OutputStream('ANALYSIS'))
119 
120  if self.args.run_perf_stat:
121  self.job.options().setBool(ROOT.EL.Job.optXAODPerfStats, 1)
122  if self.args.algorithm_timers:
123  self.job.options().setBool(ROOT.EL.Job.optAlgorithmTimer, 1)
124  if self.args.algorithm_memory_monitoring:
125  self.job.options().setBool(ROOT.EL.Job.optAlgorithmMemoryMonitor, 1)
126 
127  driver = ROOT.EL.DirectDriver() if self.args.direct_driver else ROOT.EL.ExecDriver()
128  self.driverSubmit(driver)
129  if self.args.work_dir is None: # move output if work_dir is not used
130  self.moveOutputFiles()

Member Data Documentation

◆ job

python.EventLoopCPRunScript.EventLoopCPRunScript.job

Definition at line 106 of file EventLoopCPRunScript.py.

◆ sampleHandler

python.EventLoopCPRunScript.EventLoopCPRunScript.sampleHandler

Definition at line 43 of file EventLoopCPRunScript.py.


The documentation for this class was generated from the following file:
configure
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: TrigGlobEffCorrValidation.cxx:514
python.AlgSequence.AlgSequence
AlgSequence
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py:7
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:58
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:378
calibdata.exit
exit
Definition: calibdata.py:235
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
str
Definition: BTagTrackIpAccessor.cxx:11
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87