CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 namespace edm {
42  class ESConsumesCollectorAdaptor;
43  class ESConsumesCollectorWithTagAdaptor;
44 
47  edm::eventsetup::DataKey const& iProduct,
48  std::string moduleLabel,
49  std::unique_ptr<edm::eventsetup::impl::MayConsumeChooserCore> chooser)
50  : recordKey_{iRecord},
51  productKey_{iProduct},
52  moduleLabel_{std::move(moduleLabel)},
53  chooser_{std::move(chooser)} {}
57  std::unique_ptr<edm::eventsetup::impl::MayConsumeChooserCore> chooser_;
58  };
59  using ESConsumesInfo = std::vector<ESConsumesInfoEntry>;
60 
62  public:
63  ESConsumesCollector() = delete;
68 
69  // ---------- member functions ---------------------------
70  template <typename Product, typename Record>
71  auto consumesFrom(ESInputTag const& tag) {
72  using namespace edm::eventsetup;
73  ESTokenIndex index{static_cast<ESTokenIndex::Value_t>(m_consumer->size())};
74  m_consumer->emplace_back(EventSetupRecordKey::makeKey<Record>(),
75  DataKey(DataKey::makeTypeTag<Product>(), tag.data().c_str()),
76  tag.module(),
77  nullptr);
78  //even though m_consumer may expand, the address for
79  // name().value() remains the same since it is 'moved'.
80  return ESGetToken<Product, Record>{m_transitionID, index, m_consumer->back().productKey_.name().value()};
81  }
82 
83  template <typename Product, typename Record>
84  auto consumesFrom() {
85  using namespace edm::eventsetup;
86  ESTokenIndex index{static_cast<ESTokenIndex::Value_t>(m_consumer->size())};
87  m_consumer->emplace_back(
88  EventSetupRecordKey::makeKey<Record>(), DataKey(DataKey::makeTypeTag<Product>(), ""), "", nullptr);
89  //even though m_consumer may expand, the address for
90  // name().value() remains the same since it is 'moved'.
91  return ESGetToken<Product, Record>{m_transitionID, index, m_consumer->back().productKey_.name().value()};
92  }
93 
96 
97  protected:
98  explicit ESConsumesCollector(ESConsumesInfo* const iConsumer, unsigned int iTransitionID)
99  : m_consumer{iConsumer}, m_transitionID{iTransitionID} {}
100 
101  template <typename Product, typename Record, typename Collector, typename PTag>
102  auto registerMayConsume(std::unique_ptr<Collector> iCollector, PTag const& productTag) {
103  //NOTE: for now, just treat like standard consumes request for the product needed to
104  // do the decision
105  iCollector->token() = consumes(productTag.inputTag());
106 
107  using namespace edm::eventsetup;
108  ESTokenIndex index{static_cast<ESTokenIndex::Value_t>(m_consumer->size())};
109  m_consumer->emplace_back(EventSetupRecordKey::makeKey<Record>(),
110  DataKey(DataKey::makeTypeTag<Product>(), "@mayConsume"),
111  "@mayConsume",
112  std::move(iCollector));
113  //even though m_consumer may expand, the address for
114  // name().value() remains the same since it is 'moved'.
115  return ESGetToken<Product, Record>{m_transitionID, index, m_consumer->back().productKey_.name().value()};
116  }
117 
118  private:
119  // ---------- member data --------------------------------
121  unsigned int m_transitionID{0};
122  };
123 
124  template <typename RECORD>
126  public:
127  ESConsumesCollectorT() = delete;
132 
133  // ---------- member functions ---------------------------
134 
136  template <typename Product>
137  auto consumes(ESInputTag const& tag) {
138  return consumesFrom<Product, RECORD>(tag);
139  }
140 
141  template <typename Product>
142  auto consumes() {
143  return consumesFrom<Product, RECORD>();
144  }
145 
146  template <typename Product, typename FromRecord, typename Func, typename PTag>
147  auto mayConsumeFrom(Func&& func, PTag const& productTag) {
148  return registerMayConsume<Product, FromRecord>(
149  std::make_unique<eventsetup::impl::MayConsumeChooser<RECORD, Product, FromRecord, Func, PTag>>(
150  std::forward<Func>(func)),
151  productTag);
152  }
153 
154  template <typename Product, typename FromRecord, typename Func, typename PTag>
156  token = mayConsumeFrom<Product, FromRecord>(std::forward<Func>(func), productTag);
157  return *this;
158  }
159 
160  private:
161  //only ESProducer is allowed to make an instance of this class
162  friend class ESProducer;
163 
164  explicit ESConsumesCollectorT(ESConsumesInfo* const iConsumer, unsigned int iTransitionID)
165  : ESConsumesCollector(iConsumer, iTransitionID) {}
166  };
167 
169  public:
170  template <typename TYPE, typename REC>
172  return m_consumer->template consumesFrom<TYPE, REC>();
173  }
174 
175  private:
176  //only ESConsumesCollector is allowed to make an instance of this class
177  friend class ESConsumesCollector;
179 
181  };
182 
184  public:
185  template <typename TYPE, typename REC>
187  return m_consumer->template consumesFrom<TYPE, REC>(m_tag);
188  }
189 
190  private:
191  //only ESConsumesCollector is allowed to make an instance of this class
192  friend class ESConsumesCollector;
194  : m_consumer(iBase), m_tag(std::move(iTag)) {}
195 
198  };
199 
202  return ESConsumesCollectorWithTagAdaptor(this, std::move(tag));
203  }
204 
205 } // namespace edm
206 
207 #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)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
auto consumesFrom(ESInputTag const &tag)
auto consumes(ESInputTag const &tag)
def move
Definition: eostools.py:511
ESConsumesCollectorWithTagAdaptor(ESConsumesCollector *iBase, ESInputTag iTag)
ESConsumesCollectorAdaptor(ESConsumesCollector *iBase)
const std::string & data() const
Definition: ESInputTag.h:104
auto registerMayConsume(std::unique_ptr< Collector > iCollector, PTag const &productTag)
edm::eventsetup::DataKey productKey_
std::unique_ptr< edm::eventsetup::impl::MayConsumeChooserCore > chooser_
ESConsumesCollectorT(ESConsumesInfo *const iConsumer, unsigned int iTransitionID)
const std::string & module() const
Definition: ESInputTag.h:99
ESConsumesCollector & operator=(ESConsumesCollector const &)=delete
edm::propagate_const< ESConsumesInfo * > m_consumer
ESConsumesCollectorAdaptor consumes()
ESConsumesInfoEntry(edm::eventsetup::EventSetupRecordKey const &iRecord, edm::eventsetup::DataKey const &iProduct, std::string moduleLabel, std::unique_ptr< edm::eventsetup::impl::MayConsumeChooserCore > chooser)