CMS 3D CMS Logo

Functions | Variables
convertParamsToOnlineFormat Namespace Reference

Functions

def createMIF (aFilePath, aValue)
 
def createXML (parameters, contextId, outputFilePath)
 
def getFullListOfParameters (aModule)
 
def getMifParameterMap (aModule)
 
def getXmlParameterMap (aModule)
 
def indent (elem, level=0)
 
def pairwiseGen (aList)
 
def parseOfflineLUTfile (aRelPath, aExpectedSize, aPaddingValue=None, aTruncate=False)
 

Variables

 action
 
 args
 
 caloParams
 
 help
 
 moduleName
 
 outputFormatGroup
 
 parser
 
 required
 

Function Documentation

◆ createMIF()

def convertParamsToOnlineFormat.createMIF (   aFilePath,
  aValue 
)

Definition at line 198 of file convertParamsToOnlineFormat.py.

References join(), print(), and str.

198 def createMIF(aFilePath, aValue):
199  print("Writing MIF file:", aFilePath)
200  with open(aFilePath, 'w') as f:
201  if isinstance(aValue, bool):
202  aValue = (1 if aValue else 0)
203 
204  if isinstance(aValue, int):
205  f.write( hex(aValue) )
206  elif isinstance(aValue, list):
207  f.write("\n".join([hex(x) for x in aValue]))
208  else:
209  raise RuntimeError("Do not know how to deal with parameter of type " + str(type(aValue)))
210 
211 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21
#define str(s)

◆ createXML()

def convertParamsToOnlineFormat.createXML (   parameters,
  contextId,
  outputFilePath 
)

Definition at line 212 of file convertParamsToOnlineFormat.py.

References indent(), join(), print(), and str.

212 def createXML(parameters, contextId, outputFilePath):
213  topNode = ET.Element('algo', id='calol2')
214  contextNode = ET.SubElement(topNode, 'context', id=contextId)
215  for paramId, value in parameters:
216  if isinstance(value, bool):
217  ET.SubElement(contextNode, 'param', id=paramId, type='bool').text = str(value).lower()
218  elif isinstance(value, int):
219  ET.SubElement(contextNode, 'param', id=paramId, type='uint').text = "0x{0:05X}".format(value)
220  elif isinstance(value, str):
221  ET.SubElement(contextNode, 'param', id=paramId, type='string').text = value
222  elif isinstance(value, list):
223  ET.SubElement(contextNode, 'param', id=paramId, type='vector:uint').text = "\n " + ",\n ".join(["0x{0:05X}".format(x) for x in value]) + "\n "
224  else:
225  raise RuntimeError("Do not know how to deal with parameter '" + paramId + "' of type " + str(type(value)))
226  indent(topNode)
227 
228  print("Writing XML file:", outputFilePath)
229  with open(outputFilePath, 'w') as f:
230  f.write(ET.tostring(topNode, encoding="unicode"))
231 
232 
233 
def createXML(parameters, contextId, outputFilePath)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21
#define str(s)

◆ getFullListOfParameters()

def convertParamsToOnlineFormat.getFullListOfParameters (   aModule)

Definition at line 82 of file convertParamsToOnlineFormat.py.

References nano_mu_local_reco_cff.bool, createfilelist.int, and parseOfflineLUTfile().

Referenced by getMifParameterMap(), and getXmlParameterMap().

