Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef L1GtConfigProducers_L1GtTriggerMenuXmlParser_h
0002 #define L1GtConfigProducers_L1GtTriggerMenuXmlParser_h
0003 
0004 /**
0005  * \class L1GtTriggerMenuXmlParser
0006  *
0007  *
0008  * Description: Xerces-C XML parser for the L1 Trigger menu.
0009  *
0010  * Implementation:
0011  *    <TODO: enter implementation details>
0012  *
0013  * \author: Vasile Mihai Ghete - HEPHY Vienna
0014  * \author  M. Eder            - HEPHY Vienna - ORCA version, reduced functionality
0015  *
0016  *
0017  */
0018 
0019 // system include files
0020 #include <string>
0021 #include <vector>
0022 
0023 #include <xercesc/sax/HandlerBase.hpp>
0024 #include <xercesc/dom/DOM.hpp>
0025 #include <xercesc/parsers/XercesDOMParser.hpp>
0026 
0027 // user include files
0028 // base class
0029 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtXmlParserTags.h"
0030 
0031 #include "CondFormats/L1TObjects/interface/L1GtFwd.h"
0032 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
0033 
0034 #include "CondFormats/L1TObjects/interface/L1GtMuonTemplate.h"
0035 #include "CondFormats/L1TObjects/interface/L1GtCaloTemplate.h"
0036 #include "CondFormats/L1TObjects/interface/L1GtEnergySumTemplate.h"
0037 #include "CondFormats/L1TObjects/interface/L1GtJetCountsTemplate.h"
0038 #include "CondFormats/L1TObjects/interface/L1GtCastorTemplate.h"
0039 #include "CondFormats/L1TObjects/interface/L1GtHfBitCountsTemplate.h"
0040 #include "CondFormats/L1TObjects/interface/L1GtHfRingEtSumsTemplate.h"
0041 #include "CondFormats/L1TObjects/interface/L1GtCorrelationTemplate.h"
0042 #include "CondFormats/L1TObjects/interface/L1GtBptxTemplate.h"
0043 #include "CondFormats/L1TObjects/interface/L1GtExternalTemplate.h"
0044 #include <cstdint>
0045 
0046 // forward declarations
0047 class L1GtCondition;
0048 class L1GtAlgorithm;
0049 
0050 // class declaration
0051 class L1GtTriggerMenuXmlParser : public L1GtXmlParserTags {
0052 public:
0053   /// constructor
0054   ///    empty
0055   L1GtTriggerMenuXmlParser();
0056 
0057   /// destructor
0058   ~L1GtTriggerMenuXmlParser() override;
0059 
0060 public:
0061   ///   get / set the number of condition chips in GTL
0062   inline const unsigned int gtNumberConditionChips() const { return m_numberConditionChips; }
0063 
0064   void setGtNumberConditionChips(const unsigned int&);
0065 
0066   ///   get / set the number of pins on the GTL condition chips
0067   inline const unsigned int gtPinsOnConditionChip() const { return m_pinsOnConditionChip; }
0068 
0069   void setGtPinsOnConditionChip(const unsigned int&);
0070 
0071   ///   get / set the correspondence "condition chip - GTL algorithm word"
0072   ///   in the hardware
0073   inline std::vector<int> gtOrderConditionChip() const { return m_orderConditionChip; }
0074 
0075   void setGtOrderConditionChip(const std::vector<int>&);
0076 
0077   /// get / set the number of physics trigger algorithms
0078   inline const unsigned int gtNumberPhysTriggers() const { return m_numberPhysTriggers; }
0079 
0080   void setGtNumberPhysTriggers(const unsigned int&);
0081 
0082   /// get / set the number of technical triggers
0083   inline const unsigned int gtNumberTechTriggers() const { return m_numberTechTriggers; }
0084 
0085   void setGtNumberTechTriggers(const unsigned int&);
0086 
0087   ///  get / set the number of L1 jet counts received by GT
0088   inline const unsigned int gtNumberL1JetCounts() const { return m_numberL1JetCounts; }
0089 
0090   void setGtNumberL1JetCounts(const unsigned int&);
0091 
0092 public:
0093   /// get / set / build the condition maps
0094   inline const std::vector<ConditionMap>& gtConditionMap() const { return m_conditionMap; }
0095 
0096   void setGtConditionMap(const std::vector<ConditionMap>&);
0097 
0098   /// get / set the trigger menu names
0099   inline const std::string& gtTriggerMenuInterface() const { return m_triggerMenuInterface; }
0100 
0101   void setGtTriggerMenuInterface(const std::string&);
0102 
0103   //
0104   inline const std::string& gtTriggerMenuName() const { return m_triggerMenuName; }
0105 
0106   void setGtTriggerMenuName(const std::string&);
0107 
0108   //
0109   inline const std::string& gtTriggerMenuImplementation() const { return m_triggerMenuImplementation; }
0110 
0111   void setGtTriggerMenuImplementation(const std::string&);
0112 
0113   /// menu associated scale key
0114   inline const std::string& gtScaleDbKey() const { return m_scaleDbKey; }
0115 
0116   void setGtScaleDbKey(const std::string&);
0117 
0118   /// get / set the vectors containing the conditions
0119   inline const std::vector<std::vector<L1GtMuonTemplate> >& vecMuonTemplate() const { return m_vecMuonTemplate; }
0120   void setVecMuonTemplate(const std::vector<std::vector<L1GtMuonTemplate> >&);
0121 
0122   //
0123   inline const std::vector<std::vector<L1GtCaloTemplate> >& vecCaloTemplate() const { return m_vecCaloTemplate; }
0124 
0125   void setVecCaloTemplate(const std::vector<std::vector<L1GtCaloTemplate> >&);
0126 
0127   //
0128   inline const std::vector<std::vector<L1GtEnergySumTemplate> >& vecEnergySumTemplate() const {
0129     return m_vecEnergySumTemplate;
0130   }
0131 
0132   void setVecEnergySumTemplate(const std::vector<std::vector<L1GtEnergySumTemplate> >&);
0133 
0134   //
0135   inline const std::vector<std::vector<L1GtJetCountsTemplate> >& vecJetCountsTemplate() const {
0136     return m_vecJetCountsTemplate;
0137   }
0138 
0139   void setVecJetCountsTemplate(const std::vector<std::vector<L1GtJetCountsTemplate> >&);
0140 
0141   //
0142   inline const std::vector<std::vector<L1GtCastorTemplate> >& vecCastorTemplate() const { return m_vecCastorTemplate; }
0143 
0144   void setVecCastorTemplate(const std::vector<std::vector<L1GtCastorTemplate> >&);
0145 
0146   //
0147   inline const std::vector<std::vector<L1GtHfBitCountsTemplate> >& vecHfBitCountsTemplate() const {
0148     return m_vecHfBitCountsTemplate;
0149   }
0150 
0151   void setVecHfBitCountsTemplate(const std::vector<std::vector<L1GtHfBitCountsTemplate> >&);
0152 
0153   //
0154   inline const std::vector<std::vector<L1GtHfRingEtSumsTemplate> >& vecHfRingEtSumsTemplate() const {
0155     return m_vecHfRingEtSumsTemplate;
0156   }
0157 
0158   void setVecHfRingEtSumsTemplate(const std::vector<std::vector<L1GtHfRingEtSumsTemplate> >&);
0159 
0160   //
0161   inline const std::vector<std::vector<L1GtBptxTemplate> >& vecBptxTemplate() const { return m_vecBptxTemplate; }
0162 
0163   void setVecBptxTemplate(const std::vector<std::vector<L1GtBptxTemplate> >&);
0164 
0165   //
0166   inline const std::vector<std::vector<L1GtExternalTemplate> >& vecExternalTemplate() const {
0167     return m_vecExternalTemplate;
0168   }
0169 
0170   void setVecExternalTemplate(const std::vector<std::vector<L1GtExternalTemplate> >&);
0171 
0172   //
0173   inline const std::vector<std::vector<L1GtCorrelationTemplate> >& vecCorrelationTemplate() const {
0174     return m_vecCorrelationTemplate;
0175   }
0176 
0177   void setVecCorrelationTemplate(const std::vector<std::vector<L1GtCorrelationTemplate> >&);
0178 
0179   // get / set the vectors containing the conditions for correlation templates
0180   //
0181   inline const std::vector<std::vector<L1GtMuonTemplate> >& corMuonTemplate() const { return m_corMuonTemplate; }
0182 
0183   void setCorMuonTemplate(const std::vector<std::vector<L1GtMuonTemplate> >&);
0184 
0185   //
0186   inline const std::vector<std::vector<L1GtCaloTemplate> >& corCaloTemplate() const { return m_corCaloTemplate; }
0187 
0188   void setCorCaloTemplate(const std::vector<std::vector<L1GtCaloTemplate> >&);
0189 
0190   //
0191   inline const std::vector<std::vector<L1GtEnergySumTemplate> >& corEnergySumTemplate() const {
0192     return m_corEnergySumTemplate;
0193   }
0194 
0195   void setCorEnergySumTemplate(const std::vector<std::vector<L1GtEnergySumTemplate> >&);
0196 
0197   /// get / set the algorithm map (by name)
0198   inline const AlgorithmMap& gtAlgorithmMap() const { return m_algorithmMap; }
0199 
0200   void setGtAlgorithmMap(const AlgorithmMap&);
0201 
0202   /// get / set the algorithm map (by alias)
0203   inline const AlgorithmMap& gtAlgorithmAliasMap() const { return m_algorithmAliasMap; }
0204 
0205   void setGtAlgorithmAliasMap(const AlgorithmMap&);
0206 
0207   /// get / set the technical trigger map
0208   inline const AlgorithmMap& gtTechnicalTriggerMap() const { return m_technicalTriggerMap; }
0209 
0210   void setGtTechnicalTriggerMap(const AlgorithmMap&);
0211 
0212 public:
0213   /// parse def.xml and vme.xml files
0214   void parseXmlFile(const std::string& defXmlFile, const std::string& vmeXmlFile);
0215 
0216 public:
0217   /// get / set the XML parser creation date, author, description for menu interface, menu
0218   inline const std::string& gtTriggerMenuInterfaceDate() const { return m_triggerMenuInterfaceDate; }
0219 
0220   void setGtTriggerMenuInterfaceDate(const std::string&);
0221 
0222   inline const std::string& gtTriggerMenuInterfaceAuthor() const { return m_triggerMenuInterfaceAuthor; }
0223 
0224   void setGtTriggerMenuInterfaceAuthor(const std::string&);
0225 
0226   inline const std::string& gtTriggerMenuInterfaceDescription() const { return m_triggerMenuInterfaceDescription; }
0227 
0228   void setGtTriggerMenuInterfaceDescription(const std::string&);
0229 
0230   //
0231 
0232   inline const std::string& gtTriggerMenuDate() const { return m_triggerMenuDate; }
0233 
0234   void setGtTriggerMenuDate(const std::string&);
0235 
0236   inline const std::string& gtTriggerMenuAuthor() const { return m_triggerMenuAuthor; }
0237 
0238   void setGtTriggerMenuAuthor(const std::string&);
0239 
0240   inline const std::string& gtTriggerMenuDescription() const { return m_triggerMenuDescription; }
0241 
0242   void setGtTriggerMenuDescription(const std::string&);
0243 
0244   inline const std::string& gtAlgorithmImplementation() const { return m_algorithmImplementation; }
0245 
0246   void setGtAlgorithmImplementation(const std::string&);
0247 
0248 private:
0249   // XML methods
0250 
0251   /// init xml system
0252   XERCES_CPP_NAMESPACE::XercesDOMParser* initXML(const std::string& xmlFile);
0253 
0254   /// find a named child of a xml node
0255   XERCES_CPP_NAMESPACE::DOMNode* findXMLChild(XERCES_CPP_NAMESPACE::DOMNode* startChild,
0256                                               const std::string& tagName,
0257                                               bool beginOnly = false,
0258                                               std::string* rest = nullptr);
0259 
0260   /// get a named attribute for an xml node as string
0261   std::string getXMLAttribute(const XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name);
0262 
0263   /// get the text value of a xml node as string
0264   std::string getXMLTextValue(XERCES_CPP_NAMESPACE::DOMNode* node);
0265 
0266   /// convert a hexadecimal string with up to 128 to 2 uint64_t
0267   bool hexString2UInt128(const std::string& hexString, uint64_t& dstL, uint64_t& dstH);
0268 
0269   /// get a hexadecimal value of a xml node containing text with up to 128 bit
0270   bool getXMLHexTextValue128(XERCES_CPP_NAMESPACE::DOMNode* node, uint64_t& dstL, uint64_t& dstH);
0271 
0272   /// get a hexadecimal value of a xml node containing text
0273   bool getXMLHexTextValue(XERCES_CPP_NAMESPACE::DOMNode* node, uint64_t& dst);
0274 
0275   /// get the number of bits in the max attribute of a condition child
0276   bool countConditionChildMaxBits(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& childName, unsigned int& dst);
0277 
0278   /// get values from a child of a condition
0279   bool getConditionChildValues(XERCES_CPP_NAMESPACE::DOMNode* node,
0280                                const std::string& childName,
0281                                unsigned int num,
0282                                std::vector<uint64_t>& dst);
0283 
0284   /// shutdown the xml utils and deallocate parser and error handler
0285   void cleanupXML(XERCES_CPP_NAMESPACE::XercesDOMParser* parser);
0286 
0287 private:
0288   // methods for the VME file
0289 
0290   /// parse the vme xml file
0291   bool parseVmeXML(XERCES_CPP_NAMESPACE::XercesDOMParser* parser);
0292 
0293 private:
0294   // methods for conditions and algorithms
0295 
0296   /// clearMaps - delete all conditions and algorithms in
0297   /// the maps and clear the maps.
0298   void clearMaps();
0299 
0300   /// insertConditionIntoMap - safe insert of condition into condition map.
0301   /// if the condition name already exists, do not insert it and return false
0302   bool insertConditionIntoMap(L1GtCondition& cond, const int chipNr);
0303 
0304   /// insert an algorithm into algorithm map
0305   bool insertAlgorithmIntoMap(const L1GtAlgorithm& alg);
0306 
0307   /// insert a technical trigger into technical trigger map
0308   bool insertTechTriggerIntoMap(const L1GtAlgorithm& alg);
0309 
0310   /// get the type of the condition, as defined in enum, from the condition type
0311   /// as defined in the XML file
0312   L1GtConditionType getTypeFromType(const std::string& type);
0313 
0314   /// get number of particles from condition type
0315   int getNumFromType(const std::string& type);
0316 
0317   /// get bit from a bit node
0318   int getBitFromNode(XERCES_CPP_NAMESPACE::DOMNode* node);
0319 
0320   /// getGEqFlag - get the "greater or equal flag" from a condition
0321   int getGEqFlag(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& nodeName);
0322 
0323   /// get MIP and Isolation bits from a muon
0324   bool getMuonMipIsoBits(XERCES_CPP_NAMESPACE::DOMNode* node,
0325                          unsigned int num,
0326                          std::vector<bool>& mipDst,
0327                          std::vector<bool>& isoEnDst,
0328                          std::vector<bool>& isoReqDst);
0329 
0330   /// parse a muon condition
0331   bool parseMuon(XERCES_CPP_NAMESPACE::DOMNode* node,
0332                  const std::string& name,
0333                  unsigned int chipNr = 0,
0334                  const bool corrFlag = false);
0335 
0336   /// parse a calorimeter condition
0337   bool parseCalo(XERCES_CPP_NAMESPACE::DOMNode* node,
0338                  const std::string& name,
0339                  unsigned int chipNr = 0,
0340                  const bool corrFlag = false);
0341 
0342   /// parse an "energy sum" condition
0343   bool parseEnergySum(XERCES_CPP_NAMESPACE::DOMNode* node,
0344                       const std::string& name,
0345                       unsigned int chipNr = 0,
0346                       const bool corrFlag = false);
0347 
0348   /// parse a "jet counts" condition
0349   bool parseJetCounts(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name, unsigned int chipNr = 0);
0350 
0351   /// parse a CASTOR condition
0352   bool parseCastor(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name, unsigned int chipNr = 0);
0353 
0354   /// parse a HfBitCounts condition
0355   bool parseHfBitCounts(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name, unsigned int chipNr = 0);
0356 
0357   /// parse a HfRingEtSums condition
0358   bool parseHfRingEtSums(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name, unsigned int chipNr = 0);
0359 
0360   /// parse a Bptx condition
0361   bool parseBptx(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name, unsigned int chipNr = 0);
0362 
0363   /// parse an External condition
0364   bool parseExternal(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name, unsigned int chipNr = 0);
0365 
0366   /// parse a correlation condition
0367   bool parseCorrelation(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name, unsigned int chipNr = 0);
0368 
0369   /// parse all parse all identification attributes (trigger menu names, scale DB key, etc)
0370   bool parseId(XERCES_CPP_NAMESPACE::XercesDOMParser* parser);
0371 
0372   /// choose the parser for a particular condition
0373   bool workCondition(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name, unsigned int chipNr);
0374 
0375   /// parse all conditions
0376   bool parseConditions(XERCES_CPP_NAMESPACE::XercesDOMParser* parser);
0377 
0378   /// parse an algorithm and insert it into algorithm map.
0379   bool workAlgorithm(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name, unsigned int chipNr);
0380 
0381   /// parse all algorithms
0382   bool parseAlgorithms(XERCES_CPP_NAMESPACE::XercesDOMParser* parser);
0383 
0384   /// parse an algorithm and insert it into algorithm map.
0385   bool workTechTrigger(XERCES_CPP_NAMESPACE::DOMNode* node, const std::string& name);
0386 
0387   /// parse all algorithms
0388   bool parseTechTriggers(XERCES_CPP_NAMESPACE::XercesDOMParser* parser);
0389 
0390   /// do all the steps for filling a trigger menu
0391   bool workXML(XERCES_CPP_NAMESPACE::XercesDOMParser* parser);
0392 
0393 private:
0394   /// error handler for xml-parser
0395   XERCES_CPP_NAMESPACE::ErrorHandler* m_xmlErrHandler;
0396 
0397   /// hardware limits
0398 
0399   /// number of condition chips
0400   unsigned int m_numberConditionChips;
0401 
0402   /// number of pins on the GTL condition chips
0403   unsigned int m_pinsOnConditionChip;
0404 
0405   /// correspondence "condition chip - GTL algorithm word" in the hardware
0406   /// chip 2: 0 - 95;  chip 1: 96 - 128 (191)
0407   std::vector<int> m_orderConditionChip;
0408 
0409   /// number of physics trigger algorithms
0410   unsigned int m_numberPhysTriggers;
0411 
0412   /// number of technical triggers
0413   unsigned int m_numberTechTriggers;
0414 
0415   /// jet counts
0416   unsigned int m_numberL1JetCounts;
0417 
0418 private:
0419   ///  members  for XML parser only (do not appear in CondFormats)
0420 
0421   std::string m_triggerMenuInterfaceDate;
0422   std::string m_triggerMenuInterfaceAuthor;
0423   std::string m_triggerMenuInterfaceDescription;
0424 
0425   std::string m_triggerMenuDate;
0426   std::string m_triggerMenuAuthor;
0427   std::string m_triggerMenuDescription;
0428 
0429   std::string m_algorithmImplementation;
0430 
0431 private:
0432   /// map containing the conditions (per condition chip) - transient
0433   std::vector<ConditionMap> m_conditionMap;
0434 
0435 private:
0436   /// menu names
0437   std::string m_triggerMenuInterface;
0438   std::string m_triggerMenuName;
0439   std::string m_triggerMenuImplementation;
0440 
0441   /// menu associated scale key
0442   std::string m_scaleDbKey;
0443 
0444   /// vectors containing the conditions
0445   /// explicit, due to persistency...
0446   std::vector<std::vector<L1GtMuonTemplate> > m_vecMuonTemplate;
0447   std::vector<std::vector<L1GtCaloTemplate> > m_vecCaloTemplate;
0448   std::vector<std::vector<L1GtEnergySumTemplate> > m_vecEnergySumTemplate;
0449   std::vector<std::vector<L1GtJetCountsTemplate> > m_vecJetCountsTemplate;
0450   std::vector<std::vector<L1GtCastorTemplate> > m_vecCastorTemplate;
0451   std::vector<std::vector<L1GtHfBitCountsTemplate> > m_vecHfBitCountsTemplate;
0452   std::vector<std::vector<L1GtHfRingEtSumsTemplate> > m_vecHfRingEtSumsTemplate;
0453   std::vector<std::vector<L1GtBptxTemplate> > m_vecBptxTemplate;
0454   std::vector<std::vector<L1GtExternalTemplate> > m_vecExternalTemplate;
0455 
0456   std::vector<std::vector<L1GtCorrelationTemplate> > m_vecCorrelationTemplate;
0457   std::vector<std::vector<L1GtMuonTemplate> > m_corMuonTemplate;
0458   std::vector<std::vector<L1GtCaloTemplate> > m_corCaloTemplate;
0459   std::vector<std::vector<L1GtEnergySumTemplate> > m_corEnergySumTemplate;
0460 
0461   /// map containing the physics algorithms (by name)
0462   AlgorithmMap m_algorithmMap;
0463 
0464   /// map containing the physics algorithms (by alias)
0465   AlgorithmMap m_algorithmAliasMap;
0466 
0467   /// map containing the technical triggers
0468   AlgorithmMap m_technicalTriggerMap;
0469 };
0470 
0471 #endif /*L1GtConfigProducers_L1GtTriggerMenuXmlParser_h*/