4 import FWCore.ParameterSet.Config
as cms
5 from importlib
import import_module
8 import xml.etree.ElementTree
as ET
13 for i
in xrange(len(aList)-1):
14 yield (aList[i], aList[i+1])
18 searchPaths = os.getenv(
'CMSSW_SEARCH_PATH').
split(
':')
20 for baseDir
in searchPaths:
21 print "Looking for '" + aRelPath +
"' under '" + baseDir +
"'" 22 if os.path.isfile(os.path.join(baseDir, aRelPath)):
24 resolvedPath = os.path.join(baseDir, aRelPath)
26 if resolvedPath
is None:
27 raise RuntimeError(
"Could not find LUT file '" + aRelPath +
"' under directories in 'CMSSW_SEARCH_PATH'")
29 with open(resolvedPath)
as f:
35 if line.startswith(
'#')
or line ==
'\n':
39 stripped_line = line[:line.find(
'#')]
42 items = stripped_line.split()
44 print "ERROR parsing file", resolvedPath,
"on line", line_nr,
"'" + line +
"' : Splitting on whitespace produced", len(items),
"items" 47 entries.append( (
int(items[0]),
int(items[1])) )
50 entries.sort(key=
lambda x : x[0])
53 print "ERROR parsing file", resolvedPath,
": No LUT entries defined in the file" 57 if entries[0][0] != 0:
58 print "ERROR parsing file", resolvedPath,
": LUT entries before index", entries[0][0],
"are not defined" 62 if x1[0] != (x2[0]-1):
63 print "ERROR parsing file", resolvedPath,
": ", x2[0] - x1[0] - 1,
"LUT entries between indices", x1[0],
"and", x2[0],
"are not defined" 66 return [x[1]
for x
in entries]
71 def divideByEgLsb(aParam):
72 return int(aParam.value() / aModule.egLsb.value())
74 def divideByTauLsb(aParam):
75 return int(aParam.value() / aModule.tauLsb.value())
77 def divideByJetLsb(aParam):
78 return int(aParam.value() / aModule.jetLsb.value())
82 ((
'mp_common',
'sdfile'),
None,
''),
83 ((
'mp_common',
'algoRev'),
None,
''),
84 ((
'mp_common',
'leptonSeedThreshold'),
'2_ClusterSeedThreshold.mif', divideByEgLsb(aModule.egSeedThreshold)),
85 ((
'mp_common',
'leptonTowerThreshold'),
'3_ClusterThreshold.mif', divideByEgLsb(aModule.egNeighbourThreshold)),
86 ((
'mp_common',
'pileUpTowerThreshold'),
'4_PileUpThreshold.mif', 0x0)
90 ((
'mp_egamma',
'egammaRelaxationThreshold'),
'10_EgRelaxThr.mif', divideByEgLsb(aModule.egMaxPtHOverE)),
91 ((
'mp_egamma',
'egammaMaxEta'),
'5_EgammaTauEtaMax.mif', aModule.egEtaCut.value()),
92 ((
'mp_egamma',
'egammaBypassCuts'),
'BypassEgVeto.mif',
bool(aModule.egBypassEGVetos.value())),
93 ((
'mp_egamma',
'egammaHOverECut_iEtaLT15'),
'_RatioCutLt15.mif', aModule.egHOverEcutBarrel.value()),
94 ((
'mp_egamma',
'egammaHOverECut_iEtaGTEq15'),
'_RatioCutGe15.mif', aModule.egHOverEcutEndcap.value()),
95 ((
'mp_egamma',
'egammaBypassExtendedHOverE'),
'_BypassExtHE.mif',
bool(aModule.egBypassExtHOverE)),
96 ((
'mp_egamma',
'egammaEnergyCalibLUT'),
'C_EgammaCalibration_12to18.mif',
parseOfflineLUTfile(aModule.egCalibrationLUTFile.value())),
97 ((
'mp_egamma',
'egammaIsoLUT1'),
'D_EgammaIsolation1_13to9.mif',
parseOfflineLUTfile(aModule.egIsoLUTFile.value())),
98 ((
'mp_egamma',
'egammaIsoLUT2'),
'D_EgammaIsolation2_13to9.mif',
parseOfflineLUTfile(aModule.egIsoLUTFile2.value()))
102 ((
'mp_tau',
'tauMaxEta'),
'5_EgammaTauEtaMax.mif', aModule.isoTauEtaMax.value()),
103 ((
'mp_tau',
'tauEnergyCalibLUT'),
'I_TauCalibration_11to18.mif',
parseOfflineLUTfile(aModule.tauCalibrationLUTFile.value())),
104 ((
'mp_tau',
'tauIsoLUT'),
'H_TauIsolation_12to9.mif',
parseOfflineLUTfile(aModule.tauIsoLUTFile.value()))
108 ((
'mp_jet',
'jetSeedThreshold'),
'1_JetSeedThreshold.mif', divideByJetLsb(aModule.jetSeedThreshold)),
109 ((
'mp_jet',
'jetMaxEta'),
'6_JetEtaMax.mif', 0x00028),
110 ((
'mp_jet',
'HTMHT_maxJetEta'),
'7_RingEtaMax.mif', aModule.etSumEtaMax[1]),
111 ((
'mp_jet',
'HT_jetThreshold'),
'8_HtThreshold.mif',
int(aModule.etSumEtThreshold[1] / aModule.etSumLsb.value())),
112 ((
'mp_jet',
'MHT_jetThreshold'),
'9_MHtThreshold.mif',
int(aModule.etSumEtThreshold[3] / aModule.etSumLsb.value())),
113 ((
'mp_jet',
'jetBypassPileUpSub'),
'BypassJetPUS.mif',
bool(aModule.jetBypassPUS.value())),
114 ((
'mp_jet',
'jetEnergyCalibLUT'),
'L_JetCalibration_11to18.mif', aModule.jetCalibrationLUTFile)
118 ((
'mp_sums',
'towerCountThreshold'),
'HeavyIonThr.mif',
int(aModule.etSumEtThreshold[4] / aModule.etSumLsb.value()) ),
119 ((
'mp_sums',
'towerCountMaxEta'),
'HeavyIonEta.mif', aModule.etSumEtaMax[4]),
120 ((
'mp_sums',
'ETMET_maxTowerEta'),
'7_RingEtaMax.mif', aModule.etSumEtaMax[0]),
121 ((
'mp_sums',
'ecalET_towerThresholdLUT'),
'X_EcalTHR_11to9.mif', aModule.etSumEcalSumPUSLUTFile),
122 ((
'mp_sums',
'ET_towerThresholdLUT'),
'X_ETTHR_11to9.mif', aModule.etSumMetPUSLUTFile),
123 ((
'mp_sums',
'MET_towerThresholdLUT'),
'X_METTHR_11to9.mif', aModule.etSumMetPUSLUTFile)
127 ((
'demux',
'sdfile'),
None,
''),
128 ((
'demux',
'algoRev'),
None, 0xcafe)
131 result = [(a, b,
parseOfflineLUTfile(c.value())
if type(c)
is cms.FileInPath
else c)
for a, b, c
in result]
139 if xmlDetails
is not None:
140 if xmlDetails[0]
in result:
141 result[xmlDetails[0]] += [(xmlDetails[1], value)]
143 result[xmlDetails[0]] = [(xmlDetails[1], value)]
152 return {mifFileName : value
for (_, mifFileName, value)
in fullList
if mifFileName
is not None}
159 if not elem.text
or not elem.text.strip():
161 if not elem.tail
or not elem.tail.strip():
165 if not elem.tail
or not elem.tail.strip():
168 if level
and (
not elem.tail
or not elem.tail.strip()):
172 print "Writing MIF file:", aFilePath
173 with open(aFilePath,
'w')
as f:
174 if type(aValue)
is bool:
175 aValue = (1
if aValue
else 0)
177 if type(aValue)
is int:
178 f.write( hex(aValue) )
179 elif type(aValue)
is list:
180 f.write(
"\n".
join([hex(x)
for x
in aValue]))
182 raise RuntimeError(
"Do not know how to deal with parameter of type " +
str(type(aValue)))
186 topNode = ET.Element(
'algo', id=
'calol2')
187 contextNode = ET.SubElement(topNode,
'context', id=contextId)
188 for paramId, value
in parameters:
189 if type(value)
is bool:
190 ET.SubElement(contextNode,
'param', id=paramId, type=
'bool').text =
str(value).lower()
191 elif type(value)
is int:
192 ET.SubElement(contextNode,
'param', id=paramId, type=
'uint').text =
"0x{0:05X}".
format(value)
193 elif type(value)
is str:
194 ET.SubElement(contextNode,
'param', id=paramId, type=
'string').text = value
195 elif type(value)
is list:
196 ET.SubElement(contextNode,
'param', id=paramId, type=
'vector:uint').text =
"\n " +
",\n ".
join([
"0x{0:05X}".
format(x)
for x
in value]) +
"\n " 198 raise RuntimeError(
"Do not know how to deal with parameter '" + paramId +
"' of type " +
str(type(value)))
201 print "Writing XML file:", outputFilePath
202 with open(outputFilePath,
'w')
as f:
203 f.write(ET.tostring(topNode))
207 if __name__ ==
'__main__':
211 parser.add_argument(
'params_cfi', help=
'Name of CMSSW cfi python file specifying the values for the calo parameters')
212 parser.add_argument(
'output_dir', help=
'Directory for MIF/XML output files')
214 outputFormatGroup = parser.add_mutually_exclusive_group(required=
True)
215 outputFormatGroup.add_argument(
'--mif', action=
'store_true')
216 outputFormatGroup.add_argument(
'--xml', action=
'store_true')
218 args = parser.parse_args()
220 moduleName =
'L1Trigger.L1TCalorimeter.' + args.params_cfi
221 print "Importing calo params from module:", moduleName
222 caloParams = import_module(moduleName).caloStage2Params
224 print caloParams.egCalibrationLUTFile.value()
225 print caloParams.egIsoLUTFile.value()
226 print caloParams.egIsoLUTFile2.value()
227 os.mkdir(args.output_dir)
231 createMIF(args.output_dir +
'/' + fileName, value)
234 createXML(paramList,
'MainProcessor' if fileTag.startswith(
'mp')
else 'Demux', args.output_dir +
'/algo_' + fileTag +
'.xml')
static std::string join(char **cmd)