Skip to content

Commit

Permalink
Enforce ESGetToken use for ESProducers
Browse files Browse the repository at this point in the history
EventSetupRecord and EventSetup now have an option to enforce the use of ESGetTokens. For ESProducers that option is enabled,  for ED modules it is disabled.
  • Loading branch information
Dr15Jones committed Oct 8, 2019
1 parent 70bdca8 commit cf2f131
Show file tree
Hide file tree
Showing 31 changed files with 416 additions and 251 deletions.
2 changes: 1 addition & 1 deletion FWCore/Framework/interface/CallbackProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace edm::eventsetup {
EventSetupImpl const* iEventSetupImpl) override {
assert(iRecord.key() == RecordT::keyForClass());
RecordType rec;
rec.setImpl(&iRecord, callback_->transitionID(), callback_->getTokenIndices(), iEventSetupImpl);
rec.setImpl(&iRecord, callback_->transitionID(), callback_->getTokenIndices(), iEventSetupImpl, true);
(*callback_)(rec);
return smart_pointer_traits::getPointer(data_);
}
Expand Down
2 changes: 1 addition & 1 deletion FWCore/Framework/interface/DataProxyTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace edm {
EventSetupImpl const* iEventSetupImpl) override {
assert(iRecord.key() == RecordT::keyForClass());
RecordT rec;
rec.setImpl(&iRecord, std::numeric_limits<unsigned int>::max(), nullptr, iEventSetupImpl);
rec.setImpl(&iRecord, std::numeric_limits<unsigned int>::max(), nullptr, iEventSetupImpl, true);
return this->make(rec, iKey);
}

