CMS 3D CMS Logo

L1GtTriggerMenuXmlParser.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtTriggerMenuXmlParser.h"
00019 
00020 // system include files
00021 #include <string>
00022 #include <vector>
00023 
00024 #include <iostream>
00025 #include <fstream>
00026 #include <iomanip>
00027 
00028 #include <boost/cstdint.hpp>
00029 
00030 // user include files
00031 // base class
00032 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtXmlParserTags.h"
00033 
00034 #include "CondFormats/L1TObjects/interface/L1GtCondition.h"
00035 #include "CondFormats/L1TObjects/interface/L1GtAlgorithm.h"
00036 
00037 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00038 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00039 
00040 // constructor
00041 L1GtTriggerMenuXmlParser::L1GtTriggerMenuXmlParser() : L1GtXmlParserTags()
00042 {
00043     // error handler for xml-parser
00044     m_xmlErrHandler = 0;
00045 
00046 }
00047 
00048 // destructor
00049 L1GtTriggerMenuXmlParser::~L1GtTriggerMenuXmlParser() {
00050 
00051     clearMaps();
00052 
00053 }
00054 
00055 // set the number of condition chips in GTL
00056 void L1GtTriggerMenuXmlParser::setGtNumberConditionChips(
00057     const unsigned int& numberConditionChipsValue) {
00058 
00059     m_numberConditionChips = numberConditionChipsValue;
00060 
00061 }
00062 
00063 // set the number of pins on the GTL condition chips
00064 void L1GtTriggerMenuXmlParser::setGtPinsOnConditionChip(const unsigned int& pinsOnConditionChipValue) {
00065 
00066     m_pinsOnConditionChip = pinsOnConditionChipValue;
00067 
00068 }
00069 
00070 // set the correspondence "condition chip - GTL algorithm word"
00071 // in the hardware
00072 void L1GtTriggerMenuXmlParser::setGtOrderConditionChip(
00073     const std::vector<int>& orderConditionChipValue) {
00074 
00075     m_orderConditionChip = orderConditionChipValue;
00076 
00077 }
00078 
00079 // set the number of physics trigger algorithms
00080 void L1GtTriggerMenuXmlParser::setGtNumberPhysTriggers(
00081         const unsigned int& numberPhysTriggersValue) {
00082 
00083     m_numberPhysTriggers = numberPhysTriggersValue;
00084 
00085 }
00086 
00087 // set the number of technical triggers
00088 void L1GtTriggerMenuXmlParser::setGtNumberTechTriggers(
00089         const unsigned int& numberTechTriggersValue) {
00090 
00091     m_numberTechTriggers = numberTechTriggersValue;
00092 
00093 }
00094 
00095 // set the number of L1 jet counts received by GT
00096 void L1GtTriggerMenuXmlParser::setGtNumberL1JetCounts(const unsigned int& numberL1JetCountsValue) {
00097 
00098     m_numberL1JetCounts = numberL1JetCountsValue;
00099 
00100 }
00101 
00102 
00103 // set the condition maps
00104 void L1GtTriggerMenuXmlParser::setGtConditionMap(const std::vector<ConditionMap>& condMap) {
00105     m_conditionMap = condMap;
00106 }
00107 
00108 // set the trigger menu name
00109 void L1GtTriggerMenuXmlParser::setGtTriggerMenuName(const std::string& menuName) {
00110     m_triggerMenuName = menuName;
00111 }
00112 
00113 // get / set the vectors containing the conditions
00114 void L1GtTriggerMenuXmlParser::setVecMuonTemplate(
00115         const std::vector<std::vector<L1GtMuonTemplate> >& vecMuonTempl) {
00116 
00117     m_vecMuonTemplate = vecMuonTempl;
00118 }
00119 
00120 void L1GtTriggerMenuXmlParser::setVecCaloTemplate(
00121         const std::vector<std::vector<L1GtCaloTemplate> >& vecCaloTempl) {
00122 
00123     m_vecCaloTemplate = vecCaloTempl;
00124 }
00125 
00126 void L1GtTriggerMenuXmlParser::setVecEnergySumTemplate(
00127         const std::vector<std::vector<L1GtEnergySumTemplate> >& vecEnergySumTempl) {
00128 
00129     m_vecEnergySumTemplate = vecEnergySumTempl;
00130 }
00131 
00132 void L1GtTriggerMenuXmlParser::setVecJetCountsTemplate(
00133         const std::vector<std::vector<L1GtJetCountsTemplate> >& vecJetCountsTempl) {
00134 
00135     m_vecJetCountsTemplate = vecJetCountsTempl;
00136 }
00137 
00138 void L1GtTriggerMenuXmlParser::setVecCastorTemplate(
00139         const std::vector<std::vector<L1GtCastorTemplate> >& vecCastorTempl) {
00140 
00141     m_vecCastorTemplate = vecCastorTempl;
00142 }
00143 
00144 void L1GtTriggerMenuXmlParser::setVecHfBitCountsTemplate(
00145         const std::vector<std::vector<L1GtHfBitCountsTemplate> >& vecHfBitCountsTempl) {
00146 
00147     m_vecHfBitCountsTemplate = vecHfBitCountsTempl;
00148 }
00149 
00150 void L1GtTriggerMenuXmlParser::setVecHfRingEtSumsTemplate(
00151         const std::vector<std::vector<L1GtHfRingEtSumsTemplate> >& vecHfRingEtSumsTempl) {
00152 
00153     m_vecHfRingEtSumsTemplate = vecHfRingEtSumsTempl;
00154 }
00155 
00156 void L1GtTriggerMenuXmlParser::setVecCorrelationTemplate(
00157         const std::vector<std::vector<L1GtCorrelationTemplate> >& vecCorrelationTempl) {
00158 
00159     m_vecCorrelationTemplate = vecCorrelationTempl;
00160 }
00161 
00162 // set the vectors containing the conditions for correlation templates
00163 //
00164 void L1GtTriggerMenuXmlParser::setCorMuonTemplate(
00165         const std::vector<std::vector<L1GtMuonTemplate> >& corMuonTempl) {
00166 
00167     m_corMuonTemplate = corMuonTempl;
00168 }
00169 
00170 void L1GtTriggerMenuXmlParser::setCorCaloTemplate(
00171         const std::vector<std::vector<L1GtCaloTemplate> >& corCaloTempl) {
00172 
00173     m_corCaloTemplate = corCaloTempl;
00174 }
00175 
00176 void L1GtTriggerMenuXmlParser::setCorEnergySumTemplate(
00177         const std::vector<std::vector<L1GtEnergySumTemplate> >& corEnergySumTempl) {
00178 
00179     m_corEnergySumTemplate = corEnergySumTempl;
00180 }
00181 
00182 
00183 
00184 
00185 // set the algorithm map
00186 void L1GtTriggerMenuXmlParser::setGtAlgorithmMap(const AlgorithmMap& algoMap) {
00187     m_algorithmMap = algoMap;
00188 }
00189 
00190 // set the technical trigger map
00191 void L1GtTriggerMenuXmlParser::setGtTechnicalTriggerMap(const AlgorithmMap& ttMap) {
00192     m_technicalTriggerMap = ttMap;
00193 }
00194 
00195 //
00196 
00197 
00198 // parse def.xml and vme.xml files
00199 void L1GtTriggerMenuXmlParser::parseXmlFile(const std::string& defXmlFile,
00200     const std::string& vmeXmlFile) {
00201 
00202     XERCES_CPP_NAMESPACE_USE
00203 
00204     // resize the vector of condition maps
00205     // the number of condition chips should be correctly set before calling parseXmlFile
00206     m_conditionMap.resize(m_numberConditionChips);
00207 
00208     m_vecMuonTemplate.resize(m_numberConditionChips);
00209     m_vecCaloTemplate.resize(m_numberConditionChips);
00210     m_vecEnergySumTemplate.resize(m_numberConditionChips);
00211     m_vecJetCountsTemplate.resize(m_numberConditionChips);
00212     m_vecCastorTemplate.resize(m_numberConditionChips);
00213     m_vecHfBitCountsTemplate.resize(m_numberConditionChips);
00214     m_vecHfRingEtSumsTemplate.resize(m_numberConditionChips);
00215 
00216     m_vecCorrelationTemplate.resize(m_numberConditionChips);
00217     m_corMuonTemplate.resize(m_numberConditionChips);
00218     m_corCaloTemplate.resize(m_numberConditionChips);
00219     m_corEnergySumTemplate.resize(m_numberConditionChips);
00220 
00221     // set the name of the trigger menu: defXmlFile, stripped of absolute path and .xml
00222     std::string::iterator itString;
00223     m_triggerMenuName = defXmlFile;
00224     size_t xmlPos = m_triggerMenuName.find_last_of("/");
00225     m_triggerMenuName.erase(m_triggerMenuName.begin(), m_triggerMenuName.begin()+ xmlPos+1);
00226 
00227     xmlPos = m_triggerMenuName.find_last_of(".");
00228     m_triggerMenuName.erase(m_triggerMenuName.begin()+ xmlPos, m_triggerMenuName.end());
00229 
00230     // error handler for xml-parser
00231     m_xmlErrHandler = 0;
00232 
00233     XercesDOMParser* parser;
00234 
00235     LogTrace("L1GtTriggerMenuXmlParser") << "\nOpening XML-File: \n  " << defXmlFile << std::endl;
00236 
00237     if ((parser = initXML(defXmlFile)) != 0) {
00238         workXML(parser);
00239     }
00240     cleanupXML(parser);
00241 
00242 }
00243 
00253 XERCES_CPP_NAMESPACE::XercesDOMParser* L1GtTriggerMenuXmlParser::initXML(const std::string &xmlFile) {
00254 
00255     XERCES_CPP_NAMESPACE_USE
00256 
00257     // try to initialize
00258     try {
00259         XMLPlatformUtils::Initialize();
00260     }
00261     catch (const XMLException& toCatch) {
00262         char* message = XMLString::transcode(toCatch.getMessage());
00263 
00264         edm::LogError("L1GtTriggerMenuXmlParser")
00265         << "Error during Xerces-c initialization! :"
00266         << message << std::endl;
00267 
00268         XMLString::release(&message);
00269         return 0;
00270     }
00271 
00272     XercesDOMParser* parser = new XercesDOMParser();
00273     parser->setValidationScheme(XercesDOMParser::Val_Always);
00274     parser->setDoNamespaces(false); // we got no dtd
00275 
00276     if (m_xmlErrHandler == 0) { // redundant check
00277         m_xmlErrHandler = (ErrorHandler*) new HandlerBase();
00278     }
00279     else {
00280         // TODO ASSERTION
00281     }
00282     parser->setErrorHandler(m_xmlErrHandler);
00283 
00284     // try to parse the file
00285     try {
00286         parser->parse(xmlFile.c_str());
00287     }
00288     catch(const XMLException &toCatch) {
00289         char* message = XMLString::transcode(toCatch.getMessage());
00290 
00291         edm::LogError("L1GtTriggerMenuXmlParser")
00292         << "Exception while parsing XML: \n"
00293         << message << std::endl;
00294 
00295         XMLString::release(&message);
00296         delete parser;
00297         delete m_xmlErrHandler;
00298         m_xmlErrHandler = 0;
00299         return 0;
00300     }
00301     catch (const DOMException &toCatch) {
00302         char *message = XMLString::transcode(toCatch.msg);
00303 
00304         edm::LogError("L1GtTriggerMenuXmlParser")
00305         << "DOM-Exception while parsing XML: \n"
00306         << message << std::endl;
00307 
00308         XMLString::release(&message);
00309         delete parser;
00310         delete m_xmlErrHandler;
00311         m_xmlErrHandler = 0;
00312         return 0;
00313     }
00314     catch (...) {
00315 
00316         edm::LogError("L1GtTriggerMenuXmlParser")
00317         << "Unexpected Exception while parsing XML!"
00318         << std::endl;
00319 
00320         delete parser;
00321         delete m_xmlErrHandler;
00322         m_xmlErrHandler = 0;
00323         return 0;
00324     }
00325 
00326     return parser;
00327 }
00328 
00329 // find a named child of a xml node
00330 XERCES_CPP_NAMESPACE::DOMNode* L1GtTriggerMenuXmlParser::findXMLChild(
00331     XERCES_CPP_NAMESPACE::DOMNode* startChild, const std::string& tagName, bool beginOnly,
00332     std::string* rest) {
00333 
00334     XERCES_CPP_NAMESPACE_USE
00335 
00336     char* nodeName = 0;
00337 
00338     DOMNode *n1 = startChild;
00339     if (n1 == 0) {
00340         return 0;
00341     }
00342 
00343     if ( !tagName.empty() ) {
00344         nodeName = XMLString::transcode(n1->getNodeName());
00345 
00346         if (!beginOnly) {
00347             //match the whole tag
00348             while (XMLString::compareIString(nodeName, tagName.c_str())) {
00349 
00350                 XMLString::release(&nodeName);
00351                 n1 = n1->getNextSibling();
00352                 if (n1 == 0) {
00353                     break;
00354                 }
00355 
00356                 nodeName = XMLString::transcode(n1->getNodeName());
00357             }
00358         }
00359         else {
00360             // match only the beginning
00361             while (XMLString::compareNIString(nodeName, tagName.c_str(), tagName.length())) {
00362                 XMLString::release(&nodeName);
00363                 n1 = n1->getNextSibling();
00364                 if (n1 == 0) {
00365                     break;
00366                 }
00367 
00368                 nodeName = XMLString::transcode(n1->getNodeName());
00369             }
00370             if (n1 != 0 && rest != 0) {
00371                 *rest = std::string(nodeName).substr(tagName.length(), strlen(nodeName) - tagName.length());
00372             }
00373         }
00374     }
00375     else { // empty string given
00376         while (n1->getNodeType() != DOMNode::ELEMENT_NODE) {
00377             n1 = n1->getNextSibling();
00378             if (n1 == 0) {
00379                 break;
00380             }
00381 
00382         }
00383         if (n1 != 0 && rest != 0) {
00384             nodeName = XMLString::transcode(n1->getNodeName());
00385             *rest = std::string(nodeName);
00386         }
00387     }
00388 
00389     XMLString::release(&nodeName);
00390 
00391     return n1;
00392 
00393 }
00394 
00404 std::string L1GtTriggerMenuXmlParser::getXMLAttribute(const XERCES_CPP_NAMESPACE::DOMNode* node,
00405     const std::string& name) {
00406 
00407     XERCES_CPP_NAMESPACE_USE
00408 
00409     std::string ret;
00410 
00411     // get attributes list
00412     DOMNamedNodeMap* attributes = node->getAttributes();
00413     if (attributes == 0) {
00414         return ret;
00415     }
00416 
00417     // get attribute node
00418     XMLCh* attrName = XMLString::transcode(name.c_str());
00419     DOMNode* attribNode = attributes->getNamedItem(attrName);
00420 
00421     XMLString::release(&attrName);
00422     if (attribNode == 0) {
00423         return ret;
00424     }
00425 
00426     char* retCstr = XMLString::transcode(attribNode->getNodeValue());
00427     ret = retCstr;
00428     XMLString::release(&retCstr);
00429 
00430     return ret;
00431 }
00432 
00441 std::string L1GtTriggerMenuXmlParser::getXMLTextValue(XERCES_CPP_NAMESPACE::DOMNode* node) {
00442 
00443     XERCES_CPP_NAMESPACE_USE
00444 
00445     std::string ret;
00446 
00447     DOMNode* n1 = node;
00448     if (n1 == 0) {
00449         return ret;
00450     }
00451 
00452     const XMLCh* retXmlCh = n1->getTextContent();
00453     if (retXmlCh == 0) {
00454         return ret;
00455     }
00456 
00457     char* retCstr = XMLString::transcode(retXmlCh);
00458     XMLString::trim(retCstr); // trim spaces
00459 
00460     ret = retCstr;
00461     XMLString::release(&retCstr);
00462 
00463     return ret;
00464 }
00465 
00476 bool L1GtTriggerMenuXmlParser::hexString2UInt128(const std::string& hexString,
00477     boost::uint64_t& dstL, boost::uint64_t& dstH) {
00478 
00479     // string to determine start of hex value, do not ignore leading zeros
00480     static const std::string valid_hex_start("0123456789ABCDEFabcdef");
00481 
00482     // string to determine end of hex value
00483     static const std::string valid_hex_end("0123456789ABCDEFabcdef");
00484 
00485     std::string tempStr = hexString;
00486 
00487     // start / end position of the hex value in the string
00488     unsigned int hexStart = tempStr.find_first_of(valid_hex_start);
00489     unsigned int hexEnd = tempStr.find_first_not_of(valid_hex_end, hexStart);
00490 
00491     if (hexStart == hexEnd) {
00492 
00493         LogDebug("L1GtTriggerMenuXmlParser") << "No hex value found in: " << tempStr << std::endl;
00494 
00495         return false;
00496     }
00497 
00498     tempStr = tempStr.substr(hexStart, hexEnd - hexStart);
00499 
00500     if (tempStr.empty() ) {
00501 
00502         LogDebug("L1GtTriggerMenuXmlParser") << "Empty value in " << __PRETTY_FUNCTION__
00503             << std::endl;
00504 
00505         return false;
00506     }
00507 
00508     // split the string
00509     std::string tempStrH, tempStrL;
00510 
00511     if (tempStr.length() > 16) { // more than 64 bit
00512         tempStrL = tempStr.substr(tempStr.length()-16, 16);
00513         tempStrH = tempStr.substr(0, tempStr.length()-16);
00514     }
00515     else {
00516         tempStrL = tempStr;
00517         tempStrH = "0";
00518     }
00519 
00520     // convert lower 64bit
00521     char* endPtr = (char*) tempStrL.c_str();
00522     boost::uint64_t tempUIntL = strtoull(tempStrL.c_str(), &endPtr, 16);
00523 
00524     if (*endPtr != 0) {
00525 
00526         LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << tempStr << " to hex."
00527             << std::endl;
00528 
00529         return false;
00530     }
00531 
00532     // convert higher64 bit
00533     endPtr = (char*) tempStrH.c_str();
00534     boost::uint64_t tempUIntH = strtoull(tempStrH.c_str(), &endPtr, 16);
00535 
00536     if (*endPtr != 0) {
00537 
00538         LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << tempStr << " to hex."
00539             << std::endl;
00540 
00541         return false;
00542     }
00543 
00544     dstL = tempUIntL;
00545     dstH = tempUIntH;
00546 
00547     return true;
00548 }
00549 
00560 bool L1GtTriggerMenuXmlParser::getXMLHexTextValue128(XERCES_CPP_NAMESPACE::DOMNode* node,
00561     boost::uint64_t& dstL, boost::uint64_t& dstH) {
00562 
00563     if (node == 0) {
00564 
00565         LogDebug("L1GtTriggerMenuXmlParser") << "node == 0 in " << __PRETTY_FUNCTION__ << std::endl;
00566 
00567         return false;
00568     }
00569 
00570     boost::uint64_t tempUIntH, tempUIntL;
00571 
00572     std::string tempStr = getXMLTextValue(node);
00573     if ( !hexString2UInt128(tempStr, tempUIntL, tempUIntH) ) {
00574         return false;
00575     }
00576 
00577     dstL = tempUIntL;
00578     dstH = tempUIntH;
00579 
00580     return true;
00581 }
00582 
00594 bool L1GtTriggerMenuXmlParser::getXMLHexTextValue(XERCES_CPP_NAMESPACE::DOMNode* node,
00595     boost::uint64_t& dst) {
00596 
00597     boost::uint64_t dummyH; // dummy for eventual higher 64bit
00598     boost::uint64_t tempUInt; // temporary unsigned integer
00599 
00600     if ( !getXMLHexTextValue128(node, tempUInt, dummyH) ) {
00601         return false;
00602     }
00603 
00604     if (dummyH != 0) {
00605         edm::LogError("L1GtTriggerMenuXmlParser") << "Too large hex-value!" << std::endl;
00606         return false;
00607     }
00608 
00609     dst = tempUInt;
00610 
00611     return true;
00612 }
00613 
00625 bool L1GtTriggerMenuXmlParser::countConditionChildMaxBits(XERCES_CPP_NAMESPACE::DOMNode* node,
00626     const std::string& childName, unsigned int& dst) {
00627 
00628     XERCES_CPP_NAMESPACE_USE
00629 
00630     // should never happen...
00631     if (node == 0) {
00632 
00633         LogDebug("L1GtTriggerMenuXmlParser")
00634         << "node == 0 in " << __PRETTY_FUNCTION__ << std::endl;
00635 
00636         return false;
00637     }
00638 
00639     DOMNode* n1 = findXMLChild(node->getFirstChild(), childName);
00640 
00641     if (n1 == 0) {
00642 
00643         LogDebug("L1GtTriggerMenuXmlParser") << "Child of condition not found ( " << childName
00644             << ")" << std::endl;
00645 
00646         return false;
00647     }
00648 
00649     DOMNode* n2 = findXMLChild(n1->getFirstChild(), m_xmlTagValue);
00650 
00651     if (n2 == 0) {
00652 
00653         LogDebug("L1GtTriggerMenuXmlParser") << "No value tag found for child " << childName
00654             << " in " << __PRETTY_FUNCTION__ << std::endl;
00655 
00656         return false;
00657     }
00658 
00659     // first try direct
00660     std::string maxString = getXMLAttribute(n1, m_xmlAttrMax); // string for the maxbits
00661 
00662     if (maxString.empty() ) {
00663         maxString = getXMLAttribute(n2, m_xmlAttrMax); // try next value tag
00664         // if no max was found neither in value nor in the childName tag
00665         if (maxString.empty() ) {
00666 
00667             LogDebug("L1GtTriggerMenuXmlParser") << "No Max value found for " << childName
00668                 << std::endl;
00669 
00670             return false;
00671         }
00672     }
00673 
00674     // do the hex conversion
00675 
00676     boost::uint64_t maxBitsL, maxBitsH;
00677     if ( !hexString2UInt128(maxString, maxBitsL, maxBitsH) ) {
00678         return false;
00679     }
00680 
00681     // count the bits
00682     //LogTrace("L1GtTriggerMenuXmlParser")
00683     //<< std::dec
00684     //<< "        words: dec: high (MSB) word = " << maxBitsH << " low word = " << maxBitsL
00685     //<< std::hex << "\n"
00686     //<< "        words: hex: high (MSB) word = " << maxBitsH << " low word = " << maxBitsL
00687     //<< std::dec
00688     //<< std::endl;
00689 
00690     unsigned int counter = 0;
00691 
00692     while (maxBitsL != 0) {
00693         // check if bits set countinously
00694         if ( (maxBitsL & 1) == 0) {
00695 
00696             edm::LogError("L1GtTriggerMenuXmlParser")
00697                 << "      Confused by not continous set bits for max value " << maxString
00698                 << "(child=" << childName << ")" << std::endl;
00699 
00700             return false;
00701         }
00702 
00703         maxBitsL >>= 1;
00704         counter++;
00705     }
00706 
00707     if ( (maxBitsH != 0) && (counter != 64)) {
00708 
00709         edm::LogError("L1GtTriggerMenuXmlParser")
00710             << "      Confused by not continous set bits for max value " << maxString << "(child="
00711             << childName << ")" << std::endl;
00712 
00713         return false;
00714     }
00715 
00716     while (maxBitsH != 0) {
00717         //check if bits set countinously
00718         if ( (maxBitsH & 1) == 0) {
00719 
00720             edm::LogError("L1GtTriggerMenuXmlParser")
00721                 << "      Confused by not continous set bits for max value " << maxString
00722                 << "(child=" << childName << ")" << std::endl;
00723 
00724             return false;
00725         }
00726 
00727         maxBitsH >>= 1;
00728         counter++;
00729     }
00730 
00731     dst = counter;
00732     return true;
00733 
00734 }
00735 
00747 bool L1GtTriggerMenuXmlParser::getConditionChildValues(XERCES_CPP_NAMESPACE::DOMNode* node,
00748     const std::string& childName, unsigned int num, std::vector<boost::uint64_t>& dst) {
00749 
00750     XERCES_CPP_NAMESPACE_USE
00751 
00752     if (node == 0) {
00753 
00754         LogDebug("L1GtTriggerMenuXmlParser")
00755         << "node == 0 in " << __PRETTY_FUNCTION__
00756         << std::endl;
00757 
00758         return false;
00759     }
00760 
00761     DOMNode* n1 = findXMLChild(node->getFirstChild(), childName);
00762 
00763     // if child not found
00764     if (n1 == 0) {
00765 
00766         LogDebug("L1GtTriggerMenuXmlParser") << "Child of condition not found ( " << childName
00767             << ")" << std::endl;
00768 
00769         return false;
00770     }
00771 
00772     // no values are sucessfull
00773     if (num == 0) {
00774         return true;
00775     }
00776 
00777     //
00778     dst.reserve(num);
00779 
00780     //
00781     n1 = findXMLChild(n1->getFirstChild(), m_xmlTagValue);
00782     for (unsigned int i = 0; i < num; i++) {
00783         if (n1 == 0) {
00784 
00785             LogDebug("L1GtTriggerMenuXmlParser") << "Not enough values in condition child ( "
00786                 << childName << ")" << std::endl;
00787 
00788             return false;
00789         }
00790 
00791         if ( !getXMLHexTextValue(n1, dst[i]) ) {
00792 
00793             edm::LogError("L1GtTriggerMenuXmlParser") << "Error converting condition child ( "
00794                 << childName << ") value." << std::endl;
00795 
00796             return false;
00797         }
00798 
00799         n1 = findXMLChild(n1->getNextSibling(), m_xmlTagValue); // next child
00800     }
00801 
00802     return true;
00803 }
00804 
00812 void L1GtTriggerMenuXmlParser::cleanupXML(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
00813 
00814     XERCES_CPP_NAMESPACE_USE
00815 
00816     if (parser != 0) {
00817         delete parser;
00818     }
00819 
00820     if (m_xmlErrHandler != 0) {
00821         delete m_xmlErrHandler;
00822         m_xmlErrHandler = 0;
00823     }
00824 
00825     XMLPlatformUtils::Terminate();
00826 
00827 }
00828 
00829 // FIXME remove it after new L1 Trigger Menu Editor available
00830 // mirrors the LUT table from GTgui format to correct bit format
00831 boost::uint64_t L1GtTriggerMenuXmlParser::mirror(const boost::uint64_t oldLUT,
00832         int maxBitsLUT, int maxBitsReal)
00833 {
00834 
00835     LogTrace("L1GtTriggerMenuXmlParser") << "\n maxBitsLUT (dec) = "
00836             << maxBitsLUT << std::endl;
00837 
00838     boost::uint64_t newLUT = 0ULL;
00839     int newBit = -1;
00840 
00841     int firstBin = 0;
00842     int diffScale = maxBitsLUT - maxBitsReal;
00843     //int bits16 = maxBitsLUT/4; // hex size
00844 
00845     if (diffScale != 0) {
00846         firstBin = 1;
00847     }
00848 
00849     for (int oldBit = 0; oldBit < maxBitsLUT; ++oldBit) {
00850 
00851         boost::uint64_t bitValue = (oldLUT & (1ULL << oldBit)) >> oldBit;
00852 
00853         newBit = maxBitsReal/2 + firstBin - oldBit - 1;
00854 
00855         if (newBit < 0) {
00856             int newVal = (maxBitsLUT/2 + std::abs(newBit) - 1 );
00857             int endValid = maxBitsLUT/2 + maxBitsReal/2;
00858             if ((newVal < endValid)) {
00859                 newBit = newVal;
00860             }
00861             else {
00862                 newBit = oldBit + (maxBitsReal - maxBitsLUT)/2;
00863 
00864                 if (newBit >= maxBitsLUT/2) {
00865                     newBit = oldBit;
00866                 }
00867             }
00868         }
00869 
00870         newLUT = newLUT | (bitValue << newBit);
00871 
00872         //LogTrace("L1GtTriggerMenuXmlParser") << "  old bit number -> new bit number: "
00873         //        << oldBit
00874         //        << "\t ---> " << newBit << ";\t  bit value = "
00875         //        << bitValue << std::endl;
00876     }
00877 
00878     //LogTrace("L1GtTriggerMenuXmlParser") << "\n Converting old LUT  (hex) "
00879     //        << "\n    GTgui.XML:    "
00880     //        << std::hex << std::setw(bits16) << std::setfill('0')
00881     //        << oldLUT
00882     //        << "\n    Mirror:       "
00883     //        << std::hex << std::setw(bits16) << std::setfill('0')
00884     //        << newLUT << std::dec
00885     //        << std::endl;
00886 
00887     return newLUT;
00888 }
00889 
00890 // methods for the VME file
00891 
00892 
00902 bool L1GtTriggerMenuXmlParser::parseVmeXML(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
00903 
00904     XERCES_CPP_NAMESPACE_USE
00905 
00906     DOMDocument* doc = parser->getDocument();
00907     DOMNode* n1 = doc->getFirstChild();
00908 
00909     if (n1 == 0) {
00910 
00911         edm::LogError("L1GtTriggerMenuXmlParser") << "Error: Found no XML child" << std::endl;
00912 
00913         return false;
00914     }
00915 
00916     // find "vme"-tag
00917     n1 = findXMLChild(n1, m_xmlTagVme);
00918     if (n1 == 0) {
00919 
00920         edm::LogError("L1GtTriggerMenuXmlParser") << "Error: No vme tag found." << std::endl;
00921         return false;
00922     }
00923 
00924     n1 = n1->getFirstChild();
00925 
00926     unsigned int chipCounter = 0; // count chips
00927 
00928     while (chipCounter < m_numberConditionChips) {
00929 
00930         n1 = findXMLChild(n1, m_xmlTagChip, true);
00931         if (n1 == 0) {
00932             // just break if no more chips found
00933             break;
00934         }
00935 
00936         // node for a particle
00937         //DOMNode* particleNode = n1->getFirstChild(); // FIXME un-comment
00938 
00939         // FIXME parse vme.xml, modify the menu
00940 
00941         n1 = n1->getNextSibling();
00942         chipCounter++;
00943     } // end while chipCounter
00944 
00945     return true;
00946 
00947 }
00948 
00949 // methods for conditions and algorithms
00950 
00951 // clearMaps - delete all conditions and algorithms in
00952 // the maps and clear the maps.
00953 void L1GtTriggerMenuXmlParser::clearMaps() {
00954 
00955     // loop over condition maps (one map per condition chip)
00956     // then loop over conditions in the map
00957     for (std::vector<ConditionMap>::iterator itCondOnChip = m_conditionMap.begin(); itCondOnChip
00958         != m_conditionMap.end(); itCondOnChip++) {
00959 
00960         // the conditions in the maps are deleted in L1GtTriggerMenu, not here
00961 
00962         itCondOnChip->clear();
00963 
00964     }
00965 
00966     // the algorithms in the maps are deleted in L1GtTriggerMenu, not here
00967     m_algorithmMap.clear();
00968 
00969 }
00970 
00971 // insertConditionIntoMap - safe insert of condition into condition map.
00972 // if the condition name already exists, do not insert it and return false
00973 bool L1GtTriggerMenuXmlParser::insertConditionIntoMap(L1GtCondition& cond, const int chipNr) {
00974 
00975     std::string cName = cond.condName();
00976     //LogTrace("L1GtTriggerMenuXmlParser")
00977     //<< "    Trying to insert condition \"" << cName << "\" in the condition map." ;
00978 
00979     // no condition name has to appear twice!
00980     if ((m_conditionMap[chipNr]).count(cName) != 0) {
00981         LogTrace("L1GtTriggerMenuXmlParser") << "      Condition " << cName
00982             << " already exists - not inserted!" << std::endl;
00983         return false;
00984     }
00985 
00986     (m_conditionMap[chipNr])[cName] = &cond;
00987     //LogTrace("L1GtTriggerMenuXmlParser")
00988     //<< "      OK - condition inserted!"
00989     //<< std::endl;
00990 
00991 
00992     return true;
00993 
00994 }
00995 
00996 // insert an algorithm into algorithm map
00997 bool L1GtTriggerMenuXmlParser::insertAlgorithmIntoMap(const L1GtAlgorithm& alg) {
00998 
00999     std::string algName = alg.algoName();
01000     //LogTrace("L1GtTriggerMenuXmlParser")
01001     //<< "    Trying to insert algorithm \"" << algName << "\" in the algorithm map." ;
01002 
01003     // no algorithm name has to appear twice!
01004     if (m_algorithmMap.count(algName) != 0) {
01005         LogTrace("L1GtTriggerMenuXmlParser") << "      Algorithm \"" << algName
01006             << "\"already exists in the algorithm map- not inserted!" << std::endl;
01007         return false;
01008     }
01009 
01010     // bit number less than zero or greater than maximum number of algorithms
01011     int bitNumber = alg.algoBitNumber();
01012     if ((bitNumber < 0) || (bitNumber >= static_cast<int>(m_numberPhysTriggers))) {
01013         LogTrace("L1GtTriggerMenuXmlParser") << "      Bit number " << bitNumber
01014             << " outside allowed range [0, " << m_numberPhysTriggers
01015             << ") - algorithm not inserted!" << std::endl;
01016         return false;
01017     }
01018 
01019     // maximum number of algorithms
01020     if (m_algorithmMap.size() >= m_numberPhysTriggers) {
01021         LogTrace("L1GtTriggerMenuXmlParser") << "      More than maximum allowed "
01022             << m_numberPhysTriggers << " algorithms in the algorithm map - not inserted!"
01023             << std::endl;
01024         return false;
01025     }
01026 
01027     // chip number outside allowed values
01028     int chipNr = alg.algoChipNumber(static_cast<int>(m_numberConditionChips),
01029         static_cast<int>(m_pinsOnConditionChip), m_orderConditionChip);
01030 
01031     if ((chipNr < 0) || (chipNr > static_cast<int>(m_numberConditionChips))) {
01032         LogTrace("L1GtTriggerMenuXmlParser") << "      Chip number " << chipNr
01033             << " outside allowed range [0, " << m_numberConditionChips
01034             << ") - algorithm not inserted!" << std::endl;
01035         return false;
01036     }
01037 
01038     // output pin outside allowed values
01039     int outputPin = alg.algoOutputPin(static_cast<int>(m_numberConditionChips),
01040         static_cast<int>(m_pinsOnConditionChip), m_orderConditionChip);
01041 
01042     if ((outputPin < 0) || (outputPin > static_cast<int>(m_pinsOnConditionChip))) {
01043         LogTrace("L1GtTriggerMenuXmlParser") << "      Output pin " << outputPin
01044             << " outside allowed range [0, " << m_pinsOnConditionChip
01045             << "] - algorithm not inserted!" << std::endl;
01046         return false;
01047     }
01048 
01049     // no two algorithms on the same chip can have the same output pin
01050     for (CItAlgo itAlgo = m_algorithmMap.begin(); itAlgo != m_algorithmMap.end(); itAlgo++) {
01051 
01052         int iPin = (itAlgo->second).algoOutputPin( static_cast<int>(m_numberConditionChips),
01053             static_cast<int>(m_pinsOnConditionChip), m_orderConditionChip);
01054         std::string iName = itAlgo->first;
01055         int iChip = (itAlgo->second).algoChipNumber(static_cast<int>(m_numberConditionChips),
01056             static_cast<int>(m_pinsOnConditionChip), m_orderConditionChip);
01057 
01058         if ( (outputPin == iPin) && (chipNr == iChip)) {
01059             LogTrace("L1GtTriggerMenuXmlParser") << "      Output pin " << outputPin
01060                 << " is the same as for algorithm " << iName
01061                 << "\n      from the same chip number " << chipNr << " - algorithm not inserted!"
01062                 << std::endl;
01063             return false;
01064         }
01065 
01066     }
01067 
01068     // insert algorithm
01069     m_algorithmMap[algName] = alg;
01070 
01071     //LogTrace("L1GtTriggerMenuXmlParser")
01072     //<< "      OK - algorithm inserted!"
01073     //<< std::endl;
01074 
01075     return true;
01076 
01077 }
01078 
01079 // insert a technical trigger into technical trigger map
01080 bool L1GtTriggerMenuXmlParser::insertTechTriggerIntoMap(const L1GtAlgorithm& alg) {
01081 
01082     std::string algName = alg.algoName();
01083     //LogTrace("L1GtTriggerMenuXmlParser")
01084     //<< "    Trying to insert technical trigger \"" << algName
01085     //<< "\" in the technical trigger map." ;
01086 
01087     // no technical trigger name has to appear twice!
01088     if (m_technicalTriggerMap.count(algName) != 0) {
01089         LogTrace("L1GtTriggerMenuXmlParser") << "      Technical trigger \""
01090                 << algName
01091                 << "\"already exists in the technical trigger map- not inserted!"
01092                 << std::endl;
01093         return false;
01094     }
01095 
01096     // bit number less than zero or greater than maximum number of technical triggers
01097     int bitNumber = alg.algoBitNumber();
01098     if ((bitNumber < 0)
01099             || (bitNumber >= static_cast<int>(m_numberTechTriggers))) {
01100         LogTrace("L1GtTriggerMenuXmlParser") << "      Bit number "
01101                 << bitNumber << " outside allowed range [0, "
01102                 << m_numberTechTriggers
01103                 << ") - technical trigger not inserted!" << std::endl;
01104         return false;
01105     }
01106 
01107     // no two technical triggers can have the same bit number
01108     for (CItAlgo itAlgo = m_technicalTriggerMap.begin(); itAlgo
01109             != m_technicalTriggerMap.end(); itAlgo++) {
01110 
01111         int iBitNumber = (itAlgo->second).algoBitNumber();
01112         std::string iName = itAlgo->first;
01113 
01114         if ((iBitNumber == bitNumber)) {
01115             LogTrace("L1GtTriggerMenuXmlParser") << "      Bit number "
01116                     << iBitNumber << " is the same as for technical trigger "
01117                     << iName << " - technical trigger not inserted!"
01118                     << std::endl;
01119             return false;
01120         }
01121 
01122     }
01123 
01124     // maximum number of technical triggers
01125     if (m_technicalTriggerMap.size() >= m_numberTechTriggers) {
01126         LogTrace("L1GtTriggerMenuXmlParser")
01127                 << "      More than maximum allowed " << m_numberTechTriggers
01128                 << " technical triggers in the technical trigger map - not inserted!"
01129                 << std::endl;
01130         return false;
01131     }
01132 
01133     // insert technical trigger
01134     m_technicalTriggerMap[algName] = alg;
01135 
01136     //LogTrace("L1GtTriggerMenuXmlParser")
01137     //<< "      OK - technical trigger inserted!"
01138     //<< std::endl;
01139 
01140     return true;
01141 
01142 }
01143 
01144 
01145 
01146 // get the type of the condition, as defined in enum, from the condition type
01147 // as defined in the XML file
01148 L1GtConditionType L1GtTriggerMenuXmlParser::getTypeFromType(const std::string& type) {
01149 
01150     if (type == m_xmlConditionAttrType1s) {
01151         return Type1s;
01152     }
01153 
01154     if (type == m_xmlConditionAttrType2s) {
01155         return Type2s;
01156     }
01157 
01158     if (type == m_xmlConditionAttrType3s) {
01159         return Type3s;
01160     }
01161 
01162     if (type == m_xmlConditionAttrType4s) {
01163         return Type4s;
01164     }
01165 
01166     if (type == m_xmlConditionAttrType2wsc) {
01167         return Type2wsc;
01168     }
01169 
01170     if (type == m_xmlConditionAttrType2cor) {
01171         return Type2cor;
01172     }
01173 
01174     return TypeNull;
01175 }
01176 
01186 int L1GtTriggerMenuXmlParser::getNumFromType(const std::string &type) {
01187 
01188     if (type == m_xmlConditionAttrType1s) {
01189         return 1;
01190     }
01191 
01192     if (type == m_xmlConditionAttrType2s) {
01193         return 2;
01194     }
01195 
01196     if (type == m_xmlConditionAttrType3s) {
01197         return 3;
01198     }
01199 
01200     if (type == m_xmlConditionAttrType4s) {
01201         return 4;
01202     }
01203 
01204     if (type == m_xmlConditionAttrType2wsc) {
01205         return 2;
01206     }
01207 
01208     if (type == m_xmlConditionAttrType2cor) {
01209         return 2;
01210     }
01211 
01212     return -1;
01213 }
01214 
01223 int L1GtTriggerMenuXmlParser::getBitFromNode(XERCES_CPP_NAMESPACE::DOMNode* node) {
01224 
01225     if (getXMLAttribute(node, m_xmlAttrMode) != m_xmlAttrModeBit) {
01226 
01227         edm::LogError("L1GtTriggerMenuXmlParser") << "Invalid mode for single bit" << std::endl;
01228 
01229         return -1;
01230     }
01231 
01232     std::string tmpStr = getXMLTextValue(node);
01233     if (tmpStr == "0") {
01234         return 0;
01235     }
01236     else if (tmpStr == "1") {
01237         return 1;
01238     }
01239     else {
01240         edm::LogError("L1GtTriggerMenuXmlParser") << "Bad bit value (" << tmpStr << ")"
01241             << std::endl;
01242         return -1;
01243     }
01244 }
01245 
01255 int L1GtTriggerMenuXmlParser::getGEqFlag(XERCES_CPP_NAMESPACE::DOMNode* node,
01256     const std::string& nodeName) {
01257 
01258     XERCES_CPP_NAMESPACE_USE
01259 
01260     if (node == 0) {
01261 
01262         LogDebug("L1GtTriggerMenuXmlParser")
01263         << "node == 0 in " << __PRETTY_FUNCTION__
01264         << std::endl;
01265 
01266         return -1;
01267     }
01268 
01269     // usually the GEq flag is a child of the first child (the first element node)
01270     DOMNode* n1 = node->getFirstChild();
01271     n1 = findXMLChild(n1, nodeName);
01272 
01273     if (n1 != 0) {
01274         n1 = findXMLChild(n1->getFirstChild(), m_xmlTagGEq);
01275         if (n1 == 0) {
01276 
01277             LogDebug("L1GtTriggerMenuXmlParser") << "No \"greater or equal\" tag found"
01278                 << std::endl;
01279 
01280             return -1;
01281         }
01282 
01283         return getBitFromNode(n1);
01284     }
01285     else {
01286 
01287         return -1;
01288 
01289     }
01290 
01291 }
01292 
01305 bool L1GtTriggerMenuXmlParser::getMuonMipIsoBits(XERCES_CPP_NAMESPACE::DOMNode* node,
01306     unsigned int num, std::vector<bool>& mipDst, std::vector<bool>& isoEnDst,
01307     std::vector<bool>& isoReqDst) {
01308 
01309     XERCES_CPP_NAMESPACE_USE
01310 
01311     if (node == 0) {
01312         return false;
01313     }
01314 
01315     // find ptLowThreshold child
01316     DOMNode* n1 = findXMLChild(node->getFirstChild(), m_xmlTagPtLowThreshold);
01317 
01318     if (n1 == 0) {
01319         return false;
01320     }
01321 
01322     // get first value tag
01323     n1 = findXMLChild(n1->getFirstChild(), m_xmlTagValue);
01324 
01325     for (unsigned int i = 0; i < num; i++) {
01326 
01327         if (n1 == 0) {
01328             return false;
01329         }
01330 
01331         // MIP bit
01332 
01333         DOMNode* bitnode = findXMLChild(n1->getFirstChild(), m_xmlTagEnableMip);
01334         if (bitnode == 0) {
01335             return true;
01336         }
01337 
01338         int tmpint = getBitFromNode(bitnode);
01339         if (tmpint < 0) {
01340             return false;
01341         }
01342 
01343         mipDst[i] = (tmpint != 0);
01344 
01345         //LogTrace("L1GtTriggerMenuXmlParser")
01346         //<< "      MIP bit value for muon " << i << " = " << mipDst[i]
01347         //<< std::endl;
01348 
01349 
01350         // enable iso bit
01351         bitnode = findXMLChild(n1->getFirstChild(), m_xmlTagEnableIso);
01352         if (bitnode == 0) {
01353             return true;
01354         }
01355 
01356         tmpint = getBitFromNode(bitnode);
01357         if (tmpint < 0) {
01358             return false;
01359         }
01360 
01361         isoEnDst[i] = (tmpint != 0);
01362 
01363         //LogTrace("L1GtTriggerMenuXmlParser")
01364         //<< "      Enabled iso bit value for muon " << i << " = " << isoEnDst[i]
01365         //<< std::endl;
01366 
01367         // request iso bit
01368         bitnode = findXMLChild(n1->getFirstChild(), m_xmlTagRequestIso);
01369         if (bitnode == 0) {
01370             return true;
01371         }
01372 
01373         tmpint = getBitFromNode(bitnode);
01374         if (tmpint < 0) {
01375             return false;
01376         }
01377 
01378         isoReqDst[i] = (tmpint != 0);
01379 
01380         //LogTrace("L1GtTriggerMenuXmlParser")
01381         //<< "      Request iso bit value for muon " << i << " = " << isoReqDst[i]
01382         //<< std::endl;
01383 
01384         //
01385         n1 = findXMLChild(n1->getNextSibling(), m_xmlTagValue); // next value
01386     }
01387 
01388     return true;
01389 }
01390 
01402 bool L1GtTriggerMenuXmlParser::parseMuon(XERCES_CPP_NAMESPACE::DOMNode* node,
01403         const std::string& name, unsigned int chipNr, const bool corrFlag) {
01404 
01405     XERCES_CPP_NAMESPACE_USE
01406 
01407     // get condition, particle name (must be muon) and type name
01408     std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
01409     std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
01410     std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
01411 
01412     if (particle != m_xmlConditionAttrObjectMu) {
01413         edm::LogError("L1GtTriggerMenuXmlParser") << "Wrong particle for muon-condition ("
01414             << particle << ")" << std::endl;
01415         return false;
01416     }
01417 
01418     int nrObj = getNumFromType(type);
01419     if (nrObj < 0) {
01420         edm::LogError("L1GtTriggerMenuXmlParser") << "Unknown type for muon-condition (" << type
01421             << ")" << "\nCan not determine number of trigger objects. " << std::endl;
01422         return false;
01423     }
01424 
01425     // get greater equal flag
01426 
01427     int intGEq = getGEqFlag(node, m_xmlTagPtHighThreshold);
01428     if (intGEq < 0) {
01429         edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag"
01430             << std::endl;
01431         return false;
01432     }
01433     // set the boolean value for the ge_eq mode
01434     bool gEq = (intGEq != 0);
01435 
01436     // get values
01437 
01438     // temporary storage of the parameters
01439     std::vector<L1GtMuonTemplate::ObjectParameter> objParameter(nrObj);
01440     L1GtMuonTemplate::CorrelationParameter corrParameter;
01441 
01442     // need at least two values for deltaPhi
01443     std::vector<boost::uint64_t> tmpValues((nrObj > 2) ? nrObj : 2);
01444 
01445     // get ptHighThreshold values and fill into structure
01446     if ( !getConditionChildValues(node, m_xmlTagPtHighThreshold, nrObj, tmpValues) ) {
01447         return false;
01448     }
01449 
01450     for (int i = 0; i < nrObj; i++) {
01451         objParameter[i].ptHighThreshold = tmpValues[i];
01452 
01453         //LogTrace("L1GtTriggerMenuXmlParser")
01454         //<< "      Muon pT high threshold (hex) for muon " << i << " = "
01455         //<< std::hex << objParameter[i].ptHighThreshold << std::dec
01456         //<< std::endl;
01457     }
01458 
01459     // get ptLowThreshold values  and fill into structure
01460     if ( !getConditionChildValues(node, m_xmlTagPtLowThreshold, nrObj, tmpValues) ) {
01461         return false;
01462     }
01463 
01464     for (int i = 0; i < nrObj; i++) {
01465         //LogTrace("L1GtTriggerMenuXmlParser")
01466         //<< "        Muon pT low threshold word (hex) for muon " << i << " = "
01467         //<< std::hex << tmpValues[i] << std::dec
01468         //<< std::endl;
01469 
01470         // TODO FIXME stupid format in def.xml...
01471         // one takes mip bit also, therefore one divide by 16
01472         tmpValues[i] = (tmpValues[i])/16;
01473 
01474         objParameter[i].ptLowThreshold = tmpValues[i];
01475 
01476         //LogTrace("L1GtTriggerMenuXmlParser")
01477         //<< "      Muon pT low threshold (hex) for muon  " << i << " = "
01478         //<< std::hex << objParameter[i].ptLowThreshold << std::dec
01479         //<< std::endl;
01480     }
01481 
01482     // get qualityRange and fill into structure
01483     if ( !getConditionChildValues(node, m_xmlTagQuality, nrObj, tmpValues) ) {
01484         return false;
01485     }
01486 
01487     for (int i = 0; i < nrObj; i++) {
01488         objParameter[i].qualityRange = tmpValues[i];
01489 
01490         //LogTrace("L1GtTriggerMenuXmlParser")
01491         //<< "      qualityRange mask (hex) for muon " << i << " = "
01492         //<< std::hex << objParameter[i].qualityRange << std::dec
01493         //<< std::endl;
01494     }
01495 
01496     // get etaRange and fill into structure
01497     if ( !getConditionChildValues(node, m_xmlTagEta, nrObj, tmpValues) ) {
01498         return false;
01499     }
01500 
01501     for (int i = 0; i < nrObj; i++) {
01502 
01503         objParameter[i].etaRange = tmpValues[i];
01504 
01505         //LogTrace("L1GtTriggerMenuXmlParser")
01506         //<< "      etaRange (hex) for muon " << i << " = "
01507         //<< std::hex << objParameter[i].etaRange << std::dec
01508         //<< std::endl;
01509     }
01510 
01511     // get phiHigh values and fill into structure
01512     if ( !getConditionChildValues(node, m_xmlTagPhiHigh, nrObj, tmpValues) ) {
01513         return false;
01514     }
01515 
01516     for (int i = 0; i < nrObj; i++) {
01517         objParameter[i].phiHigh = tmpValues[i];
01518 
01519         //LogTrace("L1GtTriggerMenuXmlParser")
01520         //<< "      phiHigh (hex) for muon " << i << " = "
01521         //<< std::hex << objParameter[i].phiHigh << std::dec
01522         //<< std::endl;
01523     }
01524 
01525     // get phiLow values and fill into structure
01526     if ( !getConditionChildValues(node, m_xmlTagPhiLow, nrObj, tmpValues) ) {
01527         return false;
01528     }
01529 
01530     for (int i = 0; i < nrObj; i++) {
01531         objParameter[i].phiLow = tmpValues[i];
01532 
01533         //LogTrace("L1GtTriggerMenuXmlParser")
01534         //<< "      phiLow (hex) for muon " << i << " = "
01535         //<< std::hex << objParameter[i].phiLow << std::dec
01536         //<< std::endl;
01537     }
01538 
01539     // get charge correlation and fill into structure
01540     if ( !getXMLHexTextValue(findXMLChild(node->getFirstChild(), m_xmlTagChargeCorrelation),
01541         tmpValues[0]) ) {
01542 
01543         LogDebug("L1GtTriggerMenuXmlParser")
01544             << "    Error getting charge correlation from muon condition (" << name << ")"
01545             << std::endl;
01546         return false;
01547     }
01548 
01549     corrParameter.chargeCorrelation = tmpValues[0];
01550 
01551     //LogTrace("L1GtTriggerMenuXmlParser")
01552     //<< "      charge correlation" << " = "
01553     //<< std::hex << corrParameter.chargeCorrelation << std::dec
01554     //<< std::endl;
01555 
01556     // get mip and iso bits and fill into structure
01557 
01558     std::vector<bool> tmpMip(nrObj);
01559     std::vector<bool> tmpEnableIso(nrObj);
01560     std::vector<bool> tmpRequestIso(nrObj);
01561 
01562     if ( !getMuonMipIsoBits(node, nrObj, tmpMip, tmpEnableIso, tmpRequestIso) ) {
01563         edm::LogError("L1GtTriggerMenuXmlParser")
01564             << "    Could not get mip and iso bits from muon condition (" << name << ")"
01565             << std::endl;
01566         return false;
01567     }
01568 
01569     for (int i = 0; i < nrObj; i++) {
01570         objParameter[i].enableMip = tmpMip[i];
01571         objParameter[i].enableIso = tmpEnableIso[i];
01572         objParameter[i].requestIso = tmpRequestIso[i];
01573     }
01574 
01575     // indicates if a correlation is used
01576     bool wscVal = (type == m_xmlConditionAttrType2wsc );
01577 
01578     if (wscVal) {
01579         // get deltaEtaRange
01580         if ( !getConditionChildValues(node, m_xmlTagDeltaEta, 1, tmpValues) ) {
01581             return false;
01582         }
01583 
01584         corrParameter.deltaEtaRange = tmpValues[0];
01585 
01586         // deltaPhi is larger than 64bit
01587         if ( !getXMLHexTextValue128(findXMLChild(node->getFirstChild(), m_xmlTagDeltaPhi),
01588             tmpValues[0], tmpValues[1])) {
01589             edm::LogError("L1GtTriggerMenuXmlParser")
01590                 << "    Could not get deltaPhi for muon condition with wsc (" << name << ")"
01591                 << std::endl;
01592             return false;
01593         }
01594 
01595         corrParameter.deltaPhiRange0Word = tmpValues[0];
01596         corrParameter.deltaPhiRange1Word = tmpValues[1];
01597 
01598         // get maximum number of bits for delta phi
01599         //LogTrace("L1GtTriggerMenuXmlParser")
01600         //<< "      Counting deltaPhiMaxbits"
01601         //<< std::endl;
01602 
01603         unsigned int maxbits;
01604 
01605         if ( !countConditionChildMaxBits(node, m_xmlTagDeltaPhi, maxbits) ) {
01606             return false;
01607         }
01608 
01609         corrParameter.deltaPhiMaxbits = maxbits;
01610         //LogTrace("L1GtTriggerMenuXmlParser")
01611         //<< "        deltaPhiMaxbits (dec) = " << maxbits
01612         //<< std::endl;
01613     }
01614 
01615     // get the type of the condition, as defined in enum, from the condition type
01616     // as defined in the XML file
01617     L1GtConditionType cType = getTypeFromType(type);
01618     //LogTrace("L1GtTriggerMenuXmlParser")
01619     //<< "      Condition type (enum value) = " << cType
01620     //<< std::endl;
01621 
01622     if (cType == TypeNull) {
01623         edm::LogError("L1GtTriggerMenuXmlParser")
01624             << "Type for muon condition id TypeNull - it means not defined in the XML file."
01625             << "\nNumber of trigger objects is set to zero. " << std::endl;
01626         return false;
01627     }
01628 
01629     // object types - all muons
01630     std::vector<L1GtObject> objType(nrObj, Mu);
01631 
01632     // now create a new CondMuonition
01633 
01634     L1GtMuonTemplate muonCond(name);
01635 
01636     muonCond.setCondType(cType);
01637     muonCond.setObjectType(objType);
01638     muonCond.setCondGEq(gEq);
01639     muonCond.setCondChipNr(chipNr);
01640 
01641     muonCond.setConditionParameter(objParameter, corrParameter);
01642 
01643     if (edm::isDebugEnabled() ) {
01644         std::ostringstream myCoutStream;
01645         muonCond.print(myCoutStream);
01646         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
01647     }
01648 
01649     // insert condition into the map and into muon template vector
01650     if ( !insertConditionIntoMap(muonCond, chipNr)) {
01651 
01652         edm::LogError("L1GtTriggerMenuXmlParser")
01653                 << "    Error: duplicate condition (" << name << ")"
01654                 << std::endl;
01655         return false;
01656     }
01657     else {
01658         if (corrFlag) {
01659             (m_corMuonTemplate[chipNr]).push_back(muonCond);
01660 
01661         }
01662         else {
01663             (m_vecMuonTemplate[chipNr]).push_back(muonCond);
01664         }
01665 
01666     }
01667 
01668     //
01669     return true;
01670 }
01671 
01683 bool L1GtTriggerMenuXmlParser::parseCalo(XERCES_CPP_NAMESPACE::DOMNode* node,
01684         const std::string& name, unsigned int chipNr, const bool corrFlag) {
01685 
01686     XERCES_CPP_NAMESPACE_USE
01687 
01688     // get condition, particle name and type name
01689     std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
01690     std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
01691     std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
01692 
01693     // determine object type type
01694     L1GtObject caloObjType;
01695 
01696     if (particle == m_xmlConditionAttrObjectNoIsoEG) {
01697         caloObjType = NoIsoEG;
01698     }
01699     else if (particle == m_xmlConditionAttrObjectIsoEG) {
01700         caloObjType = IsoEG;
01701     }
01702     else if (particle == m_xmlConditionAttrObjectCenJet) {
01703         caloObjType = CenJet;
01704     }
01705     else if (particle == m_xmlConditionAttrObjectTauJet) {
01706         caloObjType = TauJet;
01707     }
01708     else if (particle == m_xmlConditionAttrObjectForJet) {
01709         caloObjType = ForJet;
01710     }
01711     else {
01712         edm::LogError("L1GtTriggerMenuXmlParser") << "Wrong particle for calo-condition ("
01713             << particle << ")" << std::endl;
01714         return false;
01715     }
01716 
01717     int nrObj = getNumFromType(type);
01718     if (nrObj < 0) {
01719         edm::LogError("L1GtTriggerMenuXmlParser") << "Unknown type for calo-condition (" << type
01720             << ")" << "\nCan not determine number of trigger objects. " << std::endl;
01721         return false;
01722     }
01723 
01724     // get greater equal flag
01725 
01726     int intGEq = getGEqFlag(node, m_xmlTagEtThreshold);
01727     if (intGEq < 0) {
01728         edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag"
01729             << std::endl;
01730         return false;
01731     }
01732     // set the boolean value for the ge_eq mode
01733     bool gEq = (intGEq != 0);
01734 
01735     // get values
01736 
01737     // temporary storage of the parameters
01738     std::vector<L1GtCaloTemplate::ObjectParameter> objParameter(nrObj);
01739     L1GtCaloTemplate::CorrelationParameter corrParameter;
01740 
01741     // need at least one value for deltaPhiRange
01742     std::vector<boost::uint64_t> tmpValues((nrObj > 1) ? nrObj : 1);
01743 
01744     // get etThreshold values and fill into structure
01745     if ( !getConditionChildValues(node, m_xmlTagEtThreshold, nrObj, tmpValues) ) {
01746         return false;
01747     }
01748 
01749     for (int i = 0; i < nrObj; i++) {
01750         objParameter[i].etThreshold = tmpValues[i];
01751 
01752         //LogTrace("L1GtTriggerMenuXmlParser")
01753         //<< "      Calo ET high threshold (hex) for calo object " << i << " = "
01754         //<< std::hex << objParameter[i].etThreshold << std::dec
01755         //<< std::endl;
01756     }
01757 
01758     // get etaRange and fill into structure
01759     if ( !getConditionChildValues(node, m_xmlTagEta, nrObj, tmpValues) ) {
01760         return false;
01761     }
01762 
01763 
01764     for (int i = 0; i < nrObj; i++) {
01765 
01766         objParameter[i].etaRange = tmpValues[i];
01767 
01768         //LogTrace("L1GtTriggerMenuXmlParser")
01769         //<< "      etaRange (hex) for calo object " << i << " = "
01770         //<< std::hex << objParameter[i].etaRange << std::dec
01771         //<< std::endl;
01772     }
01773 
01774     // get phiRange values and fill into structure
01775     if ( !getConditionChildValues(node, m_xmlTagPhi, nrObj, tmpValues) ) {
01776         return false;
01777     }
01778 
01779     for (int i = 0; i < nrObj; i++) {
01780         objParameter[i].phiRange = tmpValues[i];
01781 
01782         //LogTrace("L1GtTriggerMenuXmlParser")
01783         //<< "      phiRange (hex) for calo object " << i << " = "
01784         //<< std::hex << objParameter[i].phiRange << std::dec
01785         //<< std::endl;
01786     }
01787 
01788     // indicates if a correlation is used
01789     bool wscVal = (type == m_xmlConditionAttrType2wsc );
01790 
01791     if (wscVal) {
01792         // get deltaEtaRange
01793         if ( !getConditionChildValues(node, m_xmlTagDeltaEta, 1, tmpValues) ) {
01794             return false;
01795         }
01796 
01797         corrParameter.deltaEtaRange = tmpValues[0];
01798 
01799         // get deltaPhiRange
01800         if ( !getConditionChildValues(node, m_xmlTagDeltaPhi, 1, tmpValues) ) {
01801             return false;
01802         }
01803 
01804         corrParameter.deltaPhiRange = tmpValues[0];
01805 
01806         // get maximum number of bits for delta phi
01807         //LogTrace("L1GtTriggerMenuXmlParser")
01808         //<< "      Counting deltaPhiMaxbits"
01809         //<< std::endl;
01810 
01811         unsigned int maxbits;
01812 
01813         if ( !countConditionChildMaxBits(node, m_xmlTagDeltaPhi, maxbits) ) {
01814             return false;
01815         }
01816 
01817         corrParameter.deltaPhiMaxbits = maxbits;
01818         //LogTrace("L1GtTriggerMenuXmlParser")
01819         //<< "        deltaPhiMaxbits (dec) = " << maxbits
01820         //<< std::endl;
01821     }
01822 
01823     // get the type of the condition, as defined in enum, from the condition type
01824     // as defined in the XML file
01825     L1GtConditionType cType = getTypeFromType(type);
01826     //LogTrace("L1GtTriggerMenuXmlParser")
01827     //<< "      Condition type (enum value) = " << cType
01828     //<< std::endl;
01829 
01830     if (cType == TypeNull) {
01831         edm::LogError("L1GtTriggerMenuXmlParser")
01832             << "Type for calo condition id TypeNull - it means not defined in the XML file."
01833             << "\nNumber of trigger objects is set to zero. " << std::endl;
01834         return false;
01835     }
01836 
01837     // object types - all same caloObjType
01838     std::vector<L1GtObject> objType(nrObj, caloObjType);
01839 
01840     // now create a new calo condition
01841 
01842     L1GtCaloTemplate caloCond(name);
01843 
01844     caloCond.setCondType(cType);
01845     caloCond.setObjectType(objType);
01846     caloCond.setCondGEq(gEq);
01847     caloCond.setCondChipNr(chipNr);
01848 
01849     caloCond.setConditionParameter(objParameter, corrParameter);
01850 
01851     if (edm::isDebugEnabled() ) {
01852 
01853         std::ostringstream myCoutStream;
01854         caloCond.print(myCoutStream);
01855         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
01856 
01857     }
01858 
01859     // insert condition into the map
01860     if ( !insertConditionIntoMap(caloCond, chipNr)) {
01861 
01862         edm::LogError("L1GtTriggerMenuXmlParser")
01863                 << "    Error: duplicate condition (" << name << ")"
01864                 << std::endl;
01865 
01866         return false;
01867     }
01868     else {
01869 
01870         if (corrFlag) {
01871             (m_corCaloTemplate[chipNr]).push_back(caloCond);
01872        }
01873         else {
01874             (m_vecCaloTemplate[chipNr]).push_back(caloCond);
01875         }
01876 
01877     }
01878 
01879 
01880     //
01881     return true;
01882 }
01883 
01895 bool L1GtTriggerMenuXmlParser::parseEnergySum(
01896         XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name,
01897         unsigned int chipNr, const bool corrFlag) {
01898 
01899     XERCES_CPP_NAMESPACE_USE
01900 
01901     // get condition, particle name and type name
01902     std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
01903     std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
01904     std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
01905 
01906     // determine object type type
01907     L1GtObject energySumObjType;
01908     L1GtConditionType cType;
01909 
01910     if ((particle == m_xmlConditionAttrObjectETM) && (type == m_xmlConditionAttrObjectETM)) {
01911 
01912         energySumObjType = ETM;
01913         cType = TypeETM;
01914 
01915     }
01916     else if ((particle == m_xmlConditionAttrObjectETT) && (type == m_xmlConditionAttrObjectETT)) {
01917 
01918         energySumObjType = ETT;
01919         cType = TypeETT;
01920 
01921     }
01922     else if ((particle == m_xmlConditionAttrObjectHTT) && (type == m_xmlConditionAttrObjectHTT)) {
01923 
01924         energySumObjType = HTT;
01925         cType = TypeHTT;
01926 
01927     }
01928     else {
01929         edm::LogError("L1GtTriggerMenuXmlParser")
01930             << "Wrong particle or type for energy-sum condition (" << particle << ", " << type
01931             << ")" << std::endl;
01932         return false;
01933     }
01934 
01935     // global object
01936     int nrObj = 1;
01937 
01938     // get greater equal flag
01939 
01940     int intGEq = getGEqFlag(node, m_xmlTagEtThreshold);
01941     if (intGEq < 0) {
01942         edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag"
01943             << std::endl;
01944         return false;
01945     }
01946     // set the boolean value for the ge_eq mode
01947     bool gEq = (intGEq != 0);
01948 
01949     // get values
01950 
01951     // temporary storage of the parameters
01952     std::vector<L1GtEnergySumTemplate::ObjectParameter> objParameter(nrObj);
01953 
01954     // need at least two values for phi
01955     std::vector<boost::uint64_t> tmpValues((nrObj > 2) ? nrObj : 2);
01956 
01957     // get etThreshold values and fill into structure
01958     if ( !getConditionChildValues(node, m_xmlTagEtThreshold, nrObj, tmpValues) ) {
01959         return false;
01960     }
01961 
01962     for (int i = 0; i < nrObj; i++) {
01963         objParameter[i].etThreshold = tmpValues[i];
01964 
01965         //LogTrace("L1GtTriggerMenuXmlParser")
01966         //<< "      EnergySum ET high threshold (hex) for energySum object " << i << " = "
01967         //<< std::hex << objParameter[i].etThreshold << std::dec
01968         //<< std::endl;
01969 
01970         // for ETM read phi value
01971         // phi is larger than 64 bits -it needs two 64bits words
01972         if (energySumObjType == ETM) {
01973 
01974             if ( !getXMLHexTextValue128(findXMLChild(node->getFirstChild(), m_xmlTagPhi),
01975                 tmpValues[0], tmpValues[1])) {
01976                 edm::LogError("L1GtTriggerMenuXmlParser")
01977                     << "    Could not get phi for ETM condition (" << name << ")" << std::endl;
01978                 return false;
01979             }
01980 
01981             objParameter[i].phiRange0Word = tmpValues[0];
01982             objParameter[i].phiRange1Word = tmpValues[1];
01983 
01984         }
01985 
01986         // get energyOverflow logical flag and fill into structure
01987         DOMNode* n1;
01988         if ( (n1 = findXMLChild(node->getFirstChild(), m_xmlTagEtThreshold)) == 0) {
01989             edm::LogError("L1GtTriggerMenuXmlParser")
01990                 << "    Could not get energyOverflow for EnergySum condition (" << name << ")"
01991                 << std::endl;
01992             return false;
01993         }
01994         if ( (n1 = findXMLChild(n1->getFirstChild(), m_xmlTagEnergyOverflow)) == 0) {
01995             edm::LogError("L1GtTriggerMenuXmlParser")
01996                 << "    Could not get energyOverflow for EnergySum condition (" << name << ")"
01997                 << std::endl;
01998             return false;
01999         }
02000 
02001         int tmpInt = getBitFromNode(n1);
02002         if (tmpInt == 0) {
02003             objParameter[i].energyOverflow = false;
02004 
02005             //LogTrace("L1GtTriggerMenuXmlParser")
02006             //<< "      EnergySum energyOverflow logical flag (hex) = "
02007             //<< std::hex << objParameter[i].energyOverflow << std::dec
02008             //<< std::endl;
02009         }
02010         else if (tmpInt == 1) {
02011             objParameter[i].energyOverflow = true;
02012 
02013             //LogTrace("L1GtTriggerMenuXmlParser")
02014             //<< "      EnergySum energyOverflow logical flag (hex) = "
02015             //<< std::hex << objParameter[i].energyOverflow << std::dec
02016             //<< std::endl;
02017         }
02018         else {
02019             LogTrace("L1GtTriggerMenuXmlParser")
02020                 << "      EnergySum energyOverflow logical flag (hex) = " << std::hex << tmpInt
02021                 << std::dec << " - wrong value! " << std::endl;
02022             return false;
02023         }
02024 
02025     }
02026 
02027     // object types - all same energySumObjType
02028     std::vector<L1GtObject> objType(nrObj, energySumObjType);
02029 
02030     // now create a new energySum condition
02031 
02032     L1GtEnergySumTemplate energySumCond(name);
02033 
02034     energySumCond.setCondType(cType);
02035     energySumCond.setObjectType(objType);
02036     energySumCond.setCondGEq(gEq);
02037     energySumCond.setCondChipNr(chipNr);
02038 
02039     energySumCond.setConditionParameter(objParameter);
02040 
02041     if (edm::isDebugEnabled() ) {
02042 
02043         std::ostringstream myCoutStream;
02044         energySumCond.print(myCoutStream);
02045         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
02046 
02047     }
02048 
02049     // insert condition into the map
02050     if ( !insertConditionIntoMap(energySumCond, chipNr)) {
02051 
02052         edm::LogError("L1GtTriggerMenuXmlParser")
02053                 << "    Error: duplicate condition (" << name << ")"
02054                 << std::endl;
02055 
02056         return false;
02057     }
02058     else {
02059 
02060         if (corrFlag) {
02061             (m_corEnergySumTemplate[chipNr]).push_back(energySumCond);
02062 
02063         }
02064         else {
02065             (m_vecEnergySumTemplate[chipNr]).push_back(energySumCond);
02066         }
02067 
02068     }
02069 
02070 
02071     //
02072     return true;
02073 }
02074 
02087 bool L1GtTriggerMenuXmlParser::parseJetCounts(XERCES_CPP_NAMESPACE::DOMNode* node,
02088     const std::string& name, unsigned int chipNr) {
02089 
02090     XERCES_CPP_NAMESPACE_USE
02091 
02092     // get condition, particle name and type name
02093     std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
02094     std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
02095     std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
02096 
02097     if (particle != m_xmlConditionAttrObjectJetCounts) {
02098         edm::LogError("L1GtTriggerMenuXmlParser") << "Wrong particle for JetCounts condition ("
02099             << particle << ")" << std::endl;
02100         return false;
02101     }
02102 
02103     // object type and condition type
02104     L1GtObject jetCountsObjType = JetCounts;
02105     L1GtConditionType cType = TypeJetCounts;
02106 
02107     // global object
02108     int nrObj = 1;
02109 
02110     // get greater equal flag
02111 
02112     int intGEq = getGEqFlag(node, m_xmlTagCountThreshold);
02113     if (intGEq < 0) {
02114         edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag"
02115             << std::endl;
02116         return false;
02117     }
02118     // set the boolean value for the ge_eq mode
02119     bool gEq = (intGEq != 0);
02120 
02121     // get values
02122 
02123     // temporary storage of the parameters
02124     std::vector<L1GtJetCountsTemplate::ObjectParameter> objParameter(nrObj);
02125 
02126     // get countIndex value and fill into structure
02127     // they are expressed in  base 10  (values: 0 - m_numberL1JetCounts)
02128     char* endPtr = const_cast<char*>(type.c_str());
02129     long int typeInt = strtol(type.c_str(), &endPtr, 10); // base = 10
02130     unsigned int typeIntUInt = static_cast<unsigned int>(typeInt);
02131 
02132     if (*endPtr != 0) {
02133 
02134         LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << type << " to dec."
02135             << std::endl;
02136 
02137         return false;
02138     }
02139 
02140     // test if count index is out of range
02141     if ((typeIntUInt < 0) || (typeIntUInt > m_numberL1JetCounts)) {
02142         LogDebug("L1GtTriggerMenuXmlParser") << "Count index " << typeIntUInt
02143             << " outside range [0, " << m_numberL1JetCounts << "]" << std::endl;
02144 
02145         return false;
02146     }
02147 
02148     objParameter[0].countIndex = typeIntUInt;
02149 
02150     // get count threshold values and fill into structure
02151     std::vector<boost::uint64_t> tmpValues(nrObj);
02152 
02153     if ( !getConditionChildValues(node, m_xmlTagCountThreshold, nrObj, tmpValues) ) {
02154         return false;
02155     }
02156 
02157     for (int i = 0; i < nrObj; i++) {
02158         objParameter[i].countThreshold = tmpValues[i];
02159 
02160         //LogTrace("L1GtTriggerMenuXmlParser")
02161         //<< "      JetCounts count threshold (hex) for JetCounts object " << i << " = "
02162         //<< std::hex << objParameter[i].countThreshold << std::dec
02163         //<< std::endl;
02164 
02165         // TODO FIXME un-comment when tag available in XML file
02166 
02167         //        // get countOverflow logical flag and fill into structure
02168         //        DOMNode* n1;
02169         //        if ( (n1 = findXMLChild(node->getFirstChild(), m_xmlTagCountThreshold)) == 0) {
02170         //            edm::LogError("L1GtTriggerMenuXmlParser")
02171         //            << "    Could not get countOverflow for JetCounts condition ("
02172         //            << name << ")"
02173         //            << std::endl;
02174         //            return false;
02175         //        }
02176         //        if ( (n1 = findXMLChild(n1->getFirstChild(), m_xmlTagCountThreshold)) == 0) {
02177         //            edm::LogError("L1GtTriggerMenuXmlParser")
02178         //            << "    Could not get countOverflow for JetCounts condition ("
02179         //            << name << ")"
02180         //            << std::endl;
02181         //            return false;
02182         //        }
02183         //
02184         //        int tmpInt = getBitFromNode(n1);
02185         //        if (tmpInt == 0) {
02186         //            objParameter[i].countOverflow = false;
02187         //
02188         //            LogTrace("L1GtTriggerMenuXmlParser")
02189         //            << "      JetCounts countOverflow logical flag (hex) = "
02190         //            << std::hex << objParameter[i].countOverflow << std::dec
02191         //            << std::endl;
02192         //        } else if (tmpInt == 1) {
02193         //            objParameter[i].countOverflow = true;
02194         //
02195         //            LogTrace("L1GtTriggerMenuXmlParser")
02196         //            << "      JetCounts countOverflow logical flag (hex) = "
02197         //            << std::hex << objParameter[i].countOverflow << std::dec
02198         //            << std::endl;
02199         //        } else {
02200         //            LogTrace("L1GtTriggerMenuXmlParser")
02201         //            << "      JetCounts countOverflow logical flag (hex) = "
02202         //            << std::hex << tmpInt << std::dec << " - wrong value! "
02203         //            << std::endl;
02204         //            return false;
02205         //        }
02206 
02207     }
02208 
02209     // object types - all same objType
02210     std::vector<L1GtObject> objType(nrObj, jetCountsObjType);
02211 
02212     // now create a new JetCounts condition
02213 
02214     L1GtJetCountsTemplate jetCountsCond(name);
02215 
02216     jetCountsCond.setCondType(cType);
02217     jetCountsCond.setObjectType(objType);
02218     jetCountsCond.setCondGEq(gEq);
02219     jetCountsCond.setCondChipNr(chipNr);
02220 
02221     jetCountsCond.setConditionParameter(objParameter);
02222 
02223     if (edm::isDebugEnabled() ) {
02224 
02225         std::ostringstream myCoutStream;
02226         jetCountsCond.print(myCoutStream);
02227         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
02228 
02229     }
02230 
02231     // insert condition into the map
02232     if ( !insertConditionIntoMap(jetCountsCond, chipNr)) {
02233 
02234         edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name
02235             << ")" << std::endl;
02236 
02237         return false;
02238     } else {
02239 
02240         (m_vecJetCountsTemplate[chipNr]).push_back(jetCountsCond);
02241 
02242     }
02243 
02244 
02245     //
02246     return true;
02247 }
02248 
02261 bool L1GtTriggerMenuXmlParser::parseCastor(XERCES_CPP_NAMESPACE::DOMNode* node,
02262     const std::string& name, unsigned int chipNr) {
02263 
02264     XERCES_CPP_NAMESPACE_USE
02265 
02266     // get condition, particle name and type name
02267     std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
02268     std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
02269     std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
02270 
02271     if (particle != m_xmlConditionAttrObjectCastor) {
02272         edm::LogError("L1GtTriggerMenuXmlParser")
02273             << "\nError: wrong particle for Castor condition ("
02274             << particle << ")" << std::endl;
02275         return false;
02276     }
02277 
02278     // object type and condition type
02279     // object type - irrelevant for CASTOR conditions
02280     L1GtConditionType cType = TypeCastor;
02281 
02282     // no objects for CASTOR conditions
02283 
02284     // set the boolean value for the ge_eq mode - irrelevant for CASTOR conditions
02285     bool gEq = false;
02286 
02287     // now create a new CASTOR condition
02288 
02289     L1GtCastorTemplate castorCond(name);
02290 
02291     castorCond.setCondType(cType);
02292     castorCond.setCondGEq(gEq);
02293     castorCond.setCondChipNr(chipNr);
02294 
02295 
02296     if (edm::isDebugEnabled() ) {
02297 
02298         std::ostringstream myCoutStream;
02299         castorCond.print(myCoutStream);
02300         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
02301 
02302     }
02303 
02304     // insert condition into the map
02305     if ( !insertConditionIntoMap(castorCond, chipNr)) {
02306 
02307         edm::LogError("L1GtTriggerMenuXmlParser")
02308             << "    Error: duplicate condition (" << name
02309             << ")" << std::endl;
02310 
02311         return false;
02312     } else {
02313 
02314         (m_vecCastorTemplate[chipNr]).push_back(castorCond);
02315 
02316     }
02317 
02318 
02319     //
02320     return true;
02321 }
02322 
02323 
02336 bool L1GtTriggerMenuXmlParser::parseHfBitCounts(XERCES_CPP_NAMESPACE::DOMNode* node,
02337     const std::string& name, unsigned int chipNr) {
02338 
02339     XERCES_CPP_NAMESPACE_USE
02340 
02341     // get condition, particle name and type name
02342     std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
02343     std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
02344     std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
02345 
02346     if (particle != m_xmlConditionAttrObjectHfBitCounts) {
02347         edm::LogError("L1GtTriggerMenuXmlParser") << "Wrong particle for HfBitCounts condition ("
02348             << particle << ")" << std::endl;
02349         return false;
02350     }
02351 
02352     // object type and condition type
02353     L1GtObject hfBitCountsObjType = HfBitCounts;
02354     L1GtConditionType cType = TypeHfBitCounts;
02355 
02356     // global object
02357     int nrObj = 1;
02358 
02359     // get greater equal flag
02360 
02361     int intGEq = getGEqFlag(node, m_xmlTagCountThreshold);
02362     if (intGEq < 0) {
02363         edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag"
02364             << std::endl;
02365         return false;
02366     }
02367     // set the boolean value for the ge_eq mode
02368     bool gEq = (intGEq != 0);
02369 
02370     // get values
02371 
02372     // temporary storage of the parameters
02373     std::vector<L1GtHfBitCountsTemplate::ObjectParameter> objParameter(nrObj);
02374 
02375     // get countIndex value and fill into structure
02376     // they are expressed in  base 10
02377     char* endPtr = const_cast<char*>(type.c_str());
02378     long int typeInt = strtol(type.c_str(), &endPtr, 10); // base = 10
02379     unsigned int typeIntUInt = static_cast<unsigned int>(typeInt);
02380 
02381     if (*endPtr != 0) {
02382 
02383         LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << type << " to dec."
02384             << std::endl;
02385 
02386         return false;
02387     }
02388 
02389     // test if count index is out of range FIXME introduce m_numberL1HfBitCounts?
02390     //if ((typeIntUInt < 0) || (typeIntUInt > m_numberL1HfBitCounts)) {
02391     //    LogDebug("L1GtTriggerMenuXmlParser") << "Count index " << typeIntUInt
02392     //        << " outside range [0, " << m_numberL1HfBitCounts << "]" << std::endl;
02393     //
02394     //    return false;
02395     //}
02396 
02397     objParameter[0].countIndex = typeIntUInt;
02398 
02399     // get count threshold values and fill into structure
02400     std::vector<boost::uint64_t> tmpValues(nrObj);
02401 
02402     if ( !getConditionChildValues(node, m_xmlTagCountThreshold, nrObj, tmpValues) ) {
02403         return false;
02404     }
02405 
02406     for (int i = 0; i < nrObj; i++) {
02407         objParameter[i].countThreshold = tmpValues[i];
02408 
02409         //LogTrace("L1GtTriggerMenuXmlParser")
02410         //<< "      HfBitCounts count threshold (hex) for HfBitCounts object " << i << " = "
02411         //<< std::hex << objParameter[i].countThreshold << std::dec
02412         //<< std::endl;
02413 
02414     }
02415 
02416     // object types - all same objType
02417     std::vector<L1GtObject> objType(nrObj, hfBitCountsObjType);
02418 
02419     // now create a new HfBitCounts condition
02420 
02421     L1GtHfBitCountsTemplate hfBitCountsCond(name);
02422 
02423     hfBitCountsCond.setCondType(cType);
02424     hfBitCountsCond.setObjectType(objType);
02425     hfBitCountsCond.setCondGEq(gEq);
02426     hfBitCountsCond.setCondChipNr(chipNr);
02427 
02428     hfBitCountsCond.setConditionParameter(objParameter);
02429 
02430     if (edm::isDebugEnabled() ) {
02431 
02432         std::ostringstream myCoutStream;
02433         hfBitCountsCond.print(myCoutStream);
02434         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
02435 
02436     }
02437 
02438     // insert condition into the map
02439     if ( !insertConditionIntoMap(hfBitCountsCond, chipNr)) {
02440 
02441         edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name
02442             << ")" << std::endl;
02443 
02444         return false;
02445     } else {
02446 
02447         (m_vecHfBitCountsTemplate[chipNr]).push_back(hfBitCountsCond);
02448 
02449     }
02450 
02451 
02452     //
02453     return true;
02454 }
02455 
02456 
02469 bool L1GtTriggerMenuXmlParser::parseHfRingEtSums(XERCES_CPP_NAMESPACE::DOMNode* node,
02470     const std::string& name, unsigned int chipNr) {
02471 
02472     XERCES_CPP_NAMESPACE_USE
02473 
02474     // get condition, particle name and type name
02475     std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
02476     std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
02477     std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
02478 
02479     if (particle != m_xmlConditionAttrObjectHfRingEtSums) {
02480         edm::LogError("L1GtTriggerMenuXmlParser") << "Wrong particle for HfRingEtSums condition ("
02481             << particle << ")" << std::endl;
02482         return false;
02483     }
02484 
02485     // object type and condition type
02486     L1GtObject hfRingEtSumsObjType = HfRingEtSums;
02487     L1GtConditionType cType = TypeHfRingEtSums;
02488 
02489     // global object
02490     int nrObj = 1;
02491 
02492     // get greater equal flag
02493 
02494     int intGEq = getGEqFlag(node, m_xmlTagEtThreshold);
02495     if (intGEq < 0) {
02496         edm::LogError("L1GtTriggerMenuXmlParser") << "Error getting \"greater or equal\" flag"
02497             << std::endl;
02498         return false;
02499     }
02500     // set the boolean value for the ge_eq mode
02501     bool gEq = (intGEq != 0);
02502 
02503     // get values
02504 
02505     // temporary storage of the parameters
02506     std::vector<L1GtHfRingEtSumsTemplate::ObjectParameter> objParameter(nrObj);
02507 
02508     // get etSumIndex value and fill into structure
02509     // they are expressed in  base 10
02510     char* endPtr = const_cast<char*>(type.c_str());
02511     long int typeInt = strtol(type.c_str(), &endPtr, 10); // base = 10
02512     unsigned int typeIntUInt = static_cast<unsigned int>(typeInt);
02513 
02514     if (*endPtr != 0) {
02515 
02516         LogDebug("L1GtTriggerMenuXmlParser") << "Unable to convert " << type << " to dec."
02517             << std::endl;
02518 
02519         return false;
02520     }
02521 
02522     // test if ET sum index is out of range FIXME introduce m_numberL1HfRingEtSums?
02523     //if ((typeIntUInt < 0) || (typeIntUInt > m_numberL1HfRingEtSums)) {
02524     //    LogDebug("L1GtTriggerMenuXmlParser") << "Count index " << typeIntUInt
02525     //        << " outside range [0, " << m_numberL1HfRingEtSums << "]" << std::endl;
02526     //
02527     //    return false;
02528     //}
02529 
02530     objParameter[0].etSumIndex = typeIntUInt;
02531 
02532     // get ET sum threshold values and fill into structure
02533     std::vector<boost::uint64_t> tmpValues(nrObj);
02534 
02535     if ( !getConditionChildValues(node, m_xmlTagEtThreshold, nrObj, tmpValues) ) {
02536         return false;
02537     }
02538 
02539     for (int i = 0; i < nrObj; i++) {
02540         objParameter[i].etSumThreshold = tmpValues[i];
02541 
02542         //LogTrace("L1GtTriggerMenuXmlParser")
02543         //<< "      HfRingEtSums count threshold (hex) for HfRingEtSums object " << i << " = "
02544         //<< std::hex << objParameter[i].etSumThreshold << std::dec
02545         //<< std::endl;
02546 
02547     }
02548 
02549     // object types - all same objType
02550     std::vector<L1GtObject> objType(nrObj, hfRingEtSumsObjType);
02551 
02552     // now create a new HfRingEtSums condition
02553 
02554     L1GtHfRingEtSumsTemplate hfRingEtSumsCond(name);
02555 
02556     hfRingEtSumsCond.setCondType(cType);
02557     hfRingEtSumsCond.setObjectType(objType);
02558     hfRingEtSumsCond.setCondGEq(gEq);
02559     hfRingEtSumsCond.setCondChipNr(chipNr);
02560 
02561     hfRingEtSumsCond.setConditionParameter(objParameter);
02562 
02563     if (edm::isDebugEnabled() ) {
02564 
02565         std::ostringstream myCoutStream;
02566         hfRingEtSumsCond.print(myCoutStream);
02567         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
02568 
02569     }
02570 
02571     // insert condition into the map
02572     if ( !insertConditionIntoMap(hfRingEtSumsCond, chipNr)) {
02573 
02574         edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: duplicate condition (" << name
02575             << ")" << std::endl;
02576 
02577         return false;
02578     } else {
02579 
02580         (m_vecHfRingEtSumsTemplate[chipNr]).push_back(hfRingEtSumsCond);
02581 
02582     }
02583 
02584 
02585     //
02586     return true;
02587 }
02588 
02601 bool L1GtTriggerMenuXmlParser::parseCorrelation(
02602         XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name,
02603         unsigned int chipNr) {
02604 
02605     XERCES_CPP_NAMESPACE_USE
02606 
02607     // create a new correlation condition
02608     L1GtCorrelationTemplate correlationCond(name);
02609 
02610     // check that the condition does not exist already in the map
02611     if ( !insertConditionIntoMap(correlationCond, chipNr)) {
02612 
02613         edm::LogError("L1GtTriggerMenuXmlParser")
02614                 << "    Error: duplicate correlation condition (" << name << ")"
02615                 << std::endl;
02616 
02617         return false;
02618     }
02619 
02620     // get condition, particle name and type name
02621     std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
02622     std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
02623     std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
02624 
02625     LogTrace("L1GtTriggerMenuXmlParser") << "    Condition category: "
02626             << condition << ", particle: " << particle << ", type: " << type
02627             << "\n" << std::endl;
02628 
02629     // condition type
02630     L1GtConditionType cType = Type2cor;
02631 
02632     // two objects (for sure)
02633     const int nrObj = 2;
02634 
02635     // object types and greater equal flag - filled in the loop
02636     int intGEq[nrObj] = { -1, -1 };
02637     std::vector<L1GtObject> objType(nrObj);
02638     std::vector<L1GtConditionCategory> condCateg(nrObj);
02639 
02640     // correlation flag and index in the cor*vector
02641     const bool corrFlag = true;
02642     int corrIndexVal[nrObj] = { -1, -1 };
02643 
02644     // get the subconditions
02645 
02646     DOMNode* conditionsNode = node->getFirstChild();
02647     std::string conditionNameNodeName;
02648     conditionsNode = findXMLChild(conditionsNode, "", true,
02649             &conditionNameNodeName);
02650 
02651 
02652     for (int iSubCond = 0; iSubCond < nrObj; ++iSubCond) {
02653 
02654         // get for sub-condition:  category, object name and type name and condition name
02655         condition = getXMLAttribute(conditionsNode, m_xmlConditionAttrCondition);
02656         particle = getXMLAttribute(conditionsNode, m_xmlConditionAttrObject);
02657         type = getXMLAttribute(conditionsNode, m_xmlConditionAttrType);
02658 
02659         LogTrace("L1GtTriggerMenuXmlParser") << "    Sub-condition category: "
02660                 << condition << ", particle: " << particle << ", type: "
02661                 << type << ", name: " << conditionNameNodeName << "\n"
02662                 << std::endl;
02663 
02664         // call the appropiate function for this condition
02665         if (condition == m_xmlConditionAttrConditionMuon) {
02666             if (!parseMuon(conditionsNode, conditionNameNodeName, chipNr,
02667                     corrFlag)) {
02668                 edm::LogError("L1GtTriggerMenuXmlParser")
02669                         << "Error parsing sub-condition " << condition << ")"
02670                         << " with name " << conditionNameNodeName << std::endl;
02671 
02672             }
02673 
02674             // get greater equal flag
02675             intGEq[iSubCond] = getGEqFlag(conditionsNode,
02676                     m_xmlTagPtHighThreshold);
02677             if (intGEq[iSubCond] < 0) {
02678                 edm::LogError("L1GtTriggerMenuXmlParser")
02679                         << "Error getting \"greater or equal\" flag"
02680                         << " for sub-condition " << conditionNameNodeName
02681                         << " for the correlation condition " << name
02682                         << std::endl;
02683                 return false;
02684             }
02685 
02686             // set object type and sub-condition category
02687             objType[iSubCond] = Mu;
02688             condCateg[iSubCond] = CondMuon;
02689             corrIndexVal[iSubCond] = (m_corMuonTemplate[chipNr]).size() - 1;
02690 
02691         }
02692         else if (condition == m_xmlConditionAttrConditionCalo) {
02693             if (!parseCalo(conditionsNode, conditionNameNodeName, chipNr,
02694                     corrFlag)) {
02695                 edm::LogError("L1GtTriggerMenuXmlParser")
02696                         << "Error parsing sub-condition " << condition << ")"
02697                         << " with name " << conditionNameNodeName << std::endl;
02698 
02699             }
02700 
02701             // get greater equal flag
02702             intGEq[iSubCond] = getGEqFlag(conditionsNode, m_xmlTagEtThreshold);
02703             if (intGEq[iSubCond] < 0) {
02704                 edm::LogError("L1GtTriggerMenuXmlParser")
02705                         << "Error getting \"greater or equal\" flag"
02706                         << " for sub-condition " << conditionNameNodeName
02707                         << " for the correlation condition " << name
02708                         << std::endl;
02709                 return false;
02710             }
02711 
02712             // set object type and sub-condition category
02713             if (particle == m_xmlConditionAttrObjectNoIsoEG) {
02714                 objType[iSubCond] = NoIsoEG;
02715             }
02716             else if (particle == m_xmlConditionAttrObjectIsoEG) {
02717                 objType[iSubCond] = IsoEG;
02718             }
02719             else if (particle == m_xmlConditionAttrObjectCenJet) {
02720                 objType[iSubCond] = CenJet;
02721             }
02722             else if (particle == m_xmlConditionAttrObjectTauJet) {
02723                 objType[iSubCond] = TauJet;
02724             }
02725             else if (particle == m_xmlConditionAttrObjectForJet) {
02726                 objType[iSubCond] = ForJet;
02727             }
02728             else {
02729                 edm::LogError("L1GtTriggerMenuXmlParser")
02730                         << "Wrong object type " << particle
02731                         << " for sub-condition " << conditionNameNodeName
02732                         << " from the correlation condition " << name
02733                         << std::endl;
02734                 return false;
02735             }
02736 
02737             condCateg[iSubCond] = CondCalo;
02738             corrIndexVal[iSubCond] = (m_corCaloTemplate[chipNr]).size() - 1;
02739 
02740         }
02741         else if (condition == m_xmlConditionAttrConditionEnergySum) {
02742             if (!parseEnergySum(conditionsNode, conditionNameNodeName, chipNr,
02743                     corrFlag)) {
02744                 edm::LogError("L1GtTriggerMenuXmlParser")
02745                         << "Error parsing sub-condition " << condition << ")"
02746                         << " with name " << conditionNameNodeName << std::endl;
02747 
02748             }
02749 
02750             // get greater equal flag
02751             intGEq[iSubCond] = getGEqFlag(conditionsNode, m_xmlTagEtThreshold);
02752             if (intGEq[iSubCond] < 0) {
02753                 edm::LogError("L1GtTriggerMenuXmlParser")
02754                         << "Error getting \"greater or equal\" flag"
02755                         << " for sub-condition " << conditionNameNodeName
02756                         << " for the correlation condition " << name
02757                         << std::endl;
02758                 return false;
02759             }
02760 
02761             // set object type and sub-condition category
02762             if (particle == m_xmlConditionAttrObjectETM) {
02763                 objType[iSubCond] = ETM;
02764             }
02765             else if (particle == m_xmlConditionAttrObjectETT) {
02766                 objType[iSubCond] = ETT;
02767             }
02768             else if (particle == m_xmlConditionAttrObjectHTT) {
02769                 objType[iSubCond] = HTT;
02770             }
02771             else {
02772                 edm::LogError("L1GtTriggerMenuXmlParser")
02773                         << "Wrong object type " << particle
02774                         << " for sub-condition " << conditionNameNodeName
02775                         << " from the correlation condition " << name
02776                         << std::endl;
02777                 return false;
02778             }
02779 
02780             condCateg[iSubCond] = CondEnergySum;
02781             corrIndexVal[iSubCond] = (m_corEnergySumTemplate[chipNr]).size() - 1;
02782 
02783         }
02784         else {
02785             edm::LogError("L1GtTriggerMenuXmlParser")
02786                     << "Unknown or un-adequate sub-condition (" << condition
02787                     << ")" << " with name " << conditionNameNodeName
02788                     << " for the correlation condition " << name << std::endl;
02789 
02790             return false;
02791         }
02792 
02793         conditionsNode = findXMLChild(conditionsNode->getNextSibling(), "",
02794                 true, &conditionNameNodeName);
02795 
02796     }
02797 
02798     // get greater equal flag for the correlation condition
02799     bool gEq = true;
02800     if (intGEq[0] != intGEq[1]) {
02801         edm::LogError("L1GtTriggerMenuXmlParser")
02802                 << "Inconsistent GEq flags for sub-conditions (" << condition
02803                 << ")" << " with name " << conditionNameNodeName
02804                 << " for the correlation condition " << name << std::endl;
02805         return false;
02806 
02807     }
02808     else {
02809         gEq = (intGEq[0] != 0);
02810 
02811     }
02812 
02813     // correlation parameters
02814 
02815     // temporary storage of the parameters
02816     L1GtCorrelationTemplate::CorrelationParameter corrParameter;
02817     std::vector<boost::uint64_t> tmpValues(nrObj);
02818 
02819     // get deltaEtaRange
02820 //    if ( !getConditionChildValues(node, m_xmlTagDeltaEta, 1, tmpValues) ) {
02821 //        return false;
02822 //    }
02823 //
02824 //    corrParameter.deltaEtaRange = tmpValues[0];
02825 
02826     XERCES_CPP_NAMESPACE::DOMNode* node1 = findXMLChild(node->getFirstChild(),
02827             m_xmlTagDeltaEta);
02828 
02829     std::string valString;
02830 
02831     if (node1 == 0) {
02832         edm::LogError("L1GtTriggerMenuXmlParser")
02833                 << "    Could not get deltaEta for correlation condition "
02834                 << name << ". " << std::endl;
02835         return false;
02836     }
02837     else {
02838         valString = getXMLTextValue(node1);
02839     }
02840 
02841     corrParameter.deltaEtaRange = valString;
02842 
02843 //    // deltaPhi is larger than 64bit
02844 //    if ( !getXMLHexTextValue128(findXMLChild(node->getFirstChild(), m_xmlTagDeltaPhi),
02845 //        tmpValues[0], tmpValues[1])) {
02846 //        edm::LogError("L1GtTriggerMenuXmlParser")
02847 //            << "    Could not get deltaPhi for correlation condition " << name << ". "
02848 //            << std::endl;
02849 //        return false;
02850 //    }
02851 //
02852 //    corrParameter.deltaPhiRange = tmpValues[0];
02853 
02854    node1 = findXMLChild(node->getFirstChild(), m_xmlTagDeltaPhi);
02855 
02856     if (node1 == 0) {
02857         return false;
02858         edm::LogError("L1GtTriggerMenuXmlParser")
02859                 << "    Could not get deltaPhi for correlation condition "
02860                 << name << ". " << std::endl;
02861     }
02862     else {
02863         valString = getXMLTextValue(node1);
02864     }
02865 
02866     corrParameter.deltaPhiRange = valString;
02867 
02868     // get maximum number of bits for delta phi
02869     //LogTrace("L1GtTriggerMenuXmlParser")
02870     //<< "      Counting deltaPhiMaxbits"
02871     //<< std::endl;
02872 
02873     unsigned int maxbits;
02874 
02875     if ( !countConditionChildMaxBits(node, m_xmlTagDeltaPhi, maxbits) ) {
02876         return false;
02877     }
02878 
02879     corrParameter.deltaPhiMaxbits = maxbits;
02880     //LogTrace("L1GtTriggerMenuXmlParser")
02881     //<< "        deltaPhiMaxbits (dec) = " << maxbits
02882     //<< std::endl;
02883 
02884 
02885     // fill the correlation condition
02886     correlationCond.setCondType(cType);
02887     correlationCond.setObjectType(objType);
02888     correlationCond.setCondGEq(gEq);
02889     correlationCond.setCondChipNr(chipNr);
02890 
02891     correlationCond.setCond0Category(condCateg[0]);
02892     correlationCond.setCond1Category(condCateg[1]);
02893 
02894     correlationCond.setCond0Index(corrIndexVal[0]);
02895     correlationCond.setCond1Index(corrIndexVal[1]);
02896 
02897     correlationCond.setCorrelationParameter(corrParameter);
02898 
02899     if (edm::isDebugEnabled() ) {
02900 
02901         std::ostringstream myCoutStream;
02902         correlationCond.print(myCoutStream);
02903         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n"
02904                 << std::endl;
02905 
02906     }
02907 
02908     // insert condition into the map
02909     // condition is not duplicate, check was done at the beginning
02910 
02911     (m_vecCorrelationTemplate[chipNr]).push_back(correlationCond);
02912 
02913     //
02914     return true;
02915 }
02916 
02917 
02929 bool L1GtTriggerMenuXmlParser::workCondition(XERCES_CPP_NAMESPACE::DOMNode* node,
02930     const std::string& name, unsigned int chipNr) {
02931 
02932     XERCES_CPP_NAMESPACE_USE
02933 
02934     // get condition, particle name and type name
02935     std::string condition = getXMLAttribute(node, m_xmlConditionAttrCondition);
02936     std::string particle = getXMLAttribute(node, m_xmlConditionAttrObject);
02937     std::string type = getXMLAttribute(node, m_xmlConditionAttrType);
02938 
02939     if (condition.empty() || particle.empty() || type.empty() ) {
02940 
02941         edm::LogError("L1GtTriggerMenuXmlParser") << "Missing attributes for condition " << name
02942             << std::endl;
02943 
02944         return false;
02945     }
02946 
02947     //LogTrace("L1GtTriggerMenuXmlParser")
02948     //<< "    condition: " << condition << ", particle: " << particle
02949     //<< ", type: " << type << std::endl;
02950 
02951     // call the appropiate function for this condition
02952 
02953     if (condition == m_xmlConditionAttrConditionMuon) {
02954         return parseMuon(node, name, chipNr);
02955     }
02956     else if (condition == m_xmlConditionAttrConditionCalo) {
02957         return parseCalo(node, name, chipNr);
02958     }
02959     else if (condition == m_xmlConditionAttrConditionEnergySum) {
02960         return parseEnergySum(node, name, chipNr);
02961     }
02962     else if (condition == m_xmlConditionAttrConditionJetCounts) {
02963         return parseJetCounts(node, name, chipNr);
02964     }
02965     else if (condition == m_xmlConditionAttrConditionCastor) {
02966         return parseCastor(node, name, chipNr);
02967     }
02968     else if (condition == m_xmlConditionAttrConditionHfBitCounts) {
02969         return parseHfBitCounts(node, name, chipNr);
02970     }
02971     else if (condition == m_xmlConditionAttrConditionHfRingEtSums) {
02972         return parseHfRingEtSums(node, name, chipNr);
02973     }
02974     else if (condition == m_xmlConditionAttrConditionCorrelation) {
02975         return parseCorrelation(node, name, chipNr);
02976     }
02977     else {
02978         edm::LogError("L1GtTriggerMenuXmlParser")
02979             << "\n Error: unknown condition (" << condition << ")"
02980             << std::endl;
02981 
02982         return false;
02983     }
02984 
02985     return true;
02986 
02987 }
02988 
02999 bool L1GtTriggerMenuXmlParser::parseConditions(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
03000 
03001     XERCES_CPP_NAMESPACE_USE
03002 
03003     LogTrace("L1GtTriggerMenuXmlParser") << "\nParsing conditions" << std::endl;
03004 
03005     DOMNode* doc = parser->getDocument();
03006     DOMNode* n1 = doc->getFirstChild();
03007 
03008     // we assume that the first child is m_xmlTagDef because it was checked in workXML
03009 
03010     DOMNode* chipNode = n1->getFirstChild();
03011     if (chipNode == 0) {
03012 
03013         edm::LogError("L1GtTriggerMenuXmlParser") << "Error: No child of <" << m_xmlTagDef
03014             << "> tag found." << std::endl;
03015 
03016         return false;
03017     }
03018 
03019     // find chip
03020 
03021     std::string chipName; // name of the actual chip
03022     chipNode = findXMLChild(chipNode, m_xmlTagChip, true, &chipName);
03023     if (chipNode == 0) {
03024 
03025         edm::LogError("L1GtTriggerMenuXmlParser") << "  Error: Could not find <" << m_xmlTagChip
03026             << std::endl;
03027 
03028         return false;
03029     }
03030 
03031     unsigned int chipNr = 0;
03032     do {
03033 
03034         // find conditions
03035         DOMNode* conditionsNode = chipNode->getFirstChild();
03036         conditionsNode = findXMLChild(conditionsNode, m_xmlTagConditions);
03037         if (conditionsNode == 0) {
03038 
03039             edm::LogError("L1GtTriggerMenuXmlParser") << "Error: No <" << m_xmlTagConditions
03040                 << "> child found in Chip " << chipName << std::endl;
03041 
03042             return false;
03043         }
03044 
03045         char* nodeName = XMLString::transcode(chipNode->getNodeName());
03046         //LogTrace("L1GtTriggerMenuXmlParser")
03047         //<< "\n  Found Chip: " << nodeName << " Name: " << chipName
03048         //<< std::endl;
03049 
03050         XMLString::release(&nodeName);
03051 
03052         // walk through conditions
03053         DOMNode* conditionNameNode = conditionsNode->getFirstChild();
03054         std::string conditionNameNodeName;
03055         conditionNameNode = findXMLChild(conditionNameNode, "", true, &conditionNameNodeName);
03056         while (conditionNameNode != 0) {
03057 
03058             LogTrace("L1GtTriggerMenuXmlParser")
03059             << "\n    Found a condition with name: " << conditionNameNodeName
03060             << std::endl;
03061 
03062             if ( !workCondition(conditionNameNode, conditionNameNodeName, chipNr) ) {
03063                 return false;
03064             }
03065             conditionNameNode = findXMLChild(conditionNameNode->getNextSibling(), "", true,
03066                 &conditionNameNodeName);
03067 
03068         }
03069         // next chip
03070         chipNode = findXMLChild(chipNode->getNextSibling(), m_xmlTagChip, true, &chipName);
03071         chipNr++;
03072 
03073     } while (chipNode != 0 && chipNr < m_numberConditionChips);
03074 
03075     return true;
03076 }
03077 
03089 bool L1GtTriggerMenuXmlParser::workAlgorithm(XERCES_CPP_NAMESPACE::DOMNode* node,
03090     const std::string& algName, unsigned int chipNr) {
03091 
03092     XERCES_CPP_NAMESPACE_USE
03093 
03094     if (node == 0) {
03095         LogDebug("L1GtTriggerMenuXmlParser")
03096         << "    Node is 0 in " << __PRETTY_FUNCTION__
03097         << " can not parse the algorithm " << algName
03098         << std::endl;
03099         return false;
03100     }
03101 
03102     // get the logical expression from the node
03103     std::string logExpression = getXMLTextValue(node);
03104 
03105     //LogTrace("L1GtTriggerMenuXmlParser")
03106     //<< "      Logical expression: " << logExpression
03107     //<< std::endl;
03108 
03109     //LogTrace("L1GtTriggerMenuXmlParser")
03110     //<< "      Chip number:        " << chipNr
03111     //<< std::endl;
03112 
03113     // determine output pin
03114     DOMNode* pinNode = findXMLChild(node->getFirstChild(), m_xmlTagOutput);
03115     std::string pinString;
03116     int outputPin = 0;
03117 
03118     pinNode = node->getFirstChild();
03119     while ( (pinNode = findXMLChild(pinNode, m_xmlTagOutputPin) ) != 0) {
03120         pinString = getXMLAttribute(pinNode, m_xmlAttrPin); // we look for the "a" pin
03121         if (pinString == m_xmlAttrPinA) {
03122             // found pin a
03123             pinString = getXMLAttribute(pinNode, m_xmlAttrNr);
03124 
03125             // convert pinString to integer
03126             std::istringstream opStream(pinString);
03127 
03128             if ((opStream >> outputPin).fail()) {
03129                 LogDebug("L1GtTriggerMenuXmlParser") << "    Unable to convert pin string "
03130                     << pinString << " to int for algorithm : " << algName << std::endl;
03131 
03132                 return false;
03133             }
03134 
03135             //LogTrace("L1GtTriggerMenuXmlParser")
03136             //<< "      Output pin:         " << outputPin
03137             //<< std::endl;
03138 
03139             break;
03140         }
03141         pinNode = pinNode->getNextSibling();
03142     }
03143 
03144     if (pinNode == 0) {
03145         LogTrace("L1GtTriggerMenuXmlParser") << "    Warning: No pin number found for algorithm: "
03146             << algName << std::endl;
03147 
03148         return false;
03149     }
03150 
03151     // compute the bit number from chip number, output pin and order of the chips
03152     // pin numbering start with 1, bit numbers with 0
03153     int bitNumber = outputPin + (m_orderConditionChip[chipNr] -1)*m_pinsOnConditionChip -1;
03154 
03155     //LogTrace("L1GtTriggerMenuXmlParser")
03156     //<< "      Bit number:         " << bitNumber
03157     //<< std::endl;
03158 
03159     // create a new algorithm and insert it into algorithm map
03160     L1GtAlgorithm alg(algName, logExpression, bitNumber);
03161     alg.setAlgoChipNumber(static_cast<int>(chipNr));
03162 
03163     if (edm::isDebugEnabled() ) {
03164 
03165         std::ostringstream myCoutStream;
03166         alg.print(myCoutStream);
03167         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
03168 
03169     }
03170 
03171     // insert algorithm into the map
03172     if ( !insertAlgorithmIntoMap(alg)) {
03173 
03174         return false;
03175     }
03176 
03177     return true;
03178 
03179 }
03180 
03181 /*
03182  * parseAlgorithms Parse the algorithms
03183  * NOTE: the algorithms used here are equivalent to "prealgo" from XML file
03184  *       for the VERSION_FINAL
03185  *       The "VERSION_PROTOTYPE algo" will be phased out later in the XML file
03186  *       See L1GlobalTriggerConfig.h (in the attic)
03187  *
03188  * @param parser A reference to the XercesDOMParser to use.
03189  *
03190  * @return "true" if succeeded, "false" if an error occured.
03191  *
03192  */
03193 
03194 bool L1GtTriggerMenuXmlParser::parseAlgorithms(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
03195 
03196     XERCES_CPP_NAMESPACE_USE
03197 
03198     //LogTrace("L1GtTriggerMenuXmlParser") << "\nParsing algorithms" << std::endl;
03199 
03200     DOMNode* doc = parser->getDocument();
03201     DOMNode* node = doc->getFirstChild();
03202 
03203     DOMNode* chipNode = node->getFirstChild();
03204     if (chipNode == 0) {
03205         edm::LogError("L1GtTriggerMenuXmlParser") << "  Error: No child found for " << m_xmlTagDef
03206             << std::endl;
03207         return false;
03208     }
03209 
03210     // find first chip
03211     std::string chipName;
03212     chipNode = findXMLChild(chipNode, m_xmlTagChip, true, &chipName);
03213     if (chipNode == 0) {
03214         edm::LogError("L1GtTriggerMenuXmlParser") << "  Error: Could not find <" << m_xmlTagChip
03215             << std::endl;
03216         return false;
03217     }
03218 
03219     unsigned int chipNr = 0;
03220     do {
03221 
03222         //LogTrace("L1GtTriggerMenuXmlParser") << std::endl;
03223 
03224         std::string nodeName = m_xmlTagChip + chipName;
03225         //LogTrace("L1GtTriggerMenuXmlParser")
03226         //<< "  Chip: " << nodeName << " Name: " << chipName
03227         //<< std::endl;
03228 
03229         // find algorithms
03230         DOMNode* algNode = chipNode->getFirstChild();
03231         algNode = findXMLChild(algNode, m_xmlTagAlgorithms);
03232         if (algNode == 0) {
03233             edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: No <" << m_xmlTagAlgorithms
03234                 << "> child found in chip " << chipName << std::endl;
03235             return false;
03236         }
03237 
03238         // walk through algorithms
03239         DOMNode* algNameNode = algNode->getFirstChild();
03240         std::string algNameNodeName;
03241         algNameNode = findXMLChild(algNameNode, "", true, &algNameNodeName);
03242 
03243         while (algNameNode != 0) {
03244             //LogTrace("L1GtTriggerMenuXmlParser")
03245             //<< "    Found an algorithm with name: " << algNameNodeName
03246             //<< std::endl;
03247 
03248             if ( !workAlgorithm(algNameNode, algNameNodeName, chipNr)) {
03249                 return false;
03250             }
03251 
03252             algNameNode = findXMLChild(algNameNode->getNextSibling(), "", true, &algNameNodeName);
03253 
03254         }
03255 
03256         // next chip
03257         chipNode = findXMLChild(chipNode->getNextSibling(), m_xmlTagChip, true, &chipName);
03258         chipNr++;
03259 
03260     } while (chipNode != 0 && chipNr < m_numberConditionChips);
03261 
03262     return true;
03263 }
03264 
03275 bool L1GtTriggerMenuXmlParser::workTechTrigger(XERCES_CPP_NAMESPACE::DOMNode* node,
03276     const std::string& algName) {
03277 
03278     XERCES_CPP_NAMESPACE_USE
03279 
03280     if (node == 0) {
03281         LogDebug("L1GtTriggerMenuXmlParser")
03282         << "    Node is 0 in " << __PRETTY_FUNCTION__
03283         << " can not parse the technical trigger " << algName
03284         << std::endl;
03285         return false;
03286     }
03287 
03288     // get the logical expression from the node
03289     std::string logExpression = getXMLTextValue(node);
03290 
03291     //LogTrace("L1GtTriggerMenuXmlParser")
03292     //<< "      Logical expression: " << logExpression
03293     //<< std::endl;
03294 
03295     // determine bit number (use output pin tag)
03296     DOMNode* pinNode = findXMLChild(node->getFirstChild(), m_xmlTagOutput);
03297     std::string pinString;
03298     int outputPin = 0;
03299 
03300     pinNode = node->getFirstChild();
03301     if ( (pinNode = findXMLChild(pinNode, m_xmlTagOutputPin) ) != 0) {
03302         pinString = getXMLAttribute(pinNode, m_xmlAttrNr);
03303 
03304         // convert pinString to integer
03305         std::istringstream opStream(pinString);
03306 
03307         if ((opStream >> outputPin).fail()) {
03308             LogDebug("L1GtTriggerMenuXmlParser")
03309                     << "    Unable to convert pin string " << pinString
03310                     << " to int for technical trigger : " << algName
03311                     << std::endl;
03312 
03313             return false;
03314         }
03315 
03316     }
03317 
03318     if (pinNode == 0) {
03319         LogTrace("L1GtTriggerMenuXmlParser")
03320             << "    Warning: No pin number found for technical trigger: "
03321             << algName << std::endl;
03322 
03323         return false;
03324     }
03325 
03326     // set the bit number
03327     int bitNumber = outputPin;
03328 
03329     //LogTrace("L1GtTriggerMenuXmlParser")
03330     //<< "      Bit number:         " << bitNumber
03331     //<< std::endl;
03332 
03333     // create a new technical trigger and insert it into technical trigger map
03334     L1GtAlgorithm alg(algName, logExpression, bitNumber);
03335 
03336     if (edm::isDebugEnabled() ) {
03337 
03338         std::ostringstream myCoutStream;
03339         alg.print(myCoutStream);
03340         LogTrace("L1GtTriggerMenuXmlParser") << myCoutStream.str() << "\n" << std::endl;
03341 
03342     }
03343 
03344     // insert technical trigger into the map
03345     if ( !insertTechTriggerIntoMap(alg)) {
03346 
03347         return false;
03348     }
03349 
03350     return true;
03351 
03352 }
03353 
03354 /*
03355  * parseTechTriggers Parse the technical triggers
03356  *
03357  * @param parser A reference to the XercesDOMParser to use.
03358  *
03359  * @return "true" if succeeded, "false" if an error occured.
03360  *
03361  */
03362 
03363 bool L1GtTriggerMenuXmlParser::parseTechTriggers(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
03364 
03365     XERCES_CPP_NAMESPACE_USE
03366 
03367     //LogTrace("L1GtTriggerMenuXmlParser") << "\nParsing technical triggers" << std::endl;
03368 
03369     DOMNode* doc = parser->getDocument();
03370     DOMNode* node = doc->getFirstChild();
03371 
03372     DOMNode* algNode = node->getFirstChild();
03373     if (algNode == 0) {
03374         edm::LogError("L1GtTriggerMenuXmlParser")
03375                 << "  Error: No child found for " << m_xmlTagDef << std::endl;
03376         return false;
03377     }
03378 
03379     algNode = findXMLChild(algNode, m_xmlTagTechTriggers);
03380     if (algNode == 0) {
03381         edm::LogError("L1GtTriggerMenuXmlParser") << "    Error: No <"
03382                 << m_xmlTagTechTriggers << "> child found."
03383                 << std::endl;
03384         return false;
03385     }
03386 
03387     // walk through technical triggers
03388     DOMNode* algNameNode = algNode->getFirstChild();
03389     std::string algNameNodeName;
03390     algNameNode = findXMLChild(algNameNode, "", true, &algNameNodeName);
03391 
03392     while (algNameNode != 0) {
03393         //LogTrace("L1GtTriggerMenuXmlParser")
03394         //<< "    Found an technical trigger with name: " << algNameNodeName
03395         //<< std::endl;
03396 
03397         if ( !workTechTrigger(algNameNode, algNameNodeName)) {
03398             return false;
03399         }
03400 
03401         algNameNode = findXMLChild(algNameNode->getNextSibling(), "", true,
03402                 &algNameNodeName);
03403 
03404     }
03405 
03406     return true;
03407 }
03408 
03409 
03418 bool L1GtTriggerMenuXmlParser::workXML(XERCES_CPP_NAMESPACE::XercesDOMParser* parser) {
03419 
03420     XERCES_CPP_NAMESPACE_USE
03421 
03422     DOMDocument* doc = parser->getDocument();
03423     DOMNode* n1 = doc->getFirstChild();
03424 
03425     if (n1 == 0) {
03426 
03427         edm::LogError("L1GtTriggerMenuXmlParser") << "Error: Found no XML child" << std::endl;
03428 
03429         return false;
03430     }
03431 
03432     char* nodeName = XMLString::transcode(n1->getNodeName());
03433 
03434     if (XMLString::compareIString(nodeName, m_xmlTagDef.c_str())) {
03435 
03436         edm::LogError("L1GtTriggerMenuXmlParser") << "Error: First XML child is not \" "
03437             << m_xmlTagDef << "\" " << std::endl;
03438 
03439         return false;
03440     }
03441 
03442     LogTrace("L1GtTriggerMenuXmlParser")
03443     << "\nFirst node name is: " << nodeName
03444     << std::endl;
03445     XMLString::release(&nodeName);
03446 
03447     // clear possible old maps
03448     clearMaps();
03449 
03450     if ( !parseConditions(parser) ) {
03451         clearMaps();
03452         return false;
03453     }
03454 
03455     if ( !parseAlgorithms(parser) ) {
03456         clearMaps();
03457         return false;
03458     }
03459 
03460     if ( !parseTechTriggers(parser) ) {
03461         clearMaps();
03462         return false;
03463     }
03464 
03465     return true;
03466 
03467 }
03468 
03469 // static class members
03470 

Generated on Tue Jun 9 17:40:28 2009 for CMSSW by  doxygen 1.5.4