ATLAS Offline Software
scheduler.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon import Logging
4 from functools import partial
5 from . import generators
6 from . import postprocessors
7 from . import preprocessors
8 
9 
10 
11 logger = Logging.logging.getLogger("PowhegControl")
12 
13 
15  """! Schedule algorithms in appropriate order.
16 
17  @author James Robinson <james.robinson@cern.ch>
18  """
19 
20 
21  powheg_LHE_output = "pwgevents.lhe"
22 
23 
24  ordered_preprocessors = ["directory cleaner", "reweighter"]
25 
26 
27  ordered_event_generators = ["singlecore", "multicore", "merge output", "output validation"]
28 
29 
30  ordered_postprocessors = [
31  "quark colour fixer",
32  "PHOTOS",
33  "reweighter", "NNLO reweighter",
34  "LHE ubexcess_correct weight updater",
35  "LHE file nominal weight updater",
36  "mu2tau",
37  "mu2e",
38  "e2tau",
39  "e2mu",
40  "gg4l_emu2all",
41  "MadSpin",
42  "integration grid tester",
43  "cross section calculator",
44  "LHE file cleaner",
45  "output file renamer",
46  "output tarball preparer",
47  "integration gridpack creator",
48  "directory cleaner",
49  ]
50 
51 
52  preprocessor_fn_dict = {
53  "directory cleaner": preprocessors.directory_cleaner,
54  "reweighter": preprocessors.reweighter
55  }
56 
57 
58  generator_fn_dict = {
59  "merge output": partial(generators.merge_output, powheg_LHE_output=powheg_LHE_output),
60  "multicore": generators.multicore,
61  "output validator": partial(generators.output_validator, powheg_LHE_output=powheg_LHE_output),
62  "singlecore": generators.singlecore
63  }
64 
65 
66  postprocessor_fn_dict = {
67  "cross section calculator": partial(postprocessors.cross_section_calculator, powheg_LHE_output=powheg_LHE_output),
68  "directory cleaner": postprocessors.directory_cleaner,
69  "integration gridpack creator": postprocessors.integration_gridpack_creator,
70  "integration grid tester": postprocessors.integration_grid_tester,
71  "MadSpin": partial(postprocessors.MadSpin, powheg_LHE_output=powheg_LHE_output),
72  "NNLO reweighter": partial(postprocessors.NNLO_reweighter, powheg_LHE_output=powheg_LHE_output),
73  "output file renamer": partial(postprocessors.output_file_renamer, powheg_LHE_output=powheg_LHE_output),
74  "output tarball preparer": postprocessors.output_tarball_preparer,
75  "PHOTOS": partial(postprocessors.PHOTOS, powheg_LHE_output=powheg_LHE_output),
76  "reweighter": partial(postprocessors.reweighter, powheg_LHE_output=powheg_LHE_output),
77  "quark colour fixer": partial(postprocessors.quark_colour_fixer, powheg_LHE_output=powheg_LHE_output),
78  "mu2tau": partial(postprocessors.mu2tau, powheg_LHE_output=powheg_LHE_output),
79  "mu2e": partial(postprocessors.mu2e, powheg_LHE_output=powheg_LHE_output),
80  "e2tau": partial(postprocessors.e2tau, powheg_LHE_output=powheg_LHE_output),
81  "e2mu": partial(postprocessors.e2mu, powheg_LHE_output=powheg_LHE_output),
82  "gg4l_emu2all": partial(postprocessors.gg4l_emu2all, powheg_LHE_output=powheg_LHE_output),
83  "LHE file cleaner": partial(postprocessors.lhe_cleaner, powheg_LHE_output=powheg_LHE_output),
84  "LHE file nominal weight updater": partial(postprocessors.lhe_nominal_weight_updater, powheg_LHE_output=powheg_LHE_output),
85  "LHE ubexcess_correct weight updater": partial(postprocessors.lhe_ubexcess_correct_reweighter, powheg_LHE_output=powheg_LHE_output),
86  }
87 
88  def __init__(self):
89  """! Constructor."""
90 
91  self.sequence = {"preprocessors": {}, "generators": {}, "postprocessors": {}}
92 
93  # Add universal components
94  self.add("output validator")
95  self.add("integration grid tester")
96  self.add("LHE file cleaner")
97 
98  def add(self, name, *args):
99  """! Add a component to the sequence.
100 
101  @param name name of component to add.
102  @param args arguments to pass to this component when it runs.
103  """
104  if name in self.ordered_preprocessors:
105  if name not in self.sequence["preprocessors"].keys():
106  self.sequence["preprocessors"][name] = args
107 
108  if name in self.ordered_event_generators:
109  if name not in self.sequence["generators"].keys():
110  self.sequence["generators"][name] = args
111 
112  if name in self.ordered_postprocessors:
113  if name not in self.sequence["postprocessors"].keys():
114  self.sequence["postprocessors"][name] = args
115 
116  def print_structure(self):
117  """! Print the sequence to the logger."""
118  logger.info("Scheduling the following PowhegControl sequence:")
119  logger.info("|---+ Preprocessing:")
120  for name in sorted(self.sequence["preprocessors"].keys(), key=lambda x: self.ordered_preprocessors.index(x)):
121  logger.info(" |--- {}".format(name))
122  logger.info("|---+ Event generation:")
123  for name in sorted(self.sequence["generators"].keys(), key=lambda x: self.ordered_event_generators.index(x)):
124  logger.info(" |--- {}".format(name))
125  logger.info("|---+ Postprocessing:")
126  for name in sorted(self.sequence["postprocessors"].keys(), key=lambda x: self.ordered_postprocessors.index(x)):
127  logger.info(" |--- {}".format(name))
128 
129  def run_preprocessors(self):
130  """! Run all preprocessors in order."""
131  for name in filter(lambda x: x in self.sequence["preprocessors"].keys(), self.ordered_preprocessors):
132  self.preprocessor_fn_dict[name](*self.sequence["preprocessors"][name])
133 
134  def run_generators(self):
135  """! Run all event generators in order."""
136  for name in filter(lambda x: x in self.sequence["generators"].keys(), self.ordered_event_generators):
137  self.generator_fn_dict[name](*self.sequence["generators"][name])
138 
140  """! Run all postprocessors in order."""
141  for name in filter(lambda x: x in self.sequence["postprocessors"].keys(), self.ordered_postprocessors):
142  self.postprocessor_fn_dict[name](*self.sequence["postprocessors"][name])
vtune_athena.format
format
Definition: vtune_athena.py:14
index
Definition: index.py:1
python.algorithms.scheduler.Scheduler.ordered_postprocessors
list ordered_postprocessors
Postprocessing evaluation order.
Definition: scheduler.py:30
python.algorithms.scheduler.Scheduler.postprocessor_fn_dict
dictionary postprocessor_fn_dict
Map postprocessing names to functions.
Definition: scheduler.py:66
python.algorithms.scheduler.Scheduler
Schedule algorithms in appropriate order.
Definition: scheduler.py:14
python.algorithms.scheduler.Scheduler.generator_fn_dict
dictionary generator_fn_dict
Map event generation names to functions.
Definition: scheduler.py:58
python.algorithms.scheduler.Scheduler.sequence
sequence
Sequence of functions to run.
Definition: scheduler.py:91
python.algorithms.scheduler.Scheduler.__init__
def __init__(self)
Constructor.
Definition: scheduler.py:88
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.algorithms.scheduler.Scheduler.add
def add(self, name, *args)
Add a component to the sequence.
Definition: scheduler.py:98
python.algorithms.scheduler.Scheduler.run_postprocessors
def run_postprocessors(self)
Run all postprocessors in order.
Definition: scheduler.py:139
python.algorithms.scheduler.Scheduler.ordered_event_generators
list ordered_event_generators
Event generation evaluation order.
Definition: scheduler.py:27
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.algorithms.scheduler.Scheduler.ordered_preprocessors
list ordered_preprocessors
Preprocessing evaluation order.
Definition: scheduler.py:24
python.algorithms.scheduler.Scheduler.run_generators
def run_generators(self)
Run all event generators in order.
Definition: scheduler.py:134
python.algorithms.scheduler.Scheduler.preprocessor_fn_dict
dictionary preprocessor_fn_dict
Map preprocessing names to functions.
Definition: scheduler.py:52
pickleTool.object
object
Definition: pickleTool.py:30
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
python.algorithms.scheduler.Scheduler.print_structure
def print_structure(self)
Print the sequence to the logger.
Definition: scheduler.py:116
python.algorithms.scheduler.Scheduler.run_preprocessors
def run_preprocessors(self)
Run all preprocessors in order.
Definition: scheduler.py:129