Skip to content

Commit 3966c73

Browse files
authored
Merge pull request #48358 from Dr15Jones/refactorWorker
Refactor Worker/Module system
2 parents 01b3ca5 + 52b4e8f commit 3966c73

21 files changed

+508
-439
lines changed

FWCore/Framework/interface/GlobalSchedule.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "FWCore/Framework/interface/RunPrincipal.h"
1414
#include "FWCore/Framework/interface/WorkerManager.h"
1515
#include "FWCore/Framework/interface/maker/Worker.h"
16-
#include "FWCore/Framework/interface/WorkerRegistry.h"
1716
#include "FWCore/Framework/interface/SignallingProductRegistryFiller.h"
1817
#include "FWCore/MessageLogger/interface/ExceptionMessages.h"
1918
#include "FWCore/ServiceRegistry/interface/GlobalContext.h"
@@ -74,10 +73,7 @@ namespace edm {
7473
ServiceToken const& token,
7574
bool cleaningUpAfterException = false);
7675

77-
void beginJob(ProductRegistry const&,
78-
eventsetup::ESRecordsToProductResolverIndices const&,
79-
ProcessBlockHelperBase const&,
80-
ProcessContext const&);
76+
void beginJob(ProcessContext const&);
8177
void endJob(ExceptionCollector& collector);
8278

