Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:14

0001 #ifndef GenericTriggerEventFlag_H
0002 #define GenericTriggerEventFlag_H
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    CommonTools/TriggerUtils
0007 // Class:      GenericTriggerEventFlag
0008 //
0009 // $Id: GenericTriggerEventFlag.h,v 1.5 2012/01/19 20:17:34 vadler Exp $
0010 //
0011 /**
0012   \class    GenericTriggerEventFlag GenericTriggerEventFlag.h "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
0013   \brief    Provides a code based selection for trigger and DCS information in order to have no failing filters in the CMSSW path.
0014 
0015    [...]
0016 
0017   \author   Volker Adler
0018   \version  $Id: GenericTriggerEventFlag.h,v 1.5 2012/01/19 20:17:34 vadler Exp $
0019 */
0020 
0021 #include "FWCore/Framework/interface/Run.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/EventSetup.h"
0024 #include "FWCore/Framework/interface/ESWatcher.h"
0025 #include "FWCore/Framework/interface/ConsumesCollector.h"
0026 #include "FWCore/Utilities/interface/ESGetToken.h"
0027 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0028 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
0029 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
0030 #include "CondFormats/HLTObjects/interface/AlCaRecoTriggerBits.h"
0031 #include "CondFormats/DataRecord/interface/AlCaRecoTriggerBitsRcd.h"
0032 #include "DataFormats/Common/interface/TriggerResults.h"
0033 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0034 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
0035 #include "DataFormats/Scalers/interface/DcsStatus.h"
0036 #include "DataFormats/OnlineMetaData/interface/DCSRecord.h"
0037 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h"
0038 #include "L1Trigger/L1TGlobal/interface/L1TGlobalUtil.h"
0039 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0040 
0041 #include <memory>
0042 #include <string>
0043 
0044 class GenericTriggerEventFlag {
0045   // Utility classes
0046   std::unique_ptr<edm::ESWatcher<AlCaRecoTriggerBitsRcd> > watchDB_;
0047   std::unique_ptr<L1GtUtils> l1Gt_;
0048   std::unique_ptr<l1t::L1TGlobalUtil> l1uGt_;
0049   HLTConfigProvider hltConfig_;
0050   bool hltConfigInit_;
0051   edm::ESGetToken<L1GtTriggerMenu, L1GtTriggerMenuRcd> l1GtTriggerMenuToken_;
0052   edm::ESGetToken<AlCaRecoTriggerBits, AlCaRecoTriggerBitsRcd> alCaRecoTriggerBitsToken_;
0053   // Configuration parameters
0054   bool andOr_;
0055   std::string dbLabel_;
0056   unsigned verbose_;
0057   bool andOrDcs_;
0058   edm::InputTag dcsInputTag_;
0059   edm::InputTag dcsRecordInputTag_;
0060   edm::EDGetTokenT<DcsStatusCollection> dcsInputToken_;
0061   edm::EDGetTokenT<DCSRecord> dcsRecordToken_;
0062   std::vector<int> dcsPartitions_;
0063   bool errorReplyDcs_;
0064   bool andOrGt_;
0065   edm::InputTag gtInputTag_;
0066   edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> gtInputToken_;
0067   edm::InputTag gtEvmInputTag_;
0068   edm::EDGetTokenT<L1GlobalTriggerEvmReadoutRecord> gtEvmInputToken_;
0069   std::string gtDBKey_;
0070   std::vector<std::string> gtLogicalExpressions_;
0071   bool errorReplyGt_;
0072   bool andOrL1_;
0073   bool stage2_;
0074   bool l1BeforeMask_;
0075   std::string l1DBKey_;
0076   std::vector<std::string> l1LogicalExpressionsCache_;
0077   std::vector<std::string> l1LogicalExpressions_;
0078   bool errorReplyL1_;
0079   bool andOrHlt_;
0080   edm::InputTag hltInputTag_;
0081   edm::EDGetTokenT<edm::TriggerResults> hltInputToken_;
0082   std::string hltDBKey_;
0083   std::vector<std::string> hltLogicalExpressionsCache_;
0084   std::vector<std::string> hltLogicalExpressions_;
0085   bool errorReplyHlt_;
0086   // Switches
0087   bool on_;
0088   bool onDcs_;
0089   bool onGt_;
0090   bool onL1_;
0091   bool onHlt_;
0092   // Member constants
0093   const std::string configError_;
0094   const std::string emptyKeyError_;
0095 
0096 public:
0097   //so passing in the owning EDProducer is a pain for me (S. Harper)
0098   //and its only needed for legacy/stage1 L1 info which is mostly obsolete now
0099   //defined a new constructor which doesnt allow for the use of legacy/stage 1 L1, only stage2
0100   //so you no longer have to pass in the EDProducer
0101   //however I set things up such that its an error to try and configure the stage-1 L1 here
0102   //hence the extra private constructor
0103   //tldr: use these constructors, not the other two if unsure, if you get it wrong, there'll be an error
0104   //
0105   //The last constructor argument declares whether EventSetup
0106   //information is retrieved during beginRun, during the Event,
0107   //or during both. This is needed to declare which EventSetup
0108   //products are consumed. In the future, this will affect
0109   //when prefetching is done. Declare both and it will always
0110   //work, but there is some performance advantage to only
0111   //declaring the necessary one. With only a few exceptions,
0112   //existing clients call both initRun and accept (the two main
0113   //functions in this class getting EventSetup data), so EventSetup
0114   //objects might be retrieved in both periods. The argument defaults
0115   //to this. The function expressionsFromDB also gets data from
0116   //the EventSetup and is called by a few clients.
0117   GenericTriggerEventFlag(const edm::ParameterSet& config,
0118                           edm::ConsumesCollector&& iC,
0119                           l1t::UseEventSetupIn use = l1t::UseEventSetupIn::RunAndEvent)
0120       : GenericTriggerEventFlag(config, iC, use) {}
0121   GenericTriggerEventFlag(const edm::ParameterSet& config,
0122                           edm::ConsumesCollector& iC,
0123                           l1t::UseEventSetupIn use = l1t::UseEventSetupIn::RunAndEvent);
0124 
0125   // Constructors must be called from the ED module's c'tor
0126   template <typename T>
0127   GenericTriggerEventFlag(const edm::ParameterSet& config,
0128                           edm::ConsumesCollector&& iC,
0129                           T& module,
0130                           l1t::UseEventSetupIn use = l1t::UseEventSetupIn::RunAndEvent);
0131 
0132   template <typename T>
0133   GenericTriggerEventFlag(const edm::ParameterSet& config,
0134                           edm::ConsumesCollector& iC,
0135                           T& module,
0136                           l1t::UseEventSetupIn use = l1t::UseEventSetupIn::RunAndEvent);
0137 
0138   // Public methods
0139   bool on() { return on_; }
0140   bool off() { return (!on_); }
0141   void initRun(const edm::Run& run, const edm::EventSetup& setup);     // To be called from beginRun() methods
0142   bool accept(const edm::Event& event, const edm::EventSetup& setup);  // To be called from analyze/filter() methods
0143 
0144   bool allHLTPathsAreValid() const;
0145 
0146   static void fillPSetDescription(edm::ParameterSetDescription& desc);
0147 
0148 private:
0149   GenericTriggerEventFlag(const edm::ParameterSet& config, edm::ConsumesCollector& iC, bool stage1Valid);
0150   // Private methods
0151 
0152   // DCS
0153   bool acceptDcs(const edm::Event& event);
0154   bool acceptDcsPartition(const edm::Handle<DcsStatusCollection>& dcsStatus,
0155                           const edm::Handle<DCSRecord>& dcsRecord,
0156                           bool useDCSRecord,
0157                           int dcsPartition) const;
0158 
0159   // GT status bits
0160   bool acceptGt(const edm::Event& event);
0161   bool acceptGtLogicalExpression(const edm::Event& event, std::string gtLogicalExpression);
0162 
0163   // L1
0164   bool acceptL1(const edm::Event& event, const edm::EventSetup& setup);
0165   bool acceptL1LogicalExpression(const edm::Event& event,
0166                                  const edm::EventSetup& setup,
0167                                  std::string l1LogicalExpression);
0168 
0169   // HLT
0170   bool acceptHlt(const edm::Event& event);
0171   bool acceptHltLogicalExpression(const edm::Handle<edm::TriggerResults>& hltTriggerResults,
0172                                   std::string hltLogicalExpression) const;
0173 
0174   // Algos
0175   std::string expandLogicalExpression(const std::vector<std::string>& target,
0176                                       const std::string& expr,
0177                                       bool useAnd = false) const;
0178   bool negate(std::string& word) const;
0179 
0180 public:
0181   // Methods for expert analysis
0182 
0183   std::string gtDBKey() { return gtDBKey_; }    // can be empty
0184   std::string l1DBKey() { return l1DBKey_; }    // can be empty
0185   std::string hltDBKey() { return hltDBKey_; }  // can be empty
0186 
0187   // Must be called only during beginRun
0188   std::vector<std::string> expressionsFromDB(const std::string& key, const edm::EventSetup& setup);
0189 };
0190 
0191 template <typename T>
0192 GenericTriggerEventFlag::GenericTriggerEventFlag(const edm::ParameterSet& config,
0193                                                  edm::ConsumesCollector&& iC,
0194                                                  T& module,
0195                                                  l1t::UseEventSetupIn use)
0196     : GenericTriggerEventFlag(config, iC, module, use) {}
0197 
0198 template <typename T>
0199 GenericTriggerEventFlag::GenericTriggerEventFlag(const edm::ParameterSet& config,
0200                                                  edm::ConsumesCollector& iC,
0201                                                  T& module,
0202                                                  l1t::UseEventSetupIn use)
0203     : GenericTriggerEventFlag(config, iC, true) {
0204   if (on_ && config.exists("andOrL1")) {
0205     if (stage2_) {
0206       l1uGt_ = std::make_unique<l1t::L1TGlobalUtil>(config, iC, use);
0207     } else {
0208       L1GtUtils::UseEventSetupIn useL1GtUtilsIn = L1GtUtils::UseEventSetupIn::Run;
0209       if (use == l1t::UseEventSetupIn::RunAndEvent) {
0210         useL1GtUtilsIn = L1GtUtils::UseEventSetupIn::RunAndEvent;
0211       } else if (use == l1t::UseEventSetupIn::Event) {
0212         useL1GtUtilsIn = L1GtUtils::UseEventSetupIn::Event;
0213       }
0214       l1Gt_ = std::make_unique<L1GtUtils>(config, iC, false, module, useL1GtUtilsIn);
0215     }
0216   }
0217   //these pointers are already null so no need to reset them to a nullptr
0218   //if andOrL1 doesnt exist
0219 }
0220 
0221 #endif