Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef GlobalTriggerAnalyzer_L1GtUtilsHelper_h
0002 #define GlobalTriggerAnalyzer_L1GtUtilsHelper_h
0003 
0004 /**
0005  * \class L1GtUtilsHelper
0006  *
0007  *
0008  * Description: Gets tokens for L1GtUtils to use when getting products
0009  *              from the Event and Run. This class was introduced
0010  *              when the consumes function calls were added for L1GtUtils.
0011  *              It preserves the special feature of L1GtUtils that allows
0012  *              it to run without configuration of InputTags, although it
0013  *              allows InputTags to be configured optionally or passed in
0014  *              via the constructor arguments.
0015  *
0016  * \author: W.David Dagenhart - Fermilab 30 April 2015
0017  *
0018  */
0019 
0020 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerRecord.h"
0021 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0022 #include "DataFormats/L1GlobalTrigger/interface/L1GtTriggerMenuLite.h"
0023 
0024 #include "FWCore/Framework/interface/ConsumesCollector.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/Utilities/interface/EDGetToken.h"
0027 #include "FWCore/Utilities/interface/InputTag.h"
0028 
0029 #include <string>
0030 #include <utility>
0031 
0032 namespace edm {
0033   class BranchDescription;
0034   class ParameterSetDescription;
0035 }  // namespace edm
0036 
0037 class L1GtUtilsHelper {
0038 public:
0039   // Using this constructor will require InputTags to be specified in the configuration
0040   L1GtUtilsHelper(edm::ParameterSet const& pset, edm::ConsumesCollector& iC, bool useL1GtTriggerMenuLite);
0041 
0042   // Using this constructor will cause it to look for valid InputTags in
0043   // the following ways in the specified order until they are found.
0044   //   1. The configuration
0045   //   2. Search all products from the preferred input tags for the required type
0046   //   3. Search all products from any other process for the required type
0047   template <typename T>
0048   L1GtUtilsHelper(edm::ParameterSet const& pset, edm::ConsumesCollector& iC, bool useL1GtTriggerMenuLite, T& module);
0049 
0050   // Using this constructor will cause it to look for valid InputTags in
0051   // the following ways in the specified order until they are found.
0052   //   1. The constructor arguments
0053   //   2. The configuration
0054   //   3. Search all products from the preferred input tags for the required type
0055   //   4. Search all products from any other process for the required type
0056   template <typename T>
0057   L1GtUtilsHelper(edm::ParameterSet const& pset,
0058                   edm::ConsumesCollector& iC,
0059                   bool useL1GtTriggerMenuLite,
0060                   T& module,
0061                   edm::InputTag const& l1GtRecordInputTag,
0062                   edm::InputTag const& l1GtReadoutRecordInputTag,
0063                   edm::InputTag const& l1GtTriggerMenuLiteInputTag);
0064 
0065   // A module defining its fillDescriptions function might want to use this
0066   static void fillDescription(edm::ParameterSetDescription& desc);
0067 
0068   edm::InputTag const& l1GtRecordInputTag() const { return m_l1GtRecordInputTag; }
0069   edm::InputTag const& l1GtReadoutRecordInputTag() const { return m_l1GtReadoutRecordInputTag; }
0070   edm::InputTag const& l1GtTriggerMenuLiteInputTag() const { return m_l1GtTriggerMenuLiteInputTag; }
0071 
0072   edm::EDGetTokenT<L1GlobalTriggerRecord> const& l1GtRecordToken() const { return m_l1GtRecordToken; }
0073   edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> const& l1GtReadoutRecordToken() const {
0074     return m_l1GtReadoutRecordToken;
0075   }
0076   edm::EDGetTokenT<L1GtTriggerMenuLite> const& l1GtTriggerMenuLiteToken() const { return m_l1GtTriggerMenuLiteToken; }
0077 
0078 private:
0079   // Callback which will be registered with the Framework if the InputTags
0080   // are not specified in the configuration or constructor arguments. It
0081   // will get called for each product in the ProductRegistry.
0082   void checkToUpdateTags(edm::BranchDescription const& branchDescription,
0083                          edm::ConsumesCollector,
0084                          bool findRecord,
0085                          bool findReadoutRecord,
0086                          bool findMenuLite);
0087 
0088   edm::InputTag m_l1GtRecordInputTag;
0089   edm::InputTag m_l1GtReadoutRecordInputTag;
0090   edm::InputTag m_l1GtTriggerMenuLiteInputTag;
0091 
0092   edm::EDGetTokenT<L1GlobalTriggerRecord> m_l1GtRecordToken;
0093   edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> m_l1GtReadoutRecordToken;
0094   edm::EDGetTokenT<L1GtTriggerMenuLite> m_l1GtTriggerMenuLiteToken;
0095 };
0096 
0097 template <typename T>
0098 L1GtUtilsHelper::L1GtUtilsHelper(edm::ParameterSet const& pset,
0099                                  edm::ConsumesCollector& iC,
0100                                  bool useL1GtTriggerMenuLite,
0101                                  T& module)
0102     : L1GtUtilsHelper(pset, iC, useL1GtTriggerMenuLite, module, edm::InputTag(), edm::InputTag(), edm::InputTag()) {}
0103 
0104 template <typename T>
0105 L1GtUtilsHelper::L1GtUtilsHelper(edm::ParameterSet const& pset,
0106                                  edm::ConsumesCollector& iC,
0107                                  bool useL1GtTriggerMenuLite,
0108                                  T& module,
0109                                  edm::InputTag const& l1GtRecordInputTag,
0110                                  edm::InputTag const& l1GtReadoutRecordInputTag,
0111                                  edm::InputTag const& l1GtTriggerMenuLiteInputTag)
0112     :  // Set InputTags from arguments
0113       m_l1GtRecordInputTag(l1GtRecordInputTag),
0114       m_l1GtReadoutRecordInputTag(l1GtReadoutRecordInputTag),
0115       m_l1GtTriggerMenuLiteInputTag(l1GtTriggerMenuLiteInputTag) {
0116   // If the InputTags are not set to valid values by the arguments, then
0117   // try to set them from the configuration.
0118   if (m_l1GtRecordInputTag.label().empty() && pset.existsAs<edm::InputTag>("l1GtRecordInputTag")) {
0119     m_l1GtRecordInputTag = pset.getParameter<edm::InputTag>("l1GtRecordInputTag");
0120   }
0121   if (m_l1GtReadoutRecordInputTag.label().empty() && pset.existsAs<edm::InputTag>("l1GtReadoutRecordInputTag")) {
0122     m_l1GtReadoutRecordInputTag = pset.getParameter<edm::InputTag>("l1GtReadoutRecordInputTag");
0123   }
0124   if (useL1GtTriggerMenuLite && m_l1GtTriggerMenuLiteInputTag.label().empty() &&
0125       pset.existsAs<edm::InputTag>("l1GtTriggerMenuLiteInputTag")) {
0126     m_l1GtTriggerMenuLiteInputTag = pset.getParameter<edm::InputTag>("l1GtTriggerMenuLiteInputTag");
0127   }
0128 
0129   // If the InputTags were set to valid values, make the consumes calls.
0130   if (!m_l1GtRecordInputTag.label().empty()) {
0131     m_l1GtRecordToken = iC.consumes<L1GlobalTriggerRecord>(m_l1GtRecordInputTag);
0132   }
0133   if (!m_l1GtReadoutRecordInputTag.label().empty()) {
0134     m_l1GtReadoutRecordToken = iC.consumes<L1GlobalTriggerReadoutRecord>(m_l1GtReadoutRecordInputTag);
0135   }
0136   if (useL1GtTriggerMenuLite && !m_l1GtTriggerMenuLiteInputTag.label().empty()) {
0137     m_l1GtTriggerMenuLiteToken = iC.consumes<L1GtTriggerMenuLite, edm::InRun>(m_l1GtTriggerMenuLiteInputTag);
0138   }
0139 
0140   // Do we still need to search for each InputTag?
0141   bool findRecord = m_l1GtRecordInputTag.label().empty();
0142   bool findReadoutRecord = m_l1GtReadoutRecordInputTag.label().empty();
0143   bool findMenuLite = m_l1GtTriggerMenuLiteInputTag.label().empty() && useL1GtTriggerMenuLite;
0144 
0145   // Register the callback function with the Framework
0146   // if any InputTags still need to be found.
0147   if (findRecord || findReadoutRecord || findMenuLite) {
0148     module.callWhenNewProductsRegistered([this, findRecord, findReadoutRecord, findMenuLite, iC](auto iBranch) {
0149       checkToUpdateTags(iBranch, iC, findRecord, findReadoutRecord, findMenuLite);
0150     });
0151   }
0152 }
0153 #endif