Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef L1GtConfigProducers_L1GtTriggerMenuConfigOnlineProd_h
0002 #define L1GtConfigProducers_L1GtTriggerMenuConfigOnlineProd_h
0003 
0004 /**
0005  * \class L1GtTriggerMenuConfigOnlineProd
0006  *
0007  *
0008  * Description: online producer for L1GtTriggerMenu.
0009  *
0010  * Implementation:
0011  *    <TODO: enter implementation details>
0012  *
0013  * \author: Vasile Mihai Ghete - HEPHY Vienna
0014  *
0015  *
0016  */
0017 
0018 // system include files
0019 
0020 #include <memory>
0021 #include <string>
0022 #include <vector>
0023 #include <iomanip>
0024 #include <iostream>
0025 
0026 // user include files
0027 //   base class
0028 #include "CondTools/L1Trigger/interface/L1ConfigOnlineProdBase.h"
0029 
0030 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
0031 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
0032 
0033 #include "CondFormats/L1TObjects/interface/L1GtMuonTemplate.h"
0034 #include "CondFormats/L1TObjects/interface/L1GtCaloTemplate.h"
0035 #include "CondFormats/L1TObjects/interface/L1GtEnergySumTemplate.h"
0036 #include "CondFormats/L1TObjects/interface/L1GtJetCountsTemplate.h"
0037 #include "CondFormats/L1TObjects/interface/L1GtCastorTemplate.h"
0038 #include "CondFormats/L1TObjects/interface/L1GtHfBitCountsTemplate.h"
0039 #include "CondFormats/L1TObjects/interface/L1GtHfRingEtSumsTemplate.h"
0040 #include "CondFormats/L1TObjects/interface/L1GtCorrelationTemplate.h"
0041 #include "CondFormats/L1TObjects/interface/L1GtBptxTemplate.h"
0042 #include "CondFormats/L1TObjects/interface/L1GtExternalTemplate.h"
0043 
0044 // forward declarations
0045 
0046 // class declaration
0047 class L1GtTriggerMenuConfigOnlineProd : public L1ConfigOnlineProdBase<L1GtTriggerMenuRcd, L1GtTriggerMenu> {
0048 public:
0049   /// constructor
0050   L1GtTriggerMenuConfigOnlineProd(const edm::ParameterSet&);
0051 
0052   /// destructor
0053   ~L1GtTriggerMenuConfigOnlineProd() override;
0054 
0055   /// public methods
0056   std::unique_ptr<L1GtTriggerMenu> newObject(const std::string& objectKey) override;
0057 
0058   /// initialize the class (mainly reserve/resize)
0059   void init(const int numberConditionChips);
0060 
0061 private:
0062   /// define simple structures to get the tables from DB
0063 
0064   struct TableMenuGeneral {
0065     std::string menuInterface;
0066     std::string menuImplementation;
0067     std::string algoImplTag;
0068     std::string scalesKey;
0069   };
0070 
0071   struct TableMenuAlgo {
0072     short bitNumberSh;
0073     std::string algName;
0074     std::string algAlias;
0075     std::string logExpression;
0076   };
0077 
0078   struct TableMenuAlgoCond {
0079     short bitNumberSh;
0080     float condIndexF;
0081     std::string condFK;
0082   };
0083 
0084   struct TableMenuCond {
0085     std::string cond;
0086     std::string condCategory;
0087     std::string condType;
0088     std::string gtObject1;
0089     std::string gtObject2;
0090     bool condGEq;
0091     short countIndex;
0092     short countThreshold;
0093 
0094     // Oracle / Coral pretends that chargeCorrelation is bool in OMDS
0095     //   can not be - it has three values...
0096     //   but it reads/writes correctly the numerical value from OMDS (1, 2...)
0097     bool chargeCorrelation;
0098     std::string objectParameter1FK;
0099     std::string objectParameter2FK;
0100     std::string objectParameter3FK;
0101     std::string objectParameter4FK;
0102     std::string deltaEtaRange;
0103     std::string deltaPhiRange;
0104   };
0105 
0106   struct TableMenuObjectParameters {
0107     std::string opId;
0108     short ptHighThreshold;
0109     short ptLowThreshold;
0110     bool enableMip;
0111     bool enableIso;
0112     bool requestIso;
0113     bool energyOverflow;
0114     float etThreshold;
0115     std::string etaRange;
0116     std::string phiRange;
0117     short phiHigh;
0118     short phiLow;
0119     std::string qualityRange;
0120     bool charge;
0121   };
0122 
0123   struct TableMenuTechTrig {
0124     short bitNumberSh;
0125     std::string techName;
0126   };
0127 
0128   /// methods to retrieve the tables from DB
0129 
0130   /// retrieve table with general menu parameters from DB
0131   bool tableMenuGeneralFromDB(const std::string& gtSchema, const std::string& objKey);
0132 
0133   /// retrieve table with physics algorithms from DB
0134   bool tableMenuAlgoFromDB(const std::string& gtSchema, const std::string& objKey);
0135 
0136   /// retrieve table with conditions associated to physics algorithms from DB
0137   bool tableMenuAlgoCondFromDB(const std::string& gtSchema, const std::string& objKey);
0138 
0139   /// retrieve table with list of conditions in the menu
0140   bool tableMenuCondFromDB(const std::string& gtSchema, const std::string& objKey);
0141 
0142   /// retrieve table with object parameters from DB
0143   bool tableMenuObjectParametersFromDB(const std::string& gtSchema, const std::string& objKey);
0144 
0145   /// retrieve table with technical triggers from DB
0146   bool tableMenuTechTrigFromDB(const std::string& gtSchema, const std::string& objKey);
0147 
0148 private:
0149   /// return for an algorithm with bitNr the mapping between the integer index in logical expression
0150   /// and the condition name (FK)
0151   const std::map<int, std::string> condIndexNameMap(const short bitNr) const;
0152 
0153   /// convert a logical expression with indices to a logical expression with names
0154   std::string convertLogicalExpression(const std::string&, const std::map<int, std::string>&) const;
0155 
0156   /// return the chip number for an algorithm with index bitNumberSh
0157   int chipNumber(short) const;
0158 
0159   /// build the algorithm map in the menu
0160   void buildAlgorithmMap();
0161 
0162   /// build the technical trigger map in the menu
0163   void buildTechnicalTriggerMap();
0164 
0165   /// string to enum L1GtConditionCategory conversion
0166   L1GtConditionCategory strToEnumCondCategory(const std::string& strCategory);
0167 
0168   /// string to enum L1GtConditionType conversion
0169   L1GtConditionType strToEnumCondType(const std::string& strType);
0170 
0171   /// string to enum L1GtObject conversion
0172   L1GtObject strToEnumL1GtObject(const std::string& strObject);
0173 
0174   /// split a hex string in two 64-bit words returned as hex strings
0175   void splitHexStringInTwo64bitWords(const std::string& hexStr, std::string& hex0WordStr, std::string& hex1WordStr);
0176 
0177   /// get a list of chip numbers from the m_tableMenuAlgoCond table for a condition
0178   std::list<int> listChipNumber(const std::string&);
0179 
0180   void fillMuonObjectParameter(const std::string& opFK, L1GtMuonTemplate::ObjectParameter&);
0181   void addMuonCondition(const TableMenuCond&);
0182 
0183   void fillCaloObjectParameter(const std::string& opFK, L1GtCaloTemplate::ObjectParameter&);
0184   void addCaloCondition(const TableMenuCond&);
0185 
0186   void fillEnergySumObjectParameter(const std::string& opFK,
0187                                     L1GtEnergySumTemplate::ObjectParameter&,
0188                                     const L1GtObject&);
0189   void addEnergySumCondition(const TableMenuCond&);
0190 
0191   void addJetCountsCondition(const TableMenuCond&);
0192   void addHfBitCountsCondition(const TableMenuCond&);
0193   void addHfRingEtSumsCondition(const TableMenuCond&);
0194   void addCastorCondition(const TableMenuCond&);
0195   void addBptxCondition(const TableMenuCond&);
0196   void addExternalCondition(const TableMenuCond&);
0197   void addCorrelationCondition(const TableMenuCond&);
0198 
0199   /// add the conditions from a menu to the corresponding list
0200   void addConditions();
0201 
0202 private:
0203   template <typename Result, typename Source>
0204   Result lexical_cast_from_hex(Source& value) const;
0205 
0206 private:
0207   /// member to keep various tables retrieved from DB
0208 
0209   TableMenuGeneral m_tableMenuGeneral;
0210   std::vector<TableMenuAlgo> m_tableMenuAlgo;
0211   std::vector<TableMenuAlgoCond> m_tableMenuAlgoCond;
0212   std::vector<TableMenuCond> m_tableMenuCond;
0213   std::vector<TableMenuObjectParameters> m_tableMenuObjectParameters;
0214   std::vector<TableMenuTechTrig> m_tableMenuTechTrig;
0215 
0216 private:
0217   /// menu representation
0218 
0219   /// menu names
0220   std::string m_triggerMenuInterface;
0221   std::string m_triggerMenuName;
0222   std::string m_triggerMenuImplementation;
0223 
0224   /// menu associated scale key
0225   std::string m_scaleDbKey;
0226 
0227   /// vectors containing the conditions
0228   /// explicit, due to persistency...
0229   std::vector<std::vector<L1GtMuonTemplate> > m_vecMuonTemplate;
0230   std::vector<std::vector<L1GtCaloTemplate> > m_vecCaloTemplate;
0231   std::vector<std::vector<L1GtEnergySumTemplate> > m_vecEnergySumTemplate;
0232   std::vector<std::vector<L1GtJetCountsTemplate> > m_vecJetCountsTemplate;
0233   std::vector<std::vector<L1GtCastorTemplate> > m_vecCastorTemplate;
0234   std::vector<std::vector<L1GtHfBitCountsTemplate> > m_vecHfBitCountsTemplate;
0235   std::vector<std::vector<L1GtHfRingEtSumsTemplate> > m_vecHfRingEtSumsTemplate;
0236   std::vector<std::vector<L1GtBptxTemplate> > m_vecBptxTemplate;
0237   std::vector<std::vector<L1GtExternalTemplate> > m_vecExternalTemplate;
0238 
0239   std::vector<std::vector<L1GtCorrelationTemplate> > m_vecCorrelationTemplate;
0240   std::vector<std::vector<L1GtMuonTemplate> > m_corMuonTemplate;
0241   std::vector<std::vector<L1GtCaloTemplate> > m_corCaloTemplate;
0242   std::vector<std::vector<L1GtEnergySumTemplate> > m_corEnergySumTemplate;
0243 
0244   /// map containing the physics algorithms (by name)
0245   AlgorithmMap m_algorithmMap;
0246 
0247   /// map containing the physics algorithms (by alias)
0248   AlgorithmMap m_algorithmAliasMap;
0249 
0250   /// map containing the technical triggers
0251   AlgorithmMap m_technicalTriggerMap;
0252 
0253 private:
0254   bool m_isDebugEnabled;
0255 };
0256 
0257 template <typename Result, typename Source>
0258 Result L1GtTriggerMenuConfigOnlineProd::lexical_cast_from_hex(Source& value) const {
0259   std::stringstream convertor;
0260   convertor << value;
0261 
0262   Result result;
0263   if (!(convertor >> std::hex >> result) || !convertor.eof()) {
0264     throw std::exception();
0265   }
0266 
0267   return result;
0268 }
0269 
0270 #endif