ATLAS Offline Software
Classes | Functions | Variables
python.AutoConfigFlags Namespace Reference

Classes

class  DynamicallyLoadMetadata
 

Functions

def GetFileMD (filenames, allowEmpty=True, maxLevel='peeker')
 
def _initializeGeometryParameters (geoTag, sqliteDB, sqliteDBFullPath)
 
def DetDescrInfo (geoTag, sqliteDB, sqliteDBFullPath)
 
def getDefaultDetectors (geoTag, sqliteDB, sqliteDBFullPath, includeForward=False)
 
def getRunToTimestampDict ()
 
def getInitialTimeStampsFromRunNumbers (runNumbers)
 
def getGeneratorsInfo (flags)
 
def getSpecialConfigurationMetadata (flags)
 

Variables

 msg = logging.getLogger('AutoConfigFlags')
 
 _fileMetaData = dict()
 

Function Documentation

◆ _initializeGeometryParameters()

def python.AutoConfigFlags._initializeGeometryParameters (   geoTag,
  sqliteDB,
  sqliteDBFullPath 
)
private
Read geometry database for all detectors

Definition at line 88 of file AutoConfigFlags.py.

88 def _initializeGeometryParameters(geoTag,sqliteDB,sqliteDBFullPath):
89  """Read geometry database for all detectors"""
90 
91  from AtlasGeoModel import CommonGeoDB
92  from PixelGeoModel import PixelGeoDB
93  from LArGeoAlgsNV import LArGeoDB
94  from MuonGeoModel import MuonGeoDB
95 
96  if not sqliteDB:
97  # Read parameters from Oracle/Frontier
98  from AtlasGeoModel.AtlasGeoDBInterface import AtlasGeoDBInterface
99  dbGeomCursor = AtlasGeoDBInterface(geoTag)
100  dbGeomCursor.ConnectAndBrowseGeoDB()
101 
102  params = { 'Common' : CommonGeoDB.InitializeGeometryParameters(dbGeomCursor),
103  'Pixel' : PixelGeoDB.InitializeGeometryParameters(dbGeomCursor),
104  'LAr' : LArGeoDB.InitializeGeometryParameters(dbGeomCursor),
105  'Muon' : MuonGeoDB.InitializeGeometryParameters(dbGeomCursor),
106  'Luminosity' : CommonGeoDB.InitializeLuminosityDetectorParameters(dbGeomCursor),
107  }
108 
109  msg.debug('Config parameters retrieved from Geometry DB (Frontier/Oracle):')
110  for key in params.keys():
111  msg.debug(f'{key} -> {params[key]}')
112  else:
113  # Read parameters from SQLite
114  from AtlasGeoModel.AtlasGeoDBInterface import AtlasGeoDBInterface_SQLite
115  sqliteReader = AtlasGeoDBInterface_SQLite(geoTag,sqliteDBFullPath)
116  sqliteReader.ConnectToDB()
117 
118  params = { 'Common' : CommonGeoDB.InitializeGeometryParameters_SQLite(sqliteReader),
119  'Pixel' : PixelGeoDB.InitializeGeometryParameters_SQLite(sqliteReader),
120  'LAr' : LArGeoDB.InitializeGeometryParameters_SQLite(sqliteReader),
121  'Muon' : MuonGeoDB.InitializeGeometryParameters_SQLite(sqliteReader),
122  'Luminosity' : CommonGeoDB.InitializeLuminosityDetectorParameters_SQLite(sqliteReader),
123  }
124 
125  msg.debug('Config parameters retrieved from Geometry DB (SQLite):')
126  for key in params.keys():
127  msg.debug(f'{key} -> {params[key]}')
128 
129  return params
130 
131 
132 @lru_cache(maxsize=4) # maxsize=1 should be enough for most jobs

◆ DetDescrInfo()

def python.AutoConfigFlags.DetDescrInfo (   geoTag,
  sqliteDB,
  sqliteDBFullPath 
)
Query geometry DB for detector description. Returns dictionary with
detector description. Queries DB for each tag only once.

geoTag: geometry tag (e.g. ATLAS-R2-2016-01-00-01)

Definition at line 133 of file AutoConfigFlags.py.

133 def DetDescrInfo(geoTag, sqliteDB, sqliteDBFullPath):
134  """Query geometry DB for detector description. Returns dictionary with
135  detector description. Queries DB for each tag only once.
136 
137  geoTag: geometry tag (e.g. ATLAS-R2-2016-01-00-01)
138  """
139  if not geoTag:
140  raise ValueError("No geometry tag specified")
141 
142  detDescrInfo = _initializeGeometryParameters(geoTag,sqliteDB,sqliteDBFullPath)
143  detDescrInfo["geomTag"] = geoTag
144  return detDescrInfo
145 
146 
147 @lru_cache(maxsize=4) # maxsize=1 should be enough for most jobs

