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"
37 XMLCh *buff = XMLString::transcode(
temp.c_str());
61 const std::vector<std::string> &
types) {
65 for (
unsigned int i = 0;
i < luts.size();
i++) {
69 std::stringstream strStream;
73 if (
type ==
"iCharge")
79 if (
type ==
"meanDistPhi") {
89 strStream <<
"#<header> V1 " << totalInWidth <<
" " << outWidth <<
" </header> " << std::endl;
93 for (
auto it :
aGPs) {
94 if (
type ==
"iCharge")
95 out = it->key().theCharge == -1 ? 0 : 1;
97 out = it->key().theEtaCode;
99 out = it->key().thePtCode;
100 if (
type ==
"meanDistPhi") {
101 for (
unsigned int iLayer = 0; iLayer < (unsigned)aConfig.
nLayers(); ++iLayer) {
102 for (
unsigned int iRefLayer = 0; iRefLayer < (unsigned)aConfig.
nRefLayers(); ++iRefLayer) {
103 out = (1 << (outWidth - 1)) + it->meanDistPhiValue(iLayer, iRefLayer);
104 strStream <<
in <<
" " <<
out << std::endl;
110 for (
unsigned int iLayer = 0; iLayer < (unsigned)aConfig.
nLayers(); ++iLayer) {
111 for (
unsigned int iRefLayer = 0; iRefLayer < (unsigned)aConfig.
nRefLayers(); ++iRefLayer) {
112 for (
unsigned int iPdf = 0; iPdf < exp2(aConfig.
nPdfAddrBits()); ++iPdf) {
113 out = it->pdfValue(iLayer, iRefLayer, iPdf);
114 strStream <<
in <<
" " <<
out << std::endl;
120 if (
type !=
"meanDistPhi" &&
type !=
"pdf") {
121 strStream <<
in <<
" " <<
out << std::endl;
127 lut->
read(strStream);
137 XMLPlatformUtils::Initialize();
140 parser.setValidationScheme(XercesDOMParser::Val_Auto);
141 parser.setDoNamespaces(
false);
144 xercesc::DOMDocument *
doc =
parser.getDocument();
147 XMLCh *xmlOmtf =
_toDOMS(
"OMTF");
148 XMLCh *xmlVersion =
_toDOMS(
"version");
149 DOMNode *aNode =
doc->getElementsByTagName(xmlOmtf)->item(0);
150 DOMElement *aOMTFElement = static_cast<DOMElement *>(aNode);
152 version = std::stoul(
_toString(aOMTFElement->getAttribute(xmlVersion)),
nullptr, 16);
155 parser.resetDocumentPool();
157 XMLPlatformUtils::Terminate();
166 XMLPlatformUtils::Initialize();
173 parser.setValidationScheme(XercesDOMParser::Val_Auto);
174 parser.setDoNamespaces(
false);
177 xercesc::DOMDocument *
doc =
parser.getDocument();
180 unsigned int nElem =
doc->getElementsByTagName(xmlGP)->getLength();
183 edm::LogError(
"critical") <<
"No GoldenPattern items: GP found" << std::endl;
187 DOMNode *aNode =
nullptr;
188 DOMElement *aGPElement =
nullptr;
189 unsigned int iGPNumber = 0;
191 for (
unsigned int iItem = 0; iItem < nElem; ++iItem) {
192 aNode =
doc->getElementsByTagName(xmlGP)->item(iItem);
193 aGPElement = static_cast<DOMElement *>(aNode);
195 std::unique_ptr<GoldenPattern> aGP;
198 if (aGPElement->getAttributeNode(xmliPt[
index - 1])) {
205 aGP =
buildGP(aGPElement, aConfig);
217 parser.resetDocumentPool();
225 XMLPlatformUtils::Terminate();
234 unsigned int aGPNumber) {
235 XMLCh *xmliEta =
_toDOMS(
"iEta");
237 std::ostringstream stringStr;
239 stringStr <<
"iPt" <<
index;
241 stringStr.str(
"iPt");
242 XMLCh *xmliPt =
_toDOMS(stringStr.str());
245 stringStr <<
"value" <<
index;
247 stringStr.str(
"value");
248 XMLCh *xmlValue =
_toDOMS(stringStr.str());
250 XMLCh *xmliCharge =
_toDOMS(
"iCharge");
251 XMLCh *xmlLayer =
_toDOMS(
"Layer");
252 XMLCh *xmlRefLayer =
_toDOMS(
"RefLayer");
253 XMLCh *xmlmeanDistPhi =
_toDOMS(
"meanDistPhi");
254 XMLCh *xmlPDF =
_toDOMS(
"PDF");
256 unsigned int iPt = std::atoi(
_toString(aGPElement->getAttribute(xmliPt)).c_str());
257 int iEta = std::atoi(
_toString(aGPElement->getAttribute(xmliEta)).c_str());
258 int iCharge = std::atoi(
_toString(aGPElement->getAttribute(xmliCharge)).c_str());
260 unsigned int nLayers = aGPElement->getElementsByTagName(xmlLayer)->getLength();
263 DOMNode *aNode =
nullptr;
264 DOMElement *aLayerElement =
nullptr;
265 DOMElement *aItemElement =
nullptr;
273 meanDistPhi2D.assign(aConfig.
nLayers(), meanDistPhi1D);
276 pdf3D.assign(aConfig.
nLayers(), pdf2D);
278 Key aKey(
iEta, iPt, iCharge, aGPNumber);
279 auto aGP = std::make_unique<GoldenPattern>(aKey, static_cast<const OMTFConfiguration *>(
nullptr));
280 aGP->setMeanDistPhi(meanDistPhi2D);
286 for (
unsigned int iLayer = 0; iLayer <
nLayers; ++iLayer) {
287 aNode = aGPElement->getElementsByTagName(xmlLayer)->item(iLayer);
288 aLayerElement = static_cast<DOMElement *>(aNode);
290 unsigned int nItems = aLayerElement->getElementsByTagName(xmlRefLayer)->getLength();
293 for (
unsigned int iItem = 0; iItem < nItems; ++iItem) {
294 aNode = aLayerElement->getElementsByTagName(xmlRefLayer)->item(iItem);
295 aItemElement = static_cast<DOMElement *>(aNode);
296 val = std::atoi(
_toString(aItemElement->getAttribute(xmlmeanDistPhi)).c_str());
297 meanDistPhi1D[iItem] =
val;
299 meanDistPhi2D[iLayer] = meanDistPhi1D;
302 nItems = aLayerElement->getElementsByTagName(xmlPDF)->getLength();
304 for (
unsigned int iRefLayer = 0; iRefLayer < (unsigned)aConfig.
nRefLayers(); ++iRefLayer) {
306 for (
unsigned int iPdf = 0; iPdf < exp2(aConfig.
nPdfAddrBits()); ++iPdf) {
307 aNode = aLayerElement->getElementsByTagName(xmlPDF)->item(iRefLayer * exp2(aConfig.
nPdfAddrBits()) + iPdf);
308 aItemElement = static_cast<DOMElement *>(aNode);
309 val = std::atoi(
_toString(aItemElement->getAttribute(xmlValue)).c_str());
312 pdf2D[iRefLayer] = pdf1D;
314 pdf3D[iLayer] = pdf2D;
317 Key aKey(
iEta, iPt, iCharge, aGPNumber);
318 auto aGP = std::make_unique<GoldenPattern>(aKey, static_cast<const OMTFConfiguration *>(
nullptr));
319 aGP->setMeanDistPhi(meanDistPhi2D);
341 XMLPlatformUtils::Initialize();
344 parser.setValidationScheme(XercesDOMParser::Val_Auto);
345 parser.setDoNamespaces(
false);
347 XMLCh *xmlOMTF =
_toDOMS(
"OMTF");
348 XMLCh *xmlversion =
_toDOMS(
"version");
349 XMLCh *xmlGlobalData =
_toDOMS(
"GlobalData");
350 XMLCh *xmlnPdfAddrBits =
_toDOMS(
"nPdfAddrBits");
351 XMLCh *xmlnPdfValBits =
_toDOMS(
"nPdfValBits");
352 XMLCh *xmlnPhiBits =
_toDOMS(
"nPhiBits");
353 XMLCh *xmlnPhiBins =
_toDOMS(
"nPhiBins");
354 XMLCh *xmlnProcessors =
_toDOMS(
"nProcessors");
355 XMLCh *xmlnLogicRegions =
_toDOMS(
"nLogicRegions");
356 XMLCh *xmlnInputs =
_toDOMS(
"nInputs");
357 XMLCh *xmlnLayers =
_toDOMS(
"nLayers");
358 XMLCh *xmlnRefLayers =
_toDOMS(
"nRefLayers");
359 XMLCh *xmliProcessor =
_toDOMS(
"iProcessor");
360 XMLCh *xmlbarrelMin =
_toDOMS(
"barrelMin");
361 XMLCh *xmlbarrelMax =
_toDOMS(
"barrelMax");
362 XMLCh *xmlendcap10DegMin =
_toDOMS(
"endcap10DegMin");
363 XMLCh *xmlendcap10DegMax =
_toDOMS(
"endcap10DegMax");
364 XMLCh *xmlendcap20DegMin =
_toDOMS(
"endcap20DegMin");
365 XMLCh *xmlendcap20DegMax =
_toDOMS(
"endcap20DegMax");
366 XMLCh *xmlLayerMap =
_toDOMS(
"LayerMap");
367 XMLCh *xmlhwNumber =
_toDOMS(
"hwNumber");
368 XMLCh *xmllogicNumber =
_toDOMS(
"logicNumber");
369 XMLCh *xmlbendingLayer =
_toDOMS(
"bendingLayer");
370 XMLCh *xmlconnectedToLayer =
_toDOMS(
"connectedToLayer");
371 XMLCh *xmlRefLayerMap =
_toDOMS(
"RefLayerMap");
372 XMLCh *xmlrefLayer =
_toDOMS(
"refLayer");
373 XMLCh *xmlProcessor =
_toDOMS(
"Processor");
374 XMLCh *xmlRefLayer =
_toDOMS(
"RefLayer");
375 XMLCh *xmliRefLayer =
_toDOMS(
"iRefLayer");
376 XMLCh *xmliGlobalPhiStart =
_toDOMS(
"iGlobalPhiStart");
377 XMLCh *xmlRefHit =
_toDOMS(
"RefHit");
378 XMLCh *xmliRefHit =
_toDOMS(
"iRefHit");
379 XMLCh *xmliPhiMin =
_toDOMS(
"iPhiMin");
380 XMLCh *xmliPhiMax =
_toDOMS(
"iPhiMax");
381 XMLCh *xmliInput =
_toDOMS(
"iInput");
382 XMLCh *xmliRegion =
_toDOMS(
"iRegion");
383 XMLCh *xmlLogicRegion =
_toDOMS(
"LogicRegion");
384 XMLCh *xmlLayer =
_toDOMS(
"Layer");
385 XMLCh *xmliLayer =
_toDOMS(
"iLayer");
386 XMLCh *xmliFirstInput =
_toDOMS(
"iFirstInput");
387 XMLCh *xmlnHitsPerLayer =
_toDOMS(
"nHitsPerLayer");
388 XMLCh *xmlnRefHits =
_toDOMS(
"nRefHits");
389 XMLCh *xmlnTestRefHits =
_toDOMS(
"nTestRefHits");
390 XMLCh *xmlnGoldenPatterns =
_toDOMS(
"nGoldenPatterns");
391 XMLCh *xmlConnectionMap =
_toDOMS(
"ConnectionMap");
393 xercesc::DOMDocument *
doc =
parser.getDocument();
395 unsigned int nElem =
doc->getElementsByTagName(xmlOMTF)->getLength();
400 DOMNode *aNode =
doc->getElementsByTagName(xmlOMTF)->item(0);
401 DOMElement *aOMTFElement = static_cast<DOMElement *>(aNode);
403 unsigned int version = std::stoul(
_toString(aOMTFElement->getAttribute(xmlversion)),
nullptr, 16);
407 nElem = aOMTFElement->getElementsByTagName(xmlGlobalData)->getLength();
409 aNode = aOMTFElement->getElementsByTagName(xmlGlobalData)->item(0);
410 DOMElement *aElement = static_cast<DOMElement *>(aNode);
412 unsigned int nPdfAddrBits = std::atoi(
_toString(aElement->getAttribute(xmlnPdfAddrBits)).c_str());
413 unsigned int nPdfValBits = std::atoi(
_toString(aElement->getAttribute(xmlnPdfValBits)).c_str());
414 unsigned int nHitsPerLayer = std::atoi(
_toString(aElement->getAttribute(xmlnHitsPerLayer)).c_str());
415 unsigned int nPhiBits = std::atoi(
_toString(aElement->getAttribute(xmlnPhiBits)).c_str());
416 unsigned int nPhiBins = std::atoi(
_toString(aElement->getAttribute(xmlnPhiBins)).c_str());
418 unsigned int nRefHits = std::atoi(
_toString(aElement->getAttribute(xmlnRefHits)).c_str());
419 unsigned int nTestRefHits = std::atoi(
_toString(aElement->getAttribute(xmlnTestRefHits)).c_str());
420 unsigned int nProcessors = std::atoi(
_toString(aElement->getAttribute(xmlnProcessors)).c_str());
421 unsigned int nLogicRegions = std::atoi(
_toString(aElement->getAttribute(xmlnLogicRegions)).c_str());
422 unsigned int nInputs = std::atoi(
_toString(aElement->getAttribute(xmlnInputs)).c_str());
423 unsigned int nLayers = std::atoi(
_toString(aElement->getAttribute(xmlnLayers)).c_str());
424 unsigned int nRefLayers = std::atoi(
_toString(aElement->getAttribute(xmlnRefLayers)).c_str());
425 unsigned int nGoldenPatterns = std::atoi(
_toString(aElement->getAttribute(xmlnGoldenPatterns)).c_str());
445 std::vector<int> sectorsStart(3 * nProcessors), sectorsEnd(3 * nProcessors);
446 nElem = aOMTFElement->getElementsByTagName(xmlConnectionMap)->getLength();
447 DOMElement *aConnectionElement =
nullptr;
448 for (
unsigned int i = 0;
i < nElem; ++
i) {
449 aNode = aOMTFElement->getElementsByTagName(xmlConnectionMap)->item(
i);
450 aConnectionElement = static_cast<DOMElement *>(aNode);
451 unsigned int iProcessor = std::atoi(
_toString(aConnectionElement->getAttribute(xmliProcessor)).c_str());
452 unsigned int barrelMin = std::atoi(
_toString(aConnectionElement->getAttribute(xmlbarrelMin)).c_str());
453 unsigned int barrelMax = std::atoi(
_toString(aConnectionElement->getAttribute(xmlbarrelMax)).c_str());
454 unsigned int endcap10DegMin = std::atoi(
_toString(aConnectionElement->getAttribute(xmlendcap10DegMin)).c_str());
455 unsigned int endcap10DegMax = std::atoi(
_toString(aConnectionElement->getAttribute(xmlendcap10DegMax)).c_str());
456 unsigned int endcap20DegMin = std::atoi(
_toString(aConnectionElement->getAttribute(xmlendcap20DegMin)).c_str());
457 unsigned int endcap20DegMax = std::atoi(
_toString(aConnectionElement->getAttribute(xmlendcap20DegMax)).c_str());
459 sectorsStart[iProcessor] = barrelMin;
460 sectorsStart[iProcessor + nProcessors] = endcap10DegMin;
461 sectorsStart[iProcessor + 2 * nProcessors] = endcap20DegMin;
463 sectorsEnd[iProcessor] = barrelMax;
464 sectorsEnd[iProcessor + nProcessors] = endcap10DegMax;
465 sectorsEnd[iProcessor + 2 * nProcessors] = endcap20DegMax;
471 std::vector<L1TMuonOverlapParams::LayerMapNode> aLayerMapVec;
474 nElem = aOMTFElement->getElementsByTagName(xmlLayerMap)->getLength();
475 DOMElement *aLayerElement =
nullptr;
476 for (
unsigned int i = 0;
i < nElem; ++
i) {
477 aNode = aOMTFElement->getElementsByTagName(xmlLayerMap)->item(
i);
478 aLayerElement = static_cast<DOMElement *>(aNode);
479 unsigned int hwNumber = std::atoi(
_toString(aLayerElement->getAttribute(xmlhwNumber)).c_str());
480 unsigned int logicNumber = std::atoi(
_toString(aLayerElement->getAttribute(xmllogicNumber)).c_str());
481 unsigned int isBendingLayer = std::atoi(
_toString(aLayerElement->getAttribute(xmlbendingLayer)).c_str());
482 unsigned int iConnectedLayer = std::atoi(
_toString(aLayerElement->getAttribute(xmlconnectedToLayer)).c_str());
487 aLayerMapVec.push_back(aLayerMapNode);
492 std::vector<L1TMuonOverlapParams::RefLayerMapNode> aRefLayerMapVec;
495 nElem = aOMTFElement->getElementsByTagName(xmlRefLayerMap)->getLength();
496 DOMElement *aRefLayerElement =
nullptr;
497 for (
unsigned int i = 0;
i < nElem; ++
i) {
498 aNode = aOMTFElement->getElementsByTagName(xmlRefLayerMap)->item(
i);
499 aRefLayerElement = static_cast<DOMElement *>(aNode);
500 unsigned int refLayer = std::atoi(
_toString(aRefLayerElement->getAttribute(xmlrefLayer)).c_str());
501 unsigned int logicNumber = std::atoi(
_toString(aRefLayerElement->getAttribute(xmllogicNumber)).c_str());
504 aRefLayerMapVec.push_back(aRefLayerNode);
508 std::vector<int> aGlobalPhiStartVec(nProcessors * nRefLayers);
510 std::vector<L1TMuonOverlapParams::RefHitNode> aRefHitMapVec(nProcessors * nRefHits);
513 std::vector<L1TMuonOverlapParams::LayerInputNode> aLayerInputMapVec(nProcessors * nLogicRegions *
nLayers);
516 nElem = aOMTFElement->getElementsByTagName(xmlProcessor)->getLength();
517 assert(nElem == nProcessors);
518 DOMElement *aProcessorElement =
nullptr;
519 for (
unsigned int i = 0;
i < nElem; ++
i) {
520 aNode = aOMTFElement->getElementsByTagName(xmlProcessor)->item(
i);
521 aProcessorElement = static_cast<DOMElement *>(aNode);
522 unsigned int iProcessor = std::atoi(
_toString(aProcessorElement->getAttribute(xmliProcessor)).c_str());
523 unsigned int nElem1 = aProcessorElement->getElementsByTagName(xmlRefLayer)->getLength();
524 assert(nElem1 == nRefLayers);
525 DOMElement *aRefLayerElement =
nullptr;
526 for (
unsigned int ii = 0;
ii < nElem1; ++
ii) {
527 aNode = aProcessorElement->getElementsByTagName(xmlRefLayer)->item(
ii);
528 aRefLayerElement = static_cast<DOMElement *>(aNode);
529 unsigned int iRefLayer = std::atoi(
_toString(aRefLayerElement->getAttribute(xmliRefLayer)).c_str());
530 int iPhi = std::atoi(
_toString(aRefLayerElement->getAttribute(xmliGlobalPhiStart)).c_str());
531 aGlobalPhiStartVec[iRefLayer + iProcessor * nRefLayers] = iPhi;
534 nElem1 = aProcessorElement->getElementsByTagName(xmlRefHit)->getLength();
535 assert((iProcessor == 0 && nElem1 == nRefHits) || (iProcessor != 0 && nElem1 == 0));
536 DOMElement *aRefHitElement =
nullptr;
537 for (
unsigned int ii = 0;
ii < nElem1; ++
ii) {
538 aNode = aProcessorElement->getElementsByTagName(xmlRefHit)->item(
ii);
539 aRefHitElement = static_cast<DOMElement *>(aNode);
540 unsigned int iRefHit = std::atoi(
_toString(aRefHitElement->getAttribute(xmliRefHit)).c_str());
541 int iPhiMin = std::atoi(
_toString(aRefHitElement->getAttribute(xmliPhiMin)).c_str());
542 int iPhiMax = std::atoi(
_toString(aRefHitElement->getAttribute(xmliPhiMax)).c_str());
543 unsigned int iInput = std::atoi(
_toString(aRefHitElement->getAttribute(xmliInput)).c_str());
544 unsigned int iRegion = std::atoi(
_toString(aRefHitElement->getAttribute(xmliRegion)).c_str());
545 unsigned int iRefLayer = std::atoi(
_toString(aRefHitElement->getAttribute(xmliRefLayer)).c_str());
550 aRefHitNode.
iInput = iInput;
553 for (
unsigned int iProcessor = 0; iProcessor < nProcessors; iProcessor++)
554 aRefHitMapVec[iRefHit + iProcessor * nRefHits] = aRefHitNode;
557 unsigned int nElem2 = aProcessorElement->getElementsByTagName(xmlLogicRegion)->getLength();
558 assert((iProcessor == 0 && nElem2 == nLogicRegions) || (iProcessor != 0 && nElem2 == 0));
559 DOMElement *aRegionElement =
nullptr;
560 for (
unsigned int ii = 0;
ii < nElem2; ++
ii) {
561 aNode = aProcessorElement->getElementsByTagName(xmlLogicRegion)->item(
ii);
562 aRegionElement = static_cast<DOMElement *>(aNode);
563 unsigned int iRegion = std::atoi(
_toString(aRegionElement->getAttribute(xmliRegion)).c_str());
564 unsigned int nElem3 = aRegionElement->getElementsByTagName(xmlLayer)->getLength();
566 DOMElement *aLayerElement =
nullptr;
567 for (
unsigned int iii = 0; iii < nElem3; ++iii) {
568 aNode = aRegionElement->getElementsByTagName(xmlLayer)->item(iii);
569 aLayerElement = static_cast<DOMElement *>(aNode);
570 unsigned int iLayer = std::atoi(
_toString(aLayerElement->getAttribute(xmliLayer)).c_str());
571 unsigned int iFirstInput = std::atoi(
_toString(aLayerElement->getAttribute(xmliFirstInput)).c_str());
572 unsigned int nInputs = std::atoi(
_toString(aLayerElement->getAttribute(xmlnInputs)).c_str());
573 aLayerInputNode.
iLayer = iLayer;
575 aLayerInputNode.
nInputs = nInputs;
576 for (
unsigned int iProcessor = 0; iProcessor < nProcessors; ++iProcessor)
577 aLayerInputMapVec[iLayer + iRegion *
nLayers + iProcessor *
nLayers * nLogicRegions] = aLayerInputNode;
587 parser.resetDocumentPool();
635 XMLPlatformUtils::Terminate();