Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce EventSetup products can be obtained only with ESGetToken #35588

Merged
merged 4 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FWCore/Framework/interface/Callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace edm {
//Handle mayGets
TRecord rec;
edm::ESParentContext pc{&callingContext_};
rec.setImpl(iRecord, transitionID(), getTokenIndices(), iEventSetupImpl, &pc, true);
rec.setImpl(iRecord, transitionID(), getTokenIndices(), iEventSetupImpl, &pc);
postMayGetProxies_ = producer_->updateFromMayConsumes(id_, rec);
return static_cast<bool>(postMayGetProxies_);
}
Expand Down Expand Up @@ -194,7 +194,7 @@ namespace edm {
}
TRecord rec;
edm::ESParentContext pc{&callingContext_};
rec.setImpl(iRecord, transitionID(), proxies, iEventSetupImpl, &pc, true);
rec.setImpl(iRecord, transitionID(), proxies, iEventSetupImpl, &pc);
ServiceRegistry::Operate operate(weakToken.lock());
iRecord->activityRegistry()->preESModuleSignal_.emit(iRecord->key(), callingContext_);
struct EndGuard {
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 @@ -72,7 +72,7 @@ namespace edm {
iTask.group()->run([this, &iRecord, iKey, iEventSetupImpl, iToken, iParent]() {
try {
RecordT rec;
rec.setImpl(&iRecord, std::numeric_limits<unsigned int>::max(), nullptr, iEventSetupImpl, &iParent, true);
rec.setImpl(&iRecord, std::numeric_limits<unsigned int>::max(), nullptr, iEventSetupImpl, &iParent);
ServiceRegistry::Operate operate(iToken);
this->make(rec, iKey);
} catch (...) {
Expand Down
14 changes: 4 additions & 10 deletions FWCore/Framework/interface/DependentRecordImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ namespace edm {
(list_type::template contains<DepRecordT>()),
"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(),
*this->esParentContext(),
this->requireTokens()};
EventSetup const eventSetupT{
this->eventSetup(), this->transitionID(), this->getTokenIndices(), *this->esParentContext()};
return eventSetupT.get<DepRecordT>();
} catch (cms::Exception& e) {
std::ostringstream sstrm;
Expand All @@ -73,11 +70,8 @@ namespace edm {
static_assert(
(list_type::template contains<DepRecordT>()),
"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(),
*this->esParentContext(),
this->requireTokens()};
EventSetup const eventSetupT{
this->eventSetup(), this->transitionID(), this->getTokenIndices(), *this->esParentContext()};
return eventSetupT.tryToGet<DepRecordT>();
}

Expand Down
4 changes: 4 additions & 0 deletions FWCore/Framework/interface/ESConsumesCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@

#include <vector>
#include <memory>

class testEventsetupRecord;

namespace edm {
class ESConsumesCollectorAdaptor;
class ESConsumesCollectorWithTagAdaptor;
Expand Down Expand Up @@ -160,6 +163,7 @@ namespace edm {
private:
//only ESProducer is allowed to make an instance of this class
friend class ESProducer;
friend class ::testEventsetupRecord;

explicit ESConsumesCollectorT(ESConsumesInfo* const iConsumer, unsigned int iTransitionID)
: ESConsumesCollector(iConsumer, iTransitionID) {}
Expand Down
19 changes: 6 additions & 13 deletions FWCore/Framework/interface/EventSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,14 @@ namespace edm {
explicit EventSetup(T const& info,
unsigned int iTransitionID,
ESProxyIndex const* iGetTokenIndices,
ESParentContext const& iContext,
bool iRequireToken)
: EventSetup(info.eventSetupImpl(), iTransitionID, iGetTokenIndices, iContext, iRequireToken) {}
ESParentContext const& iContext)
: EventSetup(info.eventSetupImpl(), iTransitionID, iGetTokenIndices, iContext) {}

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

Expand All @@ -99,7 +93,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, m_context, m_requireToken);
returnValue.setImpl(temp, m_id, m_getTokenIndices, &m_setup, m_context);
return returnValue;
}

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

// Free functions to retrieve an object from the EventSetup.
Expand Down
49 changes: 7 additions & 42 deletions FWCore/Framework/interface/EventSetupRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,12 @@ namespace edm {
unsigned int transitionID,
ESProxyIndex const* getTokenIndices,
EventSetupImpl const* iEventSetupImpl,
ESParentContext const* iContext,
bool requireTokens) {
ESParentContext const* iContext) {
impl_ = iImpl;
transitionID_ = transitionID;
getTokenIndices_ = getTokenIndices;
eventSetupImpl_ = iEventSetupImpl;
context_ = iContext;
requireTokens_ = requireTokens;
}

template <typename HolderT>
Expand All @@ -125,23 +123,8 @@ namespace edm {

template <typename HolderT>
CMS_DEPRECATED 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;
impl_->getImplementation(
value, iTag.data().c_str(), desc, iHolder.transientAccessOnly, whyFailedFactory, *context_, eventSetupImpl_);

if (value) {
validate(desc, iTag);
iHolder = HolderT(value, desc);
return true;
} else {
iHolder = HolderT(std::move(whyFailedFactory));
return false;
}
throwCalledGetWithoutToken(heterocontainer::className<typename HolderT::value_type>(), iTag.data().c_str());
return false;
}

///returns false if no data available for key
Expand Down Expand Up @@ -241,27 +224,11 @@ namespace edm {

unsigned int transitionID() const { return transitionID_; }

bool requireTokens() const { return requireTokens_; }

private:
template <typename HolderT>
bool deprecated_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;
impl_->getImplementation(
value, iName, desc, iHolder.transientAccessOnly, whyFailedFactory, *context_, eventSetupImpl_);

if (value) {
iHolder = HolderT(value, desc);
return true;
} else {
iHolder = HolderT(std::move(whyFailedFactory));
return false;
}
throwCalledGetWithoutToken(heterocontainer::className<typename HolderT::value_type>(), iName);
return false;
}

template <template <typename> typename H, typename T, typename R>
Expand Down Expand Up @@ -296,7 +263,6 @@ namespace edm {
ESProxyIndex const* getTokenIndices_ = nullptr;
ESParentContext const* context_ = nullptr;
unsigned int transitionID_ = std::numeric_limits<unsigned int>::max();
bool requireTokens_ = false;
};

class EventSetupRecordGeneric : public EventSetupRecord {
Expand All @@ -305,9 +271,8 @@ namespace edm {
unsigned int iTransitionID,
ESProxyIndex const* getTokenIndices,
EventSetupImpl const* eventSetupImpl,
ESParentContext const* context,
bool requireTokens = false) {
setImpl(iImpl, iTransitionID, getTokenIndices, eventSetupImpl, context, requireTokens);
ESParentContext const* context) {
setImpl(iImpl, iTransitionID, getTokenIndices, eventSetupImpl, context);
}

EventSetupRecordKey key() const final { return impl()->key(); }
Expand Down
12 changes: 4 additions & 8 deletions FWCore/Framework/interface/stream/EDAnalyzerAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::BeginRun),
this->consumer()->esGetTokenIndices(Transition::BeginRun),
pc,
false};
pc};
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 @@ -178,8 +177,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::EndRun),
this->consumer()->esGetTokenIndices(Transition::EndRun),
pc,
false};
pc};
MyGlobalRunSummary::globalEndRun(r, c, &rc, m_runSummaries[ri].get());
MyGlobalRun::endRun(r, c, &rc);
}
Expand All @@ -198,8 +196,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::BeginLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::BeginLuminosityBlock),
pc,
false};
pc};
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 @@ -218,8 +215,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::EndLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::EndLuminosityBlock),
pc,
false};
pc};
MyGlobalLuminosityBlockSummary::globalEndLuminosityBlock(lb, c, &lc, m_lumiSummaries[li].get());
MyGlobalLuminosityBlock::endLuminosityBlock(lb, c, &lc);
}
Expand Down
12 changes: 4 additions & 8 deletions FWCore/Framework/interface/stream/ProducingModuleAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::BeginRun),
this->consumer()->esGetTokenIndices(Transition::BeginRun),
parentC,
false};
parentC};
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 @@ -199,8 +198,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::EndRun),
this->consumer()->esGetTokenIndices(Transition::EndRun),
parentC,
false};
parentC};
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 @@ -225,8 +223,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::BeginLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::BeginLuminosityBlock),
parentC,
false};
parentC};

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 @@ -252,8 +249,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::EndLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::EndLuminosityBlock),
parentC,
false};
parentC};
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
12 changes: 5 additions & 7 deletions FWCore/Framework/src/EDAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace edm {
EventSignalsSentry sentry(act, mcc);
ESParentContext parentC(mcc);
const EventSetup c{
info, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC, false};
info, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC};
this->analyze(e, c);
return true;
}
Expand All @@ -55,7 +55,7 @@ namespace edm {
r.setConsumer(this);
ESParentContext parentC(mcc);
const EventSetup c{
info, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC, false};
info, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC};
this->beginRun(r, c);
return true;
}
Expand All @@ -65,7 +65,7 @@ namespace edm {
r.setConsumer(this);
ESParentContext parentC(mcc);
const EventSetup c{
info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC, false};
info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC};
this->endRun(r, c);
return true;
}
Expand All @@ -77,8 +77,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::BeginLuminosityBlock),
esGetTokenIndices(Transition::BeginLuminosityBlock),
parentC,
false};
parentC};
this->beginLuminosityBlock(lb, c);
return true;
}
Expand All @@ -90,8 +89,7 @@ namespace edm {
const EventSetup c{info,
static_cast<unsigned int>(Transition::EndLuminosityBlock),
esGetTokenIndices(Transition::EndLuminosityBlock),
parentC,
false};
parentC};
this->endLuminosityBlock(lb, c);
return true;
}
Expand Down
21 changes: 8 additions & 13 deletions FWCore/Framework/src/EDFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ namespace edm {
ESParentContext parentC(mcc);
rc = this->filter(
e,
EventSetup{
info, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC, false});
EventSetup{info, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC});
commit_(e, &previousParentageId_);
return rc;
}
Expand All @@ -56,12 +55,10 @@ namespace edm {
r.setConsumer(this);
Run const& cnstR = r;
ESParentContext parentC(mcc);
this->beginRun(cnstR,
EventSetup{info,
static_cast<unsigned int>(Transition::BeginRun),
esGetTokenIndices(Transition::BeginRun),
parentC,
false});
this->beginRun(
cnstR,
EventSetup{
info, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC});
commit_(r);
return;
}
Expand All @@ -74,7 +71,7 @@ namespace edm {
this->endRun(
cnstR,
EventSetup{
info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC, false});
info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC});
commit_(r);
return;
}
Expand All @@ -88,8 +85,7 @@ namespace edm {
EventSetup{info,
static_cast<unsigned int>(Transition::BeginLuminosityBlock),
esGetTokenIndices(Transition::BeginLuminosityBlock),
parentC,
false});
parentC});
commit_(lb);
}

Expand All @@ -102,8 +98,7 @@ namespace edm {
EventSetup{info,
static_cast<unsigned int>(Transition::EndLuminosityBlock),
esGetTokenIndices(Transition::EndLuminosityBlock),
parentC,
false});
parentC});
commit_(lb);
return;
}
Expand Down
Loading