5 from AthenaCommon.Logging
import logging
6 from PyUtils.MetaReader
import read_metadata
8 logger = logging.getLogger(
"OverlayMetadataConfig")
11 _fileMetadata = dict()
14 if type(filenames)
is list:
15 filename = filenames[0]
19 if filename
not in _fileMetadata:
20 logger.info(
"Obtaining full metadata of %s", filename)
23 _fileMetadata.update(thisFileMD)
25 return _fileMetadata[filename]
29 """Validate geometry tag so it is the same as target"""
30 target_layout = target.split(
'-')
31 value_layout = value.split(
'-')
32 if len(target_layout) != len(value_layout):
35 for p, s
in zip(target_layout[:-1], value_layout[:-1]):
36 if not re.match(p, s):
39 if not re.match(target_layout[-1], value_layout[-1]):
40 logger.warning(
"Simulation geometry tag mismatch! %s vs %s", target, value)
46 """Check the metadata for signal HITS or presampled pileup RDO file"""
47 logger.info(
"Checking Overlay configuration against Signal or presampled pileup RDO metadata...")
49 simKeys = simDict.keys()
50 tagInfoKeys = tagInfoDict.keys()
53 if "PhysicsList" in simKeys:
54 if re.match(simDict[
"PhysicsList"], flags.Sim.PhysicsList):
55 logger.debug(
"Overlay configuration matches Signal Simulation metadata. [Sim.PhysicsList = %s]", flags.Sim.PhysicsList)
57 flags.Sim.PhysicsList = simDict[
"PhysicsList"]
58 logger.warning(
"Overlay Sim.PhysicsList does not match the PhysicsList used in the Signal Simulation step! Assume the value from the Signal Simulation step is correct!")
59 logger.warning(
"Set Sim.PhysicsList = %s", flags.Sim.PhysicsList)
61 logger.error(
"'PhysicsList' key not found in Signal Simulation metadata!")
62 raise AssertionError(
"Signal Simulation metadata key not found")
65 if "SimLayout" in simKeys:
67 logger.debug(
"Overlay configuration matches Signal Simulation metadata. [Geomodel.AtlasVersion = %s]",
68 flags.GeoModel.AtlasVersion)
70 flags.GeoModel.AtlasVersion = simDict[
"SimLayout"]
71 logger.warning(
"Overlay Geomodel.AtlasVersion does not match the value used in the Signal Simulation step! Assume the value from the Signal Simulation step is correct!")
72 logger.warning(
"Set Geomodel.AtlasVersion = %s", flags.GeoModel.AtlasVersion)
74 logger.error(
"'SimLayout' key not found in Signal Simulation metadata!")
75 raise AssertionError(
"Signal Simulation metadata key not found")
78 if "IOVDbGlobalTag" in tagInfoKeys:
79 if not re.match(tagInfoDict[
"IOVDbGlobalTag"], flags.IOVDb.GlobalTag):
80 logger.debug(
"Overlay configuration: [IOVDb.GlobalTag = %s], Signal Simulation metadata: [IOVDb.GlobalTag = %s]",
81 flags.IOVDb.GlobalTag, tagInfoDict[
'IOVDbGlobalTag'])
83 logger.error(
"'IOVDbGlobalTag' key not found in Signal Simulation metadata!")
84 raise AssertionError(
"Signal Simulation metadata key not found")
87 if "TRTRangeCut" in simKeys:
88 if not re.match(simDict[
"TRTRangeCut"],
str(flags.Sim.TRTRangeCut)):
89 flags.Sim.TRTRangeCut = simDict[
"TRTRangeCut"]
90 logger.warning(
"Overlay Sim.TRTRangeCut does not match the value used in the Signal Simulation step! Assume the value from the Signal Simulation step is correct!")
91 logger.warning(
"Set Sim.TRTRangeCut = %s", flags.Sim.TRTRangeCut)
93 logger.warning(
"'TRTRangeCut' key not found in Signal Simulation metadata!")
98 logger.info(
"Completed checks of Overlay configuration against Signal Simulation metadata.")
102 """Check the simulation metadata for presampled pileup RDO file"""
103 sigkeys = sigdict.keys()
104 pukeys = pudict.keys()
107 warningKeys = [
'G4Version']
108 sigKeysToCheck = [
'PhysicsList',
'SimLayout',
'MagneticField',
'hitFileMagicNumber'] + warningKeys
109 for o
in sigKeysToCheck:
112 except AssertionError:
113 logger.error(
"%s key missing from Presampled pile-up Simulation metadata!", o)
114 raise AssertionError(
"Presampled pile-up Simulation metadata key not found")
117 except AssertionError:
118 logger.error(
"%s key missing from Signal Simulation metadata!", o)
119 raise AssertionError(
"Signal Simulation metadata key not found")
123 elif not isinstance(pudict[o],
type(sigdict[o])):
124 assert re.match(
str(pudict[o]),
str(sigdict[o]))
126 if isinstance(pudict[o], str):
127 assert re.match(pudict[o], sigdict[o])
128 elif isinstance(pudict[o], int):
129 assert (pudict[o] == sigdict[o])
131 assert re.match(
str(pudict[o]),
str(sigdict[o]))
132 except AssertionError:
134 logger.warning(
"Simulation metadata mismatch! Presampled pile-up: [%s = %s] Signal: [%s = %s]", o, pudict[o], o, sigdict[o])
136 logger.error(
"Simulation metadata mismatch! Presampled pile-up: [%s = %s] Signal: [%s = %s]", o, pudict[o], o, sigdict[o])
137 raise AssertionError(
"Simulation metadata mismatch")
141 """Check the tag info metadata for presampled pileup RDO File"""
142 sigkeys = sigdict.keys()
143 pukeys = pudict.keys()
145 logger.debug(
"Signal /TagInfo ", sigdict)
146 logger.debug(
"Pileup /TagInfo ", pudict)
149 sigOnlyKeySet =
set(sigkeys).difference(
set(pukeys))
150 logger.debug(
"The following keys only appear in Signal /TagInfo metadata:")
151 logger.debug(sigOnlyKeySet)
152 for key
in sigOnlyKeySet:
153 sigOnlyDict[key] = sigdict[key]
154 logger.debug(
" key: ", key,
"value: ", sigdict[key])
158 logger.debug(
"The following keys appear in Signal and Presampled pile-up /TagInfo metadata:")
159 logger.debug(keysToCompareSet)
162 warningKeys = [
'IOVDbGlobalTag']
163 sigKeysToCheck = warningKeys
164 for o
in sigKeysToCheck:
167 except AssertionError:
168 logger.error(
"%s key missing from Presampled pile-up Simulation metadata!", o)
169 raise AssertionError(
"Presampled pile-up Simulation metadata key not found")
172 except AssertionError:
173 logger.error(
"%s key missing from Signal Simulation metadata!", o)
174 raise AssertionError(
"Signal Simulation metadata key not found")
176 if not isinstance(pudict[o],
type(sigdict[o])):
177 assert re.match(
str(pudict[o]),
str(sigdict[o]))
179 if isinstance(pudict[o], str):
180 assert re.match(pudict[o], sigdict[o])
181 elif isinstance(pudict[o], int):
182 assert (pudict[o] == sigdict[o])
184 assert re.match(
str(pudict[o]),
str(sigdict[o]))
185 except AssertionError:
187 logger.warning(
"Simulation metadata mismatch! Presampled pile-up: [%s = %s] Signal: [%s = %s]", o, pudict[o], o, sigdict[o])
189 logger.error(
"Simulation metadata mismatch! Presampled pile-up: [%s = %s] Signal: [%s = %s]", o, pudict[o], o, sigdict[o])
190 raise AssertionError(
"Simulation metadata mismatch")
194 """Check overlay metadata"""
195 if flags.Overlay.DataOverlay:
196 files = flags.Input.Files
197 filesPileup = flags.Input.SecondaryFiles
199 files = flags.Input.SecondaryFiles
200 filesPileup = flags.Input.Files
204 signalSimulationMetadata = signalMetadata[
"/Simulation/Parameters"]
205 signalTagInfoMetadata = signalMetadata[
"/TagInfo"]
211 logger.info(
"Simulation metadata check not done due to no inputs")
214 if not flags.Overlay.DataOverlay
and filesPileup:
216 pileupDigitizationMetadata = pileupMetaDataCheck[
"/Digitization/Parameters"]
217 pileupSimulationMetadata = pileupMetaDataCheck[
"/Simulation/Parameters"]
218 pileupTagInfoMetadata = pileupMetaDataCheck[
"/TagInfo"]
220 logger.info(
"Checking Presampled pile-up metadata against Signal Simulation metadata...")
223 logger.info(
"Completed all checks against Presampled pile-up Simulation metadata.")
225 if pileupDigitizationMetadata:
230 """Check fastchain overlay metadata"""
231 if flags.Overlay.DataOverlay:
232 filesPileup = flags.Input.SecondaryFiles
234 filesPileup = flags.Input.Files
237 if not flags.Overlay.DataOverlay
and filesPileup:
239 pileupDigitizationMetadata = pileupMetaDataCheck[
"/Digitization/Parameters"]
240 pileupSimulationMetadata = pileupMetaDataCheck[
"/Simulation/Parameters"]
241 pileupTagInfoMetadata = pileupMetaDataCheck[
"/TagInfo"]
243 logger.info(
"Checking Presampled pile-up metadata against configuration of jobs (i.e. flags)...")
245 logger.info(
"Completed all checks against Presampled pile-up Simulation metadata.")
247 if pileupDigitizationMetadata:
252 from IOVDbMetaDataTools
import ParameterDbFiller
254 runNumber = flags.Input.RunNumbers[0]
255 runNumberEnd = flags.Input.RunNumbers[-1]
256 if runNumberEnd == runNumber:
258 logger.debug(
'ParameterDbFiller BeginRun = %s',
str(runNumber) )
259 dbFiller.setBeginRun(runNumber)
260 logger.debug(
'ParameterDbFiller EndRun = %s',
str(runNumberEnd) )
261 dbFiller.setEndRun(runNumberEnd)
263 logger.info(
'Filling Digitization MetaData')
266 for key
in pileupDict:
267 value =
str(pileupDict[key])
268 logger.info(
'DigitizationMetaData: setting "%s" to be %s', key, value)
269 if key
in [
"BeamIntensityPattern"]:
270 dbFiller.addDigitParam64(key, value)
272 dbFiller.addDigitParam(key, value)
275 dbFiller.genDigitDb()