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)
138 detectors =
DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Detectors']
140 manualConfig =
not DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
"DetectorsConfigured"]
144 detectors.add(
'Bpipe')
145 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
not in [
'RUN1',
'RUN2',
'RUN3']:
146 detectors.add(
'ITkPixel')
147 detectors.add(
'ITkStrip')
148 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Luminosity'][
'BCMPrime']:
149 detectors.add(
'BCMPrime')
150 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Luminosity'][
'PLR']:
153 detectors.add(
'Pixel')
158 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
not in [
'RUN1',
'RUN2',
'RUN3']:
159 detectors.add(
'HGTD')
162 detectors.add(
'Tile')
165 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
in [
'RUN1',
'RUN2',
'RUN3']:
166 detectors.add(
'MBTS')
168 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasMDT']:
170 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasRPC']:
172 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasTGC']:
174 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasCSC']:
176 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasSTGC']:
177 detectors.add(
'sTGC')
178 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Muon'][
'HasMM']:
182 detectors.add(
'Lucid')
183 if DetDescrInfo(geoTag,sqliteDB,sqliteDBFullPath)[
'Common'][
'Run']
not in [
'RUN1']:
186 detectors.add(
'ALFA')
187 detectors.add(
'FwdRegion')
195 from .RunToTimestampData
import RunToTimestampDict
196 return RunToTimestampDict
200 """This is used to hold a dictionary of the form
201 {152166:1269948352889940910, ...} to allow the
202 timestamp to be determined from the run.
205 timeStamps = [run2timestampDict.get(runNumber,1)
for runNumber
in runNumbers]
210 """Read in GeneratorsInfo from the input file
212 from AthenaConfiguration.Enums
import ProductionStep
213 inputFiles = flags.Input.Files
214 if flags.Common.ProductionStep
in [ProductionStep.Overlay, ProductionStep.FastChain]
and not flags.Overlay.DataOverlay
and flags.Input.SecondaryFiles:
216 inputFiles = flags.Input.SecondaryFiles
217 generatorsString =
""
218 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
220 generatorsString =
GetFileMD(inputFiles).
get(
"generators",
"")
221 from GeneratorConfig.Versioning
import generatorsGetFromMetadata
226 """Read in special simulation job option fragments based on metadata
227 passed by the evgen stage
229 specialConfigDict = dict()
230 legacyPreIncludeToCAPostInclude = {
'SimulationJobOptions/preInclude.AMSB.py' :
'Charginos.CharginosConfig.AMSB_Cfg',
231 'SimulationJobOptions/preInclude.Monopole.py' :
'Monopole.MonopoleConfig.MonopoleCfg',
232 'SimulationJobOptions/preInclude.Quirks.py' :
'Quirks.QuirksConfig.QuirksCfg',
233 'SimulationJobOptions/preInclude.SleptonsLLP.py' :
'Sleptons.SleptonsConfig.SleptonsLLPCfg',
234 'SimulationJobOptions/preInclude.GMSB.py' :
'Sleptons.SleptonsConfig.GMSB_Cfg',
235 'SimulationJobOptions/preInclude.Qball.py' :
'Monopole.MonopoleConfig.QballCfg',
236 'SimulationJobOptions/preInclude.RHadronsPythia8.py' :
'RHadrons.RHadronsConfig.RHadronsCfg',
237 'SimulationJobOptions/preInclude.fcp.py' :
'Monopole.MonopoleConfig.fcpCfg' }
238 legacyPreIncludeToCAPreInclude = {
'SimulationJobOptions/preInclude.AMSB.py' :
None,
239 'SimulationJobOptions/preInclude.Monopole.py' :
'Monopole.MonopoleConfig.MonopolePreInclude',
240 'SimulationJobOptions/preInclude.Quirks.py' :
None,
241 'SimulationJobOptions/preInclude.SleptonsLLP.py' :
None,
242 'SimulationJobOptions/preInclude.GMSB.py' :
None,
243 'SimulationJobOptions/preInclude.Qball.py' :
'Monopole.MonopoleConfig.QballPreInclude',
244 'SimulationJobOptions/preInclude.RHadronsPythia8.py' :
'RHadrons.RHadronsConfig.RHadronsPreInclude',
245 'SimulationJobOptions/preInclude.fcp.py' :
'Monopole.MonopoleConfig.fcpPreInclude' }
246 specialConfigString =
''
247 from AthenaConfiguration.Enums
import ProductionStep
248 inputFiles = flags.Input.Files
249 secondaryInputFiles = flags.Input.SecondaryFiles
250 if flags.Common.ProductionStep
in [ProductionStep.Overlay, ProductionStep.FastChain]
and not flags.Overlay.DataOverlay
and flags.Input.SecondaryFiles:
252 inputFiles = flags.Input.SecondaryFiles
253 secondaryInputFiles = flags.Input.Files
254 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
255 if len(inputFiles)>0:
256 specialConfigString =
GetFileMD(inputFiles).
get(
'specialConfiguration',
'')
257 if (
not len(specialConfigString)
or specialConfigString ==
'NONE')
and len(secondaryInputFiles)>0:
260 specialConfigString =
GetFileMD(secondaryInputFiles).
get(
'specialConfiguration',
'')
261 if len(specialConfigString)>0:
264 spcitems = specialConfigString.split(
";")
265 for spcitem
in spcitems:
268 if not spcitem
or spcitem.upper() ==
"NONE":
271 if "=" not in spcitem:
272 spcitem =
"preInclude=" + spcitem
274 k, v = spcitem.split(
"=")
275 if k ==
"preInclude" and v.endswith(
'.py'):
276 if v ==
'SimulationJobOptions/preInclude.RhadronsPythia8.py':
277 v =
'SimulationJobOptions/preInclude.RHadronsPythia8.py'
278 v1 = legacyPreIncludeToCAPreInclude[v]
280 specialConfigDict[k] = v1
281 v2 = legacyPreIncludeToCAPostInclude[v]
283 specialConfigDict[
'postInclude'] = v2
285 specialConfigDict[k] = v
286 return specialConfigDict