Skip to content

Commit a52b578

Browse files
committed
Sources now have independent ProductRegistry
Sources can now update their ProductRegistry without affecting the rest of the system. The system will pick up the changes when they are needed.
1 parent 78ffd9a commit a52b578

File tree

15 files changed

+56
-73
lines changed

15 files changed

+56
-73
lines changed

FWCore/Framework/interface/InputSource.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Some examples of InputSource subclasses are:
2020
#include "DataFormats/Provenance/interface/RunAuxiliary.h"
2121
#include "DataFormats/Provenance/interface/RunID.h"
2222
#include "DataFormats/Provenance/interface/Timestamp.h"
23+
#include "DataFormats/Provenance/interface/ProductRegistry.h"
2324
#include "FWCore/Common/interface/FWCoreCommonFwd.h"
2425
#include "FWCore/Framework/interface/Frameworkfwd.h"
2526
#include "FWCore/Framework/interface/ProcessingController.h"
@@ -43,7 +44,6 @@ namespace edm {
4344
class ParameterSetDescription;
4445
class ProcessContext;
4546
class ProcessHistoryRegistry;
46-
class ProductRegistry;
4747
class SignallingProductRegistry;
4848
class StreamContext;
4949
class ModuleCallingContext;
@@ -159,11 +159,11 @@ namespace edm {
159159
/// issue an event report
160160
void issueReports(EventID const& eventID, StreamID streamID);
161161

162-
/// Register any produced products
163-
virtual void registerProducts(SignallingProductRegistry&);
162+
/// Register any produced products into source's registry
163+
virtual void registerProducts();
164164

165165
/// Accessors for product registry
166-
std::shared_ptr<ProductRegistry const> productRegistry() const { return get_underlying_safe(productRegistry_); }
166+
ProductRegistry const& productRegistry() const { return productRegistry_; }
167167

168168
/// Accessors for process history registry.
169169
ProcessHistoryRegistry const& processHistoryRegistry() const { return *processHistoryRegistry_; }
@@ -198,9 +198,6 @@ namespace edm {
198198
/// Returns nullptr if no resource shared between the Source and a DelayedReader
199199
std::pair<SharedResourcesAcquirer*, std::recursive_mutex*> resourceSharedWithDelayedReader();
200200

201-
/// switch to a different ProductRegistry.
202-
void switchTo(std::shared_ptr<ProductRegistry> iOther) { productRegistry_ = iOther; }
203-
204201
/// Accessor for maximum number of events to be read.
205202
/// -1 is used for unlimited.
206203
int maxEvents() const { return maxEvents_; }
@@ -226,8 +223,8 @@ namespace edm {
226223
/// Accessor for global process identifier
227224
std::string const& processGUID() const { return processGUID_; }
228225

229-
/// Called by framework at beginning of job
230-
void doBeginJob();
226+
/// Called by framework at beginning of job. The argument is the full product registry
227+
void doBeginJob(edm::ProductRegistry const&);
231228

232229
/// Called by framework at end of job
233230
void doEndJob();
@@ -357,7 +354,7 @@ namespace edm {
357354
/// To set the current time, as seen by the input source
358355
void setTimestamp(Timestamp const& theTime) { time_ = theTime; }
359356

360-
ProductRegistry& productRegistryUpdate() { return *productRegistry_; }
357+
ProductRegistry& productRegistryUpdate() { return productRegistry_; }
361358
ProcessHistoryRegistry& processHistoryRegistryForUpdate() { return *processHistoryRegistry_; }
362359
ItemTypeInfo state() const { return state_; }
363360
void setRunAuxiliary(RunAuxiliary* rp) {
@@ -397,7 +394,7 @@ namespace edm {
397394
void decreaseRemainingEventsBy(int iSkipped);
398395

399396
///Begin protected makes it easier to do template programming
400-
virtual void beginJob();
397+
virtual void beginJob(edm::ProductRegistry const&);
401398

402399
private:
403400
bool eventLimitReached() const { return remainingEvents_ == 0; }
@@ -451,7 +448,7 @@ namespace edm {
451448
std::chrono::time_point<std::chrono::steady_clock> processingStart_;
452449
ProcessingMode processingMode_;
453450
ModuleDescription const moduleDescription_;
454-
edm::propagate_const<std::shared_ptr<ProductRegistry>> productRegistry_;
451+
ProductRegistry productRegistry_;
455452
edm::propagate_const<std::unique_ptr<ProcessHistoryRegistry>> processHistoryRegistry_;
456453
edm::propagate_const<std::shared_ptr<BranchIDListHelper>> branchIDListHelper_;
457454
edm::propagate_const<std::shared_ptr<ProcessBlockHelper>> processBlockHelper_;

FWCore/Framework/interface/InputSourceDescription.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,9 @@ namespace edm {
1919
class ThinnedAssociationsHelper;
2020

2121
struct InputSourceDescription {
22-
InputSourceDescription()
23-
: moduleDescription_(),
24-
productRegistry_(nullptr),
25-
actReg_(),
26-
maxEvents_(-1),
27-
maxLumis_(-1),
28-
allocations_(nullptr) {}
22+
InputSourceDescription() : moduleDescription_(), actReg_(), maxEvents_(-1), maxLumis_(-1), allocations_(nullptr) {}
2923

3024
InputSourceDescription(ModuleDescription const& md,
31-
std::shared_ptr<ProductRegistry> preg,
3225
std::shared_ptr<BranchIDListHelper> branchIDListHelper,
3326
std::shared_ptr<ProcessBlockHelper> const& processBlockHelper,
3427
std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper,
@@ -38,7 +31,6 @@ namespace edm {
3831
int maxSecondsUntilRampdown,
3932
PreallocationConfiguration const& allocations)
4033
: moduleDescription_(md),
41-
productRegistry_(preg),
4234
branchIDListHelper_(branchIDListHelper),
4335
processBlockHelper_(processBlockHelper),
4436
thinnedAssociationsHelper_(thinnedAssociationsHelper),
@@ -49,7 +41,6 @@ namespace edm {
4941
allocations_(&allocations) {}
5042

5143
ModuleDescription moduleDescription_;
52-
std::shared_ptr<ProductRegistry> productRegistry_;
5344
std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
5445
std::shared_ptr<ProcessBlockHelper> processBlockHelper_;
5546
std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;

FWCore/Framework/interface/maker/InputSourceFactory.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ namespace edm {
2121

2222
static InputSourceFactory const* get();
2323

24-
std::unique_ptr<InputSource> makeInputSource(ParameterSet const&,
25-
SignallingProductRegistry&,
26-
InputSourceDescription const&) const;
24+
std::unique_ptr<InputSource> makeInputSource(ParameterSet const&, InputSourceDescription const&) const;
2725

2826
private:
2927
InputSourceFactory();

FWCore/Framework/src/EventProcessor.cc

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ namespace edm {
121121
std::unique_ptr<InputSource> makeInput(unsigned int moduleIndex,
122122
ParameterSet& params,
123123
CommonParams const& common,
124-
std::shared_ptr<SignallingProductRegistry> preg,
125124
std::shared_ptr<BranchIDListHelper> branchIDListHelper,
126125
std::shared_ptr<ProcessBlockHelper> const& processBlockHelper,
127126
std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper,
@@ -166,7 +165,6 @@ namespace edm {
166165
moduleIndex);
167166

168167
InputSourceDescription isdesc(md,
169-
preg,
170168
branchIDListHelper,
171169
processBlockHelper,
172170
thinnedAssociationsHelper,
@@ -182,8 +180,7 @@ namespace edm {
182180
//even if we have an exception, send the signal
183181
std::shared_ptr<int> sentry(nullptr, [areg, &md](void*) { areg->postSourceConstructionSignal_(md); });
184182
convertException::wrap([&]() {
185-
input = std::unique_ptr<InputSource>(
186-
InputSourceFactory::get()->makeInputSource(*main_input, *preg, isdesc).release());
183+
input = InputSourceFactory::get()->makeInputSource(*main_input, isdesc);
187184
input->preEventReadFromSourceSignal_.connect(std::cref(areg->preEventReadFromSourceSignal_));
188185
input->postEventReadFromSourceSignal_.connect(std::cref(areg->postEventReadFromSourceSignal_));
189186
});
@@ -489,7 +486,6 @@ namespace edm {
489486
tbb::task_group group;
490487

491488
// initialize the input source
492-
auto tempReg = std::make_shared<SignallingProductRegistry>();
493489
auto sourceID = ModuleDescription::getUniqueID();
494490

495491
group.run([&, this]() {
@@ -500,12 +496,11 @@ namespace edm {
500496
items.initModules(*parameterSet, tns, preallocations_, &processContext_, moduleTypeResolverMaker_.get());
501497
});
502498

503-
group.run([&, this, tempReg]() {
499+
group.run([&, this]() {
504500
ServiceRegistry::Operate operate(serviceToken_);
505501
input_ = makeInput(sourceID,
506502
*parameterSet,
507503
*common,
508-
/*items.preg(),*/ tempReg,
509504
items.branchIDListHelper(),
510505
get_underlying_safe(processBlockHelper_),
511506
items.thinnedAssociationsHelper(),
@@ -515,9 +510,7 @@ namespace edm {
515510
});
516511

517512
group.wait();
518-
items.preg()->addFromInput(*tempReg);
519-
input_->switchTo(items.preg());
520-
513+
items.preg()->addFromInput(input_->productRegistry());
521514
{
522515
auto const& tns = ServiceRegistry::instance().get<service::TriggerNamesService>();
523516
schedule_ = items.finishSchedule(std::move(*madeModules),
@@ -726,7 +719,7 @@ namespace edm {
726719
espController_->finishConfiguration();
727720
actReg_->eventSetupConfigurationSignal_(esp_->recordsToResolverIndices(), processContext_);
728721
try {
729-
convertException::wrap([&]() { input_->doBeginJob(); });
722+
convertException::wrap([&]() { input_->doBeginJob(*preg_); });
730723
} catch (cms::Exception& ex) {
731724
ex.addContext("Calling beginJob for the source");
732725
throw;
@@ -1014,7 +1007,6 @@ namespace edm {
10141007

10151008
void EventProcessor::readFile() {
10161009
FDEBUG(1) << " \treadFile\n";
1017-
size_t size = preg_->size();
10181010
SendSourceTerminationSignalIfException sentry(actReg_.get());
10191011

10201012
if (streamRunActive_ > 0) {
@@ -1027,6 +1019,9 @@ namespace edm {
10271019
}
10281020

10291021
fb_ = input_->readFile();
1022+
//incase the input's registry changed
1023+
const size_t size = preg_->size();
1024+
preg_->merge(input_->productRegistry(), fb_ ? fb_->fileName() : std::string());
10301025
if (size < preg_->size()) {
10311026
principalCache_.adjustIndexesAfterProductRegistryAddition();
10321027
}

FWCore/Framework/src/InputSource.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ namespace edm {
5454
maxSecondsUntilRampdown_(desc.maxSecondsUntilRampdown_),
5555
processingMode_(RunsLumisAndEvents),
5656
moduleDescription_(desc.moduleDescription_),
57-
productRegistry_(desc.productRegistry_),
5857
processHistoryRegistry_(new ProcessHistoryRegistry),
5958
branchIDListHelper_(desc.branchIDListHelper_),
6059
processBlockHelper_(desc.processBlockHelper_),
@@ -205,7 +204,7 @@ namespace edm {
205204
"Calling InputSource::readRunAuxiliary_");
206205
}
207206

208-
void InputSource::doBeginJob() { this->beginJob(); }
207+
void InputSource::doBeginJob(edm::ProductRegistry const& iReg) { this->beginJob(iReg); }
209208

210209
void InputSource::doEndJob() { endJob(); }
211210

@@ -217,7 +216,7 @@ namespace edm {
217216
return std::pair<SharedResourcesAcquirer*, std::recursive_mutex*>(nullptr, nullptr);
218217
}
219218

220-
void InputSource::registerProducts(SignallingProductRegistry&) {}
219+
void InputSource::registerProducts() {}
221220

222221
// Return a dummy file block.
223222
std::shared_ptr<FileBlock> InputSource::readFile() {
@@ -436,7 +435,7 @@ namespace edm {
436435
"Calling InputSource::reverseState__");
437436
}
438437

439-
void InputSource::beginJob() {}
438+
void InputSource::beginJob(ProductRegistry const&) {}
440439

441440
void InputSource::endJob() {}
442441

FWCore/Framework/src/InputSourceFactory.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace edm {
2424
}
2525

2626
std::unique_ptr<InputSource> InputSourceFactory::makeInputSource(ParameterSet const& conf,
27-
SignallingProductRegistry& reg,
2827
InputSourceDescription const& desc) const
2928

3029
{
@@ -40,7 +39,7 @@ namespace edm {
4039
<< "Try running EdmPluginDump to obtain a list of available Plugins.";
4140
}
4241

43-
wm->registerProducts(reg);
42+
wm->registerProducts();
4443

4544
FDEBUG(1) << "InputSourceFactory: created input source " << modtype << std::endl;
4645

FWCore/Integration/plugins/PutOrMergeTestSource.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace edmtest {
2727
PutOrMergeTestSource(ParameterSet const&, InputSourceDescription const&);
2828

2929
/// Register any produced products
30-
void registerProducts(SignallingProductRegistry&) final;
30+
void registerProducts() final;
3131

3232
private:
3333
ItemTypeInfo getNextItemType() final;
@@ -86,7 +86,7 @@ PutOrMergeTestSource::PutOrMergeTestSource(ParameterSet const& iPS, InputSourceD
8686
historyID_ = history.id();
8787
}
8888

89-
void PutOrMergeTestSource::registerProducts(SignallingProductRegistry&) {
89+
void PutOrMergeTestSource::registerProducts() {
9090
edm::ParameterSet dummyPset;
9191
dummyPset.registerIt();
9292

FWCore/Integration/plugins/ThrowingSource.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace edm {
1212
explicit ThrowingSource(ParameterSet const&, InputSourceDescription const&);
1313
~ThrowingSource() noexcept(false) override;
1414

15-
void beginJob() override;
15+
void beginJob(ProductRegistry const&) override;
1616
void endJob() override;
1717
void beginLuminosityBlock(edm::LuminosityBlock&) override;
1818
void beginRun(edm::Run&) override;
@@ -63,7 +63,7 @@ namespace edm {
6363

6464
void ThrowingSource::produce(edm::Event&) {}
6565

66-
void ThrowingSource::beginJob() {
66+
void ThrowingSource::beginJob(edm::ProductRegistry const&) {
6767
if (whenToThrow_ == kBeginJob)
6868
throw cms::Exception("TestThrow") << "ThrowingSource::beginJob";
6969
}

FWCore/Sources/interface/IDGeneratorSourceBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace edm {
7171
virtual bool setRunAndEventInfo(EventID& id, TimeValue_t& time, EventAuxiliary::ExperimentType& etype) = 0;
7272
virtual bool noFiles() const;
7373
virtual size_t fileIndex() const;
74-
void beginJob() override;
74+
void beginJob(ProductRegistry const&) override;
7575

7676
std::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_() override;
7777
std::shared_ptr<RunAuxiliary> readRunAuxiliary_() override;

FWCore/Sources/interface/PuttableSourceBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ namespace edm {
4040
// ---------- member functions ---------------------------
4141
using ProducerBase::registerProducts;
4242
using ProducerBase::resolvePutIndicies;
43-
void registerProducts(SignallingProductRegistry&) final;
43+
void registerProducts() final;
4444

4545
bool hasAbilityToProduceInBeginRuns() const final { return true; }
4646

4747
bool hasAbilityToProduceInBeginLumis() const final { return true; }
4848

4949
protected:
5050
//If inheriting class overrides, they need to call this function as well
51-
void beginJob() override;
51+
void beginJob(edm::ProductRegistry const&) override;
5252

5353
private:
5454
void doBeginLumi(LuminosityBlockPrincipal& lbp, ProcessContext const*) override;

0 commit comments

Comments
 (0)