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 namespace edm {
42  class ESConsumesCollectorAdaptor;
43  class ESConsumesCollectorWithTagAdaptor;
44 
47  edm::eventsetup::DataKey const& iProduct,
49  std::unique_ptr<edm::eventsetup::impl::MayConsumeChooserCore> chooser)
50  : recordKey_{iRecord},
51  productKey_{iProduct},
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>(
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 
203  }
204 
205 } // namespace edm
206 
207 #endif
edm::ESConsumesInfoEntry::ESConsumesInfoEntry
ESConsumesInfoEntry(edm::eventsetup::EventSetupRecordKey const &iRecord, edm::eventsetup::DataKey const &iProduct, std::string moduleLabel, std::unique_ptr< edm::eventsetup::impl::MayConsumeChooserCore > chooser)
Definition: ESConsumesCollector.h:46
edm::ESConsumesCollectorAdaptor::consumes
ESGetToken< TYPE, REC > consumes()
Definition: ESConsumesCollector.h:171
edm::ESTokenIndex
Definition: ESIndices.h:55
edm::ESConsumesInfoEntry::moduleLabel_
std::string moduleLabel_
Definition: ESConsumesCollector.h:56
edm::ESInputTag
Definition: ESInputTag.h:87
edm::ESConsumesInfoEntry::productKey_
edm::eventsetup::DataKey productKey_
Definition: ESConsumesCollector.h:55
edm::ESConsumesInfoEntry
Definition: ESConsumesCollector.h:45
edm::eventsetup::impl::MayConsumeChooser
Definition: MayConsumeChooser.h:34
edm::ESConsumesCollector
Definition: ESConsumesCollector.h:61
propagate_const.h
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::eventsetup::DataKey
Definition: DataKey.h:29
edm::ESConsumesCollector::m_transitionID
unsigned int m_transitionID
Definition: ESConsumesCollector.h:121
edm::ESConsumesInfoEntry::chooser_
std::unique_ptr< edm::eventsetup::impl::MayConsumeChooserCore > chooser_
Definition: ESConsumesCollector.h:57
ESGetToken.h
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
edm::ESConsumesCollectorT::ESConsumesCollectorT
ESConsumesCollectorT(ESConsumesInfo *const iConsumer, unsigned int iTransitionID)
Definition: ESConsumesCollector.h:164
edm::ESConsumesCollector::consumesFrom
auto consumesFrom()
Definition: ESConsumesCollector.h:84
edm::ESConsumesCollectorT
Definition: ESConsumesCollector.h:125
edm::ESConsumesCollectorAdaptor::ESConsumesCollectorAdaptor
ESConsumesCollectorAdaptor(ESConsumesCollector *iBase)
Definition: ESConsumesCollector.h:178
edm::ESConsumesCollectorWithTagAdaptor::m_consumer
ESConsumesCollector * m_consumer
Definition: ESConsumesCollector.h:196
edm::propagate_const< ESConsumesInfo * >
edm::ESConsumesCollector::registerMayConsume
auto registerMayConsume(std::unique_ptr< Collector > iCollector, PTag const &productTag)
Definition: ESConsumesCollector.h:102
edm::ESConsumesCollectorWithTagAdaptor::ESConsumesCollectorWithTagAdaptor
ESConsumesCollectorWithTagAdaptor(ESConsumesCollector *iBase, ESInputTag iTag)
Definition: ESConsumesCollector.h:193
MayConsumeChooser.h
edm::ESConsumesCollectorWithTagAdaptor
Definition: ESConsumesCollector.h:183
edm::ESConsumesInfo
std::vector< ESConsumesInfoEntry > ESConsumesInfo
Definition: ESConsumesCollector.h:59
edm::ESConsumesCollector::operator=
ESConsumesCollector & operator=(ESConsumesCollector const &)=delete
edm::ESConsumesCollectorT::mayConsumeFrom
auto mayConsumeFrom(Func &&func, PTag const &productTag)
Definition: ESConsumesCollector.h:147
edm::ESConsumesCollectorAdaptor
Definition: ESConsumesCollector.h:168
edm::ESConsumesCollector::m_consumer
edm::propagate_const< ESConsumesInfo * > m_consumer
Definition: ESConsumesCollector.h:120
edm::ESConsumesCollector::consumes
ESConsumesCollectorAdaptor consumes()
Definition: ESConsumesCollector.h:200
Transition.h
edm::ESConsumesCollectorWithTagAdaptor::m_tag
const ESInputTag m_tag
Definition: ESConsumesCollector.h:197
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
DataKey.h
edm::ESConsumesCollectorWithTagAdaptor::consumes
ESGetToken< TYPE, REC > consumes()
Definition: ESConsumesCollector.h:186
edm::ESConsumesCollectorT::consumes
auto consumes()
Definition: ESConsumesCollector.h:142
edm::ESConsumesCollector::consumesFrom
auto consumesFrom(ESInputTag const &tag)
Definition: ESConsumesCollector.h:71
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
edm::ESGetToken
Definition: EventSetup.h:48
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESConsumesCollectorT::consumes
auto consumes(ESInputTag const &tag)
Definition: ESConsumesCollector.h:137
edm::ESConsumesCollectorAdaptor::m_consumer
ESConsumesCollector * m_consumer
Definition: ESConsumesCollector.h:180
ESInputTag.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ESConsumesCollector::ESConsumesCollector
ESConsumesCollector(ESConsumesInfo *const iConsumer, unsigned int iTransitionID)
Definition: ESConsumesCollector.h:98
edm::ESConsumesCollectorT::setMayConsume
ESConsumesCollector & setMayConsume(ESGetToken< Product, FromRecord > &token, Func &&func, PTag const &productTag)
Definition: ESConsumesCollector.h:155
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::ESProducer
Definition: ESProducer.h:104
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
EventSetupRecordKey.h
edm::eventsetup
Definition: ES_DDDetector.cc:16
edm::ESConsumesCollector::ESConsumesCollector
ESConsumesCollector()=delete
edm::ESConsumesInfoEntry::recordKey_
edm::eventsetup::EventSetupRecordKey recordKey_
Definition: ESConsumesCollector.h:54
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316