12 from TrigTransform.dbgEventInfo
import dbgEventInfo
13 from TrigConfStorage.TriggerCoolUtil
import TriggerCoolUtil
14 from TrigConfIO.L1TriggerConfigAccess
import L1MenuAccess
15 from TrigConfIO.HLTTriggerConfigAccess
import HLTMenuAccess
17 from ROOT
import TFile, TH1F
20 msg = logging.getLogger(
"PyJobTransforms." + __name__)
23 def dbgPreRun(inputFileList, outputFileList, argdict = None):
24 msg.info(
'Running debug_stream analysis PreRun operations on files :{0} '.
format(inputFileList))
25 msg.info(
'Running debug_stream analysis PreRun, histogram output in :{0} '.
format(outputFileList))
28 outFile = outputFileList[0]
29 hfile = TFile(outFile,
'RECREATE')
31 maxEvents = argdict.get(
'maxEvents')
32 maxEvents = maxEvents.value.get(
'first')
if maxEvents
else -1
34 skipEvents = argdict.get(
'skipEvents')
35 skipEvents = skipEvents.value.get(
'first')
if skipEvents
else 0
38 eventInfo = dbgEventInfo(
'_Pre', inputFileList.value[0])
43 for inputFile
in inputFileList.value:
44 bsfile = eformat.istream(inputFile)
48 bsfile = bsfile[skipEvents:skipEvents+maxEvents]
if maxEvents > -1
else bsfile[skipEvents:]
53 runNumber = event.run_no()
if event.run_no()
else int(inputFile.split(
".")[1])
56 if not argdict.get(
'useDB'):
57 msg.debug(
"Reading chains and items from database is skipped (missing --useDB=True)")
58 l1Info, hltInfo = ([], [])
60 l1Info, hltInfo =
TriggerDBInfo(configKeys.get(
'DB'), configKeys.get(
'SMK'))
67 data = [event.run_no(), event.lumi_block(), event.global_id(),
68 event.lvl1_id(), event.bc_time_seconds(), event.bc_time_nanoseconds()]
69 msg.info(
'Event details :%s', data)
72 eventInfo.eventCount(event)
73 eventInfo.eventInfo(event, l1Info, hltInfo)
74 eventInfo.eventConfig(configKeys, event)
81 msg.info(
'Finished running debug_stream analysis PreRun operations')
83 dbAlias = configKeys.get(
'DB')
86 if 'REL' in configKeys:
90 msg.warn(
"Release not found in configuration - asetup string won't be created")
96 def dbgPostRun(inputFile, outputFile, argdict = None, isSplitStream=False):
97 msg.info(
'Running debug_stream analysis PostRun operations on files :{0} '.
format(inputFile))
98 msg.info(
'Running debug_stream analysis PostRun, histogram output in :{0} '.
format(outputFile))
101 hfile = TFile(outputFile,
'UPDATE')
105 eventInfo = dbgEventInfo(
'_Pos_Split', inputFile)
107 eventInfo = dbgEventInfo(
'_Pos', inputFile)
113 bsfile = eformat.istream(inputFile)
122 if not argdict.get(
'useDB'):
123 msg.debug(
"Reading chains and items from database is skipped (missing --useDB=True)")
124 l1Info, hltInfo = ([], [])
126 l1Info, hltInfo =
TriggerDBInfo(configKeys.get(
'DB'), configKeys.get(
'SMK'))
133 data = [event.run_no(), event.lumi_block(), event.global_id(),
134 event.lvl1_id(), event.bc_time_seconds(), event.bc_time_nanoseconds()]
135 msg.info(
'Event details :{0}'.
format(data))
138 eventInfo.eventCount(event)
139 eventInfo.eventInfo(event, l1Info, hltInfo)
140 eventInfo.eventConfig(configKeys, event)
146 msg.info(
'Finished running debug_stream analysis PostRun operations')
153 if not dbalias
or not smk:
154 msg.warn(
"Reading chains and items from database is skipped (config keys are not available)")
155 return (l1Info, hltInfo)
159 l1Cfg = L1MenuAccess(dbalias = dbalias, smkey = smk)
163 l1Items = l1Cfg.items()
166 ctpid = l1Items[item][
'ctpid']
167 l1ItemsMap[ctpid] = item
169 l1Info = (
max(l1ItemsMap.keys()) + 1) * [0]
171 for item
in l1ItemsMap:
172 l1Info[item] = l1ItemsMap[item]
175 msg.info(
"Database for L1 Menu not available")
179 hltCfg = HLTMenuAccess(dbalias = dbalias, smkey = smk)
180 hltChains = hltCfg.chains()
182 for chain
in hltChains:
183 counter = hltChains[chain][
'counter']
184 hltChainsMap[counter] = chain
186 hltInfo = (
max(hltChainsMap.keys()) + 1) * [0]
188 for chain
in hltChainsMap:
189 hltInfo[chain] = hltChainsMap[chain]
191 msg.info(
"Database for HLT Menu not available")
194 return (l1Info, hltInfo)
199 asetupString = release
204 if os.environ[
'TestArea']:
205 TestArea = os.environ[
'TestArea']
206 if TestArea.find(
'tzero/software/patches/AthenaP1-') > 0:
207 testarea = TestArea.split(
'-')
208 TestArea = testarea[0] +
'-' + release
209 asetupString +=
' --testarea ' + TestArea
216 Returns map with config keys:
219 SMK - Super Master Key
220 HLTPSK - HLT Prescale key
223 dbconn = TriggerCoolUtil.GetConnection(
"CONDBR2")
224 configKeys = TriggerCoolUtil.getHLTConfigKeys(dbconn, [[runNumber, runNumber]])
226 if configKeys
and runNumber
in configKeys.keys():
227 configKeys = configKeys[runNumber]
229 configKeys[
'HLTPSK'] = TriggerCoolUtil.getHLTPrescaleKeys(dbconn, [[runNumber, runNumber]])[runNumber][
'HLTPSK2']
231 msg.info(
"Found config keys %s", configKeys)
233 msg.info(
"Config keys not found in COOL")
236 if 'DB' in configKeys:
237 if 'DBserver' in args
and configKeys[
'DB'] != args[
'DBserver'].value:
238 msg.warn(
"Different database read from config keys ({0}) and from args ({1})".
format(configKeys[
'DB'], args[
'DBserver'].value))
239 msg.warn(
"Database {0} from config keys will be used.".
format(configKeys[
'DB']))
246 Prepare dictionary with data extracted from arguments if available. Contains:
248 SMK - Super Master Key
249 HLTPSC - HLT Prescale key
255 configKeys[
'DB'] = args[
'DBserver'].value
256 configKeys[
'SMK'] =
int(args[
'DBsmkey'].value)
257 configKeys[
'HLTPSK'] =
int(args[
'DBhltpskey'].value)
259 msg.info(
"Found config keys in args %s", configKeys)
262 msg.warn(
"Config keys not found in argdict")
269 Add HLT_accepted_events and HLT_rejected_events to outputFile
273 hfile = TFile(outputFile,
'UPDATE')
275 HLT_rejected_events =
TH1F(
"HLT_rejected_events",
"HLT_rejected_events", 3, 0.0, 3.0)
277 HLT_accepted_events =
TH1F(
"HLT_accepted_events",
"HLT_accepted_events", 3, 0.0, 3.0)
282 HLT_rejected_events.Fill(1, rejected)
287 HLT_accepted_events.Fill(1, accepted)
290 hfile.Write(
"", TFile.kOverwrite)
292 return msg.info(
"Added HLT_accepted_events and HLT_rejeceted_events to %s", outputFile)