ATLAS Offline Software
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 
9 import 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
15 import logging
16 msg = logging.getLogger("PyJobTransforms." + __name__)
17 
18 # create option dict needed by athenaHLT from runargs
19 def 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  # TODO (ATR-11854) l1psk, hltpsk, smk should be compared to triggerConfig
53  # example below based on old comparison but needs work to retrieve keys and do comparisons of all three keys
54  # if 'triggerConfig' in runArgs:
55  # retrieve keys from triggerConfig string
56  # if 'lvl1key' in triggerConfig:
57  # if 'DBlvl1pskey' in runArgs:
58  # add check to compare DBlvl1pskey to lvl1key from triggerConfig
59  # raise trfExceptions.TransformArgException(trfExit.nameToCode('TRF_ARG_ERROR'), 'Inconsistent definition of lvl1key in --DBlvl1pskey {0} and --triggerConfig {1}'.format(runArgs['DBlvl1pskey'], runArgs['triggerConfig']))
60  # else:
61  # set lvl1key in triggerConfig
62  # if 'DBlvl1pskey' in runArgs and 'triggerConfig' not in option:
63  # set lvl1key in triggerConfig
64 
65  # below based on PyJobTransforms/python/trfJobOptions.py
66  for k in set(tfToAthenaHLT) & set(runArgs):
67  v = runArgs[k]
68 
71  if isinstance(v, trfArgClasses.argSubstep):
72  myValue = v.returnMyValue(name, substep, first)
73  if myValue is not None:
74  option[tfToAthenaHLT[k]] = myValue
75  else:
76  # return just the value to avoid returning all the properties (e.g. isRunArg=True)
77  option[tfToAthenaHLT[k]] = v.value
78 
79  # Now make sure that if we did not add maxEvents then we set this to -1, which
80  # avoids some strange defaults that only allow 5 events to be processed
81  if tfToAthenaHLT['maxEvents'] not in option:
82  option[tfToAthenaHLT['maxEvents']] = -1
83  msg.info('maxEvents not defined, explicitly set to -1')
84 
85  # Skips all the other runArgs (extra, literal, etc)
86  # as these are for running with athena not athenaHLT
87 
88  return option
89 
90 # return option list to be used as command line for athenaHLT jobs
91 # In Run2 this was handled by producing runTranslate file which is no longer needed
92 def getTranslated(runArgs, name, substep, first, output):
93  option = getOption(runArgs, name, substep, first, output)
94  msg.info('Options set to: \"%s\":', option)
95  optionList = list()
96  for k, v in option.items():
97  item = "--{0}={1}"
98  if k == 'file':
99  for f in v:
100  optionList.append(item.format(k, f))
101  else:
102  if type(v) is list:
103  v = ''.join(v)
104  optionList.append(item.format(k, v))
105 
106  # Replace --use-database=True with no argument version
107  if '--use-database=True' in optionList:
108  optionList.remove('--use-database=True')
109  optionList.append('--use-database')
110 
111  return optionList
PyJobTransforms.trfArgClasses
Transform argument class definitions.
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
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
python.trfArgClasses.argSubstep
Base class for substep arguments.
Definition: trfArgClasses.py:1926
python.trigTranslate.getOption
def getOption(runArgs, name, substep, first, output)
Definition: trigTranslate.py:19
python.trigTranslate.getTranslated
def getTranslated(runArgs, name, substep, first, output)
Definition: trigTranslate.py:92