5 from TrigEDMConfig
import DataScoutingInfo
6 from TrigEDMConfig.TriggerEDM
import recordable
7 from TriggerMenuMT.HLT.Menu
import EventBuildingInfo
8 from TriggerMenuMT.HLT.Config.MenuComponents
import ChainStep, MenuSequence, SelectionCA, InEventRecoCA
9 from TrigPartialEventBuilding.TrigPartialEventBuildingConfig
import StaticPEBInfoWriterToolCfg, RoIPEBInfoWriterToolCfg
10 from HLTSeeding.HLTSeedingConfig
import mapThresholdToL1DecisionCollection
11 from libpyeformat_helper
import SourceIdentifier, SubDetector
12 from AthenaConfiguration.ComponentFactory
import CompFactory
13 from .LATOMESourceIDs
import LATOMESourceIDs
14 from .FEXSourceIDs
import FEXSourceIDs
15 from AthenaCommon.Logging
import logging
16 log = logging.getLogger(__name__)
21 Add an extra ChainStep to a Chain object with a PEBInfoWriter sequence configured for the eventBuildType
23 if not eventBuildType:
24 log.error(
'No eventBuildType specified')
26 if eventBuildType
not in EventBuildingInfo.getAllEventBuildingIdentifiers():
27 log.error(
'eventBuildType \'%s\' not found in the allowed Event Building identifiers', eventBuildType)
30 seq = functools.partial(pebMenuSequenceGenCfg, flags, chain=chain, eventBuildType=eventBuildType, chainDict=chainDict)
32 if len(chain.steps)==0:
34 step_name =
'PEBInfoWriter_{:s}'.
format( eventBuildType)
35 step = ChainStep(name=step_name,
37 chainDicts=[chainDict])
40 prevStep = chain.steps[-1]
41 step_name =
'EventBuild_{:s}_PEBInfoWriter_{:s}'.
format(prevStep.name, eventBuildType)
42 step = ChainStep(name=step_name,
43 SequenceGens=[seq
for leg
in prevStep.legIds],
44 chainDicts=prevStep.stepDicts)
46 chain.steps.append(step)
49 """Create PEBInfoWriterTool configuration for the eventBuildType"""
52 HLT_ROB = SourceIdentifier(SubDetector.TDAQ_HLT, DataScoutingInfo.getFullHLTResultID())
55 if 'BeamSpotPEB' == eventBuildType:
58 subDets = [SubDetector.PIXEL_BARREL,
59 SubDetector.PIXEL_DISK_SIDE,
60 SubDetector.PIXEL_B_LAYER,
61 SubDetector.PIXEL_IBL,
62 SubDetector.SCT_BARREL_A_SIDE,
63 SubDetector.SCT_BARREL_C_SIDE,
64 SubDetector.SCT_ENDCAP_A_SIDE,
65 SubDetector.SCT_ENDCAP_C_SIDE,
66 SubDetector.TDAQ_CTP] )
68 elif 'MuonTrkPEB' == eventBuildType:
71 regSelDets = [
'Pixel',
'SCT',
'TRT',
'MDT',
'RPC',
'TGC',
'CSC',
'MM',
'sTGC'],
75 subDets = [SubDetector.TDAQ_CTP],
78 elif 'IDCalibPEB' == eventBuildType:
81 regSelDets = [
'Pixel',
'SCT',
'TRT'],
84 subDets = [SubDetector.TDAQ_CTP] )
86 elif 'LArPEBCalib' == eventBuildType:
89 subDets = [SubDetector.LAR_EM_BARREL_A_SIDE,
90 SubDetector.LAR_EM_BARREL_C_SIDE,
91 SubDetector.LAR_EM_ENDCAP_A_SIDE,
92 SubDetector.LAR_EM_ENDCAP_C_SIDE,
93 SubDetector.LAR_HAD_ENDCAP_A_SIDE,
94 SubDetector.LAR_HAD_ENDCAP_C_SIDE,
95 SubDetector.LAR_FCAL_A_SIDE,
96 SubDetector.LAR_FCAL_C_SIDE,
97 SubDetector.LAR_EM_BARREL_ENDCAP_A_SIDE,
98 SubDetector.LAR_EM_BARREL_ENDCAP_C_SIDE,
99 SubDetector.LAR_EM_HAD_ENDCAP_A_SIDE,
100 SubDetector.LAR_EM_HAD_ENDCAP_C_SIDE,
101 SubDetector.TDAQ_CTP] )
103 elif eventBuildType
in (
'LArPEBHLT',
'LArPEB'):
106 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD'],
108 ROBs = [HLT_ROB] + LATOMESourceIDs,
109 subDets = [SubDetector.TDAQ_CTP] )
111 elif 'LATOMEPEB' == eventBuildType:
114 ROBs = LATOMESourceIDs + FEXSourceIDs,
115 subDets = [SubDetector.TDAQ_CTP] )
117 elif 'SCTPEB' == eventBuildType:
120 subDets = [SubDetector.SCT_BARREL_A_SIDE,
121 SubDetector.SCT_BARREL_C_SIDE,
122 SubDetector.SCT_ENDCAP_A_SIDE,
123 SubDetector.SCT_ENDCAP_C_SIDE,
124 SubDetector.TDAQ_CTP] )
126 elif 'TilePEB' == eventBuildType:
129 subDets = [SubDetector.TILECAL_LASER_CRATE,
130 SubDetector.TILECAL_BARREL_A_SIDE,
131 SubDetector.TILECAL_BARREL_C_SIDE,
132 SubDetector.TILECAL_EXT_A_SIDE,
133 SubDetector.TILECAL_EXT_C_SIDE,
134 SubDetector.TDAQ_CTP,
135 SubDetector.TDAQ_CALO_PREPROC,
136 SubDetector.TDAQ_CALO_CLUSTER_PROC_DAQ,
137 SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI,
138 SubDetector.TDAQ_CALO_JET_PROC_DAQ,
139 SubDetector.TDAQ_CALO_JET_PROC_ROI
141 MatchTriggerType = [0x31, 0x32, 0x34]
if '_L1CALREQ' in name
else [] )
143 elif 'LArPEBNoise' == eventBuildType:
146 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD'],
148 ROBs = [HLT_ROB] + LATOMESourceIDs,
149 subDets = [SubDetector.MUON_MMEGA_ENDCAP_A_SIDE,
150 SubDetector.MUON_MMEGA_ENDCAP_C_SIDE,
151 SubDetector.MUON_STGC_ENDCAP_A_SIDE,
152 SubDetector.MUON_STGC_ENDCAP_C_SIDE,
153 SubDetector.TDAQ_CTP] )
155 elif 'ZDCPEB' == eventBuildType:
158 subDets = [SubDetector.FORWARD_ZDC,
159 SubDetector.TDAQ_CTP],
160 MatchTriggerType = [0x69, 0x6a, 0x6c]
if '_L1CALREQ' in name
else [] )
162 elif 'AFPPEB' == eventBuildType:
165 subDets = [SubDetector.FORWARD_AFP,
166 SubDetector.TDAQ_CTP] )
168 elif 'LumiPEB' == eventBuildType:
172 subDets = [SubDetector.PIXEL_IBL,
173 SubDetector.PIXEL_BARREL,
174 SubDetector.PIXEL_DISK_SIDE,
175 SubDetector.PIXEL_B_LAYER,
176 SubDetector.SCT_BARREL_A_SIDE,
177 SubDetector.SCT_BARREL_C_SIDE,
178 SubDetector.SCT_ENDCAP_A_SIDE,
179 SubDetector.SCT_ENDCAP_C_SIDE,
180 SubDetector.PIXEL_DBM,
181 SubDetector.TDAQ_CTP] )
183 elif 'Lvl1CaloPEB' == eventBuildType:
188 subDets = [SubDetector.TDAQ_CALO_PREPROC,
189 SubDetector.TDAQ_CALO_CLUSTER_PROC_DAQ,
190 SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI,
191 SubDetector.TDAQ_CALO_JET_PROC_DAQ,
192 SubDetector.TDAQ_CALO_JET_PROC_ROI,
193 SubDetector.TDAQ_CTP] )
195 elif 'DarkJetPEBTLA' == eventBuildType:
199 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD',
'TILE',
'MDT',
'RPC',
'TGC',
'CSC',
'MM',
'STGC'],
201 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
202 DataScoutingInfo.getDataScoutingResultID(eventBuildType))],
207 elif 'EgammaPEBTLA' == eventBuildType:
211 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD',
'TILE'],
213 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
214 DataScoutingInfo.getDataScoutingResultID(eventBuildType))],
218 elif 'FTagPEBTLA' == eventBuildType:
222 regSelDets = [
'Pixel',
'SCT'],
224 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
225 DataScoutingInfo.getDataScoutingResultID(eventBuildType))],
230 elif eventBuildType
in DataScoutingInfo.getAllDataScoutingIdentifiers():
234 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
235 DataScoutingInfo.getDataScoutingResultID(eventBuildType))] )
239 log.error(
'PEBInfoWriterTool configuration is missing for event building identifier \'%s\'', eventBuildType)
245 Define suffix for unique configurations - prevents config clashes.
251 _isRoIBasedPEB = EventBuildingInfo.isRoIBasedPEB(eventBuildType)
254 if _isNoalg
or not _isRoIBasedPEB: suffix+=
'_noSeed'
255 if _isFullscan
and _isRoIBasedPEB: suffix+=
'_RoIBasedFS'
266 _isRoIBasedPEB = EventBuildingInfo.isRoIBasedPEB(eventBuildType)
270 maker = CompFactory.InputMakerForRoI(
"IMpeb_" + eventBuildType + suffix)
271 maker.RoIs =
"pebInputRoI_" + eventBuildType + suffix
273 maker.mergeUsingFeature = _isRoIBasedPEB
and not _isNoalg
276 if _isNoalg
or not _isRoIBasedPEB:
278 maker.RoITool = CompFactory.ViewCreatorInitialROITool()
279 elif isFullscan
and _isRoIBasedPEB:
281 maker.RoITool = CompFactory.ViewCreatorCentredOnIParticleROITool()
282 maker.RoITool.RoisWriteHandleKey =
recordable(
"HLT_Roi_" + eventBuildType)
285 maker.RoITool = CompFactory.ViewCreatorPreviousROITool()
292 Return the MenuSequence for the PEB input maker for this chain.
295 def pebInfoWriterToolGenerator(flags, chainDict):
301 recoAcc = InEventRecoCA(
"pebSequence_"+eventBuildType, inputMaker=inputMaker)
302 selAcc = SelectionCA(
"pebMainSeq_"+eventBuildType+suffix)
303 selAcc.mergeReco(recoAcc)
304 selAcc.addHypoAlgo(CompFactory.PEBInfoWriterAlg(
'PEBInfoWriterAlg_' + eventBuildType+suffix))
306 return MenuSequence(flags,
308 HypoToolGen = pebInfoWriterToolGenerator)
312 pebSteps = [s
for s
in chainConfig.steps
if 'PEBInfoWriter' in s.name
and 'EmptyPEBAlign' not in s.name]
313 if len(pebSteps) == 0:
315 elif len(pebSteps) > 1:
316 raise RuntimeError(
'Multiple Event Building steps in one chain are not supported but found in chain ' + chainConfig.name)
322 all_peb_chain_configs = [ch
for ch
in chain_configs
if len(chain_dicts[ch.name][
'eventBuildType'])>0]
324 def getPebStepPosition(chainConfig):
326 return chainConfig.steps.index(pebStep) + 1
329 maxPebStepPosition = {}
330 for chain
in all_peb_chain_configs:
331 pebStepPosition = getPebStepPosition(chain)
332 ebt = chain_dicts[chain.name][
'eventBuildType']
333 if ebt
not in maxPebStepPosition
or pebStepPosition > maxPebStepPosition[ebt]:
334 maxPebStepPosition[ebt] = pebStepPosition
337 for chain
in all_peb_chain_configs:
338 pebStepPosition = getPebStepPosition(chain)
339 ebt = chain_dicts[chain.name][
'eventBuildType']
340 if pebStepPosition < maxPebStepPosition[ebt]:
341 numStepsNeeded = maxPebStepPosition[ebt] - pebStepPosition
342 log.debug(
'Aligning PEB step for chain %s by adding %d empty steps', chain.name, numStepsNeeded)
343 chain.insertEmptySteps(
'EmptyPEBAlign', numStepsNeeded, pebStepPosition-1)
344 chain.numberAllSteps()
348 '''Helper function to determine if chain is full scan'''
354 '''Helper function to determine if chain has HLT reco'''
355 return (len(chain.steps) == 1
and "PEBInfoWriter" in chain.steps[0].name)
359 if __name__ ==
"__main__":
360 from AthenaConfiguration.TestDefaults
import defaultTestFiles, defaultGeometryTags
361 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
363 flags.Input.Files = defaultTestFiles.RAW_RUN3
364 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
368 assert(
set(DataScoutingInfo.getAllDataScoutingIdentifiers()).issubset(
369 EventBuildingInfo.getAllEventBuildingIdentifiers()) )
372 for eb_identifier
in EventBuildingInfo.getAllEventBuildingIdentifiers():
373 log.info(
'Checking %s event building identifier', eb_identifier)
377 tool = cfg.popPrivateTools()
378 except Exception
as ex:
380 log.error(
'Caught exception while configuring PEBInfoWriterTool for %s: %s', eb_identifier, ex)
387 log.error(
'No tool created for %s', eb_identifier)
390 if not isinstance(tool, (CompFactory.StaticPEBInfoWriterTool, CompFactory.RoIPEBInfoWriterTool)):
392 log.error(
'Unexpected tool type for %s: %s', eb_identifier, tool.getType())
395 isRoIBasedPEB = EventBuildingInfo.isRoIBasedPEB(eb_identifier)
396 if isinstance(tool, CompFactory.RoIPEBInfoWriterTool) != isRoIBasedPEB:
398 log.error(
'Tool type %s for %s but isRoIBasedPEB==%s',
399 tool.getType(), eb_identifier, isRoIBasedPEB)
402 robs = tool.ROBList
if tool.getType() ==
'StaticPEBInfoWriterTool' else tool.ExtraROBs
403 dets = tool.SubDetList
if tool.getType() ==
'StaticPEBInfoWriterTool' else tool.ExtraSubDets
404 robs_check_passed =
True
405 is_data_scouting =
False
407 rob_sid = SourceIdentifier(rob_id)
408 rob_det_id = rob_sid.subdetector_id()
409 if rob_det_id == SubDetector.TDAQ_HLT
and rob_sid.module_id() != DataScoutingInfo.getFullHLTResultID():
410 is_data_scouting =
True
411 if int(rob_det_id)
in dets:
412 robs_check_passed =
False
413 log.error(
'Redundant configuration for %s: ROB %s added to the ROB list while full SubDetector '
414 '%s is already in the SubDets list', eb_identifier, rob_sid.human(),
str(rob_det_id))
416 if not robs_check_passed:
422 always_present_rob = SourceIdentifier(SubDetector.TDAQ_CTP, 0)
423 if not is_data_scouting
and \
424 always_present_rob.code()
not in robs
and \
425 always_present_rob.subdetector_id()
not in dets:
426 log.error(
'Bug-prone configuration for %s: without always-present CTP data in the PEB list, the '
427 'streaming may break when all requested detectors are disabled. Add CTP data to this PEB '
428 'configuration to prevent the bug (ATR-24378).', eb_identifier)
432 log.info(
'%s correctly configured', tool.name()
if callable(tool.name)
else tool.name)