◆ getDefaultDetectors()

def python.AutoConfigFlags.getDefaultDetectors (   geoTag,
  sqliteDB,
  sqliteDBFullPath,
  includeForward = False 
)
Query geometry DB for detector description.
Returns a set of detectors used in a geometry tag.

geoTag: geometry tag (e.g. ATLAS-R2-2016-01-00-01)

Definition at line 148 of file AutoConfigFlags.py.

148 def getDefaultDetectors(geoTag, sqliteDB, sqliteDBFullPath, includeForward=False):
149  """Query geometry DB for detector description.
150  Returns a set of detectors used in a geometry tag.
151 
152  geoTag: geometry tag (e.g. ATLAS-R2-2016-01-00-01)
153  """
154  detectors = DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Common']['Detectors']
155 
156  manualConfig = not DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Common']["DetectorsConfigured"]
157 
158 
159  if manualConfig:
160  detectors.add('Bpipe')
161  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Common']['Run'] not in ['RUN1', 'RUN2', 'RUN3']: # RUN4 and beyond
162  detectors.add('ITkPixel')
163  detectors.add('ITkStrip')
164  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Luminosity']['BCMPrime']:
165  detectors.add('BCMPrime') # since https://gitlab.cern.ch/Atlas-Inner-Tracking/ITKLayouts/-/merge_requests/347 introduced BCMPrime geometry
166  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Luminosity']['PLR']:
167  detectors.add('PLR')
168  else:
169  detectors.add('Pixel')
170  detectors.add('SCT')
171  detectors.add('TRT')
172  detectors.add('BCM')
173 
174  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Common']['Run'] not in ['RUN1', 'RUN2', 'RUN3']: # RUN4 and beyond
175  detectors.add('HGTD')
176 
177  detectors.add('LAr')
178  detectors.add('Tile')
179 
180 
181  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Common']['Run'] in ['RUN1', 'RUN2', 'RUN3']:
182  detectors.add('MBTS')
183 
184  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Muon']['HasMDT']:
185  detectors.add('MDT')
186  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Muon']['HasRPC']:
187  detectors.add('RPC')
188  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Muon']['HasTGC']:
189  detectors.add('TGC')
190  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Muon']['HasCSC']:
191  detectors.add('CSC')
192  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Muon']['HasSTGC']:
193  detectors.add('sTGC')
194  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Muon']['HasMM']:
195  detectors.add('MM')
196 
197  if includeForward:
198  detectors.add('Lucid')
199  if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)['Common']['Run'] not in ['RUN1']:
200  detectors.add('AFP')
201  detectors.add('ZDC')
202  detectors.add('ALFA')
203  detectors.add('FwdRegion')
204 
205  return detectors
206 
207 
208 # Based on RunDMCFlags.py

◆ GetFileMD()

def python.AutoConfigFlags.GetFileMD (   filenames,
  allowEmpty = True,
  maxLevel = 'peeker' 
)

Definition at line 65 of file AutoConfigFlags.py.

65 def GetFileMD(filenames, allowEmpty=True, maxLevel='peeker'):
66  if not filenames:
67  if allowEmpty:
68  msg.info("Running an input-less job. Will have empty metadata.")
69  return {}
70  raise RuntimeError("Metadata can not be read in an input-less job.")
71  if isinstance(filenames, str):
72  filenames = [filenames]
73  if '_ATHENA_GENERIC_INPUTFILE_NAME_' in filenames:
74  raise RuntimeError('Input file name not set, instead _ATHENA_GENERIC_INPUTFILE_NAME_ found. Cannot read metadata.')
75  for filename in filenames:
76  if filename not in _fileMetaData:
77  msg.info("Obtaining metadata of auto-configuration by peeking into '%s'", filename)
78  _fileMetaData[filename] = DynamicallyLoadMetadata(filename, maxLevel)
79  if _fileMetaData[filename].maxAccessLevel != maxLevel:
80  _fileMetaData[filename].maxAccessLevel = maxLevel
81  if _fileMetaData[filename]['nentries'] not in [None, 0]:
82  return _fileMetaData[filename]
83  else:
84  msg.info("The file: %s has no entries, going to the next one for harvesting the metadata", filename)
85  msg.info("No file with events found, returning anyways metadata associated to the first file %s", filenames[0])
86  return _fileMetaData[filenames[0]]
87 

◆ getGeneratorsInfo()

def python.AutoConfigFlags.getGeneratorsInfo (   flags)
Read in GeneratorsInfo from the input file