82 def getFullListOfParameters(aModule):
83 
84  def divideByEgLsb(aParam):
85  return int(aParam.value() / aModule.egLsb.value())
86 
87  def divideByTauLsb(aParam):
88  return int(aParam.value() / aModule.tauLsb.value())
89 
90  def divideByJetLsb(aParam):
91  return int(aParam.value() / aModule.jetLsb.value())
92 
93 
94  result = [
95  (('mp_common', 'sdfile'), None, ''),
96  (('mp_common', 'algoRev'), None, ''),
97  (('mp_common', 'leptonSeedThreshold'), '2_ClusterSeedThreshold.mif', divideByEgLsb(aModule.egSeedThreshold)),
98  (('mp_common', 'leptonTowerThreshold'), '3_ClusterThreshold.mif', divideByEgLsb(aModule.egNeighbourThreshold)),
99  (('mp_common', 'pileUpTowerThreshold'), '4_PileUpThreshold.mif', 0x0)
100  ]
101 
102  result += [
103  (('mp_egamma', 'egammaRelaxationThreshold'), '10_EgRelaxThr.mif', divideByEgLsb(aModule.egMaxPtHOverE)),
104  (('mp_egamma', 'egammaMaxEta'), 'egammaMaxEta.mif', aModule.egEtaCut.value()),
105  (('mp_egamma', 'egammaBypassCuts'), 'BypassEgVeto.mif', bool(aModule.egBypassEGVetos.value())),
106  (('mp_egamma', 'egammaBypassShape'), 'BypassEgShape.mif', bool(aModule.egBypassShape.value())),
107  (('mp_egamma', 'egammaBypassEcalFG'), 'BypassEcalFG.mif', bool(aModule.egBypassECALFG.value())),
108  (('mp_egamma', 'egammaBypassExtendedHOverE'), '_BypassExtHE.mif', bool(aModule.egBypassExtHOverE)),
109  (('mp_egamma', 'egammaHOverECut_iEtaLT15'), '_RatioCutLt15.mif', aModule.egHOverEcutBarrel.value()),
110  (('mp_egamma', 'egammaHOverECut_iEtaGTEq15'), '_RatioCutGe15.mif', aModule.egHOverEcutEndcap.value()),
111  (('mp_egamma', 'egammaEnergyCalibLUT'), 'C_EgammaCalibration_12to18.mif', parseOfflineLUTfile(aModule.egCalibrationLUTFile.value(), 4096)),
112  (('mp_egamma', 'egammaIsoLUT1'), 'D_EgammaIsolation1_13to9.mif', parseOfflineLUTfile(aModule.egIsoLUTFile.value(), 8192)),
113  (('mp_egamma', 'egammaIsoLUT2'), 'D_EgammaIsolation2_13to9.mif', parseOfflineLUTfile(aModule.egIsoLUTFile2.value(), 8192))
114  ]
115 
116  result += [
117  (('mp_tau', 'tauMaxEta'), 'tauMaxEta.mif', aModule.isoTauEtaMax.value()),
118  (('mp_tau', 'tauEnergyCalibLUT'), 'I_TauCalibration_11to18.mif', parseOfflineLUTfile(aModule.tauCalibrationLUTFile.value(), 2048, 0x0)),
119  (('mp_tau', 'tauIsoLUT'), 'H_TauIsolation_12to9.mif', parseOfflineLUTfile(aModule.tauIsoLUTFile.value(), 4096)),
120  (('mp_tau', 'tauTrimmingLUT'), 'P_TauTrimming_13to8.mif', parseOfflineLUTfile(aModule.tauTrimmingShapeVetoLUTFile.value(), 8192))
121  ]
122 
123  result += [
124  (('mp_jet', 'jetSeedThreshold'), '1_JetSeedThreshold.mif', divideByJetLsb(aModule.jetSeedThreshold)),
125  (('mp_jet', 'jetMaxEta'), '6_JetEtaMax.mif', 0x00028),
126  (('mp_jet', 'jetBypassPileUpSub'), 'BypassJetPUS.mif', bool(aModule.jetBypassPUS.value())),
127  (('mp_jet', 'jetPUSUsePhiRing'), 'PhiRingPUS.mif', bool(aModule.jetPUSUsePhiRing.value())),
128  (('mp_jet', 'jetEnergyCalibLUT'), 'L_JetCalibration_11to18.mif', parseOfflineLUTfile(aModule.jetCalibrationLUTFile.value(), 4096)),
129  (('mp_jet', 'jetCompressPtLUT'), 'K_EnergyCompression_8to4.mif', parseOfflineLUTfile(aModule.jetCompressPtLUTFile.value(), 256)),
130  (('mp_jet', 'jetCompressEtaLUT'), 'J_EtaCompression_6to6.mif', parseOfflineLUTfile(aModule.jetCompressEtaLUTFile.value(), 64)),
131  (('mp_jet', 'HTMHT_maxJetEta'), 'HTMHT_maxJetEta.mif', aModule.etSumEtaMax[1]), # assert == etSumEtaMax[3] ?
132  (('mp_jet', 'HT_jetThreshold'), '8_HtThreshold.mif', int(aModule.etSumEtThreshold[1] / aModule.etSumLsb.value())),
133  (('mp_jet', 'MHT_jetThreshold'), '9_MHtThreshold.mif', int(aModule.etSumEtThreshold[3] / aModule.etSumLsb.value())),
134  ]
135 
136  result += [
137  (('mp_sums', 'towerCountThreshold'), 'HeavyIonThr.mif', int(aModule.etSumEtThreshold[4] / aModule.etSumLsb.value()) ),
138  (('mp_sums', 'towerCountMaxEta'), 'HeavyIonEta.mif', aModule.etSumEtaMax[4]),
139  (('mp_sums', 'ETMET_maxTowerEta'), 'ETMET_maxTowerEta.mif', aModule.etSumEtaMax[0]), # assert == etSumEtaMax[2] ?
140  (('mp_sums', 'ecalET_towerThresholdLUT'), 'X_EcalTHR_11to9.mif', parseOfflineLUTfile(aModule.etSumEcalSumPUSLUTFile.value(), 2048, aTruncate = True)),
141  (('mp_sums', 'ET_towerThresholdLUT'), 'X_ETTHR_11to9.mif', parseOfflineLUTfile(aModule.etSumEttPUSLUTFile.value(), 2048, aTruncate = True)),
142  (('mp_sums', 'MET_towerThresholdLUT'), 'X_METTHR_11to9.mif', parseOfflineLUTfile(aModule.etSumMetPUSLUTFile.value(), 2048))
143  ]
144 
145  result += [
146  (('demux', 'sdfile'), None, ''),
147  (('demux', 'algoRev'), None, 0xcafe),
148  (('demux', 'ET_centralityLowerThresholds'), 'CentralityLowerThrs.mif', [ int(round(loBound / aModule.etSumLsb.value())) for loBound in aModule.etSumCentralityLower.value()]),
149  (('demux', 'ET_centralityUpperThresholds'), 'CentralityUpperThrs.mif', [ int(round(upBound / aModule.etSumLsb.value())) for upBound in aModule.etSumCentralityUpper.value()]),
150  #(('demux', 'MET_energyCalibLUT'), 'M_METnoHFenergyCalibration_12to18.mif', parseOfflineLUTfile(aModule.metCalibrationLUTFile.value(), 4096, aTruncate = True)),
151  #(('demux', 'METHF_energyCalibLUT'), 'M_METwithHFenergyCalibration_12to18.mif', parseOfflineLUTfile(aModule.metHFCalibrationLUTFile.value(), 4096, aTruncate = True)),
152  #(('demux', 'ET_energyCalibLUT'), 'S_ETcalibration_12to18.mif', parseOfflineLUTfile(aModule.etSumEttCalibrationLUTFile.value(), 4096, aTruncate = True)),
153  #(('demux', 'ecalET_energyCalibLUT'), 'R_EcalCalibration_12to18.mif', parseOfflineLUTfile(aModule.etSumEcalSumCalibrationLUTFile.value(), 4096, aTruncate = True)),
154  #(('demux', 'MET_phiCalibLUT'), 'Q_METnoHFphiCalibration_12to18.mif', parseOfflineLUTfile(aModule.metPhiCalibrationLUTFile.value(), 4096, aTruncate = True)),
155  #(('demux', 'METHF_phiCalibLUT'), 'Q_METwithHFphiCalibration_12to18.mif', parseOfflineLUTfile(aModule.metHFPhiCalibrationLUTFile.value(), 4096, aTruncate = True)),
156  ]
157 
158  result = [(a, b, parseOfflineLUTfile(c.value()) if isinstance(c, cms.FileInPath) else c) for a, b, c in result]
159 
160  return result
161 
162 
def parseOfflineLUTfile(aRelPath, aExpectedSize, aPaddingValue=None, aTruncate=False)

