CMS 3D CMS Logo

ESConsumesCollector.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_ESConsumesCollector_h
2 #define FWCore_Framework_ESConsumesCollector_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : edm::ConsumesCollector
7 //
26 //
27 // Original Author: Kyle Knoepfel
28 // Created: Fri, 02 Oct 2018 12:44:47 GMT
29 //
30 
38 
39 #include <vector>
40 #include <memory>
41 
42 class testEventsetupRecord;
43 
44 namespace edm {
45  class ESConsumesCollectorAdaptor;
46  class ESConsumesCollectorWithTagAdaptor;
47 
50  edm::eventsetup::DataKey const& iProduct,
52  std::unique_ptr<edm::eventsetup::impl::MayConsumeChooserCore> chooser)
53  : recordKey_{iRecord},
54  productKey_{iProduct},
56  chooser_{std::move(chooser)} {}
60  std::unique_ptr<edm::eventsetup::impl::MayConsumeChooserCore> chooser_;
61  };
62  using ESConsumesInfo = std::vector<ESConsumesInfoEntry>;
63 
65  public:
66  ESConsumesCollector() = delete;
71 
72  // ---------- member functions ---------------------------
73  template <typename Product, typename Record>
74  auto consumesFrom(ESInputTag const& tag) {
75  using namespace edm::eventsetup;
76  ESTokenIndex index{static_cast<ESTokenIndex::Value_t>(m_consumer->size())};
77  m_consumer->emplace_back(EventSetupRecordKey::makeKey<Record>(),
78  DataKey(DataKey::makeTypeTag<Product>(), tag.data().c_str()),
79  tag.module(),
80  nullptr);
81  //even though m_consumer may expand, the address for
82  // name().value() remains the same since it is 'moved'.
83  return ESGetToken<Product, Record>{m_transitionID, index, m_consumer->back().productKey_.name().value()};
84  }
85 
86  template <typename Product, typename Record>
87  auto consumesFrom() {
88  using namespace edm::eventsetup;
89  ESTokenIndex index{static_cast<ESTokenIndex::Value_t>(m_consumer->size())};
90  m_consumer->emplace_back(
91  EventSetupRecordKey::makeKey<Record>(), DataKey(DataKey::makeTypeTag<Product>(), ""), "", nullptr);
92  //even though m_consumer may expand, the address for
93  // name().value() remains the same since it is 'moved'.
94  return ESGetToken<Product, Record>{m_transitionID, index, m_consumer->back().productKey_.name().value()};
95  }
96 
99 
100  protected:
101  explicit ESConsumesCollector(ESConsumesInfo* const iConsumer, unsigned int iTransitionID)
102  : m_consumer{iConsumer}, m_transitionID{iTransitionID} {}
103 
104  template <typename Product, typename Record, typename Collector, typename PTag>
105  auto registerMayConsume(std::unique_ptr<Collector> iCollector, PTag const& productTag) {
106  //NOTE: for now, just treat like standard consumes request for the product needed to
107  // do the decision
108  iCollector->token() = consumes(productTag.inputTag());
109 
110  using namespace edm::eventsetup;
111  ESTokenIndex index{static_cast<ESTokenIndex::Value_t>(m_consumer->size())};
112  m_consumer->emplace_back(EventSetupRecordKey::makeKey<Record>(),
113  DataKey(DataKey::makeTypeTag<Product>(), "@mayConsume"),
114  "@mayConsume",
115  std::move(iCollector));
116  //even though m_consumer may expand, the address for
117  // name().value() remains the same since it is 'moved'.
118  return ESGetToken<Product, Record>{m_transitionID, index, m_consumer->back().productKey_.name().value()};
119  }
120 
121  private:
122  // ---------- member data --------------------------------
124  unsigned int m_transitionID{0};
125  };
126 
127  template <typename RECORD>
129  public:
130  ESConsumesCollectorT() = delete;
135 
136  // ---------- member functions ---------------------------
137 
139  template <typename Product>
140  auto consumes(ESInputTag const& tag) {
141  return consumesFrom<Product, RECORD>(tag);
142  }
143 
144  template <typename Product>
145  auto consumes() {
146  return consumesFrom<Product, RECORD>();
147  }
148 
149  template <typename Product, typename FromRecord, typename Func, typename PTag>
150  auto mayConsumeFrom(Func&& func, PTag const& productTag) {
151  return registerMayConsume<Product, FromRecord>(
152  std::make_unique<eventsetup::impl::MayConsumeChooser<RECORD, Product, FromRecord, Func, PTag>>(
153  std::forward<Func>(func)),
154  productTag);
155  }
156 
157  template <typename Product, typename FromRecord, typename Func, typename PTag>
159  token = mayConsumeFrom<Product, FromRecord>(std::forward<Func>(func), productTag);
160  return *this;
161  }
162 
163  private:
164  //only ESProducer is allowed to make an instance of this class
165  friend class ESProducer;
166  friend class ::testEventsetupRecord;
167 
168  explicit ESConsumesCollectorT(ESConsumesInfo* const iConsumer, unsigned int iTransitionID)
169  : ESConsumesCollector(iConsumer, iTransitionID) {}
170  };
171 
173  public:
174  template <typename TYPE, typename REC>
176  return m_consumer->template consumesFrom<TYPE, REC>();
177  }
178 
179  private:
180  //only ESConsumesCollector is allowed to make an instance of this class
181  friend class ESConsumesCollector;
183 
185  };
186 
188  public:
189  template <typename TYPE, typename REC>
191  return m_consumer->template consumesFrom<TYPE, REC>(m_tag);
192  }
193 
194  private:
195  //only ESConsumesCollector is allowed to make an instance of this class
196  friend class ESConsumesCollector;
198  : m_consumer(iBase), m_tag(std::move(iTag)) {}
199 
202  };
203 
207  }
208 
209 } // namespace edm
210 
211 #endif
ESConsumesCollector & setMayConsume(ESGetToken< Product, FromRecord > &token, Func &&func, PTag const &productTag)
edm::eventsetup::EventSetupRecordKey recordKey_
std::vector< ESConsumesInfoEntry > ESConsumesInfo
ESGetToken< TYPE, REC > consumes()
ESConsumesCollector(ESConsumesInfo *const iConsumer, unsigned int iTransitionID)
auto mayConsumeFrom(Func &&func, PTag const &productTag)
auto consumesFrom(ESInputTag const &tag)
auto consumes(ESInputTag const &tag)
ESConsumesCollectorWithTagAdaptor(ESConsumesCollector *iBase, ESInputTag iTag)
ESConsumesCollectorAdaptor(ESConsumesCollector *iBase)
auto registerMayConsume(std::unique_ptr< Collector > iCollector, PTag const &productTag)
HLT enums.
edm::eventsetup::DataKey productKey_
std::unique_ptr< edm::eventsetup::impl::MayConsumeChooserCore > chooser_
ESConsumesCollectorT(ESConsumesInfo *const iConsumer, unsigned int iTransitionID)
ESConsumesCollector & operator=(ESConsumesCollector const &)=delete
edm::propagate_const< ESConsumesInfo * > m_consumer
ESConsumesCollectorAdaptor consumes()
def move(src, dest)
Definition: eostools.py:511
ESConsumesInfoEntry(edm::eventsetup::EventSetupRecordKey const &iRecord, edm::eventsetup::DataKey const &iProduct, std::string moduleLabel, std::unique_ptr< edm::eventsetup::impl::MayConsumeChooserCore > chooser)