-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Refactor PathsAndConsumesOfModules #47937
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
base: master
Are you sure you want to change the base?
Changes from all commits
d834701
bcf17d7
f1d9dc9
cbba1ae
c63aa5b
f488fec
fd2c767
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#include "CondCore/ESSources/interface/ProductResolver.h" | ||
|
||
#include "CondCore/CondDB/interface/PayloadProxy.h" | ||
#include "FWCore/Framework/interface/ESModuleProducesInfo.h" | ||
#include "FWCore/Catalog/interface/SiteLocalConfig.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
|
@@ -648,6 +649,23 @@ edm::eventsetup::ESProductResolverProvider::KeyedResolversVector CondDBESSource: | |
return keyedResolversVector; | ||
} | ||
|
||
std::vector<edm::eventsetup::ESModuleProducesInfo> CondDBESSource::producesInfo() const { | ||
std::vector<edm::eventsetup::ESModuleProducesInfo> returnValue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about returnValue.reserve(m_resolvers.size()); ? |
||
returnValue.reserve(m_resolvers.size()); | ||
|
||
for (auto const& recToResolver : m_resolvers) { | ||
unsigned int index = returnValue.size(); | ||
|
||
EventSetupRecordKey rec{edm::eventsetup::TypeTag::findType(recToResolver.first)}; | ||
|
||
edm::eventsetup::TypeTag type = recToResolver.second->type(); | ||
DataKey key(type, edm::eventsetup::IdTags(recToResolver.second->label().c_str())); | ||
returnValue.emplace_back(rec, key, index); | ||
} | ||
|
||
return returnValue; | ||
} | ||
|
||
void CondDBESSource::initConcurrentIOVs(const EventSetupRecordKey& key, unsigned int nConcurrentIOVs) { | ||
std::string recordname = key.name(); | ||
ResolverMap::const_iterator b = m_resolvers.lower_bound(recordname); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,9 @@ | |
#include "FWCore/Framework/interface/HCTypeTag.h" | ||
#include "FWCore/Framework/interface/DataKey.h" | ||
#include "FWCore/Framework/interface/data_default_record_trait.h" | ||
#include "FWCore/Framework/interface/ModuleConsumesMinimalESInfo.h" | ||
#include "FWCore/ServiceRegistry/interface/ServiceRegistryfwd.h" | ||
#include "FWCore/ServiceRegistry/interface/ModuleConsumesInfo.h" | ||
#include "FWCore/Utilities/interface/BranchType.h" | ||
#include "FWCore/Utilities/interface/ESIndices.h" | ||
#include "FWCore/Utilities/interface/TypeID.h" | ||
|
@@ -114,20 +116,12 @@ namespace edm { | |
typedef ProductLabels Labels; | ||
void labelsForToken(EDGetToken iToken, Labels& oLabels) const; | ||
|
||
void modulesWhoseProductsAreConsumed(std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modulesAll, | ||
ProductRegistry const& preg, | ||
std::map<std::string, ModuleDescription const*> const& labelsToDesc, | ||
std::string const& processName) const; | ||
|
||
void esModulesWhoseProductsAreConsumed( | ||
std::array<std::vector<eventsetup::ComponentDescription const*>*, kNumberOfEventSetupTransitions>& esModules, | ||
eventsetup::ESRecordsToProductResolverIndices const&) const; | ||
|
||
/// Convert "@currentProcess" in InputTag process names to the actual current process name. | ||
void convertCurrentProcessAlias(std::string const& processName); | ||
|
||
std::vector<ModuleConsumesInfo> moduleConsumesInfos() const; | ||
std::vector<ModuleConsumesESInfo> moduleConsumesESInfos(eventsetup::ESRecordsToProductResolverIndices const&) const; | ||
///This can only be called before the end of beginJob (after that the underlying data has been deleted) | ||
std::vector<ModuleConsumesMinimalESInfo> moduleConsumesMinimalESInfos() const; | ||
Comment on lines
+123
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment here if the returned |
||
|
||
ESResolverIndex const* esGetTokenIndices(edm::Transition iTrans) const { | ||
if (iTrans < edm::Transition::NumberOfEventSetupTransitions) { | ||
|
@@ -232,6 +226,20 @@ namespace edm { | |
return ESGetTokenGeneric(static_cast<unsigned int>(Tr), index, iRecord.type()); | ||
} | ||
|
||
/**The passed functor must take the following signature | ||
* F( ModuleConsumesInfo const& ) | ||
* The functor will be called for each consumed EDProduct registered for the module | ||
*/ | ||
template <typename F> | ||
void consumedProducts(F&& iFunc) const; | ||
|
||
/**The passed functor must take the following signature | ||
* F(edm::ModuleConsumesMinimalESInfo const& ) | ||
* The functor will be called for each consumed ESProduct registered for the module | ||
*/ | ||
template <typename F> | ||
void consumedESProducts(F&& iFunct) const; | ||
|
||
private: | ||
virtual void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const&); | ||
virtual void registerLateConsumes(eventsetup::ESRecordsToProductResolverIndices const&) {} | ||
|
@@ -326,6 +334,47 @@ namespace edm { | |
bool containsCurrentProcessAlias_; | ||
}; | ||
|
||
template <typename F> | ||
void EDConsumerBase::consumedProducts(F&& iFunc) const { | ||
auto itKind = m_tokenInfo.begin<kKind>(); | ||
auto itLabels = m_tokenInfo.begin<kLabels>(); | ||
auto itAlways = m_tokenInfo.begin<kAlwaysGets>(); | ||
for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd; | ||
++itInfo, ++itKind, ++itLabels, ++itAlways) { | ||
auto labels = *itLabels; | ||
unsigned int start = labels.m_startOfModuleLabel; | ||
auto module = &(m_tokenLabels[start]); | ||
auto productInstance = module + labels.m_deltaToProductInstance; | ||
auto process = module + labels.m_deltaToProcessName; | ||
|
||
iFunc(ModuleConsumesInfo(itInfo->m_type, | ||
module, | ||
productInstance, | ||
process, | ||
itInfo->m_branchType, | ||
*itKind, | ||
*itAlways, | ||
itInfo->m_index.skipCurrentProcess())); | ||
} | ||
} | ||
|
||
template <typename F> | ||
void EDConsumerBase::consumedESProducts(F&& iFunc) const { | ||
unsigned int index = 0; | ||
auto itResolverIndex = esTokenLookupInfoContainer().begin<kESResolverIndex>(); | ||
for (auto it = esTokenLookupInfoContainer().begin<kESLookupInfo>(); | ||
it != esTokenLookupInfoContainer().end<kESLookupInfo>(); | ||
++it, ++index, ++itResolverIndex) { | ||
//NOTE: memory for it->m_key is passed on to call via the ModuleConsumesMinimalESInfo constructor | ||
// this avoids a copy and avoids code later in the call chain accidently using deleted memory | ||
iFunc(ModuleConsumesMinimalESInfo(static_cast<Transition>(consumesIndexConverter()[index].first), | ||
it->m_record, | ||
it->m_key, | ||
&(m_tokenLabels[it->m_startOfComponentName]), | ||
*itResolverIndex)); | ||
} | ||
} | ||
|
||
template <Transition TR> | ||
class EDConsumerBaseESAdaptor { | ||
public: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef FWCore_Framework_ESModuleConsumesMinimalInfo_h | ||
#define FWCore_Framework_ESModuleConsumesMinimalInfo_h | ||
|
||
// -*- C++ -*- | ||
// Package: FWCore/Framework | ||
// Class : ESModuleConsumesMinimalInfo | ||
// Minimal information about the consumes call for an EventSetup product by an ESModule | ||
|
||
#include "FWCore/Utilities/interface/ESIndices.h" | ||
#include "FWCore/Framework/interface/EventSetupRecordKey.h" | ||
#include "FWCore/Framework/interface/DataKey.h" | ||
#include <string_view> | ||
|
||
namespace edm::eventsetup { | ||
struct ESModuleConsumesMinimalInfo { | ||
ESModuleConsumesMinimalInfo(unsigned int iProduceMethodID, | ||
eventsetup::EventSetupRecordKey const& iRecord, | ||
eventsetup::DataKey const& iDataKey, | ||
std::string_view iComponentLabel) | ||
: recordForDataKey_(iRecord), | ||
dataKey_(iDataKey.type(), iDataKey.name(), eventsetup::DataKey::DoNotCopyMemory()), | ||
componentLabel_(iComponentLabel), | ||
produceMethodID_(iProduceMethodID) {} | ||
ESModuleConsumesMinimalInfo() = default; | ||
ESModuleConsumesMinimalInfo(ESModuleConsumesMinimalInfo&&) = default; | ||
ESModuleConsumesMinimalInfo& operator=(ESModuleConsumesMinimalInfo&&) = default; | ||
|
||
// avoid accidentally copying data key as the strings would be copied instead of shared | ||
ESModuleConsumesMinimalInfo(ESModuleConsumesMinimalInfo const&) = delete; | ||
ESModuleConsumesMinimalInfo& operator=(ESModuleConsumesMinimalInfo const&) = delete; | ||
|
||
eventsetup::EventSetupRecordKey recordForDataKey_; | ||
eventsetup::DataKey dataKey_; | ||
std::string_view componentLabel_; | ||
unsigned int produceMethodID_ = 0; | ||
}; | ||
} // namespace edm::eventsetup | ||
#endif // FWCore_Framework_ESModuleConsumesMinimalInfo_h |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef FWCore_Framework_ESModuleProducesInfo_h | ||
#define FWCore_Framework_ESModuleProducesInfo_h | ||
// -*- C++ -*- | ||
|
||
// Package: Framework | ||
// Class : ESModuleProducesInfo | ||
// | ||
// Description: Contains information about which products | ||
// a module declares it will produce from the EventSetup. | ||
|
||
#include "FWCore/Framework/interface/DataKey.h" | ||
#include "FWCore/Framework/interface/EventSetupRecordKey.h" | ||
namespace edm::eventsetup { | ||
class ESModuleProducesInfo { | ||
public: | ||
ESModuleProducesInfo(EventSetupRecordKey const& iRecord, DataKey const& iDataKey, unsigned int iProduceMethodID) | ||
: record_(iRecord), dataKey_(iDataKey), produceMethodID_(iProduceMethodID) {} | ||
|
||
EventSetupRecordKey const& record() const { return record_; } | ||
DataKey const& dataKey() const { return dataKey_; } | ||
unsigned int produceMethodID() const { return produceMethodID_; } | ||
|
||
private: | ||
EventSetupRecordKey record_; | ||
DataKey dataKey_; | ||
unsigned int produceMethodID_; | ||
}; | ||
} // namespace edm::eventsetup | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would
returnValue.reserve()
be worth it? E.g. withrecords_.size()
? (unlikely to be exact, but maybe would avoid a number of small reallocations)