◆ getMifParameterMap()

def convertParamsToOnlineFormat.getMifParameterMap (   aModule)

Definition at line 175 of file convertParamsToOnlineFormat.py.

References getFullListOfParameters().

175 def getMifParameterMap(aModule):
176 
177  fullList = getFullListOfParameters(aModule)
178 
179  return {mifFileName : value for (_, mifFileName, value) in fullList if mifFileName is not None}
180 
181 
182 # Stolen from https://stackoverflow.com/questions/3095434/inserting-newlines-in-xml-file-generated-via-xml-etree-elementtree-in-python

◆ getXmlParameterMap()

def convertParamsToOnlineFormat.getXmlParameterMap (   aModule)

Definition at line 163 of file convertParamsToOnlineFormat.py.

References getFullListOfParameters().

163 def getXmlParameterMap(aModule):
164  result = {}
165  for xmlDetails, mifName, value in getFullListOfParameters(aModule):
166  if xmlDetails is not None:
167  if xmlDetails[0] in result:
168  result[xmlDetails[0]] += [(xmlDetails[1], value)]
169  else:
170  result[xmlDetails[0]] = [(xmlDetails[1], value)]
171 
172  return result
173 
174 

◆ indent()

def convertParamsToOnlineFormat.indent (   elem,
  level = 0 
)

Definition at line 183 of file convertParamsToOnlineFormat.py.

Referenced by createXML().

183 def indent(elem, level=0):
184  i = "\n" + level*" "
185  if len(elem):
186  if not elem.text or not elem.text.strip():
187  elem.text = i + " "
188  if not elem.tail or not elem.tail.strip():
189  elem.tail = i
190  for elem in elem:
191  indent(elem, level+1)
192  if not elem.tail or not elem.tail.strip():
193  elem.tail = i
194  else:
195  if level and (not elem.tail or not elem.tail.strip()):
196  elem.tail = i
197 

◆ pairwiseGen()

def convertParamsToOnlineFormat.pairwiseGen (   aList)

Definition at line 13 of file convertParamsToOnlineFormat.py.

