6 from AthenaConfiguration.ComponentFactory
import CompFactory
7 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
8 from AthenaCommon.Logging
import logging
9 log = logging.getLogger(
'RunTrigCostAnalysis.py')
14 from TrigCostAnalysis.ROSToROB
import ROSToROBMap
18 if len(flags.Input.RunNumbers) > 1:
19 log.error(
'Multiple run numbers from metadata! Only one expected per cost processing')
22 enhancedBiasWeighter = CompFactory.EnhancedBiasWeighter()
23 enhancedBiasWeighter.RunNumber = flags.Input.RunNumbers[0]
24 enhancedBiasWeighter.UseBunchCrossingData =
False
25 enhancedBiasWeighter.IsMC = isMC
28 enhancedBiasWeighter.MCCrossSection = MCpayload.get(
'MCCrossSection')
29 enhancedBiasWeighter.MCFilterEfficiency = MCpayload.get(
'MCFilterEfficiency')
30 enhancedBiasWeighter.MCKFactor = MCpayload.get(
'MCKFactor')
31 enhancedBiasWeighter.MCIgnoreGeneratorWeights = MCpayload.get(
'MCIgnoreGeneratorWeights')
33 trigCostAnalysis = CompFactory.TrigCostAnalysis()
34 trigCostAnalysis.OutputLevel = args.loglevel
35 trigCostAnalysis.BaseEventWeight = args.baseWeight
36 trigCostAnalysis.EnhancedBiasTool = enhancedBiasWeighter
37 trigCostAnalysis.AlgToChainTool = CompFactory.getComp(
"TrigCompositeUtils::AlgToChainTool")()
38 trigCostAnalysis.UseEBWeights = args.useEBWeights
39 trigCostAnalysis.MaxFullEventDumps = 100
40 trigCostAnalysis.FullEventDumpProbability = 1
41 trigCostAnalysis.UseSingleTimeRange = isMC
or args.useEBWeights
42 trigCostAnalysis.ROSToROBMap =
ROSToROBMap().get_mapping()
43 trigCostAnalysis.DoMonitorChainAlgorithm = args.monitorChainAlgorithm
46 trigCostAnalysis.AdditionalHashList =
readHashesFromHLTJO(args.joFile, args.smk, args.dbAlias)
48 log.debug(
"Hashes from the HLTJO won't be retrieved for MC job")
49 trigCostAnalysis.AdditionalHashList =
list()
51 acc.addEventAlgo(trigCostAnalysis)
59 payload[
'MCCrossSection'] = args.MCCrossSection
60 payload[
'MCFilterEfficiency'] = args.MCFilterEfficiency
61 payload[
'MCKFactor'] = args.MCKFactor
62 payload[
'MCIgnoreGeneratorWeights'] = args.MCIgnoreGeneratorWeights
64 dset = args.MCDatasetName
65 if payload[
'MCCrossSection'] == 0:
66 from RatesAnalysis.GetCrossSectionAMITool
import GetCrossSectionAMI
67 amiTool = GetCrossSectionAMI()
69 dset = amiTool.getDatasetNameFromPath(flags.Input.Files[0])
70 amiTool.queryAmi(dset)
71 payload[
'MCCrossSection'] = amiTool.crossSection
72 payload[
'MCFilterEfficiency'] = amiTool.filterEfficiency
81 log.debug(
"Reading HLTJobOptions from file {0}".
format(joFileName))
82 with open(joFileName,
"r")
as joFile:
84 joData = json.load(joFile)
86 log.debug(
"Reading HLTJobOptions from database {0} {1}".
format(smk, dbAlias))
87 from TrigConfIO.HLTTriggerConfigAccess
import HLTJobOptionsAccess
88 joData = HLTJobOptionsAccess(dbalias = dbAlias, smkey = smk)
90 log.debug(
"Additional collections' names from HLTJobOptions file are not available")
92 except Exception
as err:
93 log.warning(
"Retrieving additional names fron HLTJO failed: {0}".
format(err))
97 for entry
in joData[
"properties"]:
98 namesList.add(entry.split(
'.')[0])
101 entryObj = joData[
"properties"][entry]
102 if "Members" in entryObj:
103 membersList = entryObj[
"Members"].strip(
'][').
replace(
"'",
"").
split(
', ')
104 namesList.update(membersList)
107 log.info(
"Retrieved {0} additional names from HLT JO file".
format(len(namesList)))
108 return list(namesList)
113 from AthenaCommon.CFElements
import seqAND
114 from TrigEDMConfig
import DataScoutingInfo
118 acc.addSequence(
seqAND(
"Decoding"))
119 acc.addEventAlgo(CompFactory.HLTResultMTByteStreamDecoderAlg(),
"Decoding")
121 costDataDeserialiser = CompFactory.TriggerEDMDeserialiserAlg(
"CostDataTrigDeserialiser")
122 costDataDeserialiser.ModuleID = DataScoutingInfo.getDataScoutingResultID(
"CostMonDS")
123 acc.addEventAlgo(costDataDeserialiser,
"Decoding")
132 hltConfigSvc = CompFactory.getComp(
"TrigConf::HLTConfigSvc")(
"HLTConfigSvc")
137 log.debug(
"Reading HLTMenu from file {0}".
format(menuFile))
139 hltConfigSvc.InputType =
"FILE"
140 hltConfigSvc.HLTJsonFileName = menuFile
141 elif smk
and dbAlias:
142 log.debug(
"Reading HLTMenu from database {0} {1}".
format(smk, dbAlias))
144 hltConfigSvc.InputType =
"DB"
145 hltConfigSvc.HLTJsonFileName =
""
146 hltConfigSvc.TriggerDB = dbAlias
147 hltConfigSvc.SMK = smk
149 log.error(
"Cannot read the HLTMenu! Provide file or relevant keys.")
151 acc.addService(hltConfigSvc,
False,
True)
158 from TrigConfStorage.TriggerCoolUtil
import TriggerCoolUtil
159 dbconn = TriggerCoolUtil.GetConnection(
"CONDBR2")
160 runNumber = flags.Input.RunNumbers[0]
161 configKeys = TriggerCoolUtil.getHLTConfigKeys(dbconn, [[runNumber, runNumber]])
163 log.debug(
"Getting keys from COOL for run {0}".
format(runNumber))
164 if configKeys
and runNumber
in configKeys.keys():
166 smk = configKeys[runNumber][
'SMK']
169 dbAlias = configKeys[runNumber][
'DB']
171 log.debug(
"Config keys are SMK: {0} DB alias: {1}".
format(smk, dbAlias))
174 log.debug(
"Configuration keys for run {0} not found!".
format(runNumber))
175 dbAlias =
None if not dbAlias
else dbAlias
176 smk =
None if not smk
else smk
178 return (smk, dbAlias)
184 menuFileName =
'HLTMenu_.*json'
187 r = re.compile(menuFileName)
188 menuFiles =
list(
filter(r.match, os.listdir(
'.')))
190 if len(menuFiles) > 1:
191 log.info(
"Found more than one menu file! Saving first match %s", menuFiles[0])
193 return menuFiles[0]
if len(menuFiles) > 0
else ""
196 if __name__==
'__main__':
198 from argparse
import ArgumentParser
199 parser = ArgumentParser()
200 parser.add_argument(
'--outputHist', type=str, default=
'TrigCostRoot_Results.root', help=
'Histogram output ROOT file')
201 parser.add_argument(
'--monitorChainAlgorithm', action=
'store_true', help=
'Turn on Chain Algorithm monitoring')
202 parser.add_argument(
'--baseWeight', type=float, default=1.0, help=
'Base events weight')
203 parser.add_argument(
'--useEBWeights', type=bool, default=
False, help=
'Apply Enhanced Bias weights')
204 parser.add_argument(
'--joFile', type=str, help=
'Optional HLTJobOptions file to add more hashes')
206 parser.add_argument(
'--smk', type=int, help=
'SuperMasterKey to retrieve menu file')
207 parser.add_argument(
'--dbAlias', type=str, help=
'Database alias to retrieve menu file')
209 parser.add_argument(
'--MCDatasetName', default=
'', type=str, help=
'For MC input: Name of the dataset, can be used instead of MCCrossSection, MCFilterEfficiency')
210 parser.add_argument(
'--MCCrossSection', default=0.0, type=float, help=
'For MC input: Cross section of process in nb')
211 parser.add_argument(
'--MCFilterEfficiency', default=1.0, type=float, help=
'For MC input: Filter efficiency of any MC filter (0.0 - 1.0)')
212 parser.add_argument(
'--MCKFactor', default=1.0, type=float, help=
'For MC input: Additional multiplicitive fudge-factor to the supplied cross section.')
213 parser.add_argument(
'--MCIgnoreGeneratorWeights', action=
'store_true', help=
'For MC input: Flag to disregard any generator weights.')
215 parser.add_argument(
'--maxEvents', type=int, help=
'Maximum number of events to process')
216 parser.add_argument(
'--skipEvents',type=int, help=
'Number of events to skip')
217 parser.add_argument(
'--loglevel', type=int, default=3, help=
'Verbosity level: 1 - VERBOSE, 2 - DEBUG, 3 - INFO')
218 parser.add_argument(
'flags', nargs=
'*', help=
'Config flag overrides')
219 args = parser.parse_args()
221 log.level = args.loglevel
224 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
227 flags.Exec.OutputLevel = args.loglevel
228 flags.fillFromArgs(args.flags)
232 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
236 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
239 from ByteStreamCnvSvc.ByteStreamConfig
import ByteStreamReadCfg
243 histSvc = CompFactory.THistSvc()
244 histSvc.Output += [
"COSTSTREAM DATAFILE='" + args.outputHist +
"' OPT='RECREATE'"]
245 cfg.addService(histSvc)
248 if not flags.Input.isMC
and (
not args.smk
or not args.dbAlias):
256 cfg.printConfig(withDetails=
False)
257 sc = cfg.run(args.maxEvents)
258 sys.exit(0
if sc.isSuccess()
else 1)