Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:28

0001 #include <iostream>
0002 #include <cmath>
0003 #include <algorithm>
0004 #include <utility>
0005 #include <array>
0006 
0007 #include "L1Trigger/L1TMuonOverlap/interface/XMLConfigReader.h"
0008 #include "L1Trigger/L1TMuonOverlap/interface/GoldenPattern.h"
0009 #include "L1Trigger/L1TMuonOverlap/interface/OMTFinput.h"
0010 
0011 #include "CondFormats/L1TObjects/interface/L1TMuonOverlapParams.h"
0012 
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 
0015 #include "xercesc/framework/StdOutFormatTarget.hpp"
0016 #include "xercesc/framework/LocalFileFormatTarget.hpp"
0017 #include "xercesc/parsers/XercesDOMParser.hpp"
0018 #include "xercesc/dom/DOM.hpp"
0019 #include "xercesc/dom/DOMException.hpp"
0020 #include "xercesc/dom/DOMImplementation.hpp"
0021 #include "xercesc/sax/HandlerBase.hpp"
0022 #include "xercesc/util/XMLString.hpp"
0023 #include "xercesc/util/PlatformUtils.hpp"
0024 #include "xercesc/util/XercesDefs.hpp"
0025 XERCES_CPP_NAMESPACE_USE
0026 
0027 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
0028 //////////////////////////////////
0029 // XMLConfigReader
0030 //////////////////////////////////
0031 inline std::string _toString(XMLCh const *toTranscode) {
0032   std::string tmp(xercesc::XMLString::transcode(toTranscode));
0033   return tmp;
0034 }
0035 
0036 inline XMLCh *_toDOMS(std::string temp) {
0037   XMLCh *buff = XMLString::transcode(temp.c_str());
0038   return buff;
0039 }
0040 ////////////////////////////////////
0041 ////////////////////////////////////
0042 XMLConfigReader::XMLConfigReader() {
0043   //XMLPlatformUtils::Initialize();
0044 
0045   ///Initialise XML parser
0046   //parser = new XercesDOMParser();
0047   //parser->setValidationScheme(XercesDOMParser::Val_Auto);
0048   //parser->setDoNamespaces(false);
0049 
0050   //doc = 0;
0051 }
0052 
0053 XMLConfigReader::~XMLConfigReader() {
0054   //  delete parser;
0055   //XMLPlatformUtils::Terminate();
0056 }
0057 //////////////////////////////////////////////////
0058 //////////////////////////////////////////////////
0059 void XMLConfigReader::readLUTs(std::vector<l1t::LUT *> luts,
0060                                const L1TMuonOverlapParams &aConfig,
0061                                const std::vector<std::string> &types) {
0062   ///Fill payload string
0063   auto const &aGPs = readPatterns(aConfig);
0064 
0065   for (unsigned int i = 0; i < luts.size(); i++) {
0066     l1t::LUT *lut = luts[i];
0067     const std::string &type = types[i];
0068 
0069     std::stringstream strStream;
0070     int totalInWidth = 7;  //Number of bits used to address LUT
0071     int outWidth = 6;      //Number of bits used to store LUT value
0072 
0073     if (type == "iCharge")
0074       outWidth = 1;
0075     if (type == "iEta")
0076       outWidth = 2;
0077     if (type == "iPt")
0078       outWidth = 9;
0079     if (type == "meanDistPhi") {
0080       outWidth = 11;
0081       totalInWidth = 14;
0082     }
0083     if (type == "pdf") {
0084       outWidth = 6;
0085       totalInWidth = 21;
0086     }
0087 
0088     ///Prepare the header
0089     strStream << "#<header> V1 " << totalInWidth << " " << outWidth << " </header> " << std::endl;
0090 
0091     unsigned int in = 0;
0092     int out = 0;
0093     for (const auto &it : aGPs) {
0094       if (type == "iCharge")
0095         out = it->key().theCharge == -1 ? 0 : 1;
0096       if (type == "iEta")
0097         out = it->key().theEtaCode;
0098       if (type == "iPt")
0099         out = it->key().thePtCode;
0100       if (type == "meanDistPhi") {
0101         for (unsigned int iLayer = 0; iLayer < (unsigned)aConfig.nLayers(); ++iLayer) {
0102           for (unsigned int iRefLayer = 0; iRefLayer < (unsigned)aConfig.nRefLayers(); ++iRefLayer) {
0103             out = (1 << (outWidth - 1)) + it->meanDistPhiValue(iLayer, iRefLayer);
0104             strStream << in << " " << out << std::endl;
0105             ++in;
0106           }
0107         }
0108       }
0109       if (type == "pdf") {
0110         for (unsigned int iLayer = 0; iLayer < (unsigned)aConfig.nLayers(); ++iLayer) {
0111           for (unsigned int iRefLayer = 0; iRefLayer < (unsigned)aConfig.nRefLayers(); ++iRefLayer) {
0112             for (unsigned int iPdf = 0; iPdf < exp2(aConfig.nPdfAddrBits()); ++iPdf) {
0113               out = it->pdfValue(iLayer, iRefLayer, iPdf);
0114               strStream << in << " " << out << std::endl;
0115               ++in;
0116             }
0117           }
0118         }
0119       }
0120       if (type != "meanDistPhi" && type != "pdf") {
0121         strStream << in << " " << out << std::endl;
0122         ++in;
0123       }
0124     }
0125 
0126     ///Read the data into LUT
0127     lut->read(strStream);
0128   }
0129 }
0130 //////////////////////////////////////////////////
0131 //////////////////////////////////////////////////
0132 unsigned int XMLConfigReader::getPatternsVersion() const {
0133   if (patternsFile.empty())
0134     return 0;
0135 
0136   unsigned int version = 0;
0137   XMLPlatformUtils::Initialize();
0138   {
0139     XercesDOMParser parser;
0140     parser.setValidationScheme(XercesDOMParser::Val_Auto);
0141     parser.setDoNamespaces(false);
0142 
0143     parser.parse(patternsFile.c_str());
0144     xercesc::DOMDocument *doc = parser.getDocument();
0145     assert(doc);
0146 
0147     XMLCh *xmlOmtf = _toDOMS("OMTF");
0148     XMLCh *xmlVersion = _toDOMS("version");
0149     DOMNode *aNode = doc->getElementsByTagName(xmlOmtf)->item(0);
0150     DOMElement *aOMTFElement = static_cast<DOMElement *>(aNode);
0151 
0152     version = std::stoul(_toString(aOMTFElement->getAttribute(xmlVersion)), nullptr, 16);
0153     XMLString::release(&xmlOmtf);
0154     XMLString::release(&xmlVersion);
0155     parser.resetDocumentPool();
0156   }
0157   XMLPlatformUtils::Terminate();
0158 
0159   return version;
0160 }
0161 //////////////////////////////////////////////////
0162 //////////////////////////////////////////////////
0163 std::vector<std::shared_ptr<GoldenPattern>> XMLConfigReader::readPatterns(const L1TMuonOverlapParams &aConfig) {
0164   aGPs.clear();
0165 
0166   XMLPlatformUtils::Initialize();
0167 
0168   XMLCh *xmlGP = _toDOMS("GP");
0169   std::array<XMLCh *, 4> xmliPt = {{_toDOMS("iPt1"), _toDOMS("iPt2"), _toDOMS("iPt3"), _toDOMS("iPt4")}};
0170 
0171   {
0172     XercesDOMParser parser;
0173     parser.setValidationScheme(XercesDOMParser::Val_Auto);
0174     parser.setDoNamespaces(false);
0175 
0176     parser.parse(patternsFile.c_str());
0177     xercesc::DOMDocument *doc = parser.getDocument();
0178     assert(doc);
0179 
0180     unsigned int nElem = doc->getElementsByTagName(xmlGP)->getLength();
0181     if (nElem < 1) {
0182       edm::LogError("critical") << "Problem parsing XML file " << patternsFile << std::endl;
0183       edm::LogError("critical") << "No GoldenPattern items: GP found" << std::endl;
0184       return aGPs;
0185     }
0186 
0187     DOMNode *aNode = nullptr;
0188     DOMElement *aGPElement = nullptr;
0189     unsigned int iGPNumber = 0;
0190 
0191     for (unsigned int iItem = 0; iItem < nElem; ++iItem) {
0192       aNode = doc->getElementsByTagName(xmlGP)->item(iItem);
0193       aGPElement = static_cast<DOMElement *>(aNode);
0194 
0195       std::unique_ptr<GoldenPattern> aGP;
0196       for (unsigned int index = 1; index < 5; ++index) {
0197         ///Patterns XML format backward compatibility. Can use both packed by 4, or by 1 XML files.
0198         if (aGPElement->getAttributeNode(xmliPt[index - 1])) {
0199           aGP = buildGP(aGPElement, aConfig, index, iGPNumber);
0200           if (aGP) {
0201             aGPs.emplace_back(std::move(aGP));
0202             iGPNumber++;
0203           }
0204         } else {
0205           aGP = buildGP(aGPElement, aConfig);
0206           if (aGP) {
0207             aGPs.emplace_back(std::move(aGP));
0208             iGPNumber++;
0209           }
0210           break;
0211         }
0212       }
0213     }
0214 
0215     // Reset the documents vector pool and release all the associated memory back to the system.
0216     //parser->resetDocumentPool();
0217     parser.resetDocumentPool();
0218   }
0219   XMLString::release(&xmlGP);
0220   XMLString::release(&xmliPt[0]);
0221   XMLString::release(&xmliPt[1]);
0222   XMLString::release(&xmliPt[2]);
0223   XMLString::release(&xmliPt[3]);
0224 
0225   XMLPlatformUtils::Terminate();
0226 
0227   return aGPs;
0228 }
0229 //////////////////////////////////////////////////
0230 //////////////////////////////////////////////////
0231 std::unique_ptr<GoldenPattern> XMLConfigReader::buildGP(DOMElement *aGPElement,
0232                                                         const L1TMuonOverlapParams &aConfig,
0233                                                         unsigned int index,
0234                                                         unsigned int aGPNumber) {
0235   XMLCh *xmliEta = _toDOMS("iEta");
0236   //index 0 means no number at the end
0237   std::ostringstream stringStr;
0238   if (index > 0)
0239     stringStr << "iPt" << index;
0240   else
0241     stringStr.str("iPt");
0242   XMLCh *xmliPt = _toDOMS(stringStr.str());
0243   stringStr.str("");
0244   if (index > 0)
0245     stringStr << "value" << index;
0246   else
0247     stringStr.str("value");
0248   XMLCh *xmlValue = _toDOMS(stringStr.str());
0249 
0250   XMLCh *xmliCharge = _toDOMS("iCharge");
0251   XMLCh *xmlLayer = _toDOMS("Layer");
0252   XMLCh *xmlRefLayer = _toDOMS("RefLayer");
0253   XMLCh *xmlmeanDistPhi = _toDOMS("meanDistPhi");
0254   XMLCh *xmlPDF = _toDOMS("PDF");
0255 
0256   unsigned int iPt = std::atoi(_toString(aGPElement->getAttribute(xmliPt)).c_str());
0257   int iEta = std::atoi(_toString(aGPElement->getAttribute(xmliEta)).c_str());
0258   int iCharge = std::atoi(_toString(aGPElement->getAttribute(xmliCharge)).c_str());
0259   int val = 0;
0260   unsigned int nLayers = aGPElement->getElementsByTagName(xmlLayer)->getLength();
0261   assert(nLayers == (unsigned)aConfig.nLayers());
0262 
0263   DOMNode *aNode = nullptr;
0264   DOMElement *aLayerElement = nullptr;
0265   DOMElement *aItemElement = nullptr;
0266   GoldenPattern::vector2D meanDistPhi2D(nLayers);
0267   GoldenPattern::vector1D pdf1D(exp2(aConfig.nPdfAddrBits()));
0268   GoldenPattern::vector3D pdf3D(aConfig.nLayers());
0269   GoldenPattern::vector2D pdf2D(aConfig.nRefLayers());
0270 
0271   if (iPt == 0) {  ///Build empty GP
0272     GoldenPattern::vector1D meanDistPhi1D(aConfig.nRefLayers());
0273     meanDistPhi2D.assign(aConfig.nLayers(), meanDistPhi1D);
0274     pdf1D.assign(exp2(aConfig.nPdfAddrBits()), 0);
0275     pdf2D.assign(aConfig.nRefLayers(), pdf1D);
0276     pdf3D.assign(aConfig.nLayers(), pdf2D);
0277 
0278     Key aKey(iEta, iPt, iCharge, aGPNumber);
0279     auto aGP = std::make_unique<GoldenPattern>(aKey, static_cast<const OMTFConfiguration *>(nullptr));
0280     aGP->setMeanDistPhi(meanDistPhi2D);
0281     aGP->setPdf(pdf3D);
0282     return aGP;
0283   }
0284 
0285   ///Loop over layers
0286   for (unsigned int iLayer = 0; iLayer < nLayers; ++iLayer) {
0287     aNode = aGPElement->getElementsByTagName(xmlLayer)->item(iLayer);
0288     aLayerElement = static_cast<DOMElement *>(aNode);
0289     ///MeanDistPhi vector
0290     unsigned int nItems = aLayerElement->getElementsByTagName(xmlRefLayer)->getLength();
0291     assert(nItems == (unsigned)aConfig.nRefLayers());
0292     GoldenPattern::vector1D meanDistPhi1D(nItems);
0293     for (unsigned int iItem = 0; iItem < nItems; ++iItem) {
0294       aNode = aLayerElement->getElementsByTagName(xmlRefLayer)->item(iItem);
0295       aItemElement = static_cast<DOMElement *>(aNode);
0296       val = std::atoi(_toString(aItemElement->getAttribute(xmlmeanDistPhi)).c_str());
0297       meanDistPhi1D[iItem] = val;
0298     }
0299     meanDistPhi2D[iLayer] = meanDistPhi1D;
0300 
0301     ///PDF vector
0302     nItems = aLayerElement->getElementsByTagName(xmlPDF)->getLength();
0303     assert(nItems == aConfig.nRefLayers() * exp2(aConfig.nPdfAddrBits()));
0304     for (unsigned int iRefLayer = 0; iRefLayer < (unsigned)aConfig.nRefLayers(); ++iRefLayer) {
0305       pdf1D.assign(exp2(aConfig.nPdfAddrBits()), 0);
0306       for (unsigned int iPdf = 0; iPdf < exp2(aConfig.nPdfAddrBits()); ++iPdf) {
0307         aNode = aLayerElement->getElementsByTagName(xmlPDF)->item(iRefLayer * exp2(aConfig.nPdfAddrBits()) + iPdf);
0308         aItemElement = static_cast<DOMElement *>(aNode);
0309         val = std::atoi(_toString(aItemElement->getAttribute(xmlValue)).c_str());
0310         pdf1D[iPdf] = val;
0311       }
0312       pdf2D[iRefLayer] = pdf1D;
0313     }
0314     pdf3D[iLayer] = pdf2D;
0315   }
0316 
0317   Key aKey(iEta, iPt, iCharge, aGPNumber);
0318   auto aGP = std::make_unique<GoldenPattern>(aKey, static_cast<const OMTFConfiguration *>(nullptr));
0319   aGP->setMeanDistPhi(meanDistPhi2D);
0320   aGP->setPdf(pdf3D);
0321 
0322   XMLString::release(&xmliEta);
0323   XMLString::release(&xmliPt);
0324   XMLString::release(&xmliCharge);
0325   XMLString::release(&xmlLayer);
0326   XMLString::release(&xmlRefLayer);
0327   XMLString::release(&xmlmeanDistPhi);
0328   XMLString::release(&xmlPDF);
0329   XMLString::release(&xmlValue);
0330 
0331   return aGP;
0332 }
0333 //////////////////////////////////////////////////
0334 //////////////////////////////////////////////////
0335 std::vector<std::vector<int>> XMLConfigReader::readEvent(unsigned int iEvent, unsigned int iProcessor, bool readEta) {
0336   return OMTFinput::vector2D();
0337 }
0338 //////////////////////////////////////////////////
0339 //////////////////////////////////////////////////
0340 void XMLConfigReader::readConfig(L1TMuonOverlapParams *aConfig) const {
0341   XMLPlatformUtils::Initialize();
0342   {
0343     XercesDOMParser parser;
0344     parser.setValidationScheme(XercesDOMParser::Val_Auto);
0345     parser.setDoNamespaces(false);
0346 
0347     XMLCh *xmlOMTF = _toDOMS("OMTF");
0348     XMLCh *xmlversion = _toDOMS("version");
0349     XMLCh *xmlGlobalData = _toDOMS("GlobalData");
0350     XMLCh *xmlnPdfAddrBits = _toDOMS("nPdfAddrBits");
0351     XMLCh *xmlnPdfValBits = _toDOMS("nPdfValBits");
0352     XMLCh *xmlnPhiBits = _toDOMS("nPhiBits");
0353     XMLCh *xmlnPhiBins = _toDOMS("nPhiBins");
0354     XMLCh *xmlnProcessors = _toDOMS("nProcessors");
0355     XMLCh *xmlnLogicRegions = _toDOMS("nLogicRegions");
0356     XMLCh *xmlnInputs = _toDOMS("nInputs");
0357     XMLCh *xmlnLayers = _toDOMS("nLayers");
0358     XMLCh *xmlnRefLayers = _toDOMS("nRefLayers");
0359     XMLCh *xmliProcessor = _toDOMS("iProcessor");
0360     XMLCh *xmlbarrelMin = _toDOMS("barrelMin");
0361     XMLCh *xmlbarrelMax = _toDOMS("barrelMax");
0362     XMLCh *xmlendcap10DegMin = _toDOMS("endcap10DegMin");
0363     XMLCh *xmlendcap10DegMax = _toDOMS("endcap10DegMax");
0364     XMLCh *xmlendcap20DegMin = _toDOMS("endcap20DegMin");
0365     XMLCh *xmlendcap20DegMax = _toDOMS("endcap20DegMax");
0366     XMLCh *xmlLayerMap = _toDOMS("LayerMap");
0367     XMLCh *xmlhwNumber = _toDOMS("hwNumber");
0368     XMLCh *xmllogicNumber = _toDOMS("logicNumber");
0369     XMLCh *xmlbendingLayer = _toDOMS("bendingLayer");
0370     XMLCh *xmlconnectedToLayer = _toDOMS("connectedToLayer");
0371     XMLCh *xmlRefLayerMap = _toDOMS("RefLayerMap");
0372     XMLCh *xmlrefLayer = _toDOMS("refLayer");
0373     XMLCh *xmlProcessor = _toDOMS("Processor");
0374     XMLCh *xmlRefLayer = _toDOMS("RefLayer");
0375     XMLCh *xmliRefLayer = _toDOMS("iRefLayer");
0376     XMLCh *xmliGlobalPhiStart = _toDOMS("iGlobalPhiStart");
0377     XMLCh *xmlRefHit = _toDOMS("RefHit");
0378     XMLCh *xmliRefHit = _toDOMS("iRefHit");
0379     XMLCh *xmliPhiMin = _toDOMS("iPhiMin");
0380     XMLCh *xmliPhiMax = _toDOMS("iPhiMax");
0381     XMLCh *xmliInput = _toDOMS("iInput");
0382     XMLCh *xmliRegion = _toDOMS("iRegion");
0383     XMLCh *xmlLogicRegion = _toDOMS("LogicRegion");
0384     XMLCh *xmlLayer = _toDOMS("Layer");
0385     XMLCh *xmliLayer = _toDOMS("iLayer");
0386     XMLCh *xmliFirstInput = _toDOMS("iFirstInput");
0387     XMLCh *xmlnHitsPerLayer = _toDOMS("nHitsPerLayer");
0388     XMLCh *xmlnRefHits = _toDOMS("nRefHits");
0389     XMLCh *xmlnTestRefHits = _toDOMS("nTestRefHits");
0390     XMLCh *xmlnGoldenPatterns = _toDOMS("nGoldenPatterns");
0391     XMLCh *xmlConnectionMap = _toDOMS("ConnectionMap");
0392     parser.parse(configFile.c_str());
0393     xercesc::DOMDocument *doc = parser.getDocument();
0394     assert(doc);
0395     unsigned int nElem = doc->getElementsByTagName(xmlOMTF)->getLength();
0396     if (nElem != 1) {
0397       edm::LogError("critical") << "Problem parsing XML file " << configFile << std::endl;
0398       assert(nElem == 1);
0399     }
0400     DOMNode *aNode = doc->getElementsByTagName(xmlOMTF)->item(0);
0401     DOMElement *aOMTFElement = static_cast<DOMElement *>(aNode);
0402 
0403     unsigned int version = std::stoul(_toString(aOMTFElement->getAttribute(xmlversion)), nullptr, 16);
0404     aConfig->setFwVersion(version);
0405 
0406     ///Addresing bits numbers
0407     nElem = aOMTFElement->getElementsByTagName(xmlGlobalData)->getLength();
0408     assert(nElem == 1);
0409     aNode = aOMTFElement->getElementsByTagName(xmlGlobalData)->item(0);
0410     DOMElement *aElement = static_cast<DOMElement *>(aNode);
0411 
0412     unsigned int nPdfAddrBits = std::atoi(_toString(aElement->getAttribute(xmlnPdfAddrBits)).c_str());
0413     unsigned int nPdfValBits = std::atoi(_toString(aElement->getAttribute(xmlnPdfValBits)).c_str());
0414     unsigned int nHitsPerLayer = std::atoi(_toString(aElement->getAttribute(xmlnHitsPerLayer)).c_str());
0415     unsigned int nPhiBits = std::atoi(_toString(aElement->getAttribute(xmlnPhiBits)).c_str());
0416     unsigned int nPhiBins = std::atoi(_toString(aElement->getAttribute(xmlnPhiBins)).c_str());
0417 
0418     unsigned int nRefHits = std::atoi(_toString(aElement->getAttribute(xmlnRefHits)).c_str());
0419     unsigned int nTestRefHits = std::atoi(_toString(aElement->getAttribute(xmlnTestRefHits)).c_str());
0420     unsigned int nProcessors = std::atoi(_toString(aElement->getAttribute(xmlnProcessors)).c_str());
0421     unsigned int nLogicRegions = std::atoi(_toString(aElement->getAttribute(xmlnLogicRegions)).c_str());
0422     unsigned int nInputs = std::atoi(_toString(aElement->getAttribute(xmlnInputs)).c_str());
0423     unsigned int nLayers = std::atoi(_toString(aElement->getAttribute(xmlnLayers)).c_str());
0424     unsigned int nRefLayers = std::atoi(_toString(aElement->getAttribute(xmlnRefLayers)).c_str());
0425     unsigned int nGoldenPatterns = std::atoi(_toString(aElement->getAttribute(xmlnGoldenPatterns)).c_str());
0426 
0427     std::vector<int> paramsVec(L1TMuonOverlapParams::GENERAL_NCONFIG);
0428     paramsVec[L1TMuonOverlapParams::GENERAL_ADDRBITS] = nPdfAddrBits;
0429     paramsVec[L1TMuonOverlapParams::GENERAL_VALBITS] = nPdfValBits;
0430     paramsVec[L1TMuonOverlapParams::GENERAL_HITSPERLAYER] = nHitsPerLayer;
0431     paramsVec[L1TMuonOverlapParams::GENERAL_PHIBITS] = nPhiBits;
0432     paramsVec[L1TMuonOverlapParams::GENERAL_PHIBINS] = nPhiBins;
0433     paramsVec[L1TMuonOverlapParams::GENERAL_NREFHITS] = nRefHits;
0434     paramsVec[L1TMuonOverlapParams::GENERAL_NTESTREFHITS] = nTestRefHits;
0435     paramsVec[L1TMuonOverlapParams::GENERAL_NPROCESSORS] = nProcessors;
0436     paramsVec[L1TMuonOverlapParams::GENERAL_NLOGIC_REGIONS] = nLogicRegions;
0437     paramsVec[L1TMuonOverlapParams::GENERAL_NINPUTS] = nInputs;
0438     paramsVec[L1TMuonOverlapParams::GENERAL_NLAYERS] = nLayers;
0439     paramsVec[L1TMuonOverlapParams::GENERAL_NREFLAYERS] = nRefLayers;
0440     paramsVec[L1TMuonOverlapParams::GENERAL_NGOLDENPATTERNS] = nGoldenPatterns;
0441     aConfig->setGeneralParams(paramsVec);
0442 
0443     ///Chamber sectors connections to logic processros.
0444     ///Start/End values for all processors, and chamber types are put into a single vector
0445     std::vector<int> sectorsStart(3 * nProcessors), sectorsEnd(3 * nProcessors);
0446     nElem = aOMTFElement->getElementsByTagName(xmlConnectionMap)->getLength();
0447     DOMElement *aConnectionElement = nullptr;
0448     for (unsigned int i = 0; i < nElem; ++i) {
0449       aNode = aOMTFElement->getElementsByTagName(xmlConnectionMap)->item(i);
0450       aConnectionElement = static_cast<DOMElement *>(aNode);
0451       unsigned int iProcessor = std::atoi(_toString(aConnectionElement->getAttribute(xmliProcessor)).c_str());
0452       unsigned int barrelMin = std::atoi(_toString(aConnectionElement->getAttribute(xmlbarrelMin)).c_str());
0453       unsigned int barrelMax = std::atoi(_toString(aConnectionElement->getAttribute(xmlbarrelMax)).c_str());
0454       unsigned int endcap10DegMin = std::atoi(_toString(aConnectionElement->getAttribute(xmlendcap10DegMin)).c_str());
0455       unsigned int endcap10DegMax = std::atoi(_toString(aConnectionElement->getAttribute(xmlendcap10DegMax)).c_str());
0456       unsigned int endcap20DegMin = std::atoi(_toString(aConnectionElement->getAttribute(xmlendcap20DegMin)).c_str());
0457       unsigned int endcap20DegMax = std::atoi(_toString(aConnectionElement->getAttribute(xmlendcap20DegMax)).c_str());
0458 
0459       sectorsStart[iProcessor] = barrelMin;
0460       sectorsStart[iProcessor + nProcessors] = endcap10DegMin;
0461       sectorsStart[iProcessor + 2 * nProcessors] = endcap20DegMin;
0462 
0463       sectorsEnd[iProcessor] = barrelMax;
0464       sectorsEnd[iProcessor + nProcessors] = endcap10DegMax;
0465       sectorsEnd[iProcessor + 2 * nProcessors] = endcap20DegMax;
0466     }
0467     aConfig->setConnectedSectorsStart(sectorsStart);
0468     aConfig->setConnectedSectorsEnd(sectorsEnd);
0469 
0470     ///hw <-> logic numbering map
0471     std::vector<L1TMuonOverlapParams::LayerMapNode> aLayerMapVec;
0472     L1TMuonOverlapParams::LayerMapNode aLayerMapNode;
0473 
0474     nElem = aOMTFElement->getElementsByTagName(xmlLayerMap)->getLength();
0475     DOMElement *aLayerElement = nullptr;
0476     for (unsigned int i = 0; i < nElem; ++i) {
0477       aNode = aOMTFElement->getElementsByTagName(xmlLayerMap)->item(i);
0478       aLayerElement = static_cast<DOMElement *>(aNode);
0479       unsigned int hwNumber = std::atoi(_toString(aLayerElement->getAttribute(xmlhwNumber)).c_str());
0480       unsigned int logicNumber = std::atoi(_toString(aLayerElement->getAttribute(xmllogicNumber)).c_str());
0481       unsigned int isBendingLayer = std::atoi(_toString(aLayerElement->getAttribute(xmlbendingLayer)).c_str());
0482       unsigned int iConnectedLayer = std::atoi(_toString(aLayerElement->getAttribute(xmlconnectedToLayer)).c_str());
0483       aLayerMapNode.logicNumber = logicNumber;
0484       aLayerMapNode.hwNumber = hwNumber;
0485       aLayerMapNode.connectedToLayer = iConnectedLayer;
0486       aLayerMapNode.bendingLayer = isBendingLayer;
0487       aLayerMapVec.push_back(aLayerMapNode);
0488     }
0489     aConfig->setLayerMap(aLayerMapVec);
0490 
0491     ///ref<->logic numberig map
0492     std::vector<L1TMuonOverlapParams::RefLayerMapNode> aRefLayerMapVec;
0493     L1TMuonOverlapParams::RefLayerMapNode aRefLayerNode;
0494 
0495     nElem = aOMTFElement->getElementsByTagName(xmlRefLayerMap)->getLength();
0496     DOMElement *aRefLayerElement = nullptr;
0497     for (unsigned int i = 0; i < nElem; ++i) {
0498       aNode = aOMTFElement->getElementsByTagName(xmlRefLayerMap)->item(i);
0499       aRefLayerElement = static_cast<DOMElement *>(aNode);
0500       unsigned int refLayer = std::atoi(_toString(aRefLayerElement->getAttribute(xmlrefLayer)).c_str());
0501       unsigned int logicNumber = std::atoi(_toString(aRefLayerElement->getAttribute(xmllogicNumber)).c_str());
0502       aRefLayerNode.refLayer = refLayer;
0503       aRefLayerNode.logicNumber = logicNumber;
0504       aRefLayerMapVec.push_back(aRefLayerNode);
0505     }
0506     aConfig->setRefLayerMap(aRefLayerMapVec);
0507 
0508     std::vector<int> aGlobalPhiStartVec(nProcessors * nRefLayers);
0509 
0510     std::vector<L1TMuonOverlapParams::RefHitNode> aRefHitMapVec(nProcessors * nRefHits);
0511     L1TMuonOverlapParams::RefHitNode aRefHitNode;
0512 
0513     std::vector<L1TMuonOverlapParams::LayerInputNode> aLayerInputMapVec(nProcessors * nLogicRegions * nLayers);
0514     L1TMuonOverlapParams::LayerInputNode aLayerInputNode;
0515 
0516     nElem = aOMTFElement->getElementsByTagName(xmlProcessor)->getLength();
0517     assert(nElem == nProcessors);
0518     DOMElement *aProcessorElement = nullptr;
0519     for (unsigned int i = 0; i < nElem; ++i) {
0520       aNode = aOMTFElement->getElementsByTagName(xmlProcessor)->item(i);
0521       aProcessorElement = static_cast<DOMElement *>(aNode);
0522       unsigned int iProcessor = std::atoi(_toString(aProcessorElement->getAttribute(xmliProcessor)).c_str());
0523       unsigned int nElem1 = aProcessorElement->getElementsByTagName(xmlRefLayer)->getLength();
0524       assert(nElem1 == nRefLayers);
0525       DOMElement *aRefLayerElement = nullptr;
0526       for (unsigned int ii = 0; ii < nElem1; ++ii) {
0527         aNode = aProcessorElement->getElementsByTagName(xmlRefLayer)->item(ii);
0528         aRefLayerElement = static_cast<DOMElement *>(aNode);
0529         unsigned int iRefLayer = std::atoi(_toString(aRefLayerElement->getAttribute(xmliRefLayer)).c_str());
0530         int iPhi = std::atoi(_toString(aRefLayerElement->getAttribute(xmliGlobalPhiStart)).c_str());
0531         aGlobalPhiStartVec[iRefLayer + iProcessor * nRefLayers] = iPhi;
0532       }
0533       ///////////
0534       nElem1 = aProcessorElement->getElementsByTagName(xmlRefHit)->getLength();
0535       assert((iProcessor == 0 && nElem1 == nRefHits) || (iProcessor != 0 && nElem1 == 0));
0536       DOMElement *aRefHitElement = nullptr;
0537       for (unsigned int ii = 0; ii < nElem1; ++ii) {
0538         aNode = aProcessorElement->getElementsByTagName(xmlRefHit)->item(ii);
0539         aRefHitElement = static_cast<DOMElement *>(aNode);
0540         unsigned int iRefHit = std::atoi(_toString(aRefHitElement->getAttribute(xmliRefHit)).c_str());
0541         int iPhiMin = std::atoi(_toString(aRefHitElement->getAttribute(xmliPhiMin)).c_str());
0542         int iPhiMax = std::atoi(_toString(aRefHitElement->getAttribute(xmliPhiMax)).c_str());
0543         unsigned int iInput = std::atoi(_toString(aRefHitElement->getAttribute(xmliInput)).c_str());
0544         unsigned int iRegion = std::atoi(_toString(aRefHitElement->getAttribute(xmliRegion)).c_str());
0545         unsigned int iRefLayer = std::atoi(_toString(aRefHitElement->getAttribute(xmliRefLayer)).c_str());
0546 
0547         aRefHitNode.iRefHit = iRefHit;
0548         aRefHitNode.iPhiMin = iPhiMin;
0549         aRefHitNode.iPhiMax = iPhiMax;
0550         aRefHitNode.iInput = iInput;
0551         aRefHitNode.iRegion = iRegion;
0552         aRefHitNode.iRefLayer = iRefLayer;
0553         for (unsigned int iProcessor = 0; iProcessor < nProcessors; iProcessor++)
0554           aRefHitMapVec[iRefHit + iProcessor * nRefHits] = aRefHitNode;
0555       }
0556       ///////////
0557       unsigned int nElem2 = aProcessorElement->getElementsByTagName(xmlLogicRegion)->getLength();
0558       assert((iProcessor == 0 && nElem2 == nLogicRegions) || (iProcessor != 0 && nElem2 == 0));
0559       DOMElement *aRegionElement = nullptr;
0560       for (unsigned int ii = 0; ii < nElem2; ++ii) {
0561         aNode = aProcessorElement->getElementsByTagName(xmlLogicRegion)->item(ii);
0562         aRegionElement = static_cast<DOMElement *>(aNode);
0563         unsigned int iRegion = std::atoi(_toString(aRegionElement->getAttribute(xmliRegion)).c_str());
0564         unsigned int nElem3 = aRegionElement->getElementsByTagName(xmlLayer)->getLength();
0565         assert(nElem3 == nLayers);
0566         DOMElement *aLayerElement = nullptr;
0567         for (unsigned int iii = 0; iii < nElem3; ++iii) {
0568           aNode = aRegionElement->getElementsByTagName(xmlLayer)->item(iii);
0569           aLayerElement = static_cast<DOMElement *>(aNode);
0570           unsigned int iLayer = std::atoi(_toString(aLayerElement->getAttribute(xmliLayer)).c_str());
0571           unsigned int iFirstInput = std::atoi(_toString(aLayerElement->getAttribute(xmliFirstInput)).c_str());
0572           unsigned int nInputs = std::atoi(_toString(aLayerElement->getAttribute(xmlnInputs)).c_str());
0573           aLayerInputNode.iLayer = iLayer;
0574           aLayerInputNode.iFirstInput = iFirstInput;
0575           aLayerInputNode.nInputs = nInputs;
0576           for (unsigned int iProcessor = 0; iProcessor < nProcessors; ++iProcessor)
0577             aLayerInputMapVec[iLayer + iRegion * nLayers + iProcessor * nLayers * nLogicRegions] = aLayerInputNode;
0578         }
0579       }
0580     }
0581 
0582     aConfig->setGlobalPhiStartMap(aGlobalPhiStartVec);
0583     aConfig->setLayerInputMap(aLayerInputMapVec);
0584     aConfig->setRefHitMap(aRefHitMapVec);
0585 
0586     // Reset the documents vector pool and release all the associated memory back to the system.
0587     parser.resetDocumentPool();
0588 
0589     XMLString::release(&xmlOMTF);
0590     XMLString::release(&xmlversion);
0591     XMLString::release(&xmlGlobalData);
0592     XMLString::release(&xmlnPdfAddrBits);
0593     XMLString::release(&xmlnPdfValBits);
0594     XMLString::release(&xmlnPhiBits);
0595     XMLString::release(&xmlnPhiBins);
0596     XMLString::release(&xmlnProcessors);
0597     XMLString::release(&xmlnLogicRegions);
0598     XMLString::release(&xmlnInputs);
0599     XMLString::release(&xmlnLayers);
0600     XMLString::release(&xmlnRefLayers);
0601     XMLString::release(&xmliProcessor);
0602     XMLString::release(&xmlbarrelMin);
0603     XMLString::release(&xmlbarrelMax);
0604     XMLString::release(&xmlendcap10DegMin);
0605     XMLString::release(&xmlendcap10DegMax);
0606     XMLString::release(&xmlendcap20DegMin);
0607     XMLString::release(&xmlendcap20DegMax);
0608     XMLString::release(&xmlLayerMap);
0609     XMLString::release(&xmlhwNumber);
0610     XMLString::release(&xmllogicNumber);
0611     XMLString::release(&xmlbendingLayer);
0612     XMLString::release(&xmlconnectedToLayer);
0613     XMLString::release(&xmlRefLayerMap);
0614     XMLString::release(&xmlrefLayer);
0615     XMLString::release(&xmlProcessor);
0616     XMLString::release(&xmlRefLayer);
0617     XMLString::release(&xmliRefLayer);
0618     XMLString::release(&xmliGlobalPhiStart);
0619     XMLString::release(&xmlRefHit);
0620     XMLString::release(&xmliRefHit);
0621     XMLString::release(&xmliPhiMin);
0622     XMLString::release(&xmliPhiMax);
0623     XMLString::release(&xmliInput);
0624     XMLString::release(&xmliRegion);
0625     XMLString::release(&xmlLogicRegion);
0626     XMLString::release(&xmlLayer);
0627     XMLString::release(&xmliLayer);
0628     XMLString::release(&xmliFirstInput);
0629     XMLString::release(&xmlnHitsPerLayer);
0630     XMLString::release(&xmlnRefHits);
0631     XMLString::release(&xmlnTestRefHits);
0632     XMLString::release(&xmlnGoldenPatterns);
0633     XMLString::release(&xmlConnectionMap);
0634   }
0635   XMLPlatformUtils::Terminate();
0636 }
0637 //////////////////////////////////////////////////
0638 //////////////////////////////////////////////////
0639 
0640 //  xercesc::XercesDOMParser *parser;
0641 //  xercesc::DOMDocument* doc;