Skip to content

Commit d834701

Browse files
committed
Refactor consumes info for PathsAndConsumesOfModules
- moved complex logic for creating the internal data structures to the class itself - can no ask an ESProducer what is produces - provide a mechanism to get minimal information about what ES products are being consumed
1 parent 88ee799 commit d834701

37 files changed

+923
-450
lines changed

FWCore/Framework/interface/EDConsumerBase.h

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "FWCore/Framework/interface/HCTypeTag.h"
3838
#include "FWCore/Framework/interface/DataKey.h"
3939
#include "FWCore/Framework/interface/data_default_record_trait.h"
40+
#include "FWCore/Framework/interface/ModuleConsumesMinimalESInfo.h"
4041
#include "FWCore/ServiceRegistry/interface/ServiceRegistryfwd.h"
4142
#include "FWCore/Utilities/interface/BranchType.h"
4243
#include "FWCore/Utilities/interface/ESIndices.h"
@@ -114,20 +115,12 @@ namespace edm {
114115
typedef ProductLabels Labels;
115116
void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
116117

117-
void modulesWhoseProductsAreConsumed(std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modulesAll,
118-
ProductRegistry const& preg,
119-
std::map<std::string, ModuleDescription const*> const& labelsToDesc,
120-
std::string const& processName) const;
121-
122-
void esModulesWhoseProductsAreConsumed(
123-
std::array<std::vector<eventsetup::ComponentDescription const*>*, kNumberOfEventSetupTransitions>& esModules,
124-
eventsetup::ESRecordsToProductResolverIndices const&) const;
125-
126118
/// Convert "@currentProcess" in InputTag process names to the actual current process name.
127119
void convertCurrentProcessAlias(std::string const& processName);
128120

129121
std::vector<ModuleConsumesInfo> moduleConsumesInfos() const;
130-
std::vector<ModuleConsumesESInfo> moduleConsumesESInfos(eventsetup::ESRecordsToProductResolverIndices const&) const;
122+
///This can only be called before the end of beginJob (after that the underlying data has been deleted)
123+
std::vector<ModuleConsumesMinimalESInfo> moduleConsumesMinimalESInfos() const;
131124

132125
ESResolverIndex const* esGetTokenIndices(edm::Transition iTrans) const {
133126
if (iTrans < edm::Transition::NumberOfEventSetupTransitions) {
@@ -232,6 +225,20 @@ namespace edm {
232225
return ESGetTokenGeneric(static_cast<unsigned int>(Tr), index, iRecord.type());
233226
}
234227

228+
/**The passed functor must take the following signature
229+
* F( ModuleConsumesInfo const& )
230+
* The functor will be called for each consumed EDProduct registered for the module
231+
*/
232+
template <typename F>
233+
void consumedProducts(F&& iFunc) const;
234+
235+
/**The passed functor must take the following signature
236+
* F(edm::ModuleConsumesMinimalESInfo const& )
237+
* The functor will be called for each consumed ESProduct registered for the module
238+
*/
239+
template <typename F>
240+
void consumedESProducts(F&& iFunct) const;
241+
235242
private:
236243
virtual void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const&);
237244
virtual void registerLateConsumes(eventsetup::ESRecordsToProductResolverIndices const&) {}
@@ -326,6 +333,47 @@ namespace edm {
326333
bool containsCurrentProcessAlias_;
327334
};
328335

336+
template <typename F>
337+
void EDConsumerBase::consumedProducts(F&& iFunc) const {
338+
auto itKind = m_tokenInfo.begin<kKind>();
339+
auto itLabels = m_tokenInfo.begin<kLabels>();
340+
auto itAlways = m_tokenInfo.begin<kAlwaysGets>();
341+
for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
342+
++itInfo, ++itKind, ++itLabels, ++itAlways) {
343+
auto labels = *itLabels;
344+
unsigned int start = labels.m_startOfModuleLabel;
345+
auto module = &(m_tokenLabels[start]);
346+
auto productInstance = module + labels.m_deltaToProductInstance;
347+
auto process = module + labels.m_deltaToProcessName;
348+
349+
iFunc(ModuleConsumesInfo(itInfo->m_type,
350+
module,
351+
productInstance,
352+
process,
353+
itInfo->m_branchType,
354+
*itKind,
355+
*itAlways,
356+
itInfo->m_index.skipCurrentProcess()));
357+
}
358+
}
359+
360+
template <typename F>
361+
void EDConsumerBase::consumedESProducts(F&& iFunc) const {
362+
unsigned int index = 0;
363+
auto itResolverIndex = esTokenLookupInfoContainer().begin<kESResolverIndex>();
364+
for (auto it = esTokenLookupInfoContainer().begin<kESLookupInfo>();
365+
it != esTokenLookupInfoContainer().end<kESLookupInfo>();
366+
++it, ++index, ++itResolverIndex) {
367+
//NOTE: memory for it->m_key is passed on to call via the ModuleConsumesMinimalESInfo constructor
368+
// this avoids a copy and avoids code later in the call chain accidently using deleted memory
369+
iFunc(ModuleConsumesMinimalESInfo(static_cast<Transition>(consumesIndexConverter()[index].first),
370+
it->m_record,
371+
it->m_key,
372+
&(m_tokenLabels[it->m_startOfComponentName]),
373+
*itResolverIndex));
374+
}
375+
}
376+
329377
template <Transition TR>
330378
class EDConsumerBaseESAdaptor {
331379
public:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef FWCore_Framework_ESModuleConsumesMinimalInfo_h
2+
#define FWCore_Framework_ESModuleConsumesMinimalInfo_h
3+
4+
// -*- C++ -*-
5+
// Package: FWCore/Framework
6+
// Class : ESModuleConsumesMinimalInfo
7+
// Minimal information about the consumes call for an EventSetup product by an ESModule
8+
9+
#include "FWCore/Utilities/interface/ESIndices.h"
10+
#include "FWCore/Framework/interface/EventSetupRecordKey.h"
11+
#include "FWCore/Framework/interface/DataKey.h"
12+
#include <string_view>
13+
14+
namespace edm::eventsetup {
15+
struct ESModuleConsumesMinimalInfo {
16+
ESModuleConsumesMinimalInfo(unsigned int iProduceMethodID,
17+
eventsetup::EventSetupRecordKey const& iRecord,
18+
eventsetup::DataKey const& iDataKey,
19+
std::string_view iComponentLabel)
20+
: recordForDataKey_(iRecord),
21+
dataKey_(iDataKey.type(), iDataKey.name(), eventsetup::DataKey::DoNotCopyMemory()),
22+
componentLabel_(iComponentLabel),
23+
produceMethodID_(iProduceMethodID) {}
24+
ESModuleConsumesMinimalInfo() = default;
25+
ESModuleConsumesMinimalInfo(ESModuleConsumesMinimalInfo&&) = default;
26+
ESModuleConsumesMinimalInfo& operator=(ESModuleConsumesMinimalInfo&&) = default;
27+
28+
// avoid accidentally copying data key as the strings would be copied instead of shared
29+
ESModuleConsumesMinimalInfo(ESModuleConsumesMinimalInfo const&) = delete;
30+
ESModuleConsumesMinimalInfo& operator=(ESModuleConsumesMinimalInfo const&) = delete;
31+
32+
eventsetup::EventSetupRecordKey recordForDataKey_;
33+
eventsetup::DataKey dataKey_;
34+
std::string_view componentLabel_;
35+
unsigned int produceMethodID_ = 0;
36+
};
37+
} // namespace edm::eventsetup
38+
#endif // FWCore_Framework_ESModuleConsumesMinimalInfo_h
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef FWCore_Framework_ESModuleProducesInfo_h
2+
#define FWCore_Framework_ESModuleProducesInfo_h
3+
// -*- C++ -*-
4+
5+
// Package: Framework
6+
// Class : ESModuleProducesInfo
7+
//
8+
// Description: Contains information about which products
9+
// a module declares it will produce from the EventSetup.
10+
11+
#include "FWCore/Framework/interface/DataKey.h"
12+
#include "FWCore/Framework/interface/EventSetupRecordKey.h"
13+
namespace edm::eventsetup {
14+
class ESModuleProducesInfo {
15+
public:
16+
ESModuleProducesInfo(EventSetupRecordKey const& iRecord, DataKey const& iDataKey, unsigned int iProduceMethodID)
17+
: record_(iRecord), dataKey_(iDataKey), produceMethodID_(iProduceMethodID) {}
18+
19+
EventSetupRecordKey const& record() const { return record_; }
20+
DataKey const& dataKey() const { return dataKey_; }
21+
unsigned int produceMethodID() const { return produceMethodID_; }
22+
23+
private:
24+
EventSetupRecordKey record_;
25+
DataKey dataKey_;
26+
unsigned int produceMethodID_;
27+
};
28+
} // namespace edm::eventsetup
29+
#endif

FWCore/Framework/interface/ESProducer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ namespace edm {
9595
namespace eventsetup {
9696
struct ComponentDescription;
9797
class ESRecordsToProductResolverIndices;
98+
class ESModuleConsumesMinimalInfo;
9899

99100
//used by ESProducer to create the proper Decorator based on the
100101
// argument type passed. The default it to just 'pass through'
@@ -158,12 +159,14 @@ namespace edm {
158159

159160
SerialTaskQueueChain& queue() { return acquirer_.serialQueueChain(); }
160161

161-
void esModulesWhoseProductsAreConsumed(std::vector<eventsetup::ComponentDescription const*>& esModules,
162-
eventsetup::ESRecordsToProductResolverIndices const&) const;
163-
164162
std::vector<std::vector<ESModuleConsumesInfo>> esModuleConsumesInfos(
165163
eventsetup::ESRecordsToProductResolverIndices const&) const;
166164

165+
/** Returns a vector of ESModuleConsumesMinimalInfo.
166+
Each entry contains minimal information about the products that a method consumes.
167+
*/
168+
std::vector<eventsetup::ESModuleConsumesMinimalInfo> esModuleConsumesMinimalInfos() const;
169+
167170
protected:
168171
/** Specify the names of the shared resources used by this ESProducer */
169172
void usesResources(std::vector<std::string> const&);

FWCore/Framework/interface/ESProductResolverArgumentFactoryTemplate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ namespace edm {
6565
return DataKey(DataKey::makeTypeTag<typename ResolverType::ValueType>(), iName.c_str());
6666
}
6767

68+
unsigned int produceMethodID() const override { return callback_->second->produceMethodID(); }
69+
6870
private:
6971
std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackType>>> callback_;
7072
};

FWCore/Framework/interface/ESProductResolverFactoryBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ namespace edm {
4040
virtual std::unique_ptr<ESProductResolver> makeResolver(unsigned int iovIndex) = 0;
4141

4242
virtual DataKey makeKey(const std::string& iName) const = 0;
43+
44+
virtual unsigned int produceMethodID() const = 0;
4345
};
4446
} // namespace eventsetup
4547
} // namespace edm

FWCore/Framework/interface/ESProductResolverFactoryProducer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ namespace edm {
8383

8484
~ESProductResolverFactoryProducer() noexcept(false) override;
8585

86+
std::vector<eventsetup::ESModuleProducesInfo> producesInfo() const override;
87+
8688
protected:
8789
using EventSetupRecordKey = eventsetup::EventSetupRecordKey;
8890

FWCore/Framework/interface/ESProductResolverProvider.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace edm {
6060
namespace eventsetup {
6161
class ESProductResolver;
6262
class ESRecordsToProductResolverIndices;
63+
class ESModuleProducesInfo;
6364

6465
class ESProductResolverProvider {
6566
public:
@@ -161,6 +162,10 @@ namespace edm {
161162
void fillRecordsNotAllowingConcurrentIOVs(std::set<EventSetupRecordKey>& recordsNotAllowingConcurrentIOVs) const {
162163
productResolverContainer_.fillRecordsNotAllowingConcurrentIOVs(recordsNotAllowingConcurrentIOVs);
163164
}
165+
/// @brief Provides information about each product that this module produces.
166+
/// If the value of produceMethodID is same for different infos it means they are produced by the same call.
167+
/// @return the vector of ESModuleProducesInfo objects, one for each product produced by this module.
168+
virtual std::vector<ESModuleProducesInfo> producesInfo() const = 0;
164169

165170
virtual void initConcurrentIOVs(EventSetupRecordKey const& key, unsigned int nConcurrentIOVs) {}
166171

FWCore/Framework/interface/ESTagGetter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
Description: Used with mayConsume option of ESConsumesCollector
1111
1212
Usage:
13-
<usage>
13+
This contains a cache of data about all Resolvers which are
14+
associated with data produces which are in the Record and which
15+
are of the proper type.
1416
1517
*/
1618
//
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef FWCore_Framework_ModuleConsumesMinimalESInfo_h
2+
#define FWCore_Framework_ModuleConsumesMinimalESInfo_h
3+
4+
// -*- C++ -*-
5+
// Package: FWCore/Framework
6+
// Class : ModuleConsumesMinimalESInfo
7+
// Minimal information about the consumes call for an EventSetup product
8+
// requested from an ED module
9+
10+
#include "FWCore/Utilities/interface/Transition.h"
11+
#include "FWCore/Utilities/interface/ESIndices.h"
12+
#include "FWCore/Framework/interface/EventSetupRecordKey.h"
13+
#include "FWCore/Framework/interface/DataKey.h"
14+
#include <string_view>
15+
16+
namespace edm {
17+
struct ModuleConsumesMinimalESInfo {
18+
ModuleConsumesMinimalESInfo(Transition iTransition,
19+
eventsetup::EventSetupRecordKey const& iRecord,
20+
eventsetup::DataKey const& iDataKey,
21+
std::string_view iComponentLabel,
22+
ESResolverIndex iIndex)
23+
: transition_(iTransition),
24+
record_(iRecord),
25+
dataKey_(iDataKey.type(), iDataKey.name(), eventsetup::DataKey::DoNotCopyMemory()),
26+
componentLabel_(iComponentLabel) {}
27+
ModuleConsumesMinimalESInfo() = default;
28+
ModuleConsumesMinimalESInfo(ModuleConsumesMinimalESInfo&&) = default;
29+
ModuleConsumesMinimalESInfo& operator=(ModuleConsumesMinimalESInfo&&) = default;
30+
31+
//want to avoid accidently copying dataKey_
32+
ModuleConsumesMinimalESInfo(ModuleConsumesMinimalESInfo const&) = delete;
33+
ModuleConsumesMinimalESInfo& operator=(ModuleConsumesMinimalESInfo const&) = delete;
34+
35+
edm::Transition transition_;
36+
eventsetup::EventSetupRecordKey record_;
37+
eventsetup::DataKey dataKey_;
38+
std::string_view componentLabel_;
39+
};
40+
} // namespace edm
41+
#endif // FWCore_Framework_ModuleConsumesMinimalESInfo_h

0 commit comments

Comments
 (0)