Skip to content

Commit

Permalink
Merge pull request #31223 from Dr15Jones/simplerConsumes
Browse files Browse the repository at this point in the history
Simplify specifying consumes
  • Loading branch information
cmsbuild authored Aug 28, 2020
2 parents 0532ec1 + 31920eb commit 1bff68d
Show file tree
Hide file tree
Showing 23 changed files with 426 additions and 118 deletions.
76 changes: 76 additions & 0 deletions FWCore/Framework/interface/ConsumesCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ a functor passed to the Framework with a call to callWhenNewProductsRegistered.
// forward declarations
namespace edm {
class EDConsumerBase;
template <Transition TR>
class ConsumesCollectorESAdaptor;
template <Transition TR>
class ConsumesCollectorWithTagESAdaptor;
template <BranchType B>
class ConsumesCollectorAdaptor;

class ConsumesCollector {
public:
Expand All @@ -50,6 +56,11 @@ namespace edm {
return m_consumer->consumes<ProductType, B>(tag);
}

template <BranchType B = InEvent>
[[nodiscard]] ConsumesCollectorAdaptor<B> consumes(edm::InputTag tag) {
return ConsumesCollectorAdaptor<B>(*this, std::move(tag));
}

EDGetToken consumes(const TypeToGet& id, edm::InputTag const& tag) { return m_consumer->consumes(id, tag); }

template <BranchType B>
Expand Down Expand Up @@ -97,6 +108,16 @@ namespace edm {
return m_consumer->esConsumes<ESProduct, Tr>(key, tag);
}

template <Transition Tr = Transition::Event>
[[nodiscard]] constexpr auto esConsumes() noexcept {
return ConsumesCollectorESAdaptor<Tr>(*this);
}

template <Transition Tr = Transition::Event>
[[nodiscard]] auto esConsumes(ESInputTag tag) noexcept {
return ConsumesCollectorWithTagESAdaptor<Tr>(*this, std::move(tag));
}

private:
//only EDConsumerBase is allowed to make an instance of this class
friend class EDConsumerBase;
Expand All @@ -106,6 +127,61 @@ namespace edm {
// ---------- member data --------------------------------
edm::propagate_const<EDConsumerBase*> m_consumer;
};

template <Transition TR>
class ConsumesCollectorESAdaptor {
public:
template <typename TYPE, typename REC>
ESGetToken<TYPE, REC> consumes() {
return m_consumer.template esConsumes<TYPE, REC, TR>();
}

private:
//only ConsumesCollector is allowed to make an instance of this class
friend class ConsumesCollector;

explicit ConsumesCollectorESAdaptor(ConsumesCollector iBase) : m_consumer(std::move(iBase)) {}

ConsumesCollector m_consumer;
};

template <Transition TR>
class ConsumesCollectorWithTagESAdaptor {
public:
template <typename TYPE, typename REC>
ESGetToken<TYPE, REC> consumes() {
return m_consumer.template esConsumes<TYPE, REC, TR>(m_tag);
}

private:
//only ConsumesCollector is allowed to make an instance of this class
friend class ConsumesCollector;

ConsumesCollectorWithTagESAdaptor(ConsumesCollector iBase, ESInputTag iTag)
: m_consumer(std::move(iBase)), m_tag(std::move(iTag)) {}

ConsumesCollector m_consumer;
ESInputTag const& m_tag;
};

template <BranchType B>
class ConsumesCollectorAdaptor {
public:
template <typename TYPE>
EDGetTokenT<TYPE> consumes() {
return m_consumer.template consumes<TYPE, B>(m_tag);
}

private:
//only ConsumesCollector is allowed to make an instance of this class
friend class ConsumesCollector;

ConsumesCollectorAdaptor(ConsumesCollector iBase, edm::InputTag iTag) : m_consumer(iBase), m_tag(std::move(iTag)) {}

ConsumesCollector m_consumer;
edm::InputTag const m_tag;
};

} // namespace edm

#endif
80 changes: 80 additions & 0 deletions FWCore/Framework/interface/EDConsumerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ namespace edm {
class ProductResolverIndexHelper;
class ProductRegistry;
class ConsumesCollector;
template <Transition Tr>
class EDConsumerBaseESAdaptor;
template <Transition Tr>
class EDConsumerBaseWithTagESAdaptor;
template <BranchType B>
class EDConsumerBaseAdaptor;
template <typename T>
class WillGetIfMatch;

Expand Down Expand Up @@ -131,6 +137,12 @@ namespace edm {

protected:
friend class ConsumesCollector;
template <Transition Tr>
friend class EDConsumerBaseESAdaptor;
template <Transition Tr>
friend class EDConsumerBaseWithTagESAdaptor;
template <BranchType B>
friend class EDConsumerBaseAdaptor;
template <typename T>
friend class WillGetIfMatch;
///Use a ConsumesCollector to gather consumes information from helper functions
Expand All @@ -142,6 +154,11 @@ namespace edm {
return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), true)};
}

