3 from PyUtils.MetaReader
import read_metadata, lite_primary_keys_to_keep, lite_TagInfo_keys_to_keep
4 from AthenaCommon.Logging
import logging
5 from functools
import lru_cache
7 msg = logging.getLogger(
'AutoConfigFlags')
10 _fileMetaData = dict()
19 msg.debug(
"Loaded using 'lite' %s",
str(self.
metadata))
25 def get(self, key, default):
29 and key
not in lite_primary_keys_to_keep \
30 and key
not in lite_TagInfo_keys_to_keep:
31 msg.info(
"Looking into the file in 'peeker' mode as the configuration requires more details: %s ", key)
43 return self.
get(key,
None)
54 msg.info(
"Running an input-less job. Will have empty metadata.")
56 raise RuntimeError(
"Metadata can not be read in an input-less job.")
57 if isinstance(filenames, str):
58 filenames = [filenames]
59 if '_ATHENA_GENERIC_INPUTFILE_NAME_' in filenames:
60 raise RuntimeError(
'Input file name not set, instead _ATHENA_GENERIC_INPUTFILE_NAME_ found. Cannot read metadata.')
61 for filename
in filenames:
62 if filename
not in _fileMetaData:
63 msg.info(
"Obtaining metadata of auto-configuration by peeking into '%s'", filename)
65 if _fileMetaData[filename][
'nentries']
not in [
None, 0]:
66 return _fileMetaData[filename]
68 msg.info(
"The file: %s has no entries, going to the next one for harvesting the metadata", filename)
69 msg.info(
"No file with events found, returning anyways metadata associated to the first file %s", filenames[0])
70 return _fileMetaData[filenames[0]]
73 """Read geometry database for all detectors"""
75 from AtlasGeoModel
import CommonGeoDB
76 from PixelGeoModel
import PixelGeoDB
77 from LArGeoAlgsNV
import LArGeoDB
78 from MuonGeoModel
import MuonGeoDB
82 from AtlasGeoModel.AtlasGeoDBInterface
import AtlasGeoDBInterface
83 dbGeomCursor = AtlasGeoDBInterface(geoTag)
84 dbGeomCursor.ConnectAndBrowseGeoDB()
86 params = {
'Common' : CommonGeoDB.InitializeGeometryParameters(dbGeomCursor),
90 'Luminosity' : CommonGeoDB.InitializeLuminosityDetectorParameters(dbGeomCursor),
93 msg.debug(
'Config parameters retrieved from Geometry DB (Frontier/Oracle):')
94 for key
in params.keys():
95 msg.debug(f
'{key} -> {params[key]}')
98 from AtlasGeoModel.AtlasGeoDBInterface
import AtlasGeoDBInterface_SQLite
99 sqliteReader = AtlasGeoDBInterface_SQLite(geoTag,sqliteDBFullPath)
100 sqliteReader.ConnectToDB()
102 params = {
'Common' : CommonGeoDB.InitializeGeometryParameters_SQLite(sqliteReader),
106 'Luminosity' : CommonGeoDB.InitializeLuminosityDetectorParameters_SQLite(sqliteReader),
109 msg.debug(
'Config parameters retrieved from Geometry DB (SQLite):')
110 for key
in params.keys():
111 msg.debug(f
'{key} -> {params[key]}')
116 @lru_cache(maxsize=4)
118 """Query geometry DB for detector description. Returns dictionary with
119 detector description. Queries DB for each tag only once.
121 geoTag: geometry tag (e.g. ATLAS-R2-2016-01-00-01)
124 raise ValueError(
"No geometry tag specified")
127 detDescrInfo[
"geomTag"] = geoTag
131 @lru_cache(maxsize=4)
133 """Query geometry DB for detector description.
134 Returns a set of detectors used in a geometry tag.
136 geoTag: geometry tag (e.g. ATLAS-R2-2016-01-00-01)
139 detectors.add(
'Bpipe')
141 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
not in [
'RUN1',
'RUN2',
'RUN3']:
142 detectors.add(
'ITkPixel')
143 detectors.add(
'ITkStrip')
144 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Luminosity'][
'BCMPrime']:
145 detectors.add(
'BCMPrime')
146 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Luminosity'][
'PLR']:
149 detectors.add(
'Pixel')
157 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
not in [
'RUN1',
'RUN2',
'RUN3']:
158 detectors.add(
'HGTD')
161 detectors.add(
'Tile')
162 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
in [
'RUN1',
'RUN2',
'RUN3']:
163 detectors.add(
'MBTS')
165 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasMDT']:
167 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasRPC']:
169 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasTGC']:
171 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasCSC']:
173 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasSTGC']:
174 detectors.add(
'sTGC')
175 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasMM']:
179 detectors.add(
'Lucid')
180 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
not in [
'RUN1']:
183 detectors.add(
'ALFA')
184 detectors.add(
'FwdRegion')
192 from .RunToTimestampData
import RunToTimestampDict
193 return RunToTimestampDict
197 """This is used to hold a dictionary of the form
198 {152166:1269948352889940910, ...} to allow the
199 timestamp to be determined from the run.
202 timeStamps = [run2timestampDict.get(runNumber,1)
for runNumber
in runNumbers]
207 """Read in GeneratorsInfo from the input file
209 from AthenaConfiguration.Enums
import ProductionStep
210 inputFiles = flags.Input.Files
211 if flags.Common.ProductionStep
in [ProductionStep.Overlay, ProductionStep.FastChain]
and not flags.Overlay.DataOverlay
and flags.Input.SecondaryFiles:
213 inputFiles = flags.Input.SecondaryFiles
214 generatorsString =
""
215 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
217 generatorsString =
GetFileMD(inputFiles).
get(
"generators",
"")
218 from GeneratorConfig.Versioning
import generatorsGetFromMetadata
223 """Read in special simulation job option fragments based on metadata
224 passed by the evgen stage
226 specialConfigDict = dict()
227 legacyPreIncludeToCAPostInclude = {
'SimulationJobOptions/preInclude.AMSB.py' :
'Charginos.CharginosConfig.AMSB_Cfg',
228 'SimulationJobOptions/preInclude.Monopole.py' :
'Monopole.MonopoleConfig.MonopoleCfg',
229 'SimulationJobOptions/preInclude.Quirks.py' :
'Quirks.QuirksConfig.QuirksCfg',
230 'SimulationJobOptions/preInclude.SleptonsLLP.py' :
'Sleptons.SleptonsConfig.SleptonsLLPCfg',
231 'SimulationJobOptions/preInclude.GMSB.py' :
'Sleptons.SleptonsConfig.GMSB_Cfg',
232 'SimulationJobOptions/preInclude.Qball.py' :
'Monopole.MonopoleConfig.QballCfg',
233 'SimulationJobOptions/preInclude.RHadronsPythia8.py' :
'RHadrons.RHadronsConfig.RHadronsCfg',
234 'SimulationJobOptions/preInclude.fcp.py' :
'Monopole.MonopoleConfig.fcpCfg' }
235 legacyPreIncludeToCAPreInclude = {
'SimulationJobOptions/preInclude.AMSB.py' :
None,
236 'SimulationJobOptions/preInclude.Monopole.py' :
'Monopole.MonopoleConfig.MonopolePreInclude',
237 'SimulationJobOptions/preInclude.Quirks.py' :
None,
238 'SimulationJobOptions/preInclude.SleptonsLLP.py' :
None,
239 'SimulationJobOptions/preInclude.GMSB.py' :
None,
240 'SimulationJobOptions/preInclude.Qball.py' :
'Monopole.MonopoleConfig.QballPreInclude',
241 'SimulationJobOptions/preInclude.RHadronsPythia8.py' :
'RHadrons.RHadronsConfig.RHadronsPreInclude',
242 'SimulationJobOptions/preInclude.fcp.py' :
'Monopole.MonopoleConfig.fcpPreInclude' }
243 specialConfigString =
''
244 from AthenaConfiguration.Enums
import ProductionStep
245 inputFiles = flags.Input.Files
246 secondaryInputFiles = flags.Input.SecondaryFiles
247 if flags.Common.ProductionStep
in [ProductionStep.Overlay, ProductionStep.FastChain]
and not flags.Overlay.DataOverlay
and flags.Input.SecondaryFiles:
249 inputFiles = flags.Input.SecondaryFiles
250 secondaryInputFiles = flags.Input.Files
251 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
252 if len(inputFiles)>0:
253 specialConfigString =
GetFileMD(inputFiles).
get(
'specialConfiguration',
'')
254 if (
not len(specialConfigString)
or specialConfigString ==
'NONE')
and len(secondaryInputFiles)>0:
257 specialConfigString =
GetFileMD(secondaryInputFiles).
get(
'specialConfiguration',
'')
258 if len(specialConfigString)>0:
261 spcitems = specialConfigString.split(
";")
262 for spcitem
in spcitems:
265 if not spcitem
or spcitem.upper() ==
"NONE":
268 if "=" not in spcitem:
269 spcitem =
"preInclude=" + spcitem
271 k, v = spcitem.split(
"=")
272 if k ==
"preInclude" and v.endswith(
'.py'):
273 if v ==
'SimulationJobOptions/preInclude.RhadronsPythia8.py':
274 v =
'SimulationJobOptions/preInclude.RHadronsPythia8.py'
275 v1 = legacyPreIncludeToCAPreInclude[v]
277 specialConfigDict[k] = v1
278 v2 = legacyPreIncludeToCAPostInclude[v]
280 specialConfigDict[
'postInclude'] = v2
282 specialConfigDict[k] = v
283 return specialConfigDict