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 {
44  edm::eventsetup::DataKey const& iProduct,
46  std::unique_ptr<edm::eventsetup::impl::MayConsumeChooserCore> chooser)
47  : recordKey_{iRecord},
48  productKey_{iProduct},
50  chooser_{std::move(chooser)} {}
54  std::unique_ptr<edm::eventsetup::impl::MayConsumeChooserCore> chooser_;
55  };
56  using ESConsumesInfo = std::vector<ESConsumesInfoEntry>;
57 
59  public:
60  ESConsumesCollector() = delete;
65 
66  // ---------- member functions ---------------------------
67  template <typename Product, typename Record>
68  auto consumesFrom(ESInputTag const& tag) {
69  using namespace edm::eventsetup;
70  ESTokenIndex index{static_cast<ESTokenIndex::Value_t>(m_consumer->size())};
71  m_consumer->emplace_back(EventSetupRecordKey::makeKey<Record>(),
72  DataKey(DataKey::makeTypeTag<Product>(), tag.data().c_str()),
73  tag.module(),
74  nullptr);
75  //even though m_consumer may expand, the address for
76  // name().value() remains the same since it is 'moved'.
77  return ESGetToken<Product, Record>{m_transitionID, index, m_consumer->back().productKey_.name().value()};
78  }
79 
80  template <typename Product, typename Record>
81  auto consumesFrom() {
82  using namespace edm::eventsetup;
83  ESTokenIndex index{static_cast<ESTokenIndex::Value_t>(m_consumer->size())};
84  m_consumer->emplace_back(
85  EventSetupRecordKey::makeKey<Record>(), DataKey(DataKey::makeTypeTag<Product>(), ""), "", nullptr);
86  //even though m_consumer may expand, the address for
87  // name().value() remains the same since it is 'moved'.
88  return ESGetToken<Product, Record>{m_transitionID, index, m_consumer->back().productKey_.name().value()};
89  }
90 
91  template <typename Product, typename Record>
93  token = consumesFrom<Product, Record>(tag);
94  return *this;
95  }
96 
97  template <typename Product, typename Record>
99  token = consumesFrom<Product, Record>();
100  return *this;
101  }
102 
103  protected:
104  explicit ESConsumesCollector(ESConsumesInfo* const iConsumer, unsigned int iTransitionID)
105  : m_consumer{iConsumer}, m_transitionID{iTransitionID} {}
106 
107  template <typename Product, typename Record, typename Collector, typename PTag>
108  auto registerMayConsume(std::unique_ptr<Collector> iCollector, PTag const& productTag) {
109  //NOTE: for now, just treat like standard consumes request for the product needed to
110  // do the decision
111  setConsumes(iCollector->token(), productTag.inputTag());
112 
113  using namespace edm::eventsetup;
114  ESTokenIndex index{static_cast<ESTokenIndex::Value_t>(m_consumer->size())};
115  m_consumer->emplace_back(EventSetupRecordKey::makeKey<Record>(),
116  DataKey(DataKey::makeTypeTag<Product>(), "@mayConsume"),
117  "@mayConsume",
118  std::move(iCollector));
119  //even though m_consumer may expand, the address for
120  // name().value() remains the same since it is 'moved'.
121  return ESGetToken<Product, Record>{m_transitionID, index, m_consumer->back().productKey_.name().value()};
122  }
123 
124  private:
125  // ---------- member data --------------------------------
127  unsigned int m_transitionID{0};
128  };
129 
130  template <typename RECORD>
132  public:
133  ESConsumesCollectorT() = delete;
138 
139  // ---------- member functions ---------------------------
140 
141  template <typename Product>
142  auto consumes(ESInputTag const& tag) {
143  return consumesFrom<Product, RECORD>(tag);
144  }
145 
146  template <typename Product>
147  auto consumes() {
148  return consumesFrom<Product, RECORD>();
149  }
150 
151  template <typename Product, typename FromRecord, typename Func, typename PTag>
152  auto mayConsumeFrom(Func&& func, PTag const& productTag) {
153  return registerMayConsume<Product, FromRecord>(
155  std::forward<Func>(func)),
156  productTag);
157  }
158 
159  template <typename Product, typename FromRecord, typename Func, typename PTag>
161  token = mayConsumeFrom<Product, FromRecord>(std::forward<Func>(func), productTag);
162  return *this;
163  }
164 
165  private:
166  //only ESProducer is allowed to make an instance of this class
167  friend class ESProducer;
168 
169  explicit ESConsumesCollectorT(ESConsumesInfo* const iConsumer, unsigned int iTransitionID)
170  : ESConsumesCollector(iConsumer, iTransitionID) {}
171  };
172 
173 } // namespace edm
174 
175 #endif
edm::ESConsumesCollector::setConsumes
ESConsumesCollector & setConsumes(ESGetToken< Product, Record > &token, ESInputTag const &tag)
Definition: ESConsumesCollector.h:92
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:43
edm::ESTokenIndex
Definition: ESIndices.h:54
edm::ESConsumesInfoEntry::moduleLabel_
std::string moduleLabel_
Definition: ESConsumesCollector.h:53
edm::ESInputTag
Definition: ESInputTag.h:87
edm::ESConsumesInfoEntry::productKey_
edm::eventsetup::DataKey productKey_
Definition: ESConsumesCollector.h:52
edm::ESConsumesInfoEntry
Definition: ESConsumesCollector.h:42
edm::eventsetup::impl::MayConsumeChooser
Definition: MayConsumeChooser.h:34
edm::ESConsumesCollector
Definition: ESConsumesCollector.h:58
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:127
edm::ESConsumesInfoEntry::chooser_
std::unique_ptr< edm::eventsetup::impl::MayConsumeChooserCore > chooser_
Definition: ESConsumesCollector.h:54
ESGetToken.h
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
edm::ESConsumesCollectorT::ESConsumesCollectorT
ESConsumesCollectorT(ESConsumesInfo *const iConsumer, unsigned int iTransitionID)
Definition: ESConsumesCollector.h:169
edm::ESConsumesCollector::consumesFrom
auto consumesFrom()
Definition: ESConsumesCollector.h:81
edm::ESConsumesCollectorT
Definition: ESConsumesCollector.h:131
edm::propagate_const< ESConsumesInfo * >
edm::ESConsumesCollector::registerMayConsume
auto registerMayConsume(std::unique_ptr< Collector > iCollector, PTag const &productTag)
Definition: ESConsumesCollector.h:108
MayConsumeChooser.h
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
edm::ESConsumesInfo
std::vector< ESConsumesInfoEntry > ESConsumesInfo
Definition: ESConsumesCollector.h:56
edm::ESConsumesCollector::operator=
ESConsumesCollector & operator=(ESConsumesCollector const &)=delete
edm::ESConsumesCollectorT::mayConsumeFrom
auto mayConsumeFrom(Func &&func, PTag const &productTag)
Definition: ESConsumesCollector.h:152
edm::ESConsumesCollector::m_consumer
edm::propagate_const< ESConsumesInfo * > m_consumer
Definition: ESConsumesCollector.h:126
Transition.h
edm::ESConsumesCollector::setConsumes
ESConsumesCollector & setConsumes(ESGetToken< Product, Record > &token)
Definition: ESConsumesCollector.h:98
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DataKey.h
edm::ESConsumesCollectorT::consumes
auto consumes()
Definition: ESConsumesCollector.h:147
edm::ESConsumesCollector::consumesFrom
auto consumesFrom(ESInputTag const &tag)
Definition: ESConsumesCollector.h:68
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
edm::ESGetToken
Definition: EventSetup.h:48
edm::ESConsumesCollectorT::consumes
auto consumes(ESInputTag const &tag)
Definition: ESConsumesCollector.h:142
ESInputTag.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::ESConsumesCollector::ESConsumesCollector
ESConsumesCollector(ESConsumesInfo *const iConsumer, unsigned int iTransitionID)
Definition: ESConsumesCollector.h:104
edm::ESConsumesCollectorT::setMayConsume
ESConsumesCollector & setMayConsume(ESGetToken< Product, FromRecord > &token, Func &&func, PTag const &productTag)
Definition: ESConsumesCollector.h:160
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::ESProducer
Definition: ESProducer.h:101
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:51
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316