ATLAS Offline Software
OverlayTestHelpers.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """Overlay test helpers
3 
4 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 """
6 
7 from argparse import ArgumentParser
8 from AthenaCommon.Debugging import DbgStage
9 from AthenaConfiguration.AutoConfigFlags import GetFileMD
10 from AthenaConfiguration.Enums import LHCPeriod
11 from AthenaConfiguration.JobOptsDumper import JobOptsDumperCfg
12 
13 
15  """Configure event loop for overlay"""
16  return JobOptsDumperCfg(flags, FileName="OverlayTestConfig.txt")
17 
18 
20  """Common overlay test argument parser"""
21  parser = ArgumentParser(prog=prog)
22  parser.add_argument("-d", "--data", default=False,
23  action="store_true", help="Run data overlay")
24  parser.add_argument("-n", "--maxEvents", default=3, type=int,
25  help="The number of events to run. 0 skips execution")
26  parser.add_argument("-t", "--threads", default=1, type=int,
27  help="The number of concurrent threads to run. 0 uses serial Athena.")
28  parser.add_argument("-p", "--processes", default=0, type=int,
29  help="The number of concurrent processes to run. 0 uses serial Athena.")
30  parser.add_argument("-c", "--concurrent", default=0, type=int,
31  help="The number of concurrent events to run. 0 uses the same as number of threads.")
32  parser.add_argument("-V", "--verboseAccumulators", default=False, action="store_true",
33  help="Print full details of the AlgSequence for each accumulator")
34  parser.add_argument("-S", "--verboseStoreGate", default=False, action="store_true",
35  help="Dump the StoreGate(s) each event iteration")
36  parser.add_argument("-o", "--output", default='', type=str,
37  help="Output RDO file")
38  parser.add_argument("-s", "--outputSig", default='', type=str,
39  help="Output RDO_SGNL file")
40  parser.add_argument("-r", "--run", default=LHCPeriod.Run2,
41  type=LHCPeriod, choices=list(LHCPeriod))
42  parser.add_argument("--disableTruth", default=False, action="store_true",
43  help="Disable truth overlay")
44  parser.add_argument("--debug", default='', type=str,
45  choices=DbgStage.allowed_values,
46  help="Debugging flag: " + ','.join (DbgStage.allowed_values))
47  return parser
48 
49 
50 def overlayTestFlags(flags, args):
51  """Fill default overlay flags for testing"""
52  if args.disableTruth:
53  flags.Digitization.EnableTruth = False
54 
55  from AthenaConfiguration.TestDefaults import defaultTestFiles, defaultConditionsTags
56  from AthenaConfiguration.Enums import ProductionStep
57  flags.Common.ProductionStep = ProductionStep.Overlay
58  if args.data:
59  flags.Input.isMC = False
60  flags.Input.Files = defaultTestFiles.HITS_DATA_OVERLAY
61  flags.Input.SecondaryFiles = defaultTestFiles.RAW_BKG
62  flags.Output.RDOFileName = "dataOverlayRDO.pool.root"
63  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN2_DATA
64  flags.IOVDb.DatabaseInstance = "CONDBR2"
65  flags.Overlay.DataOverlay = True
66  from Campaigns import DataOverlayPPTest
67  DataOverlayPPTest(flags)
68  else:
69  if args.run is LHCPeriod.Run2:
70  flags.Input.Files = defaultTestFiles.RDO_BKG_RUN2
71  flags.Input.SecondaryFiles = defaultTestFiles.HITS_RUN2
72  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN2_MC
73  from Campaigns import MC20e
74  MC20e(flags)
75  elif args.run is LHCPeriod.Run3:
76  flags.Input.Files = defaultTestFiles.RDO_BKG_RUN3
77  flags.Input.SecondaryFiles = defaultTestFiles.HITS_RUN3
78  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN3_MC
79  from Campaigns import MC23a
80  MC23a(flags)
81  elif args.run is LHCPeriod.Run4:
82  flags.Input.Files = defaultTestFiles.RDO_BKG_RUN4
83  flags.Input.SecondaryFiles = defaultTestFiles.HITS_RUN4
84  flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
85  from Campaigns import PhaseIIPileUp200
86  PhaseIIPileUp200(flags)
87  else:
88  raise ValueError("Run not supported")
89  flags.Input.MCChannelNumber = GetFileMD(flags.Input.SecondaryFiles, allowEmpty=False).get("mc_channel_number", 0)
90  flags.Output.RDOFileName = "mcOverlayRDO.pool.root"
91  flags.Overlay.DataOverlay = False
92 
93  if args.output:
94  if args.output == 'None':
95  flags.Output.RDOFileName = ''
96  else:
97  flags.Output.RDOFileName = args.output
98 
99  if args.outputSig:
100  flags.Output.RDO_SGNLFileName = args.outputSig
101 
102  if 'detectors' in args and args.detectors:
103  detectors = args.detectors
104  else:
105  detectors = None
106 
107  from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
108  setupDetectorFlags(flags, detectors, toggle_geometry=True, use_metadata=True)
109 
110  # Moving here so that it is ahead of flags being locked. Need to
111  # iterate on exact best position w.r.t. above calls
112  from OverlayConfiguration.OverlayMetadata import overlayMetadataCheck
113  # Handle metadata correctly
114  overlayMetadataCheck(flags)
115 
116 
117 def postprocessAndLockFlags(flags, args):
118  """Postprocess and lock config flags for overlay"""
119  flags.Concurrency.NumThreads = args.threads
120  flags.Concurrency.NumProcs = args.processes
121  if args.threads > 0:
122  flags.Scheduler.ShowDataDeps = True
123  flags.Scheduler.ShowDataFlow = True
124  flags.Scheduler.ShowControlFlow = True
125  flags.Concurrency.NumConcurrentEvents = args.concurrent if args.concurrent > 0 else args.threads
126 
127  flags.lock()
128 
129 
130 def printAndRun(accessor, flags, args):
131  """Common debugging and execution for overlay tests"""
132  # Dump config
133  accessor.printConfig(withDetails=args.verboseAccumulators)
134  if args.verboseStoreGate:
135  accessor.getService("StoreGateSvc").Dump = True
136  flags.dump()
137 
138  if args.debug:
139  accessor.setDebugStage (args.debug)
140 
141  # Execute and finish
142  sc = accessor.run(maxEvents=args.maxEvents)
143 
144  # Success should be 0
145  return not sc.isSuccess()
python.MC23.MC23a
def MC23a(flags)
Definition: MC23.py:6
python.OverlayTestHelpers.postprocessAndLockFlags
def postprocessAndLockFlags(flags, args)
Definition: OverlayTestHelpers.py:117
python.JobOptsDumper.JobOptsDumperCfg
def JobOptsDumperCfg(flags, FileName="JobOptsConfig.txt")
Definition: JobOptsDumper.py:6
python.OverlayTestHelpers.OverlayJobOptsDumperCfg
def OverlayJobOptsDumperCfg(flags)
Definition: OverlayTestHelpers.py:14
python.OverlayMetadata.overlayMetadataCheck
def overlayMetadataCheck(flags)
Definition: OverlayMetadata.py:193
python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True)
Definition: AutoConfigFlags.py:51
python.OverlayTestHelpers.printAndRun
def printAndRun(accessor, flags, args)
Definition: OverlayTestHelpers.py:130
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.DetectorConfigFlags.setupDetectorFlags
def setupDetectorFlags(flags, custom_list=None, use_metadata=False, toggle_geometry=False, validate_only=False, keep_beampipe=False)
Definition: DetectorConfigFlags.py:289
python.MC20.MC20e
def MC20e(flags)
Definition: MC20.py:63
python.DataOverlayRun2.DataOverlayPPTest
def DataOverlayPPTest(flags)
Definition: DataOverlayRun2.py:3
python.PhaseII.PhaseIIPileUp200
def PhaseIIPileUp200(flags)
Definition: PhaseII.py:81
python.OverlayTestHelpers.overlayTestFlags
def overlayTestFlags(flags, args)
Definition: OverlayTestHelpers.py:50
python.OverlayTestHelpers.CommonTestArgumentParser
def CommonTestArgumentParser(prog)
Definition: OverlayTestHelpers.py:19
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127