ATLAS Offline Software
DetectorConfigFlags.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.AthConfigFlags import AthConfigFlags
4 from AthenaConfiguration.AutoConfigFlags import getDefaultDetectors
5 
6 # all detectors - used in helper functions
7 allDetectors = [
8  'Bpipe',
9  'BCM', 'Pixel', 'SCT', 'TRT',
10  'BCMPrime', 'PLR', 'ITkPixel', 'ITkStrip', 'HGTD',
11  'LAr', 'Tile', 'MBTS',
12  'CSC', 'MDT', 'RPC', 'TGC', 'sTGC', 'MM',
13  'Lucid', 'ZDC', 'ALFA', 'AFP', 'FwdRegion',
14  'Cavern',
15 ]
16 # all detector groups - used in helper functions
17 allGroups = {
18  'ID': ['BCM', 'Pixel', 'SCT', 'TRT'],
19  'ITk': ['BCMPrime', 'ITkPixel', 'ITkStrip', 'PLR'],
20  'Calo': ['LAr', 'Tile', 'MBTS'],
21  'Muon': ['CSC', 'MDT', 'RPC', 'TGC', 'sTGC', 'MM'],
22  'Forward': ['Lucid', 'ZDC', 'ALFA', 'AFP', 'FwdRegion'],
23 }
24 
25 
27  dcf = AthConfigFlags()
28 
29 
31  dcf.addFlag('Detector.GeometryBpipe', True) # always enabled by default
32 
33  # Inner Detector
34  dcf.addFlag('Detector.GeometryBCM', lambda prevFlags : 'BCM' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
35  dcf.addFlag('Detector.GeometryPixel', lambda prevFlags : 'Pixel' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
36  dcf.addFlag('Detector.GeometrySCT', lambda prevFlags : 'SCT' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
37  dcf.addFlag('Detector.GeometryTRT', lambda prevFlags : 'TRT' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
38  dcf.addFlag('Detector.GeometryID', lambda prevFlags : (prevFlags.Detector.GeometryBCM
39  or prevFlags.Detector.GeometryPixel or prevFlags.Detector.GeometrySCT
40  or prevFlags.Detector.GeometryTRT))
41 
42  # Upgrade ITk Inner Tracker is a separate and parallel detector
43  dcf.addFlag('Detector.GeometryPLR', lambda prevFlags : 'PLR' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
44  dcf.addFlag('Detector.GeometryBCMPrime', lambda prevFlags : 'BCMPrime' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
45  dcf.addFlag('Detector.GeometryITkPixel', lambda prevFlags : 'ITkPixel' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
46  dcf.addFlag('Detector.GeometryITkStrip', lambda prevFlags : 'ITkStrip' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
47  dcf.addFlag('Detector.GeometryITk', lambda prevFlags : (prevFlags.Detector.GeometryBCMPrime
48  or prevFlags.Detector.GeometryITkPixel
49  or prevFlags.Detector.GeometryITkStrip
50  or prevFlags.Detector.GeometryPLR))
51  # HGTD
52  dcf.addFlag('Detector.GeometryHGTD', lambda prevFlags : 'HGTD' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
53 
54  # Calorimeters
55  dcf.addFlag('Detector.GeometryLAr', lambda prevFlags : 'LAr' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath)) # Add separate em HEC and FCAL flags?
56  dcf.addFlag('Detector.GeometryTile', lambda prevFlags : 'Tile' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
57  dcf.addFlag('Detector.GeometryMBTS', lambda prevFlags : (prevFlags.Detector.GeometryLAr and 'MBTS' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath)))
58  dcf.addFlag('Detector.GeometryCalo', lambda prevFlags : (prevFlags.Detector.GeometryLAr or prevFlags.Detector.GeometryTile))
59 
60  # Muon Spectrometer
61  dcf.addFlag('Detector.GeometryCSC', lambda prevFlags : 'CSC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
62  dcf.addFlag('Detector.GeometryMDT', lambda prevFlags : 'MDT' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
63  dcf.addFlag('Detector.GeometryRPC', lambda prevFlags : 'RPC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
64  dcf.addFlag('Detector.GeometryTGC', lambda prevFlags : 'TGC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
65  dcf.addFlag('Detector.GeometrysTGC', lambda prevFlags : 'sTGC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
66  dcf.addFlag('Detector.GeometryMM', lambda prevFlags : 'MM' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath))
67  dcf.addFlag('Detector.GeometryMuon', lambda prevFlags : (prevFlags.Detector.GeometryCSC or prevFlags.Detector.GeometryMDT
68  or prevFlags.Detector.GeometryRPC or prevFlags.Detector.GeometryTGC
69  or prevFlags.Detector.GeometrysTGC or prevFlags.Detector.GeometryMM))
70 
71  # Forward detectors (disabled by default)
72  dcf.addFlag('Detector.GeometryLucid', lambda prevFlags : 'Lucid' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=not prevFlags.Input.isMC))
73  dcf.addFlag('Detector.GeometryZDC', lambda prevFlags : 'ZDC' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=not prevFlags.Input.isMC))
74  dcf.addFlag('Detector.GeometryALFA', lambda prevFlags : 'ALFA' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=not prevFlags.Input.isMC))
75  dcf.addFlag('Detector.GeometryAFP', lambda prevFlags : 'AFP' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=not prevFlags.Input.isMC))
76  dcf.addFlag('Detector.GeometryFwdRegion', lambda prevFlags : 'FwdRegion' in getDefaultDetectors(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB, prevFlags.GeoModel.SQLiteDBFullPath, includeForward=not prevFlags.Input.isMC))
77  dcf.addFlag('Detector.GeometryForward', lambda prevFlags : (prevFlags.Detector.GeometryLucid or prevFlags.Detector.GeometryZDC
78  or prevFlags.Detector.GeometryALFA or prevFlags.Detector.GeometryAFP
79  or prevFlags.Detector.GeometryFwdRegion))
80 
81  # Cavern (disabled by default)
82  dcf.addFlag('Detector.GeometryCavern', False)
83 
84 
85 
88  dcf.addFlag('Detector.EnableBCM', lambda prevFlags : prevFlags.Detector.GeometryBCM)
89  dcf.addFlag('Detector.EnablePixel', lambda prevFlags : prevFlags.Detector.GeometryPixel)
90  dcf.addFlag('Detector.EnableSCT', lambda prevFlags : prevFlags.Detector.GeometrySCT)
91  dcf.addFlag('Detector.EnableTRT', lambda prevFlags : prevFlags.Detector.GeometryTRT)
92  dcf.addFlag('Detector.EnableID', lambda prevFlags : prevFlags.Detector.GeometryID and
93  (prevFlags.Detector.EnableBCM
94  or prevFlags.Detector.EnablePixel or prevFlags.Detector.EnableSCT
95  or prevFlags.Detector.EnableTRT))
96 
97  # Upgrade ITk Inner Tracker is a separate and parallel detector
98  dcf.addFlag('Detector.EnablePLR', lambda prevFlags : prevFlags.Detector.GeometryPLR)
99  dcf.addFlag('Detector.EnableBCMPrime', lambda prevFlags : prevFlags.Detector.GeometryBCMPrime)
100  dcf.addFlag('Detector.EnableITkPixel', lambda prevFlags : prevFlags.Detector.GeometryITkPixel)
101  dcf.addFlag('Detector.EnableITkStrip', lambda prevFlags : prevFlags.Detector.GeometryITkStrip)
102  dcf.addFlag('Detector.EnableITk', lambda prevFlags : prevFlags.Detector.GeometryITk and
103  (prevFlags.Detector.EnableBCMPrime
104  or prevFlags.Detector.EnableITkPixel
105  or prevFlags.Detector.EnableITkStrip
106  or prevFlags.Detector.EnablePLR))
107  # HGTD
108  dcf.addFlag('Detector.EnableHGTD', lambda prevFlags : prevFlags.Detector.GeometryHGTD)
109 
110  # Calorimeters
111  dcf.addFlag('Detector.EnableLAr', lambda prevFlags : prevFlags.Detector.GeometryLAr)
112  dcf.addFlag('Detector.EnableTile', lambda prevFlags : prevFlags.Detector.GeometryTile)
113  dcf.addFlag('Detector.EnableMBTS', lambda prevFlags : prevFlags.Detector.GeometryMBTS)
114  dcf.addFlag('Detector.EnableL1Calo', lambda prevFlags : (prevFlags.Detector.EnableLAr or prevFlags.Detector.EnableTile))
115  dcf.addFlag('Detector.EnableCalo', lambda prevFlags : prevFlags.Detector.GeometryCalo and
116  (prevFlags.Detector.EnableLAr or prevFlags.Detector.EnableTile))
117 
118  # Muon Spectrometer
119  dcf.addFlag('Detector.EnableCSC', lambda prevFlags : prevFlags.Detector.GeometryCSC)
120  dcf.addFlag('Detector.EnableMDT', lambda prevFlags : prevFlags.Detector.GeometryMDT)
121  dcf.addFlag('Detector.EnableRPC', lambda prevFlags : prevFlags.Detector.GeometryRPC)
122  dcf.addFlag('Detector.EnableTGC', lambda prevFlags : prevFlags.Detector.GeometryTGC)
123  dcf.addFlag('Detector.EnablesTGC', lambda prevFlags : prevFlags.Detector.GeometrysTGC)
124  dcf.addFlag('Detector.EnableMM', lambda prevFlags : prevFlags.Detector.GeometryMM)
125  dcf.addFlag('Detector.EnableMuon', lambda prevFlags : prevFlags.Detector.GeometryMuon and
126  (prevFlags.Detector.EnableCSC or prevFlags.Detector.EnableMDT
127  or prevFlags.Detector.EnableRPC or prevFlags.Detector.EnableTGC
128  or prevFlags.Detector.EnablesTGC or prevFlags.Detector.EnableMM))
129 
130  # Forward detectors (disabled by default)
131  dcf.addFlag('Detector.EnableLucid', lambda prevFlags : prevFlags.Detector.GeometryLucid)
132  # EnableZDC enables the overall ZDC system, while _ZDC and _RPD refer to the subsystems, which are now independent
133  dcf.addFlag('Detector.EnableZDC', lambda prevFlags : prevFlags.Detector.GeometryZDC)
134  dcf.addFlag('Detector.EnableZDC_ZDC', lambda prevFlags : prevFlags.Detector.GeometryZDC)
135  dcf.addFlag('Detector.EnableZDC_RPD', lambda prevFlags : prevFlags.Detector.GeometryZDC)
136  dcf.addFlag('Detector.EnableALFA', lambda prevFlags : prevFlags.Detector.GeometryALFA)
137  dcf.addFlag('Detector.EnableAFP', lambda prevFlags : prevFlags.Detector.GeometryAFP)
138  dcf.addFlag('Detector.EnableFwdRegion', lambda prevFlags : prevFlags.Detector.GeometryFwdRegion)
139  dcf.addFlag('Detector.EnableForward', lambda prevFlags : prevFlags.Detector.GeometryForward and
140  (prevFlags.Detector.EnableLucid or prevFlags.Detector.EnableZDC
141  or prevFlags.Detector.EnableALFA or prevFlags.Detector.EnableAFP
142  or prevFlags.Detector.EnableFwdRegion))
143 
144  return dcf
145 
146 
147 def getEnabledDetectors(flags, geometry=False):
148  # load flags
149  flags._loadDynaFlags('Detector')
150  values = []
151  for d in allDetectors:
152  # test whether each detector is on
153  name = f'Detector.Geometry{d}' if geometry else f'Detector.Enable{d}'
154  if flags.hasFlag(name):
155  if flags[name] is not False:
156  values.append(d)
157  return values
158 
159 
160 def _parseDetectorsList(flags, detectors):
161  # setup logging
162  from AthenaCommon.Logging import logging
163  log = logging.getLogger('DetectorConfigFlags')
164  # load flags
165  flags._loadDynaFlags('Detector')
166  # compatibility
167  ignored_detectors = ['None', 'Truth', 'DBM']
168  def compatibility_layer(detector):
169  if detector == 'pixel':
170  return 'Pixel'
171  return detector
172 
173  # first check if we have groups
174  groups = {d for d in detectors if d in allGroups.keys()}
175  detectors = {compatibility_layer(d) for d in detectors if d not in allGroups.keys()}
176  for g in groups:
177  log.debug("Evaluating detector group '%s'", g)
178  if g == 'Forward':
179  # forward detectors are special
180  for d in allGroups[g]:
181  log.debug("Appending detector '%s'", d)
182  detectors.add(d)
183  else:
184  # in case of groups only enable defaults
185  for d in allGroups[g]:
186  if d in getDefaultDetectors(flags.GeoModel.AtlasVersion,flags.GeoModel.SQLiteDB,flags.GeoModel.SQLiteDBFullPath):
187  log.debug("Appending detector '%s'", d)
188  detectors.add(d)
189 
190  # check if valid detectors are required
191  for d in detectors:
192  if d not in allDetectors and d not in ignored_detectors:
193  log.warning("Unknown detector '%s'", d)
194 
195  # sort the detectors
196  return [d for d in allDetectors if d in detectors]
197 
198 
199 def _loadDetectorsFromMetaData(flags, key, keep_beampipe=False):
200  from AthenaConfiguration.AutoConfigFlags import GetFileMD
201  detectors = eval(GetFileMD(flags.Input.Files).get(key, '[]'))
202  if not detectors:
203  return []
204 
205  # MBTS compatibility check
206  from AthenaConfiguration.Enums import LHCPeriod
207  if (flags.GeoModel.Run < LHCPeriod.Run4 and 'LAr' in detectors # built as part of LAr
208  or 'TileHitVector#MBTSHits' in flags.Input.TypedCollections
209  or 'TileTTL1Container#TileTTL1MBTS' in flags.Input.TypedCollections):
210  detectors.append('MBTS')
211 
212  if keep_beampipe and flags.Detector.GeometryBpipe:
213  detectors.append('Bpipe')
214 
215  return _parseDetectorsList(flags, detectors)
216 
217 
218 def _getDetectorFlagStatus(flags, list=None, geometry=False):
219  # load flags
220  flags._loadDynaFlags('Detector')
221 
222  values = []
223  for d in allDetectors:
224  # test whether each detector is on
225  name = f'Detector.Geometry{d}' if geometry else f'Detector.Enable{d}'
226  if flags.hasFlag(name):
227  if list is not None:
228  if d in list:
229  values.append('ON')
230  else:
231  values.append('--')
232  else:
233  if flags[name] is not False:
234  values.append('ON')
235  else:
236  values.append('--')
237  else:
238  values.append('n/a')
239  return values
240 
241 
242 def _printDetectorFlags(flags, info_dict):
243  # setup logging
244  from AthenaCommon.Logging import logging
245  log = logging.getLogger('DetectorConfigFlags')
246  # generate common formatting string
247  item_len = 7
248  # initial is always there
249  types = ['Initial']
250  subtypes = ['Geo.', 'Enbl.']
251  format_header = f'%-{item_len * 2}s'
252  if 'metadata_simulated' in info_dict.keys() or 'metadata_digitized' in info_dict.keys():
253  metadata_len = 0
254  if 'metadata_simulated' in info_dict.keys():
255  subtypes.append('Sim.')
256  metadata_len += item_len
257  if 'metadata_digitized' in info_dict.keys():
258  subtypes.append('Digi.')
259  metadata_len += item_len
260  types.append('Metadata' if item_len > 8 else 'Meta.')
261  format_header += f'%-{metadata_len}s'
262  if 'requested_geometry' in info_dict.keys():
263  types.append('Requested')
264  subtypes += ['Geo.', 'Enbl.']
265  format_header += f'%-{item_len * 2}s'
266  # final is always there ?
267  types.append('Final')
268  subtypes += ['Geo.', 'Enbl.']
269  format_header += f'%-{item_len * 2}s'
270 
271  detector_len = 7
272  for d in allDetectors:
273  detector_len = max(detector_len, len(d) + 2)
274 
275  format_header = f'%{detector_len}s ' + format_header
276  format_subheader = f'%{detector_len}s ' + len(subtypes) * f'%-{item_len}s'
277  format = f'%{detector_len}s : ' + len(subtypes) * f'%-{item_len}s'
278  data = [allDetectors] + [v for _, v in info_dict.items()]
279  data = list(map(list, zip(*data)))
280 
281  # print header rows
282  log.info(format_header, *([''] + types))
283  log.info(format_subheader, *([''] + subtypes))
284  # print data
285  for row in data:
286  log.info(format, *row)
287 
288 
289 def setupDetectorFlags(flags, custom_list=None, use_metadata=False, toggle_geometry=False, validate_only=False, keep_beampipe=False):
290  """Setup detector flags from metadata or a list"""
291  info_dict = {}
292  # setup logging
293  from AthenaCommon.Logging import logging
294  log = logging.getLogger('DetectorConfigFlags')
295 
296  initial_set = set(getEnabledDetectors(flags))
297 
298  info_dict['initial_geometry'] = _getDetectorFlagStatus(flags, geometry=True)
299  info_dict['initial_enable'] = _getDetectorFlagStatus(flags, geometry=False)
300 
301  final_set = initial_set
302  has_metadata = False
303  if use_metadata:
304  simulated_set = set(_loadDetectorsFromMetaData(flags, 'SimulatedDetectors', keep_beampipe=keep_beampipe))
305  digitized_set = set(_loadDetectorsFromMetaData(flags, 'DigitizedDetectors', keep_beampipe=keep_beampipe))
306  if simulated_set:
307  has_metadata = True
308  info_dict['metadata_simulated'] = _getDetectorFlagStatus(flags, list=simulated_set, geometry=False)
309  if digitized_set:
310  has_metadata = True
311  info_dict['metadata_digitized'] = _getDetectorFlagStatus(flags, list=digitized_set, geometry=False)
312 
313  if digitized_set and digitized_set != initial_set:
314  final_set = digitized_set
315  elif simulated_set and simulated_set != initial_set:
316  final_set = simulated_set
317 
318  requested_inconsistency_set = set()
319  if custom_list is not None and custom_list:
320  requested_set = set(_parseDetectorsList(flags, custom_list))
321  if toggle_geometry:
322  info_dict['requested_geometry'] = _getDetectorFlagStatus(flags, list=requested_set, geometry=True)
323  else:
324  info_dict['requested_geometry'] = info_dict['initial_geometry']
325  info_dict['requested_enable'] = _getDetectorFlagStatus(flags, list=requested_set, geometry=False)
326 
327  if has_metadata:
328  requested_inconsistency_set = requested_set.difference(final_set)
329  final_set = requested_set.intersection(final_set)
330  else:
331  final_set = requested_set
332 
333  info_dict['final_geometry'] = _getDetectorFlagStatus(flags, list=final_set, geometry=True)
334  info_dict['final_enable'] = _getDetectorFlagStatus(flags, list=final_set, geometry=False)
335 
336  _printDetectorFlags(flags, info_dict)
337 
338  if requested_inconsistency_set:
339  log.error('Requested detectors %s which are not enabled in the input file.', list(requested_inconsistency_set))
340  raise ValueError(list(requested_inconsistency_set))
341 
342  if initial_set != final_set:
343  diff_enable = final_set.difference(initial_set)
344  if 'Bpipe' in diff_enable and (keep_beampipe or flags.Detector.GeometryBpipe):
345  diff_enable.remove('Bpipe')
346  diff_disable = initial_set.difference(final_set)
347  if diff_enable:
348  log.info('Enabling detectors: %s', _parseDetectorsList(flags, diff_enable))
349  if diff_disable:
350  log.info('Disabling detectors: %s', _parseDetectorsList(flags, diff_disable))
351  setupDetectorsFromList(flags, final_set, toggle_geometry, validate_only)
352 
353 
354 def setupDetectorsFromList(flags, detectors, toggle_geometry=False, validate_only=False):
355  """Setup (toggle) detectors from a pre-defined list"""
356  changed = False
357  # setup logging
358  from AthenaCommon.Logging import logging
359  log = logging.getLogger('DetectorConfigFlags')
360  # parse the list
361  detectors = _parseDetectorsList(flags, detectors)
362 
363  # print summary
364  if validate_only:
365  log.info('Required detectors: %s', detectors)
366  else:
367  log.debug('Setting detectors to: %s', detectors)
368 
369  # go through all of the detectors and check what should happen
370  for d in allDetectors:
371  status = d in detectors
372  name = f'Detector.Enable{d}'
373  if flags.hasFlag(name):
374  if flags[name] != status:
375  changed = True
376  if validate_only:
377  log.warning("Flag '%s' should be %s but is set to %s", name, status, not status)
378  else:
379  log.debug("Toggling '%s' from %s to %s", name, not status, status)
380  flags._set(name, status)
381  if toggle_geometry:
382  name = f'Detector.Geometry{d}'
383  if flags.hasFlag(name):
384  if flags[name] != status:
385  changed = True
386  if validate_only:
387  log.warning("Flag '%s' should be %s but is set to %s", name, status, not status)
388  else:
389  log.debug("Toggling '%s' from %s to %s", name, not status, status)
390  flags._set(name, status)
391 
392  return changed
393 
394 
395 def enableDetectors(flags, detectors, toggle_geometry=False):
396  """Enable detectors from a list"""
397  changed = False
398  # setup logging
399  from AthenaCommon.Logging import logging
400  log = logging.getLogger('DetectorConfigFlags')
401  # parse the list
402  detectors = _parseDetectorsList(flags, detectors)
403 
404  # debugging
405  log.info('Enabling detectors: %s', detectors)
406 
407  # go through all of the detectors and enable them if needed
408  for d in detectors:
409  name = f'Detector.Enable{d}'
410  if flags.hasFlag(name):
411  if flags[name] is not True:
412  changed = True
413  log.info("Enabling '%s'", name)
414  flags._set(name, True)
415  if toggle_geometry:
416  name = f'Detector.Geometry{d}'
417  if flags.hasFlag(name):
418  if flags[name] is not True:
419  changed = True
420  log.info("Enabling '%s'", name)
421  flags._set(name, True)
422 
423  return changed
424 
425 
426 def disableDetectors(flags, detectors, toggle_geometry=False):
427  """Disable detectors from a list"""
428  changed = False
429  # setup logging
430  from AthenaCommon.Logging import logging
431  log = logging.getLogger('DetectorConfigFlags')
432  # parse the list
433  detectors = _parseDetectorsList(flags, detectors)
434 
435  # debugging
436  log.info('Disabling detectors: %s', detectors)
437 
438  # go through all of the detectors and disable them if needed
439  for d in detectors:
440  name = f'Detector.Enable{d}'
441  if flags.hasFlag(name):
442  if flags[name] is not False:
443  changed = True
444  log.info("Disabling '%s'", name)
445  flags._set(name, False)
446  if toggle_geometry:
447  name = f'Detector.Geometry{d}'
448  if flags.hasFlag(name):
449  if flags[name] is not False:
450  changed = True
451  log.info("Disabling '%s'", name)
452  flags._set(name, False)
453 
454  return changed
455 
python.DetectorConfigFlags._parseDetectorsList
def _parseDetectorsList(flags, detectors)
Definition: DetectorConfigFlags.py:160
max
#define max(a, b)
Definition: cfImp.cxx:41
python.AutoConfigFlags.getDefaultDetectors
def getDefaultDetectors(geoTag, sqliteDB, sqliteDBFullPath, includeForward=False)
Definition: AutoConfigFlags.py:132
python.DetectorConfigFlags.getEnabledDetectors
def getEnabledDetectors(flags, geometry=False)
Definition: DetectorConfigFlags.py:147
python.DetectorConfigFlags._loadDetectorsFromMetaData
def _loadDetectorsFromMetaData(flags, key, keep_beampipe=False)
Definition: DetectorConfigFlags.py:199
python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True)
Definition: AutoConfigFlags.py:51
python.DetectorConfigFlags._getDetectorFlagStatus
def _getDetectorFlagStatus(flags, list=None, geometry=False)
Definition: DetectorConfigFlags.py:218
python.DetectorConfigFlags.createDetectorConfigFlags
def createDetectorConfigFlags()
Definition: DetectorConfigFlags.py:26
python.DetectorConfigFlags.enableDetectors
def enableDetectors(flags, detectors, toggle_geometry=False)
Definition: DetectorConfigFlags.py:395
python.DetectorConfigFlags.setupDetectorsFromList
def setupDetectorsFromList(flags, detectors, toggle_geometry=False, validate_only=False)
Definition: DetectorConfigFlags.py:354
python.DetectorConfigFlags.disableDetectors
def disableDetectors(flags, detectors, toggle_geometry=False)
Definition: DetectorConfigFlags.py:426
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
python.DetectorConfigFlags.setupDetectorFlags
def setupDetectorFlags(flags, custom_list=None, use_metadata=False, toggle_geometry=False, validate_only=False, keep_beampipe=False)
Definition: DetectorConfigFlags.py:289
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
python.DetectorConfigFlags._printDetectorFlags
def _printDetectorFlags(flags, info_dict)
Definition: DetectorConfigFlags.py:242