4 import FWCore.ParameterSet.Config
as cms
5 from importlib
import import_module
8 import xml.etree.ElementTree
as ET
14 for i
in xrange(len(aList)-1):
15 yield (aList[i], aList[i+1])
19 searchPaths = os.getenv(
'CMSSW_SEARCH_PATH').
split(
':')
21 for baseDir
in searchPaths:
22 print "Looking for '" + aRelPath +
"' under '" + baseDir +
"'" 23 if os.path.isfile(os.path.join(baseDir, aRelPath)):
25 resolvedPath = os.path.join(baseDir, aRelPath)
27 if resolvedPath
is None:
28 raise RuntimeError(
"Could not find LUT file '" + aRelPath +
"' under directories in 'CMSSW_SEARCH_PATH'")
30 with open(resolvedPath)
as f:
36 if line.startswith(
'#')
or line ==
'\n':
40 stripped_line = line[:line.find(
'#')]
43 items = stripped_line.split()
45 print "ERROR parsing file", resolvedPath,
"on line", line_nr,
"'" + line +
"' : Splitting on whitespace produced", len(items),
"items" 48 entries.append( (
int(items[0]),
int(items[1])) )
51 entries.sort(key=
lambda x : x[0])
54 print "ERROR parsing file", resolvedPath,
": No LUT entries defined in the file" 58 if entries[0][0] != 0:
59 print "ERROR parsing file", resolvedPath,
": LUT entries before index", entries[0][0],
"are not defined" 63 if x1[0] != (x2[0]-1):
64 print "ERROR parsing file", resolvedPath,
": ", x2[0] - x1[0] - 1,
"LUT entries between indices", x1[0],
"and", x2[0],
"are not defined" 67 return [x[1]
for x
in entries]
72 def divideByEgLsb(aParam):
73 return int(aParam.value() / aModule.egLsb.value())
75 def divideByTauLsb(aParam):
76 return int(aParam.value() / aModule.tauLsb.value())
78 def divideByJetLsb(aParam):
79 return int(aParam.value() / aModule.jetLsb.value())
83 ((
'mp_common',
'sdfile'),
None,
''),
84 ((
'mp_common',
'algoRev'),
None,
''),
85 ((
'mp_common',
'leptonSeedThreshold'),
'2_ClusterSeedThreshold.mif', divideByEgLsb(aModule.egSeedThreshold)),
86 ((
'mp_common',
'leptonTowerThreshold'),
'3_ClusterThreshold.mif', divideByEgLsb(aModule.egNeighbourThreshold)),
87 ((
'mp_common',
'pileUpTowerThreshold'),
'4_PileUpThreshold.mif', 0x0)
91 ((
'mp_egamma',
'egammaRelaxationThreshold'),
'10_EgRelaxThr.mif', divideByEgLsb(aModule.egMaxPtHOverE)),
92 ((
'mp_egamma',
'egammaMaxEta'),
'5_EgammaTauEtaMax.mif', aModule.egEtaCut.value()),
93 ((
'mp_egamma',
'egammaBypassCuts'),
'BypassEgVeto.mif',
bool(aModule.egBypassEGVetos.value())),
94 ((
'mp_egamma',
'egammaHOverECut_iEtaLT15'),
'_RatioCutLt15.mif', aModule.egHOverEcutBarrel.value()),
95 ((
'mp_egamma',
'egammaHOverECut_iEtaGTEq15'),
'_RatioCutGe15.mif', aModule.egHOverEcutEndcap.value()),
96 ((
'mp_egamma',
'egammaBypassExtendedHOverE'),
'_BypassExtHE.mif',
bool(aModule.egBypassExtHOverE)),
97 ((
'mp_egamma',
'egammaEnergyCalibLUT'),
'C_EgammaCalibration_12to18.mif',
parseOfflineLUTfile(aModule.egCalibrationLUTFile.value())),
98 ((
'mp_egamma',
'egammaIsoLUT1'),
'D_EgammaIsolation1_13to9.mif',
parseOfflineLUTfile(aModule.egIsoLUTFile.value())),
99 ((
'mp_egamma',
'egammaIsoLUT2'),
'D_EgammaIsolation2_13to9.mif',
parseOfflineLUTfile(aModule.egIsoLUTFile2.value()))
103 ((
'mp_tau',
'tauMaxEta'),
'5_EgammaTauEtaMax.mif', aModule.isoTauEtaMax.value()),
104 ((
'mp_tau',
'tauEnergyCalibLUT'),
'I_TauCalibration_11to18.mif',
parseOfflineLUTfile(aModule.tauCalibrationLUTFile.value())),
105 ((
'mp_tau',
'tauIsoLUT'),
'H_TauIsolation_12to9.mif',
parseOfflineLUTfile(aModule.tauIsoLUTFile.value()))
109 ((
'mp_jet',
'jetSeedThreshold'),
'1_JetSeedThreshold.mif', divideByJetLsb(aModule.jetSeedThreshold)),
110 ((
'mp_jet',
'jetMaxEta'),
'6_JetEtaMax.mif', 0x00028),
111 ((
'mp_jet',
'HTMHT_maxJetEta'),
'7_RingEtaMax.mif', aModule.etSumEtaMax[1]),
112 ((
'mp_jet',
'HT_jetThreshold'),
'8_HtThreshold.mif',
int(aModule.etSumEtThreshold[1] / aModule.etSumLsb.value())),
113 ((
'mp_jet',
'MHT_jetThreshold'),
'9_MHtThreshold.mif',
int(aModule.etSumEtThreshold[3] / aModule.etSumLsb.value())),
114 ((
'mp_jet',
'jetBypassPileUpSub'),
'BypassJetPUS.mif',
bool(aModule.jetBypassPUS.value())),
115 ((
'mp_jet',
'jetEnergyCalibLUT'),
'L_JetCalibration_11to18.mif', aModule.jetCalibrationLUTFile)
119 ((
'mp_sums',
'towerCountThreshold'),
'HeavyIonThr.mif',
int(aModule.etSumEtThreshold[4] / aModule.etSumLsb.value()) ),
120 ((
'mp_sums',
'towerCountMaxEta'),
'HeavyIonEta.mif', aModule.etSumEtaMax[4]),
121 ((
'mp_sums',
'ETMET_maxTowerEta'),
'7_RingEtaMax.mif', aModule.etSumEtaMax[0]),
122 ((
'mp_sums',
'ecalET_towerThresholdLUT'),
'X_EcalTHR_11to9.mif', aModule.etSumEcalSumPUSLUTFile),
123 ((
'mp_sums',
'ET_towerThresholdLUT'),
'X_ETTHR_11to9.mif', aModule.etSumMetPUSLUTFile),
124 ((
'mp_sums',
'MET_towerThresholdLUT'),
'X_METTHR_11to9.mif', aModule.etSumMetPUSLUTFile)
128 ((
'demux',
'sdfile'),
None,
''),
129 ((
'demux',
'algoRev'),
None, 0xcafe)
132 result = [(a, b,
parseOfflineLUTfile(c.value())
if isinstance(c, cms.FileInPath)
else c)
for a, b, c
in result]
140 if xmlDetails
is not None:
141 if xmlDetails[0]
in result:
142 result[xmlDetails[0]] += [(xmlDetails[1], value)]
144 result[xmlDetails[0]] = [(xmlDetails[1], value)]
153 return {mifFileName : value
for (_, mifFileName, value)
in fullList
if mifFileName
is not None}
160 if not elem.text
or not elem.text.strip():
162 if not elem.tail
or not elem.tail.strip():
166 if not elem.tail
or not elem.tail.strip():
169 if level
and (
not elem.tail
or not elem.tail.strip()):
173 print "Writing MIF file:", aFilePath
174 with open(aFilePath,
'w')
as f:
175 if isinstance(aValue, bool):
176 aValue = (1
if aValue
else 0)
178 if isinstance(aValue, int):
179 f.write( hex(aValue) )
180 elif isinstance(aValue, list):
181 f.write(
"\n".
join([hex(x)
for x
in aValue]))
183 raise RuntimeError(
"Do not know how to deal with parameter of type " +
str(type(aValue)))
187 topNode = ET.Element(
'algo', id=
'calol2')
188 contextNode = ET.SubElement(topNode,
'context', id=contextId)
189 for paramId, value
in parameters:
190 if isinstance(value, bool):
191 ET.SubElement(contextNode,
'param', id=paramId, type=
'bool').text =
str(value).lower()
192 elif isinstance(value, int):
193 ET.SubElement(contextNode,
'param', id=paramId, type=
'uint').text =
"0x{0:05X}".
format(value)
194 elif isinstance(value, str):
195 ET.SubElement(contextNode,
'param', id=paramId, type=
'string').text = value
196 elif isinstance(value, list):
197 ET.SubElement(contextNode,
'param', id=paramId, type=
'vector:uint').text =
"\n " +
",\n ".
join([
"0x{0:05X}".
format(x)
for x
in value]) +
"\n " 199 raise RuntimeError(
"Do not know how to deal with parameter '" + paramId +
"' of type " +
str(type(value)))
202 print "Writing XML file:", outputFilePath
203 with open(outputFilePath,
'w')
as f:
204 f.write(ET.tostring(topNode))
208 if __name__ ==
'__main__':
210 parser = argparse.ArgumentParser()
212 parser.add_argument(
'params_cfi', help=
'Name of CMSSW cfi python file specifying the values for the calo parameters')
213 parser.add_argument(
'output_dir', help=
'Directory for MIF/XML output files')
215 outputFormatGroup = parser.add_mutually_exclusive_group(required=
True)
216 outputFormatGroup.add_argument(
'--mif', action=
'store_true')
217 outputFormatGroup.add_argument(
'--xml', action=
'store_true')
219 args = parser.parse_args()
221 moduleName =
'L1Trigger.L1TCalorimeter.' + args.params_cfi
222 print "Importing calo params from module:", moduleName
223 caloParams = import_module(moduleName).caloStage2Params
225 print caloParams.egCalibrationLUTFile.value()
226 print caloParams.egIsoLUTFile.value()
227 print caloParams.egIsoLUTFile2.value()
228 os.mkdir(args.output_dir)
232 createMIF(args.output_dir +
'/' + fileName, value)
235 createXML(paramList,
'MainProcessor' if fileTag.startswith(
'mp')
else 'Demux', args.output_dir +
'/algo_' + fileTag +
'.xml')
static std::string join(char **cmd)