ATLAS Offline Software
Loading...
Searching...
No Matches
athenaHLT Namespace Reference

Classes

class  MyHelp

Functions

str arg_sor_time (s)
 The following arg_* methods are used as custom types in argparse.
 arg_detector_mask (s)
 arg_ros2rob (s)
 arg_log_level (s)
 arg_eval (s)
 check_args (parser, args)
 update_pcommands (args, cdict)
 update_run_params (args, flags)
 update_trigconf_keys (args, flags)
 update_nested_dict (d, u)
 HLTMPPy_cfgdict (args)
 main ()

Variables

 log = logging.getLogger('athenaHLT')

Detailed Description

date"

# defaults
export USETCMALLOC=1
export USEIMF=1

# parse command line arguments
for a in ${@}
do
    case "$a" in
        --stdcmalloc)    USETCMALLOC=0;;
        --tcmalloc)      USETCMALLOC=1;;
        --stdcmath)      USEIMF=0;;
        --imf)           USEIMF=1;;
        --preloadlib*)   export ATHENA_ADD_PRELOAD=${a#*=};;
        --no-ers-signal-handlers)  export TDAQ_ERS_NO_SIGNAL_HANDLERS=1;;
    esac
done

# Do the actual preloading via LD_PRELOAD
source `which athena_preload.sh `

# Now resurrect ourselves as python script
python_path=`which python`
"exec" "$python_path" "-tt" "$0" "$@";

Function Documentation

◆ arg_detector_mask()

athenaHLT.arg_detector_mask ( s)
Convert detector mask to format expected by eformat

Definition at line 70 of file athenaHLT.py.

70def arg_detector_mask(s):
71 """Convert detector mask to format expected by eformat"""
72 if s=='all':
73 return 'f'*32
74 dmask = hex(int(s,16)) # Normalize input to hex-string
75 dmask = dmask.lower().replace('0x', '').replace('l', '') # remove markers
76 return '0' * (32 - len(dmask)) + dmask # (pad with 0s)
77
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310

◆ arg_eval()

athenaHLT.arg_eval ( s)
Argument handler for python types (list, dict, ...)

Definition at line 103 of file athenaHLT.py.

103def arg_eval(s):
104 """Argument handler for python types (list, dict, ...)"""
105 return ast.literal_eval(s)
106

◆ arg_log_level()

athenaHLT.arg_log_level ( s)
Argument handler for log levels

Definition at line 97 of file athenaHLT.py.

97def arg_log_level(s):
98 """Argument handler for log levels"""
99 lvls = s.split(',')
100 if len(lvls)==1: lvls.append('ERROR')
101 return lvls
102

◆ arg_ros2rob()

athenaHLT.arg_ros2rob ( s)
Handle an explicit dictionary or read it from a file

Definition at line 78 of file athenaHLT.py.

78def arg_ros2rob(s):
79 """Handle an explicit dictionary or read it from a file"""
80 try:
81 with open(s) as f:
82 s = f.read() # If file exists, replace ros2rob with content of the file
83 print("Reading ros2rob from a file")
84 except IOError:
85 pass
86
87 try:
88 ros2robdict = arg_eval(s)
89 if type(ros2robdict) is not dict:
90 raise(ValueError)
91 return ros2robdict
92 except Exception:
93 sys.stderr.write("ERROR! ros2rob cannot be evaluated as it is not a proper python dictionary: {}\n".format(s))
94 sys.stderr.write("Using empty ros2rob dictionary instead\n")
95 return {}
96
void print(char *figname, TCanvas *c1)

◆ arg_sor_time()

str athenaHLT.arg_sor_time ( s)

The following arg_* methods are used as custom types in argparse.

Convert possible SOR time arguments to an OWLTime compatible string

Definition at line 63 of file athenaHLT.py.

63def arg_sor_time(s) -> str:
64 """Convert possible SOR time arguments to an OWLTime compatible string"""
65 fmt = '%d/%m/%y %H:%M:%S.%f'
66 if s=='now': return dt.now().strftime(fmt)
67 elif s.isdigit(): return dt.fromtimestamp(float(s)/1e9).strftime(fmt)
68 else: return s
69

◆ check_args()

