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 AthenaCommon.Logging
import logging
15 log = logging.getLogger(__name__)
20 Add an extra ChainStep to a Chain object with a PEBInfoWriter sequence configured for the eventBuildType
22 if not eventBuildType:
23 log.error(
'No eventBuildType specified')
25 if eventBuildType
not in EventBuildingInfo.getAllEventBuildingIdentifiers():
26 log.error(
'eventBuildType \'%s\' not found in the allowed Event Building identifiers', eventBuildType)
29 seq = functools.partial(pebMenuSequenceGenCfg, flags, chain=chain, eventBuildType=eventBuildType, chainDict=chainDict)
31 if len(chain.steps)==0:
33 step_name =
'PEBInfoWriter_{:s}'.
format( eventBuildType)
34 step = ChainStep(name=step_name,
36 chainDicts=[chainDict])
39 prevStep = chain.steps[-1]
40 step_name =
'EventBuild_{:s}_PEBInfoWriter_{:s}'.
format(prevStep.name, eventBuildType)
41 step = ChainStep(name=step_name,
42 SequenceGens=[seq
for leg
in prevStep.legIds],
43 chainDicts=prevStep.stepDicts)
45 chain.steps.append(step)
48 """Create PEBInfoWriterTool configuration for the eventBuildType"""
51 HLT_ROB = SourceIdentifier(SubDetector.TDAQ_HLT, DataScoutingInfo.getFullHLTResultID())
54 if 'BeamSpotPEB' == eventBuildType:
57 subDets = [SubDetector.PIXEL_BARREL,
58 SubDetector.PIXEL_DISK_SIDE,
59 SubDetector.PIXEL_B_LAYER,
60 SubDetector.PIXEL_IBL,
61 SubDetector.SCT_BARREL_A_SIDE,
62 SubDetector.SCT_BARREL_C_SIDE,
63 SubDetector.SCT_ENDCAP_A_SIDE,
64 SubDetector.SCT_ENDCAP_C_SIDE,
65 SubDetector.TDAQ_CTP] )
67 elif 'MuonTrkPEB' == eventBuildType:
70 regSelDets = [
'Pixel',
'SCT',
'TRT',
'MDT',
'RPC',
'TGC',
'CSC',
'MM',
'sTGC'],
74 subDets = [SubDetector.TDAQ_CTP],
77 elif 'IDCalibPEB' == eventBuildType:
80 regSelDets = [
'Pixel',
'SCT',
'TRT'],
83 subDets = [SubDetector.TDAQ_CTP] )
85 elif 'LArPEBCalib' == eventBuildType:
88 subDets = [SubDetector.LAR_EM_BARREL_A_SIDE,
89 SubDetector.LAR_EM_BARREL_C_SIDE,
90 SubDetector.LAR_EM_ENDCAP_A_SIDE,
91 SubDetector.LAR_EM_ENDCAP_C_SIDE,
92 SubDetector.LAR_HAD_ENDCAP_A_SIDE,
93 SubDetector.LAR_HAD_ENDCAP_C_SIDE,
94 SubDetector.LAR_FCAL_A_SIDE,
95 SubDetector.LAR_FCAL_C_SIDE,
96 SubDetector.LAR_EM_BARREL_ENDCAP_A_SIDE,
97 SubDetector.LAR_EM_BARREL_ENDCAP_C_SIDE,
98 SubDetector.LAR_EM_HAD_ENDCAP_A_SIDE,
99 SubDetector.LAR_EM_HAD_ENDCAP_C_SIDE,
100 SubDetector.TDAQ_CTP] )
102 elif eventBuildType
in (
'LArPEBHLT',
'LArPEB'):
105 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD'],
107 ROBs = [HLT_ROB] + LATOMESourceIDs,
108 subDets = [SubDetector.TDAQ_CTP] )
110 elif 'LATOMEPEB' == eventBuildType:
113 ROBs = LATOMESourceIDs,
114 subDets = [SubDetector.TDAQ_CTP] )
116 elif 'SCTPEB' == eventBuildType:
119 subDets = [SubDetector.SCT_BARREL_A_SIDE,
120 SubDetector.SCT_BARREL_C_SIDE,
121 SubDetector.SCT_ENDCAP_A_SIDE,
122 SubDetector.SCT_ENDCAP_C_SIDE,
123 SubDetector.TDAQ_CTP] )
125 elif 'TilePEB' == eventBuildType:
128 subDets = [SubDetector.TILECAL_LASER_CRATE,
129 SubDetector.TILECAL_BARREL_A_SIDE,
130 SubDetector.TILECAL_BARREL_C_SIDE,
131 SubDetector.TILECAL_EXT_A_SIDE,
132 SubDetector.TILECAL_EXT_C_SIDE,
133 SubDetector.TDAQ_CTP,
134 SubDetector.TDAQ_CALO_PREPROC,
135 SubDetector.TDAQ_CALO_CLUSTER_PROC_DAQ,
136 SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI,
137 SubDetector.TDAQ_CALO_JET_PROC_DAQ,
138 SubDetector.TDAQ_CALO_JET_PROC_ROI
140 MatchTriggerType = [0x31, 0x32, 0x34]
if '_L1CALREQ' in name
else [] )
142 elif 'LArPEBNoise' == eventBuildType:
145 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD'],
147 ROBs = [HLT_ROB] + LATOMESourceIDs,
148 subDets = [SubDetector.MUON_MMEGA_ENDCAP_A_SIDE,
149 SubDetector.MUON_MMEGA_ENDCAP_C_SIDE,
150 SubDetector.MUON_STGC_ENDCAP_A_SIDE,
151 SubDetector.MUON_STGC_ENDCAP_C_SIDE,
152 SubDetector.TDAQ_CTP] )
154 elif 'ZDCPEB' == eventBuildType:
157 subDets = [SubDetector.FORWARD_ZDC,
158 SubDetector.TDAQ_CTP],
159 MatchTriggerType = [0x69, 0x6a, 0x6c]
if '_L1CALREQ' in name
else [] )
161 elif 'AFPPEB' == eventBuildType:
164 subDets = [SubDetector.FORWARD_AFP,
165 SubDetector.TDAQ_CTP] )
167 elif 'LumiPEB' == eventBuildType:
171 subDets = [SubDetector.PIXEL_IBL,
172 SubDetector.PIXEL_BARREL,
173 SubDetector.PIXEL_DISK_SIDE,
174 SubDetector.PIXEL_B_LAYER,
175 SubDetector.SCT_BARREL_A_SIDE,
176 SubDetector.SCT_BARREL_C_SIDE,
177 SubDetector.SCT_ENDCAP_A_SIDE,
178 SubDetector.SCT_ENDCAP_C_SIDE,
179 SubDetector.PIXEL_DBM,
180 SubDetector.TDAQ_CTP] )
182 elif 'Lvl1CaloPEB' == eventBuildType:
187 subDets = [SubDetector.TDAQ_CALO_PREPROC,
188 SubDetector.TDAQ_CALO_CLUSTER_PROC_DAQ,
189 SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI,
190 SubDetector.TDAQ_CALO_JET_PROC_DAQ,
191 SubDetector.TDAQ_CALO_JET_PROC_ROI,
192 SubDetector.TDAQ_CTP] )
194 elif 'DarkJetPEBTLA' == eventBuildType:
198 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD',
'TILE',
'MDT',
'RPC',
'TGC',
'CSC',
'MM',
'STGC'],
200 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
201 DataScoutingInfo.getDataScoutingResultID(eventBuildType))],
206 elif 'EgammaPEBTLA' == eventBuildType:
210 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD',
'TILE'],
212 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
213 DataScoutingInfo.getDataScoutingResultID(eventBuildType))],
217 elif 'FTagPEBTLA' == eventBuildType:
221 regSelDets = [
'Pixel',
'SCT'],
223 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
224 DataScoutingInfo.getDataScoutingResultID(eventBuildType))],
229 elif eventBuildType
in DataScoutingInfo.getAllDataScoutingIdentifiers():
233 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
234 DataScoutingInfo.getDataScoutingResultID(eventBuildType))] )
238 log.error(
'PEBInfoWriterTool configuration is missing for event building identifier \'%s\'', eventBuildType)
244 Define suffix for unique configurations - prevents config clashes.
250 _isRoIBasedPEB = EventBuildingInfo.isRoIBasedPEB(eventBuildType)
253 if _isNoalg
or not _isRoIBasedPEB: suffix+=
'_noSeed'
254 if _isFullscan
and _isRoIBasedPEB: suffix+=
'_RoIBasedFS'
265 _isRoIBasedPEB = EventBuildingInfo.isRoIBasedPEB(eventBuildType)
269 maker = CompFactory.InputMakerForRoI(
"IMpeb_" + eventBuildType + suffix)
270 maker.RoIs =
"pebInputRoI_" + eventBuildType + suffix
272 maker.mergeUsingFeature = _isRoIBasedPEB
and not _isNoalg
275 if _isNoalg
or not _isRoIBasedPEB:
277 maker.RoITool = CompFactory.ViewCreatorInitialROITool()
278 elif isFullscan
and _isRoIBasedPEB:
280 maker.RoITool = CompFactory.ViewCreatorCentredOnIParticleROITool()
281 maker.RoITool.RoisWriteHandleKey =
recordable(
"HLT_Roi_" + eventBuildType)
284 maker.RoITool = CompFactory.ViewCreatorPreviousROITool()
291 Return the MenuSequence for the PEB input maker for this chain.
294 def pebInfoWriterToolGenerator(chainDict):
300 recoAcc = InEventRecoCA(
"pebSequence_"+eventBuildType, inputMaker=inputMaker)
301 selAcc = SelectionCA(
"pebMainSeq_"+eventBuildType+suffix)
302 selAcc.mergeReco(recoAcc)
303 selAcc.addHypoAlgo(CompFactory.PEBInfoWriterAlg(
'PEBInfoWriterAlg_' + eventBuildType+suffix))
305 return MenuSequence(flags,
307 HypoToolGen = pebInfoWriterToolGenerator)
311 pebSteps = [s
for s
in chainConfig.steps
if 'PEBInfoWriter' in s.name
and 'EmptyPEBAlign' not in s.name]
312 if len(pebSteps) == 0:
314 elif len(pebSteps) > 1:
315 raise RuntimeError(
'Multiple Event Building steps in one chain are not supported but found in chain ' + chainConfig.name)
321 all_peb_chain_configs = [ch
for ch
in chain_configs
if len(chain_dicts[ch.name][
'eventBuildType'])>0]
323 def getPebStepPosition(chainConfig):
325 return chainConfig.steps.index(pebStep) + 1
328 maxPebStepPosition = {}
329 for chain
in all_peb_chain_configs:
330 pebStepPosition = getPebStepPosition(chain)
331 ebt = chain_dicts[chain.name][
'eventBuildType']
332 if ebt
not in maxPebStepPosition
or pebStepPosition > maxPebStepPosition[ebt]:
333 maxPebStepPosition[ebt] = pebStepPosition
336 for chain
in all_peb_chain_configs:
337 pebStepPosition = getPebStepPosition(chain)
338 ebt = chain_dicts[chain.name][
'eventBuildType']
339 if pebStepPosition < maxPebStepPosition[ebt]:
340 numStepsNeeded = maxPebStepPosition[ebt] - pebStepPosition
341 log.debug(
'Aligning PEB step for chain %s by adding %d empty steps', chain.name, numStepsNeeded)
342 chain.insertEmptySteps(
'EmptyPEBAlign', numStepsNeeded, pebStepPosition-1)
343 chain.numberAllSteps()
347 '''Helper function to determine if chain is full scan'''
353 '''Helper function to determine if chain has HLT reco'''
354 return (len(chain.steps) == 1
and "PEBInfoWriter" in chain.steps[0].name)
358 if __name__ ==
"__main__":
359 from AthenaConfiguration.TestDefaults
import defaultTestFiles, defaultGeometryTags
360 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
362 flags.Input.Files = defaultTestFiles.RAW_RUN3
363 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
367 assert(
set(DataScoutingInfo.getAllDataScoutingIdentifiers()).issubset(
368 EventBuildingInfo.getAllEventBuildingIdentifiers()) )
371 for eb_identifier
in EventBuildingInfo.getAllEventBuildingIdentifiers():
372 log.info(
'Checking %s event building identifier', eb_identifier)
376 tool = cfg.popPrivateTools()
377 except Exception
as ex:
379 log.error(
'Caught exception while configuring PEBInfoWriterTool for %s: %s', eb_identifier, ex)
386 log.error(
'No tool created for %s', eb_identifier)
389 if not isinstance(tool, (CompFactory.StaticPEBInfoWriterTool, CompFactory.RoIPEBInfoWriterTool)):
391 log.error(
'Unexpected tool type for %s: %s', eb_identifier, tool.getType())
394 isRoIBasedPEB = EventBuildingInfo.isRoIBasedPEB(eb_identifier)
395 if isinstance(tool, CompFactory.RoIPEBInfoWriterTool) != isRoIBasedPEB:
397 log.error(
'Tool type %s for %s but isRoIBasedPEB==%s',
398 tool.getType(), eb_identifier, isRoIBasedPEB)
401 robs = tool.ROBList
if tool.getType() ==
'StaticPEBInfoWriterTool' else tool.ExtraROBs
402 dets = tool.SubDetList
if tool.getType() ==
'StaticPEBInfoWriterTool' else tool.ExtraSubDets
403 robs_check_passed =
True
404 is_data_scouting =
False
406 rob_sid = SourceIdentifier(rob_id)
407 rob_det_id = rob_sid.subdetector_id()
408 if rob_det_id == SubDetector.TDAQ_HLT
and rob_sid.module_id() != DataScoutingInfo.getFullHLTResultID():
409 is_data_scouting =
True
410 if int(rob_det_id)
in dets:
411 robs_check_passed =
False
412 log.error(
'Redundant configuration for %s: ROB %s added to the ROB list while full SubDetector '
413 '%s is already in the SubDets list', eb_identifier, rob_sid.human(),
str(rob_det_id))
415 if not robs_check_passed:
421 always_present_rob = SourceIdentifier(SubDetector.TDAQ_CTP, 0)
422 if not is_data_scouting
and \
423 always_present_rob.code()
not in robs
and \
424 always_present_rob.subdetector_id()
not in dets:
425 log.error(
'Bug-prone configuration for %s: without always-present CTP data in the PEB list, the '
426 'streaming may break when all requested detectors are disabled. Add CTP data to this PEB '
427 'configuration to prevent the bug (ATR-24378).', eb_identifier)
431 log.info(
'%s correctly configured', tool.name()
if callable(tool.name)
else tool.name)