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, MenuSequenceCA, 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
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 Sequences=[seq
for leg
in prevStep.legIds],
43 multiplicity=prevStep.multiplicity,
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,
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
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] )
160 elif 'AFPPEB' == eventBuildType:
163 subDets = [SubDetector.FORWARD_AFP,
164 SubDetector.TDAQ_CTP] )
166 elif 'LumiPEB' == eventBuildType:
170 subDets = [SubDetector.PIXEL_IBL,
171 SubDetector.PIXEL_BARREL,
172 SubDetector.PIXEL_DISK_SIDE,
173 SubDetector.PIXEL_B_LAYER,
174 SubDetector.SCT_BARREL_A_SIDE,
175 SubDetector.SCT_BARREL_C_SIDE,
176 SubDetector.SCT_ENDCAP_A_SIDE,
177 SubDetector.SCT_ENDCAP_C_SIDE,
178 SubDetector.PIXEL_DBM,
179 SubDetector.TDAQ_CTP] )
181 elif 'Lvl1CaloPEB' == eventBuildType:
186 subDets = [SubDetector.TDAQ_CALO_PREPROC,
187 SubDetector.TDAQ_CALO_CLUSTER_PROC_DAQ,
188 SubDetector.TDAQ_CALO_CLUSTER_PROC_ROI,
189 SubDetector.TDAQ_CALO_JET_PROC_DAQ,
190 SubDetector.TDAQ_CALO_JET_PROC_ROI,
191 SubDetector.TDAQ_CTP] )
193 elif 'DarkJetPEBTLA' == eventBuildType:
197 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD',
'TILE'],
199 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
200 DataScoutingInfo.getDataScoutingResultID(eventBuildType))],
205 elif 'EgammaPEBTLA' == eventBuildType:
209 regSelDets = [
'Pixel',
'SCT',
'TRT',
'TTEM',
'TTHEC',
'FCALEM',
'FCALHAD',
'TILE'],
211 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
212 DataScoutingInfo.getDataScoutingResultID(eventBuildType))],
216 elif 'FTagPEBTLA' == eventBuildType:
220 regSelDets = [
'Pixel',
'SCT'],
222 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
223 DataScoutingInfo.getDataScoutingResultID(eventBuildType))],
228 elif eventBuildType
in DataScoutingInfo.getAllDataScoutingIdentifiers():
232 ROBs = [SourceIdentifier(SubDetector.TDAQ_HLT,
233 DataScoutingInfo.getDataScoutingResultID(eventBuildType))] )
237 log.error(
'PEBInfoWriterTool configuration is missing for event building identifier \'%s\'', eventBuildType)
243 Define suffix for unique configurations - prevents config clashes.
249 _isRoIBasedPEB = EventBuildingInfo.isRoIBasedPEB(eventBuildType)
252 if _isNoalg
or not _isRoIBasedPEB: suffix+=
'_noSeed'
253 if _isFullscan
and _isRoIBasedPEB: suffix+=
'_RoIBasedFS'
264 _isRoIBasedPEB = EventBuildingInfo.isRoIBasedPEB(eventBuildType)
268 maker = CompFactory.InputMakerForRoI(
"IMpeb_" + eventBuildType + suffix)
269 maker.RoIs =
"pebInputRoI_" + eventBuildType + suffix
271 maker.mergeUsingFeature = _isRoIBasedPEB
and not _isNoalg
274 if _isNoalg
or not _isRoIBasedPEB:
276 maker.RoITool = CompFactory.ViewCreatorInitialROITool()
277 elif isFullscan
and _isRoIBasedPEB:
279 maker.RoITool = CompFactory.ViewCreatorCentredOnIParticleROITool()
280 maker.RoITool.RoisWriteHandleKey =
recordable(
"HLT_Roi_" + eventBuildType)
283 maker.RoITool = CompFactory.ViewCreatorPreviousROITool()
290 Return the MenuSequenceCA for the PEB input maker for this chain.
293 def pebInfoWriterToolGenerator(chainDict):
299 recoAcc = InEventRecoCA(
"pebSequence_"+eventBuildType, inputMaker=inputMaker)
300 selAcc = SelectionCA(
"pebMainSeq_"+eventBuildType+suffix)
301 selAcc.mergeReco(recoAcc)
302 selAcc.addHypoAlgo(CompFactory.PEBInfoWriterAlg(
'PEBInfoWriterAlg_' + eventBuildType+suffix))
304 return MenuSequenceCA(flags,
306 HypoToolGen = pebInfoWriterToolGenerator)
310 pebSteps = [s
for s
in chainConfig.steps
if 'PEBInfoWriter' in s.name
and 'EmptyPEBAlign' not in s.name]
311 if len(pebSteps) == 0:
313 elif len(pebSteps) > 1:
314 raise RuntimeError(
'Multiple Event Building steps in one chain are not supported but found in chain ' + chainConfig.name)
320 all_peb_chain_configs = [ch
for ch
in chain_configs
if len(chain_dicts[ch.name][
'eventBuildType'])>0]
322 def getPebStepPosition(chainConfig):
324 return chainConfig.steps.index(pebStep) + 1
327 maxPebStepPosition = {}
328 for chain
in all_peb_chain_configs:
329 pebStepPosition = getPebStepPosition(chain)
330 ebt = chain_dicts[chain.name][
'eventBuildType']
331 if ebt
not in maxPebStepPosition
or pebStepPosition > maxPebStepPosition[ebt]:
332 maxPebStepPosition[ebt] = pebStepPosition
335 for chain
in all_peb_chain_configs:
336 pebStepPosition = getPebStepPosition(chain)
337 ebt = chain_dicts[chain.name][
'eventBuildType']
338 if pebStepPosition < maxPebStepPosition[ebt]:
339 numStepsNeeded = maxPebStepPosition[ebt] - pebStepPosition
340 log.debug(
'Aligning PEB step for chain %s by adding %d empty steps', chain.name, numStepsNeeded)
341 chain.insertEmptySteps(
'EmptyPEBAlign', numStepsNeeded, pebStepPosition-1)
342 chain.numberAllSteps()
346 '''Helper function to determine if chain is full scan'''
352 '''Helper function to determine if chain has HLT reco'''
353 return (len(chain.steps) == 1
and "PEBInfoWriter" in chain.steps[0].name)
357 if __name__ ==
"__main__":
358 from AthenaConfiguration.TestDefaults
import defaultTestFiles, defaultGeometryTags
359 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
361 flags.Input.Files = defaultTestFiles.RAW_RUN3
362 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
366 assert(
set(DataScoutingInfo.getAllDataScoutingIdentifiers()).issubset(
367 EventBuildingInfo.getAllEventBuildingIdentifiers()) )
370 for eb_identifier
in EventBuildingInfo.getAllEventBuildingIdentifiers():
371 log.info(
'Checking %s event building identifier', eb_identifier)
375 tool = cfg.popPrivateTools()
376 except Exception
as ex:
378 log.error(
'Caught exception while configuring PEBInfoWriterTool for %s: %s', eb_identifier, ex)
385 log.error(
'No tool created for %s', eb_identifier)
388 if not isinstance(tool, (CompFactory.StaticPEBInfoWriterTool, CompFactory.RoIPEBInfoWriterTool)):
390 log.error(
'Unexpected tool type for %s: %s', eb_identifier, tool.getType())
393 isRoIBasedPEB = EventBuildingInfo.isRoIBasedPEB(eb_identifier)
394 if isinstance(tool, CompFactory.RoIPEBInfoWriterTool) != isRoIBasedPEB:
396 log.error(
'Tool type %s for %s but isRoIBasedPEB==%s',
397 tool.getType(), eb_identifier, isRoIBasedPEB)
400 robs = tool.ROBList
if tool.getType() ==
'StaticPEBInfoWriterTool' else tool.ExtraROBs
401 dets = tool.SubDetList
if tool.getType() ==
'StaticPEBInfoWriterTool' else tool.ExtraSubDets
402 robs_check_passed =
True
403 is_data_scouting =
False
405 rob_sid = SourceIdentifier(rob_id)
406 rob_det_id = rob_sid.subdetector_id()
407 if rob_det_id == SubDetector.TDAQ_HLT
and rob_sid.module_id() != DataScoutingInfo.getFullHLTResultID():
408 is_data_scouting =
True
409 if int(rob_det_id)
in dets:
410 robs_check_passed =
False
411 log.error(
'Redundant configuration for %s: ROB %s added to the ROB list while full SubDetector '
412 '%s is already in the SubDets list', eb_identifier, rob_sid.human(),
str(rob_det_id))
414 if not robs_check_passed:
420 always_present_rob = SourceIdentifier(SubDetector.TDAQ_CTP, 0)
421 if not is_data_scouting
and \
422 always_present_rob.code()
not in robs
and \
423 always_present_rob.subdetector_id()
not in dets:
424 log.error(
'Bug-prone configuration for %s: without always-present CTP data in the PEB list, the '
425 'streaming may break when all requested detectors are disabled. Add CTP data to this PEB '
426 'configuration to prevent the bug (ATR-24378).', eb_identifier)
430 log.info(
'%s correctly configured', tool.name()
if callable(tool.name)
else tool.name)