From 5538699f547f28bbb8ea686a2662017a232d3251 Mon Sep 17 00:00:00 2001 From: Matti Kortelainen Date: Tue, 5 Oct 2021 19:48:56 +0200 Subject: [PATCH] Throw exception from deprecated EventSetupRecord::get() Remove all tests of the deprecated API for which tests for the new API exist, and migrate the rest. --- FWCore/Framework/interface/Callback.h | 4 +- .../Framework/interface/DataProxyTemplate.h | 2 +- .../interface/DependentRecordImplementation.h | 14 +- .../Framework/interface/ESConsumesCollector.h | 4 + FWCore/Framework/interface/EventSetup.h | 19 +- FWCore/Framework/interface/EventSetupRecord.h | 49 +-- .../interface/stream/EDAnalyzerAdaptor.h | 12 +- .../interface/stream/ProducingModuleAdaptor.h | 12 +- FWCore/Framework/src/EDAnalyzer.cc | 12 +- FWCore/Framework/src/EDFilter.cc | 21 +- FWCore/Framework/src/EDLooperBase.cc | 21 +- FWCore/Framework/src/EDProducer.cc | 12 +- FWCore/Framework/src/EventSetupRecord.cc | 4 +- FWCore/Framework/src/global/EDAnalyzerBase.cc | 32 +- FWCore/Framework/src/global/EDFilterBase.cc | 34 +- FWCore/Framework/src/global/EDProducerBase.cc | 39 +- .../Framework/src/limited/EDAnalyzerBase.cc | 32 +- FWCore/Framework/src/limited/EDFilterBase.cc | 32 +- .../Framework/src/limited/EDProducerBase.cc | 32 +- FWCore/Framework/src/one/EDAnalyzerBase.cc | 17 +- FWCore/Framework/src/one/EDFilterBase.cc | 17 +- FWCore/Framework/src/one/EDProducerBase.cc | 17 +- .../src/stream/EDAnalyzerAdaptorBase.cc | 17 +- .../src/stream/EDFilterAdaptorBase.cc | 4 +- .../src/stream/EDProducerAdaptorBase.cc | 4 +- .../src/stream/ProducingModuleAdaptorBase.cc | 20 +- FWCore/Framework/test/callback_t.cppunit.cc | 3 +- .../test/dependentrecord_t.cppunit.cc | 114 +++--- FWCore/Framework/test/esproducer_t.cppunit.cc | 145 +++++-- FWCore/Framework/test/eventsetup_t.cppunit.cc | 365 +++++++----------- .../test/eventsetuprecord_t.cppunit.cc | 144 +++---- FWCore/Framework/test/fullchain_t.cppunit.cc | 41 +- .../test/run_test_1_thread_es_prefetching.sh | 2 - .../test/stubs/TestESDummyDataAnalyzer.cc | 24 -- .../test_1_thread_es_mixed_prefetch_cfg.py | 30 -- .../test/test_1_thread_es_no_prefetch_cfg.py | 27 -- 36 files changed, 537 insertions(+), 841 deletions(-) delete mode 100644 FWCore/Framework/test/test_1_thread_es_mixed_prefetch_cfg.py delete mode 100644 FWCore/Framework/test/test_1_thread_es_no_prefetch_cfg.py diff --git a/FWCore/Framework/interface/Callback.h b/FWCore/Framework/interface/Callback.h index a584e3d9046f9..3c7751419e6d0 100644 --- a/FWCore/Framework/interface/Callback.h +++ b/FWCore/Framework/interface/Callback.h @@ -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(postMayGetProxies_); } @@ -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 { diff --git a/FWCore/Framework/interface/DataProxyTemplate.h b/FWCore/Framework/interface/DataProxyTemplate.h index c930ece872f69..96666a98fd662 100644 --- a/FWCore/Framework/interface/DataProxyTemplate.h +++ b/FWCore/Framework/interface/DataProxyTemplate.h @@ -72,7 +72,7 @@ namespace edm { iTask.group()->run([this, &iRecord, iKey, iEventSetupImpl, iToken, iParent]() { try { RecordT rec; - rec.setImpl(&iRecord, std::numeric_limits::max(), nullptr, iEventSetupImpl, &iParent, true); + rec.setImpl(&iRecord, std::numeric_limits::max(), nullptr, iEventSetupImpl, &iParent); ServiceRegistry::Operate operate(iToken); this->make(rec, iKey); } catch (...) { diff --git a/FWCore/Framework/interface/DependentRecordImplementation.h b/FWCore/Framework/interface/DependentRecordImplementation.h index e9ba823a16417..0a0b7db2d5446 100644 --- a/FWCore/Framework/interface/DependentRecordImplementation.h +++ b/FWCore/Framework/interface/DependentRecordImplementation.h @@ -53,11 +53,8 @@ namespace edm { (list_type::template contains()), "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(); } catch (cms::Exception& e) { std::ostringstream sstrm; @@ -73,11 +70,8 @@ namespace edm { static_assert( (list_type::template contains()), "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(); } diff --git a/FWCore/Framework/interface/ESConsumesCollector.h b/FWCore/Framework/interface/ESConsumesCollector.h index 2cac15a7fc198..745f498bfbe45 100644 --- a/FWCore/Framework/interface/ESConsumesCollector.h +++ b/FWCore/Framework/interface/ESConsumesCollector.h @@ -38,6 +38,9 @@ #include #include + +class testEventsetupRecord; + namespace edm { class ESConsumesCollectorAdaptor; class ESConsumesCollectorWithTagAdaptor; @@ -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) {} diff --git a/FWCore/Framework/interface/EventSetup.h b/FWCore/Framework/interface/EventSetup.h index 7b2e4b902e7b4..d4f0ac7034b2b 100644 --- a/FWCore/Framework/interface/EventSetup.h +++ b/FWCore/Framework/interface/EventSetup.h @@ -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; @@ -99,7 +93,7 @@ namespace edm { throw eventsetup::NoRecordException(recordDoesExist(m_setup, eventsetup::EventSetupRecordKey::makeKey())); } 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; } @@ -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; @@ -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. diff --git a/FWCore/Framework/interface/EventSetupRecord.h b/FWCore/Framework/interface/EventSetupRecord.h index d2153b4455aa2..a10f616339104 100644 --- a/FWCore/Framework/interface/EventSetupRecord.h +++ b/FWCore/Framework/interface/EventSetupRecord.h @@ -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 @@ -125,23 +123,8 @@ namespace edm { template CMS_DEPRECATED bool get(ESInputTag const& iTag, HolderT& iHolder) const { - if UNLIKELY (requireTokens_) { - throwCalledGetWithoutToken(heterocontainer::className(), iTag.data().c_str()); - } - typename HolderT::value_type const* value = nullptr; - ComponentDescription const* desc = nullptr; - std::shared_ptr 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(), iTag.data().c_str()); + return false; } ///returns false if no data available for key @@ -241,27 +224,11 @@ namespace edm { unsigned int transitionID() const { return transitionID_; } - bool requireTokens() const { return requireTokens_; } - private: template bool deprecated_get(char const* iName, HolderT& iHolder) const { - if UNLIKELY (requireTokens_) { - throwCalledGetWithoutToken(heterocontainer::className(), iName); - } - typename HolderT::value_type const* value = nullptr; - ComponentDescription const* desc = nullptr; - std::shared_ptr 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(), iName); + return false; } template