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