athenaHLT.check_args ( parser,
args )
Consistency check of command line arguments

Definition at line 107 of file athenaHLT.py.

107def check_args(parser, args):
108 """Consistency check of command line arguments"""
109
110 if not args.jobOptions and not args.use_database:
111 parser.error("No job options file specified")
112
113 # Due to missing per-worker dirs this is not supported (ATR-19462)
114 if args.perfmon and args.oh_monitoring and args.nprocs>1:
115 parser.error("--perfmon cannot be used with --oh-monitoring and --nprocs > 1")
116
117 if not args.file and not args.dump_config_exit:
118 parser.error("--file is required unless using --dump-config-exit")
119
120 if args.use_crest and not args.use_database:
121 parser.error("--use-database is required when using --use-crest")
122

◆ HLTMPPy_cfgdict()

athenaHLT.HLTMPPy_cfgdict ( args)
Create the configuration dictionary as expected by HLTMPPy as defined in
https://gitlab.cern.ch/atlas-tdaq-software/HLTMPPU/blob/master/python/HLTMPPy/runner.py

Definition at line 197 of file athenaHLT.py.

197def HLTMPPy_cfgdict(args):
198 """Create the configuration dictionary as expected by HLTMPPy as defined in
199 https://gitlab.cern.ch/atlas-tdaq-software/HLTMPPU/blob/master/python/HLTMPPy/runner.py"""
200
201 cdict = {}
202 # Composing unique application name from hostname, PID, and timestamp. See ATR-31976
203 host = os.uname().nodename.split('.')[0]
204 pid = os.getpid()
205 ts = dt.now().strftime('%Y%m%dT%H%M%S.%f')[:-3]
206 cdict['HLTMPPU'] = {
207 'application_name' : 'athenaHLT-%s-%d-%s' % (host, pid, ts),
208 'extra_params' : ["dumpFDs=1", "dumpThreads=1"] if args.debug_fork else None,
209 'interactive' : args.interactive,
210 'log_root' : os.getcwd(),
211 'log_name' : ('' if args.unique_log_files else 'athenaHLT:'),
212 'module' : 'HLTMPPU',
213 'num_forks' : args.nprocs,
214 'num_threads' : args.threads,
215 'num_slots' : args.concurrent_events,
216 'partition_name' : args.partition,
217 'hard_timeout' : args.timeout,
218 'soft_timeout_fraction' : 0.95,
219 'hltresultSizeMb': args.hltresult_size
220 }
221 if args.debug:
222 cdict['HLTMPPU']['debug'] = args.debug
223 if args.script_after_fork:
224 cdict['HLTMPPU']['scriptAfterFork'] = args.script_after_fork
225
226 if args.file:
227 cdict['datasource'] = {
228 'module': 'dffileds',
229 'dslibrary': 'DFDcmEmuBackend',
230 'compressionFormat': 'ZLIB',
231 'compressionLevel': 2,
232 'file': args.file,
233 'loopFiles': args.loop_files,
234 'numEvents': args.number_of_events,
235 'outFile': args.save_output,
236 'preload': False,
237 'extraL1Robs': args.extra_l1r_robs,
238 'skipEvents': args.skip_events
239 }
240 else:
241 cdict['datasource'] = {'module': 'dcmds'}
242
243 cdict['global'] = {
244 'date': args.sor_time,
245 'detector_mask': args.detector_mask,
246 'log_root': cdict['HLTMPPU']['log_root'],
247 'options_file': None,
248 'partition_name': args.partition,
249 'ros2robs': args.ros2rob,
250 'run_number': args.run_number,
251 'save_options': None,
252 'solenoid_current': 7730,
253 'toroid_current': 20400,
254 'schema_files': ['Larg.LArNoiseBurstCandidates.is.schema.xml'],
255 'with_infrastructure': args.oh_monitoring
256 }
257
258 if not args.file:
259 cdict['global']['trigger_type'] = ''
260 cdict['global']['detector_mask'] = 'f'*32
261 cdict['global']['beam_type'] = 0
262 cdict['global']['beam_energy'] = 0
263 cdict['global']['T0_project_tag'] = ''
264
265 if args.oh_monitoring:
266 cdict['monitoring'] = {
267 'module': 'monsvcis',
268 'library': 'MonSvcInfoService',
269 'ISInterval': 10,
270 'ISRegex': '.*',
271 'ISServer': '${TDAQ_IS_SERVER=DF}',
272 'ISSlots': 1,
273 'OHInterval': args.oh_interval,
274 'OHInclude': '.*',
275 'OHExclude': '',
276 'OHServerName': 'HLT-Histogramming',
277 'OHSlots': 5
278 }
279
280 cdict['trigger'] = {
281 'library': ['TrigPSC'],
282 'joType' : args.joboptionsvc_type,
283 'msgType' : args.msgsvc_type
284 }
285 if not args.use_database:
286 cdict['trigger'].update({
287 'module': 'joboptions',
288 'joFile': args.jobOptions,
289 'SMK': None,
290 'l1PSK': None,
291 'l1BG': 0,
292 'l1MenuConfig': 'DB',
293 'precommand' : args.precommand,
294 'postcommand' : args.postcommand,
295 'logLevels' : args.log_level
296 })
297 # Python bootstrap depending on file type
298 cdict['trigger']['pythonSetupFile'] = 'TrigPSC.TrigPSCPythonDbSetup' if \
299 args.jobOptions.endswith('.json') else 'TrigPSC.TrigPSCPythonCASetup'
300
301 else:
302 if args.use_crest:
303 crestconn: str | None = TriggerCrestUtil.getCrestConnection(args.db_server)
304 dbalias: str = f"{args.crest_server}/{crestconn}"
305 else:
306 dbalias = args.db_server
307 cdict['trigger'].update({
308 'module': 'DBPython',
309 'pythonSetupFile' : 'TrigPSC.TrigPSCPythonDbSetup',
310 'db_alias': dbalias,
311 'coral_server': args.db_server,
312 'use_coral': True,
313 'crest_server': args.crest_server,
314 'use_crest': args.use_crest,
315 'SMK': args.smk,
316 'l1PSK': args.l1psk,
317 'HLTPSK': args.hltpsk,
318 'l1BG': 0,
319 'l1MenuConfig': 'DB',
320 'precommand' : args.precommand,
321 'postcommand' : args.postcommand,
322 'logLevels' : args.log_level
323 })
324
325 return cdict
326
327