References FastTimerService_cff.range.

Referenced by parseOfflineLUTfile().

13 def pairwiseGen(aList):
14  for i in range(len(aList)-1):
15  yield (aList[i], aList[i+1])
16 

◆ parseOfflineLUTfile()

def convertParamsToOnlineFormat.parseOfflineLUTfile (   aRelPath,
  aExpectedSize,
  aPaddingValue = None,
  aTruncate = False 
)

Definition at line 17 of file convertParamsToOnlineFormat.py.

References createfilelist.int, pairwiseGen(), print(), submitPVValidationJobs.split(), and str.

Referenced by getFullListOfParameters().

17 def parseOfflineLUTfile(aRelPath, aExpectedSize, aPaddingValue = None, aTruncate = False):
18  # Find file by looking under directories listed in 'CMSSW_SEARCH_PATH' as outlined in https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideEdmFileInPath
19  searchPaths = os.getenv('CMSSW_SEARCH_PATH').split(':')
20  resolvedPath = None
21  for baseDir in searchPaths:
22  print("Looking for '" + aRelPath + "' under '" + baseDir + "'")
23  if os.path.isfile(os.path.join(baseDir, aRelPath)):
24  print(" success!")
25  resolvedPath = os.path.join(baseDir, aRelPath)
26  break
27  if resolvedPath is None:
28  raise RuntimeError("Could not find LUT file '" + aRelPath + "' under directories in 'CMSSW_SEARCH_PATH'")
29 
30  with open(resolvedPath) as f:
31  entries = []
32  line_nr = 0
33  for line in f:
34  line_nr += 1
35  # Ignore comment lines
36  if line.startswith('#') or line == '\n':
37  continue
38 
39  # Remove trailing comments from data lines
40  stripped_line = line[:line.find('#')]
41 
42  # Split line into list of whitespace-separated items
43  items = stripped_line.split()
44  if len(items) != 2:
45  print("ERROR parsing file", resolvedPath, "on line", line_nr, "'" + line + "' : Splitting on whitespace produced", len(items), "items")
46  sys.exit(1)
47 
48  entries.append( (int(items[0]), int(items[1])) )
49 
50  # Sort the LUT
51  entries.sort(key= lambda x : x[0])
52  # Check that the LUT is not empty
53  if len(entries) == 0:
54  print("ERROR parsing file", resolvedPath, ": No LUT entries defined in the file")
55  sys.exit(1)
56 
57  # Check that no items from the LUT are missing
58  if entries[0][0] != 0:
59  print("ERROR parsing file", resolvedPath, ": LUT entries before index", entries[0][0], "are not defined")
60  sys.exit(1)
61 
62  for x1, x2 in pairwiseGen(entries):
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")
65  sys.exit(1)
66 
67  result = [x[1] for x in entries]
68 
69  if (len(result) < aExpectedSize) and not (aPaddingValue is None):
70  print ("WARNING : Padding", str(len(result))+"-entry LUT with value", aPaddingValue, "to have", aExpectedSize, "entries")
71  result += ([aPaddingValue] * (aExpectedSize - len(result)))
72  elif (len(result) > aExpectedSize) and aTruncate:
73  print ("WARNING : Truncating", str(len(result))+"-entry LUT to have", aExpectedSize, "entries")
74  result = result[0:aExpectedSize]
75  elif len(result) != aExpectedSize:
76  print ("ERROR parsing file", resolvedPath, ": Expected LUT of size", aExpectedSize, ", but", len(result), "entries were specified (and no padding/truncation requested)")
77  sys.exit(1)
78 
79  return result
80 
81 
def parseOfflineLUTfile(aRelPath, aExpectedSize, aPaddingValue=None, aTruncate=False)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)

Variable Documentation

◆ action

convertParamsToOnlineFormat.action

Definition at line 242 of file convertParamsToOnlineFormat.py.

◆ args

convertParamsToOnlineFormat.args

Definition at line 245 of file convertParamsToOnlineFormat.py.

◆ caloParams

convertParamsToOnlineFormat.caloParams

Definition at line 249 of file convertParamsToOnlineFormat.py.

◆ help

convertParamsToOnlineFormat.help

Definition at line 238 of file convertParamsToOnlineFormat.py.

◆ moduleName

convertParamsToOnlineFormat.moduleName

Definition at line 247 of file convertParamsToOnlineFormat.py.

◆ outputFormatGroup

convertParamsToOnlineFormat.outputFormatGroup

Definition at line 241 of file convertParamsToOnlineFormat.py.

◆ parser

convertParamsToOnlineFormat.parser

Definition at line 236 of file convertParamsToOnlineFormat.py.

◆ required

convertParamsToOnlineFormat.required

Definition at line 241 of file convertParamsToOnlineFormat.py.