ATLAS Offline Software
TrigInDetValidation_Base.py
Go to the documentation of this file.
1 #!/Usr/bin/env python
2 
3 # Slices = ['fsjet']
4 # Events = 10
5 # Threads = 1
6 # Slots = 1
7 # Input = 'ttbar' # defined in TrigValTools/share/TrigValInputs.json
8 # TrackReference = 'Truth'
9 
10 import re
11 
12 from TrigValTools.TrigValSteering import Test, CheckSteps
13 from TrigInDetValidation.TrigInDetArtSteps import TrigInDetReco, TrigInDetAna, TrigCostStep, TrigInDetRdictStep, TrigInDetCompStep, TrigInDetCpuCostStep
14 
15 import os,sys,getopt
16 
17 try:
18  opts, args = getopt.getopt(sys.argv[1:],"lcxptirmn:",["local","config"])
19 except getopt.GetoptError:
20  print("Usage: ")
21  print("-l | --local run locally with input file from art eos grid-input")
22  print("-x don't run athena or post post-processing, only plotting")
23  print("-m run cost monitoring plotting, even if -x is set")
24  print("-r run only ntuple building stage")
25  print("-p run post-processing, even if -x is set")
26  print("-n N run only on N events per job")
27  print("-c | --config run with config_only and print to a pkl file")
28  print("-t test steering, dry run for all steps")
29  print("-i force the dry AbortDryRun flag to be False")
30  print("")
31  sys.exit(1)
32 
33 Events_local = 0
34 local = False
35 exclude = False
36 costplot = False
37 postproc = False
38 testconfig = False
39 dry_run = False
40 runstuff = True
41 abort_dry_run = True
42 
43 
44 if "Art_type" not in locals(): Art_type = 'grid'
45 if "GridFiles" not in locals(): GridFiles=False
46 if "Malloc" not in locals(): Malloc=False
47 if "AbortDryRun" in locals(): abort_dry_run=AbortDryRun
48 
49 for opt,arg in opts:
50  if opt in ("-l", "--local"):
51  local=True
52  if opt=="-x":
53  exclude=True
54  if opt=="-p":
55  postproc=True
56  if opt=="-m":
57  costplot=True
58  if opt=="-n":
59  Events_local=int(arg)
60  if opt=="-r":
61  runstuff=False
62  if opt in ("-c", "--config"):
63  testconfig = True
64  if opt=="-t":
65  dry_run=True
66  if opt=="-i":
67  abort_dry_run=False
68 
69 vdry_run = os.environ.get('TRIGVALSTEERING_DRY_RUN')
70 
71 if vdry_run == '1':
72  dry_run=True
73 
74 
75 if 'postinclude_file' in dir() :
76  if 'preinclude_file' in dir() :
77  rdo2aod = TrigInDetReco( postinclude_file=postinclude_file, preinclude_file=preinclude_file )
78  else :
79  rdo2aod = TrigInDetReco( postinclude_file=postinclude_file )
80 else :
81  if 'preinclude_file' in dir() :
82  rdo2aod = TrigInDetReco( preinclude_file=preinclude_file )
83  else :
84  rdo2aod = TrigInDetReco()
85 
86 # test specific variables ...
87 
88 rdo2aod.slices = Slices
89 rdo2aod.threads = Threads
90 rdo2aod.concurrent_events = Slots
91 rdo2aod.config_only = testconfig
92 if 'Release' in dir():
93  rdo2aod.release = Release
94 
95 
96 if "Args" not in locals() :
97  Args = " "
98 
99 
100 # allow command line to override programed number of events to process
101 
102 if Events_local != 0 :
103  rdo2aod.max_events = Events_local
104 else :
105  rdo2aod.max_events = Events
106 
107 
108 rdo2aod.perfmon = False
109 rdo2aod.costmon = True
110 rdo2aod.timeout = 18*3600
111 rdo2aod.input = Input # defined in TrigValTools/share/TrigValInputs.json
112 
113 if GridFiles:
114  if local:
115  rdo2aod.input = Input # should match definition in TrigValTools/share/TrigValInputs.json
116  else:
117  rdo2aod.input = ''
118  rdo2aod.args += ' --inputRDOFile=$ArtInFile '
119 
120 # temporary conditions override: force MC23e global tag by default and Run4 global tag for Run4 inputs, until input RDOs are updated
121 from AthenaConfiguration.TestDefaults import defaultConditionsTags
122 
123 if "conditionsOverride" not in locals():
124  rdo2aod.args += f' --conditionsTag "default:{defaultConditionsTags.RUN3_MC}"'
125 elif conditionsOverride == "Run4":
126  rdo2aod.args += f' --conditionsTag "default:{defaultConditionsTags.RUN4_MC}"'
127 
128 
129 if (Malloc):
130  import os
131  os.environ["MALLOC_CHECK_"] = "3"
132  rdo2aod.malloc = True
133 
134 for a in ["preexec_trig", "preexec_reco", "preexec_all", "postexec_trig", "postexec_reco"]:
135  if a in locals():
136  v = locals()[a]
137  if type(v) is list: v = ";".join(v)
138  v0 = getattr (rdo2aod, a)
139  if v0 is None or v0 == "":
140  v0 = v
141  else:
142  v0 += ";"+v
143  setattr (rdo2aod, a, v0)
144 
145 # Run athena analysis to produce TrkNtuple
146 
147 test = Test.Test()
148 test.art_type = Art_type
149 
150 
151 if 'ExtraAna' not in locals() :
152  ExtraAna = None
153 aod_to_ntup = TrigInDetAna(extraArgs = ExtraAna)
154 
155 
156 rdo_to_cost = TrigCostStep()
157 
158 if dry_run:
159  if abort_dry_run:
160  sys.exit(0)
161  test.dry_run = True
162 if (not exclude):
163  if runstuff:
164  test.exec_steps = [rdo2aod, aod_to_ntup, rdo_to_cost]
165  else:
166  test.exec_steps = [aod_to_ntup]
167  test.check_steps = CheckSteps.default_check_steps(test)
168 
169 # Run TIDArdict
170 
171 if ((not exclude) or postproc ):
172  for job in Jobs :
173  if len(job) >= 3:
174  rdict = TrigInDetRdictStep( name=job[0], args=job[1], testbin=job[2], config=(testconfig or dry_run) )
175  else:
176  rdict = TrigInDetRdictStep( name=job[0], args=job[1], config=(testconfig or dry_run) )
177  print( "\n\033[0;32m TIDArdict "+job[1]+" \033[0m" )
178  test.check_steps.append(rdict)
179 
180 
181 
182 
183 
184 for _slice in Comp :
185  compstep = TrigInDetCompStep( name=_slice[0], slice=_slice[1], file=_slice[2], args=_slice[3] )
186  test.check_steps.append(compstep)
187 
188 # CPU cost steps
189 # cputest defined with "name" "output directory" "filename" "args"
190 cputest = [ ( "CpuCostStep1", " times ", "expert-monitoring.root", " --auto -p TIME" ),
191  ( "CpuCostStep2", " times-FTF ", "expert-monitoring.root", " --auto -p TIME -d TrigFastTrackFinder_" ),
192  ( "CpuCostStep3", " cost-perCall ", "TrigCostRoot_Results.root", " --auto -p _Time_perCall -d /Algorithm --logx " ),
193  ( "CpuCostStep4", " cost-perEvent ", "TrigCostRoot_Results.root", " --auto -p _Time_perEvent -d /Algorithm --logx " ),
194  ( "CpuCostStep5", " cost-perCall-chain ", "TrigCostRoot_Results.root", " --auto -p _Time_perCall -d /Chain_Algorithm --logx " ),
195  ( "CpuCostStep6", " cost-perEvent-chain ", "TrigCostRoot_Results.root", " --auto -p _Time_perEvent -d /Chain_Algorithm --logx " ) ]
196 
197 
198 if ((not exclude) or postproc or costplot ):
199  for job in cputest :
200  cpucost = TrigInDetCpuCostStep( name=job[0], outdir=job[1], infile=job[2], extra=job[3] )
201  test.check_steps.append(cpucost)
202 
203 
204 import sys
205 sys.exit(test.run())
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
beamspotman.dir
string dir
Definition: beamspotman.py:623
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78