ATLAS Offline Software
Loading...
Searching...
No Matches
trigTranslate.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4
5# @brief: Trigger translator to setup arguments for athenaHLT
6# @details: to be used with Trig_tf_reco.py and trigRecoExe.py
7# @author: Mark Stockton
8
9import PyJobTransforms.trfArgClasses as trfArgClasses
10# TODO for check of prescale keys
11# import PyJobTransforms.trfExceptions as trfExceptions
12# from PyJobTransforms.trfExitCodes import trfExit
13
14# Setup logging here
15import logging
16msg = logging.getLogger("PyJobTransforms." + __name__)
17
18# create option dict needed by athenaHLT from runargs
19def getOption(runArgs, name, substep, first, output):
20
21 # Dictionary to be filled to run athenaHLT from
22 option = {}
23
24 # Dictionary defining args: key=transform value=athenaHLT
25 tfToAthenaHLT = {}
26 tfToAthenaHLT['inputBS_RDOFile'] = 'file'
27 tfToAthenaHLT['maxEvents'] = 'number-of-events'
28 tfToAthenaHLT['skipEvents'] = 'skip-events'
29 tfToAthenaHLT['precommand'] = 'precommand'
30 tfToAthenaHLT['postcommand'] = 'postcommand'
31 tfToAthenaHLT['useDB'] = 'use-database'
32 tfToAthenaHLT['DBserver'] = 'db-server'
33 tfToAthenaHLT['DBsmkey'] = 'smk'
34 tfToAthenaHLT['DBhltpskey'] = 'hltpsk'
35 tfToAthenaHLT['DBl1pskey'] = 'l1psk'
36
38
39 # Output needs the string not a list
40 # (as in PyJobTransforms/python/trfJobOptions.py)
41 # For a multi step tf it can be defined by the transform itself rather than on command line
42 if 'outputBSFile' in runArgs:
43 option['save-output'] = runArgs['outputBSFile'].value[0]
44 elif 'BS' in output:
45 option['save-output'] = output['BS'].value[0]
46 elif 'DRAW_TRIGCOST' in output or 'HIST_DEBUGSTREAMMON' in output:
47 msg.info('BS output needed, but not defined. Saving as temp.BS, but not avaialable to other steps')
48 option['save-output'] = "temp.BS"
49 else:
50 msg.warning('No BS filename defined, athenaHLT will not save the output')
51
52 # Added support for multithread option of trfArgs
53 from PyJobTransforms.trfMTTools import detectAthenaMTThreads
54 athenaMT, athenaConcurrentEvents = detectAthenaMTThreads(runArgs, name, False)
55 # skip the options if not set (detectAthenaMTThreads returns 0)
56 if athenaMT != 0:
57 option['threads'] = athenaMT
58 if athenaConcurrentEvents != 0:
59 option['concurrent-events'] = athenaConcurrentEvents
60
61 # TODO (ATR-11854) l1psk, hltpsk, smk should be compared to triggerConfig
62 # example below based on old comparison but needs work to retrieve keys and do comparisons of all three keys
63 # if 'triggerConfig' in runArgs:
64 # retrieve keys from triggerConfig string
65 # if 'lvl1key' in triggerConfig:
66 # if 'DBlvl1pskey' in runArgs:
67 # add check to compare DBlvl1pskey to lvl1key from triggerConfig
68 # raise trfExceptions.TransformArgException(trfExit.nameToCode('TRF_ARG_ERROR'), 'Inconsistent definition of lvl1key in --DBlvl1pskey {0} and --triggerConfig {1}'.format(runArgs['DBlvl1pskey'], runArgs['triggerConfig']))
69 # else:
70 # set lvl1key in triggerConfig
71 # if 'DBlvl1pskey' in runArgs and 'triggerConfig' not in option:
72 # set lvl1key in triggerConfig
73
74 # below based on PyJobTransforms/python/trfJobOptions.py
75 for k in set(tfToAthenaHLT) & set(runArgs):
76 v = runArgs[k]
77
80 if isinstance(v, trfArgClasses.argSubstep):
81 myValue = v.returnMyValue(name, substep, first)
82 if myValue is not None:
83 option[tfToAthenaHLT[k]] = myValue
84 else:
85 # return just the value to avoid returning all the properties (e.g. isRunArg=True)
86 option[tfToAthenaHLT[k]] = v.value
87
88 # Now make sure that if we did not add maxEvents then we set this to -1, which
89 # avoids some strange defaults that only allow 5 events to be processed
90 if tfToAthenaHLT['maxEvents'] not in option:
91 option[tfToAthenaHLT['maxEvents']] = -1
92 msg.info('maxEvents not defined, explicitly set to -1')
93
94 # Skips all the other runArgs (extra, literal, etc)
95 # as these are for running with athena not athenaHLT
96
97 return option
98
99# return option list to be used as command line for athenaHLT jobs
100# In Run2 this was handled by producing runTranslate file which is no longer needed
101def getTranslated(runArgs, name, substep, first, output):
102 option = getOption(runArgs, name, substep, first, output)
103 msg.info('Options set to: \"%s\":', option)
104 optionList = list()
105 for k, v in option.items():
106 item = "--{0}={1}"
107 if k == 'file':
108 for f in v:
109 optionList.append(item.format(k, f))
110 else:
111 if type(v) is list:
112 v = ''.join(v)
113 optionList.append(item.format(k, v))
114
115 # Replace --use-database=True with no argument version
116 if '--use-database=True' in optionList:
117 optionList.remove('--use-database=True')
118 optionList.append('--use-database')
119
120 return optionList
Base class for substep arguments.
STL class.
Transform argument class definitions.
Utilities for handling AthenaMT jobs.
getOption(runArgs, name, substep, first, output)
getTranslated(runArgs, name, substep, first, output)