Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-14 04:15:40

0001 #ifndef HLTrigger_HLTcore_HLTConfigData_h
0002 #define HLTrigger_HLTcore_HLTConfigData_h
0003 
0004 /** \class HLTConfigData
0005  *
0006  *  
0007  *  This class provides access routines to get hold of the HLT Configuration
0008  *
0009  *
0010  *  \author Martin Grunewald
0011  *
0012  */
0013 
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "DataFormats/HLTReco/interface/HLTPrescaleTable.h"
0016 #include "HLTrigger/HLTcore/interface/FractionalPrescale.h"
0017 
0018 #include <map>
0019 #include <string>
0020 #include <vector>
0021 #include <type_traits>
0022 #include <oneapi/tbb/concurrent_unordered_map.h>
0023 
0024 //
0025 // class declaration
0026 //
0027 
0028 class HLTConfigData {
0029 public:
0030   HLTConfigData();
0031   HLTConfigData(const edm::ParameterSet* iID);
0032 
0033 private:
0034   /// extract information into data members - called by init() methods
0035   void extract();
0036 
0037 public:
0038   /// Dumping config info to cout
0039   void dump(const std::string& what) const;
0040 
0041   /// Accessors (const methods)
0042 
0043   /// process name
0044   const std::string& processName() const;
0045 
0046   /// GlobalTag.globaltag
0047   const std::string& globalTag() const;
0048 
0049   /// HLT ConfDB table name
0050   const std::string& tableName() const;
0051 
0052   /// number of trigger paths in trigger table
0053   unsigned int size() const;
0054   /// number of modules on a specific trigger path
0055   unsigned int size(unsigned int trigger) const;
0056   unsigned int size(const std::string& trigger) const;
0057 
0058   /// names of trigger paths
0059   const std::vector<std::string>& triggerNames() const;
0060   const std::string& triggerName(unsigned int triggerIndex) const;
0061 
0062   /// slot position of trigger path in trigger table (0 - size-1)
0063   unsigned int triggerIndex(const std::string& triggerName) const;
0064 
0065   /// label(s) of module(s) on a trigger path
0066   const std::vector<std::string>& moduleLabels(unsigned int trigger) const;
0067   const std::vector<std::string>& moduleLabels(const std::string& trigger) const;
0068   const std::vector<std::string>& saveTagsModules(unsigned int trigger) const;
0069   const std::vector<std::string>& saveTagsModules(const std::string& trigger) const;
0070   const std::string& moduleLabel(unsigned int trigger, unsigned int module) const;
0071   const std::string& moduleLabel(const std::string& trigger, unsigned int module) const;
0072 
0073   /// slot position of module on trigger path (0 - size-1)
0074   unsigned int moduleIndex(unsigned int trigger, const std::string& module) const;
0075   unsigned int moduleIndex(const std::string& trigger, const std::string& module) const;
0076 
0077   /// C++ class name of module
0078   const std::string& moduleType(const std::string& module) const;
0079 
0080   /// C++ base class name of module
0081   const std::string& moduleEDMType(const std::string& module) const;
0082 
0083   /// ParameterSet of process
0084   const edm::ParameterSet& processPSet() const;
0085 
0086   /// ParameterSet of module
0087   const edm::ParameterSet& modulePSet(const std::string& module) const;
0088 
0089   /// Is module an L3 filter (ie, tracked saveTags=true)
0090   bool saveTags(const std::string& module) const;
0091 
0092   /// L1T type (0=unknown, 1=legacy/stage-1 or 2=stage-2)
0093   unsigned int l1tType() const;
0094 
0095   /// HLTLevel1GTSeed module
0096   /// HLTLevel1GTSeed modules for all trigger paths
0097   const std::vector<std::vector<std::pair<bool, std::string>>>& hltL1GTSeeds() const;
0098   /// HLTLevel1GTSeed modules for trigger path with name
0099   const std::vector<std::pair<bool, std::string>>& hltL1GTSeeds(const std::string& trigger) const;
0100   /// HLTLevel1GTSeed modules for trigger path with index i
0101   const std::vector<std::pair<bool, std::string>>& hltL1GTSeeds(unsigned int trigger) const;
0102 
0103   /// HLTL1TSeed module
0104   /// HLTL1TSeed modules for all trigger paths
0105   const std::vector<std::vector<std::string>>& hltL1TSeeds() const;
0106   /// HLTL1TSeed modules for trigger path with name
0107   const std::vector<std::string>& hltL1TSeeds(const std::string& trigger) const;
0108   /// HLTL1TSeed modules for trigger path with index i
0109   const std::vector<std::string>& hltL1TSeeds(unsigned int trigger) const;
0110 
0111   /// Streams
0112   /// list of names of all streams
0113   const std::vector<std::string>& streamNames() const;
0114   /// name of stream with index i
0115   const std::string& streamName(unsigned int stream) const;
0116   /// index of stream with name
0117   unsigned int streamIndex(const std::string& stream) const;
0118   /// names of datasets for all streams
0119   const std::vector<std::vector<std::string>>& streamContents() const;
0120   /// names of datasets in stream with index i
0121   const std::vector<std::string>& streamContent(unsigned int stream) const;
0122   /// names of datasets in stream with name
0123   const std::vector<std::string>& streamContent(const std::string& stream) const;
0124 
0125   /// Datasets
0126   /// list of names of all datasets
0127   const std::vector<std::string>& datasetNames() const;
0128   /// name of dataset with index i
0129   const std::string& datasetName(unsigned int dataset) const;
0130   /// index of dataset with name
0131   unsigned int datasetIndex(const std::string& dataset) const;
0132   /// names of trigger paths for all datasets
0133   const std::vector<std::vector<std::string>>& datasetContents() const;
0134   /// names of trigger paths in dataset with index i
0135   const std::vector<std::string>& datasetContent(unsigned int dataset) const;
0136   /// names of trigger paths in dataset with name
0137   const std::vector<std::string>& datasetContent(const std::string& dataset) const;
0138 
0139   /// HLT prescale info
0140   /// Number of HLT prescale sets
0141   unsigned int prescaleSize() const;
0142   /// HLT prescale value in specific prescale set for a specific trigger path
0143   template <typename T = unsigned int>
0144   T prescaleValue(unsigned int set, const std::string& trigger) const;
0145   /// labels of HLT prescale columns
0146   const std::vector<std::string>& prescaleLabels() const;
0147   /// map of HLT prescales by trigger-path name (key=path, value=prescales)
0148   template <typename T = unsigned int>
0149   std::map<std::string, std::vector<T>> const& prescaleTable() const;
0150 
0151   /// technical: id() function needed for use with ThreadSafeRegistry
0152   edm::ParameterSetID id() const;
0153 
0154 private:
0155   inline std::string canonicalModuleName(const std::string& module) const {
0156     return module.front() != '-' ? module : module.substr(1);
0157   }
0158 
0159   const edm::ParameterSet* processPSet_;
0160 
0161   std::string processName_;
0162   std::string globalTag_;
0163   std::string tableName_;
0164   std::vector<std::string> triggerNames_;
0165   std::vector<std::vector<std::string>> moduleLabels_;
0166   std::vector<std::vector<std::string>> saveTagsModules_;
0167 
0168   std::map<std::string, unsigned int> triggerIndex_;
0169   std::vector<std::map<std::string, unsigned int>> moduleIndex_;
0170 
0171   unsigned int l1tType_;
0172   std::vector<std::vector<std::pair<bool, std::string>>> hltL1GTSeeds_;
0173   std::vector<std::vector<std::string>> hltL1TSeeds_;
0174 
0175   std::vector<std::string> streamNames_;
0176   std::map<std::string, unsigned int> streamIndex_;
0177   std::vector<std::vector<std::string>> streamContents_;
0178 
0179   std::vector<std::string> datasetNames_;
0180   std::map<std::string, unsigned int> datasetIndex_;
0181   std::vector<std::vector<std::string>> datasetContents_;
0182 
0183   trigger::HLTPrescaleTable hltPrescaleTable_;
0184   std::map<std::string, std::vector<double>> hltPrescaleTableValuesDouble_;
0185   std::map<std::string, std::vector<FractionalPrescale>> hltPrescaleTableValuesFractional_;
0186   struct ModuleInfo {
0187     ModuleInfo(edm::ParameterSet const* iPSet, const std::string& iClass, const std::string& iType)
0188         : pset_(iPSet), class_(iClass), edmType_(iType) {}
0189 
0190     edm::ParameterSet const* pset_ = nullptr;
0191     std::string class_;
0192     std::string edmType_;
0193   };
0194 
0195   const ModuleInfo& moduleInfoFor(const std::string& iModule) const;
0196   mutable oneapi::tbb::concurrent_unordered_map<std::string, ModuleInfo> modulesInfo_;
0197 };
0198 
0199 template <typename T>
0200 T HLTConfigData::prescaleValue(unsigned int set, const std::string& trigger) const {
0201   static_assert(std::is_same_v<T, double> or std::is_same_v<T, FractionalPrescale>,
0202                 "\n\tPlease use prescaleValue<double> or prescaleValue<FractionalPrescale>"
0203                 "\n\t(other types for HLT prescales are not supported anymore by HLTConfigData)");
0204   return hltPrescaleTable_.prescale(set, trigger);
0205 }
0206 
0207 template <typename T>
0208 std::map<std::string, std::vector<T>> const& HLTConfigData::prescaleTable() const {
0209   static_assert(std::is_same_v<T, double> or std::is_same_v<T, FractionalPrescale>,
0210                 "\n\tPlease use prescaleTable<double> or prescaleTable<FractionalPrescale>"
0211                 "\n\t(other types for HLT prescales are not supported anymore by HLTConfigData)");
0212   return hltPrescaleTable_.table();
0213 }
0214 
0215 template <>
0216 std::map<std::string, std::vector<double>> const& HLTConfigData::prescaleTable() const;
0217 
0218 template <>
0219 std::map<std::string, std::vector<FractionalPrescale>> const& HLTConfigData::prescaleTable() const;
0220 
0221 #endif  // HLTrigger_HLTcore_HLTConfigData_h