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
63 std::stringstream strStream;
67 if(type==
"iCharge") outWidth = 1;
68 if(type==
"iEta") outWidth = 2;
69 if(type==
"iPt") outWidth = 9;
70 if(type==
"meanDistPhi"){
80 strStream <<
"#<header> V1 "<<totalInWidth<<
" "<<outWidth<<
" </header> "<<std::endl;
88 if(type==
"iCharge") out = it->key().theCharge==-1 ? 0:1;
89 if(type==
"iEta") out = it->key().theEtaCode;
90 if(type==
"iPt") out = it->key().thePtCode;
91 if(type==
"meanDistPhi"){
92 for(
unsigned int iLayer = 0;iLayer<(unsigned) aConfig.
nLayers();++iLayer){
93 for(
unsigned int iRefLayer=0;iRefLayer<(unsigned) aConfig.
nRefLayers();++iRefLayer){
94 out = (1<<(outWidth-1)) + it->meanDistPhiValue(iLayer,iRefLayer);
95 strStream<<in<<
" "<<out<<std::endl;
101 for(
unsigned int iLayer = 0;iLayer<(unsigned)aConfig.
nLayers();++iLayer){
102 for(
unsigned int iRefLayer=0;iRefLayer<(unsigned)aConfig.
nRefLayers();++iRefLayer){
103 for(
unsigned int iPdf=0;iPdf<exp2(aConfig.
nPdfAddrBits());++iPdf){
104 out = it->pdfValue(iLayer,iRefLayer,iPdf);
105 strStream<<in<<
" "<<out<<std::endl;
111 if(type!=
"meanDistPhi" && type!=
"pdf"){
112 strStream<<in<<
" "<<out<<std::endl;
118 lut->
read(strStream);
127 XMLPlatformUtils::Initialize();
130 parser.setValidationScheme(XercesDOMParser::Val_Auto);
131 parser.setDoNamespaces(
false);
134 xercesc::DOMDocument* doc = parser.getDocument();
137 XMLCh *xmlOmtf=
_toDOMS(
"OMTF");
138 XMLCh *xmlVersion=
_toDOMS(
"version");
139 DOMNode *aNode = doc->getElementsByTagName(xmlOmtf)->item(0);
140 DOMElement* aOMTFElement =
static_cast<DOMElement *
>(aNode);
142 version = std::stoul(
_toString(aOMTFElement->getAttribute(xmlVersion)),
nullptr, 16);
145 parser.resetDocumentPool();
147 XMLPlatformUtils::Terminate();
157 XMLPlatformUtils::Initialize();
164 parser.setValidationScheme(XercesDOMParser::Val_Auto);
165 parser.setDoNamespaces(
false);
169 xercesc::DOMDocument* doc = parser.getDocument();
172 unsigned int nElem = doc->getElementsByTagName(xmlGP)->getLength();
175 edm::LogError(
"critical")<<
"No GoldenPattern items: GP found"<<std::endl;
180 DOMElement* aGPElement = 0;
181 unsigned int iGPNumber=0;
183 for(
unsigned int iItem=0;iItem<nElem;++iItem){
184 aNode = doc->getElementsByTagName(xmlGP)->item(iItem);
185 aGPElement =
static_cast<DOMElement *
>(aNode);
190 if(aGPElement->getAttributeNode(xmliPt[
index-1])) {
198 aGP =
buildGP(aGPElement, aConfig);
210 parser.resetDocumentPool();
219 XMLPlatformUtils::Terminate();
228 unsigned int aGPNumber){
231 XMLCh *xmliEta=
_toDOMS(
"iEta");
233 std::ostringstream stringStr;
234 if (index>0) stringStr<<
"iPt"<<
index;
235 else stringStr.str(
"iPt");
236 XMLCh *xmliPt=
_toDOMS(stringStr.str().c_str());
238 if (index>0) stringStr<<
"value"<<
index;
239 else stringStr.str(
"value");
240 XMLCh *xmlValue=
_toDOMS(stringStr.str().c_str());
242 XMLCh *xmliCharge=
_toDOMS(
"iCharge");
243 XMLCh *xmlLayer=
_toDOMS(
"Layer");
244 XMLCh *xmlRefLayer=
_toDOMS(
"RefLayer");
245 XMLCh *xmlmeanDistPhi=
_toDOMS(
"meanDistPhi");
248 unsigned int iPt = std::atoi(
_toString(aGPElement->getAttribute(xmliPt)).c_str());
249 int iEta = std::atoi(
_toString(aGPElement->getAttribute(xmliEta)).c_str());
250 int iCharge = std::atoi(
_toString(aGPElement->getAttribute(xmliCharge)).c_str());
252 unsigned int nLayers = aGPElement->getElementsByTagName(xmlLayer)->getLength();
256 DOMElement* aLayerElement = 0;
257 DOMElement* aItemElement = 0;
265 meanDistPhi2D.assign(aConfig.
nLayers(),meanDistPhi1D);
268 pdf3D.assign(aConfig.
nLayers(),pdf2D);
270 Key aKey(iEta,iPt,iCharge, aGPNumber);
278 for(
unsigned int iLayer=0;iLayer<nLayers;++iLayer){
279 aNode = aGPElement->getElementsByTagName(xmlLayer)->item(iLayer);
280 aLayerElement =
static_cast<DOMElement *
>(aNode);
282 unsigned int nItems = aLayerElement->getElementsByTagName(xmlRefLayer)->getLength();
285 for(
unsigned int iItem=0;iItem<nItems;++iItem){
286 aNode = aLayerElement->getElementsByTagName(xmlRefLayer)->item(iItem);
287 aItemElement =
static_cast<DOMElement *
>(aNode);
288 val = std::atoi(
_toString(aItemElement->getAttribute(xmlmeanDistPhi)).c_str());
289 meanDistPhi1D[iItem] = val;
291 meanDistPhi2D[iLayer] = meanDistPhi1D;
294 nItems = aLayerElement->getElementsByTagName(xmlPDF)->getLength();
296 for(
unsigned int iRefLayer=0;iRefLayer<(unsigned) aConfig.
nRefLayers();++iRefLayer){
298 for(
unsigned int iPdf=0;iPdf<exp2(aConfig.
nPdfAddrBits());++iPdf){
299 aNode = aLayerElement->getElementsByTagName(xmlPDF)->item(iRefLayer*exp2(aConfig.
nPdfAddrBits())+iPdf);
300 aItemElement =
static_cast<DOMElement *
>(aNode);
301 val = std::atoi(
_toString(aItemElement->getAttribute(xmlValue)).c_str());
304 pdf2D[iRefLayer] = pdf1D;
306 pdf3D[iLayer] = pdf2D;
309 Key aKey(iEta,iPt,iCharge, aGPNumber);
328 unsigned int iProcessor,
338 XMLPlatformUtils::Initialize();
341 parser.setValidationScheme(XercesDOMParser::Val_Auto);
342 parser.setDoNamespaces(
false);
344 XMLCh *xmlOMTF=
_toDOMS(
"OMTF");
345 XMLCh *xmlversion=
_toDOMS(
"version");
346 XMLCh *xmlGlobalData=
_toDOMS(
"GlobalData");
347 XMLCh *xmlnPdfAddrBits=
_toDOMS(
"nPdfAddrBits");
348 XMLCh *xmlnPdfValBits=
_toDOMS(
"nPdfValBits");
349 XMLCh *xmlnPhiBits=
_toDOMS(
"nPhiBits");
350 XMLCh *xmlnPhiBins=
_toDOMS(
"nPhiBins");
351 XMLCh *xmlnProcessors =
_toDOMS(
"nProcessors");
352 XMLCh *xmlnLogicRegions =
_toDOMS(
"nLogicRegions");
353 XMLCh *xmlnInputs=
_toDOMS(
"nInputs");
354 XMLCh *xmlnLayers=
_toDOMS(
"nLayers");
355 XMLCh *xmlnRefLayers=
_toDOMS(
"nRefLayers");
356 XMLCh *xmliProcessor=
_toDOMS(
"iProcessor");
357 XMLCh *xmlbarrelMin=
_toDOMS(
"barrelMin");
358 XMLCh *xmlbarrelMax=
_toDOMS(
"barrelMax");
359 XMLCh *xmlendcap10DegMin=
_toDOMS(
"endcap10DegMin");
360 XMLCh *xmlendcap10DegMax=
_toDOMS(
"endcap10DegMax");
361 XMLCh *xmlendcap20DegMin=
_toDOMS(
"endcap20DegMin");
362 XMLCh *xmlendcap20DegMax=
_toDOMS(
"endcap20DegMax");
363 XMLCh *xmlLayerMap =
_toDOMS(
"LayerMap");
364 XMLCh *xmlhwNumber =
_toDOMS(
"hwNumber");
365 XMLCh *xmllogicNumber =
_toDOMS(
"logicNumber");
366 XMLCh *xmlbendingLayer =
_toDOMS(
"bendingLayer");
367 XMLCh *xmlconnectedToLayer =
_toDOMS(
"connectedToLayer");
368 XMLCh *xmlRefLayerMap =
_toDOMS(
"RefLayerMap");
369 XMLCh *xmlrefLayer =
_toDOMS(
"refLayer");
370 XMLCh *xmlProcessor =
_toDOMS(
"Processor");
371 XMLCh *xmlRefLayer =
_toDOMS(
"RefLayer");
372 XMLCh *xmliRefLayer =
_toDOMS(
"iRefLayer");
373 XMLCh *xmliGlobalPhiStart =
_toDOMS(
"iGlobalPhiStart");
374 XMLCh *xmlRefHit =
_toDOMS(
"RefHit");
375 XMLCh *xmliRefHit =
_toDOMS(
"iRefHit");
376 XMLCh *xmliPhiMin =
_toDOMS(
"iPhiMin");
377 XMLCh *xmliPhiMax =
_toDOMS(
"iPhiMax");
378 XMLCh *xmliInput =
_toDOMS(
"iInput");
379 XMLCh *xmliRegion =
_toDOMS(
"iRegion");
380 XMLCh *xmlLogicRegion =
_toDOMS(
"LogicRegion");
381 XMLCh *xmlLayer =
_toDOMS(
"Layer");
382 XMLCh *xmliLayer =
_toDOMS(
"iLayer");
383 XMLCh *xmliFirstInput =
_toDOMS(
"iFirstInput");
384 XMLCh *xmlnHitsPerLayer =
_toDOMS(
"nHitsPerLayer");
385 XMLCh *xmlnRefHits =
_toDOMS(
"nRefHits");
386 XMLCh *xmlnTestRefHits =
_toDOMS(
"nTestRefHits");
387 XMLCh *xmlnGoldenPatterns =
_toDOMS(
"nGoldenPatterns");
388 XMLCh *xmlConnectionMap =
_toDOMS(
"ConnectionMap");
390 xercesc::DOMDocument* doc = parser.getDocument();
392 unsigned int nElem = doc->getElementsByTagName(xmlOMTF)->getLength();
397 DOMNode *aNode = doc->getElementsByTagName(xmlOMTF)->item(0);
398 DOMElement* aOMTFElement =
static_cast<DOMElement *
>(aNode);
400 unsigned int version = std::stoul(
_toString(aOMTFElement->getAttribute(xmlversion)),
nullptr, 16);
404 nElem = aOMTFElement->getElementsByTagName(xmlGlobalData)->getLength();
406 aNode = aOMTFElement->getElementsByTagName(xmlGlobalData)->item(0);
407 DOMElement* aElement =
static_cast<DOMElement *
>(aNode);
409 unsigned int nPdfAddrBits = std::atoi(
_toString(aElement->getAttribute(xmlnPdfAddrBits)).c_str());
410 unsigned int nPdfValBits = std::atoi(
_toString(aElement->getAttribute(xmlnPdfValBits)).c_str());
411 unsigned int nHitsPerLayer = std::atoi(
_toString(aElement->getAttribute(xmlnHitsPerLayer)).c_str());
412 unsigned int nPhiBits = std::atoi(
_toString(aElement->getAttribute(xmlnPhiBits)).c_str());
413 unsigned int nPhiBins = std::atoi(
_toString(aElement->getAttribute(xmlnPhiBins)).c_str());
415 unsigned int nRefHits = std::atoi(
_toString(aElement->getAttribute(xmlnRefHits)).c_str());
416 unsigned int nTestRefHits = std::atoi(
_toString(aElement->getAttribute(xmlnTestRefHits)).c_str());
417 unsigned int nProcessors = std::atoi(
_toString(aElement->getAttribute(xmlnProcessors)).c_str());
418 unsigned int nLogicRegions = std::atoi(
_toString(aElement->getAttribute(xmlnLogicRegions)).c_str());
419 unsigned int nInputs = std::atoi(
_toString(aElement->getAttribute(xmlnInputs)).c_str());
420 unsigned int nLayers = std::atoi(
_toString(aElement->getAttribute(xmlnLayers)).c_str());
421 unsigned int nRefLayers = std::atoi(
_toString(aElement->getAttribute(xmlnRefLayers)).c_str());
422 unsigned int nGoldenPatterns = std::atoi(
_toString(aElement->getAttribute(xmlnGoldenPatterns)).c_str());
442 std::vector<int> sectorsStart(3*nProcessors), sectorsEnd(3*nProcessors);
443 nElem = aOMTFElement->getElementsByTagName(xmlConnectionMap)->getLength();
444 DOMElement* aConnectionElement = 0;
445 for(
unsigned int i=0;
i<nElem;++
i){
446 aNode = aOMTFElement->getElementsByTagName(xmlConnectionMap)->item(
i);
447 aConnectionElement =
static_cast<DOMElement *
>(aNode);
448 unsigned int iProcessor = std::atoi(
_toString(aConnectionElement->getAttribute(xmliProcessor)).c_str());
449 unsigned int barrelMin = std::atoi(
_toString(aConnectionElement->getAttribute(xmlbarrelMin)).c_str());
450 unsigned int barrelMax = std::atoi(
_toString(aConnectionElement->getAttribute(xmlbarrelMax)).c_str());
451 unsigned int endcap10DegMin = std::atoi(
_toString(aConnectionElement->getAttribute(xmlendcap10DegMin)).c_str());
452 unsigned int endcap10DegMax = std::atoi(
_toString(aConnectionElement->getAttribute(xmlendcap10DegMax)).c_str());
453 unsigned int endcap20DegMin = std::atoi(
_toString(aConnectionElement->getAttribute(xmlendcap20DegMin)).c_str());
454 unsigned int endcap20DegMax = std::atoi(
_toString(aConnectionElement->getAttribute(xmlendcap20DegMax)).c_str());
456 sectorsStart[iProcessor] = barrelMin;
457 sectorsStart[iProcessor + nProcessors] = endcap10DegMin;
458 sectorsStart[iProcessor + 2*nProcessors] = endcap20DegMin;
460 sectorsEnd[iProcessor] = barrelMax;
461 sectorsEnd[iProcessor + nProcessors] = endcap10DegMax;
462 sectorsEnd[iProcessor + 2*nProcessors] = endcap20DegMax;
469 std::vector<L1TMuonOverlapParams::LayerMapNode> aLayerMapVec;
472 nElem = aOMTFElement->getElementsByTagName(xmlLayerMap)->getLength();
473 DOMElement* aLayerElement = 0;
474 for(
unsigned int i=0;
i<nElem;++
i){
475 aNode = aOMTFElement->getElementsByTagName(xmlLayerMap)->item(
i);
476 aLayerElement =
static_cast<DOMElement *
>(aNode);
477 unsigned int hwNumber = std::atoi(
_toString(aLayerElement->getAttribute(xmlhwNumber)).c_str());
478 unsigned int logicNumber = std::atoi(
_toString(aLayerElement->getAttribute(xmllogicNumber)).c_str());
479 unsigned int isBendingLayer = std::atoi(
_toString(aLayerElement->getAttribute(xmlbendingLayer)).c_str());
480 unsigned int iConnectedLayer = std::atoi(
_toString(aLayerElement->getAttribute(xmlconnectedToLayer)).c_str());
485 aLayerMapVec.push_back(aLayerMapNode);
490 std::vector<L1TMuonOverlapParams::RefLayerMapNode> aRefLayerMapVec;
493 nElem = aOMTFElement->getElementsByTagName(xmlRefLayerMap)->getLength();
494 DOMElement* aRefLayerElement = 0;
495 for(
unsigned int i=0;
i<nElem;++
i){
496 aNode = aOMTFElement->getElementsByTagName(xmlRefLayerMap)->item(
i);
497 aRefLayerElement =
static_cast<DOMElement *
>(aNode);
498 unsigned int refLayer = std::atoi(
_toString(aRefLayerElement->getAttribute(xmlrefLayer)).c_str());
499 unsigned int logicNumber = std::atoi(
_toString(aRefLayerElement->getAttribute(xmllogicNumber)).c_str());
502 aRefLayerMapVec.push_back(aRefLayerNode);
506 std::vector<int> aGlobalPhiStartVec(nProcessors*nRefLayers);
508 std::vector<L1TMuonOverlapParams::RefHitNode> aRefHitMapVec(nProcessors*nRefHits);
511 std::vector<L1TMuonOverlapParams::LayerInputNode> aLayerInputMapVec(nProcessors*nLogicRegions*nLayers);
514 nElem = aOMTFElement->getElementsByTagName(xmlProcessor)->getLength();
515 assert(nElem==nProcessors);
516 DOMElement* aProcessorElement = 0;
517 for(
unsigned int i=0;
i<nElem;++
i){
518 aNode = aOMTFElement->getElementsByTagName(xmlProcessor)->item(
i);
519 aProcessorElement =
static_cast<DOMElement *
>(aNode);
520 unsigned int iProcessor = std::atoi(
_toString(aProcessorElement->getAttribute(xmliProcessor)).c_str());
521 unsigned int nElem1 = aProcessorElement->getElementsByTagName(xmlRefLayer)->getLength();
522 assert(nElem1==nRefLayers);
523 DOMElement* aRefLayerElement = 0;
524 for(
unsigned int ii=0;
ii<nElem1;++
ii){
525 aNode = aProcessorElement->getElementsByTagName(xmlRefLayer)->item(
ii);
526 aRefLayerElement =
static_cast<DOMElement *
>(aNode);
527 unsigned int iRefLayer = std::atoi(
_toString(aRefLayerElement->getAttribute(xmliRefLayer)).c_str());
528 int iPhi = std::atoi(
_toString(aRefLayerElement->getAttribute(xmliGlobalPhiStart)).c_str());
529 aGlobalPhiStartVec[iRefLayer + iProcessor*nRefLayers] = iPhi;
532 nElem1 = aProcessorElement->getElementsByTagName(xmlRefHit)->getLength();
533 assert( (iProcessor==0 && nElem1==nRefHits) || (iProcessor!=0 && nElem1==0) );
534 DOMElement* aRefHitElement = 0;
535 for(
unsigned int ii=0;
ii<nElem1;++
ii){
536 aNode = aProcessorElement->getElementsByTagName(xmlRefHit)->item(
ii);
537 aRefHitElement =
static_cast<DOMElement *
>(aNode);
538 unsigned int iRefHit = std::atoi(
_toString(aRefHitElement->getAttribute(xmliRefHit)).c_str());
539 int iPhiMin = std::atoi(
_toString(aRefHitElement->getAttribute(xmliPhiMin)).c_str());
540 int iPhiMax = std::atoi(
_toString(aRefHitElement->getAttribute(xmliPhiMax)).c_str());
541 unsigned int iInput = std::atoi(
_toString(aRefHitElement->getAttribute(xmliInput)).c_str());
542 unsigned int iRegion = std::atoi(
_toString(aRefHitElement->getAttribute(xmliRegion)).c_str());
543 unsigned int iRefLayer = std::atoi(
_toString(aRefHitElement->getAttribute(xmliRefLayer)).c_str());
548 aRefHitNode.
iInput = iInput;
551 for (
unsigned int iProcessor=0; iProcessor<nProcessors; iProcessor++) aRefHitMapVec[iRefHit + iProcessor*nRefHits] = aRefHitNode;
554 unsigned int nElem2 = aProcessorElement->getElementsByTagName(xmlLogicRegion)->getLength();
555 assert( (iProcessor==0 && nElem2==nLogicRegions) || (iProcessor!=0 && nElem2==0) );
556 DOMElement* aRegionElement = 0;
557 for(
unsigned int ii=0;
ii<nElem2;++
ii){
558 aNode = aProcessorElement->getElementsByTagName(xmlLogicRegion)->item(
ii);
559 aRegionElement =
static_cast<DOMElement *
>(aNode);
560 unsigned int iRegion = std::atoi(
_toString(aRegionElement->getAttribute(xmliRegion)).c_str());
561 unsigned int nElem3 = aRegionElement->getElementsByTagName(xmlLayer)->getLength();
563 DOMElement* aLayerElement = 0;
564 for(
unsigned int iii=0;iii<nElem3;++iii){
565 aNode = aRegionElement->getElementsByTagName(xmlLayer)->item(iii);
566 aLayerElement =
static_cast<DOMElement *
>(aNode);
567 unsigned int iLayer = std::atoi(
_toString(aLayerElement->getAttribute(xmliLayer)).c_str());
568 unsigned int iFirstInput = std::atoi(
_toString(aLayerElement->getAttribute(xmliFirstInput)).c_str());
569 unsigned int nInputs = std::atoi(
_toString(aLayerElement->getAttribute(xmlnInputs)).c_str());
570 aLayerInputNode.
iLayer = iLayer;
572 aLayerInputNode.
nInputs = nInputs;
573 for (
unsigned int iProcessor=0; iProcessor<nProcessors; ++iProcessor) aLayerInputMapVec[iLayer + iRegion*nLayers + iProcessor*nLayers*nLogicRegions] = aLayerInputNode;
583 parser.resetDocumentPool();
632 XMLPlatformUtils::Terminate();
GoldenPattern * buildGP(xercesc::DOMElement *aGPElement, const L1TMuonOverlapParams &aConfig, unsigned int index=0, unsigned int aGPNumber=999)
void setLayerMap(const std::vector< LayerMapNode > &aVector)
Connections definitions.
void setConnectedSectorsEnd(const std::vector< int > &aVector)
unsigned int hwNumber
short layer number used within OMTF emulator
std::vector< int > vector1D
void setRefLayerMap(const std::vector< RefLayerMapNode > &aVector)
std::string _toString(const XMLCh *toTranscode)
void readLUT(l1t::LUT *lut, const L1TMuonOverlapParams &aConfig, const std::string &type)
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)
std::vector< GoldenPattern * > readPatterns(const L1TMuonOverlapParams &aConfig)
int read(std::istream &stream)
std::vector< vector1D > vector2D
std::vector< vector2D > vector3D
void setPdf(const vector3D &aPdf)
void setGeneralParams(const std::vector< int > ¶msVec)
XMLCh * transcode(const T &fInput)
void readConfig(const std::string fName)
bool bendingLayer
Is this a bending layers?
unsigned int getPatternsVersion() const
void setConnectedSectorsStart(const std::vector< int > &aVector)
int nPdfAddrBits() const
Access to specific general settings.
unsigned int refLayer
Reference layer number.
void setGlobalPhiStartMap(const std::vector< int > &aVector)
void setLayerInputMap(const std::vector< LayerInputNode > &aVector)
std::vector< GoldenPattern * > aGPs
Cache with GPs read.
void setRefHitMap(const std::vector< RefHitNode > &aVector)
std::vector< std::vector< double > > tmp
void setMeanDistPhi(const vector2D &aMeanDistPhi)
unsigned int logicNumber
Corresponding logical layer number.
unsigned int connectedToLayer
XMLCh * _toDOMS(std::string temp)
void setFwVersion(unsigned fwVersion)