8379
/// Return a vector allowing const access to all the
@@ -100,8 +96,6 @@ namespace edm {
10096
/// returns the collection of pointers to workers
10197
AllWorkers const& allWorkers() const { return workerManagers_[0].allWorkers(); }
10298

103-
void releaseMemoryPostLookupSignal();
104-
10599
private:
106100
/// returns the action table
107101
ExceptionToActionTable const& actionTable() const { return workerManagers_[0].actionTable(); }

FWCore/Framework/interface/ModuleRegistry.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
// user include files
2727
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
2828
#include "FWCore/Utilities/interface/propagate_const.h"
29+
#include "FWCore/Utilities/interface/Exception.h"
2930
#include "FWCore/Framework/interface/ModuleTypeResolverMaker.h"
31+
#include "FWCore/Framework/interface/maker/ModuleHolder.h"
3032

3133
// forward declarations
3234
namespace edm {
@@ -46,6 +48,8 @@ namespace edm {
4648
std::string const& moduleLabel,
4749
signalslot::Signal<void(ModuleDescription const&)>& iPre,
4850
signalslot::Signal<void(ModuleDescription const&)>& iPost);
51+
//returns a null if module not found
52+
std::shared_ptr<maker::ModuleHolder> getExistingModule(std::string const& moduleLabel);
4953

5054
maker::ModuleHolder* replaceModule(std::string const& iModuleLabel,
5155
edm::ParameterSet const& iPSet,
@@ -55,6 +59,43 @@ namespace edm {
5559
signalslot::Signal<void(ModuleDescription const&)>& iPre,
5660
signalslot::Signal<void(ModuleDescription const&)>& iPost);
5761

62+
template <typename T, typename... Args>
63+
std::shared_ptr<T> makeExplicitModule(ModuleDescription const& md,
64+
PreallocationConfiguration const& iPrealloc,
65+
SignallingProductRegistryFiller* iReg,
66+
signalslot::Signal<void(ModuleDescription const&)>& iPre,
67+
signalslot::Signal<void(ModuleDescription const&)>& iPost,
68+
Args&&... args) {
69+
bool postCalled = false;
70+
if (labelToModule_.find(md.moduleLabel()) != labelToModule_.end()) {
71+
throw cms::Exception("InsertError") << "Module with label '" << md.moduleLabel() << "' already exists.";
72+
}
73+
74+
try {
75+
std::shared_ptr<T> module;
76+
convertException::wrap([&]() {
77+
iPre(md);
78+
module = std::make_shared<T>(std::forward<Args>(args)...);
79+
80+
auto holder = std::make_shared<maker::ModuleHolderT<typename T::ModuleType>>(module);
81+
holder->finishModuleInitialization(md, iPrealloc, iReg);
82+
labelToModule_.emplace(md.moduleLabel(), std::move(holder));
83+
84+
// if exception then post will be called in the catch block
85+
postCalled = true;
86+
iPost(md);
87+
});
88+
return module;
89+
} catch (cms::Exception& iException) {
90+
if (!postCalled) {
91+
CMS_SA_ALLOW try { iPost(md); } catch (...) {
92+
// If post throws an exception ignore it because we are already handling another exception
93+
}
94+
}
95+
throw;
96+
}
97+
}
98+
5899
template <typename F>
59100
void forAllModuleHolders(F iFunc) {
60101
for (auto& labelMod : labelToModule_) {
@@ -63,6 +104,11 @@ namespace edm {
63104
}
64105
}
65106

107+
void finishModulesInitialization(ProductRegistry const& iRegistry,
108+
eventsetup::ESRecordsToProductResolverIndices const& iESIndices,
109+
ProcessBlockHelperBase const& processBlockHelperBase,
110+
std::string const& processName);
111+
66112
private:
67113
std::map<std::string, edm::propagate_const<std::shared_ptr<maker::ModuleHolder>>> labelToModule_;
68114
ModuleTypeResolverMaker const* typeResolverMaker_;

FWCore/Framework/interface/Schedule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
#include "FWCore/Framework/interface/OccurrenceTraits.h"
6767
#include "FWCore/Framework/interface/WorkerManager.h"
6868
#include "FWCore/Framework/interface/maker/Worker.h"
69-
#include "FWCore/Framework/interface/WorkerRegistry.h"
7069
#include "FWCore/Framework/interface/GlobalSchedule.h"
7170
#include "FWCore/Framework/interface/StreamSchedule.h"
7271
#include "FWCore/Framework/interface/SystemTimeKeeper.h"
@@ -305,10 +304,10 @@ namespace edm {
305304
std::shared_ptr<ModuleRegistry const> moduleRegistry() const { return get_underlying_safe(moduleRegistry_); }
306305
std::shared_ptr<ModuleRegistry>& moduleRegistry() { return get_underlying_safe(moduleRegistry_); }
307306

307+
edm::propagate_const<std::shared_ptr<ModuleRegistry>> moduleRegistry_;
308308
edm::propagate_const<std::shared_ptr<TriggerResultInserter>> resultsInserter_;
309309
std::vector<edm::propagate_const<std::shared_ptr<PathStatusInserter>>> pathStatusInserters_;
310310
std::vector<edm::propagate_const<std::shared_ptr<EndPathStatusInserter>>> endPathStatusInserters_;
311-
edm::propagate_const<std::shared_ptr<ModuleRegistry>> moduleRegistry_;
312311
std::vector<edm::propagate_const<std::shared_ptr<StreamSchedule>>> streamSchedules_;
313312
//In the future, we will have one GlobalSchedule per simultaneous transition
314313
edm::propagate_const<std::unique_ptr<GlobalSchedule>> globalSchedule_;

FWCore/Framework/interface/StreamSchedule.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
#include "FWCore/Framework/interface/Path.h"
7070
#include "FWCore/Framework/interface/TransitionInfoTypes.h"
7171
#include "FWCore/Framework/interface/maker/Worker.h"
72-
#include "FWCore/Framework/interface/WorkerRegistry.h"
7372
#include "FWCore/Framework/interface/EarlyDeleteHelper.h"
7473
#include "FWCore/MessageLogger/interface/ExceptionMessages.h"
7574
#include "FWCore/MessageLogger/interface/JobReport.h"
@@ -129,7 +128,6 @@ namespace edm {
129128
typedef std::vector<Path> TrigPaths;
130129
typedef std::shared_ptr<HLTGlobalStatus> TrigResPtr;
131130
typedef std::shared_ptr<HLTGlobalStatus const> TrigResConstPtr;
132-
typedef std::shared_ptr<Worker> WorkerPtr;
133131
typedef std::vector<Worker*> AllWorkers;
134132

135133
typedef std::vector<Worker*> Workers;
@@ -263,16 +261,15 @@ namespace edm {
263261
SignallingProductRegistryFiller& preg,
264262
PreallocationConfiguration const* prealloc,
265263
std::shared_ptr<ProcessConfiguration const> processConfiguration);
266-
void fillWorkers(ParameterSet& proc_pset,
267-
SignallingProductRegistryFiller& preg,
268-
PreallocationConfiguration const* prealloc,
269-
std::shared_ptr<ProcessConfiguration const> processConfiguration,
270-
std::string const& name,
271-
bool ignoreFilters,
272-
PathWorkers& out,
273-
std::vector<std::string> const& endPathNames,
274-
ConditionalTaskHelper const& conditionalTaskHelper,
275-
std::unordered_set<std::string>& allConditionalModules);
264+
PathWorkers fillWorkers(ParameterSet& proc_pset,
265+
SignallingProductRegistryFiller& preg,
266+
PreallocationConfiguration const* prealloc,
267+
std::shared_ptr<ProcessConfiguration const> processConfiguration,
268+
std::string const& name,
269+
bool ignoreFilters,
270+
std::vector<std::string> const& endPathNames,
271+
ConditionalTaskHelper const& conditionalTaskHelper,
272+
std::unordered_set<std::string>& allConditionalModules);
276273
void fillTrigPath(ParameterSet& proc_pset,
277274
SignallingProductRegistryFiller& preg,
278275
PreallocationConfiguration const* prealloc,
@@ -320,9 +317,9 @@ namespace edm {
320317

321318
edm::propagate_const<TrigResPtr> results_;
322319

323-
edm::propagate_const<WorkerPtr> results_inserter_;
324-
std::vector<edm::propagate_const<WorkerPtr>> pathStatusInserterWorkers_;
325-
std::vector<edm::propagate_const<WorkerPtr>> endPathStatusInserterWorkers_;
320+
edm::propagate_const<Worker*> results_inserter_;
321+
std::vector<edm::propagate_const<Worker*>> pathStatusInserterWorkers_;
322+
std::vector<edm::propagate_const<Worker*>> endPathStatusInserterWorkers_;
326323

327324
TrigPaths trig_paths_;
328325
TrigPaths end_paths_;

FWCore/Framework/interface/WorkerManager.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ namespace edm {
3232
public:
3333
typedef std::vector<Worker*> AllWorkers;
3434

35-
WorkerManager(std::shared_ptr<ActivityRegistry> actReg,
36-
ExceptionToActionTable const& actions,
37-
ModuleTypeResolverMaker const* typeResolverMaker);
3835
WorkerManager(WorkerManager&&) = default;
3936

4037
WorkerManager(std::shared_ptr<ModuleRegistry> modReg,
@@ -70,10 +67,7 @@ namespace edm {
7067
void setupResolvers(Principal& principal);
7168
void setupOnDemandSystem(EventTransitionInfo const&);
7269

73-
void beginJob(ProductRegistry const& iRegistry,
74-
eventsetup::ESRecordsToProductResolverIndices const&,
75-
ProcessBlockHelperBase const&,
76-
GlobalContext const&);
70+
void beginJob(GlobalContext const&);
7771
void endJob(ExceptionCollector&, GlobalContext const&);
7872

7973
void beginStream(StreamID, StreamContext const&);
@@ -90,13 +84,21 @@ namespace edm {
9084
SignallingProductRegistryFiller& preg,
9185
PreallocationConfiguration const* prealloc,
9286
std::shared_ptr<ProcessConfiguration const> processConfiguration,
93-
std::string const& label);
87+
std::string const& label,
88+
bool addToAllWorkers = true);
9489

90+
template <typename T>
91+
Worker* getWorkerForModule(T const& module) {
92+
auto* worker = getWorkerForExistingModule(module.moduleDescription().moduleLabel());
93+
assert(worker != nullptr);
94+
assert(worker->matchesBaseClassPointer(static_cast<typename T::ModuleType const*>(&module)));
95+
return worker;
96+
}
9597
void resetAll();
9698

97-
void releaseMemoryPostLookupSignal();
98-
9999
private:
100+
Worker* getWorkerForExistingModule(std::string const& label);
101+
100102
WorkerRegistry workerReg_;
101103
ExceptionToActionTable const* actionTable_;
102104
AllWorkers allWorkers_;

FWCore/Framework/interface/WorkerRegistry.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ namespace edm {
2424
class ModuleRegistry;
2525
class ModuleTypeResolverMaker;
2626
class ParameterSet;
27+
class ExceptionToActionTable;
2728
namespace maker {
2829
class ModuleHolder;
2930
}
3031

3132
/**
3233
\class WorkerRegistry WorkerRegistry.h "edm/WorkerRegistry.h"
3334
34-
\brief The Registry of all workers that where requested
35+
\brief The Registry of all workers that were requested
3536
Holds all instances of workers. In this implementation, Workers
3637
are owned.
3738
*/
3839

3940
class WorkerRegistry {
4041
public:
41-
explicit WorkerRegistry(std::shared_ptr<ActivityRegistry> areg, ModuleTypeResolverMaker const* resolverMaker);
4242
WorkerRegistry(std::shared_ptr<ActivityRegistry> areg, std::shared_ptr<ModuleRegistry> iModReg);
4343
~WorkerRegistry();
4444

@@ -56,6 +56,9 @@ namespace edm {
5656
/// If one doesn't exist, returns nullptr
5757
Worker const* get(std::string const& moduleLabel) const;
5858

59+
//Creates worker if needed
60+
Worker* getWorkerFromExistingModule(std::string const& moduleLabel, ExceptionToActionTable const* actions);
61+
5962
/// Deletes the module of the Worker, but the Worker continues to exist.
6063
void deleteModule(std::string const& moduleLabel);
6164

FWCore/Framework/interface/maker/ModuleHolder.h

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,24 @@
2323

2424
// user include files
2525
#include "FWCore/Framework/interface/maker/WorkerT.h"
26-
#include "FWCore/Framework/interface/OutputModuleCommunicatorT.h"
2726
#include "FWCore/Framework/interface/SignallingProductRegistryFiller.h"
27+
#include "FWCore/Framework/interface/OutputModuleCommunicator.h"
28+
29+
#include "FWCore/Utilities/interface/BranchType.h"
30+
#include "FWCore/Utilities/interface/ProductResolverIndex.h"
31+
32+
#include <unordered_map>
33+
#include <string>
2834
// forward declarations
2935
namespace edm {
3036
class ModuleDescription;
3137
class SignallingProductRegistryFiller;
3238
class ExceptionToActionTable;
3339
class PreallocationConfiguration;
40+
class ProductResolverIndexHelper;
41+
class ProductResolverIndexAndSkipBit;
42+
class ProductRegistry;
43+
class ThinnedAssociationsHelper;
3444

3545
namespace maker {
3646
class ModuleHolder {
@@ -46,6 +56,22 @@ namespace edm {
4656
virtual void replaceModuleFor(Worker*) const = 0;
4757

4858
virtual std::unique_ptr<OutputModuleCommunicator> createOutputModuleCommunicator() = 0;
59+
60+
void registerThinnedAssociations(ProductRegistry const& registry, ThinnedAssociationsHelper& helper);
61+
//Used to make EDGetToken work
62+
virtual void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const&) = 0;
63+
virtual void updateLookup(eventsetup::ESRecordsToProductResolverIndices const&) = 0;
64+
virtual void releaseMemoryPostLookupSignal() = 0;
65+
virtual void selectInputProcessBlocks(ProductRegistry const&, ProcessBlockHelperBase const&) = 0;
66+
virtual void resolvePutIndicies(
67+
BranchType iBranchType,
68+
std::unordered_multimap<std::string, std::tuple<TypeID const*, const char*, edm::ProductResolverIndex>> const&
69+
iIndicies) = 0;
70+
virtual void convertCurrentProcessAlias(std::string const& processName) = 0;
71+
72+
private:
73+
virtual void implRegisterThinnedAssociations(ProductRegistry const& registry,
74+
ThinnedAssociationsHelper& helper) = 0;
4975
};
5076

5177
template <typename T>
@@ -59,7 +85,7 @@ namespace edm {
5985
assert(nullptr != w);
6086
w->setModule(m_mod);
6187
}
62-
std::unique_ptr<Worker> makeWorker(ExceptionToActionTable const* actions) const override {
88+
std::unique_ptr<Worker> makeWorker(ExceptionToActionTable const* actions) const final {
6389
return std::make_unique<edm::WorkerT<T>>(module(), moduleDescription(), actions);
6490
}
6591

@@ -73,18 +99,30 @@ namespace edm {
7399
iModule.registerProductsAndCallbacks(&iModule, iReg);
74100
}
75101
};
76-
ModuleDescription const& moduleDescription() const override { return m_mod->moduleDescription(); }
102+
ModuleDescription const& moduleDescription() const final { return m_mod->moduleDescription(); }
77103

78104
void finishModuleInitialization(ModuleDescription const& iDesc,
79105
PreallocationConfiguration const& iPrealloc,
80106
SignallingProductRegistryFiller* iReg) override {
81107
finishModuleInitialization(*m_mod, iDesc, iPrealloc, iReg);
82108
}
83-
std::unique_ptr<OutputModuleCommunicator> createOutputModuleCommunicator() override {
84-
return OutputModuleCommunicatorT<T>::createIfNeeded(m_mod.get());
109+
std::unique_ptr<OutputModuleCommunicator> createOutputModuleCommunicator() final;
110+
111+
void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const&) final;
112+
void updateLookup(eventsetup::ESRecordsToProductResolverIndices const&) final;
113+
void releaseMemoryPostLookupSignal() final;
114+
void selectInputProcessBlocks(ProductRegistry const&, ProcessBlockHelperBase const&) final;
115+
void resolvePutIndicies(
116+
BranchType iBranchType,
117+
std::unordered_multimap<std::string, std::tuple<TypeID const*, const char*, edm::ProductResolverIndex>> const&
118+
iIndicies) final;
119+
void convertCurrentProcessAlias(std::string const& processName) final {
120+
m_mod->convertCurrentProcessAlias(processName);
85121
}
86122

87123
private:
124+
void implRegisterThinnedAssociations(ProductRegistry const& registry, ThinnedAssociationsHelper& helper) final;
125+
88126
std::shared_ptr<T> m_mod;
89127
};
90128
} // namespace maker

0 commit comments

Comments
 (0)