ATLAS Offline Software
Loading...
Searching...
No Matches
RegSelToolConfig.py
Go to the documentation of this file.
2# @file RegSelToolConfig.py
3#
4# configuration functions for the new RegSelTools
5#
6# @author sutt
7#
8# @date Sun 8 Mar 2020 03:27:57 GMT
9#
10# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration#
11#
12from AthenaConfiguration.AccumulatorCache import AccumulatorCache
13from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
14from AthenaConfiguration.ComponentFactory import CompFactory
15from AthenaCommon.Logging import logging
16_log = logging.getLogger(__name__)
17
18def _condAlgName(detector):
19 return "RegSelCondAlg_"+detector
20
21def _createRegSelCondAlg( detector, CondAlgConstructor, printTable=False ):
22 """
23 Creates conditions alg that provides data to a RegSel Tool
24 """
25 if detector == "TRT":
26 condAlg = CondAlgConstructor( name = _condAlgName( detector ),
27 PrintTable = printTable,
28 RegSelLUT = ("RegSelLUTCondData_"+detector) )
29 else:
30 condAlg = CondAlgConstructor( name = _condAlgName( detector ),
31 ManagerName = detector,
32 PrintTable = printTable,
33 RegSelLUT = ("RegSelLUTCondData_"+detector) )
34
35 if detector == "Pixel":
36 condAlg.DetEleCollKey = "PixelDetectorElementCollection"
37 condAlg.PixelCablingCondData = "PixelCablingCondData"
38 elif detector == "SCT":
39 condAlg.DetEleCollKey = "SCT_DetectorElementCollection"
40 condAlg.SCT_CablingData = "SCT_CablingData"
41 elif detector == "ITkPixel":
42 condAlg.DetEleCollKey = "ITkPixelDetectorElementCollection"
43 # No cabling data for ITk
44 condAlg.PixelCablingCondData = ""
45 elif detector == "PLR":
46 condAlg.DetEleCollKey = "PLR_DetectorElementCollection"
47 # No cabling data for PLR RDO input
48 condAlg.PixelCablingCondData = ""
49 elif detector == "ITkStrip":
50 condAlg.DetEleCollKey = "ITkStripDetectorElementCollection"
51 # No cabling data for ITk
52 condAlg.SCT_CablingData = ""
53 return condAlg
54
55def _createRegSelTool( detector, enable ):
56 """
57 Creates RegSelTool and corresponding cond tool that is needed for its function
58
59 If the enable flag is set - the tool is properly configured, else it is configured NOT to provide the data.
60
61 """
62
63
64 tool = CompFactory.RegSelTool(name="RegSelTool_"+detector)
65
66 # should we enable the look up table access for this subsystem ?
67
68 if not enable:
69 # detector not configured so don't enable
70 # lookup table access
71 tool.Initialised = False
72 return tool
73
74 # add the lookup table to retrieve
75
76 tool.RegSelLUT = "RegSelLUTCondData_"+detector # has to match wiht appropriate RegSelCondAlg
77 tool.Initialised = True
78 return tool
79
80
81def regSelToolCfg(flags, detector, algorithm, readout_geometry=None, conditions=None):
82 ca = ComponentAccumulator()
83 if readout_geometry:
84 ca.merge(readout_geometry)
85 if conditions:
86 ca.merge(conditions)
87 ca.setPrivateTools(_createRegSelTool(detector, True))
88
89 # test if we have a PrintLUT flag ...
90 printLUT = False
91 if flags.hasFlag("PrintLUT"):
92 printLUT = flags.PrintLUT
93
94 the_alg = _createRegSelCondAlg(detector, algorithm, printTable=printLUT)
95 ca.addCondAlgo(the_alg)
96 return ca
97
98
99# inner detector
100@AccumulatorCache
102 from PixelGeoModel.PixelGeoModelConfig import PixelReadoutGeometryCfg
103 from PixelConditionsAlgorithms.PixelConditionsConfig import PixelCablingCondAlgCfg
104 return regSelToolCfg(flags, "Pixel", CompFactory.SiRegSelCondAlg,
105 readout_geometry=PixelReadoutGeometryCfg(flags), conditions=PixelCablingCondAlgCfg(flags))
106
107@AccumulatorCache
109 from SCT_GeoModel.SCT_GeoModelConfig import SCT_ReadoutGeometryCfg
110 from SCT_Cabling.SCT_CablingConfig import SCT_CablingCondAlgCfg
111 return regSelToolCfg(flags, "SCT", CompFactory.SiRegSelCondAlg,
112 readout_geometry=SCT_ReadoutGeometryCfg(flags), conditions=SCT_CablingCondAlgCfg(flags))
113
114@AccumulatorCache
116 from TRT_GeoModel.TRT_GeoModelConfig import TRT_ReadoutGeometryCfg
117 return regSelToolCfg(flags, "TRT", CompFactory.TRT_RegSelCondAlg,
118 readout_geometry=TRT_ReadoutGeometryCfg(flags))
119
120# ITk
121@AccumulatorCache
123 from PixelGeoModelXml.ITkPixelGeoModelConfig import ITkPixelReadoutGeometryCfg
124 return regSelToolCfg(flags, "ITkPixel", CompFactory.SiRegSelCondAlg,
125 readout_geometry=ITkPixelReadoutGeometryCfg(flags))
126
127@AccumulatorCache
129 from PLRGeoModelXml.PLR_GeoModelConfig import PLR_ReadoutGeometryCfg
130 return regSelToolCfg(flags, "PLR", CompFactory.SiRegSelCondAlg,
131 readout_geometry=PLR_ReadoutGeometryCfg(flags))
132
133@AccumulatorCache
135 from StripGeoModelXml.ITkStripGeoModelConfig import ITkStripReadoutGeometryCfg
136 return regSelToolCfg(flags, "ITkStrip", CompFactory.SiRegSelCondAlg,
137 readout_geometry=ITkStripReadoutGeometryCfg(flags))
138
139
140# muon spectrometer
141@AccumulatorCache
143 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
144 result = ComponentAccumulator()
145 result.merge(RegionSelCondAlgCfg(flags, detector = "MDT"))
146 result.setPrivateTools(_createRegSelTool("MDT", True))
147 return result
148
149@AccumulatorCache
151 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
152 result = ComponentAccumulator()
153 result.merge(RegionSelCondAlgCfg(flags, detector = "RPC"))
154 result.setPrivateTools(_createRegSelTool("RPC", True))
155 return result
156
157@AccumulatorCache
159 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
160 result = ComponentAccumulator()
161 result.merge(RegionSelCondAlgCfg(flags, detector = "TGC"))
162 result.setPrivateTools(_createRegSelTool("TGC", True))
163 return result
164
165@AccumulatorCache
167 from MuonConfig.MuonGeometryConfig import MuonGeoModelCfg
168 from MuonConfig.MuonCablingConfig import CSCCablingConfigCfg
169
170 conditions = ComponentAccumulator()
171 conditions.merge(MuonGeoModelCfg(flags))
172 conditions.merge(CSCCablingConfigCfg(flags))
173
174 return regSelToolCfg(flags, "CSC", CompFactory.CSC_RegSelCondAlg,
175 conditions=conditions)
176
177@AccumulatorCache
179 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
180 result = ComponentAccumulator()
181 result.merge(RegionSelCondAlgCfg(flags, detector = "sTGC"))
182 result.setPrivateTools(_createRegSelTool("sTGC", True))
183 return result
184
185@AccumulatorCache
187 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
188 result = ComponentAccumulator()
189 result.merge(RegionSelCondAlgCfg(flags, detector = "MM"))
190 result.setPrivateTools(_createRegSelTool("MM", True))
191 return result
192
193
194
195# calo
196@AccumulatorCache
198 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
199 from LArRecUtils.LArRecUtilsConfig import LArRoIMapCondAlgCfg
200
201 conditions = ComponentAccumulator()
202 conditions.merge(LArGMCfg(flags))
203 conditions.merge(LArRoIMapCondAlgCfg(flags))
204
205 return regSelToolCfg(flags, "TTEM", CompFactory.RegSelCondAlg_LAr,
206 conditions=conditions)
207
208@AccumulatorCache
210 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
211 from LArRecUtils.LArRecUtilsConfig import LArRoIMapCondAlgCfg
212
213 conditions = ComponentAccumulator()
214 conditions.merge(LArGMCfg(flags))
215 conditions.merge(LArRoIMapCondAlgCfg(flags))
216
217 return regSelToolCfg(flags, "TTHEC", CompFactory.RegSelCondAlg_LAr,
218 conditions=conditions)
219
220@AccumulatorCache
222 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
223 from LArRecUtils.LArRecUtilsConfig import LArRoIMapCondAlgCfg
224
225 conditions = ComponentAccumulator()
226 conditions.merge(LArGMCfg(flags))
227 conditions.merge(LArRoIMapCondAlgCfg(flags))
228
229 return regSelToolCfg(flags, "FCALEM", CompFactory.RegSelCondAlg_LAr,
230 conditions=conditions)
231
232@AccumulatorCache
234 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
235 from LArRecUtils.LArRecUtilsConfig import LArRoIMapCondAlgCfg
236
237 conditions = ComponentAccumulator()
238 conditions.merge(LArGMCfg(flags))
239 conditions.merge(LArRoIMapCondAlgCfg(flags))
240
241 return regSelToolCfg(flags, "FCALHAD", CompFactory.RegSelCondAlg_LAr,
242 conditions=conditions)
243
244@AccumulatorCache
246 from TileByteStream.TileHid2RESrcIDConfig import TileHid2RESrcIDCondAlgCfg
247 return regSelToolCfg(flags, "TILE", CompFactory.RegSelCondAlg_Tile,
248 conditions=TileHid2RESrcIDCondAlgCfg(flags, ForHLT=True))
249
250
251def regSelToolsCfg( flags, detNames ):
252 '''
253 Get a list of RegionSelector tools for given detector look-up tables if the corresponding Detector flags are enabled
254 '''
255 acc = ComponentAccumulator()
256 regSelTools = []
257 for det in detNames:
258 flagName = det
259 if det in ['TTEM', 'TTHEC', 'FCALEM', 'FCALHAD']:
260 flagName = 'LAr'
261 elif det == 'TILE':
262 flagName = 'Tile'
263 elif det == 'STGC':
264 flagName = 'sTGC'
265 detFlag = f'Enable{flagName}'
266 detEnabled = getattr(flags.Detector, detFlag)
267 if not detEnabled:
268 _log.debug('regSelToolsCfg: skip adding detector "%s" because the flag Detector.%s is False', det, detFlag)
269 continue
270 funcName = f'regSelTool_{det}_Cfg'
271 func = globals().get(funcName, None)
272 if func is None:
273 raise RuntimeError('regSelToolsCfg: cannot add detector "' + det + '", RegSelToolConfig does not have a function ' + funcName)
274 regSelTools += [acc.popToolsAndMerge(func(flags))]
275 acc.setPrivateTools(regSelTools)
276 return acc
277
278
279# unit test
280if __name__=='__main__':
281 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
282 from AthenaConfiguration.AllConfigFlags import initConfigFlags
283 from AthenaConfiguration import DetectorConfigFlags, TestDefaults
284 from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
285 import sys
286
287 flags = initConfigFlags()
288 flags.Input.Files = TestDefaults.defaultTestFiles.RAW_RUN3
289 flags.GeoModel.AtlasVersion = TestDefaults.defaultGeometryTags.RUN3
290 flags.IOVDb.GlobalTag = TestDefaults.defaultConditionsTags.RUN3_DATA23
291 flags.Exec.MaxEvents = 1
292 flags.Concurrency.NumThreads = 1
293
294 # Strict dependency checking
295 flags.Input.FailOnUnknownCollections = True
296 flags.Scheduler.AutoLoadUnmetDependencies = False
297
298 # have to add a printLUT=True flag, so it can be tested in the regSelToolCgf
299 # and passed in to _createRe=gSelTool woithout having to add it to *every* tool config
300
301 flags.addFlag( "PrintLUT", True )
302
303 detNames = sys.argv[1:]
304
305 # Toggle detectors. Note that we are not toggling the geometry because this would
306 # result in un-physical configurations that we are not supporting in reco anyway.
307
308 DetectorConfigFlags.disableDetectors(flags, DetectorConfigFlags.allDetectors +
309 list(DetectorConfigFlags.allGroups.keys()), toggle_geometry=False)
310
311 DetectorConfigFlags.enableDetectors(flags, detNames, toggle_geometry=False)
312
313 flags.lock()
314
315 acc = MainServicesCfg(flags)
316 acc.merge(ByteStreamReadCfg(flags))
317
318 if 'LAr' in detNames:
319 detNames.remove('LAr')
320 detNames += ['TTEM', 'TTHEC', 'FCALEM', 'FCALHAD']
321 if 'Tile' in detNames:
322 detNames.remove('Tile')
323 detNames.append('TILE')
324 if 'sTGC' in detNames:
325 detNames.remove('sTGC')
326 detNames.append('STGC')
327
328 toolsCfg = regSelToolsCfg(flags, detNames)
329
330 alg = CompFactory.RegSelToolTester(
331 RegionSelectorTools = acc.popToolsAndMerge(toolsCfg) )
332
333 acc.addEventAlgo(alg, sequenceName='AthAlgSeq')
334
335 sys.exit(acc.run().isFailure())
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132
_createRegSelCondAlg(detector, CondAlgConstructor, printTable=False)
regSelToolCfg(flags, detector, algorithm, readout_geometry=None, conditions=None)
regSelToolsCfg(flags, detNames)
_createRegSelTool(detector, enable)