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()
13 def __init__(self, filename, maxLevel='peeker'):
20 msg.debug(
"Loaded using 'lite' %s",
str(self.
metadata))
28 def get(self, key, default):
31 if key
in lite_primary_keys_to_keep
or key
in lite_TagInfo_keys_to_keep:
40 levels = [
'peeker',
'full']
if self.
maxAccessLevel ==
'full' else [
'peeker']
45 msg.info(
"Looking into the file in '%s' mode as the configuration requires more details: %s ", level, key)
57 return self.
get(key,
None)
65 def GetFileMD(filenames, allowEmpty=True, maxLevel='peeker'):
66 if not filenames
or '_ATHENA_GENERIC_INPUTFILE_NAME_' in filenames:
68 msg.info(
"Running an input-less job. Will have empty metadata.")
70 raise RuntimeError(
"Metadata can not be read in an input-less job.")
71 if isinstance(filenames, str):
72 filenames = [filenames]
73 for filename
in filenames:
74 if filename
not in _fileMetaData:
75 msg.info(
"Obtaining metadata of auto-configuration by peeking into '%s'", filename)
77 if _fileMetaData[filename].maxAccessLevel != maxLevel:
78 _fileMetaData[filename].maxAccessLevel = maxLevel
79 if _fileMetaData[filename][
'nentries']
not in [
None, 0]:
80 return _fileMetaData[filename]
82 msg.info(
"The file: %s has no entries, going to the next one for harvesting the metadata", filename)
83 msg.info(
"No file with events found, returning anyways metadata associated to the first file %s", filenames[0])
84 return _fileMetaData[filenames[0]]
87 """Read geometry database for all detectors"""
89 from AtlasGeoModel
import CommonGeoDB
90 from PixelGeoModel
import PixelGeoDB
91 from LArGeoAlgsNV
import LArGeoDB
92 from MuonGeoModel
import MuonGeoDB
96 from AtlasGeoModel.AtlasGeoDBInterface
import AtlasGeoDBInterface
97 dbGeomCursor = AtlasGeoDBInterface(geoTag)
98 dbGeomCursor.ConnectAndBrowseGeoDB()
100 params = {
'Common' : CommonGeoDB.InitializeGeometryParameters(dbGeomCursor),
104 'Luminosity' : CommonGeoDB.InitializeLuminosityDetectorParameters(dbGeomCursor),
107 msg.debug(
'Config parameters retrieved from Geometry DB (Frontier/Oracle):')
108 for key
in params.keys():
109 msg.debug(f
'{key} -> {params[key]}')
112 from AtlasGeoModel.AtlasGeoDBInterface
import AtlasGeoDBInterface_SQLite
113 sqliteReader = AtlasGeoDBInterface_SQLite(geoTag,sqliteDBFullPath)
114 sqliteReader.ConnectToDB()
116 params = {
'Common' : CommonGeoDB.InitializeGeometryParameters_SQLite(sqliteReader),
120 'Luminosity' : CommonGeoDB.InitializeLuminosityDetectorParameters_SQLite(sqliteReader),
123 msg.debug(
'Config parameters retrieved from Geometry DB (SQLite):')
124 for key
in params.keys():
125 msg.debug(f
'{key} -> {params[key]}')
130 @lru_cache(maxsize=4)
132 """Query geometry DB for detector description. Returns dictionary with
133 detector description. Queries DB for each tag only once.
135 geoTag: geometry tag (e.g. ATLAS-R2-2016-01-00-01)
138 raise ValueError(
"No geometry tag specified")
141 detDescrInfo[
"geomTag"] = geoTag
145 @lru_cache(maxsize=4)
147 """Query geometry DB for detector description.
148 Returns a set of detectors used in a geometry tag.
150 geoTag: geometry tag (e.g. ATLAS-R2-2016-01-00-01)
152 detectors =
DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Detectors']
154 manualConfig =
not DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
"DetectorsConfigured"]
158 detectors.add(
'Bpipe')
159 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
not in [
'RUN1',
'RUN2',
'RUN3']:
160 detectors.add(
'ITkPixel')
161 detectors.add(
'ITkStrip')
162 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Luminosity'][
'BCMPrime']:
163 detectors.add(
'BCMPrime')
164 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Luminosity'][
'PLR']:
167 detectors.add(
'Pixel')
172 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
not in [
'RUN1',
'RUN2',
'RUN3']:
173 detectors.add(
'HGTD')
176 detectors.add(
'Tile')
179 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
in [
'RUN1',
'RUN2',
'RUN3']:
180 detectors.add(
'MBTS')
182 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasMDT']:
184 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasRPC']:
186 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasTGC']:
188 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasCSC']:
190 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasSTGC']:
191 detectors.add(
'sTGC')
192 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasMM']:
196 detectors.add(
'Lucid')
197 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
not in [
'RUN1']:
200 detectors.add(
'ALFA')
201 detectors.add(
'FwdRegion')
209 from .RunToTimestampData
import RunToTimestampDict
210 return RunToTimestampDict
214 """This is used to hold a dictionary of the form
215 {152166:1269948352889940910, ...} to allow the
216 timestamp to be determined from the run.
219 timeStamps = [run2timestampDict.get(runNumber,1)
for runNumber
in runNumbers]
224 """Read in GeneratorsInfo from the input file
226 from AthenaConfiguration.Enums
import ProductionStep
227 inputFiles = flags.Input.Files
228 if flags.Common.ProductionStep
in [ProductionStep.Overlay, ProductionStep.FastChain]
and flags.Input.SecondaryFiles
and not flags.Overlay.ByteStream:
230 inputFiles = flags.Input.SecondaryFiles
231 generatorsString =
""
232 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
234 generatorsString =
GetFileMD(inputFiles).
get(
"generators",
"")
235 from GeneratorConfig.Versioning
import generatorsGetFromMetadata
240 """Read in special simulation job option fragments based on metadata
241 passed by the evgen stage
243 specialConfigDict = dict()
244 legacyPreIncludeToCAPostInclude = {
'SimulationJobOptions/preInclude.AMSB.py' :
'Charginos.CharginosConfig.AMSB_Cfg',
245 'SimulationJobOptions/preInclude.Monopole.py' :
'Monopole.MonopoleConfig.MonopoleCfg',
246 'SimulationJobOptions/preInclude.Quirks.py' :
'Quirks.QuirksConfig.QuirksCfg',
247 'SimulationJobOptions/preInclude.SleptonsLLP.py' :
'Sleptons.SleptonsConfig.SleptonsLLPCfg',
248 'SimulationJobOptions/preInclude.GMSB.py' :
'Sleptons.SleptonsConfig.GMSB_Cfg',
249 'SimulationJobOptions/preInclude.Qball.py' :
'Monopole.MonopoleConfig.QballCfg',
250 'SimulationJobOptions/preInclude.RHadronsPythia8.py' :
'RHadrons.RHadronsConfig.RHadronsCfg',
251 'SimulationJobOptions/preInclude.fcp.py' :
'Monopole.MonopoleConfig.fcpCfg' }
252 legacyPreIncludeToCAPreInclude = {
'SimulationJobOptions/preInclude.AMSB.py' :
None,
253 'SimulationJobOptions/preInclude.Monopole.py' :
'Monopole.MonopoleConfig.MonopolePreInclude',
254 'SimulationJobOptions/preInclude.Quirks.py' :
None,
255 'SimulationJobOptions/preInclude.SleptonsLLP.py' :
None,
256 'SimulationJobOptions/preInclude.GMSB.py' :
None,
257 'SimulationJobOptions/preInclude.Qball.py' :
'Monopole.MonopoleConfig.QballPreInclude',
258 'SimulationJobOptions/preInclude.RHadronsPythia8.py' :
'RHadrons.RHadronsConfig.RHadronsPreInclude',
259 'SimulationJobOptions/preInclude.fcp.py' :
'Monopole.MonopoleConfig.fcpPreInclude' }
260 specialConfigString =
''
261 from AthenaConfiguration.Enums
import ProductionStep
262 inputFiles = flags.Input.Files
263 secondaryInputFiles = flags.Input.SecondaryFiles
264 if flags.Common.ProductionStep
in [ProductionStep.Overlay, ProductionStep.FastChain]
and not flags.Overlay.DataOverlay
and flags.Input.SecondaryFiles:
266 inputFiles = flags.Input.SecondaryFiles
267 secondaryInputFiles = flags.Input.Files
268 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
269 if len(inputFiles)>0:
270 specialConfigString =
GetFileMD(inputFiles).
get(
'specialConfiguration',
'')
271 if (
not len(specialConfigString)
or specialConfigString ==
'NONE')
and len(secondaryInputFiles)>0:
274 specialConfigString =
GetFileMD(secondaryInputFiles).
get(
'specialConfiguration',
'')
275 if len(specialConfigString)>0:
278 spcitems = specialConfigString.split(
";")
279 for spcitem
in spcitems:
282 if not spcitem
or spcitem.upper() ==
"NONE":
285 if "=" not in spcitem:
286 spcitem =
"preInclude=" + spcitem
288 k, v = spcitem.split(
"=")
289 if k ==
"preInclude" and v.endswith(
'.py'):
290 if v ==
'SimulationJobOptions/preInclude.RhadronsPythia8.py':
291 v =
'SimulationJobOptions/preInclude.RHadronsPythia8.py'
292 v1 = legacyPreIncludeToCAPreInclude[v]
294 specialConfigDict[k] = v1
295 v2 = legacyPreIncludeToCAPostInclude[v]
297 specialConfigDict[
'postInclude'] = v2
299 specialConfigDict[k] = v
300 return specialConfigDict