◆ main()

athenaHLT.main ( )

Definition at line 343 of file athenaHLT.py.

343def main():
344 parser = argparse.ArgumentParser(prog='athenaHLT.py', formatter_class=
345 lambda prog : argparse.ArgumentDefaultsHelpFormatter(prog, max_help_position=32, width=100),
346 usage = '%(prog)s [OPTION]... -f FILE jobOptions',
347 add_help=False)
348 parser.expert_groups = [] # Keep list of expert option groups
349
350
351 g = parser.add_argument_group('Options')
352 g.add_argument('jobOptions', nargs='?', help='job options, CA module or JSON file')
353 g.add_argument('--threads', metavar='N', type=int, default=1, help='number of threads')
354 g.add_argument('--nprocs', metavar='N', type=int, default=1, help='number of children to fork')
355 g.add_argument('--concurrent-events', metavar='N', type=int, help='number of concurrent events if different from --threads')
356 g.add_argument('--log-level', '-l', metavar='LVL', type=arg_log_level, default='INFO,ERROR', help='OutputLevel of athena,POOL')
357 g.add_argument('--precommand', '-c', metavar='CMD', action='append', default=[],
358 help='Python commands executed before job options or database configuration')
359 g.add_argument('--postcommand', '-C', metavar='CMD', action='append', default=[],
360 help='Python commands executed after job options or database configuration')
361 g.add_argument('--interactive', '-i', action='store_true', help='interactive mode')
362 g.add_argument('--help', '-h', nargs='?', choices=['all'], action=MyHelp, help='show help')
363
364 g = parser.add_argument_group('Input/Output')
365 g.add_argument('--file', '--filesInput', '-f', action='append', help='input RAW file')
366 g.add_argument('--save-output', '-o', metavar='FILE', help='output file name')
367 g.add_argument('--number-of-events', '--evtMax', '-n', metavar='N', type=int, default=-1, help='processes N events (<=0 means all)')
368 g.add_argument('--skip-events', '--skipEvents', '-k', metavar='N', type=int, default=0, help='skip N first events')
369 g.add_argument('--loop-files', action='store_true', help='loop over input files if no more events')
370
371
372 g = parser.add_argument_group('Performance and debugging')
373 g.add_argument('--debug', '-d', nargs='?', const='child', choices=['parent','child'],
374 help='attach debugger (to child by default)')
375 g.add_argument('--script-after-fork', metavar='CMD', help='Execute a command after forking. The command has to be in the'
376 ' form "whichProc:cmd" where whichProc is one of [mother,firstFork,allForks] and cmd can contain a format'
377 ' string {pid} which will be replaced with the PID of the corresponding process (mother or fork).')
378 g.add_argument('--perfmon', action='store_true', help='enable PerfMon')
379 g.add_argument('--tcmalloc', action='store_true', default=True, help='use tcmalloc')
380 g.add_argument('--stdcmalloc', action='store_true', help='use stdcmalloc')
381 g.add_argument('--stdcmath', action='store_true', help='use stdcmath library')
382 g.add_argument('--imf', action='store_true', default=True, help='use Intel math library')
383 g.add_argument('--show-includes', '-s', action='store_true', help='show printout of included files')
384 g.add_argument('--timeout', metavar='MSEC', default=60*60*1000, help='timeout in milliseconds')
385
386
387 g = parser.add_argument_group('Database')
388 g.add_argument('--use-database', '-b', action='store_true',
389 help='configure from trigger database, reading keys from conditions DB if not specified')
390 g.add_argument('--db-server', metavar='DB', default='TRIGGERDB_RUN3', help='DB server name')
391 g.add_argument('--use-crest', action='store_true', help='Use Crest when reading the trigger configuration')
392 g.add_argument('--crest-server', help='Crest server for reading trigger configuration, if not specified it uses the one that is used for condition access')
393 g.add_argument('--smk', type=int, default=None, help='Super Master Key')
394 g.add_argument('--l1psk', type=int, default=None, help='L1 prescale key')
395 g.add_argument('--hltpsk', type=int, default=None, help='HLT prescale key')
396 g.add_argument('--dump-config', action='store_true', help='Dump joboptions JSON file')
397 g.add_argument('--dump-config-exit', action='store_true', help='Dump joboptions JSON file and exit')
398
399
400 g = parser.add_argument_group('Online Histogramming')
401 g.add_argument('--oh-monitoring', '-M', action='store_true',
402 help='enable OH monitoring')
403 g.add_argument('--oh-interval', metavar='SEC', type=int, default=5,
404 help='seconds between histogram publications.')
405
406
407 g = parser.add_argument_group('Conditions')
408 g.add_argument('--run-number', '-R', metavar='RUN', type=int,
409 help='run number (if None, read from first event)')
410 g.add_argument('--lb-number', '-L', metavar='LBN', type=int,
411 help='lumiblock number (if None, read from first event)')
412 g.add_argument('--sor-time', type=arg_sor_time,
413 help='The Start Of Run time. Three formats are accepted: '
414 '1) the string "now", for current time; '
415 '2) the number of nanoseconds since epoch (e.g. 1386355338658000000 or int(time.time() * 1e9)); '
416 '3) human-readable "20/11/18 17:40:42.3043". If not specified the sor-time is read from the conditions DB')
417 g.add_argument('--detector-mask', metavar='MASK', type=arg_detector_mask,
418 help='detector mask (if None, read from the conditions DB), use string "all" to enable all detectors')
419
420
421 g = parser.add_argument_group('Expert')
422 parser.expert_groups.append(g)
423 g.add_argument('--joboptionsvc-type', metavar='TYPE', default='TrigConf::JobOptionsSvc', help='JobOptionsSvc type')
424 g.add_argument('--msgsvc-type', metavar='TYPE', default='TrigMessageSvc', help='MessageSvc type')
425 g.add_argument('--partition', '-p', metavar='NAME', default='athenaHLT', help='partition name')
426 g.add_argument('--no-ers-signal-handlers', action='store_true', help='disable ERS signal handlers')
427 g.add_argument('--preloadlib', metavar='LIB', help='preload an arbitrary library')
428 g.add_argument('--unique-log-files', '-ul', action='store_true', help='add pid/timestamp to worker log files')
429 g.add_argument('--debug-fork', action='store_true', help='Dump open files/threads during forking')
430 g.add_argument('--hltresult-size', metavar='MB', type=int, default=10, help='Maximum HLT result size in MB')
431 g.add_argument('--extra-l1r-robs', metavar='ROBS', type=arg_eval, default=[],
432 help='List of additional ROB IDs that are considered part of the L1 result and passed to the HLT')
433 g.add_argument('--ros2rob', metavar='DICT', type=arg_ros2rob, default={},
434 help='Either a string in the form of python dictionary that contains ros-rob mappings '
435 'or a file path that contains such string. For example, /path/to/rosmap.txt or '
436 '{"ROS0":[0x11205,0x11206],"ROS1":[2120005,2120006]}')
437 g.add_argument('--cfgdict', metavar='DICT', type=arg_eval, default={},
438 help='HLTMPPy config dictionary with additional options, e.g.: '
439 '--cfgdict \'{"global": {"log_root" : "/tmp"}}\'')
440
441 (args, unparsed_args) = parser.parse_known_args()
442 check_args(parser, args)
443
444 # set ROOT to batch mode (ATR-21890)
445 from ROOT import gROOT
446 gROOT.SetBatch()
447
448 # set default OutputLevels and file inclusion
449 import AthenaCommon.Logging
450 AthenaCommon.Logging.log.setLevel(getattr(logging, args.log_level[0]))
451 AthenaCommon.Logging.log.setFormat("%(asctime)s Py:%(name)-31s %(levelname)7s %(message)s")
452 if args.show_includes:
453 from AthenaCommon.Include import include
454 include.setShowIncludes( True )
455
456 # consistency checks for arguments
457 if not args.concurrent_events:
458 args.concurrent_events = args.threads
459
460 if args.loop_files and args.number_of_events<0:
461 log.warning("Looping over files without specifying number of events will run forever!")
462
463 # interactive mode only becomes active after python configuration/reload:
464 if args.interactive and not (args.use_database or args.jobOptions.endswith('.json')):
465 args.interactive = False
466
467 # Update args and set athena flags
468 from TrigPSC import PscConfig
469
470 # Extra Psc configuration
471 from TrigPSC.PscDefaultFlags import defaultOnlineFlags
472 flags = defaultOnlineFlags()
473
474 log.info(f"Using Crest for trigger configuration: {args.use_crest}")
475 if args.use_crest:
476 flags.Trigger.useCrest = True
477 if args.crest_server:
478 flags.Trigger.crestServer = args.crest_server
479 else:
480 args.crest_server = flags.Trigger.crestServer
481
482 update_run_params(args, flags)
483
484 if args.use_database:
485 # If HLTPSK was given on the command line, we ignore what is stored in the conditions DB
486 PscConfig.forcePSK = (args.hltpsk is not None)
487 # We always read the keys corresponding to the run/LB in the first file
488 update_trigconf_keys(args, flags)
489
490 # get HLTMPPY config dictionary
491 cdict = HLTMPPy_cfgdict(args)
492
493 # Apply any expert-level overrides
494 update_nested_dict(cdict, args.cfgdict)
495
496 # Modify pre/postcommands if necessary
497 update_pcommands(args, cdict)
498
499 # Fill flags from command line (if not running from DB/JSON):
500 if not args.use_database and not args.jobOptions.endswith('.json'):
501 PscConfig.unparsedArguments = unparsed_args
502 for flag_arg in unparsed_args:
503 flags.fillFromString(flag_arg)
504
505 PscConfig.interactive = args.interactive
506 PscConfig.exitAfterDump = args.dump_config_exit
507
508 flags.PerfMon.doFastMonMT = args.perfmon
509 flags.Trigger.Online.useOnlineTHistSvc = args.oh_monitoring
510
511 # Run HLTMPPU
512 from HLTMPPy.runner import runHLTMPPy
513 runHLTMPPy(cdict)
514
515
int main()
Definition hello.cxx:18

