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 == "ITkStrip":
46 condAlg.DetEleCollKey = "ITkStripDetectorElementCollection"
47 # No cabling data for ITk
48 condAlg.SCT_CablingData = ""
49 return condAlg
50
51def _createRegSelTool( detector, enable ):
52 """
53 Creates RegSelTool and corresponding cond tool that is needed for its function
54
55 If the enable flag is set - the tool is properly configured, else it is configured NOT to provide the data.
56
57 """
58
59
60 tool = CompFactory.RegSelTool(name="RegSelTool_"+detector)
61
62 # should we enable the look up table access for this subsystem ?
63
64 if not enable:
65 # detector not configured so don't enable
66 # lookup table access
67 tool.Initialised = False
68 return tool
69
70 # add the lookup table to retrieve
71
72 tool.RegSelLUT = "RegSelLUTCondData_"+detector # has to match wiht appropriate RegSelCondAlg
73 tool.Initialised = True
74 return tool
75
76
77def regSelToolCfg(flags, detector, algorithm, readout_geometry=None, conditions=None):
78 ca = ComponentAccumulator()
79 if readout_geometry:
80 ca.merge(readout_geometry)
81 if conditions:
82 ca.merge(conditions)
83 ca.setPrivateTools(_createRegSelTool(detector, True))
84
85 # test if we have a PrintLUT flag ...
86 printLUT = False
87 if flags.hasFlag("PrintLUT"):
88 printLUT = flags.PrintLUT
89
90 the_alg = _createRegSelCondAlg(detector, algorithm, printTable=printLUT)
91 ca.addCondAlgo(the_alg)
92 return ca
93
94
95# inner detector
96@AccumulatorCache
98 from PixelGeoModel.PixelGeoModelConfig import PixelReadoutGeometryCfg
99 from PixelConditionsAlgorithms.PixelConditionsConfig import PixelCablingCondAlgCfg
100 return regSelToolCfg(flags, "Pixel", CompFactory.SiRegSelCondAlg,
101 readout_geometry=PixelReadoutGeometryCfg(flags), conditions=PixelCablingCondAlgCfg(flags))
102
103@AccumulatorCache
105 from SCT_GeoModel.SCT_GeoModelConfig import SCT_ReadoutGeometryCfg
106 from SCT_Cabling.SCT_CablingConfig import SCT_CablingCondAlgCfg
107 return regSelToolCfg(flags, "SCT", CompFactory.SiRegSelCondAlg,
108 readout_geometry=SCT_ReadoutGeometryCfg(flags), conditions=SCT_CablingCondAlgCfg(flags))
109
110@AccumulatorCache
112 from TRT_GeoModel.TRT_GeoModelConfig import TRT_ReadoutGeometryCfg
113 return regSelToolCfg(flags, "TRT", CompFactory.TRT_RegSelCondAlg,
114 readout_geometry=TRT_ReadoutGeometryCfg(flags))
115
116# ITk
117@AccumulatorCache
119 from PixelGeoModelXml.ITkPixelGeoModelConfig import ITkPixelReadoutGeometryCfg
120 return regSelToolCfg(flags, "ITkPixel", CompFactory.SiRegSelCondAlg,
121 readout_geometry=ITkPixelReadoutGeometryCfg(flags))
122
123@AccumulatorCache
125 from StripGeoModelXml.ITkStripGeoModelConfig import ITkStripReadoutGeometryCfg
126 return regSelToolCfg(flags, "ITkStrip", CompFactory.SiRegSelCondAlg,
127 readout_geometry=ITkStripReadoutGeometryCfg(flags))
128
129
130# muon spectrometer
131@AccumulatorCache
133 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
134 result = ComponentAccumulator()
135 result.merge(RegionSelCondAlgCfg(flags, detector = "MDT"))
136 result.setPrivateTools(_createRegSelTool("MDT", True))
137 return result
138
139@AccumulatorCache
141 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
142 result = ComponentAccumulator()
143 result.merge(RegionSelCondAlgCfg(flags, detector = "RPC"))
144 result.setPrivateTools(_createRegSelTool("RPC", True))
145 return result
146
147@AccumulatorCache
149 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
150 result = ComponentAccumulator()
151 result.merge(RegionSelCondAlgCfg(flags, detector = "TGC"))
152 result.setPrivateTools(_createRegSelTool("TGC", True))
153 return result
154
155@AccumulatorCache
157 from MuonConfig.MuonGeometryConfig import MuonGeoModelCfg
158 from MuonConfig.MuonCablingConfig import CSCCablingConfigCfg
159
160 conditions = ComponentAccumulator()
161 conditions.merge(MuonGeoModelCfg(flags))
162 conditions.merge(CSCCablingConfigCfg(flags))
163
164 return regSelToolCfg(flags, "CSC", CompFactory.CSC_RegSelCondAlg,
165 conditions=conditions)
166
167@AccumulatorCache
169 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
170 result = ComponentAccumulator()
171 result.merge(RegionSelCondAlgCfg(flags, detector = "sTGC"))
172 result.setPrivateTools(_createRegSelTool("sTGC", True))
173 return result
174
175@AccumulatorCache
177 from MuonConfig.MuonGeometryConfig import RegionSelCondAlgCfg
178 result = ComponentAccumulator()
179 result.merge(RegionSelCondAlgCfg(flags, detector = "MM"))
180 result.setPrivateTools(_createRegSelTool("MM", True))
181 return result
182
183
184
185# calo
186@AccumulatorCache
188 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
189 from LArRecUtils.LArRecUtilsConfig import LArRoIMapCondAlgCfg
190
191 conditions = ComponentAccumulator()
192 conditions.merge(LArGMCfg(flags))
193 conditions.merge(LArRoIMapCondAlgCfg(flags))
194
195 return regSelToolCfg(flags, "TTEM", CompFactory.RegSelCondAlg_LAr,
196 conditions=conditions)
197
198@AccumulatorCache
200 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
201 from LArRecUtils.LArRecUtilsConfig import LArRoIMapCondAlgCfg
202
203 conditions = ComponentAccumulator()
204 conditions.merge(LArGMCfg(flags))
205 conditions.merge(LArRoIMapCondAlgCfg(flags))
206
207 return regSelToolCfg(flags, "TTHEC", CompFactory.RegSelCondAlg_LAr,
208 conditions=conditions)
209
210@AccumulatorCache
212 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
213 from LArRecUtils.LArRecUtilsConfig import LArRoIMapCondAlgCfg
214
215 conditions = ComponentAccumulator()
216 conditions.merge(LArGMCfg(flags))
217 conditions.merge(LArRoIMapCondAlgCfg(flags))
218
219 return regSelToolCfg(flags, "FCALEM", CompFactory.RegSelCondAlg_LAr,
220 conditions=conditions)
221
222@AccumulatorCache
224 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
225 from LArRecUtils.LArRecUtilsConfig import LArRoIMapCondAlgCfg
226
227 conditions = ComponentAccumulator()
228 conditions.merge(LArGMCfg(flags))
229 conditions.merge(LArRoIMapCondAlgCfg(flags))
230
231 return regSelToolCfg(flags, "FCALHAD", CompFactory.RegSelCondAlg_LAr,
232 conditions=conditions)
233
234@AccumulatorCache
236 from TileByteStream.TileHid2RESrcIDConfig import TileHid2RESrcIDCondAlgCfg
237 return regSelToolCfg(flags, "TILE", CompFactory.RegSelCondAlg_Tile,
238 conditions=TileHid2RESrcIDCondAlgCfg(flags, ForHLT=True))
239
240
241def regSelToolsCfg( flags, detNames ):
242 '''
243 Get a list of RegionSelector tools for given detector look-up tables if the corresponding Detector flags are enabled
244 '''
245 acc = ComponentAccumulator()
246 regSelTools = []
247 for det in detNames:
248 flagName = det
249 if det in ['TTEM', 'TTHEC', 'FCALEM', 'FCALHAD']:
250 flagName = 'LAr'
251 elif det == 'TILE':
252 flagName = 'Tile'
253 elif det == 'STGC':
254 flagName = 'sTGC'
255 detFlag = f'Enable{flagName}'
256 detEnabled = getattr(flags.Detector, detFlag)
257 if not detEnabled:
258 _log.debug('regSelToolsCfg: skip adding detector "%s" because the flag Detector.%s is False', det, detFlag)
259 continue
260 funcName = f'regSelTool_{det}_Cfg'
261 func = globals().get(funcName, None)
262 if func is None:
263 raise RuntimeError('regSelToolsCfg: cannot add detector "' + det + '", RegSelToolConfig does not have a function ' + funcName)
264 regSelTools += [acc.popToolsAndMerge(func(flags))]
265 acc.setPrivateTools(regSelTools)
266 return acc
267
268
269# unit test
270if __name__=='__main__':
271 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
272 from AthenaConfiguration.AllConfigFlags import initConfigFlags
273 from AthenaConfiguration import DetectorConfigFlags, TestDefaults
274 from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
275 import sys
276
277 flags = initConfigFlags()
278 flags.Input.Files = TestDefaults.defaultTestFiles.RAW_RUN3
279 flags.GeoModel.AtlasVersion = TestDefaults.defaultGeometryTags.RUN3
280 flags.IOVDb.GlobalTag = TestDefaults.defaultConditionsTags.RUN3_DATA23
281 flags.Exec.MaxEvents = 1
282 flags.Concurrency.NumThreads = 1
283
284 # Strict dependency checking
285 flags.Input.FailOnUnknownCollections = True
286 flags.Scheduler.AutoLoadUnmetDependencies = False
287
288 # have to add a printLUT=True flag, so it can be tested in the regSelToolCgf
289 # and passed in to _createRe=gSelTool woithout having to add it to *every* tool config
290
291 flags.addFlag( "PrintLUT", True )
292
293 detNames = sys.argv[1:]
294
295 # Toggle detectors. Note that we are not toggling the geometry because this would
296 # result in un-physical configurations that we are not supporting in reco anyway.
297
298 DetectorConfigFlags.disableDetectors(flags, DetectorConfigFlags.allDetectors +
299 list(DetectorConfigFlags.allGroups.keys()), toggle_geometry=False)
300
301 DetectorConfigFlags.enableDetectors(flags, detNames, toggle_geometry=False)
302
303 flags.lock()
304
305 acc = MainServicesCfg(flags)
306 acc.merge(ByteStreamReadCfg(flags))
307
308 if 'LAr' in detNames:
309 detNames.remove('LAr')
310 detNames += ['TTEM', 'TTHEC', 'FCALEM', 'FCALHAD']
311 if 'Tile' in detNames:
312 detNames.remove('Tile')
313 detNames.append('TILE')
314 if 'sTGC' in detNames:
315 detNames.remove('sTGC')
316 detNames.append('STGC')
317
318 toolsCfg = regSelToolsCfg(flags, detNames)
319
320 alg = CompFactory.RegSelToolTester(
321 RegionSelectorTools = acc.popToolsAndMerge(toolsCfg) )
322
323 acc.addEventAlgo(alg, sequenceName='AthAlgSeq')
324
325 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:130
_createRegSelCondAlg(detector, CondAlgConstructor, printTable=False)
regSelToolCfg(flags, detector, algorithm, readout_geometry=None, conditions=None)
regSelToolsCfg(flags, detNames)
_createRegSelTool(detector, enable)