template <BranchType B = InEvent>
[[nodiscard]] EDConsumerBaseAdaptor<B> consumes(edm::InputTag tag) noexcept {
return EDConsumerBaseAdaptor<B>(this, std::move(tag));
}

EDGetToken consumes(const TypeToGet& id, edm::InputTag const& tag) {
return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
}
Expand Down Expand Up @@ -195,6 +212,16 @@ namespace edm {
return ESGetToken<ESProduct, ESRecord>{static_cast<unsigned int>(Tr), index, labelFor(index)};
}

template <Transition Tr = Transition::Event>
[[nodiscard]] constexpr auto esConsumes() noexcept {
return EDConsumerBaseESAdaptor<Tr>(this);
}

template <Transition Tr = Transition::Event>
[[nodiscard]] auto esConsumes(ESInputTag tag) noexcept {
return EDConsumerBaseWithTagESAdaptor<Tr>(this, std::move(tag));
}

private:
unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
ESTokenIndex recordESConsumes(Transition,
Expand Down Expand Up @@ -267,6 +294,59 @@ namespace edm {
bool frozen_;
bool containsCurrentProcessAlias_;
};

template <Transition TR>
class EDConsumerBaseESAdaptor {
public:
template <typename TYPE, typename REC>
ESGetToken<TYPE, REC> consumes() {
return m_consumer->template esConsumes<TYPE, REC, TR>();
}

private:
//only EDConsumerBase is allowed to make an instance of this class
friend class EDConsumerBase;
EDConsumerBaseESAdaptor(EDConsumerBase* iBase) : m_consumer(iBase) {}

EDConsumerBase* m_consumer;
};

template <Transition TR>
class EDConsumerBaseWithTagESAdaptor {
public:
template <typename TYPE, typename REC>
ESGetToken<TYPE, REC> consumes() {
return m_consumer->template esConsumes<TYPE, REC, TR>(m_tag);
}

private:
//only EDConsumerBase is allowed to make an instance of this class
friend class EDConsumerBase;
EDConsumerBaseWithTagESAdaptor(EDConsumerBase* iBase, ESInputTag iTag) noexcept
: m_consumer(iBase), m_tag(std::move(iTag)) {}

EDConsumerBase* m_consumer;
ESInputTag const m_tag;
};

template <BranchType B>
class EDConsumerBaseAdaptor {
public:
template <typename TYPE>
EDGetTokenT<TYPE> consumes() {
return m_consumer->template consumes<TYPE, B>(m_tag);
}

private:
//only EDConsumerBase is allowed to make an instance of this class
friend class EDConsumerBase;
EDConsumerBaseAdaptor(EDConsumerBase* iBase, edm::InputTag iTag) noexcept
: m_consumer(iBase), m_tag(std::move(iTag)) {}

EDConsumerBase* m_consumer;
edm::InputTag const m_tag;
};

} // namespace edm

