CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XMLConfigReader.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 #include <algorithm>
4 #include <utility>
5 
10 
12 
14 
15 #include "xercesc/framework/StdOutFormatTarget.hpp"
16 #include "xercesc/framework/LocalFileFormatTarget.hpp"
17 #include "xercesc/parsers/XercesDOMParser.hpp"
18 #include "xercesc/dom/DOM.hpp"
19 #include "xercesc/dom/DOMException.hpp"
20 #include "xercesc/dom/DOMImplementation.hpp"
21 #include "xercesc/sax/HandlerBase.hpp"
22 #include "xercesc/util/XMLString.hpp"
23 #include "xercesc/util/PlatformUtils.hpp"
24 #include "xercesc/util/XercesDefs.hpp"
25 XERCES_CPP_NAMESPACE_USE
26 
27 
29 // XMLConfigReader
31 inline std::string _toString(XMLCh const* toTranscode) {
33 return tmp;
34 }
35 
36 inline XMLCh* _toDOMS(std::string temp) {
37  XMLCh* buff = XMLString::transcode(temp.c_str());
38  return buff;
39 }
43 
44  XMLPlatformUtils::Initialize();
45 
47  parser = new XercesDOMParser();
48  parser->setValidationScheme(XercesDOMParser::Val_Auto);
49  parser->setDoNamespaces(false);
50 
51  doc = 0;
52 
53 
54 
55 }
59 
60  std::stringstream strStream;
61  int totalInWidth = 6;
62  int outWidth = 6;
63 
64  if(type=="iCharge") outWidth = 1;
65  if(type=="iEta") outWidth = 2;
66  if(type=="iPt") outWidth = 6;
67  if(type=="meanDistPhi"){
68  outWidth = 11;
69  totalInWidth = 14;
70  }
71  if(type=="pdf"){
72  outWidth = 6;
73  totalInWidth = 20;
74  }
75 
77  strStream <<"#<header> V1 "<<totalInWidth<<" "<<outWidth<<" </header> "<<std::endl;
78 
80  const std::vector<GoldenPattern *> & aGPs = readPatterns();
81  unsigned int in = 0;
82  int out = 0;
83  for(auto it: aGPs){
84  if(type=="iCharge") out = it->key().theCharge + 1*(it->key().theCharge<0);
85  if(type=="iEta") out = it->key().theEtaCode;
86  if(type=="iPt") out = it->key().thePtCode;
87  if(type=="meanDistPhi"){
88  for(unsigned int iLayer = 0;iLayer<OMTFConfiguration::nLayers;++iLayer){
89  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::nRefLayers;++iRefLayer){
90  out = (1<<(outWidth-1)) + it->meanDistPhiValue(iLayer,iRefLayer);
91  strStream<<in<<" "<<out<<std::endl;
92  ++in;
93  }
94  }
95  }
96  if(type=="pdf"){
97  for(unsigned int iLayer = 0;iLayer<OMTFConfiguration::nLayers;++iLayer){
98  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::nRefLayers;++iRefLayer){
99  for(unsigned int iPdf=0;iPdf<exp2(OMTFConfiguration::nPdfAddrBits);++iPdf){
100  out = it->pdfValue(iLayer,iRefLayer,iPdf);
101  strStream<<in<<" "<<out<<std::endl;
102  ++in;
103  }
104  }
105  }
106  }
107  if(type!="meanDistPhi" && type!="pdf"){
108  strStream<<in<<" "<<out<<std::endl;
109  ++in;
110  }
111  }
113  lut->read(strStream);
114 }
117 std::vector<GoldenPattern*> XMLConfigReader::readPatterns(){
118 
119  if(aGPs.size()) return aGPs;
120 
121  parser->parse(patternsFile.c_str());
122  xercesc::DOMDocument* doc = parser->getDocument();
123  assert(doc);
124 
125  unsigned int nElem = doc->getElementsByTagName(_toDOMS("GP"))->getLength();
126  if(nElem<1){
127  edm::LogError("critical")<<"Problem parsing XML file "<<patternsFile<<std::endl;
128  edm::LogError("critical")<<"No GoldenPattern items: GP found"<<std::endl;
129  return aGPs;
130  }
131 
132  DOMNode *aNode = 0;
133  DOMElement* aGPElement = 0;
134  for(unsigned int iItem=0;iItem<nElem;++iItem){
135  aNode = doc->getElementsByTagName(_toDOMS("GP"))->item(iItem);
136  aGPElement = static_cast<DOMElement *>(aNode);
137 
138  std::ostringstream stringStr;
139  GoldenPattern *aGP;
140  for(unsigned int index = 1;index<5;++index){
141  stringStr.str("");
142  stringStr<<"iPt"<<index;
144  if(aGPElement->getAttributeNode(_toDOMS(stringStr.str().c_str()))){
145  aGP = buildGP(aGPElement,index);
146  if(aGP) aGPs.push_back(aGP);
147  }
148  else{
149  aGPs.push_back(buildGP(aGPElement));
150  break;
151  }
152  }
153  }
154  delete doc;
155 
156  return aGPs;
157 }
160 GoldenPattern * XMLConfigReader::buildGP(DOMElement* aGPElement,
161  unsigned int index){
162 
163  std::ostringstream stringStr;
164  if(index>0) stringStr<<"iPt"<<index;
165  else stringStr.str("iPt");
166 
167  unsigned int iPt = std::atoi(_toString(aGPElement->getAttribute(_toDOMS(stringStr.str().c_str()))).c_str());
168  if(iPt==0) return 0;
169 
170  int iEta = std::atoi(_toString(aGPElement->getAttribute(_toDOMS("iEta"))).c_str());
171  int iCharge = std::atoi(_toString(aGPElement->getAttribute(_toDOMS("iCharge"))).c_str());
172  int val = 0;
173  unsigned int nLayers = aGPElement->getElementsByTagName(_toDOMS("Layer"))->getLength();
175  DOMNode *aNode = 0;
176  DOMElement* aLayerElement = 0;
177  DOMElement* aItemElement = 0;
178  GoldenPattern::vector2D meanDistPhi2D(nLayers);
183  for(unsigned int iLayer=0;iLayer<nLayers;++iLayer){
184  aNode = aGPElement->getElementsByTagName(_toDOMS("Layer"))->item(iLayer);
185  aLayerElement = static_cast<DOMElement *>(aNode);
187  unsigned int nItems = aLayerElement->getElementsByTagName(_toDOMS("RefLayer"))->getLength();
189  GoldenPattern::vector1D meanDistPhi1D(nItems);
190  for(unsigned int iItem=0;iItem<nItems;++iItem){
191  aNode = aLayerElement->getElementsByTagName(_toDOMS("RefLayer"))->item(iItem);
192  aItemElement = static_cast<DOMElement *>(aNode);
193  val = std::atoi(_toString(aItemElement->getAttribute(_toDOMS("meanDistPhi"))).c_str());
194  meanDistPhi1D[iItem] = val;
195  }
196  meanDistPhi2D[iLayer] = meanDistPhi1D;
197 
199  stringStr.str("");
200  if(index>0) stringStr<<"value"<<index;
201  else stringStr.str("value");
202  nItems = aLayerElement->getElementsByTagName(_toDOMS("PDF"))->getLength();
204  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::nRefLayers;++iRefLayer){
205  pdf1D.assign(exp2(OMTFConfiguration::nPdfAddrBits),0);
206  for(unsigned int iPdf=0;iPdf<exp2(OMTFConfiguration::nPdfAddrBits);++iPdf){
207  aNode = aLayerElement->getElementsByTagName(_toDOMS("PDF"))->item(iRefLayer*exp2(OMTFConfiguration::nPdfAddrBits)+iPdf);
208  aItemElement = static_cast<DOMElement *>(aNode);
209  val = std::atoi(_toString(aItemElement->getAttribute(_toDOMS(stringStr.str().c_str()))).c_str());
210  pdf1D[iPdf] = val;
211  }
212  pdf2D[iRefLayer] = pdf1D;
213  }
214  pdf3D[iLayer] = pdf2D;
215  }
216 
217  Key aKey(iEta,iPt,iCharge);
218  GoldenPattern *aGP = new GoldenPattern(aKey);
219  aGP->setMeanDistPhi(meanDistPhi2D);
220  aGP->setPdf(pdf3D);
221 
222  return aGP;
223 }
226 std::vector<std::vector<int> > XMLConfigReader::readEvent(unsigned int iEvent,
227  unsigned int iProcessor,
228  bool readEta){
229  if(!doc){
230  parser->parse(eventsFile.c_str());
231  doc = parser->getDocument();
232  }
233  assert(doc);
234 
235 
238 
239  unsigned int nElem = doc->getElementsByTagName(_toDOMS("OMTF_Events"))->getLength();
240  assert(nElem==1);
241 
242  DOMNode *aNode = doc->getElementsByTagName(_toDOMS("OMTF_Events"))->item(0);
243  DOMElement* aOMTFElement = static_cast<DOMElement *>(aNode);
244  DOMElement* aEventElement = 0;
245  DOMElement* aBxElement = 0;
246  DOMElement* aProcElement = 0;
247  DOMElement* aLayerElement = 0;
248  DOMElement* aHitElement = 0;
249  unsigned int aLogicLayer = OMTFConfiguration::nLayers+1;
250  int val = 0, input=0;
251 
252  nElem = aOMTFElement->getElementsByTagName(_toDOMS("Event"))->getLength();
253  if(nElem<iEvent){
254  edm::LogError("critical")<<"Problem parsing XML file "<<eventsFile<<std::endl;
255  edm::LogError("critical")<<"not enough events found: "<<nElem<<std::endl;
256  assert(nElem>=iEvent);
257  }
258 
259  aNode = aOMTFElement->getElementsByTagName(_toDOMS("Event"))->item(iEvent);
260  aEventElement = static_cast<DOMElement *>(aNode);
261 
262  unsigned int nBX = aEventElement->getElementsByTagName(_toDOMS("bx"))->getLength();
263  assert(nBX>0);
264  aNode = aEventElement->getElementsByTagName(_toDOMS("bx"))->item(0);
265  aBxElement = static_cast<DOMElement *>(aNode);
266 
267  unsigned int nProc = aEventElement->getElementsByTagName(_toDOMS("Processor"))->getLength();
268  unsigned int aProcID = 99;
269  assert(nProc>=iProcessor);
270  for(unsigned int aProc=0;aProc<nProc;++aProc){
271  aNode = aBxElement->getElementsByTagName(_toDOMS("Processor"))->item(aProc);
272  aProcElement = static_cast<DOMElement *>(aNode);
273  aProcID = std::atoi(_toString(aProcElement->getAttribute(_toDOMS("iProcessor"))).c_str());
274  if(aProcID==iProcessor) break;
275  }
276  if(aProcID!=iProcessor) return input2D;
277 
278  unsigned int nLayersHit = aProcElement->getElementsByTagName(_toDOMS("Layer"))->getLength();
279  assert(nLayersHit<=OMTFConfiguration::nLayers);
280 
281  input2D.assign(OMTFConfiguration::nLayers,input1D);
282 
283  for(unsigned int iLayer=0;iLayer<nLayersHit;++iLayer){
284  aNode = aProcElement->getElementsByTagName(_toDOMS("Layer"))->item(iLayer);
285  aLayerElement = static_cast<DOMElement *>(aNode);
286  aLogicLayer = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("iLayer"))).c_str());
287  nElem = aLayerElement->getElementsByTagName(_toDOMS("Hit"))->getLength();
288  input1D.assign(14,OMTFConfiguration::nPhiBins);
289  for(unsigned int iHit=0;iHit<nElem;++iHit){
290  aNode = aLayerElement->getElementsByTagName(_toDOMS("Hit"))->item(iHit);
291  aHitElement = static_cast<DOMElement *>(aNode);
292  val = std::atoi(_toString(aHitElement->getAttribute(_toDOMS("iPhi"))).c_str());
293  if(readEta) val = std::atoi(_toString(aHitElement->getAttribute(_toDOMS("iEta"))).c_str());
294  input = std::atoi(_toString(aHitElement->getAttribute(_toDOMS("iInput"))).c_str());
295  input1D[input] = val;
296  }
297  input2D[aLogicLayer] = input1D;
298  }
299 
300  //delete doc;
301  return input2D;
302 }
306 
307  parser->parse(configFile.c_str());
308  xercesc::DOMDocument* doc = parser->getDocument();
309  assert(doc);
310  unsigned int nElem = doc->getElementsByTagName(_toDOMS("OMTF"))->getLength();
311  if(nElem!=1){
312  edm::LogError("critical")<<"Problem parsing XML file "<<configFile<<std::endl;
313  assert(nElem==1);
314  }
315  DOMNode *aNode = doc->getElementsByTagName(_toDOMS("OMTF"))->item(0);
316  DOMElement* aOMTFElement = static_cast<DOMElement *>(aNode);
317 
318  unsigned int version = std::atoi(_toString(aOMTFElement->getAttribute(_toDOMS("version"))).c_str());
319  aConfig->setFwVersion(version);
320 
322  nElem = aOMTFElement->getElementsByTagName(_toDOMS("GlobalData"))->getLength();
323  assert(nElem==1);
324  aNode = aOMTFElement->getElementsByTagName(_toDOMS("GlobalData"))->item(0);
325  DOMElement* aElement = static_cast<DOMElement *>(aNode);
326 
327  unsigned int nPdfAddrBits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nPdfAddrBits"))).c_str());
328  unsigned int nPdfValBits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nPdfValBits"))).c_str());
329  unsigned int nHitsPerLayer = std::atoi(_toString(aElement->getAttribute(_toDOMS("nHitsPerLayer"))).c_str());
330  unsigned int nPhiBits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nPhiBits"))).c_str());
331  unsigned int nPhiBins = std::atoi(_toString(aElement->getAttribute(_toDOMS("nPhiBins"))).c_str());
332  unsigned int nRefHits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nRefHits"))).c_str());
333  unsigned int nTestRefHits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nTestRefHits"))).c_str());
334  unsigned int nProcessors = std::atoi(_toString(aElement->getAttribute(_toDOMS("nProcessors"))).c_str());
335  unsigned int nLogicRegions = std::atoi(_toString(aElement->getAttribute(_toDOMS("nLogicRegions"))).c_str());
336  unsigned int nInputs = std::atoi(_toString(aElement->getAttribute(_toDOMS("nInputs"))).c_str());
337  unsigned int nLayers = std::atoi(_toString(aElement->getAttribute(_toDOMS("nLayers"))).c_str());
338  unsigned int nRefLayers = std::atoi(_toString(aElement->getAttribute(_toDOMS("nRefLayers"))).c_str());
339  unsigned int nGoldenPatterns = std::atoi(_toString(aElement->getAttribute(_toDOMS("nGoldenPatterns"))).c_str());
340 
341  std::vector<int> paramsVec(L1TMuonOverlapParams::GENERAL_NCONFIG);
342  paramsVec[L1TMuonOverlapParams::GENERAL_ADDRBITS] = nPdfAddrBits;
343  paramsVec[L1TMuonOverlapParams::GENERAL_VALBITS] = nPdfValBits;
344  paramsVec[L1TMuonOverlapParams::GENERAL_HITSPERLAYER] = nHitsPerLayer;
345  paramsVec[L1TMuonOverlapParams::GENERAL_PHIBITS] = nPhiBits;
347  paramsVec[L1TMuonOverlapParams::GENERAL_NREFHITS] = nRefHits;
348  paramsVec[L1TMuonOverlapParams::GENERAL_NTESTREFHITS] = nTestRefHits;
349  paramsVec[L1TMuonOverlapParams::GENERAL_NPROCESSORS] = nProcessors;
350  paramsVec[L1TMuonOverlapParams::GENERAL_NLOGIC_REGIONS] = nLogicRegions;
351  paramsVec[L1TMuonOverlapParams::GENERAL_NINPUTS] = nInputs;
352  paramsVec[L1TMuonOverlapParams::GENERAL_NLAYERS] = nLayers;
353  paramsVec[L1TMuonOverlapParams::GENERAL_NREFLAYERS] = nRefLayers;
354  paramsVec[L1TMuonOverlapParams::GENERAL_NGOLDENPATTERNS] = nGoldenPatterns;
355  aConfig->setGeneralParams(paramsVec);
356 
359  std::vector<int> sectorsStart(3*6), sectorsEnd(3*6);
360  nElem = aOMTFElement->getElementsByTagName(_toDOMS("ConnectionMap"))->getLength();
361  DOMElement* aConnectionElement = 0;
362  for(uint i=0;i<nElem;++i){
363  aNode = aOMTFElement->getElementsByTagName(_toDOMS("ConnectionMap"))->item(i);
364  aConnectionElement = static_cast<DOMElement *>(aNode);
365  unsigned int iProcessor = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("iProcessor"))).c_str());
366  unsigned int barrelMin = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("barrelMin"))).c_str());
367  unsigned int barrelMax = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("barrelMax"))).c_str());
368  unsigned int endcap10DegMin = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("endcap10DegMin"))).c_str());
369  unsigned int endcap10DegMax = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("endcap10DegMax"))).c_str());
370  unsigned int endcap20DegMin = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("endcap20DegMin"))).c_str());
371  unsigned int endcap20DegMax = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("endcap20DegMax"))).c_str());
372 
373  sectorsStart[iProcessor] = barrelMin;
374  sectorsStart[iProcessor + 6] = endcap10DegMin;
375  sectorsStart[iProcessor +12] = endcap20DegMin;
376 
377  sectorsEnd[iProcessor] = barrelMax;
378  sectorsEnd[iProcessor + 6] = endcap10DegMax;
379  sectorsEnd[iProcessor + 12] = endcap20DegMax;
380  }
381  aConfig->setConnectedSectorsStart(sectorsStart);
382  aConfig->setConnectedSectorsEnd(sectorsEnd);
383 
384 
386  std::vector<L1TMuonOverlapParams::LayerMapNode> aLayerMapVec;
388 
389  nElem = aOMTFElement->getElementsByTagName(_toDOMS("LayerMap"))->getLength();
390  DOMElement* aLayerElement = 0;
391  for(uint i=0;i<nElem;++i){
392  aNode = aOMTFElement->getElementsByTagName(_toDOMS("LayerMap"))->item(i);
393  aLayerElement = static_cast<DOMElement *>(aNode);
394  unsigned int hwNumber = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("hwNumber"))).c_str());
395  unsigned int logicNumber = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("logicNumber"))).c_str());
396  unsigned int isBendingLayer = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("bendingLayer"))).c_str());
397  unsigned int iConnectedLayer = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("connectedToLayer"))).c_str());
398  aLayerMapNode.logicNumber = logicNumber;
399  aLayerMapNode.hwNumber = hwNumber;
400  aLayerMapNode.connectedToLayer = iConnectedLayer;
401  aLayerMapNode.bendingLayer = isBendingLayer;
402  aLayerMapVec.push_back(aLayerMapNode);
403  }
404  aConfig->setLayerMap(aLayerMapVec);
405 
407  std::vector<L1TMuonOverlapParams::RefLayerMapNode> aRefLayerMapVec;
409 
410  nElem = aOMTFElement->getElementsByTagName(_toDOMS("RefLayerMap"))->getLength();
411  DOMElement* aRefLayerElement = 0;
412  for(uint i=0;i<nElem;++i){
413  aNode = aOMTFElement->getElementsByTagName(_toDOMS("RefLayerMap"))->item(i);
414  aRefLayerElement = static_cast<DOMElement *>(aNode);
415  unsigned int refLayer = std::atoi(_toString(aRefLayerElement->getAttribute(_toDOMS("refLayer"))).c_str());
416  unsigned int logicNumber = std::atoi(_toString(aRefLayerElement->getAttribute(_toDOMS("logicNumber"))).c_str());
417  aRefLayerNode.refLayer = refLayer;
418  aRefLayerNode.logicNumber = logicNumber;
419  aRefLayerMapVec.push_back(aRefLayerNode);
420  }
421  aConfig->setRefLayerMap(aRefLayerMapVec);
422 
423 
424  std::vector<int> aGlobalPhiStartVec(nProcessors*nRefLayers);
425 
426  std::vector<L1TMuonOverlapParams::RefHitNode> aRefHitMapVec(nProcessors*nRefHits);
428 
429  std::vector<L1TMuonOverlapParams::LayerInputNode> aLayerInputMapVec(nProcessors*nLogicRegions*nLayers);
430  L1TMuonOverlapParams::LayerInputNode aLayerInputNode;
431 
432  nElem = aOMTFElement->getElementsByTagName(_toDOMS("Processor"))->getLength();
433  assert(nElem==nProcessors);
434  DOMElement* aProcessorElement = 0;
435  for(uint i=0;i<nElem;++i){
436  aNode = aOMTFElement->getElementsByTagName(_toDOMS("Processor"))->item(i);
437  aProcessorElement = static_cast<DOMElement *>(aNode);
438  unsigned int iProcessor = std::atoi(_toString(aProcessorElement->getAttribute(_toDOMS("iProcessor"))).c_str());
439  unsigned int nElem1 = aProcessorElement->getElementsByTagName(_toDOMS("RefLayer"))->getLength();
440  assert(nElem1==nRefLayers);
441  DOMElement* aRefLayerElement = 0;
442  for(uint ii=0;ii<nElem1;++ii){
443  aNode = aProcessorElement->getElementsByTagName(_toDOMS("RefLayer"))->item(ii);
444  aRefLayerElement = static_cast<DOMElement *>(aNode);
445  unsigned int iRefLayer = std::atoi(_toString(aRefLayerElement->getAttribute(_toDOMS("iRefLayer"))).c_str());
446  int iPhi = std::atoi(_toString(aRefLayerElement->getAttribute(_toDOMS("iGlobalPhiStart"))).c_str());
447  aGlobalPhiStartVec[iRefLayer + iProcessor*nRefLayers] = iPhi;
448  }
450  nElem1 = aProcessorElement->getElementsByTagName(_toDOMS("RefHit"))->getLength();
451  assert(nElem1==nRefHits);
452  DOMElement* aRefHitElement = 0;
453  for(uint ii=0;ii<nElem1;++ii){
454  aNode = aProcessorElement->getElementsByTagName(_toDOMS("RefHit"))->item(ii);
455  aRefHitElement = static_cast<DOMElement *>(aNode);
456  unsigned int iRefHit = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iRefHit"))).c_str());
457  int iPhiMin = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iPhiMin"))).c_str());
458  int iPhiMax = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iPhiMax"))).c_str());
459  unsigned int iInput = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iInput"))).c_str());
460  unsigned int iRegion = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iRegion"))).c_str());
461  unsigned int iRefLayer = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iRefLayer"))).c_str());
462 
463  aRefHitNode.iRefHit = iRefHit;
464  aRefHitNode.iPhiMin = iPhiMin;
465  aRefHitNode.iPhiMax = iPhiMax;
466  aRefHitNode.iInput = iInput;
467  aRefHitNode.iRegion = iRegion;
468  aRefHitNode.iRefLayer = iRefLayer;
469  aRefHitMapVec[iRefHit + iProcessor*nRefHits] = aRefHitNode;
470  }
472  unsigned int nElem2 = aProcessorElement->getElementsByTagName(_toDOMS("LogicRegion"))->getLength();
473  assert(nElem2==nProcessors);
474  DOMElement* aRegionElement = 0;
475  for(uint ii=0;ii<nElem2;++ii){
476  aNode = aProcessorElement->getElementsByTagName(_toDOMS("LogicRegion"))->item(ii);
477  aRegionElement = static_cast<DOMElement *>(aNode);
478  unsigned int iRegion = std::atoi(_toString(aRegionElement->getAttribute(_toDOMS("iRegion"))).c_str());
479  unsigned int nElem3 = aRegionElement->getElementsByTagName(_toDOMS("Layer"))->getLength();
480  assert(nElem3==nLayers);
481  DOMElement* aLayerElement = 0;
482  for(uint iii=0;iii<nElem3;++iii){
483  aNode = aRegionElement->getElementsByTagName(_toDOMS("Layer"))->item(iii);
484  aLayerElement = static_cast<DOMElement *>(aNode);
485  unsigned int iLayer = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("iLayer"))).c_str());
486  unsigned int iFirstInput = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("iFirstInput"))).c_str());
487  unsigned int nInputs = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("nInputs"))).c_str());
488  aLayerInputNode.iLayer = iLayer;
489  aLayerInputNode.iFirstInput = iFirstInput;
490  aLayerInputNode.nInputs = nInputs;
491  aLayerInputMapVec[iLayer + iRegion*nLayers + iProcessor*nLayers*nLogicRegions] = aLayerInputNode;
492  }
493  }
494  }
495 
496  aConfig->setGlobalPhiStartMap(aGlobalPhiStartVec);
497  aConfig->setLayerInputMap(aLayerInputMapVec);
498  aConfig->setRefHitMap(aRefHitMapVec);
499 
500  delete doc;
501 }
505 
506  parser->parse(configFile.c_str());
507  xercesc::DOMDocument* doc = parser->getDocument();
508  assert(doc);
509  unsigned int nElem = doc->getElementsByTagName(_toDOMS("OMTF"))->getLength();
510  if(nElem!=1){
511  edm::LogError("critical")<<"Problem parsing XML file "<<configFile<<std::endl;
512  assert(nElem==1);
513  }
514  DOMNode *aNode = doc->getElementsByTagName(_toDOMS("OMTF"))->item(0);
515  DOMElement* aOMTFElement = static_cast<DOMElement *>(aNode);
516 
518  nElem = aOMTFElement->getElementsByTagName(_toDOMS("GlobalData"))->getLength();
519  assert(nElem==1);
520  aNode = aOMTFElement->getElementsByTagName(_toDOMS("GlobalData"))->item(0);
521  DOMElement* aElement = static_cast<DOMElement *>(aNode);
522 
523  float minPdfVal = 0.001;
524  unsigned int nPdfAddrBits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nPdfAddrBits"))).c_str());
525  unsigned int nPdfValBits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nPdfValBits"))).c_str());
526  unsigned int nHitsPerLayer = std::atoi(_toString(aElement->getAttribute(_toDOMS("nHitsPerLayer"))).c_str());
527  unsigned int nPhiBits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nPhiBits"))).c_str());
528  unsigned int nPhiBins = std::atoi(_toString(aElement->getAttribute(_toDOMS("nPhiBins"))).c_str());
529  unsigned int nRefHits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nRefHits"))).c_str());
530  unsigned int nTestRefHits = std::atoi(_toString(aElement->getAttribute(_toDOMS("nTestRefHits"))).c_str());
531  unsigned int nProcessors = std::atoi(_toString(aElement->getAttribute(_toDOMS("nProcessors"))).c_str());
532  unsigned int nLogicRegions = std::atoi(_toString(aElement->getAttribute(_toDOMS("nLogicRegions"))).c_str());
533  unsigned int nInputs = std::atoi(_toString(aElement->getAttribute(_toDOMS("nInputs"))).c_str());
534  unsigned int nGoldenPatterns = std::atoi(_toString(aElement->getAttribute(_toDOMS("nGoldenPatterns"))).c_str());
535  OMTFConfiguration::minPdfVal = minPdfVal;
536  OMTFConfiguration::nPdfAddrBits = nPdfAddrBits;
537  OMTFConfiguration::nPdfValBits = nPdfValBits;
538  OMTFConfiguration::nHitsPerLayer = nHitsPerLayer;
539  OMTFConfiguration::nPhiBits = nPhiBits;
541  OMTFConfiguration::nRefHits = nRefHits;
542  OMTFConfiguration::nTestRefHits = nTestRefHits;
543  OMTFConfiguration::nProcessors = nProcessors;
544  OMTFConfiguration::nLogicRegions = nLogicRegions;
545  OMTFConfiguration::nInputs = nInputs;
546  OMTFConfiguration::nGoldenPatterns = nGoldenPatterns;
547 
549  OMTFConfiguration::barrelMin = std::vector<unsigned int>(6);
550  OMTFConfiguration::barrelMax = std::vector<unsigned int>(6);
551 
552  OMTFConfiguration::endcap10DegMin = std::vector<unsigned int>(6);
553  OMTFConfiguration::endcap10DegMax = std::vector<unsigned int>(6);
554 
555  OMTFConfiguration::endcap20DegMin = std::vector<unsigned int>(6);
556  OMTFConfiguration::endcap20DegMax = std::vector<unsigned int>(6);
557 
558  nElem = aOMTFElement->getElementsByTagName(_toDOMS("ConnectionMap"))->getLength();
559  DOMElement* aConnectionElement = 0;
560  for(uint i=0;i<nElem;++i){
561  aNode = aOMTFElement->getElementsByTagName(_toDOMS("ConnectionMap"))->item(i);
562  aConnectionElement = static_cast<DOMElement *>(aNode);
563  unsigned int iProcessor = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("iProcessor"))).c_str());
564  unsigned int barrelMin = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("barrelMin"))).c_str());
565  unsigned int barrelMax = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("barrelMax"))).c_str());
566  unsigned int endcap10DegMin = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("endcap10DegMin"))).c_str());
567  unsigned int endcap10DegMax = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("endcap10DegMax"))).c_str());
568  unsigned int endcap20DegMin = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("endcap20DegMin"))).c_str());
569  unsigned int endcap20DegMax = std::atoi(_toString(aConnectionElement->getAttribute(_toDOMS("endcap20DegMax"))).c_str());
570 
571  OMTFConfiguration::barrelMin[iProcessor] = barrelMin;
572  OMTFConfiguration::endcap10DegMin[iProcessor] = endcap10DegMin;
573  OMTFConfiguration::endcap20DegMin[iProcessor] = endcap20DegMin;
574 
575  OMTFConfiguration::barrelMax[iProcessor] = barrelMax;
576  OMTFConfiguration::endcap10DegMax[iProcessor] = endcap10DegMax;
577  OMTFConfiguration::endcap20DegMax[iProcessor] = endcap20DegMax;
578  }
579 
581  unsigned int nLogicLayers = 0;
582  nElem = aOMTFElement->getElementsByTagName(_toDOMS("LayerMap"))->getLength();
583  DOMElement* aLayerElement = 0;
584  for(uint i=0;i<nElem;++i){
585  aNode = aOMTFElement->getElementsByTagName(_toDOMS("LayerMap"))->item(i);
586  aLayerElement = static_cast<DOMElement *>(aNode);
587  unsigned int hwNumber = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("hwNumber"))).c_str());
588  unsigned int logicNumber = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("logicNumber"))).c_str());
589  unsigned int isBendingLayer = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("bendingLayer"))).c_str());
590  unsigned int iConnectedLayer = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("connectedToLayer"))).c_str());
591  aConfig->hwToLogicLayer[hwNumber] = logicNumber;
592  aConfig->logicToHwLayer[logicNumber] = hwNumber;
593  aConfig->logicToLogic[logicNumber] = iConnectedLayer;
594  if(isBendingLayer) aConfig->bendingLayers.insert(logicNumber);
595  if(nLogicLayers<logicNumber) nLogicLayers = logicNumber;
596  }
597  ++nLogicLayers;//logic number in XML starts from 0.
598  OMTFConfiguration::nLayers = nLogicLayers;
599 
601  unsigned int nRefLayers = 0;
602  nElem = aOMTFElement->getElementsByTagName(_toDOMS("RefLayerMap"))->getLength();
603  aConfig->refToLogicNumber.resize(nElem);
604  DOMElement* aRefLayerElement = 0;
605  for(uint i=0;i<nElem;++i){
606  aNode = aOMTFElement->getElementsByTagName(_toDOMS("RefLayerMap"))->item(i);
607  aRefLayerElement = static_cast<DOMElement *>(aNode);
608  unsigned int refLayer = std::atoi(_toString(aRefLayerElement->getAttribute(_toDOMS("refLayer"))).c_str());
609  unsigned int logicNumber = std::atoi(_toString(aRefLayerElement->getAttribute(_toDOMS("logicNumber"))).c_str());
610  aConfig->refToLogicNumber[refLayer] = logicNumber;
611  if(nRefLayers<logicNumber) nRefLayers = refLayer;
612  }
613  ++nRefLayers;//ref number in XML starts from 0.
614  OMTFConfiguration::nRefLayers = nRefLayers;
615 
619 
625  aLayer2D.assign(OMTFConfiguration::nProcessors,aLayer1D);
628 
631  std::vector<std::pair<int,int> > aRefHit1D(OMTFConfiguration::nLogicRegions,std::pair<int,int>(9999,9999));
633  std::vector<std::vector<std::pair<int,int> > > aRefHit2D;
634  aRefHit2D.assign(OMTFConfiguration::nRefLayers,aRefHit1D);
637 
638  //Vector of ref hit definitions
639  std::vector<RefHitDef> aRefHitsDefs(OMTFConfiguration::nRefHits);
642 
643  nElem = aOMTFElement->getElementsByTagName(_toDOMS("Processor"))->getLength();
645  DOMElement* aProcessorElement = 0;
646  for(uint i=0;i<nElem;++i){
647  aNode = aOMTFElement->getElementsByTagName(_toDOMS("Processor"))->item(i);
648  aProcessorElement = static_cast<DOMElement *>(aNode);
649  unsigned int iProcessor = std::atoi(_toString(aProcessorElement->getAttribute(_toDOMS("iProcessor"))).c_str());
650  unsigned int nElem1 = aProcessorElement->getElementsByTagName(_toDOMS("RefLayer"))->getLength();
652  DOMElement* aRefLayerElement = 0;
653  for(uint ii=0;ii<nElem1;++ii){
654  aNode = aProcessorElement->getElementsByTagName(_toDOMS("RefLayer"))->item(ii);
655  aRefLayerElement = static_cast<DOMElement *>(aNode);
656  unsigned int iRefLayer = std::atoi(_toString(aRefLayerElement->getAttribute(_toDOMS("iRefLayer"))).c_str());
657  int iPhi = std::atoi(_toString(aRefLayerElement->getAttribute(_toDOMS("iGlobalPhiStart"))).c_str());
658  OMTFConfiguration::processorPhiVsRefLayer[iProcessor][iRefLayer] = iPhi;
659  }
661  nElem1 = aProcessorElement->getElementsByTagName(_toDOMS("RefHit"))->getLength();
663  DOMElement* aRefHitElement = 0;
664  std::vector<int> starts;
665  starts.assign(OMTFConfiguration::nRefLayers,-1);
666  for(uint ii=0;ii<nElem1;++ii){
667  aNode = aProcessorElement->getElementsByTagName(_toDOMS("RefHit"))->item(ii);
668  aRefHitElement = static_cast<DOMElement *>(aNode);
669  unsigned int iRefHit = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iRefHit"))).c_str());
670  int iPhiMin = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iPhiMin"))).c_str());
671  int iPhiMax = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iPhiMax"))).c_str());
672  unsigned int iInput = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iInput"))).c_str());
673  unsigned int iRegion = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iRegion"))).c_str());
674  unsigned int iRefLayer = std::atoi(_toString(aRefHitElement->getAttribute(_toDOMS("iRefLayer"))).c_str());
676  OMTFConfiguration::regionPhisVsRefLayerVsProcessor[iProcessor][iRefLayer][iRegion] = std::pair<int,int>(iPhiMin,iPhiMax);
677  OMTFConfiguration::refHitsDefs[iProcessor][iRefHit] = RefHitDef(iInput,iPhiMin,iPhiMax,iRegion,iRefLayer);
678  }
680  unsigned int nElem2 = aProcessorElement->getElementsByTagName(_toDOMS("LogicRegion"))->getLength();
682  DOMElement* aRegionElement = 0;
683  for(uint ii=0;ii<nElem2;++ii){
684  aNode = aProcessorElement->getElementsByTagName(_toDOMS("LogicRegion"))->item(ii);
685  aRegionElement = static_cast<DOMElement *>(aNode);
686  unsigned int iRegion = std::atoi(_toString(aRegionElement->getAttribute(_toDOMS("iRegion"))).c_str());
687  unsigned int nElem3 = aRegionElement->getElementsByTagName(_toDOMS("Layer"))->getLength();
689  DOMElement* aLayerElement = 0;
690  for(uint iii=0;iii<nElem3;++iii){
691  aNode = aRegionElement->getElementsByTagName(_toDOMS("Layer"))->item(iii);
692  aLayerElement = static_cast<DOMElement *>(aNode);
693  unsigned int iLayer = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("iLayer"))).c_str());
694  unsigned int iFirstInput = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("iFirstInput"))).c_str());
695  unsigned int nInputs = std::atoi(_toString(aLayerElement->getAttribute(_toDOMS("nInputs"))).c_str());
696  OMTFConfiguration::connections[iProcessor][iRegion][iLayer] = std::pair<unsigned int, unsigned int>(iFirstInput,nInputs);
697  }
698  }
699  }
700  delete doc;
701 }
704 
type
Definition: HCALResponse.h:21
static unsigned int nLayers
int i
Definition: DBlmapReader.cc:9
void setLayerMap(const std::vector< LayerMapNode > &aVector)
Connections definitions.
GoldenPattern * buildGP(xercesc::DOMElement *aGPElement, unsigned int index=0)
static unsigned int nInputs
void setConnectedSectorsEnd(const std::vector< int > &aVector)
xercesc::DOMDocument * doc
unsigned int hwNumber
short layer number used within OMTF emulator
static std::vector< unsigned int > endcap20DegMax
static vector3D_A connections
std::vector< int > vector1D
Definition: GoldenPattern.h:49
void setRefLayerMap(const std::vector< RefLayerMapNode > &aVector)
assert(m_qm.get())
std::string _toString(const XMLCh *toTranscode)
static float minPdfVal
unsigned int logicNumber
logic numer of the layer
std::vector< std::vector< int > > readEvent(unsigned int iEvent=0, unsigned int iProcessor=0, bool readEta=false)
static std::vector< unsigned int > endcap10DegMin
static std::vector< unsigned int > barrelMax
static unsigned int nProcessors
int ii
Definition: cuy.py:588
std::vector< int > vector1D
Definition: OMTFinput.h:14
static unsigned int nLogicRegions
static std::map< int, int > logicToLogic
std::vector< vector1D > vector2D
Definition: OMTFinput.h:15
static std::string const input
Definition: EdmProvDump.cc:44
std::string patternsFile
static unsigned int nPdfAddrBits
int read(std::istream &stream)
Definition: LUT.cc:35
int iEvent
Definition: GenABIO.cc:230
std::vector< vector1D > vector2D
Definition: GoldenPattern.h:50
std::vector< vector2D > vector3D
Definition: GoldenPattern.h:51
void setPdf(const vector3D &aPdf)
Definition: GoldenPattern.h:67
void setGeneralParams(const std::vector< int > &paramsVec)
static std::vector< unsigned int > barrelMin
static unsigned int nTestRefHits
XMLCh * transcode(const T &fInput)
static unsigned int nHitsPerLayer
static std::vector< std::vector< int > > processorPhiVsRefLayer
std::vector< std::pair< unsigned int, unsigned int > > vector1D_A
Map of connections.
static unsigned int nPhiBins
tuple lut
Definition: lumiPlot.py:244
void readLUT(l1t::LUT *lut, const std::string &type)
void readConfig(const std::string fName)
bool bendingLayer
Is this a bending layers?
std::string eventsFile
static std::vector< int > refToLogicNumber
static unsigned int nPhiBits
void setConnectedSectorsStart(const std::vector< int > &aVector)
xercesc::XercesDOMParser * parser
Definition: LUT.h:29
static std::map< int, int > hwToLogicLayer
unsigned int refLayer
Reference layer number.
void setGlobalPhiStartMap(const std::vector< int > &aVector)
static unsigned int nRefLayers
void setLayerInputMap(const std::vector< LayerInputNode > &aVector)
static std::map< int, int > logicToHwLayer
std::vector< GoldenPattern * > aGPs
Cache with GPs read.
std::vector< GoldenPattern * > readPatterns()
void setRefHitMap(const std::vector< RefHitNode > &aVector)
static unsigned int nRefHits
static std::set< int > bendingLayers
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void setMeanDistPhi(const vector2D &aMeanDistPhi)
Definition: GoldenPattern.h:61
unsigned int logicNumber
Corresponding logical layer number.
XMLCh * _toDOMS(std::string temp)
void setFwVersion(unsigned fwVersion)
static unsigned int nGoldenPatterns
std::vector< vector1D_A > vector2D_A
std::string configFile
static std::vector< unsigned int > endcap10DegMax
static std::vector< std::vector< std::vector< std::pair< int, int > > > > regionPhisVsRefLayerVsProcessor
static std::vector< unsigned int > endcap20DegMin
static unsigned int nPdfValBits
static std::vector< std::vector< RefHitDef > > refHitsDefs