◆ update_nested_dict()

athenaHLT.update_nested_dict ( d,
u )
Update nested dictionary (https://stackoverflow.com/q/3232943)

Definition at line 188 of file athenaHLT.py.

188def update_nested_dict(d, u):
189 """Update nested dictionary (https://stackoverflow.com/q/3232943)"""
190 for k, v in u.items():
191 if isinstance(v, collections.abc.Mapping):
192 d[k] = update_nested_dict(d.get(k, {}), v)
193 else:
194 d[k] = v
195 return d
196

◆ update_pcommands()

athenaHLT.update_pcommands ( args,
cdict )
Apply modifications to pre/postcommands

Definition at line 123 of file athenaHLT.py.

123def update_pcommands(args, cdict):
124 """Apply modifications to pre/postcommands"""
125
126 if args.run_number is not None:
127 cdict['trigger']['precommand'].append('_run_number=%d' % args.run_number)
128 if args.lb_number is not None:
129 cdict['trigger']['precommand'].append('_lb_number=%d' % args.lb_number)
130

◆ update_run_params()

athenaHLT.update_run_params ( args,
flags )
Update run parameters from file or conditions DB

Definition at line 131 of file athenaHLT.py.

131def update_run_params(args, flags):
132 """Update run parameters from file or conditions DB"""
133
134 if (args.run_number and not args.lb_number) or (not args.run_number and args.lb_number):
135 log.error("Both or neither of the options -R (--run-number) and -L (--lb-number) have to be specified")
136
137 if args.run_number is None and args.file:
138 from eformat import EventStorage
139 dr = EventStorage.pickDataReader(args.file[0])
140 args.run_number = dr.runNumber()
141 args.lb_number = dr.lumiblockNumber()
142
143 sor_params: dict[str, Any] | None = None
144 if (args.sor_time is None or args.detector_mask is None) and args.run_number is not None:
145 if flags.Trigger.useCrest:
146 sor_params = AthHLT.get_eor_params_crest(args.run_number, flags.Trigger.crestServer)
147 else:
148 sor_params = AthHLT.get_sor_params(args.run_number)
149 log.debug('SOR parameters: %s', sor_params)
150 if sor_params is None:
151 log.error("Run %d does not exist. If you want to use this run-number specify "
152 "remaining run parameters, e.g.: --sor-time=now --detector-mask=all", args.run_number)
153 sys.exit(1)
154
155 if args.sor_time is None and sor_params is not None:
156 args.sor_time = arg_sor_time(str(sor_params['SORTime']))
157
158 if args.detector_mask is None and sor_params is not None:
159 dmask = sor_params['DetectorMask']
160 if args.run_number < AthHLT.CondDB._run2:
161 dmask = hex(dmask)
162 args.detector_mask = arg_detector_mask(dmask)
163

◆ update_trigconf_keys()

athenaHLT.update_trigconf_keys ( args,
flags )
Update trigger configuration keys

Definition at line 164 of file athenaHLT.py.

164def update_trigconf_keys(args, flags):
165 """Update trigger configuration keys"""
166
167 if args.smk is None or args.l1psk is None or args.hltpsk is None:
168 if flags.Trigger.useCrest:
169 log.info("Reading trigger configuration keys from CREST for run %s", args.run_number)
170 trigconf = AthHLT.get_trigconf_keys_crest(args.run_number, args.lb_number, flags.Trigger.crestServer)
171 log.info(f"Retrived these trigger keys from CREST: {trigconf}")
172 else:
173 log.info("Reading trigger configuration keys from COOL for run %s", args.run_number)
174 trigconf = AthHLT.get_trigconf_keys(args.run_number, args.lb_number)
175 log.info(f"Retrived these trigger keys from COOL: {trigconf}")
176
177 try:
178 if args.smk is None:
179 args.smk = trigconf['SMK']
180 if args.l1psk is None:
181 args.l1psk = trigconf['LVL1PSK']
182 if args.hltpsk is None:
183 args.hltpsk = trigconf['HLTPSK']
184 except KeyError:
185 log.error("Cannot read trigger configuration keys from the conditions database for run %d", args.run_number)
186 sys.exit(1)
187

Variable Documentation

◆ log

athenaHLT.log = logging.getLogger('athenaHLT')

Definition at line 58 of file athenaHLT.py.