Skip to content

Commit a69a71c

Browse files
authored
Merge pull request #47533 from Dr15Jones/limitAddingToProductRegistry
Compartmentalize how ProductRegistry is filled
2 parents e4a8f9a + e2915ba commit a69a71c

File tree

72 files changed

+474
-407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+474
-407
lines changed

DQM/SiStripMonitorHardware/src/SiStripSpyEventMatcher.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "FWCore/Sources/interface/VectorInputSource.h"
77
#include "FWCore/Sources/interface/VectorInputSourceDescription.h"
88
#include "FWCore/Sources/interface/VectorInputSourceFactory.h"
9-
#include "FWCore/Framework/interface/SignallingProductRegistry.h"
9+
#include "DataFormats/Provenance/interface/ProductRegistry.h"
1010
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
1111
#include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
1212
#include "DataFormats/Common/interface/DetSetVector.h"
@@ -54,7 +54,7 @@ namespace sistrip {
5454
reorderedDigisTag_(config.getParameter<edm::InputTag>("SpyReorderedDigisTag")),
5555
virginRawDigisTag_(config.getParameter<edm::InputTag>("SpyVirginRawDigisTag")),
5656
counterDiffMax_(config.getParameter<uint32_t>("CounterDiffMaxAllowed")),
57-
productRegistry_(new edm::SignallingProductRegistry),
57+
productRegistry_(new edm::ProductRegistry),
5858
source_(constructSource(config.getParameter<edm::ParameterSet>("SpySource"))),
5959
// hardware information is not needed for the "overlay"
6060
processConfiguration_(std::make_unique<edm::ProcessConfiguration>(

DataFormats/Provenance/interface/ProductRegistry.h

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,29 @@
2929
#include <vector>
3030

3131
namespace edm {
32-
32+
class SignallingProductRegistryFiller;
3333
class ProductResolverIndexHelper;
3434
class TypeID;
3535

3636
class ProductRegistry {
3737
public:
38-
typedef std::map<BranchKey, ProductDescription> ProductList;
38+
friend class SignallingProductRegistryFiller;
3939

40-
ProductRegistry();
40+
typedef std::map<BranchKey, ProductDescription> ProductList;
4141

42+
ProductRegistry() = default;
43+
ProductRegistry(const ProductRegistry&) = default;
44+
ProductRegistry(ProductRegistry&&) = default;
45+
ProductRegistry& operator=(ProductRegistry&&) = default;
4246
// A constructor from the persistent data members from another product registry.
4347
// saves time by not copying the transient components.
4448
// The constructed registry will be frozen by default.
4549
explicit ProductRegistry(ProductList const& productList, bool toBeFrozen = true);
4650

47-
virtual ~ProductRegistry() {}
51+
~ProductRegistry() = default;
4852

4953
typedef std::map<BranchKey, ProductDescription const> ConstProductList;
5054

51-
void addProduct(ProductDescription const& productdesc, bool iFromListener = false);
52-
53-
void addLabelAlias(ProductDescription const& productdesc,
54-
std::string const& labelAlias,
55-
std::string const& instanceAlias);
56-
5755
void copyProduct(ProductDescription const& productdesc);
5856

5957
void setFrozen(bool initializeLookupInfo = true);
@@ -69,8 +67,6 @@ namespace edm {
6967
ProductDescription::MatchMode branchesMustMatch = ProductDescription::Permissive);
7068

7169
void updateFromInput(ProductList const& other);
72-
// triggers callbacks for modules watching registration
73-
void addFromInput(edm::ProductRegistry const&);
7470

7571
void updateFromInput(std::vector<ProductDescription> const& other);
7672

@@ -95,29 +91,13 @@ namespace edm {
9591
// colon-initialization list.
9692
std::vector<ProductDescription const*> allProductDescriptions() const;
9793

98-
//NOTE: this is not const since we only want items that have non-const access to this class to be
99-
// able to call this internal iteration
100-
// Called only for branches that are present (part of avoiding creating type information for dropped branches)
101-
template <typename T>
102-
void callForEachBranch(T const& iFunc) {
103-
//NOTE: If implementation changes from a map, need to check that iterators are still valid
104-
// after an insert with the new container, else need to copy the container and iterate over the copy
105-
for (ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(), itEntryEnd = productList_.end();
106-
itEntry != itEntryEnd;
107-
++itEntry) {
108-
if (itEntry->second.present()) {
109-
iFunc(itEntry->second);
110-
}
111-
}
112-
}
11394
ProductList::size_type size() const { return productList_.size(); }
11495

11596
void print(std::ostream& os) const;
11697

11798
bool anyProducts(BranchType const brType) const;
11899

119100
std::shared_ptr<ProductResolverIndexHelper const> productLookup(BranchType branchType) const;
120-
std::shared_ptr<ProductResolverIndexHelper> productLookup(BranchType branchType);
121101

122102
// returns the appropriate ProductResolverIndex else ProductResolverIndexInvalid if no BranchID is available
123103
ProductResolverIndex indexFrom(BranchID const& iID) const;
@@ -152,7 +132,7 @@ namespace edm {
152132
std::array<bool, NumBranchTypes> productProduced_;
153133
bool anyProductProduced_;
154134

155-
std::array<edm::propagate_const<std::shared_ptr<ProductResolverIndexHelper>>, NumBranchTypes> productLookups_;
135+
std::array<std::shared_ptr<const ProductResolverIndexHelper>, NumBranchTypes> productLookups_;
156136

157137
std::array<ProductResolverIndex, NumBranchTypes> nextIndexValues_;
158138

@@ -163,6 +143,30 @@ namespace edm {
163143
AliasToOriginalVector aliasToOriginal_;
164144
};
165145

146+
private:
147+
//The following three routines are only called by SignallingProductRegistryFiller
148+
void addProduct_(ProductDescription const& productdesc);
149+
150+
ProductDescription const& addLabelAlias_(ProductDescription const& productdesc,
151+
std::string const& labelAlias,
152+
std::string const& instanceAlias);
153+
154+
// triggers callbacks for modules watching registration
155+
template <typename F>
156+
void addFromInput_(edm::ProductRegistry const& iReg, F&& iCallback) {
157+
throwIfFrozen();
158+
for (auto const& prod : iReg.productList_) {
159+
ProductList::iterator iter = productList_.find(prod.first);
160+
if (iter == productList_.end()) {
161+
productList_.insert(std::make_pair(prod.first, prod.second));
162+
iCallback(prod.second);
163+
} else {
164+
assert(combinable(iter->second, prod.second));
165+
iter->second.merge(prod.second);
166+
}
167+
}
168+
}
169+
166170
private:
167171
void setProductProduced(BranchType branchType) {
168172
transient_.productProduced_[branchType] = true;
@@ -185,7 +189,6 @@ namespace edm {
185189

186190
void checkForDuplicateProcessName(ProductDescription const& desc, std::string const* processName) const;
187191

188-
virtual void addCalled(ProductDescription const&, bool iFromListener);
189192
void throwIfNotFrozen() const;
190193
void throwIfFrozen() const;
191194

DataFormats/Provenance/src/ProductRegistry.cc

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
namespace edm {
3131

32-
ProductRegistry::ProductRegistry() : productList_(), transient_() {}
33-
3432
ProductRegistry::Transients::Transients()
3533
: frozen_(false),
3634
productProduced_(),
@@ -65,7 +63,7 @@ namespace edm {
6563
freezeIt(toBeFrozen);
6664
}
6765

68-
void ProductRegistry::addProduct(ProductDescription const& productDesc, bool fromListener) {
66+
void ProductRegistry::addProduct_(ProductDescription const& productDesc) {
6967
assert(productDesc.produced());
7068
throwIfFrozen();
7169
std::pair<ProductList::iterator, bool> ret =
@@ -102,12 +100,11 @@ namespace edm {
102100
<< "descendants of those products.\n";
103101
}
104102
}
105-
addCalled(productDesc, fromListener);
106103
}
107104

108-
void ProductRegistry::addLabelAlias(ProductDescription const& productDesc,
109-
std::string const& labelAlias,
110-
std::string const& instanceAlias) {
105+
ProductDescription const& ProductRegistry::addLabelAlias_(ProductDescription const& productDesc,
106+
std::string const& labelAlias,
107+
std::string const& instanceAlias) {
111108
assert(productDesc.produced());
112109
assert(productDesc.branchID().isValid());
113110
throwIfFrozen();
@@ -116,7 +113,7 @@ namespace edm {
116113
assert(ret.second);
117114
transient_.aliasToOriginal_.emplace_back(
118115
PRODUCT_TYPE, productDesc.unwrappedTypeID(), labelAlias, instanceAlias, productDesc.moduleLabel());
119-
addCalled(bd, false);
116+
return ret.first->second;
120117
}
121118

122119
void ProductRegistry::copyProduct(ProductDescription const& productDesc) {
@@ -143,11 +140,7 @@ namespace edm {
143140
}
144141

145142
std::shared_ptr<ProductResolverIndexHelper const> ProductRegistry::productLookup(BranchType branchType) const {
146-
return get_underlying_safe(transient_.productLookups_[branchType]);
147-
}
148-
149-
std::shared_ptr<ProductResolverIndexHelper> ProductRegistry::productLookup(BranchType branchType) {
150-
return get_underlying_safe(transient_.productLookups_[branchType]);
143+
return transient_.productLookups_[branchType];
151144
}
152145

153146
void ProductRegistry::setFrozen(bool initializeLookupInfo) {
@@ -184,8 +177,6 @@ namespace edm {
184177
}
185178
}
186179

187-
void ProductRegistry::addCalled(ProductDescription const&, bool) {}
188-
189180
std::vector<std::string> ProductRegistry::allBranchNames() const {
190181
std::vector<std::string> result;
191182
result.reserve(productList().size());
@@ -218,20 +209,6 @@ namespace edm {
218209
}
219210
}
220211

221-
void ProductRegistry::addFromInput(edm::ProductRegistry const& other) {
222-
throwIfFrozen();
223-
for (auto const& prod : other.productList_) {
224-
ProductList::iterator iter = productList_.find(prod.first);
225-
if (iter == productList_.end()) {
226-
productList_.insert(std::make_pair(prod.first, prod.second));
227-
addCalled(prod.second, false);
228-
} else {
229-
assert(combinable(iter->second, prod.second));
230-
iter->second.merge(prod.second);
231-
}
232-
}
233-
}
234-
235212
void ProductRegistry::setUnscheduledProducts(std::set<std::string> const& unscheduledLabels) {
236213
throwIfFrozen();
237214

@@ -319,6 +296,11 @@ namespace edm {
319296

320297
transient_.branchIDToIndex_.clear();
321298

299+
std::array<std::shared_ptr<ProductResolverIndexHelper>, NumBranchTypes> new_productLookups{
300+
{std::make_shared<ProductResolverIndexHelper>(),
301+
std::make_shared<ProductResolverIndexHelper>(),
302+
std::make_shared<ProductResolverIndexHelper>(),
303+
std::make_shared<ProductResolverIndexHelper>()}};
322304
for (auto const& product : productList_) {
323305
auto const& desc = product.second;
324306

@@ -438,13 +420,12 @@ namespace edm {
438420
}
439421
}
440422
}
441-
ProductResolverIndex index = productLookup(desc.branchType())
442-
->insert(typeID,
443-
desc.moduleLabel().c_str(),
444-
desc.productInstanceName().c_str(),
445-
desc.processName().c_str(),
446-
containedTypeID,
447-
baseTypesOfContainedType);
423+
ProductResolverIndex index = new_productLookups[desc.branchType()]->insert(typeID,
424+
desc.moduleLabel().c_str(),
425+
desc.productInstanceName().c_str(),
426+
desc.processName().c_str(),
427+
containedTypeID,
428+
baseTypesOfContainedType);
448429

449430
transient_.branchIDToIndex_[desc.branchID()] = index;
450431
}
@@ -454,9 +435,12 @@ namespace edm {
454435
throwMissingDictionariesException(missingDictionaries, context, producedTypes, branchNamesForMissing);
455436
}
456437

457-
for (auto& iterProductLookup : transient_.productLookups_) {
438+
for (auto& iterProductLookup : new_productLookups) {
458439
iterProductLookup->setFrozen();
459440
}
441+
for (size_t i = 0; i < new_productLookups.size(); ++i) {
442+
transient_.productLookups_[i] = std::move(new_productLookups[i]);
443+
}
460444

461445
unsigned int indexIntoNextIndexValue = 0;
462446
for (auto const& iterProductLookup : transient_.productLookups_) {

FWCore/Framework/interface/EventProcessor.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ configured in the user's main() function, and is set running.
1818
#include "FWCore/Framework/interface/MergeableRunProductProcesses.h"
1919
#include "FWCore/Framework/interface/SharedResourcesAcquirer.h"
2020
#include "FWCore/Framework/interface/PrincipalCache.h"
21-
#include "FWCore/Framework/interface/SignallingProductRegistry.h"
21+
#include "FWCore/Framework/interface/SignallingProductRegistryFiller.h"
2222
#include "FWCore/Framework/interface/PreallocationConfiguration.h"
2323

2424
#include "FWCore/ParameterSet/interface/ParameterSet.h"
@@ -280,8 +280,7 @@ namespace edm {
280280

281281
void processEventWithLooper(EventPrincipal&, unsigned int iStreamIndex);
282282

283-
std::shared_ptr<SignallingProductRegistry const> preg() const { return get_underlying_safe(preg_); }
284-
std::shared_ptr<SignallingProductRegistry>& preg() { return get_underlying_safe(preg_); }
283+
std::shared_ptr<ProductRegistry const> preg() const { return get_underlying_safe(preg_); }
285284
std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {
286285
return get_underlying_safe(branchIDListHelper_);
287286
}
@@ -312,7 +311,7 @@ namespace edm {
312311
oneapi::tbb::task_group taskGroup_;
313312

314313
std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
315-
edm::propagate_const<std::shared_ptr<SignallingProductRegistry>> preg_;
314+
edm::propagate_const<std::shared_ptr<ProductRegistry>> preg_;
316315
edm::propagate_const<std::shared_ptr<BranchIDListHelper>> branchIDListHelper_;
317316
edm::propagate_const<std::shared_ptr<ProcessBlockHelper>> processBlockHelper_;
318317
edm::propagate_const<std::shared_ptr<ThinnedAssociationsHelper>> thinnedAssociationsHelper_;

FWCore/Framework/interface/GlobalSchedule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "FWCore/Framework/interface/WorkerManager.h"
1515
#include "FWCore/Framework/interface/maker/Worker.h"
1616
#include "FWCore/Framework/interface/WorkerRegistry.h"
17-
#include "FWCore/Framework/interface/SignallingProductRegistry.h"
17+
#include "FWCore/Framework/interface/SignallingProductRegistryFiller.h"
1818
#include "FWCore/MessageLogger/interface/ExceptionMessages.h"
1919
#include "FWCore/ServiceRegistry/interface/GlobalContext.h"
2020
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
@@ -60,7 +60,7 @@ namespace edm {
6060
std::shared_ptr<ModuleRegistry> modReg,
6161
std::vector<std::string> const& modulesToUse,
6262
ParameterSet& proc_pset,
63-
SignallingProductRegistry& pregistry,
63+
SignallingProductRegistryFiller& pregistry,
6464
PreallocationConfiguration const& prealloc,
6565
ExceptionToActionTable const& actions,
6666
std::shared_ptr<ActivityRegistry> areg,

FWCore/Framework/interface/InputSource.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace edm {
4444
class ParameterSetDescription;
4545
class ProcessContext;
4646
class ProcessHistoryRegistry;
47-
class SignallingProductRegistry;
4847
class StreamContext;
4948
class ModuleCallingContext;
5049
class SharedResourcesAcquirer;

FWCore/Framework/interface/ModuleChanger.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
namespace edm {
3232
class ParameterSet;
3333
class Schedule;
34-
class SignallingProductRegistry;
34+
class SignallingProductRegistryFiller;
3535

3636
class ModuleChanger {
3737
public:
38-
ModuleChanger(Schedule*, SignallingProductRegistry const* iReg, eventsetup::ESRecordsToProductResolverIndices);
38+
ModuleChanger(Schedule*,
39+
SignallingProductRegistryFiller const* iReg,
40+
eventsetup::ESRecordsToProductResolverIndices);
3941
ModuleChanger(const ModuleChanger&) = delete; // stop default
4042
const ModuleChanger& operator=(const ModuleChanger&) = delete; // stop default
4143
virtual ~ModuleChanger();
@@ -50,7 +52,7 @@ namespace edm {
5052
private:
5153
// ---------- member data --------------------------------
5254
edm::propagate_const<Schedule*> schedule_;
53-
SignallingProductRegistry const* registry_;
55+
SignallingProductRegistryFiller const* registry_;
5456
eventsetup::ESRecordsToProductResolverIndices indices_;
5557
};
5658
} // namespace edm

FWCore/Framework/interface/OutputModuleCore.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace edm {
5555
class PreallocationConfiguration;
5656
class ActivityRegistry;
5757
class ThinnedAssociationsHelper;
58-
class SignallingProductRegistry;
58+
class SignallingProductRegistryFiller;
5959

6060
template <typename T>
6161
class OutputModuleCommunicatorT;
@@ -214,7 +214,7 @@ namespace edm {
214214
/// Tell the OutputModule that is must end the current file.
215215
void doCloseFile();
216216

217-
void registerProductsAndCallbacks(OutputModuleCore const*, SignallingProductRegistry*);
217+
void registerProductsAndCallbacks(OutputModuleCore const*, SignallingProductRegistryFiller*);
218218

219219
bool needToRunSelection() const noexcept;
220220
std::vector<ProductResolverIndexAndSkipBit> productsUsedBySelection() const noexcept;

FWCore/Framework/interface/ProducerBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ EDProducts into an Event.
2222
namespace edm {
2323
class ModuleDescription;
2424
class ProducesCollector;
25-
class SignallingProductRegistry;
25+
class SignallingProductRegistryFiller;
2626
class Event;
2727
class LuminosityBlock;
2828
class ProcessBlock;
@@ -76,7 +76,7 @@ namespace edm {
7676
/// used by the fwk to register list of products
7777
std::function<void(ProductDescription const&)> registrationCallback() const;
7878

79-
void registerProducts(ProducerBase*, SignallingProductRegistry*, ModuleDescription const&);
79+
void registerProducts(ProducerBase*, SignallingProductRegistryFiller*, ModuleDescription const&);
8080

8181
using ProductRegistryHelper::recordProvenanceList;
8282
using ProductRegistryHelper::typeLabelList;

0 commit comments

Comments
 (0)