Definition at line 225 of file AutoConfigFlags.py.

225 def getGeneratorsInfo(flags):
226  """Read in GeneratorsInfo from the input file
227  """
228  from AthenaConfiguration.Enums import ProductionStep
229  inputFiles = flags.Input.Files
230  if flags.Common.ProductionStep in [ProductionStep.Overlay, ProductionStep.FastChain] and flags.Input.SecondaryFiles and not flags.Overlay.ByteStream:
231  # Do something special for MC Overlay
232  inputFiles = flags.Input.SecondaryFiles
233  generatorsString = ""
234  from AthenaConfiguration.AutoConfigFlags import GetFileMD
235  if inputFiles:
236  generatorsString = GetFileMD(inputFiles).get("generators", "")
237  from GeneratorConfig.Versioning import generatorsGetFromMetadata
238  return generatorsGetFromMetadata( generatorsString )
239 
240 

◆ getInitialTimeStampsFromRunNumbers()

def python.AutoConfigFlags.getInitialTimeStampsFromRunNumbers (   runNumbers)
This is used to hold a dictionary of the form
{152166:1269948352889940910, ...} to allow the
timestamp to be determined from the run.

Definition at line 215 of file AutoConfigFlags.py.

215 def getInitialTimeStampsFromRunNumbers(runNumbers):
216  """This is used to hold a dictionary of the form
217  {152166:1269948352889940910, ...} to allow the
218  timestamp to be determined from the run.
219  """
220  run2timestampDict = getRunToTimestampDict()
221  timeStamps = [run2timestampDict.get(runNumber,1) for runNumber in runNumbers] # Add protection here?
222  return timeStamps
223 
224 

◆ getRunToTimestampDict()

def python.AutoConfigFlags.getRunToTimestampDict ( )

Definition at line 209 of file AutoConfigFlags.py.

210  # this wrapper is intended to avoid an initial import
211  from .RunToTimestampData import RunToTimestampDict
212  return RunToTimestampDict
213 
214 

◆ getSpecialConfigurationMetadata()

def python.AutoConfigFlags.getSpecialConfigurationMetadata (   flags)
Read in special simulation job option fragments based on metadata
passed by the evgen stage

Definition at line 241 of file AutoConfigFlags.py.

242  """Read in special simulation job option fragments based on metadata
243  passed by the evgen stage
244  """
245  specialConfigDict = dict()
246  legacyPreIncludeToCAPostInclude = { 'SimulationJobOptions/preInclude.AMSB.py' : 'Charginos.CharginosConfig.AMSB_Cfg',
247  'SimulationJobOptions/preInclude.Monopole.py' : 'Monopole.MonopoleConfig.MonopoleCfg',
248  'SimulationJobOptions/preInclude.Quirks.py' : 'Quirks.QuirksConfig.QuirksCfg',
249  'SimulationJobOptions/preInclude.SleptonsLLP.py' : 'Sleptons.SleptonsConfig.SleptonsLLPCfg',
250  'SimulationJobOptions/preInclude.GMSB.py' : 'Sleptons.SleptonsConfig.GMSB_Cfg',
251  'SimulationJobOptions/preInclude.Qball.py' : 'Monopole.MonopoleConfig.QballCfg',
252  'SimulationJobOptions/preInclude.RHadronsPythia8.py' : 'RHadrons.RHadronsConfig.RHadronsCfg',
253  'SimulationJobOptions/preInclude.fcp.py' : 'Monopole.MonopoleConfig.fcpCfg' }
254  legacyPreIncludeToCAPreInclude = { 'SimulationJobOptions/preInclude.AMSB.py' : None,
255  'SimulationJobOptions/preInclude.Monopole.py' : 'Monopole.MonopoleConfig.MonopolePreInclude',
256  'SimulationJobOptions/preInclude.Quirks.py' : None,
257  'SimulationJobOptions/preInclude.SleptonsLLP.py' : None,
258  'SimulationJobOptions/preInclude.GMSB.py' : None,
259  'SimulationJobOptions/preInclude.Qball.py' : 'Monopole.MonopoleConfig.QballPreInclude',
260  'SimulationJobOptions/preInclude.RHadronsPythia8.py' : 'RHadrons.RHadronsConfig.RHadronsPreInclude',
261  'SimulationJobOptions/preInclude.fcp.py' : 'Monopole.MonopoleConfig.fcpPreInclude' }
262  specialConfigString = ''
263  from AthenaConfiguration.Enums import ProductionStep
264  inputFiles = flags.Input.Files
265  secondaryInputFiles = flags.Input.SecondaryFiles
266  if flags.Common.ProductionStep in [ProductionStep.Overlay, ProductionStep.FastChain] and not flags.Overlay.DataOverlay and flags.Input.SecondaryFiles:
267  # Do something special for MC Overlay
268  inputFiles = flags.Input.SecondaryFiles
269  secondaryInputFiles = flags.Input.Files
270  from AthenaConfiguration.AutoConfigFlags import GetFileMD
271  if len(inputFiles)>0:
272  specialConfigString = GetFileMD(inputFiles).get('specialConfiguration', '')
273  if (not len(specialConfigString) or specialConfigString == 'NONE') and len(secondaryInputFiles)>0:
274  # If there is no specialConfiguration metadata in the primary
275  # input try the secondary inputs (MC Overlay case)
276  specialConfigString = GetFileMD(secondaryInputFiles).get('specialConfiguration', '')
277  if len(specialConfigString)>0:
278 
280  spcitems = specialConfigString.split(";")
281  for spcitem in spcitems:
282  #print spcitem
283 
284  if not spcitem or spcitem.upper() == "NONE":
285  continue
286 
287  if "=" not in spcitem:
288  spcitem = "preInclude=" + spcitem
289 
290  k, v = spcitem.split("=")
291  if k == "preInclude" and v.endswith('.py'): # Translate old preIncludes into CA-based versions.
292  if v == 'SimulationJobOptions/preInclude.RhadronsPythia8.py':
293  v = 'SimulationJobOptions/preInclude.RHadronsPythia8.py' # ATLASSIM-6687 Fixup for older EVNT files
294  v1 = legacyPreIncludeToCAPreInclude[v]
295  if v1 is not None:
296  specialConfigDict[k] = v1
297  v2 = legacyPreIncludeToCAPostInclude[v]
298  if v2 is not None:
299  specialConfigDict['postInclude'] = v2
300  else:
301  specialConfigDict[k] = v
302  return specialConfigDict
303 

