File indexing completed on 2024-04-06 12:20:30
0001 #ifndef L1TGlobal_l1TGlobalUtilHelper_h
0002 #define L1TGlobal_l1TGlobalUtilHelper_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0021 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0022
0023 #include "FWCore/Framework/interface/ConsumesCollector.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/Utilities/interface/EDGetToken.h"
0026 #include "FWCore/Utilities/interface/InputTag.h"
0027
0028 #include <string>
0029 #include <utility>
0030
0031 namespace edm {
0032 class BranchDescription;
0033 class ParameterSetDescription;
0034 }
0035
0036 namespace l1t {
0037
0038 class L1TGlobalUtilHelper {
0039 public:
0040
0041 L1TGlobalUtilHelper(edm::ParameterSet const& pset, edm::ConsumesCollector& iC);
0042
0043
0044
0045
0046
0047
0048 template <typename T>
0049 L1TGlobalUtilHelper(edm::ParameterSet const& pset, edm::ConsumesCollector& iC, T& module);
0050
0051
0052
0053
0054
0055
0056
0057 template <typename T>
0058 L1TGlobalUtilHelper(edm::ParameterSet const& pset,
0059 edm::ConsumesCollector& iC,
0060 T& module,
0061 edm::InputTag const& l1tAlgBlkInputTag,
0062 edm::InputTag const& l1tExtBlkInputTag);
0063
0064
0065 static void fillDescription(edm::ParameterSetDescription& desc,
0066 edm::InputTag const& iAlg,
0067 edm::InputTag const& iExt,
0068 bool readPrescalesFromFile);
0069
0070 edm::InputTag const& l1tAlgBlkInputTag() const { return m_l1tAlgBlkInputTag; }
0071 edm::InputTag const& l1tExtBlkInputTag() const { return m_l1tExtBlkInputTag; }
0072
0073 bool const& readPrescalesFromFile() const { return m_readPrescalesFromFile; }
0074
0075 edm::EDGetTokenT<GlobalAlgBlkBxCollection> const& l1tAlgBlkToken() const { return m_l1tAlgBlkToken; }
0076 edm::EDGetTokenT<GlobalExtBlkBxCollection> const& l1tExtBlkToken() const { return m_l1tExtBlkToken; }
0077
0078 private:
0079
0080
0081
0082 void checkToUpdateTags(edm::BranchDescription const& branchDescription,
0083 edm::ConsumesCollector,
0084 bool findL1TAlgBlk,
0085 bool findL1TExtBlk);
0086
0087 edm::InputTag m_l1tAlgBlkInputTag;
0088 edm::InputTag m_l1tExtBlkInputTag;
0089
0090 edm::EDGetTokenT<GlobalAlgBlkBxCollection> m_l1tAlgBlkToken;
0091 edm::EDGetTokenT<GlobalExtBlkBxCollection> m_l1tExtBlkToken;
0092
0093 bool m_readPrescalesFromFile;
0094 };
0095
0096 template <typename T>
0097 L1TGlobalUtilHelper::L1TGlobalUtilHelper(edm::ParameterSet const& pset, edm::ConsumesCollector& iC, T& module)
0098 : L1TGlobalUtilHelper(pset, iC, module, edm::InputTag(), edm::InputTag()) {}
0099
0100 template <typename T>
0101 L1TGlobalUtilHelper::L1TGlobalUtilHelper(edm::ParameterSet const& pset,
0102 edm::ConsumesCollector& iC,
0103 T& module,
0104 edm::InputTag const& l1tAlgBlkInputTag,
0105 edm::InputTag const& l1tExtBlkInputTag)
0106 :
0107 m_l1tAlgBlkInputTag(l1tAlgBlkInputTag),
0108 m_l1tExtBlkInputTag(l1tExtBlkInputTag),
0109 m_readPrescalesFromFile(false) {
0110 if (pset.existsAs<bool>("ReadPrescalesFromFile")) {
0111 m_readPrescalesFromFile = pset.getParameter<bool>("ReadPrescalesFromFile");
0112 }
0113
0114
0115 if (m_l1tAlgBlkInputTag.label().empty() && pset.existsAs<edm::InputTag>("l1tAlgBlkInputTag")) {
0116 m_l1tAlgBlkInputTag = pset.getParameter<edm::InputTag>("l1tAlgBlkInputTag");
0117 }
0118 if (m_l1tExtBlkInputTag.label().empty() && pset.existsAs<edm::InputTag>("l1tExtBlkInputTag")) {
0119 m_l1tExtBlkInputTag = pset.getParameter<edm::InputTag>("l1tExtBlkInputTag");
0120 }
0121
0122
0123 if (!m_l1tAlgBlkInputTag.label().empty()) {
0124 m_l1tAlgBlkToken = iC.consumes<GlobalAlgBlkBxCollection>(m_l1tAlgBlkInputTag);
0125 }
0126
0127 if (!m_l1tExtBlkInputTag.label().empty()) {
0128 m_l1tExtBlkToken = iC.consumes<GlobalExtBlkBxCollection>(m_l1tExtBlkInputTag);
0129 }
0130
0131
0132 bool findL1TAlgBlk = m_l1tAlgBlkInputTag.label().empty();
0133 bool findL1TExtBlk = m_l1tExtBlkInputTag.label().empty();
0134
0135
0136
0137 if (findL1TAlgBlk || findL1TExtBlk) {
0138 auto const* pModule = &module;
0139 module.callWhenNewProductsRegistered([this, findL1TAlgBlk, findL1TExtBlk, iC, pModule](auto iBranch) {
0140 try {
0141 checkToUpdateTags(iBranch, iC, findL1TAlgBlk, findL1TExtBlk);
0142 } catch (cms::Exception& iExcept) {
0143 auto const& label = pModule->moduleDescription().moduleLabel();
0144 iExcept.addContext(std::string("Running 'callWhenNewProductRegistered' for module ") + label);
0145 throw;
0146 }
0147 });
0148 }
0149 }
0150
0151 }
0152
0153 #endif