#endif
44 changes: 44 additions & 0 deletions FWCore/Framework/interface/ESConsumesCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include <vector>
#include <memory>
namespace edm {
class ESConsumesCollectorAdaptor;
class ESConsumesCollectorWithTagAdaptor;

struct ESConsumesInfoEntry {
ESConsumesInfoEntry(edm::eventsetup::EventSetupRecordKey const& iRecord,
edm::eventsetup::DataKey const& iProduct,
Expand Down Expand Up @@ -100,6 +103,9 @@ namespace edm {
return *this;
}

ESConsumesCollectorAdaptor consumes();
ESConsumesCollectorWithTagAdaptor consumes(ESInputTag tag);

protected:
explicit ESConsumesCollector(ESConsumesInfo* const iConsumer, unsigned int iTransitionID)
: m_consumer{iConsumer}, m_transitionID{iTransitionID} {}
Expand Down Expand Up @@ -138,6 +144,7 @@ namespace edm {

// ---------- member functions ---------------------------

using ESConsumesCollector::consumes;
template <typename Product>
auto consumes(ESInputTag const& tag) {
return consumesFrom<Product, RECORD>(tag);
Expand Down Expand Up @@ -170,6 +177,43 @@ namespace edm {
: ESConsumesCollector(iConsumer, iTransitionID) {}
};

class ESConsumesCollectorAdaptor {
public:
template <typename TYPE, typename REC>
ESGetToken<TYPE, REC> consumes() {
return m_consumer->template consumesFrom<TYPE, REC>();
}

private:
//only ESConsumesCollector is allowed to make an instance of this class
friend class ESConsumesCollector;
explicit ESConsumesCollectorAdaptor(ESConsumesCollector* iBase) : m_consumer(iBase) {}

ESConsumesCollector* m_consumer;
};

class ESConsumesCollectorWithTagAdaptor {
public:
template <typename TYPE, typename REC>
ESGetToken<TYPE, REC> consumes() {
return m_consumer->template consumesFrom<TYPE, REC>(m_tag);
}

private:
//only ESConsumesCollector is allowed to make an instance of this class
friend class ESConsumesCollector;
ESConsumesCollectorWithTagAdaptor(ESConsumesCollector* iBase, ESInputTag iTag)
: m_consumer(iBase), m_tag(std::move(iTag)) {}

ESConsumesCollector* m_consumer;
ESInputTag const m_tag;
};

inline ESConsumesCollectorAdaptor ESConsumesCollector::consumes() { return ESConsumesCollectorAdaptor(this); }
inline ESConsumesCollectorWithTagAdaptor ESConsumesCollector::consumes(ESInputTag tag) {
return ESConsumesCollectorWithTagAdaptor(this, std::move(tag));
}

} // namespace edm

#endif
6 changes: 3 additions & 3 deletions FWCore/Framework/test/edconsumerbase_t.cppunit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace {
IntsConsumer(std::vector<edm::InputTag> const& iTags) {
m_tokens.reserve(iTags.size());
for (auto const& tag : iTags) {
m_tokens.push_back(consumes<std::vector<int>>(tag));
m_tokens.emplace_back(consumes(tag));
}
}

Expand All @@ -74,7 +74,7 @@ namespace {
m_tokens.reserve(iTags.size());
m_mayTokens.reserve(iMayTags.size());
for (auto const& tag : iTags) {
m_tokens.push_back(consumes<std::vector<int>>(tag));
m_tokens.emplace_back(consumes(tag));
}
for (auto const& tag : iMayTags) {
m_mayTokens.push_back(mayConsume<std::vector<int>>(tag));
Expand Down Expand Up @@ -109,7 +109,7 @@ namespace {
collectorCopy2 = std::move(collectorCopy1);

for (auto const& tag : iTags) {
m_tokens.push_back(collectorCopy2.consumes<std::vector<int>>(tag));
m_tokens.emplace_back(collectorCopy2.consumes(tag));
}
}

Expand Down
Loading

0 comments on commit 1bff68d

Please sign in to comment.