CMS 3D CMS Logo

L1TGlobalUtilHelper.h
Go to the documentation of this file.
1 #ifndef L1TGlobal_l1TGlobalUtilHelper_h
2 #define L1TGlobal_l1TGlobalUtilHelper_h
3 
22 
27 
28 #include <string>
29 #include <utility>
30 
31 namespace edm {
32  class BranchDescription;
34 } // namespace edm
35 
36 namespace l1t {
37 
39  public:
40  // Using this constructor will require InputTags to be specified in the configuration
42 
43  // Using this constructor will cause it to look for valid InputTags in
44  // the following ways in the specified order until they are found.
45  // 1. The configuration
46  // 2. Search all products from the preferred input tags for the required type
47  // 3. Search all products from any other process for the required type
48  template <typename T>
50 
51  // Using this constructor will cause it to look for valid InputTags in
52  // the following ways in the specified order until they are found.
53  // 1. The constructor arguments
54  // 2. The configuration
55  // 3. Search all products from the preferred input tags for the required type
56  // 4. Search all products from any other process for the required type
57  template <typename T>
60  T& module,
63 
64  // A module defining its fillDescriptions function might want to use this
66  edm::InputTag const& iAlg,
67  edm::InputTag const& iExt,
69 
72 
73  bool const& readPrescalesFromFile() const { return m_readPrescalesFromFile; }
74 
77 
78  private:
79  // Callback which will be registered with the Framework if the InputTags
80  // are not specified in the configuration or constructor arguments. It
81  // will get called for each product in the ProductRegistry.
82  void checkToUpdateTags(edm::BranchDescription const& branchDescription,
84  bool findL1TAlgBlk,
85  bool findL1TExtBlk);
86 
89 
92 
94  };
95 
96  template <typename T>
99 
100  template <typename T>
103  T& module,
106  : // Set InputTags from arguments
107  m_l1tAlgBlkInputTag(l1tAlgBlkInputTag),
108  m_l1tExtBlkInputTag(l1tExtBlkInputTag),
109  m_readPrescalesFromFile(false) {
110  if (pset.existsAs<bool>("ReadPrescalesFromFile")) {
111  m_readPrescalesFromFile = pset.getParameter<bool>("ReadPrescalesFromFile");
112  }
113  // If the InputTags are not set to valid values by the arguments, then
114  // try to set them from the configuration.
115  if (m_l1tAlgBlkInputTag.label().empty() && pset.existsAs<edm::InputTag>("l1tAlgBlkInputTag")) {
116  m_l1tAlgBlkInputTag = pset.getParameter<edm::InputTag>("l1tAlgBlkInputTag");
117  }
118  if (m_l1tExtBlkInputTag.label().empty() && pset.existsAs<edm::InputTag>("l1tExtBlkInputTag")) {
119  m_l1tExtBlkInputTag = pset.getParameter<edm::InputTag>("l1tExtBlkInputTag");
120  }
121 
122  // If the InputTags were set to valid values, make the consumes calls.
123  if (!m_l1tAlgBlkInputTag.label().empty()) {
125  }
126 
127  if (!m_l1tExtBlkInputTag.label().empty()) {
129  }
130 
131  // Do we still need to search for each InputTag?
132  bool findL1TAlgBlk = m_l1tAlgBlkInputTag.label().empty();
133  bool findL1TExtBlk = m_l1tExtBlkInputTag.label().empty();
134 
135  // Register the callback function with the Framework
136  // if any InputTags still need to be found.
137  if (findL1TAlgBlk || findL1TExtBlk) {
138  auto const* pModule = &module;
139  module.callWhenNewProductsRegistered([this, findL1TAlgBlk, findL1TExtBlk, iC, pModule](auto iBranch) {
140  try {
141  checkToUpdateTags(iBranch, iC, findL1TAlgBlk, findL1TExtBlk);
142  } catch (cms::Exception& iExcept) {
143  auto const& label = pModule->moduleDescription().moduleLabel();
144  iExcept.addContext(std::string("Running 'callWhenNewProductRegistered' for module ") + label);
145  throw;
146  }
147  });
148  }
149  }
150 
151 } // namespace l1t
152 
153 #endif
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< GlobalAlgBlkBxCollection > const & l1tAlgBlkToken() const
edm::InputTag const & l1tAlgBlkInputTag() const
bool const & readPrescalesFromFile() const
delete x;
Definition: CaloConfig.h:22
std::string const & label() const
Definition: InputTag.h:36
L1TGlobalUtilHelper(edm::ParameterSet const &pset, edm::ConsumesCollector &iC)
char const * label
edm::EDGetTokenT< GlobalExtBlkBxCollection > m_l1tExtBlkToken
static void fillDescription(edm::ParameterSetDescription &desc, edm::InputTag const &iAlg, edm::InputTag const &iExt, bool readPrescalesFromFile)
edm::InputTag const & l1tExtBlkInputTag() const
edm::EDGetTokenT< GlobalAlgBlkBxCollection > m_l1tAlgBlkToken
edm::EDGetTokenT< GlobalExtBlkBxCollection > const & l1tExtBlkToken() const
void addContext(std::string const &context)
Definition: Exception.cc:169
void checkToUpdateTags(edm::BranchDescription const &branchDescription, edm::ConsumesCollector, bool findL1TAlgBlk, bool findL1TExtBlk)
HLT enums.
long double T