Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-05 02:39:07

0001 #ifndef TriggerHelper_H
0002 #define TriggerHelper_H
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    DQM/TrackerCommon
0007 // Class:      TriggerHelper
0008 //
0009 //
0010 /**
0011   \class    TriggerHelper TriggerHelper.h
0012   "DQM/TrackerCommon/interface/TriggerHelper.h" \brief    Provides a code based
0013   selection for trigger and DCS information in order to have no failing filters
0014   in the CMSSW path.
0015 
0016    [...]
0017 
0018   \author   Volker Adler
0019 */
0020 
0021 #include "DataFormats/Common/interface/TriggerResults.h"
0022 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0023 #include "DataFormats/Scalers/interface/DcsStatus.h"
0024 #include "DataFormats/OnlineMetaData/interface/DCSRecord.h"
0025 #include "FWCore/Framework/interface/ESWatcher.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/EventSetup.h"
0028 #include "FWCore/Framework/interface/Run.h"
0029 #include "FWCore/Utilities/interface/EDGetToken.h"
0030 #include "FWCore/Utilities/interface/ESGetToken.h"
0031 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0032 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h"
0033 
0034 #include <memory>
0035 
0036 class AlCaRecoTriggerBits;
0037 class AlCaRecoTriggerBitsRcd;
0038 namespace edm {
0039   class ConsumesCollector;
0040   class ParameterSet;
0041 }  // namespace edm
0042 
0043 class TriggerHelper {
0044   // Utility classes
0045   edm::ESWatcher<AlCaRecoTriggerBitsRcd> *watchDB_;
0046   std::unique_ptr<L1GtUtils> l1Gt_;
0047   HLTConfigProvider hltConfig_;
0048   bool hltConfigInit_;
0049   // Configuration parameters
0050   bool andOr_;
0051   bool andOrDcs_;
0052   edm::InputTag dcsInputTag_;
0053   edm::InputTag dcsRecordInputTag_;
0054   edm::EDGetTokenT<DcsStatusCollection> dcsInputToken_;
0055   edm::EDGetTokenT<DCSRecord> dcsRecordToken_;
0056   std::vector<int> dcsPartitions_;
0057   bool errorReplyDcs_;
0058   bool andOrGt_;
0059   edm::InputTag gtInputTag_;
0060   edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> gtInputToken_;
0061   std::string gtDBKey_;
0062   std::vector<std::string> gtLogicalExpressions_;
0063   bool errorReplyGt_;
0064   bool andOrL1_;
0065   std::string l1DBKey_;
0066   edm::ESGetToken<AlCaRecoTriggerBits, AlCaRecoTriggerBitsRcd> alcaRecotriggerBitsToken_;
0067   std::vector<std::string> l1LogicalExpressions_;
0068   bool errorReplyL1_;
0069   bool andOrHlt_;
0070   edm::InputTag hltInputTag_;
0071   edm::EDGetTokenT<edm::TriggerResults> hltInputToken_;
0072   std::string hltDBKey_;
0073   std::vector<std::string> hltLogicalExpressions_;
0074   bool errorReplyHlt_;
0075   // Switches
0076   bool on_;
0077   bool onDcs_;
0078   bool onGt_;
0079   bool onL1_;
0080   bool onHlt_;
0081   // Member constants
0082   const std::string configError_;
0083 
0084 public:
0085   // Constructors must be called from the ED module's c'tor
0086   template <typename T>
0087   TriggerHelper(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module);
0088 
0089   template <typename T>
0090   TriggerHelper(const edm::ParameterSet &config, edm::ConsumesCollector &iC, T &module);
0091 
0092   ~TriggerHelper();
0093 
0094   // Public methods
0095   bool on() { return on_; }
0096   bool off() { return (!on_); }
0097   void initRun(const edm::Run &run,
0098                const edm::EventSetup &setup);  // To be called from beginRun() methods
0099   bool accept(const edm::Event &event,
0100               const edm::EventSetup &setup);  // To be called from analyze/filter() methods
0101 
0102 private:
0103   // Private methods
0104 
0105   TriggerHelper(const edm::ParameterSet &config, edm::ConsumesCollector &iC);
0106 
0107   // DCS
0108   bool acceptDcs(const edm::Event &event);
0109   bool acceptDcsPartition(const edm::Handle<DcsStatusCollection> &dcsStatus,
0110                           const edm::Handle<DCSRecord> &dcsRecord,
0111                           bool useDCSRecord,
0112                           int dcsPartition) const;
0113 
0114   // GT status bits
0115   bool acceptGt(const edm::Event &event);
0116   bool acceptGtLogicalExpression(const edm::Handle<L1GlobalTriggerReadoutRecord> &gtReadoutRecord,
0117                                  std::string gtLogicalExpression);
0118 
0119   // L1
0120   bool acceptL1(const edm::Event &event, const edm::EventSetup &setup);
0121   bool acceptL1LogicalExpression(const edm::Event &event, std::string l1LogicalExpression);
0122 
0123   // HLT
0124   bool acceptHlt(const edm::Event &event);
0125   bool acceptHltLogicalExpression(const edm::Handle<edm::TriggerResults> &hltTriggerResults,
0126                                   std::string hltLogicalExpression) const;
0127 
0128   // Algos
0129   std::vector<std::string> expressionsFromDB(const std::string &key, const edm::EventSetup &setup);
0130   bool negate(std::string &word) const;
0131 };
0132 
0133 template <typename T>
0134 TriggerHelper::TriggerHelper(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
0135     : TriggerHelper(config, iC, module) {
0136   gtInputTag_ = config.getParameter<edm::InputTag>("gtInputTag");
0137   gtInputToken_ = iC.consumes<L1GlobalTriggerReadoutRecord>(gtInputTag_);
0138   alcaRecotriggerBitsToken_ = iC.esConsumes<AlCaRecoTriggerBits, AlCaRecoTriggerBitsRcd>();
0139 }
0140 
0141 template <typename T>
0142 TriggerHelper::TriggerHelper(const edm::ParameterSet &config, edm::ConsumesCollector &iC, T &module)
0143     : TriggerHelper(config, iC) {
0144   if (onL1_ && (!l1DBKey_.empty() || !l1LogicalExpressions_.empty())) {
0145     l1Gt_ = std::make_unique<L1GtUtils>(config, iC, false, module, L1GtUtils::UseEventSetupIn::Event);
0146   }
0147 }
0148 
0149 #endif