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