Variable Documentation

◆ _fileMetaData

python.AutoConfigFlags._fileMetaData = dict()
private

Definition at line 10 of file AutoConfigFlags.py.

◆ msg

python.AutoConfigFlags.msg = logging.getLogger('AutoConfigFlags')

Definition at line 7 of file AutoConfigFlags.py.

python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True, maxLevel='peeker')
Definition: AutoConfigFlags.py:65
python.AutoConfigFlags.getGeneratorsInfo
def getGeneratorsInfo(flags)
Definition: AutoConfigFlags.py:225
PixelGeoDB.InitializeGeometryParameters_SQLite
def InitializeGeometryParameters_SQLite(sqliteDbReader)
Definition: PixelGeoDB.py:54
python.AutoConfigFlags.getDefaultDetectors
def getDefaultDetectors(geoTag, sqliteDB, sqliteDBFullPath, includeForward=False)
Definition: AutoConfigFlags.py:148
python.AutoConfigFlags._initializeGeometryParameters
def _initializeGeometryParameters(geoTag, sqliteDB, sqliteDBFullPath)
Definition: AutoConfigFlags.py:88
MuonGeoDB.InitializeGeometryParameters
def InitializeGeometryParameters(dbGeomCursor)
Definition: MuonGeoDB.py:3
LArGeoDB.InitializeGeometryParameters
def InitializeGeometryParameters(dbGeomCursor)
Definition: LArGeoDB.py:3
python.AutoConfigFlags.getRunToTimestampDict
def getRunToTimestampDict()
Definition: AutoConfigFlags.py:209
LArGeoDB.InitializeGeometryParameters_SQLite
def InitializeGeometryParameters_SQLite(sqliteDbReader)
Definition: LArGeoDB.py:34
python.AutoConfigFlags.getInitialTimeStampsFromRunNumbers
def getInitialTimeStampsFromRunNumbers(runNumbers)
Definition: AutoConfigFlags.py:215
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
PixelGeoDB.InitializeGeometryParameters
def InitializeGeometryParameters(dbGeomCursor)
Definition: PixelGeoDB.py:3
python.Versioning.generatorsGetFromMetadata
def generatorsGetFromMetadata(metadataString)
Definition: Versioning.py:32
python.AutoConfigFlags.DetDescrInfo
def DetDescrInfo(geoTag, sqliteDB, sqliteDBFullPath)
Definition: AutoConfigFlags.py:133
python.AutoConfigFlags.getSpecialConfigurationMetadata
def getSpecialConfigurationMetadata(flags)
Definition: AutoConfigFlags.py:241
MuonGeoDB.InitializeGeometryParameters_SQLite
def InitializeGeometryParameters_SQLite(sqliteDbReader)
Definition: MuonGeoDB.py:31