Expand Down
6 changes: 4 additions & 2 deletions FWCore/Framework/interface/DependentRecordImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ namespace edm {
!std::is_same<FoundItrT, EndItrT>::value,
"Trying to get a Record from another Record where the second Record is not dependent on the first Record.");
try {
EventSetup const eventSetupT{this->eventSetup(), this->transitionID(), this->getTokenIndices()};
EventSetup const eventSetupT{
this->eventSetup(), this->transitionID(), this->getTokenIndices(), this->requireTokens()};
return eventSetupT.get<DepRecordT>();
} catch (cms::Exception& e) {
std::ostringstream sstrm;
Expand All @@ -74,7 +75,8 @@ namespace edm {
static_assert(
!std::is_same<FoundItrT, EndItrT>::value,
"Trying to get a Record from another Record where the second Record is not dependent on the first Record.");
EventSetup const eventSetupT{this->eventSetup(), this->transitionID(), this->getTokenIndices()};
EventSetup const eventSetupT{
this->eventSetup(), this->transitionID(), this->getTokenIndices(), this->requireTokens()};
return eventSetupT.tryToGet<DepRecordT>();
}

Expand Down
12 changes: 8 additions & 4 deletions FWCore/Framework/interface/EventSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ namespace edm {
friend class edm::PileUp;

public:
explicit EventSetup(EventSetupImpl const& iSetup, unsigned int iTransitionID, ESProxyIndex const* iGetTokenIndices)
: m_setup{iSetup}, m_getTokenIndices{iGetTokenIndices}, m_id{iTransitionID} {}
explicit EventSetup(EventSetupImpl const& iSetup,
unsigned int iTransitionID,
ESProxyIndex const* iGetTokenIndices,
bool iRequireToken)
: m_setup{iSetup}, m_getTokenIndices{iGetTokenIndices}, m_id{iTransitionID}, m_requireToken(iRequireToken) {}
EventSetup(EventSetup const&) = delete;
EventSetup& operator=(EventSetup const&) = delete;

Expand All @@ -81,7 +84,7 @@ namespace edm {
throw eventsetup::NoRecordException<T>(recordDoesExist(m_setup, eventsetup::EventSetupRecordKey::makeKey<T>()));
}
T returnValue;
returnValue.setImpl(temp, m_id, m_getTokenIndices, &m_setup);
returnValue.setImpl(temp, m_id, m_getTokenIndices, &m_setup, m_requireToken);
return returnValue;
}

Expand All @@ -99,7 +102,7 @@ namespace edm {
eventsetup::EventSetupRecordKey>());
if (temp != nullptr) {
T rec;
rec.setImpl(temp, m_id, m_getTokenIndices, &m_setup);
rec.setImpl(temp, m_id, m_getTokenIndices, &m_setup, m_requireToken);
return rec;
}
return std::nullopt;
Expand Down Expand Up @@ -178,6 +181,7 @@ namespace edm {
edm::EventSetupImpl const& m_setup;
ESProxyIndex const* m_getTokenIndices;
unsigned int m_id;
bool m_requireToken;
};

// Free functions to retrieve an object from the EventSetup.
Expand Down
22 changes: 18 additions & 4 deletions FWCore/Framework/interface/EventSetupRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ namespace edm {
void setImpl(EventSetupRecordImpl const* iImpl,
unsigned int transitionID,
ESProxyIndex const* getTokenIndices,
EventSetupImpl const* iEventSetupImpl) {
EventSetupImpl const* iEventSetupImpl,
bool requireTokens) {
impl_ = iImpl;
transitionID_ = transitionID;
getTokenIndices_ = getTokenIndices;
eventSetupImpl_ = iEventSetupImpl;
requireTokens_ = requireTokens;
}

template <typename HolderT>
Expand All @@ -109,6 +111,10 @@ namespace edm {

template <typename HolderT>
bool get(char const* iName, HolderT& iHolder) const {
if
UNLIKELY(requireTokens_) {
throwCalledGetWithoutToken(heterocontainer::className<typename HolderT::value_type>(), iName);
}
typename HolderT::value_type const* value = nullptr;
ComponentDescription const* desc = nullptr;
std::shared_ptr<ESHandleExceptionFactory> whyFailedFactory;
Expand All @@ -130,6 +136,10 @@ namespace edm {

template <typename HolderT>
bool get(ESInputTag const& iTag, HolderT& iHolder) const {
if
UNLIKELY(requireTokens_) {
throwCalledGetWithoutToken(heterocontainer::className<typename HolderT::value_type>(), iTag.data().c_str());
}
typename HolderT::value_type const* value = nullptr;
ComponentDescription const* desc = nullptr;
std::shared_ptr<ESHandleExceptionFactory> whyFailedFactory;
Expand Down Expand Up @@ -235,6 +245,8 @@ namespace edm {

unsigned int transitionID() const { return transitionID_; }

bool requireTokens() const { return requireTokens_; }

private:
template <template <typename> typename H, typename T, typename R>
H<T> invalidTokenHandle(ESGetToken<T, R> const& iToken) const {
Expand All @@ -259,21 +271,23 @@ namespace edm {

static std::exception_ptr makeInvalidTokenException(EventSetupRecordKey const&, TypeTag const&);
void throwWrongTransitionID() const;

static void throwCalledGetWithoutToken(const char* iTypeName, const char* iLabel);
// ---------- member data --------------------------------
EventSetupRecordImpl const* impl_ = nullptr;
EventSetupImpl const* eventSetupImpl_ = nullptr;
ESProxyIndex const* getTokenIndices_ = nullptr;
unsigned int transitionID_ = std::numeric_limits<unsigned int>::max();
bool requireTokens_ = false;
};

class EventSetupRecordGeneric : public EventSetupRecord {
public:
EventSetupRecordGeneric(EventSetupRecordImpl const* iImpl,
unsigned int iTransitionID,
ESProxyIndex const* getTokenIndices,
EventSetupImpl const* eventSetupImpl) {
setImpl(iImpl, iTransitionID, getTokenIndices, eventSetupImpl);
EventSetupImpl const* eventSetupImpl,
bool requireTokens = false) {
setImpl(iImpl, iTransitionID, getTokenIndices, eventSetupImpl, requireTokens);
}

EventSetupRecordKey key() const final { return impl()->key(); }
Expand Down
12 changes: 8 additions & 4 deletions FWCore/Framework/interface/stream/EDAnalyzerAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ namespace edm {
RunIndex ri = rp.index();
const EventSetup c{ci,
static_cast<unsigned int>(Transition::BeginRun),
this->consumer()->esGetTokenIndices(Transition::BeginRun)};
this->consumer()->esGetTokenIndices(Transition::BeginRun),
false};
MyGlobalRun::beginRun(cnstR, c, m_global.get(), m_runs[ri]);
typename T::RunContext rc(m_runs[ri].get(), m_global.get());
MyGlobalRunSummary::beginRun(cnstR, c, &rc, m_runSummaries[ri]);
Expand All @@ -131,7 +132,8 @@ namespace edm {
typename T::RunContext rc(m_runs[ri].get(), m_global.get());
const EventSetup c{ci,
static_cast<unsigned int>(Transition::EndRun),
this->consumer()->esGetTokenIndices(Transition::EndRun)};
this->consumer()->esGetTokenIndices(Transition::EndRun),
false};
MyGlobalRunSummary::globalEndRun(r, c, &rc, m_runSummaries[ri].get());
MyGlobalRun::endRun(r, c, &rc);
}
Expand All @@ -149,7 +151,8 @@ namespace edm {
typename T::RunContext rc(m_runs[ri].get(), m_global.get());
const EventSetup c{ci,
static_cast<unsigned int>(Transition::BeginLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::BeginLuminosityBlock)};
this->consumer()->esGetTokenIndices(Transition::BeginLuminosityBlock),
false};
MyGlobalLuminosityBlock::beginLuminosityBlock(cnstLb, c, &rc, m_lumis[li]);
typename T::LuminosityBlockContext lc(m_lumis[li].get(), m_runs[ri].get(), m_global.get());
MyGlobalLuminosityBlockSummary::beginLuminosityBlock(cnstLb, c, &lc, m_lumiSummaries[li]);
Expand All @@ -167,7 +170,8 @@ namespace edm {
typename T::LuminosityBlockContext lc(m_lumis[li].get(), m_runs[ri].get(), m_global.get());
const EventSetup c{ci,
static_cast<unsigned int>(Transition::EndLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::EndLuminosityBlock)};
this->consumer()->esGetTokenIndices(Transition::EndLuminosityBlock),
false};
MyGlobalLuminosityBlockSummary::globalEndLuminosityBlock(lb, c, &lc, m_lumiSummaries[li].get());
MyGlobalLuminosityBlock::endLuminosityBlock(lb, c, &lc);
}
Expand Down
12 changes: 8 additions & 4 deletions FWCore/Framework/interface/stream/ProducingModuleAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ namespace edm {
RunIndex ri = rp.index();
const EventSetup c{ci,
static_cast<unsigned int>(Transition::BeginRun),
this->consumer()->esGetTokenIndices(Transition::BeginRun)};
this->consumer()->esGetTokenIndices(Transition::BeginRun),
false};
MyGlobalRun::beginRun(cnstR, c, m_global.get(), m_runs[ri]);
typename T::RunContext rc(m_runs[ri].get(), m_global.get());
MyGlobalRunSummary::beginRun(cnstR, c, &rc, m_runSummaries[ri]);
Expand All @@ -136,7 +137,8 @@ namespace edm {
typename T::RunContext rc(m_runs[ri].get(), m_global.get());
const EventSetup c{ci,
static_cast<unsigned int>(Transition::EndRun),
this->consumer()->esGetTokenIndices(Transition::EndRun)};
this->consumer()->esGetTokenIndices(Transition::EndRun),
false};
MyGlobalRunSummary::globalEndRun(r, c, &rc, m_runSummaries[ri].get());
if constexpr (T::HasAbility::kEndRunProducer) {
MyEndRunProduce::produce(r, c, &rc, m_runSummaries[ri].get());
Expand All @@ -160,7 +162,8 @@ namespace edm {
typename T::RunContext rc(m_runs[ri].get(), m_global.get());
const EventSetup c{ci,
static_cast<unsigned int>(Transition::BeginLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::BeginLuminosityBlock)};
this->consumer()->esGetTokenIndices(Transition::BeginLuminosityBlock),
false};

MyGlobalLuminosityBlock::beginLuminosityBlock(cnstLb, c, &rc, m_lumis[li]);
typename T::LuminosityBlockContext lc(m_lumis[li].get(), m_runs[ri].get(), m_global.get());
Expand All @@ -185,7 +188,8 @@ namespace edm {
typename T::LuminosityBlockContext lc(m_lumis[li].get(), m_runs[ri].get(), m_global.get());
const EventSetup c{ci,
static_cast<unsigned int>(Transition::EndLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::EndLuminosityBlock)};
this->consumer()->esGetTokenIndices(Transition::EndLuminosityBlock),
false};
MyGlobalLuminosityBlockSummary::globalEndLuminosityBlock(lb, c, &lc, m_lumiSummaries[li].get());
if constexpr (T::HasAbility::kEndLuminosityBlockProducer) {
MyEndLuminosityBlockProduce::produce(lb, c, &lc, m_lumiSummaries[li].get());
Expand Down
13 changes: 8 additions & 5 deletions FWCore/Framework/src/EDAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace edm {
e.setConsumer(this);
e.setSharedResourcesAcquirer(&resourceAcquirer_);
EventSignalsSentry sentry(act, mcc);
const EventSetup c{ci, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event)};
const EventSetup c{ci, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), false};
this->analyze(e, c);
return true;
}
Expand All @@ -52,15 +52,16 @@ namespace edm {
bool EDAnalyzer::doBeginRun(RunPrincipal const& rp, EventSetupImpl const& ci, ModuleCallingContext const* mcc) {
Run r(rp, moduleDescription_, mcc, false);
r.setConsumer(this);
const EventSetup c{ci, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun)};
const EventSetup c{
ci, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), false};
this->beginRun(r, c);
return true;
}

bool EDAnalyzer::doEndRun(RunPrincipal const& rp, EventSetupImpl const& ci, ModuleCallingContext const* mcc) {
Run r(rp, moduleDescription_, mcc, true);
r.setConsumer(this);
const EventSetup c{ci, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun)};
const EventSetup c{ci, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), false};
this->endRun(r, c);
return true;
}
Expand All @@ -72,7 +73,8 @@ namespace edm {
lb.setConsumer(this);
const EventSetup c{ci,
static_cast<unsigned int>(Transition::BeginLuminosityBlock),
esGetTokenIndices(Transition::BeginLuminosityBlock)};
esGetTokenIndices(Transition::BeginLuminosityBlock),
false};
this->beginLuminosityBlock(lb, c);
return true;
}
Expand All @@ -84,7 +86,8 @@ namespace edm {
lb.setConsumer(this);
const EventSetup c{ci,
static_cast<unsigned int>(Transition::EndLuminosityBlock),
esGetTokenIndices(Transition::EndLuminosityBlock)};
esGetTokenIndices(Transition::EndLuminosityBlock),
false};
this->endLuminosityBlock(lb, c);
return true;
}
Expand Down
16 changes: 10 additions & 6 deletions FWCore/Framework/src/EDFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace edm {
e.setSharedResourcesAcquirer(&resourceAcquirer_);
EventSignalsSentry sentry(act, mcc);
rc = this->filter(
e, EventSetup{c, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event)});
e, EventSetup{c, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), false});
commit_(e, &previousParentageId_);
return rc;
}
Expand All @@ -54,7 +54,8 @@ namespace edm {
r.setConsumer(this);
Run const& cnstR = r;
this->beginRun(
cnstR, EventSetup{c, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun)});
cnstR,
EventSetup{c, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), false});
commit_(r);
return;
}
Expand All @@ -63,8 +64,9 @@ namespace edm {
Run r(rp, moduleDescription_, mcc, true);
r.setConsumer(this);
Run const& cnstR = r;
this->endRun(cnstR,
EventSetup{c, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun)});
this->endRun(
cnstR,
EventSetup{c, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), false});
commit_(r);
return;
}
Expand All @@ -78,7 +80,8 @@ namespace edm {
this->beginLuminosityBlock(cnstLb,
EventSetup{c,
static_cast<unsigned int>(Transition::BeginLuminosityBlock),
esGetTokenIndices(Transition::BeginLuminosityBlock)});
esGetTokenIndices(Transition::BeginLuminosityBlock),
false});
commit_(lb);
}

