Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:20

0001 /**
0002  * \class L1GtTriggerMenuXmlParser
0003  *
0004  *
0005  * Description: Xerces-C XML parser for the L1 Trigger menu.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  * \author: Vasile Mihai Ghete - HEPHY Vienna
0011  *
0012  *
0013  */
0014 
0015 // this class header
0016 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtTriggerMenuXmlParser.h"
0017 
0018 // system include files
0019 #include <string>
0020 #include <vector>
0021 
0022 #include <iostream>
0023 #include <fstream>
0024 #include <iomanip>
0025 
0026 // user include files
0027 // base class
0028 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtXmlParserTags.h"
0029 
0030 #include "CondFormats/L1TObjects/interface/L1GtCondition.h"
0031 #include "CondFormats/L1TObjects/interface/L1GtAlgorithm.h"
0032 
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0035 #include "Utilities/Xerces/interface/Xerces.h"
0036 #include <cstdint>
0037 
0038 // constructor
0039 L1GtTriggerMenuXmlParser::L1GtTriggerMenuXmlParser()
0040     : L1GtXmlParserTags(),
0041       m_xmlErrHandler(nullptr),
0042       m_triggerMenuInterface("NULL"),
0043       m_triggerMenuName("NULL"),
0044       m_triggerMenuImplementation("NULL"),
0045       m_scaleDbKey("NULL")
0046 
0047 {
0048   // menu names, scale key initialized to NULL due to ORACLE treatment of strings
0049 
0050   // empty
0051 }
0052 
0053 // destructor
0054 L1GtTriggerMenuXmlParser::~L1GtTriggerMenuXmlParser() { clearMaps(); }
0055 
0056 // set the number of condition chips in GTL
0057 void L1GtTriggerMenuXmlParser::setGtNumberConditionChips(const unsigned int& numberConditionChipsValue) {
0058   m_numberConditionChips = numberConditionChipsValue;
0059 }
0060 
0061 // set the number of pins on the GTL condition chips
0062 void L1GtTriggerMenuXmlParser::setGtPinsOnConditionChip(const unsigned int& pinsOnConditionChipValue) {
0063   m_pinsOnConditionChip = pinsOnConditionChipValue;
0064 }
0065 
0066 // set the correspondence "condition chip - GTL algorithm word"
0067 // in the hardware
0068 void L1GtTriggerMenuXmlParser::setGtOrderConditionChip(const std::vector<int>& orderConditionChipValue) {
0069   m_orderConditionChip = orderConditionChipValue;
0070 }
0071 
0072 // set the number of physics trigger algorithms
0073 void L1GtTriggerMenuXmlParser::setGtNumberPhysTriggers(const unsigned int& numberPhysTriggersValue) {
0074   m_numberPhysTriggers = numberPhysTriggersValue;
0075 }
0076 
0077 // set the number of technical triggers
0078 void L1GtTriggerMenuXmlParser::setGtNumberTechTriggers(const unsigned int& numberTechTriggersValue) {
0079   m_numberTechTriggers = numberTechTriggersValue;
0080 }
0081 
0082 // set the number of L1 jet counts received by GT
0083 void L1GtTriggerMenuXmlParser::setGtNumberL1JetCounts(const unsigned int& numberL1JetCountsValue) {
0084   m_numberL1JetCounts = numberL1JetCountsValue;
0085 }
0086 
0087 // set the condition maps
0088 void L1GtTriggerMenuXmlParser::setGtConditionMap(const std::vector<ConditionMap>& condMap) { m_conditionMap = condMap; }
0089 
0090 // set the trigger menu name
0091 void L1GtTriggerMenuXmlParser::setGtTriggerMenuInterface(const std::string& menuInterface) {
0092   m_triggerMenuInterface = menuInterface;
0093 }
0094 
0095 void L1GtTriggerMenuXmlParser::setGtTriggerMenuName(const std::string& menuName) { m_triggerMenuName = menuName; }
0096 
0097 void L1GtTriggerMenuXmlParser::setGtTriggerMenuImplementation(const std::string& menuImplementation) {
0098   m_triggerMenuImplementation = menuImplementation;
0099 }
0100 
0101 // set menu associated scale key
0102 void L1GtTriggerMenuXmlParser::setGtScaleDbKey(const std::string& scaleKey) { m_scaleDbKey = scaleKey; }
0103 
0104 // set the vectors containing the conditions
0105 void L1GtTriggerMenuXmlParser::setVecMuonTemplate(const std::vector<std::vector<L1GtMuonTemplate> >& vecMuonTempl) {
0106   m_vecMuonTemplate = vecMuonTempl;
0107 }
0108 
0109 void L1GtTriggerMenuXmlParser::setVecCaloTemplate(const std::vector<std::vector<L1GtCaloTemplate> >& vecCaloTempl) {
0110   m_vecCaloTemplate = vecCaloTempl;
0111 }
0112 
0113 void L1GtTriggerMenuXmlParser::setVecEnergySumTemplate(
0114     const std::vector<std::vector<L1GtEnergySumTemplate> >& vecEnergySumTempl) {
0115   m_vecEnergySumTemplate = vecEnergySumTempl;
0116 }
0117 
0118 void L1GtTriggerMenuXmlParser::setVecJetCountsTemplate(
0119     const std::vector<std::vector<L1GtJetCountsTemplate> >& vecJetCountsTempl) {
0120   m_vecJetCountsTemplate = vecJetCountsTempl;
0121 }
0122 
0123 void L1GtTriggerMenuXmlParser::setVecCastorTemplate(
0124     const std::vector<std::vector<L1GtCastorTemplate> >& vecCastorTempl) {
0125   m_vecCastorTemplate = vecCastorTempl;
0126 }
0127 
0128 void L1GtTriggerMenuXmlParser::setVecHfBitCountsTemplate(
0129     const std::vector<std::vector<L1GtHfBitCountsTemplate> >& vecHfBitCountsTempl) {
0130   m_vecHfBitCountsTemplate = vecHfBitCountsTempl;
0131 }
0132 
0133 void L1GtTriggerMenuXmlParser::setVecHfRingEtSumsTemplate(
0134     const std::vector<std::vector<L1GtHfRingEtSumsTemplate> >& vecHfRingEtSumsTempl) {
0135   m_vecHfRingEtSumsTemplate = vecHfRingEtSumsTempl;
0136 }
0137 
0138 void L1GtTriggerMenuXmlParser::setVecBptxTemplate(const std::vector<std::vector<L1GtBptxTemplate> >& vecBptxTempl) {
0139   m_vecBptxTemplate = vecBptxTempl;
0140 }
0141 
0142 void L1GtTriggerMenuXmlParser::setVecExternalTemplate(
0143     const std::vector<std::vector<L1GtExternalTemplate> >& vecExternalTempl) {
0144   m_vecExternalTemplate = vecExternalTempl;
0145 }
0146 
0147 void L1GtTriggerMenuXmlParser::setVecCorrelationTemplate(
0148     const std::vector<std::vector<L1GtCorrelationTemplate> >& vecCorrelationTempl) {
0149   m_vecCorrelationTemplate = vecCorrelationTempl;
0150 }
0151 
0152 // set the vectors containing the conditions for correlation templates
0153 //
0154 void L1GtTriggerMenuXmlParser::setCorMuonTemplate(const std::vector<std::vector<L1GtMuonTemplate> >& corMuonTempl) {
0155   m_corMuonTemplate = corMuonTempl;
0156 }
0157 
0158 void L1GtTriggerMenuXmlParser::setCorCaloTemplate(const std::vector<std::vector<L1GtCaloTemplate> >& corCaloTempl) {
0159   m_corCaloTemplate = corCaloTempl;
0160 }
0161 
0162 void L1GtTriggerMenuXmlParser::setCorEnergySumTemplate(
0163     const std::vector<std::vector<L1GtEnergySumTemplate> >& corEnergySumTempl) {
0164   m_corEnergySumTemplate = corEnergySumTempl;
0165 }
0166 
0167 // set the algorithm map (by algorithm names)
0168 void L1GtTriggerMenuXmlParser::setGtAlgorithmMap(const AlgorithmMap& algoMap) { m_algorithmMap = algoMap; }
0169 
0170 // set the algorithm map (by algorithm aliases)
0171 void L1GtTriggerMenuXmlParser::setGtAlgorithmAliasMap(const AlgorithmMap& algoMap) { m_algorithmAliasMap = algoMap; }
0172 
0173 // set the technical trigger map
0174 void L1GtTriggerMenuXmlParser::setGtTechnicalTriggerMap(const AlgorithmMap& ttMap) { m_technicalTriggerMap = ttMap; }
0175 
0176 //
0177 
0178 // parse def.xml and vme.xml files
0179 void L1GtTriggerMenuXmlParser::parseXmlFile(const std::string& defXmlFile, const std::string& vmeXmlFile) {
0180   XERCES_CPP_NAMESPACE_USE
0181 
0182   // resize the vector of condition maps
0183   // the number of condition chips should be correctly set before calling parseXmlFile
0184   m_conditionMap.resize(m_numberConditionChips);
0185 
0186   m_vecMuonTemplate.resize(m_numberConditionChips);
0187   m_vecCaloTemplate.resize(m_numberConditionChips);
0188   m_vecEnergySumTemplate.resize(m_numberConditionChips);
0189   m_vecJetCountsTemplate.resize(m_numberConditionChips);
0190   m_vecCastorTemplate.resize(m_numberConditionChips);
0191   m_vecHfBitCountsTemplate.resize(m_numberConditionChips);
0192   m_vecHfRingEtSumsTemplate.resize(m_numberConditionChips);
0193   m_vecBptxTemplate.resize(m_numberConditionChips);
0194   m_vecExternalTemplate.resize(m_numberConditionChips);
0195 
0196   m_vecCorrelationTemplate.resize(m_numberConditionChips);
0197   m_corMuonTemplate.resize(m_numberConditionChips);
0198   m_corCaloTemplate.resize(m_numberConditionChips);
0199   m_corEnergySumTemplate.resize(m_numberConditionChips);
0200 
0201   // set the name of the trigger menu name:
0202   //     defXmlFile, stripped of absolute path and .xml
0203   // will be overwritten by the value read from the xml file, with a warning if
0204   // they are not the same
0205   m_triggerMenuName = defXmlFile;
0206   size_t xmlPos = m_triggerMenuName.find_last_of('/');
0207   m_triggerMenuName.erase(m_triggerMenuName.begin(), m_triggerMenuName.begin() + xmlPos + 1);
0208 
0209   xmlPos = m_triggerMenuName.find_last_of('.');
0210   m_triggerMenuName.erase(m_triggerMenuName.begin() + xmlPos, m_triggerMenuName.end());
0211 
0212   // error handler for xml-parser
0213   m_xmlErrHandler = nullptr;
0214 
0215   XercesDOMParser* parser;
0216 
0217   LogTrace("L1GtTriggerMenuXmlParser") << "\nOpening XML-File: \n  " << defXmlFile << std::endl;
0218 
0219   if ((parser = initXML(defXmlFile)) != nullptr) {
0220     workXML(parser);
0221   }
0222   cleanupXML(parser);
0223 }
0224 
0225 //
0226 
0227 void L1GtTriggerMenuXmlParser::setGtTriggerMenuInterfaceDate(const std::string& val) {
0228   m_triggerMenuInterfaceDate = val;
0229 }
0230 
0231 void L1GtTriggerMenuXmlParser::setGtTriggerMenuInterfaceAuthor(const std::string& val) {
0232   m_triggerMenuInterfaceAuthor = val;
0233 }
0234 
0235 void L1GtTriggerMenuXmlParser::setGtTriggerMenuInterfaceDescription(const std::string& val) {
0236   m_triggerMenuInterfaceDescription = val;
0237 }
0238 
0239 void L1GtTriggerMenuXmlParser::setGtTriggerMenuDate(const std::string& val) { m_triggerMenuDate = val; }
0240 
0241 void L1GtTriggerMenuXmlParser::setGtTriggerMenuAuthor(const std::string& val) { m_triggerMenuAuthor = val; }
0242 
0243 void L1GtTriggerMenuXmlParser::setGtTriggerMenuDescription(const std::string& val) { m_triggerMenuDescription = val; }
0244 
0245 void L1GtTriggerMenuXmlParser::setGtAlgorithmImplementation(const std::string& val) { m_algorithmImplementation = val; }
0246 
0247 // private methods
0248 
0249 /**
0250  * initXML - Initialize XML-utilities and try to create a parser for the specified file.
0251  *
0252  * @param xmlFile Filename of the XML-File
0253  *
0254  * @return A reference to a XercesDOMParser object if succeeded. 0 if an error occurred.
0255  *
0256  */
0257 
0258 XERCES_CPP_NAMESPACE::XercesDOMParser* L1GtTriggerMenuXmlParser::initXML(const std::string& xmlFile) {
0259   XERCES_CPP_NAMESPACE_USE
0260 
0261   // try to initialize
0262   try {
0263     cms::concurrency::xercesInitialize();
0264   } catch (const XMLException& toCatch) {
0265     char* message = XMLString::transcode(toCatch.getMessage());
0266 
0267     edm::LogError("L1GtTriggerMenuXmlParser") << "Error during Xerces-c initialization! :" << message << std::endl;
0268 
0269     XMLString::release(&message);
0270     return nullptr;
0271   }
0272 
0273   XercesDOMParser* parser = new XercesDOMParser();
0274   parser->setValidationScheme(XercesDOMParser::Val_Always);
0275   parser->setDoNamespaces(false);  // we got no dtd
0276 
0277   if (m_xmlErrHandler == nullptr) {  // redundant check
0278     m_xmlErrHandler = (ErrorHandler*)new HandlerBase();
0279   } else {
0280     // TODO ASSERTION
0281   }
0282   parser->setErrorHandler(m_xmlErrHandler);
0283 
0284   // try to parse the file
0285   try {
0286     parser->parse(xmlFile.c_str());
0287   } catch (const XMLException& toCatch) {
0288     char* message = XMLString::transcode(toCatch.getMessage());
0289 
0290     edm::LogError("L1GtTriggerMenuXmlParser") << "Exception while parsing XML: \n" << message << std::endl;
0291 
0292     XMLString::release(&message);
0293     delete parser;
0294     delete m_xmlErrHandler;
0295     m_xmlErrHandler = nullptr;
0296     return nullptr;
0297   } catch (const DOMException& toCatch) {
0298     char* message = XMLString::transcode(toCatch.msg);
0299 
0300     edm::LogError("L1GtTriggerMenuXmlParser") << "DOM-Exception while parsing XML: \n" << message << std::endl;
0301 
0302     XMLString::release(&message);
0303     delete parser;
0304     delete m_xmlErrHandler;
0305     m_xmlErrHandler = nullptr;
0306     return nullptr;
0307   } catch (...) {
0308     edm::LogError("L1GtTriggerMenuXmlParser") << "Unexpected Exception while parsing XML!" << std::endl;
0309 
0310     delete parser;
0311     delete m_xmlErrHandler;
0312     m_xmlErrHandler = nullptr;
0313     return nullptr;
0314   }
0315 
0316   return parser;
0317 }
0318 
0319 // find a named child of a xml node
0320 XERCES_CPP_NAMESPACE::DOMNode* L1GtTriggerMenuXmlParser::findXMLChild(XERCES_CPP_NAMESPACE::DOMNode* startChild,
0321                                                                       const std::string& tagName,
0322                                                                       bool beginOnly,
0323                                                                       std::string* rest) {
0324   XERCES_CPP_NAMESPACE_USE
0325 
0326   char* nodeName = nullptr;
0327 
0328   DOMNode* n1 = startChild;
0329   if (n1 == nullptr) {
0330     return nullptr;
0331   }
0332 
0333   if (!tagName.empty()) {
0334     nodeName = XMLString::transcode(n1->getNodeName());
0335 
0336     if (!beginOnly) {
0337       //match the whole tag
0338       while (XMLString::compareIString(nodeName, tagName.c_str())) {
0339         XMLString::release(&nodeName);
0340         n1 = n1->getNextSibling();
0341         if (n1 == nullptr) {
0342           break;
0343         }
0344 
0345         nodeName = XMLString::transcode(n1->getNodeName());
0346       }
0347     } else {
0348       // match only the beginning
0349       while (XMLString::compareNIString(nodeName, tagName.c_str(), tagName.length())) {
0350         XMLString::release(&nodeName);
0351         n1 = n1->getNextSibling();
0352         if (n1 == nullptr) {
0353           break;
0354         }
0355 
0356         nodeName = XMLString::transcode(n1->getNodeName());
0357       }
0358       if (n1 != nullptr && rest != nullptr) {
0359         *rest = std::string(nodeName).substr(tagName.length(), strlen(nodeName) - tagName.length());
0360       }
0361     }
0362   } else {  // empty string given
0363     while (n1->getNodeType() != DOMNode::ELEMENT_NODE) {
0364       n1 = n1->getNextSibling();
0365       if (n1 == nullptr) {
0366         break;
0367       }
0368     }
0369     if (n1 != nullptr && rest != nullptr) {
0370       nodeName = XMLString::transcode(n1->getNodeName());
0371       *rest = std::string(nodeName);
0372     }
0373   }
0374 
0375   XMLString::release(&nodeName);
0376 
0377   return n1;
0378 }
0379 
0380 /**
0381  * getXMLAttribute - get a named attribute from a node
0382  *
0383  * @param node The node to get the attribute from
0384  * @param name The name of the attribut to get
0385  *
0386  * @return The value of the attribute or empty string if an error occurred.
0387  */
0388 
0389 std::string L1GtTriggerMenuXmlParser::getXMLAttribute(const XERCES_CPP_NAMESPACE::DOMNode* node,
0390                                                       const std::string& name) {
0391   XERCES_CPP_NAMESPACE_USE
0392 
0393   std::string ret;
0394 
0395   // get attributes list
0396   DOMNamedNodeMap* attributes = node->getAttributes();
0397   if (attributes == nullptr) {
0398     return ret;
0399   }
0400 
0401   // get attribute node
0402   XMLCh* attrName = XMLString::transcode(name.c_str());
0403   DOMNode* attribNode = attributes->getNamedItem(attrName);
0404 
0405   XMLString::release(&attrName);
0406   if (attribNode == nullptr) {
0407     return ret;
0408   }
0409 
0410   char* retCstr = XMLString::transcode(attribNode->getNodeValue());
0411   ret = retCstr;
0412   XMLString::release(&retCstr);
0413 
0414   return ret;
0415 }
0416 
0417 /**
0418  * getXMLTextValue - get the textvalue from a specified node
0419  *
0420  * @param node The reference to the node.
0421  * @return The textvalue of the node or an empty std::string if no textvalue is available.
0422  *
0423  */
0424 
0425 std::string L1GtTriggerMenuXmlParser::getXMLTextValue(XERCES_CPP_NAMESPACE::DOMNode* node) {
0426   XERCES_CPP_NAMESPACE_USE
0427 
0428   std::string ret;
0429 
0430   DOMNode* n1 = node;
0431   if (n1 == nullptr) {
0432     return ret;
0433   }
0434 
0435   const XMLCh* retXmlCh = n1->getTextContent();
0436   if (retXmlCh == nullptr) {
0437     return ret;
0438   }
0439 
0440   char* retCstr = XMLString::transcode(retXmlCh);
0441   XMLString::trim(retCstr);  // trim spaces
0442 
0443   ret = retCstr;
0444   XMLString::release(&retCstr);
0445 
0446   return ret;
0447 }
0448 
0449 /**
0450  * hexString2UInt128 converts an up to 128 bit hexadecimal string to two uint64_t
0451  *
0452  * @param hex The string to be converted.
0453  * @param dstL The target for the lower 64 bit.
0454  * @param dstH The target for the upper 64 bit.
0455  *
0456  * @return true if conversion succeeded, false if an error occurred.
0457  */
0458 
0459 bool L1GtTriggerMenuXmlParser::hexString2UInt128(const std::string& hexString, uint64_t& dstL, uint64_t& dstH) {
0460   // string to determine start of hex value, do not ignore leading zeros
0461   static const std::string valid_hex_start("0123456789ABCDEFabcdef");
0462 
0463   // string to determine end of hex value
0464   static const std::string valid_hex_end("0123456789ABCDEFabcdef");
0465 
0466   std::string tempStr = hexString;
0467 
0468   // start / end position of the hex value in the string
0469   unsigned int hexStart = tempStr.find_first_of(valid_hex_start);
0470   unsigned int hexEnd = tempStr.find_first_not_of(valid_hex_end, hexStart);
0471 
0472   if (hexStart == hexEnd) {
0473     LogDebug("L1GtTriggerMenuXmlParser") << "No hex value found in: " << tempStr << std::endl;
0474 
0475     return false;
0476   }
0477 
0478   tempStr = tempStr.substr(hexStart, hexEnd - hexStart);
0479 
0480   if (tempStr.empty()) {
0481     LogDebug("L1GtTriggerMenuXmlParser") << "Empty value in " << __PRETTY_FUNCTION__ << std::endl;
0482 
0483     return false;
0484   }
0485 
0486   // split the string
0487   std::string tempStrH, tempStrL;
0488 
0489   if (tempStr.length() > 16) {  // more than 64 bit
0490     tempStrL = tempStr.substr(tempStr.length() - 16, 16);
0491     tempStrH = tempStr.substr(0, tempStr.length() - 16);
0492   } else {
0493     tempStrL = tempStr;
0494     tempStrH = "0";
0495   }
0496 
0497   // convert lower 64bit
0498   char* endPtr = (char*)tempStrL.c_str();
0499   uint64_t tempUIntL = strtoull(tempStrL.c_str(), &endPtr, 16);
0500 
0501   if (*endPtr != 0) {
0502     LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << tempStr << " to hex." << std::endl;
0503 
0504     return false;
0505   }
0506 
0507   // convert higher64 bit
0508   endPtr = (char*)tempStrH.c_str();
0509   uint64_t tempUIntH = strtoull(tempStrH.c_str(), &endPtr, 16);
0510 
0511   if (*endPtr != 0) {
0512     LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << tempStr << " to hex." << std::endl;
0513 
0514     return false;
0515   }
0516 
0517   dstL = tempUIntL;
0518   dstH = tempUIntH;
0519 
0520   return true;
0521 }
0522 
0523 /**
0524  * getXMLHexTextValue128 Get the integer representation of a xml-node
0525  *     containing a hexadecimal value. The value may contain up to 128 bits.
0526  *
0527  * node - The reference to the node to get the value from.
0528  * dstL - The destination for the lower 64bit
0529  * dstH - The destination for the higher 64bit
0530  *
0531  */
0532 
0533 bool L1GtTriggerMenuXmlParser::getXMLHexTextValue128(XERCES_CPP_NAMESPACE::DOMNode* node,
0534                                                      uint64_t& dstL,
0535                                                      uint64_t& dstH) {
0536   if (node == nullptr) {
0537     LogDebug("L1GtTriggerMenuXmlParser") << "node == 0 in " << __PRETTY_FUNCTION__ << std::endl;
0538 
0539     return false;
0540   }
0541 
0542   uint64_t tempUIntH, tempUIntL;
0543 
0544   std::string tempStr = getXMLTextValue(node);
0545   if (!hexString2UInt128(tempStr, tempUIntL, tempUIntH)) {
0546     return false;
0547   }
0548 
0549   dstL = tempUIntL;
0550   dstH = tempUIntH;
0551 
0552   return true;
0553 }
0554 
0555 /**
0556  * getXMLHexTextValue Get the integer representation of a xml text child
0557  *     representing a hex value
0558  *
0559  * @param node The xml node to get the value from.
0560  * @param dst The destination the value is written to.
0561  *
0562  * @return true if succeeded, false if an error occurred
0563  *
0564  */
0565 
0566 bool L1GtTriggerMenuXmlParser::getXMLHexTextValue(XERCES_CPP_NAMESPACE::DOMNode* node, uint64_t& dst) {
0567   uint64_t dummyH;    // dummy for eventual higher 64bit
0568   uint64_t tempUInt;  // temporary unsigned integer
0569 
0570   if (!getXMLHexTextValue128(node, tempUInt, dummyH)) {
0571     return false;
0572   }
0573 
0574   if (dummyH != 0) {
0575     edm::LogError("L1GtTriggerMenuXmlParser") << "Too large hex-value!" << std::endl;
0576     return false;
0577   }
0578 
0579   dst = tempUInt;
0580 
0581   return true;
0582 }
0583 
0584 /**
0585  * countConditionChildMaxBits Count the set bits in the max attribute.
0586  *     Needed for the wsc-values to determine 180 degree.
0587  *
0588  * @param node The xml node of the condition.
0589  * @param childName The name of the child
0590  * @param dst The destination to write the number of bits.
0591  *
0592  * @return true if the bits could be determined, otherwise false.
0593  */
0594 
0595 bool L1GtTriggerMenuXmlParser::countConditionChildMaxBits(XERCES_CPP_NAMESPACE::DOMNode* node,
0596                                                           const std::string& childName,
0597                                                           unsigned int& dst) {
0598   XERCES_CPP_NAMESPACE_USE
0599 
0600   // should never happen...
0601   if (node == nullptr) {
0602     LogDebug("L1GtTriggerMenuXmlParser") << "node == 0 in " << __PRETTY_FUNCTION__ << std::endl;
0603 
0604     return false;
0605   }
0606 
0607   DOMNode* n1 = findXMLChild(node->getFirstChild(), childName);
0608 
0609   if (n1 == nullptr) {
0610     LogDebug("L1GtTriggerMenuXmlParser") << "Child of condition not found ( " << childName << ")" << std::endl;
0611 
0612     return false;
0613   }
0614 
0615   DOMNode* n2 = findXMLChild(n1->getFirstChild(), m_xmlTagValue);
0616 
0617   if (n2 == nullptr) {
0618     LogDebug("L1GtTriggerMenuXmlParser") << "No value tag found for child " << childName << " in "
0619                                          << __PRETTY_FUNCTION__ << std::endl;
0620 
0621     return false;
0622   }
0623 
0624   // first try direct
0625   std::string maxString = getXMLAttribute(n1, m_xmlAttrMax);  // string for the maxbits
0626 
0627   if (maxString.empty()) {
0628     maxString = getXMLAttribute(n2, m_xmlAttrMax);  // try next value tag
0629     // if no max was found neither in value nor in the childName tag
0630     if (maxString.empty()) {
0631       LogDebug("L1GtTriggerMenuXmlParser") << "No Max value found for " << childName << std::endl;
0632 
0633       return false;
0634     }
0635   }
0636 
0637   // do the hex conversion
0638 
0639   uint64_t maxBitsL, maxBitsH;
0640   if (!hexString2UInt128(maxString, maxBitsL, maxBitsH)) {
0641     return false;
0642   }
0643 
0644   // count the bits
0645   //LogTrace("L1GtTriggerMenuXmlParser")
0646   //<< std::dec
0647   //<< "        words: dec: high (MSB) word = " << maxBitsH << " low word = " << maxBitsL
0648   //<< std::hex << "\n"
0649   //<< "        words: hex: high (MSB) word = " << maxBitsH << " low word = " << maxBitsL
0650   //<< std::dec
0651   //<< std::endl;
0652 
0653   unsigned int counter = 0;
0654 
0655   while (maxBitsL != 0) {
0656     // check if bits set countinously
0657     if ((maxBitsL & 1) == 0) {
0658       edm::LogError("L1GtTriggerMenuXmlParser") << "      Confused by not continous set bits for max value "
0659                                                 << maxString << "(child=" << childName << ")" << std::endl;
0660 
0661       return false;
0662     }
0663 
0664     maxBitsL >>= 1;
0665     counter++;
0666   }
0667 
0668   if ((maxBitsH != 0) && (counter != 64)) {
0669     edm::LogError("L1GtTriggerMenuXmlParser") << "      Confused by not continous set bits for max value " << maxString
0670                                               << "(child=" << childName << ")" << std::endl;
0671 
0672     return false;
0673   }
0674 
0675   while (maxBitsH != 0) {
0676     //check if bits set countinously
0677     if ((maxBitsH & 1) == 0) {
0678       edm::LogError("L1GtTriggerMenuXmlParser") << "      Confused by not continous set bits for max value "
0679                                                 << maxString << "(child=" << childName << ")" << std::endl;
0680 
0681       return false;
0682     }
0683 
0684     maxBitsH >>= 1;
0685     counter++;
0686   }
0687 
0688   dst = counter;
0689   return true;
0690 }
0691 
0692 /**
0693  * getConditionChildValues - Get values from a child of a condition.
0694  *
0695  * @param node The xml node of the condition.
0696  * @param childName The name of the child the values should be extracted from.
0697  * @param num The number of values needed.
0698  * @param dst A pointer to a vector of uint64_t where the results are written.
0699  *
0700  * @return true if succeeded. false if an error occurred or not enough values found.
0701  */
0702 
0703 bool L1GtTriggerMenuXmlParser::getConditionChildValues(XERCES_CPP_NAMESPACE::DOMNode* node,
0704                                                        const std::string& childName,
0705                                                        unsigned int num,
0706                                                        std::vector<uint64_t>& dst) {
0707   XERCES_CPP_NAMESPACE_USE
0708 
0709   if (node == nullptr) {
0710     LogDebug("L1GtTriggerMenuXmlParser") << "node == 0 in " << __PRETTY_FUNCTION__ << std::endl;
0711 
0712     return false;
0713   }
0714 
0715   DOMNode* n1 = findXMLChild(node->getFirstChild(), childName);
0716 
0717   // if child not found
0718   if (n1 == nullptr) {
0719     LogDebug("L1GtTriggerMenuXmlParser") << "Child of condition not found ( " << childName << ")" << std::endl;
0720 
0721     return false;
0722   }
0723 
0724   // no values are sucessfull
0725   if (num == 0) {
0726     return true;
0727   }
0728 
0729   //
0730   dst.reserve(num);
0731 
0732   //
0733   n1 = findXMLChild(n1->getFirstChild(), m_xmlTagValue);
0734   for (unsigned int i = 0; i < num; i++) {
0735     if (n1 == nullptr) {
0736       LogDebug("L1GtTriggerMenuXmlParser")
0737           << "Not enough values in condition child ( " << childName << ")" << std::endl;
0738 
0739       return false;
0740     }
0741 
0742     if (!getXMLHexTextValue(n1, dst[i])) {
0743       edm::LogError("L1GtTriggerMenuXmlParser")
0744           << "Error converting condition child ( " << childName << ") value." << std::endl;
0745 
0746       return false;
0747     }
0748 
0749     n1 = findXMLChild(n1->getNextSibling(), m_xmlTagValue);  // next child
0750   }
0751 
0752   return true;
0753 }
0754 
0755 /**
0756  * cleanupXML - Delete parser and error handler. Shutdown XMLPlatformUtils.
0757  *
0758  * @param parser A reference to the parser to be deleted.
0759  *
0760  */
0761 
0762 void L1GtTriggerMenuXmlParser::cleanupXML(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
0763   XERCES_CPP_NAMESPACE_USE
0764 
0765   if (parser != nullptr) {
0766     delete parser;
0767   }
0768 
0769   if (m_xmlErrHandler != nullptr) {
0770     delete m_xmlErrHandler;
0771     m_xmlErrHandler = nullptr;
0772   }
0773 
0774   cms::concurrency::xercesTerminate();
0775 }
0776 
0777 // methods for the VME file
0778 
0779 /**
0780  * parseVmeXML parse a xml file
0781  *
0782  * @param parser The parser to use for parsing the file.
0783  *
0784  * @return true if succeeded, false if an error occurred.
0785  *
0786  */
0787 
0788 bool L1GtTriggerMenuXmlParser::parseVmeXML(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
0789   XERCES_CPP_NAMESPACE_USE
0790 
0791   DOMDocument* doc = parser->getDocument();
0792   DOMNode* n1 = doc->getFirstChild();
0793 
0794   if (n1 == nullptr) {
0795     edm::LogError("L1GtTriggerMenuXmlParser") << "Error: Found no XML child" << std::endl;
0796 
0797     return false;
0798   }
0799 
0800   // find "vme"-tag
0801   n1 = findXMLChild(n1, m_xmlTagVme);
0802   if (n1 == nullptr) {
0803     edm::LogError("L1GtTriggerMenuXmlParser") << "Error: No vme tag found." << std::endl;
0804     return false;
0805   }
0806 
0807   n1 = n1->getFirstChild();
0808 
0809   unsigned int chipCounter = 0;  // count chips
0810 
0811   while (chipCounter < m_numberConditionChips) {
0812     n1 = findXMLChild(n1, m_xmlTagChip, true);
0813     if (n1 == nullptr) {
0814       // just break if no more chips found
0815       break;
0816     }
0817 
0818     // node for a particle
0819     //DOMNode* particleNode = n1->getFirstChild(); // FIXME un-comment
0820 
0821     // FIXME parse vme.xml, modify the menu
0822 
0823     n1 = n1->getNextSibling();
0824     chipCounter++;
0825   }  // end while chipCounter
0826 
0827   return true;
0828 }
0829 
0830 // methods for conditions and algorithms
0831 
0832 // clearMaps - delete all conditions and algorithms in
0833 // the maps and clear the maps.
0834 void L1GtTriggerMenuXmlParser::clearMaps() {
0835   // loop over condition maps (one map per condition chip)
0836   // then loop over conditions in the map
0837   for (std::vector<ConditionMap>::iterator itCondOnChip = m_conditionMap.begin(); itCondOnChip != m_conditionMap.end();
0838        itCondOnChip++) {
0839     // the conditions in the maps are deleted in L1GtTriggerMenu, not here
0840 
0841     itCondOnChip->clear();
0842   }
0843 
0844   // the algorithms in the maps are deleted in L1GtTriggerMenu, not here
0845   m_algorithmMap.clear();
0846 }
0847 
0848 // insertConditionIntoMap - safe insert of condition into condition map.
0849 // if the condition name already exists, do not insert it and return false
0850 bool L1GtTriggerMenuXmlParser::insertConditionIntoMap(L1GtCondition& cond, const int chipNr) {
0851   std::string cName = cond.condName();
0852   //LogTrace("L1GtTriggerMenuXmlParser")
0853   //<< "    Trying to insert condition \"" << cName << "\" in the condition map." ;
0854 
0855   // no condition name has to appear twice!
0856   if ((m_conditionMap[chipNr]).count(cName) != 0) {
0857     LogTrace("L1GtTriggerMenuXmlParser") << "      Condition " << cName << " already exists - not inserted!"
0858                                          << std::endl;
0859     return false;
0860   }
0861 
0862   (m_conditionMap[chipNr])[cName] = &cond;
0863   //LogTrace("L1GtTriggerMenuXmlParser")
0864   //<< "      OK - condition inserted!"
0865   //<< std::endl;
0866 
0867   return true;
0868 }
0869 
0870 // insert an algorithm into algorithm map
0871 bool L1GtTriggerMenuXmlParser::insertAlgorithmIntoMap(const L1GtAlgorithm& alg) {
0872   std::string algName = alg.algoName();
0873   const std::string& algAlias = alg.algoAlias();
0874   //LogTrace("L1GtTriggerMenuXmlParser")
0875   //<< "    Trying to insert algorithm \"" << algName << "\" in the algorithm map." ;
0876 
0877   // no algorithm name has to appear twice!
0878   if (m_algorithmMap.count(algName) != 0) {
0879     LogTrace("L1GtTriggerMenuXmlParser") << "      Algorithm \"" << algName
0880                                          << "\"already exists in the algorithm map- not inserted!" << std::endl;
0881     return false;
0882   }
0883 
0884   if (m_algorithmAliasMap.count(algAlias) != 0) {
0885     LogTrace("L1GtTriggerMenuXmlParser") << "      Algorithm alias \"" << algAlias
0886                                          << "\"already exists in the algorithm alias map- not inserted!" << std::endl;
0887     return false;
0888   }
0889 
0890   // bit number less than zero or greater than maximum number of algorithms
0891   int bitNumber = alg.algoBitNumber();
0892   if ((bitNumber < 0) || (bitNumber >= static_cast<int>(m_numberPhysTriggers))) {
0893     LogTrace("L1GtTriggerMenuXmlParser") << "      Bit number " << bitNumber << " outside allowed range [0, "
0894                                          << m_numberPhysTriggers << ") - algorithm not inserted!" << std::endl;
0895     return false;
0896   }
0897 
0898   // maximum number of algorithms
0899   if (m_algorithmMap.size() >= m_numberPhysTriggers) {
0900     LogTrace("L1GtTriggerMenuXmlParser") << "      More than maximum allowed " << m_numberPhysTriggers
0901                                          << " algorithms in the algorithm map - not inserted!" << std::endl;
0902     return false;
0903   }
0904 
0905   // chip number outside allowed values
0906   int chipNr = alg.algoChipNumber(
0907       static_cast<int>(m_numberConditionChips), static_cast<int>(m_pinsOnConditionChip), m_orderConditionChip);
0908 
0909   if ((chipNr < 0) || (chipNr > static_cast<int>(m_numberConditionChips))) {
0910     LogTrace("L1GtTriggerMenuXmlParser") << "      Chip number " << chipNr << " outside allowed range [0, "
0911                                          << m_numberConditionChips << ") - algorithm not inserted!" << std::endl;
0912     return false;
0913   }
0914 
0915   // output pin outside allowed values
0916   int outputPin = alg.algoOutputPin(
0917       static_cast<int>(m_numberConditionChips), static_cast<int>(m_pinsOnConditionChip), m_orderConditionChip);
0918 
0919   if ((outputPin < 0) || (outputPin > static_cast<int>(m_pinsOnConditionChip))) {
0920     LogTrace("L1GtTriggerMenuXmlParser") << "      Output pin " << outputPin << " outside allowed range [0, "
0921                                          << m_pinsOnConditionChip << "] - algorithm not inserted!" << std::endl;
0922     return false;
0923   }
0924 
0925   // no two algorithms on the same chip can have the same output pin
0926   for (CItAlgo itAlgo = m_algorithmMap.begin(); itAlgo != m_algorithmMap.end(); itAlgo++) {
0927     int iPin = (itAlgo->second)
0928                    .algoOutputPin(static_cast<int>(m_numberConditionChips),
0929                                   static_cast<int>(m_pinsOnConditionChip),
0930                                   m_orderConditionChip);
0931     std::string iName = itAlgo->first;
0932     int iChip = (itAlgo->second)
0933                     .algoChipNumber(static_cast<int>(m_numberConditionChips),
0934                                     static_cast<int>(m_pinsOnConditionChip),
0935                                     m_orderConditionChip);
0936 
0937     if ((outputPin == iPin) && (chipNr == iChip)) {
0938       LogTrace("L1GtTriggerMenuXmlParser")
0939           << "      Output pin " << outputPin << " is the same as for algorithm " << iName
0940           << "\n      from the same chip number " << chipNr << " - algorithm not inserted!" << std::endl;
0941       return false;
0942     }
0943   }
0944 
0945   // insert algorithm
0946   m_algorithmMap[algName] = alg;
0947   m_algorithmAliasMap[algAlias] = alg;
0948 
0949   //LogTrace("L1GtTriggerMenuXmlParser")
0950   //<< "      OK - algorithm inserted!"
0951   //<< std::endl;
0952 
0953   return true;
0954 }
0955 
0956 // insert a technical trigger into technical trigger map
0957 bool L1GtTriggerMenuXmlParser::insertTechTriggerIntoMap(const L1GtAlgorithm& alg) {
0958   std::string algName = alg.algoName();
0959   //LogTrace("L1GtTriggerMenuXmlParser")
0960   //<< "    Trying to insert technical trigger \"" << algName
0961   //<< "\" in the technical trigger map." ;
0962 
0963   // no technical trigger name has to appear twice!
0964   if (m_technicalTriggerMap.count(algName) != 0) {
0965     LogTrace("L1GtTriggerMenuXmlParser") << "      Technical trigger \"" << algName
0966                                          << "\"already exists in the technical trigger map- not inserted!" << std::endl;
0967     return false;
0968   }
0969 
0970   // bit number less than zero or greater than maximum number of technical triggers
0971   int bitNumber = alg.algoBitNumber();
0972   if ((bitNumber < 0) || (bitNumber >= static_cast<int>(m_numberTechTriggers))) {
0973     LogTrace("L1GtTriggerMenuXmlParser") << "      Bit number " << bitNumber << " outside allowed range [0, "
0974                                          << m_numberTechTriggers << ") - technical trigger not inserted!" << std::endl;
0975     return false;
0976   }
0977 
0978   // no two technical triggers can have the same bit number
0979   for (CItAlgo itAlgo = m_technicalTriggerMap.begin(); itAlgo != m_technicalTriggerMap.end(); itAlgo++) {
0980     int iBitNumber = (itAlgo->second).algoBitNumber();
0981     std::string iName = itAlgo->first;
0982 
0983     if (iBitNumber == bitNumber) {
0984       LogTrace("L1GtTriggerMenuXmlParser")
0985           << "      Bit number " << iBitNumber << " is the same as for technical trigger " << iName
0986           << " - technical trigger not inserted!" << std::endl;
0987       return false;
0988     }
0989   }
0990 
0991   // maximum number of technical triggers
0992   if (m_technicalTriggerMap.size() >= m_numberTechTriggers) {
0993     LogTrace("L1GtTriggerMenuXmlParser") << "      More than maximum allowed " << m_numberTechTriggers
0994                                          << " technical triggers in the technical trigger map - not inserted!"
0995                                          << std::endl;
0996     return false;
0997   }
0998 
0999   // insert technical trigger
1000   m_technicalTriggerMap[algName] = alg;
1001 
1002   //LogTrace("L1GtTriggerMenuXmlParser")
1003   //<< "      OK - technical trigger inserted!"
1004   //<< std::endl;
1005 
1006   return true;
1007 }
1008 
1009 // get the type of the condition, as defined in enum, from the condition type
1010 // as defined in the XML file
1011 L1GtConditionType L1GtTriggerMenuXmlParser::getTypeFromType(const std::string& type) {
1012   if (type == m_xmlConditionAttrType1s) {
1013     return Type1s;
1014   }
1015 
1016   if (type == m_xmlConditionAttrType2s) {
1017     return Type2s;
1018   }
1019 
1020   if (type == m_xmlConditionAttrType3s) {
1021     return Type3s;
1022   }
1023 
1024   if (type == m_xmlConditionAttrType4s) {
1025     return Type4s;
1026   }
1027 
1028   if (type == m_xmlConditionAttrType2wsc) {
1029     return Type2wsc;
1030   }
1031 
1032   if (type == m_xmlConditionAttrType2cor) {
1033     return Type2cor;
1034   }
1035 
1036   return TypeNull;
1037 }
1038 
1039 /**
1040  * getNumFromType - get the number of particles from a specified type name
1041  * (for calorimeter objects and muons)
1042  *
1043  * @param type The name of the type
1044  *
1045  * @return The number of particles in this condition. -1 if type not found.
1046  */
1047 
1048 int L1GtTriggerMenuXmlParser::getNumFromType(const std::string& type) {
1049   if (type == m_xmlConditionAttrType1s) {
1050     return 1;
1051   }
1052 
1053   if (type == m_xmlConditionAttrType2s) {
1054     return 2;
1055   }
1056 
1057   if (type == m_xmlConditionAttrType3s) {
1058     return 3;
1059   }
1060 
1061   if (type == m_xmlConditionAttrType4s) {
1062     return 4;
1063   }
1064 
1065   if (type == m_xmlConditionAttrType2wsc) {
1066     return 2;
1067   }
1068 
1069   if (type == m_xmlConditionAttrType2cor) {
1070     return 2;
1071   }
1072 
1073   return -1;
1074 }
1075 
1076 /**
1077  * getBitFromNode Get a bit from a specified bitvalue node.
1078  *
1079  * @param node The xml node.
1080  *
1081  * @return The value of the bit or -1 if an error occurred.
1082  */
1083 
1084 int L1GtTriggerMenuXmlParser::getBitFromNode(XERCES_CPP_NAMESPACE::DOMNode* node) {
1085   if (getXMLAttribute(node, m_xmlAttrMode) != m_xmlAttrModeBit) {
1086     edm::LogError("L1GtTriggerMenuXmlParser") << "Invalid mode for single bit" << std::endl;
1087 
1088     return -1;
1089   }
1090 
1091   std::string tmpStr = getXMLTextValue(node);
1092   if (tmpStr == "0") {
1093     return 0;
1094   } else if (tmpStr == "1") {
1095     return 1;
1096   } else {
1097     edm::LogError("L1GtTriggerMenuXmlParser") << "Bad bit value (" << tmpStr << ")" << std::endl;
1098     return -1;
1099   }
1100 }
1101 
1102 /**
1103  * getGEqFlag - get the "greater or equal flag" from a condition
1104  *
1105  * @param node The xml node of the condition.
1106  * @nodeName The name of the node from which the flag is a subchild.
1107  *
1108  * @return The value of the flag or -1 if no flag was found.
1109  */
1110 
1111 int L1GtTriggerMenuXmlParser::getGEqFlag(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& nodeName) {
1112   XERCES_CPP_NAMESPACE_USE
1113 
1114   if (node == nullptr) {
1115     LogDebug("L1GtTriggerMenuXmlParser") << "node == 0 in " << __PRETTY_FUNCTION__ << std::endl;
1116 
1117     return -1;
1118   }
1119 
1120   // usually the GEq flag is a child of the first child (the first element node)
1121   DOMNode* n1 = node->getFirstChild();
1122   n1 = findXMLChild(n1, nodeName);
1123 
1124   if (n1 != nullptr) {
1125     n1 = findXMLChild(n1->getFirstChild(), m_xmlTagGEq);
1126     if (n1 == nullptr) {
1127       LogDebug("L1GtTriggerMenuXmlParser") << "No \"greater or equal\" tag found" << std::endl;
1128 
1129       return -1;
1130     }
1131 
1132     return getBitFromNode(n1);
1133   } else {
1134     return -1;
1135   }
1136 }
1137 
1138 /**
1139  * getMuonMipIsoBits - get MIP and Isolation bits from a muon.
1140  *
1141  * @param node The node of the condition.
1142  * @param num The number of bits required.
1143  * @param mipDst A pointer to the vector of the MIP bits.
1144  * @param isoEnDst A pointer to the vector of the "enable isolation" bits.
1145  * @param isoReqDst A pointer to the vector of the "request isolation" bits.
1146  *
1147  * @return "true" if succeeded, "false" if an error occurred.
1148  */
1149 
1150 bool L1GtTriggerMenuXmlParser::getMuonMipIsoBits(XERCES_CPP_NAMESPACE::DOMNode* node,
1151                                                  unsigned int num,
1152                                                  std::vector<bool>& mipDst,
1153                                                  std::vector<bool>& isoEnDst,
1154                                                  std::vector<bool>& isoReqDst) {
1155   XERCES_CPP_NAMESPACE_USE
1156 
1157   if (node == nullptr) {
1158     return false;
1159   }
1160 
1161   // find ptLowThreshold child
1162   DOMNode* n1 = findXMLChild(node->getFirstChild(), m_xmlTagPtLowThreshold);
1163 
1164   if (n1 == nullptr) {
1165     return false;
1166   }
1167 
1168   // get first value tag
1169   n1 = findXMLChild(n1->getFirstChild(), m_xmlTagValue);
1170 
1171   for (unsigned int i = 0; i < num; i++) {
1172     if (n1 == nullptr) {
1173       return false;
1174     }
1175 
1176     // MIP bit
1177 
1178     DOMNode* bitnode = findXMLChild(n1->getFirstChild(), m_xmlTagEnableMip);
1179     if (bitnode == nullptr) {
1180       return true;
1181     }
1182 
1183     int tmpint = getBitFromNode(bitnode);
1184     if (tmpint < 0) {
1185       return false;
1186     }
1187 
1188     mipDst[i] = (tmpint != 0);
1189 
1190     //LogTrace("L1GtTriggerMenuXmlParser")
1191     //<< "      MIP bit value for muon " << i << " = " << mipDst[i]
1192     //<< std::endl;
1193 
1194     // enable iso bit
1195     bitnode = findXMLChild(n1->getFirstChild(), m_xmlTagEnableIso);
1196     if (bitnode == nullptr) {
1197       return true;
1198     }
1199 
1200     tmpint = getBitFromNode(bitnode);
1201     if (tmpint < 0) {
1202       return false;
1203     }
1204 
1205     isoEnDst[i] = (tmpint != 0);
1206 
1207     //LogTrace("L1GtTriggerMenuXmlParser")
1208     //<< "      Enabled iso bit value for muon " << i << " = " << isoEnDst[i]
1209     //<< std::endl;
1210 
1211     // request iso bit
1212     bitnode = findXMLChild(n1->getFirstChild(), m_xmlTagRequestIso);
1213     if (bitnode == nullptr) {
1214       return true;
1215     }
1216 
1217     tmpint = getBitFromNode(bitnode);
1218     if (tmpint < 0) {
1219       return false;
1220     }
1221 
1222     isoReqDst[i] = (tmpint != 0);
1223 
1224     //LogTrace("L1GtTriggerMenuXmlParser")
1225     //<< "      Request iso bit value for muon " << i << " = " << isoReqDst[i]
1226     //<< std::endl;
1227 
1228     //
1229     n1 = findXMLChild(n1->getNextSibling(), m_xmlTagValue);  // next value
1230   }
1231 
1232   return true;
1233 }
1234 
1235 /**
1236  * parseMuon Parse a muon condition and insert an entry to the conditions map
1237  *
1238  * @param node The corresponding node.
1239  * @param name The name of the condition.
1240  * @param chipNr The number of the chip this condition is located.
1241  *
1242  * @return "true" if succeeded, "false" if an error occurred.
1243  *
1244  */
1245 
1246 bool L1GtTriggerMenuXmlParser::parseMuon(XERCES_CPP_NAMESPACE::DOMNode* node,
1247                                          const std::string& name,
1248                                          unsigned int chipNr,
1249                                          const bool corrFlag) {
1250   XERCES_CPP_NAMESPACE_USE
1251 
1252   // get condition, particle name (must be muon) and type name
1253   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
1254   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
1255   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
1256 
1257   if (particle != m_xmlConditionAttrObjectMu) {
1258     edm::LogError("L1GtTriggerMenuXmlParser") << "Wrong particle for muon-condition (" << particle << ")" << std::endl;
1259     return false;
1260   }
1261 
1262   int nrObj = getNumFromType(type);
1263   if (nrObj < 0) {
1264     edm::LogError("L1GtTriggerMenuXmlParser") << "Unknown type for muon-condition (" << type << ")"
1265                                               << "\nCan not determine number of trigger objects. " << std::endl;
1266     return false;
1267   }
1268 
1269   // get greater equal flag
1270 
1271   int intGEq = getGEqFlag(node, m_xmlTagPtHighThreshold);
1272   if (intGEq < 0) {
1273     edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag" << std::endl;
1274     return false;
1275   }
1276   // set the boolean value for the ge_eq mode
1277   bool gEq = (intGEq != 0);
1278 
1279   // get values
1280 
1281   // temporary storage of the parameters
1282   std::vector<L1GtMuonTemplate::ObjectParameter> objParameter(nrObj);
1283   L1GtMuonTemplate::CorrelationParameter corrParameter;
1284 
1285   // need at least two values for deltaPhi
1286   std::vector<uint64_t> tmpValues((nrObj > 2) ? nrObj : 2);
1287 
1288   // get ptHighThreshold values and fill into structure
1289   if (!getConditionChildValues(node, m_xmlTagPtHighThreshold, nrObj, tmpValues)) {
1290     return false;
1291   }
1292 
1293   for (int i = 0; i < nrObj; i++) {
1294     objParameter[i].ptHighThreshold = tmpValues[i];
1295 
1296     //LogTrace("L1GtTriggerMenuXmlParser")
1297     //<< "      Muon pT high threshold (hex) for muon " << i << " = "
1298     //<< std::hex << objParameter[i].ptHighThreshold << std::dec
1299     //<< std::endl;
1300   }
1301 
1302   // get ptLowThreshold values  and fill into structure
1303   if (!getConditionChildValues(node, m_xmlTagPtLowThreshold, nrObj, tmpValues)) {
1304     return false;
1305   }
1306 
1307   for (int i = 0; i < nrObj; i++) {
1308     //LogTrace("L1GtTriggerMenuXmlParser")
1309     //<< "        Muon pT low threshold word (hex) for muon " << i << " = "
1310     //<< std::hex << tmpValues[i] << std::dec
1311     //<< std::endl;
1312 
1313     // TODO FIXME stupid format in def.xml...
1314     // one takes mip bit also, therefore one divide by 16
1315     tmpValues[i] = (tmpValues[i]) / 16;
1316 
1317     objParameter[i].ptLowThreshold = tmpValues[i];
1318 
1319     //LogTrace("L1GtTriggerMenuXmlParser")
1320     //<< "      Muon pT low threshold (hex) for muon  " << i << " = "
1321     //<< std::hex << objParameter[i].ptLowThreshold << std::dec
1322     //<< std::endl;
1323   }
1324 
1325   // get qualityRange and fill into structure
1326   if (!getConditionChildValues(node, m_xmlTagQuality, nrObj, tmpValues)) {
1327     return false;
1328   }
1329 
1330   for (int i = 0; i < nrObj; i++) {
1331     objParameter[i].qualityRange = tmpValues[i];
1332 
1333     //LogTrace("L1GtTriggerMenuXmlParser")
1334     //<< "      qualityRange mask (hex) for muon " << i << " = "
1335     //<< std::hex << objParameter[i].qualityRange << std::dec
1336     //<< std::endl;
1337   }
1338 
1339   // get etaRange and fill into structure
1340   if (!getConditionChildValues(node, m_xmlTagEta, nrObj, tmpValues)) {
1341     return false;
1342   }
1343 
1344   for (int i = 0; i < nrObj; i++) {
1345     objParameter[i].etaRange = tmpValues[i];
1346 
1347     //LogTrace("L1GtTriggerMenuXmlParser")
1348     //<< "      etaRange (hex) for muon " << i << " = "
1349     //<< std::hex << objParameter[i].etaRange << std::dec
1350     //<< std::endl;
1351   }
1352 
1353   // get phiHigh values and fill into structure
1354   if (!getConditionChildValues(node, m_xmlTagPhiHigh, nrObj, tmpValues)) {
1355     return false;
1356   }
1357 
1358   for (int i = 0; i < nrObj; i++) {
1359     objParameter[i].phiHigh = tmpValues[i];
1360 
1361     //LogTrace("L1GtTriggerMenuXmlParser")
1362     //<< "      phiHigh (hex) for muon " << i << " = "
1363     //<< std::hex << objParameter[i].phiHigh << std::dec
1364     //<< std::endl;
1365   }
1366 
1367   // get phiLow values and fill into structure
1368   if (!getConditionChildValues(node, m_xmlTagPhiLow, nrObj, tmpValues)) {
1369     return false;
1370   }
1371 
1372   for (int i = 0; i < nrObj; i++) {
1373     objParameter[i].phiLow = tmpValues[i];
1374 
1375     //LogTrace("L1GtTriggerMenuXmlParser")
1376     //<< "      phiLow (hex) for muon " << i << " = "
1377     //<< std::hex << objParameter[i].phiLow << std::dec
1378     //<< std::endl;
1379   }
1380 
1381   // get charge correlation and fill into structure
1382   if (!getXMLHexTextValue(findXMLChild(node->getFirstChild(), m_xmlTagChargeCorrelation), tmpValues[0])) {
1383     LogDebug("L1GtTriggerMenuXmlParser") << "    Error getting charge correlation from muon condition (" << name << ")"
1384                                          << std::endl;
1385     return false;
1386   }
1387 
1388   corrParameter.chargeCorrelation = tmpValues[0];
1389 
1390   //LogTrace("L1GtTriggerMenuXmlParser")
1391   //<< "      charge correlation" << " = "
1392   //<< std::hex << corrParameter.chargeCorrelation << std::dec
1393   //<< std::endl;
1394 
1395   // get mip and iso bits and fill into structure
1396 
1397   std::vector<bool> tmpMip(nrObj);
1398   std::vector<bool> tmpEnableIso(nrObj);
1399   std::vector<bool> tmpRequestIso(nrObj);
1400 
1401   if (!getMuonMipIsoBits(node, nrObj, tmpMip, tmpEnableIso, tmpRequestIso)) {
1402     edm::LogError("L1GtTriggerMenuXmlParser")
1403         << "    Could not get mip and iso bits from muon condition (" << name << ")" << std::endl;
1404     return false;
1405   }
1406 
1407   for (int i = 0; i < nrObj; i++) {
1408     objParameter[i].enableMip = tmpMip[i];
1409     objParameter[i].enableIso = tmpEnableIso[i];
1410     objParameter[i].requestIso = tmpRequestIso[i];
1411   }
1412 
1413   // indicates if a correlation is used
1414   bool wscVal = (type == m_xmlConditionAttrType2wsc);
1415 
1416   if (wscVal) {
1417     // get deltaEtaRange
1418     if (!getConditionChildValues(node, m_xmlTagDeltaEta, 1, tmpValues)) {
1419       return false;
1420     }
1421 
1422     corrParameter.deltaEtaRange = tmpValues[0];
1423 
1424     // deltaPhi is larger than 64bit
1425     if (!getXMLHexTextValue128(findXMLChild(node->getFirstChild(), m_xmlTagDeltaPhi), tmpValues[0], tmpValues[1])) {
1426       edm::LogError("L1GtTriggerMenuXmlParser")
1427           << "    Could not get deltaPhi for muon condition with wsc (" << name << ")" << std::endl;
1428       return false;
1429     }
1430 
1431     corrParameter.deltaPhiRange0Word = tmpValues[0];
1432     corrParameter.deltaPhiRange1Word = tmpValues[1];
1433 
1434     // get maximum number of bits for delta phi
1435     //LogTrace("L1GtTriggerMenuXmlParser")
1436     //<< "      Counting deltaPhiMaxbits"
1437     //<< std::endl;
1438 
1439     unsigned int maxbits;
1440 
1441     if (!countConditionChildMaxBits(node, m_xmlTagDeltaPhi, maxbits)) {
1442       return false;
1443     }
1444 
1445     corrParameter.deltaPhiMaxbits = maxbits;
1446     //LogTrace("L1GtTriggerMenuXmlParser")
1447     //<< "        deltaPhiMaxbits (dec) = " << maxbits
1448     //<< std::endl;
1449   }
1450 
1451   // get the type of the condition, as defined in enum, from the condition type
1452   // as defined in the XML file
1453   L1GtConditionType cType = getTypeFromType(type);
1454   //LogTrace("L1GtTriggerMenuXmlParser")
1455   //<< "      Condition type (enum value) = " << cType
1456   //<< std::endl;
1457 
1458   if (cType == TypeNull) {
1459     edm::LogError("L1GtTriggerMenuXmlParser")
1460         << "Type for muon condition id TypeNull - it means not defined in the XML file."
1461         << "\nNumber of trigger objects is set to zero. " << std::endl;
1462     return false;
1463   }
1464 
1465   // object types - all muons
1466   std::vector<L1GtObject> objType(nrObj, Mu);
1467 
1468   // now create a new CondMuonition
1469 
1470   L1GtMuonTemplate muonCond(name);
1471 
1472   muonCond.setCondType(cType);
1473   muonCond.setObjectType(objType);
1474   muonCond.setCondGEq(gEq);
1475   muonCond.setCondChipNr(chipNr);
1476 
1477   muonCond.setConditionParameter(objParameter, corrParameter);
1478 
1479   if (edm::isDebugEnabled()) {
1480     std::ostringstream myCoutStream;
1481     muonCond.print(myCoutStream);
1482     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
1483   }
1484 
1485   // insert condition into the map and into muon template vector
1486   if (!insertConditionIntoMap(muonCond, chipNr)) {
1487     edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name << ")" << std::endl;
1488     return false;
1489   } else {
1490     if (corrFlag) {
1491       (m_corMuonTemplate[chipNr]).push_back(muonCond);
1492 
1493     } else {
1494       (m_vecMuonTemplate[chipNr]).push_back(muonCond);
1495     }
1496   }
1497 
1498   //
1499   return true;
1500 }
1501 
1502 /**
1503  * parseCalo Parse a calo condition and insert an entry to the conditions map
1504  *
1505  * @param node The corresponding node.
1506  * @param name The name of the condition.
1507  * @param chipNr The number of the chip this condition is located.
1508  *
1509  * @return "true" if succeeded, "false" if an error occurred.
1510  *
1511  */
1512 
1513 bool L1GtTriggerMenuXmlParser::parseCalo(XERCES_CPP_NAMESPACE::DOMNode* node,
1514                                          const std::string& name,
1515                                          unsigned int chipNr,
1516                                          const bool corrFlag) {
1517   XERCES_CPP_NAMESPACE_USE
1518 
1519   // get condition, particle name and type name
1520   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
1521   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
1522   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
1523 
1524   // determine object type type
1525   L1GtObject caloObjType;
1526 
1527   if (particle == m_xmlConditionAttrObjectNoIsoEG) {
1528     caloObjType = NoIsoEG;
1529   } else if (particle == m_xmlConditionAttrObjectIsoEG) {
1530     caloObjType = IsoEG;
1531   } else if (particle == m_xmlConditionAttrObjectCenJet) {
1532     caloObjType = CenJet;
1533   } else if (particle == m_xmlConditionAttrObjectTauJet) {
1534     caloObjType = TauJet;
1535   } else if (particle == m_xmlConditionAttrObjectForJet) {
1536     caloObjType = ForJet;
1537   } else {
1538     edm::LogError("L1GtTriggerMenuXmlParser") << "Wrong particle for calo-condition (" << particle << ")" << std::endl;
1539     return false;
1540   }
1541 
1542   int nrObj = getNumFromType(type);
1543   if (nrObj < 0) {
1544     edm::LogError("L1GtTriggerMenuXmlParser") << "Unknown type for calo-condition (" << type << ")"
1545                                               << "\nCan not determine number of trigger objects. " << std::endl;
1546     return false;
1547   }
1548 
1549   // get greater equal flag
1550 
1551   int intGEq = getGEqFlag(node, m_xmlTagEtThreshold);
1552   if (intGEq < 0) {
1553     edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag" << std::endl;
1554     return false;
1555   }
1556   // set the boolean value for the ge_eq mode
1557   bool gEq = (intGEq != 0);
1558 
1559   // get values
1560 
1561   // temporary storage of the parameters
1562   std::vector<L1GtCaloTemplate::ObjectParameter> objParameter(nrObj);
1563   L1GtCaloTemplate::CorrelationParameter corrParameter;
1564 
1565   // need at least one value for deltaPhiRange
1566   std::vector<uint64_t> tmpValues((nrObj > 1) ? nrObj : 1);
1567 
1568   // get etThreshold values and fill into structure
1569   if (!getConditionChildValues(node, m_xmlTagEtThreshold, nrObj, tmpValues)) {
1570     return false;
1571   }
1572 
1573   for (int i = 0; i < nrObj; i++) {
1574     objParameter[i].etThreshold = tmpValues[i];
1575 
1576     //LogTrace("L1GtTriggerMenuXmlParser")
1577     //<< "      Calo ET high threshold (hex) for calo object " << i << " = "
1578     //<< std::hex << objParameter[i].etThreshold << std::dec
1579     //<< std::endl;
1580   }
1581 
1582   // get etaRange and fill into structure
1583   if (!getConditionChildValues(node, m_xmlTagEta, nrObj, tmpValues)) {
1584     return false;
1585   }
1586 
1587   for (int i = 0; i < nrObj; i++) {
1588     objParameter[i].etaRange = tmpValues[i];
1589 
1590     //LogTrace("L1GtTriggerMenuXmlParser")
1591     //<< "      etaRange (hex) for calo object " << i << " = "
1592     //<< std::hex << objParameter[i].etaRange << std::dec
1593     //<< std::endl;
1594   }
1595 
1596   // get phiRange values and fill into structure
1597   if (!getConditionChildValues(node, m_xmlTagPhi, nrObj, tmpValues)) {
1598     return false;
1599   }
1600 
1601   for (int i = 0; i < nrObj; i++) {
1602     objParameter[i].phiRange = tmpValues[i];
1603 
1604     //LogTrace("L1GtTriggerMenuXmlParser")
1605     //<< "      phiRange (hex) for calo object " << i << " = "
1606     //<< std::hex << objParameter[i].phiRange << std::dec
1607     //<< std::endl;
1608   }
1609 
1610   // indicates if a correlation is used
1611   bool wscVal = (type == m_xmlConditionAttrType2wsc);
1612 
1613   if (wscVal) {
1614     // get deltaEtaRange
1615     if (!getConditionChildValues(node, m_xmlTagDeltaEta, 1, tmpValues)) {
1616       return false;
1617     }
1618 
1619     corrParameter.deltaEtaRange = tmpValues[0];
1620 
1621     // get deltaPhiRange
1622     if (!getConditionChildValues(node, m_xmlTagDeltaPhi, 1, tmpValues)) {
1623       return false;
1624     }
1625 
1626     corrParameter.deltaPhiRange = tmpValues[0];
1627 
1628     // get maximum number of bits for delta phi
1629     //LogTrace("L1GtTriggerMenuXmlParser")
1630     //<< "      Counting deltaPhiMaxbits"
1631     //<< std::endl;
1632 
1633     unsigned int maxbits;
1634 
1635     if (!countConditionChildMaxBits(node, m_xmlTagDeltaPhi, maxbits)) {
1636       return false;
1637     }
1638 
1639     corrParameter.deltaPhiMaxbits = maxbits;
1640     //LogTrace("L1GtTriggerMenuXmlParser")
1641     //<< "        deltaPhiMaxbits (dec) = " << maxbits
1642     //<< std::endl;
1643   }
1644 
1645   // get the type of the condition, as defined in enum, from the condition type
1646   // as defined in the XML file
1647   L1GtConditionType cType = getTypeFromType(type);
1648   //LogTrace("L1GtTriggerMenuXmlParser")
1649   //<< "      Condition type (enum value) = " << cType
1650   //<< std::endl;
1651 
1652   if (cType == TypeNull) {
1653     edm::LogError("L1GtTriggerMenuXmlParser")
1654         << "Type for calo condition id TypeNull - it means not defined in the XML file."
1655         << "\nNumber of trigger objects is set to zero. " << std::endl;
1656     return false;
1657   }
1658 
1659   // object types - all same caloObjType
1660   std::vector<L1GtObject> objType(nrObj, caloObjType);
1661 
1662   // now create a new calo condition
1663 
1664   L1GtCaloTemplate caloCond(name);
1665 
1666   caloCond.setCondType(cType);
1667   caloCond.setObjectType(objType);
1668   caloCond.setCondGEq(gEq);
1669   caloCond.setCondChipNr(chipNr);
1670 
1671   caloCond.setConditionParameter(objParameter, corrParameter);
1672 
1673   if (edm::isDebugEnabled()) {
1674     std::ostringstream myCoutStream;
1675     caloCond.print(myCoutStream);
1676     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
1677   }
1678 
1679   // insert condition into the map
1680   if (!insertConditionIntoMap(caloCond, chipNr)) {
1681     edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name << ")" << std::endl;
1682 
1683     return false;
1684   } else {
1685     if (corrFlag) {
1686       (m_corCaloTemplate[chipNr]).push_back(caloCond);
1687     } else {
1688       (m_vecCaloTemplate[chipNr]).push_back(caloCond);
1689     }
1690   }
1691 
1692   //
1693   return true;
1694 }
1695 
1696 /**
1697  * parseEnergySum Parse an "energy sum" condition and insert an entry to the conditions map
1698  *
1699  * @param node The corresponding node.
1700  * @param name The name of the condition.
1701  * @param chipNr The number of the chip this condition is located.
1702  *
1703  * @return "true" if succeeded, "false" if an error occurred.
1704  *
1705  */
1706 
1707 bool L1GtTriggerMenuXmlParser::parseEnergySum(XERCES_CPP_NAMESPACE::DOMNode* node,
1708                                               const std::string& name,
1709                                               unsigned int chipNr,
1710                                               const bool corrFlag) {
1711   XERCES_CPP_NAMESPACE_USE
1712 
1713   // get condition, particle name and type name
1714   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
1715   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
1716   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
1717 
1718   // determine object type type
1719   L1GtObject energySumObjType;
1720   L1GtConditionType cType;
1721 
1722   if ((particle == m_xmlConditionAttrObjectETM) && (type == m_xmlConditionAttrObjectETM)) {
1723     energySumObjType = ETM;
1724     cType = TypeETM;
1725 
1726   } else if ((particle == m_xmlConditionAttrObjectETT) && (type == m_xmlConditionAttrObjectETT)) {
1727     energySumObjType = ETT;
1728     cType = TypeETT;
1729 
1730   } else if ((particle == m_xmlConditionAttrObjectHTT) && (type == m_xmlConditionAttrObjectHTT)) {
1731     energySumObjType = HTT;
1732     cType = TypeHTT;
1733 
1734   } else if ((particle == m_xmlConditionAttrObjectHTM) && (type == m_xmlConditionAttrObjectHTM)) {
1735     energySumObjType = HTM;
1736     cType = TypeHTM;
1737 
1738   } else {
1739     edm::LogError("L1GtTriggerMenuXmlParser")
1740         << "Wrong particle or type for energy-sum condition (" << particle << ", " << type << ")" << std::endl;
1741     return false;
1742   }
1743 
1744   // global object
1745   int nrObj = 1;
1746 
1747   // get greater equal flag
1748 
1749   int intGEq = getGEqFlag(node, m_xmlTagEtThreshold);
1750   if (intGEq < 0) {
1751     edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag" << std::endl;
1752     return false;
1753   }
1754   // set the boolean value for the ge_eq mode
1755   bool gEq = (intGEq != 0);
1756 
1757   // get values
1758 
1759   // temporary storage of the parameters
1760   std::vector<L1GtEnergySumTemplate::ObjectParameter> objParameter(nrObj);
1761 
1762   // need at least two values for phi
1763   std::vector<uint64_t> tmpValues((nrObj > 2) ? nrObj : 2);
1764 
1765   // get etThreshold values and fill into structure
1766   if (!getConditionChildValues(node, m_xmlTagEtThreshold, nrObj, tmpValues)) {
1767     return false;
1768   }
1769 
1770   for (int i = 0; i < nrObj; i++) {
1771     objParameter[i].etThreshold = tmpValues[i];
1772 
1773     //LogTrace("L1GtTriggerMenuXmlParser")
1774     //<< "      EnergySum ET high threshold (hex) for energySum object " << i << " = "
1775     //<< std::hex << objParameter[i].etThreshold << std::dec
1776     //<< std::endl;
1777 
1778     // for ETM and HTM read phi value
1779     // phi is larger than 64 bits for ETM - it needs two 64bits words
1780     // phi is less than 64 bits for HTM   - it needs one 64bits word
1781     if (energySumObjType == ETM) {
1782       if (!getXMLHexTextValue128(findXMLChild(node->getFirstChild(), m_xmlTagPhi), tmpValues[0], tmpValues[1])) {
1783         edm::LogError("L1GtTriggerMenuXmlParser")
1784             << "    Could not get phi for ETM condition (" << name << ")" << std::endl;
1785         return false;
1786       }
1787 
1788       objParameter[i].phiRange0Word = tmpValues[0];
1789       objParameter[i].phiRange1Word = tmpValues[1];
1790 
1791     } else if (energySumObjType == HTM) {
1792       if (!getXMLHexTextValue(findXMLChild(node->getFirstChild(), m_xmlTagPhi), tmpValues[0])) {
1793         edm::LogError("L1GtTriggerMenuXmlParser")
1794             << "    Could not get phi for HTM condition (" << name << ")" << std::endl;
1795         return false;
1796       }
1797 
1798       objParameter[i].phiRange0Word = tmpValues[0];
1799     }
1800 
1801     // get energyOverflow logical flag and fill into structure
1802     DOMNode* n1;
1803     if ((n1 = findXMLChild(node->getFirstChild(), m_xmlTagEtThreshold)) == nullptr) {
1804       edm::LogError("L1GtTriggerMenuXmlParser")
1805           << "    Could not get energyOverflow for EnergySum condition (" << name << ")" << std::endl;
1806       return false;
1807     }
1808     if ((n1 = findXMLChild(n1->getFirstChild(), m_xmlTagEnergyOverflow)) == nullptr) {
1809       edm::LogError("L1GtTriggerMenuXmlParser")
1810           << "    Could not get energyOverflow for EnergySum condition (" << name << ")" << std::endl;
1811       return false;
1812     }
1813 
1814     int tmpInt = getBitFromNode(n1);
1815     if (tmpInt == 0) {
1816       objParameter[i].energyOverflow = false;
1817 
1818       //LogTrace("L1GtTriggerMenuXmlParser")
1819       //<< "      EnergySum energyOverflow logical flag (hex) = "
1820       //<< std::hex << objParameter[i].energyOverflow << std::dec
1821       //<< std::endl;
1822     } else if (tmpInt == 1) {
1823       objParameter[i].energyOverflow = true;
1824 
1825       //LogTrace("L1GtTriggerMenuXmlParser")
1826       //<< "      EnergySum energyOverflow logical flag (hex) = "
1827       //<< std::hex << objParameter[i].energyOverflow << std::dec
1828       //<< std::endl;
1829     } else {
1830       LogTrace("L1GtTriggerMenuXmlParser") << "      EnergySum energyOverflow logical flag (hex) = " << std::hex
1831                                            << tmpInt << std::dec << " - wrong value! " << std::endl;
1832       return false;
1833     }
1834   }
1835 
1836   // object types - all same energySumObjType
1837   std::vector<L1GtObject> objType(nrObj, energySumObjType);
1838 
1839   // now create a new energySum condition
1840 
1841   L1GtEnergySumTemplate energySumCond(name);
1842 
1843   energySumCond.setCondType(cType);
1844   energySumCond.setObjectType(objType);
1845   energySumCond.setCondGEq(gEq);
1846   energySumCond.setCondChipNr(chipNr);
1847 
1848   energySumCond.setConditionParameter(objParameter);
1849 
1850   if (edm::isDebugEnabled()) {
1851     std::ostringstream myCoutStream;
1852     energySumCond.print(myCoutStream);
1853     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
1854   }
1855 
1856   // insert condition into the map
1857   if (!insertConditionIntoMap(energySumCond, chipNr)) {
1858     edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name << ")" << std::endl;
1859 
1860     return false;
1861   } else {
1862     if (corrFlag) {
1863       (m_corEnergySumTemplate[chipNr]).push_back(energySumCond);
1864 
1865     } else {
1866       (m_vecEnergySumTemplate[chipNr]).push_back(energySumCond);
1867     }
1868   }
1869 
1870   //
1871   return true;
1872 }
1873 
1874 /**
1875  * parseJetCounts Parse a "jet counts" condition and
1876  * insert an entry to the conditions map
1877  *
1878  * @param node The corresponding node.
1879  * @param name The name of the condition.
1880  * @param chipNr The number of the chip this condition is located.
1881  *
1882  * @return "true" if succeeded, "false" if an error occurred.
1883  *
1884  */
1885 
1886 bool L1GtTriggerMenuXmlParser::parseJetCounts(XERCES_CPP_NAMESPACE::DOMNode* node,
1887                                               const std::string& name,
1888                                               unsigned int chipNr) {
1889   XERCES_CPP_NAMESPACE_USE
1890 
1891   // get condition, particle name and type name
1892   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
1893   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
1894   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
1895 
1896   if (particle != m_xmlConditionAttrObjectJetCounts) {
1897     edm::LogError("L1GtTriggerMenuXmlParser")
1898         << "Wrong particle for JetCounts condition (" << particle << ")" << std::endl;
1899     return false;
1900   }
1901 
1902   // object type and condition type
1903   L1GtObject jetCountsObjType = JetCounts;
1904   L1GtConditionType cType = TypeJetCounts;
1905 
1906   // global object
1907   int nrObj = 1;
1908 
1909   // get greater equal flag
1910 
1911   int intGEq = getGEqFlag(node, m_xmlTagCountThreshold);
1912   if (intGEq < 0) {
1913     edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag" << std::endl;
1914     return false;
1915   }
1916   // set the boolean value for the ge_eq mode
1917   bool gEq = (intGEq != 0);
1918 
1919   // get values
1920 
1921   // temporary storage of the parameters
1922   std::vector<L1GtJetCountsTemplate::ObjectParameter> objParameter(nrObj);
1923 
1924   // get countIndex value and fill into structure
1925   // they are expressed in  base 10  (values: 0 - m_numberL1JetCounts)
1926   char* endPtr = nullptr;
1927   long int typeInt = strtol(type.c_str(), &endPtr, 10);  // base = 10
1928 
1929   if (*endPtr != 0) {
1930     LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << type << " to dec." << std::endl;
1931 
1932     return false;
1933   }
1934 
1935   // test if count index is out of range
1936   if ((typeInt < 0) || (typeInt > static_cast<int>(m_numberL1JetCounts))) {
1937     LogDebug("L1GtTriggerMenuXmlParser") << "Count index " << typeInt << " outside range [0, " << m_numberL1JetCounts
1938                                          << "]" << std::endl;
1939 
1940     return false;
1941   }
1942 
1943   objParameter[0].countIndex = static_cast<unsigned int>(typeInt);
1944 
1945   // get count threshold values and fill into structure
1946   std::vector<uint64_t> tmpValues(nrObj);
1947 
1948   if (!getConditionChildValues(node, m_xmlTagCountThreshold, nrObj, tmpValues)) {
1949     return false;
1950   }
1951 
1952   for (int i = 0; i < nrObj; i++) {
1953     objParameter[i].countThreshold = tmpValues[i];
1954 
1955     //LogTrace("L1GtTriggerMenuXmlParser")
1956     //<< "      JetCounts count threshold (hex) for JetCounts object " << i << " = "
1957     //<< std::hex << objParameter[i].countThreshold << std::dec
1958     //<< std::endl;
1959 
1960     // TODO FIXME un-comment when tag available in XML file
1961 
1962     //        // get countOverflow logical flag and fill into structure
1963     //        DOMNode* n1;
1964     //        if ( (n1 = findXMLChild(node->getFirstChild(), m_xmlTagCountThreshold)) == 0) {
1965     //            edm::LogError("L1GtTriggerMenuXmlParser")
1966     //            << "    Could not get countOverflow for JetCounts condition ("
1967     //            << name << ")"
1968     //            << std::endl;
1969     //            return false;
1970     //        }
1971     //        if ( (n1 = findXMLChild(n1->getFirstChild(), m_xmlTagCountThreshold)) == 0) {
1972     //            edm::LogError("L1GtTriggerMenuXmlParser")
1973     //            << "    Could not get countOverflow for JetCounts condition ("
1974     //            << name << ")"
1975     //            << std::endl;
1976     //            return false;
1977     //        }
1978     //
1979     //        int tmpInt = getBitFromNode(n1);
1980     //        if (tmpInt == 0) {
1981     //            objParameter[i].countOverflow = false;
1982     //
1983     //            LogTrace("L1GtTriggerMenuXmlParser")
1984     //            << "      JetCounts countOverflow logical flag (hex) = "
1985     //            << std::hex << objParameter[i].countOverflow << std::dec
1986     //            << std::endl;
1987     //        } else if (tmpInt == 1) {
1988     //            objParameter[i].countOverflow = true;
1989     //
1990     //            LogTrace("L1GtTriggerMenuXmlParser")
1991     //            << "      JetCounts countOverflow logical flag (hex) = "
1992     //            << std::hex << objParameter[i].countOverflow << std::dec
1993     //            << std::endl;
1994     //        } else {
1995     //            LogTrace("L1GtTriggerMenuXmlParser")
1996     //            << "      JetCounts countOverflow logical flag (hex) = "
1997     //            << std::hex << tmpInt << std::dec << " - wrong value! "
1998     //            << std::endl;
1999     //            return false;
2000     //        }
2001   }
2002 
2003   // object types - all same objType
2004   std::vector<L1GtObject> objType(nrObj, jetCountsObjType);
2005 
2006   // now create a new JetCounts condition
2007 
2008   L1GtJetCountsTemplate jetCountsCond(name);
2009 
2010   jetCountsCond.setCondType(cType);
2011   jetCountsCond.setObjectType(objType);
2012   jetCountsCond.setCondGEq(gEq);
2013   jetCountsCond.setCondChipNr(chipNr);
2014 
2015   jetCountsCond.setConditionParameter(objParameter);
2016 
2017   if (edm::isDebugEnabled()) {
2018     std::ostringstream myCoutStream;
2019     jetCountsCond.print(myCoutStream);
2020     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
2021   }
2022 
2023   // insert condition into the map
2024   if (!insertConditionIntoMap(jetCountsCond, chipNr)) {
2025     edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name << ")" << std::endl;
2026 
2027     return false;
2028   } else {
2029     (m_vecJetCountsTemplate[chipNr]).push_back(jetCountsCond);
2030   }
2031 
2032   //
2033   return true;
2034 }
2035 
2036 /**
2037  * parseCastor Parse a CASTOR condition and
2038  * insert an entry to the conditions map
2039  *
2040  * @param node The corresponding node.
2041  * @param name The name of the condition.
2042  * @param chipNr The number of the chip this condition is located.
2043  *
2044  * @return "true" if succeeded, "false" if an error occurred.
2045  *
2046  */
2047 
2048 bool L1GtTriggerMenuXmlParser::parseCastor(XERCES_CPP_NAMESPACE::DOMNode* node,
2049                                            const std::string& name,
2050                                            unsigned int chipNr) {
2051   XERCES_CPP_NAMESPACE_USE
2052 
2053   // get condition, particle name and type name
2054   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
2055   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
2056   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
2057 
2058   if (particle != m_xmlConditionAttrObjectCastor) {
2059     edm::LogError("L1GtTriggerMenuXmlParser")
2060         << "\nError: wrong particle for Castor condition (" << particle << ")" << std::endl;
2061     return false;
2062   }
2063 
2064   // object type and condition type
2065   // object type - irrelevant for CASTOR conditions
2066   L1GtConditionType cType = TypeCastor;
2067 
2068   // no objects for CASTOR conditions
2069 
2070   // set the boolean value for the ge_eq mode - irrelevant for CASTOR conditions
2071   bool gEq = false;
2072 
2073   // now create a new CASTOR condition
2074 
2075   L1GtCastorTemplate castorCond(name);
2076 
2077   castorCond.setCondType(cType);
2078   castorCond.setCondGEq(gEq);
2079   castorCond.setCondChipNr(chipNr);
2080 
2081   if (edm::isDebugEnabled()) {
2082     std::ostringstream myCoutStream;
2083     castorCond.print(myCoutStream);
2084     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
2085   }
2086 
2087   // insert condition into the map
2088   if (!insertConditionIntoMap(castorCond, chipNr)) {
2089     edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name << ")" << std::endl;
2090 
2091     return false;
2092   } else {
2093     (m_vecCastorTemplate[chipNr]).push_back(castorCond);
2094   }
2095 
2096   //
2097   return true;
2098 }
2099 
2100 /**
2101  * parseHfBitCounts Parse a "HF bit counts" condition and
2102  * insert an entry to the conditions map
2103  *
2104  * @param node The corresponding node.
2105  * @param name The name of the condition.
2106  * @param chipNr The number of the chip this condition is located.
2107  *
2108  * @return "true" if succeeded, "false" if an error occurred.
2109  *
2110  */
2111 
2112 bool L1GtTriggerMenuXmlParser::parseHfBitCounts(XERCES_CPP_NAMESPACE::DOMNode* node,
2113                                                 const std::string& name,
2114                                                 unsigned int chipNr) {
2115   XERCES_CPP_NAMESPACE_USE
2116 
2117   // get condition, particle name and type name
2118   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
2119   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
2120   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
2121 
2122   if (particle != m_xmlConditionAttrObjectHfBitCounts) {
2123     edm::LogError("L1GtTriggerMenuXmlParser")
2124         << "Wrong particle for HfBitCounts condition (" << particle << ")" << std::endl;
2125     return false;
2126   }
2127 
2128   // object type and condition type
2129   L1GtObject hfBitCountsObjType = HfBitCounts;
2130   L1GtConditionType cType = TypeHfBitCounts;
2131 
2132   // global object
2133   int nrObj = 1;
2134 
2135   // get greater equal flag
2136 
2137   int intGEq = getGEqFlag(node, m_xmlTagCountThreshold);
2138   if (intGEq < 0) {
2139     edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag" << std::endl;
2140     return false;
2141   }
2142   // set the boolean value for the ge_eq mode
2143   bool gEq = (intGEq != 0);
2144 
2145   // get values
2146 
2147   // temporary storage of the parameters
2148   std::vector<L1GtHfBitCountsTemplate::ObjectParameter> objParameter(nrObj);
2149 
2150   // get countIndex value and fill into structure
2151   // they are expressed in  base 10
2152   char* endPtr = nullptr;
2153   long int typeInt = strtol(type.c_str(), &endPtr, 10);  // base = 10
2154 
2155   if (*endPtr != 0) {
2156     LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << type << " to dec." << std::endl;
2157 
2158     return false;
2159   }
2160 
2161   // test if count index is out of range FIXME introduce m_numberL1HfBitCounts?
2162   //if ((typeInt < 0) || (typeInt > static_cast<int>(m_numberL1HfBitCounts))) {
2163   //    LogDebug("L1GtTriggerMenuXmlParser") << "Count index " << typeInt
2164   //        << " outside range [0, " << m_numberL1HfBitCounts << "]" << std::endl;
2165   //
2166   //    return false;
2167   //}
2168 
2169   objParameter[0].countIndex = static_cast<unsigned int>(typeInt);
2170 
2171   // get count threshold values and fill into structure
2172   std::vector<uint64_t> tmpValues(nrObj);
2173 
2174   if (!getConditionChildValues(node, m_xmlTagCountThreshold, nrObj, tmpValues)) {
2175     return false;
2176   }
2177 
2178   for (int i = 0; i < nrObj; i++) {
2179     objParameter[i].countThreshold = tmpValues[i];
2180 
2181     //LogTrace("L1GtTriggerMenuXmlParser")
2182     //<< "      HfBitCounts count threshold (hex) for HfBitCounts object " << i << " = "
2183     //<< std::hex << objParameter[i].countThreshold << std::dec
2184     //<< std::endl;
2185   }
2186 
2187   // object types - all same objType
2188   std::vector<L1GtObject> objType(nrObj, hfBitCountsObjType);
2189 
2190   // now create a new HfBitCounts condition
2191 
2192   L1GtHfBitCountsTemplate hfBitCountsCond(name);
2193 
2194   hfBitCountsCond.setCondType(cType);
2195   hfBitCountsCond.setObjectType(objType);
2196   hfBitCountsCond.setCondGEq(gEq);
2197   hfBitCountsCond.setCondChipNr(chipNr);
2198 
2199   hfBitCountsCond.setConditionParameter(objParameter);
2200 
2201   if (edm::isDebugEnabled()) {
2202     std::ostringstream myCoutStream;
2203     hfBitCountsCond.print(myCoutStream);
2204     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
2205   }
2206 
2207   // insert condition into the map
2208   if (!insertConditionIntoMap(hfBitCountsCond, chipNr)) {
2209     edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name << ")" << std::endl;
2210 
2211     return false;
2212   } else {
2213     (m_vecHfBitCountsTemplate[chipNr]).push_back(hfBitCountsCond);
2214   }
2215 
2216   //
2217   return true;
2218 }
2219 
2220 /**
2221  * parseHfRingEtSums Parse a "HF Ring ET sums" condition and
2222  * insert an entry to the conditions map
2223  *
2224  * @param node The corresponding node.
2225  * @param name The name of the condition.
2226  * @param chipNr The number of the chip this condition is located.
2227  *
2228  * @return "true" if succeeded, "false" if an error occurred.
2229  *
2230  */
2231 
2232 bool L1GtTriggerMenuXmlParser::parseHfRingEtSums(XERCES_CPP_NAMESPACE::DOMNode* node,
2233                                                  const std::string& name,
2234                                                  unsigned int chipNr) {
2235   XERCES_CPP_NAMESPACE_USE
2236 
2237   // get condition, particle name and type name
2238   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
2239   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
2240   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
2241 
2242   if (particle != m_xmlConditionAttrObjectHfRingEtSums) {
2243     edm::LogError("L1GtTriggerMenuXmlParser")
2244         << "Wrong particle for HfRingEtSums condition (" << particle << ")" << std::endl;
2245     return false;
2246   }
2247 
2248   // object type and condition type
2249   L1GtObject hfRingEtSumsObjType = HfRingEtSums;
2250   L1GtConditionType cType = TypeHfRingEtSums;
2251 
2252   // global object
2253   int nrObj = 1;
2254 
2255   // get greater equal flag
2256 
2257   int intGEq = getGEqFlag(node, m_xmlTagEtThreshold);
2258   if (intGEq < 0) {
2259     edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag" << std::endl;
2260     return false;
2261   }
2262   // set the boolean value for the ge_eq mode
2263   bool gEq = (intGEq != 0);
2264 
2265   // get values
2266 
2267   // temporary storage of the parameters
2268   std::vector<L1GtHfRingEtSumsTemplate::ObjectParameter> objParameter(nrObj);
2269 
2270   // get etSumIndex value and fill into structure
2271   // they are expressed in  base 10
2272   char* endPtr = nullptr;
2273   long int typeInt = strtol(type.c_str(), &endPtr, 10);  // base = 10
2274 
2275   if (*endPtr != 0) {
2276     LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << type << " to dec." << std::endl;
2277 
2278     return false;
2279   }
2280 
2281   // test if ET sum index is out of range FIXME introduce m_numberL1HfRingEtSums?
2282   //if ((typeInt < 0) || (typeInt > static_cast<int>(m_numberL1HfRingEtSums))) {
2283   //    LogDebug("L1GtTriggerMenuXmlParser") << "Count index " << typeInt
2284   //        << " outside range [0, " << m_numberL1HfRingEtSums << "]" << std::endl;
2285   //
2286   //    return false;
2287   //}
2288 
2289   objParameter[0].etSumIndex = static_cast<unsigned int>(typeInt);
2290 
2291   // get ET sum threshold values and fill into structure
2292   std::vector<uint64_t> tmpValues(nrObj);
2293 
2294   if (!getConditionChildValues(node, m_xmlTagEtThreshold, nrObj, tmpValues)) {
2295     return false;
2296   }
2297 
2298   for (int i = 0; i < nrObj; i++) {
2299     objParameter[i].etSumThreshold = tmpValues[i];
2300 
2301     //LogTrace("L1GtTriggerMenuXmlParser")
2302     //<< "      HfRingEtSums count threshold (hex) for HfRingEtSums object " << i << " = "
2303     //<< std::hex << objParameter[i].etSumThreshold << std::dec
2304     //<< std::endl;
2305   }
2306 
2307   // object types - all same objType
2308   std::vector<L1GtObject> objType(nrObj, hfRingEtSumsObjType);
2309 
2310   // now create a new HfRingEtSums condition
2311 
2312   L1GtHfRingEtSumsTemplate hfRingEtSumsCond(name);
2313 
2314   hfRingEtSumsCond.setCondType(cType);
2315   hfRingEtSumsCond.setObjectType(objType);
2316   hfRingEtSumsCond.setCondGEq(gEq);
2317   hfRingEtSumsCond.setCondChipNr(chipNr);
2318 
2319   hfRingEtSumsCond.setConditionParameter(objParameter);
2320 
2321   if (edm::isDebugEnabled()) {
2322     std::ostringstream myCoutStream;
2323     hfRingEtSumsCond.print(myCoutStream);
2324     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
2325   }
2326 
2327   // insert condition into the map
2328   if (!insertConditionIntoMap(hfRingEtSumsCond, chipNr)) {
2329     edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name << ")" << std::endl;
2330 
2331     return false;
2332   } else {
2333     (m_vecHfRingEtSumsTemplate[chipNr]).push_back(hfRingEtSumsCond);
2334   }
2335 
2336   //
2337   return true;
2338 }
2339 
2340 /**
2341  * parseBptx Parse a BPTX condition and
2342  * insert an entry to the conditions map
2343  *
2344  * @param node The corresponding node.
2345  * @param name The name of the condition.
2346  * @param chipNr The number of the chip this condition is located.
2347  *
2348  * @return "true" if succeeded, "false" if an error occurred.
2349  *
2350  */
2351 
2352 bool L1GtTriggerMenuXmlParser::parseBptx(XERCES_CPP_NAMESPACE::DOMNode* node,
2353                                          const std::string& name,
2354                                          unsigned int chipNr) {
2355   XERCES_CPP_NAMESPACE_USE
2356 
2357   // get condition, particle name and type name
2358   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
2359   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
2360   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
2361 
2362   if (particle != m_xmlConditionAttrObjectBptx) {
2363     edm::LogError("L1GtTriggerMenuXmlParser")
2364         << "\nError: wrong particle for Bptx condition (" << particle << ")" << std::endl;
2365     return false;
2366   }
2367 
2368   // object type and condition type
2369   // object type - irrelevant for BPTX conditions
2370   L1GtConditionType cType = TypeBptx;
2371 
2372   // no objects for BPTX conditions
2373 
2374   // set the boolean value for the ge_eq mode - irrelevant for BPTX conditions
2375   bool gEq = false;
2376 
2377   // now create a new BPTX condition
2378 
2379   L1GtBptxTemplate bptxCond(name);
2380 
2381   bptxCond.setCondType(cType);
2382   bptxCond.setCondGEq(gEq);
2383   bptxCond.setCondChipNr(chipNr);
2384 
2385   LogTrace("L1GtTriggerMenuXmlParser") << bptxCond << "\n" << std::endl;
2386 
2387   // insert condition into the map
2388   if (!insertConditionIntoMap(bptxCond, chipNr)) {
2389     edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name << ")" << std::endl;
2390 
2391     return false;
2392   } else {
2393     (m_vecBptxTemplate[chipNr]).push_back(bptxCond);
2394   }
2395 
2396   //
2397   return true;
2398 }
2399 
2400 /**
2401  * parseExternal Parse an External condition and
2402  * insert an entry to the conditions map
2403  *
2404  * @param node The corresponding node.
2405  * @param name The name of the condition.
2406  * @param chipNr The number of the chip this condition is located.
2407  *
2408  * @return "true" if succeeded, "false" if an error occurred.
2409  *
2410  */
2411 
2412 bool L1GtTriggerMenuXmlParser::parseExternal(XERCES_CPP_NAMESPACE::DOMNode* node,
2413                                              const std::string& name,
2414                                              unsigned int chipNr) {
2415   XERCES_CPP_NAMESPACE_USE
2416 
2417   // get condition, particle name and type name
2418   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
2419   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
2420   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
2421 
2422   if (particle != m_xmlConditionAttrObjectGtExternal) {
2423     edm::LogError("L1GtTriggerMenuXmlParser")
2424         << "\nError: wrong particle for External condition (" << particle << ")" << std::endl;
2425     return false;
2426   }
2427 
2428   // object type and condition type
2429   // object type - irrelevant for External conditions
2430   L1GtConditionType cType = TypeExternal;
2431 
2432   // no objects for External conditions
2433 
2434   // set the boolean value for the ge_eq mode - irrelevant for External conditions
2435   bool gEq = false;
2436 
2437   // now create a new External condition
2438 
2439   L1GtExternalTemplate externalCond(name);
2440 
2441   externalCond.setCondType(cType);
2442   externalCond.setCondGEq(gEq);
2443   externalCond.setCondChipNr(chipNr);
2444 
2445   LogTrace("L1GtTriggerMenuXmlParser") << externalCond << "\n" << std::endl;
2446 
2447   // insert condition into the map
2448   if (!insertConditionIntoMap(externalCond, chipNr)) {
2449     edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name << ")" << std::endl;
2450 
2451     return false;
2452   } else {
2453     (m_vecExternalTemplate[chipNr]).push_back(externalCond);
2454   }
2455 
2456   //
2457   return true;
2458 }
2459 
2460 /**
2461  * parseCorrelation Parse a correlation condition and
2462  * insert an entry to the conditions map
2463  *
2464  * @param node The corresponding node.
2465  * @param name The name of the condition.
2466  * @param chipNr The number of the chip this condition is located.
2467  *
2468  * @return "true" if succeeded, "false" if an error occurred.
2469  *
2470  */
2471 
2472 bool L1GtTriggerMenuXmlParser::parseCorrelation(XERCES_CPP_NAMESPACE::DOMNode* node,
2473                                                 const std::string& name,
2474                                                 unsigned int chipNr) {
2475   XERCES_CPP_NAMESPACE_USE
2476 
2477   // create a new correlation condition
2478   L1GtCorrelationTemplate correlationCond(name);
2479 
2480   // check that the condition does not exist already in the map
2481   if (!insertConditionIntoMap(correlationCond, chipNr)) {
2482     edm::LogError("L1GtTriggerMenuXmlParser")
2483         << "    Error: duplicate correlation condition (" << name << ")" << std::endl;
2484 
2485     return false;
2486   }
2487 
2488   // get condition, particle name and type name
2489   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
2490   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
2491   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
2492 
2493   LogTrace("L1GtTriggerMenuXmlParser") << "    Condition category: " << condition << ", particle: " << particle
2494                                        << ", type: " << type << "\n"
2495                                        << std::endl;
2496 
2497   // condition type
2498   L1GtConditionType cType = Type2cor;
2499 
2500   // two objects (for sure)
2501   const int nrObj = 2;
2502 
2503   // object types and greater equal flag - filled in the loop
2504   int intGEq[nrObj] = {-1, -1};
2505   std::vector<L1GtObject> objType(nrObj);
2506   std::vector<L1GtConditionCategory> condCateg(nrObj);
2507 
2508   // correlation flag and index in the cor*vector
2509   const bool corrFlag = true;
2510   int corrIndexVal[nrObj] = {-1, -1};
2511 
2512   // get the subconditions
2513 
2514   DOMNode* conditionsNode = node->getFirstChild();
2515   std::string conditionNameNodeName;
2516   conditionsNode = findXMLChild(conditionsNode, "", true, &conditionNameNodeName);
2517 
2518   for (int iSubCond = 0; iSubCond < nrObj; ++iSubCond) {
2519     // get for sub-condition:  category, object name and type name and condition name
2520     condition = getXMLAttribute(conditionsNode, m_xmlConditionAttrCondition);
2521     particle = getXMLAttribute(conditionsNode, m_xmlConditionAttrObject);
2522     type = getXMLAttribute(conditionsNode, m_xmlConditionAttrType);
2523 
2524     LogTrace("L1GtTriggerMenuXmlParser") << "    Sub-condition category: " << condition << ", particle: " << particle
2525                                          << ", type: " << type << ", name: " << conditionNameNodeName << "\n"
2526                                          << std::endl;
2527 
2528     // call the appropriate function for this condition
2529     if (condition == m_xmlConditionAttrConditionMuon) {
2530       if (!parseMuon(conditionsNode, conditionNameNodeName, chipNr, corrFlag)) {
2531         edm::LogError("L1GtTriggerMenuXmlParser") << "Error parsing sub-condition " << condition << ")"
2532                                                   << " with name " << conditionNameNodeName << std::endl;
2533       }
2534 
2535       // get greater equal flag
2536       intGEq[iSubCond] = getGEqFlag(conditionsNode, m_xmlTagPtHighThreshold);
2537       if (intGEq[iSubCond] < 0) {
2538         edm::LogError("L1GtTriggerMenuXmlParser")
2539             << "Error getting \"greater or equal\" flag"
2540             << " for sub-condition " << conditionNameNodeName << " for the correlation condition " << name << std::endl;
2541         return false;
2542       }
2543 
2544       // set object type and sub-condition category
2545       objType[iSubCond] = Mu;
2546       condCateg[iSubCond] = CondMuon;
2547       corrIndexVal[iSubCond] = (m_corMuonTemplate[chipNr]).size() - 1;
2548 
2549     } else if (condition == m_xmlConditionAttrConditionCalo) {
2550       if (!parseCalo(conditionsNode, conditionNameNodeName, chipNr, corrFlag)) {
2551         edm::LogError("L1GtTriggerMenuXmlParser") << "Error parsing sub-condition " << condition << ")"
2552                                                   << " with name " << conditionNameNodeName << std::endl;
2553       }
2554 
2555       // get greater equal flag
2556       intGEq[iSubCond] = getGEqFlag(conditionsNode, m_xmlTagEtThreshold);
2557       if (intGEq[iSubCond] < 0) {
2558         edm::LogError("L1GtTriggerMenuXmlParser")
2559             << "Error getting \"greater or equal\" flag"
2560             << " for sub-condition " << conditionNameNodeName << " for the correlation condition " << name << std::endl;
2561         return false;
2562       }
2563 
2564       // set object type and sub-condition category
2565       if (particle == m_xmlConditionAttrObjectNoIsoEG) {
2566         objType[iSubCond] = NoIsoEG;
2567       } else if (particle == m_xmlConditionAttrObjectIsoEG) {
2568         objType[iSubCond] = IsoEG;
2569       } else if (particle == m_xmlConditionAttrObjectCenJet) {
2570         objType[iSubCond] = CenJet;
2571       } else if (particle == m_xmlConditionAttrObjectTauJet) {
2572         objType[iSubCond] = TauJet;
2573       } else if (particle == m_xmlConditionAttrObjectForJet) {
2574         objType[iSubCond] = ForJet;
2575       } else {
2576         edm::LogError("L1GtTriggerMenuXmlParser")
2577             << "Wrong object type " << particle << " for sub-condition " << conditionNameNodeName
2578             << " from the correlation condition " << name << std::endl;
2579         return false;
2580       }
2581 
2582       condCateg[iSubCond] = CondCalo;
2583       corrIndexVal[iSubCond] = (m_corCaloTemplate[chipNr]).size() - 1;
2584 
2585     } else if (condition == m_xmlConditionAttrConditionEnergySum) {
2586       if (!parseEnergySum(conditionsNode, conditionNameNodeName, chipNr, corrFlag)) {
2587         edm::LogError("L1GtTriggerMenuXmlParser") << "Error parsing sub-condition " << condition << ")"
2588                                                   << " with name " << conditionNameNodeName << std::endl;
2589       }
2590 
2591       // get greater equal flag
2592       intGEq[iSubCond] = getGEqFlag(conditionsNode, m_xmlTagEtThreshold);
2593       if (intGEq[iSubCond] < 0) {
2594         edm::LogError("L1GtTriggerMenuXmlParser")
2595             << "Error getting \"greater or equal\" flag"
2596             << " for sub-condition " << conditionNameNodeName << " for the correlation condition " << name << std::endl;
2597         return false;
2598       }
2599 
2600       // set object type and sub-condition category
2601       if (particle == m_xmlConditionAttrObjectETM) {
2602         objType[iSubCond] = ETM;
2603       } else if (particle == m_xmlConditionAttrObjectETT) {
2604         objType[iSubCond] = ETT;
2605       } else if (particle == m_xmlConditionAttrObjectHTT) {
2606         objType[iSubCond] = HTT;
2607       } else if (particle == m_xmlConditionAttrObjectHTM) {
2608         objType[iSubCond] = HTM;
2609       } else {
2610         edm::LogError("L1GtTriggerMenuXmlParser")
2611             << "Wrong object type " << particle << " for sub-condition " << conditionNameNodeName
2612             << " from the correlation condition " << name << std::endl;
2613         return false;
2614       }
2615 
2616       condCateg[iSubCond] = CondEnergySum;
2617       corrIndexVal[iSubCond] = (m_corEnergySumTemplate[chipNr]).size() - 1;
2618 
2619     } else {
2620       edm::LogError("L1GtTriggerMenuXmlParser")
2621           << "Unknown or un-adequate sub-condition (" << condition << ")"
2622           << " with name " << conditionNameNodeName << " for the correlation condition " << name << std::endl;
2623 
2624       return false;
2625     }
2626 
2627     conditionsNode = findXMLChild(conditionsNode->getNextSibling(), "", true, &conditionNameNodeName);
2628   }
2629 
2630   // get greater equal flag for the correlation condition
2631   bool gEq = true;
2632   if (intGEq[0] != intGEq[1]) {
2633     edm::LogError("L1GtTriggerMenuXmlParser")
2634         << "Inconsistent GEq flags for sub-conditions (" << condition << ")"
2635         << " with name " << conditionNameNodeName << " for the correlation condition " << name << std::endl;
2636     return false;
2637 
2638   } else {
2639     gEq = (intGEq[0] != 0);
2640   }
2641 
2642   // correlation parameters
2643 
2644   // temporary storage of the parameters
2645   L1GtCorrelationTemplate::CorrelationParameter corrParameter;
2646   std::vector<uint64_t> tmpValues(nrObj);
2647 
2648   // get deltaEtaRange
2649   //    if ( !getConditionChildValues(node, m_xmlTagDeltaEta, 1, tmpValues) ) {
2650   //        return false;
2651   //    }
2652   //
2653   //    corrParameter.deltaEtaRange = tmpValues[0];
2654 
2655   XERCES_CPP_NAMESPACE::DOMNode* node1 = findXMLChild(node->getFirstChild(), m_xmlTagDeltaEta);
2656 
2657   std::string valString;
2658 
2659   if (node1 == nullptr) {
2660     edm::LogError("L1GtTriggerMenuXmlParser")
2661         << "    Could not get deltaEta for correlation condition " << name << ". " << std::endl;
2662     return false;
2663   } else {
2664     valString = getXMLTextValue(node1);
2665   }
2666 
2667   corrParameter.deltaEtaRange = valString;
2668 
2669   //    // deltaPhi is larger than 64bit
2670   //    if ( !getXMLHexTextValue128(findXMLChild(node->getFirstChild(), m_xmlTagDeltaPhi),
2671   //        tmpValues[0], tmpValues[1])) {
2672   //        edm::LogError("L1GtTriggerMenuXmlParser")
2673   //            << "    Could not get deltaPhi for correlation condition " << name << ". "
2674   //            << std::endl;
2675   //        return false;
2676   //    }
2677   //
2678   //    corrParameter.deltaPhiRange = tmpValues[0];
2679 
2680   node1 = findXMLChild(node->getFirstChild(), m_xmlTagDeltaPhi);
2681 
2682   if (node1 == nullptr) {
2683     return false;
2684     edm::LogError("L1GtTriggerMenuXmlParser")
2685         << "    Could not get deltaPhi for correlation condition " << name << ". " << std::endl;
2686   } else {
2687     valString = getXMLTextValue(node1);
2688   }
2689 
2690   corrParameter.deltaPhiRange = valString;
2691 
2692   // get maximum number of bits for delta phi
2693   //LogTrace("L1GtTriggerMenuXmlParser")
2694   //<< "      Counting deltaPhiMaxbits"
2695   //<< std::endl;
2696 
2697   unsigned int maxbits;
2698 
2699   if (!countConditionChildMaxBits(node, m_xmlTagDeltaPhi, maxbits)) {
2700     return false;
2701   }
2702 
2703   corrParameter.deltaPhiMaxbits = maxbits;
2704   //LogTrace("L1GtTriggerMenuXmlParser")
2705   //<< "        deltaPhiMaxbits (dec) = " << maxbits
2706   //<< std::endl;
2707 
2708   // fill the correlation condition
2709   correlationCond.setCondType(cType);
2710   correlationCond.setObjectType(objType);
2711   correlationCond.setCondGEq(gEq);
2712   correlationCond.setCondChipNr(chipNr);
2713 
2714   correlationCond.setCond0Category(condCateg[0]);
2715   correlationCond.setCond1Category(condCateg[1]);
2716 
2717   correlationCond.setCond0Index(corrIndexVal[0]);
2718   correlationCond.setCond1Index(corrIndexVal[1]);
2719 
2720   correlationCond.setCorrelationParameter(corrParameter);
2721 
2722   if (edm::isDebugEnabled()) {
2723     std::ostringstream myCoutStream;
2724     correlationCond.print(myCoutStream);
2725     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
2726   }
2727 
2728   // insert condition into the map
2729   // condition is not duplicate, check was done at the beginning
2730 
2731   (m_vecCorrelationTemplate[chipNr]).push_back(correlationCond);
2732 
2733   //
2734   return true;
2735 }
2736 
2737 /**
2738  * parseId - parse all identification attributes (trigger menu names, scale DB key, etc)
2739  *
2740  * @param parser The parser to parse the XML file with.
2741  *
2742  * @return "true" if succeeded. "false" if an error occurred.
2743  *
2744  */
2745 bool L1GtTriggerMenuXmlParser::parseId(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
2746   XERCES_CPP_NAMESPACE_USE
2747 
2748   DOMNode* doc = parser->getDocument();
2749   DOMNode* n1 = doc->getFirstChild();
2750 
2751   // we assume that the first child is m_xmlTagDef because it was checked in workXML
2752 
2753   DOMNode* headerNode = n1->getFirstChild();
2754   if (headerNode == nullptr) {
2755     edm::LogError("L1GtTriggerMenuXmlParser") << "Error: No child of <" << m_xmlTagDef << "> tag found." << std::endl;
2756     return false;
2757   }
2758 
2759   headerNode = findXMLChild(headerNode, m_xmlTagHeader);
2760   if (headerNode == nullptr) {
2761     LogDebug("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find <" << m_xmlTagHeader << "> tag"
2762                                          << "\n   - No header information." << std::endl;
2763 
2764   } else {
2765     DOMNode* idNode = headerNode->getFirstChild();
2766 
2767     // find menu interface name
2768     idNode = findXMLChild(idNode, m_xmlTagMenuInterface);
2769     if (idNode == nullptr) {
2770       LogTrace("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find <" << m_xmlTagMenuInterface << "> tag"
2771                                            << "\n   - Trigger menu interface name derived from file name." << std::endl;
2772 
2773       // set the name of the trigger menu interface: from beginning of file names
2774       // until beginning of "_L1T_Scales"
2775       size_t xmlPos = m_triggerMenuName.find("_L1T_Scales", 0);
2776       if (xmlPos == std::string::npos) {
2777         LogTrace("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find \"_L1T_Scales\" "
2778                                              << "string in file name"
2779                                              << "\n   - Trigger menu interface name set to file name." << std::endl;
2780         m_triggerMenuInterface = m_triggerMenuName;
2781 
2782       } else {
2783         m_triggerMenuInterface = m_triggerMenuName;
2784         m_triggerMenuInterface.erase(m_triggerMenuInterface.begin(), m_triggerMenuInterface.begin() + xmlPos);
2785       }
2786 
2787     } else {
2788       m_triggerMenuInterface = getXMLTextValue(idNode);
2789     }
2790 
2791     // find menu interface creation date
2792     idNode = headerNode->getFirstChild();
2793     idNode = findXMLChild(idNode, m_xmlTagMenuInterfaceDate);
2794 
2795     if (idNode == nullptr) {
2796       LogTrace("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find <" << m_xmlTagMenuInterfaceDate << "> tag"
2797                                            << "\n   - No creation date." << m_triggerMenuInterfaceDate << std::endl;
2798 
2799     } else {
2800       m_triggerMenuInterfaceDate = getXMLTextValue(idNode);
2801     }
2802 
2803     // find menu interface creation author
2804     idNode = headerNode->getFirstChild();
2805     idNode = findXMLChild(idNode, m_xmlTagMenuInterfaceAuthor);
2806 
2807     if (idNode == nullptr) {
2808       LogTrace("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find <" << m_xmlTagMenuInterfaceAuthor << "> tag"
2809                                            << "\n   - No creation author." << m_triggerMenuInterfaceAuthor << std::endl;
2810 
2811     } else {
2812       m_triggerMenuInterfaceAuthor = getXMLTextValue(idNode);
2813     }
2814 
2815     // find menu interface description
2816     idNode = headerNode->getFirstChild();
2817     idNode = findXMLChild(idNode, m_xmlTagMenuInterfaceDescription);
2818 
2819     if (idNode == nullptr) {
2820       LogTrace("L1GtTriggerMenuXmlParser")
2821           << "\n  Warning: Could not find <" << m_xmlTagMenuInterfaceDescription << "> tag"
2822           << "\n   - No description." << m_triggerMenuInterfaceDescription << std::endl;
2823 
2824     } else {
2825       m_triggerMenuInterfaceDescription = getXMLTextValue(idNode);
2826     }
2827 
2828     // find menu creation date
2829     idNode = headerNode->getFirstChild();
2830     idNode = findXMLChild(idNode, m_xmlTagMenuDate);
2831 
2832     if (idNode == nullptr) {
2833       LogTrace("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find <" << m_xmlTagMenuDate << "> tag"
2834                                            << "\n   - No creation date." << m_triggerMenuDate << std::endl;
2835 
2836     } else {
2837       m_triggerMenuDate = getXMLTextValue(idNode);
2838     }
2839 
2840     // find menu creation author
2841     idNode = headerNode->getFirstChild();
2842     idNode = findXMLChild(idNode, m_xmlTagMenuAuthor);
2843 
2844     if (idNode == nullptr) {
2845       LogTrace("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find <" << m_xmlTagMenuAuthor << "> tag"
2846                                            << "\n   - No creation author." << m_triggerMenuAuthor << std::endl;
2847 
2848     } else {
2849       m_triggerMenuAuthor = getXMLTextValue(idNode);
2850     }
2851 
2852     // find menu description
2853     idNode = headerNode->getFirstChild();
2854     idNode = findXMLChild(idNode, m_xmlTagMenuDescription);
2855 
2856     if (idNode == nullptr) {
2857       LogTrace("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find <" << m_xmlTagMenuDescription << "> tag"
2858                                            << "\n   - No description." << m_triggerMenuDescription << std::endl;
2859 
2860     } else {
2861       m_triggerMenuDescription = getXMLTextValue(idNode);
2862     }
2863 
2864     // find algorithm implementation tag
2865 
2866     idNode = headerNode->getFirstChild();
2867 
2868     idNode = findXMLChild(idNode, m_xmlTagMenuAlgImpl);
2869     if (idNode == nullptr) {
2870       m_algorithmImplementation = "";
2871       LogTrace("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find <" << m_xmlTagMenuAlgImpl << "> tag"
2872                                            << "\n   - Algorithm implementation tag set to empty string." << std::endl;
2873 
2874     } else {
2875       m_algorithmImplementation = getXMLTextValue(idNode);
2876     }
2877 
2878     // find DB key for L1 scales
2879 
2880     idNode = headerNode->getFirstChild();
2881 
2882     idNode = findXMLChild(idNode, m_xmlTagScaleDbKey);
2883     if (idNode == nullptr) {
2884       m_scaleDbKey = "NULL";
2885       LogTrace("L1GtTriggerMenuXmlParser") << "\n  Warning: Could not find <" << m_xmlTagScaleDbKey << "> tag"
2886                                            << "\n   - Scale key set to " << m_scaleDbKey << " string." << std::endl;
2887 
2888     } else {
2889       m_scaleDbKey = getXMLTextValue(idNode);
2890     }
2891   }
2892 
2893   LogDebug("L1GtTriggerMenuXmlParser") << "\n  Parsed values from XML file"
2894                                        << "\nL1 MenuInterface:                   " << m_triggerMenuInterface
2895                                        << "\nL1 MenuInterface - Creation date:   " << m_triggerMenuInterfaceDate
2896                                        << "\nL1 MenuInterface - Creation author: " << m_triggerMenuInterfaceAuthor
2897                                        << "\nL1 MenuInterface - Description:     " << m_triggerMenuInterfaceDescription
2898                                        << "\n"
2899                                        << "\nAlgorithm implementation tag:       " << m_algorithmImplementation << "\n"
2900                                        << "\nL1 Menu - Creation date:            " << m_triggerMenuDate
2901                                        << "\nL1 Menu - Creation author:          " << m_triggerMenuAuthor
2902                                        << "\nL1 Menu - Description:              " << m_triggerMenuDescription
2903                                        << std::endl;
2904 
2905   // set the trigger menu name
2906   // format:
2907   // L1MenuInterface/ScaleDbKey/AlgorithmImplementationTag
2908 
2909   std::string menuName = m_triggerMenuInterface + "/" + m_scaleDbKey + "/" + m_algorithmImplementation;
2910 
2911   if (menuName != m_triggerMenuName) {
2912     LogDebug("L1GtTriggerMenuXmlParser") << "\n  Warning: Inconsistent L1 menu name:"
2913                                          << "\n    from XML file name: " << m_triggerMenuName
2914                                          << "\n    from XML tag:       " << menuName << std::endl;
2915 
2916     if (!m_triggerMenuInterface.empty()) {
2917       if (m_scaleDbKey == "NULL") {
2918         m_triggerMenuName = m_triggerMenuInterface;
2919       } else {
2920         m_triggerMenuName = menuName;
2921       }
2922 
2923       LogTrace("L1GtTriggerMenuXmlParser") << "\n  L1 menu name set to value from XML tag!"
2924                                            << "\n  L1 Menu name: " << m_triggerMenuName << std::endl;
2925 
2926     } else {
2927       LogTrace("L1GtTriggerMenuXmlParser") << "\n  L1 menu name set to file name!"
2928                                            << "\n  L1 Menu name: " << m_triggerMenuName << std::endl;
2929     }
2930   }
2931 
2932   //
2933   return true;
2934 }
2935 
2936 /**
2937  * workCondition - call the appropriate function to parse this condition.
2938  *
2939  * @param node The corresponding node to the condition.
2940  * @param name The name of the condition.
2941  * @param chipNr The number of the chip the condition is located on.
2942  *
2943  * @return "true" on success, "false" if an error occurred.
2944  *
2945  */
2946 
2947 bool L1GtTriggerMenuXmlParser::workCondition(XERCES_CPP_NAMESPACE::DOMNode* node,
2948                                              const std::string& name,
2949                                              unsigned int chipNr) {
2950   XERCES_CPP_NAMESPACE_USE
2951 
2952   // get condition, particle name and type name
2953   std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
2954   std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
2955   std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
2956 
2957   if (condition.empty() || particle.empty() || type.empty()) {
2958     edm::LogError("L1GtTriggerMenuXmlParser") << "Missing attributes for condition " << name << std::endl;
2959 
2960     return false;
2961   }
2962 
2963   //LogTrace("L1GtTriggerMenuXmlParser")
2964   //<< "    condition: " << condition << ", particle: " << particle
2965   //<< ", type: " << type << std::endl;
2966 
2967   // call the appropiate function for this condition
2968 
2969   if (condition == m_xmlConditionAttrConditionMuon) {
2970     return parseMuon(node, name, chipNr);
2971   } else if (condition == m_xmlConditionAttrConditionCalo) {
2972     return parseCalo(node, name, chipNr);
2973   } else if (condition == m_xmlConditionAttrConditionEnergySum) {
2974     return parseEnergySum(node, name, chipNr);
2975   } else if (condition == m_xmlConditionAttrConditionJetCounts) {
2976     return parseJetCounts(node, name, chipNr);
2977   } else if (condition == m_xmlConditionAttrConditionCastor) {
2978     return parseCastor(node, name, chipNr);
2979   } else if (condition == m_xmlConditionAttrConditionHfBitCounts) {
2980     return parseHfBitCounts(node, name, chipNr);
2981   } else if (condition == m_xmlConditionAttrConditionHfRingEtSums) {
2982     return parseHfRingEtSums(node, name, chipNr);
2983   } else if (condition == m_xmlConditionAttrConditionBptx) {
2984     return parseBptx(node, name, chipNr);
2985   } else if (condition == m_xmlConditionAttrConditionExternal) {
2986     return parseExternal(node, name, chipNr);
2987   } else if (condition == m_xmlConditionAttrConditionCorrelation) {
2988     return parseCorrelation(node, name, chipNr);
2989   } else {
2990     edm::LogError("L1GtTriggerMenuXmlParser") << "\n Error: unknown condition (" << condition << ")" << std::endl;
2991 
2992     return false;
2993   }
2994 
2995   return true;
2996 }
2997 
2998 /**
2999  * parseConditions - look for conditions and call the workCondition
3000  *                   function for each node
3001  *
3002  * @param parser The parser to parse the XML file with.
3003  *
3004  * @return "true" if succeeded. "false" if an error occurred.
3005  *
3006  */
3007 
3008 bool L1GtTriggerMenuXmlParser::parseConditions(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
3009   XERCES_CPP_NAMESPACE_USE
3010 
3011   LogTrace("L1GtTriggerMenuXmlParser") << "\nParsing conditions" << std::endl;
3012 
3013   DOMNode* doc = parser->getDocument();
3014   DOMNode* n1 = doc->getFirstChild();
3015 
3016   // we assume that the first child is m_xmlTagDef because it was checked in workXML
3017 
3018   DOMNode* chipNode = n1->getFirstChild();
3019   if (chipNode == nullptr) {
3020     edm::LogError("L1GtTriggerMenuXmlParser") << "Error: No child of <" << m_xmlTagDef << "> tag found." << std::endl;
3021 
3022     return false;
3023   }
3024 
3025   // find chip
3026 
3027   std::string chipName;  // name of the actual chip
3028   chipNode = findXMLChild(chipNode, m_xmlTagChip, true, &chipName);
3029   if (chipNode == nullptr) {
3030     edm::LogError("L1GtTriggerMenuXmlParser") << "  Error: Could not find <" << m_xmlTagChip << "> tag" << std::endl;
3031 
3032     return false;
3033   }
3034 
3035   unsigned int chipNr = 0;
3036   do {
3037     // find conditions
3038     DOMNode* conditionsNode = chipNode->getFirstChild();
3039     conditionsNode = findXMLChild(conditionsNode, m_xmlTagConditions);
3040     if (conditionsNode == nullptr) {
3041       edm::LogError("L1GtTriggerMenuXmlParser")
3042           << "Error: No <" << m_xmlTagConditions << "> child found in Chip " << chipName << std::endl;
3043 
3044       return false;
3045     }
3046 
3047     char* nodeName = XMLString::transcode(chipNode->getNodeName());
3048     //LogTrace("L1GtTriggerMenuXmlParser")
3049     //<< "\n  Found Chip: " << nodeName << " Name: " << chipName
3050     //<< std::endl;
3051 
3052     XMLString::release(&nodeName);
3053 
3054     // walk through conditions
3055     DOMNode* conditionNameNode = conditionsNode->getFirstChild();
3056     std::string conditionNameNodeName;
3057     conditionNameNode = findXMLChild(conditionNameNode, "", true, &conditionNameNodeName);
3058     while (conditionNameNode != nullptr) {
3059       LogTrace("L1GtTriggerMenuXmlParser")
3060           << "\n    Found a condition with name: " << conditionNameNodeName << std::endl;
3061 
3062       if (!workCondition(conditionNameNode, conditionNameNodeName, chipNr)) {
3063         return false;
3064       }
3065       conditionNameNode = findXMLChild(conditionNameNode->getNextSibling(), "", true, &conditionNameNodeName);
3066     }
3067     // next chip
3068     chipNode = findXMLChild(chipNode->getNextSibling(), m_xmlTagChip, true, &chipName);
3069     chipNr++;
3070 
3071   } while (chipNode != nullptr && chipNr < m_numberConditionChips);
3072 
3073   return true;
3074 }
3075 
3076 /**
3077  * workAlgorithm - parse the algorithm and insert it into algorithm map.
3078  *
3079  * @param node The corresponding node to the algorithm.
3080  * @param name The name of the algorithm.
3081  * @param chipNr The number of the chip the conditions for that algorithm are located on.
3082  *
3083  * @return "true" on success, "false" if an error occurred.
3084  *
3085  */
3086 
3087 bool L1GtTriggerMenuXmlParser::workAlgorithm(XERCES_CPP_NAMESPACE::DOMNode* node,
3088                                              const std::string& algName,
3089                                              unsigned int chipNr) {
3090   XERCES_CPP_NAMESPACE_USE
3091 
3092   if (node == nullptr) {
3093     LogDebug("L1GtTriggerMenuXmlParser") << "    Node is 0 in " << __PRETTY_FUNCTION__
3094                                          << " can not parse the algorithm " << algName << std::endl;
3095     return false;
3096   }
3097 
3098   // get alias
3099   std::string algAlias = getXMLAttribute(node, m_xmlAlgorithmAttrAlias);
3100 
3101   if (algAlias.empty()) {
3102     algAlias = algName;
3103     LogDebug("L1GtTriggerMenuXmlParser") << "\n    No alias defined for algorithm. Alias set to algorithm name."
3104                                          << "\n    Algorithm name:  " << algName
3105                                          << "\n    Algorithm alias: " << algAlias << std::endl;
3106   } else {
3107     LogDebug("L1GtTriggerMenuXmlParser") << "\n    Alias defined for algorithm."
3108                                          << "\n    Algorithm name:  " << algName
3109                                          << "\n    Algorithm alias: " << algAlias << std::endl;
3110   }
3111 
3112   // get the logical expression from the node
3113   std::string logExpression = getXMLTextValue(node);
3114 
3115   //LogTrace("L1GtTriggerMenuXmlParser")
3116   //<< "      Logical expression: " << logExpression
3117   //<< std::endl;
3118 
3119   //LogTrace("L1GtTriggerMenuXmlParser")
3120   //<< "      Chip number:        " << chipNr
3121   //<< std::endl;
3122 
3123   // determine output pin
3124   DOMNode* pinNode = findXMLChild(node->getFirstChild(), m_xmlTagOutput);
3125   std::string pinString;
3126   int outputPin = 0;
3127 
3128   pinNode = node->getFirstChild();
3129   if ((pinNode = findXMLChild(pinNode, m_xmlTagOutputPin)) != nullptr) {
3130     pinString = getXMLAttribute(pinNode, m_xmlAttrNr);
3131 
3132     // convert pinString to integer
3133     std::istringstream opStream(pinString);
3134 
3135     if ((opStream >> outputPin).fail()) {
3136       LogDebug("L1GtTriggerMenuXmlParser")
3137           << "    Unable to convert pin string " << pinString << " to int for algorithm : " << algName << std::endl;
3138 
3139       return false;
3140     }
3141   }
3142 
3143   if (pinNode == nullptr) {
3144     LogTrace("L1GtTriggerMenuXmlParser") << "    Warning: No pin number found for algorithm: " << algName << std::endl;
3145 
3146     return false;
3147   }
3148 
3149   //LogTrace("L1GtTriggerMenuXmlParser")
3150   //<< "      Output pin:         " << outputPin
3151   //<< std::endl;
3152 
3153   // compute the bit number from chip number, output pin and order of the chips
3154   // pin numbering start with 1, bit numbers with 0
3155   int bitNumber = outputPin + (m_orderConditionChip[chipNr] - 1) * m_pinsOnConditionChip - 1;
3156 
3157   //LogTrace("L1GtTriggerMenuXmlParser")
3158   //<< "      Bit number:         " << bitNumber
3159   //<< std::endl;
3160 
3161   // create a new algorithm and insert it into algorithm map
3162   L1GtAlgorithm alg(algName, logExpression, bitNumber);
3163   alg.setAlgoChipNumber(static_cast<int>(chipNr));
3164   alg.setAlgoAlias(algAlias);
3165 
3166   if (edm::isDebugEnabled()) {
3167     std::ostringstream myCoutStream;
3168     alg.print(myCoutStream);
3169     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
3170   }
3171 
3172   // insert algorithm into the map
3173   if (!insertAlgorithmIntoMap(alg)) {
3174     return false;
3175   }
3176 
3177   return true;
3178 }
3179 
3180 /*
3181  * parseAlgorithms Parse the algorithms
3182  * NOTE: the algorithms used here are equivalent to "prealgo" from XML file
3183  *       for the VERSION_FINAL
3184  *       The "VERSION_PROTOTYPE algo" will be phased out later in the XML file
3185  *       See L1GlobalTriggerConfig.h (in the attic)
3186  *
3187  * @param parser A reference to the XercesDOMParser to use.
3188  *
3189  * @return "true" if succeeded, "false" if an error occurred.
3190  *
3191  */
3192 
3193 bool L1GtTriggerMenuXmlParser::parseAlgorithms(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
3194   XERCES_CPP_NAMESPACE_USE
3195 
3196   //LogTrace("L1GtTriggerMenuXmlParser") << "\nParsing algorithms" << std::endl;
3197 
3198   DOMNode* doc = parser->getDocument();
3199   DOMNode* node = doc->getFirstChild();
3200 
3201   DOMNode* chipNode = node->getFirstChild();
3202   if (chipNode == nullptr) {
3203     edm::LogError("L1GtTriggerMenuXmlParser") << "  Error: No child found for " << m_xmlTagDef << std::endl;
3204     return false;
3205   }
3206 
3207   // find first chip
3208   std::string chipName;
3209   chipNode = findXMLChild(chipNode, m_xmlTagChip, true, &chipName);
3210   if (chipNode == nullptr) {
3211     edm::LogError("L1GtTriggerMenuXmlParser") << "  Error: Could not find <" << m_xmlTagChip << std::endl;
3212     return false;
3213   }
3214 
3215   unsigned int chipNr = 0;
3216   do {
3217     //LogTrace("L1GtTriggerMenuXmlParser") << std::endl;
3218 
3219     std::string nodeName = m_xmlTagChip + chipName;
3220     //LogTrace("L1GtTriggerMenuXmlParser")
3221     //<< "  Chip: " << nodeName << " Name: " << chipName
3222     //<< std::endl;
3223 
3224     // find algorithms
3225     DOMNode* algNode = chipNode->getFirstChild();
3226     algNode = findXMLChild(algNode, m_xmlTagAlgorithms);
3227     if (algNode == nullptr) {
3228       edm::LogError("L1GtTriggerMenuXmlParser")
3229           << "    Error: No <" << m_xmlTagAlgorithms << "> child found in chip " << chipName << std::endl;
3230       return false;
3231     }
3232 
3233     // walk through algorithms
3234     DOMNode* algNameNode = algNode->getFirstChild();
3235     std::string algNameNodeName;
3236     algNameNode = findXMLChild(algNameNode, "", true, &algNameNodeName);
3237 
3238     while (algNameNode != nullptr) {
3239       //LogTrace("L1GtTriggerMenuXmlParser")
3240       //<< "    Found an algorithm with name: " << algNameNodeName
3241       //<< std::endl;
3242 
3243       if (!workAlgorithm(algNameNode, algNameNodeName, chipNr)) {
3244         return false;
3245       }
3246 
3247       algNameNode = findXMLChild(algNameNode->getNextSibling(), "", true, &algNameNodeName);
3248     }
3249 
3250     // next chip
3251     chipNode = findXMLChild(chipNode->getNextSibling(), m_xmlTagChip, true, &chipName);
3252     chipNr++;
3253 
3254   } while (chipNode != nullptr && chipNr < m_numberConditionChips);
3255 
3256   return true;
3257 }
3258 
3259 /**
3260  * workTechTrigger - parse the technical trigger and insert it into technical trigger map.
3261  *
3262  * @param node The corresponding node to the technical trigger.
3263  * @param name The name of the technical trigger.
3264  *
3265  * @return "true" on success, "false" if an error occurred.
3266  *
3267  */
3268 
3269 bool L1GtTriggerMenuXmlParser::workTechTrigger(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& algName) {
3270   XERCES_CPP_NAMESPACE_USE
3271 
3272   if (node == nullptr) {
3273     LogDebug("L1GtTriggerMenuXmlParser") << "    Node is 0 in " << __PRETTY_FUNCTION__
3274                                          << " can not parse the technical trigger " << algName << std::endl;
3275     return false;
3276   }
3277 
3278   // get the logical expression from the node
3279   std::string logExpression = getXMLTextValue(node);
3280 
3281   //LogTrace("L1GtTriggerMenuXmlParser")
3282   //<< "      Logical expression: " << logExpression
3283   //<< std::endl;
3284 
3285   // determine bit number (use output pin tag)
3286   DOMNode* pinNode = findXMLChild(node->getFirstChild(), m_xmlTagOutput);
3287   std::string pinString;
3288   int outputPin = 0;
3289 
3290   pinNode = node->getFirstChild();
3291   if ((pinNode = findXMLChild(pinNode, m_xmlTagOutputPin)) != nullptr) {
3292     pinString = getXMLAttribute(pinNode, m_xmlAttrNr);
3293 
3294     // convert pinString to integer
3295     std::istringstream opStream(pinString);
3296 
3297     if ((opStream >> outputPin).fail()) {
3298       LogDebug("L1GtTriggerMenuXmlParser") << "    Unable to convert pin string " << pinString
3299                                            << " to int for technical trigger : " << algName << std::endl;
3300 
3301       return false;
3302     }
3303   }
3304 
3305   if (pinNode == nullptr) {
3306     LogTrace("L1GtTriggerMenuXmlParser") << "    Warning: No pin number found for technical trigger: " << algName
3307                                          << std::endl;
3308 
3309     return false;
3310   }
3311 
3312   // set the bit number
3313   int bitNumber = outputPin;
3314 
3315   //LogTrace("L1GtTriggerMenuXmlParser")
3316   //<< "      Bit number:         " << bitNumber
3317   //<< std::endl;
3318 
3319   // create a new technical trigger and insert it into technical trigger map
3320   // alias set automatically to name
3321   L1GtAlgorithm alg(algName, logExpression, bitNumber);
3322   alg.setAlgoAlias(algName);
3323 
3324   if (edm::isDebugEnabled()) {
3325     std::ostringstream myCoutStream;
3326     alg.print(myCoutStream);
3327     LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
3328   }
3329 
3330   // insert technical trigger into the map
3331   if (!insertTechTriggerIntoMap(alg)) {
3332     return false;
3333   }
3334 
3335   return true;
3336 }
3337 
3338 /*
3339  * parseTechTriggers Parse the technical triggers
3340  *
3341  * @param parser A reference to the XercesDOMParser to use.
3342  *
3343  * @return "true" if succeeded, "false" if an error occurred.
3344  *
3345  */
3346 
3347 bool L1GtTriggerMenuXmlParser::parseTechTriggers(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
3348   XERCES_CPP_NAMESPACE_USE
3349 
3350   //LogTrace("L1GtTriggerMenuXmlParser") << "\nParsing technical triggers" << std::endl;
3351 
3352   DOMNode* doc = parser->getDocument();
3353   DOMNode* node = doc->getFirstChild();
3354 
3355   DOMNode* algNode = node->getFirstChild();
3356   if (algNode == nullptr) {
3357     edm::LogError("L1GtTriggerMenuXmlParser") << "  Error: No child found for " << m_xmlTagDef << std::endl;
3358     return false;
3359   }
3360 
3361   algNode = findXMLChild(algNode, m_xmlTagTechTriggers);
3362   if (algNode == nullptr) {
3363     edm::LogError("L1GtTriggerMenuXmlParser")
3364         << "    Error: No <" << m_xmlTagTechTriggers << "> child found." << std::endl;
3365     return false;
3366   }
3367 
3368   // walk through technical triggers
3369   DOMNode* algNameNode = algNode->getFirstChild();
3370   std::string algNameNodeName;
3371   algNameNode = findXMLChild(algNameNode, "", true, &algNameNodeName);
3372 
3373   while (algNameNode != nullptr) {
3374     //LogTrace("L1GtTriggerMenuXmlParser")
3375     //<< "    Found an technical trigger with name: " << algNameNodeName
3376     //<< std::endl;
3377 
3378     if (!workTechTrigger(algNameNode, algNameNodeName)) {
3379       return false;
3380     }
3381 
3382     algNameNode = findXMLChild(algNameNode->getNextSibling(), "", true, &algNameNodeName);
3383   }
3384 
3385   return true;
3386 }
3387 
3388 /**
3389  * workXML parse the XML-File
3390  *
3391  * @param parser The parser to use for parsing the XML-File
3392  *
3393  * @return "true" if succeeded, "false" if an error occurred.
3394  */
3395 
3396 bool L1GtTriggerMenuXmlParser::workXML(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
3397   XERCES_CPP_NAMESPACE_USE
3398 
3399   DOMDocument* doc = parser->getDocument();
3400   DOMNode* n1 = doc->getFirstChild();
3401 
3402   if (n1 == nullptr) {
3403     edm::LogError("L1GtTriggerMenuXmlParser") << "Error: Found no XML child" << std::endl;
3404 
3405     return false;
3406   }
3407 
3408   char* nodeName = XMLString::transcode(n1->getNodeName());
3409 
3410   if (XMLString::compareIString(nodeName, m_xmlTagDef.c_str())) {
3411     edm::LogError("L1GtTriggerMenuXmlParser")
3412         << "Error: First XML child is not \" " << m_xmlTagDef << "\" " << std::endl;
3413 
3414     return false;
3415   }
3416 
3417   LogTrace("L1GtTriggerMenuXmlParser") << "\nFirst node name is: " << nodeName << std::endl;
3418   XMLString::release(&nodeName);
3419 
3420   // clear possible old maps
3421   clearMaps();
3422 
3423   if (!parseId(parser)) {
3424     clearMaps();
3425     return false;
3426   }
3427 
3428   if (!parseConditions(parser)) {
3429     clearMaps();
3430     return false;
3431   }
3432 
3433   if (!parseAlgorithms(parser)) {
3434     clearMaps();
3435     return false;
3436   }
3437 
3438   if (!parseTechTriggers(parser)) {
3439     clearMaps();
3440     return false;
3441   }
3442 
3443   return true;
3444 }
3445 
3446 // static class members