Expand All @@ -91,7 +94,8 @@ namespace edm {
this->endLuminosityBlock(cnstLb,
EventSetup{c,
static_cast<unsigned int>(Transition::EndLuminosityBlock),
esGetTokenIndices(Transition::EndLuminosityBlock)});
esGetTokenIndices(Transition::EndLuminosityBlock),
false});
commit_(lb);
return;
}
Expand Down
14 changes: 7 additions & 7 deletions FWCore/Framework/src/EDLooperBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace edm {

Status status = kContinue;
try {
const EventSetup es{esi, static_cast<unsigned int>(Transition::Event), nullptr};
const EventSetup es{esi, static_cast<unsigned int>(Transition::Event), nullptr, false};
status = duringLoop(event, es, ioController);
} catch (cms::Exception& e) {
e.addContext("Calling the 'duringLoop' method of a looper");
Expand All @@ -69,7 +69,7 @@ namespace edm {
}

EDLooperBase::Status EDLooperBase::doEndOfLoop(const edm::EventSetupImpl& esi) {
const EventSetup es{esi, static_cast<unsigned int>(Transition::EndRun), nullptr};
const EventSetup es{esi, static_cast<unsigned int>(Transition::EndRun), nullptr, false};
return endOfLoop(es, iCounter_);
}

Expand All @@ -82,7 +82,7 @@ namespace edm {
}

void EDLooperBase::beginOfJob(const edm::EventSetupImpl& iImpl) {
beginOfJob(EventSetup{iImpl, static_cast<unsigned int>(Transition::BeginRun), nullptr});
beginOfJob(EventSetup{iImpl, static_cast<unsigned int>(Transition::BeginRun), nullptr, false});
}
void EDLooperBase::beginOfJob(const edm::EventSetup&) { beginOfJob(); }
void EDLooperBase::beginOfJob() {}
Expand All @@ -99,7 +99,7 @@ namespace edm {
ParentContext parentContext(&globalContext);
ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
Run run(iRP, moduleDescription_, &moduleCallingContext_, false);
const EventSetup es{iES, static_cast<unsigned int>(Transition::BeginRun), nullptr};
const EventSetup es{iES, static_cast<unsigned int>(Transition::BeginRun), nullptr, false};
beginRun(run, es);
}

Expand All @@ -113,7 +113,7 @@ namespace edm {
ParentContext parentContext(&globalContext);
ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
Run run(iRP, moduleDescription_, &moduleCallingContext_, true);
const EventSetup es{iES, static_cast<unsigned int>(Transition::EndRun), nullptr};
const EventSetup es{iES, static_cast<unsigned int>(Transition::EndRun), nullptr, false};
endRun(run, es);
}
void EDLooperBase::doBeginLuminosityBlock(LuminosityBlockPrincipal& iLB,
Expand All @@ -128,7 +128,7 @@ namespace edm {
ParentContext parentContext(&globalContext);
ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
LuminosityBlock luminosityBlock(iLB, moduleDescription_, &moduleCallingContext_, false);
const EventSetup es{iES, static_cast<unsigned int>(Transition::BeginLuminosityBlock), nullptr};
const EventSetup es{iES, static_cast<unsigned int>(Transition::BeginLuminosityBlock), nullptr, false};
beginLuminosityBlock(luminosityBlock, es);
}
void EDLooperBase::doEndLuminosityBlock(LuminosityBlockPrincipal& iLB,
Expand All @@ -143,7 +143,7 @@ namespace edm {
ParentContext parentContext(&globalContext);
ModuleContextSentry moduleContextSentry(&moduleCallingContext_, parentContext);
LuminosityBlock luminosityBlock(iLB, moduleDescription_, &moduleCallingContext_, true);
const EventSetup es{iES, static_cast<unsigned int>(Transition::EndLuminosityBlock), nullptr};
const EventSetup es{iES, static_cast<unsigned int>(Transition::EndLuminosityBlock), nullptr, false};
endLuminosityBlock(luminosityBlock, es);
}

Expand Down
Loading

0 comments on commit cf2f131

Please sign in to comment.