Skip to content

Commit 09d925c

Browse files
committed
DPL: pass ConfigContext to the PluginManager when creating AlgorithmSpec
This way a plugin can create more complex AlgorithmSpecs which depend on the workflow options. This will be needed to properly read metadata from parent files, and it opens the way to more service devices to be moved in a plugin.
1 parent f56b4f8 commit 09d925c

File tree

8 files changed

+15
-13
lines changed

8 files changed

+15
-13
lines changed

Framework/AnalysisSupport/src/AODJAlienReaderHelpers.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Framework/DeviceSpec.h"
2323
#include "Framework/RawDeviceService.h"
2424
#include "Framework/DataSpecUtils.h"
25+
#include "Framework/ConfigContext.h"
2526
#include "DataInputDirector.h"
2627
#include "Framework/SourceInfoHeader.h"
2728
#include "Framework/ChannelInfo.h"
@@ -117,7 +118,7 @@ static inline auto extractOriginalsTuple(framework::pack<Os...>, ProcessingConte
117118
return std::make_tuple(extractTypedOriginal<Os>(pc)...);
118119
}
119120

120-
AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback()
121+
AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const& config)
121122
{
122123
auto callback = AlgorithmSpec{adaptStateful([](ConfigParamRegistry const& options,
123124
DeviceSpec const& spec,

Framework/AnalysisSupport/src/AODJAlienReaderHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace o2::framework::readers
2424
{
2525

2626
struct AODJAlienReaderHelpers {
27-
static AlgorithmSpec rootFileReaderCallback();
27+
static AlgorithmSpec rootFileReaderCallback(ConfigContext const&context);
2828
static void dumpFileMetrics(o2::monitoring::Monitoring& monitoring, TFile* currentFile, uint64_t startedAt, uint64_t ioTime, int tfPerFile, int tfRead);
2929
};
3030

Framework/AnalysisSupport/src/Plugin.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
O2_DECLARE_DYNAMIC_LOG(analysis_support);
2727

2828
struct ROOTFileReader : o2::framework::AlgorithmPlugin {
29-
o2::framework::AlgorithmSpec create() override
29+
o2::framework::AlgorithmSpec create(o2::framework::ConfigContext const& config) override
3030
{
31-
return o2::framework::readers::AODJAlienReaderHelpers::rootFileReaderCallback();
31+
return o2::framework::readers::AODJAlienReaderHelpers::rootFileReaderCallback(config);
3232
}
3333
};
3434

Framework/CCDBSupport/src/Plugin.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "CCDBHelpers.h"
1414

1515
struct CCDBFetcherPlugin : o2::framework::AlgorithmPlugin {
16-
o2::framework::AlgorithmSpec create() final
16+
o2::framework::AlgorithmSpec create(o2::framework::ConfigContext const&) final
1717
{
1818
return o2::framework::CCDBHelpers::fetchFromCCDB();
1919
}

Framework/Core/include/Framework/AlgorithmSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct AlgorithmSpec {
8181

8282
/// Helper class for an algorithm which is loaded as a plugin.
8383
struct AlgorithmPlugin {
84-
virtual AlgorithmSpec create() = 0;
84+
virtual AlgorithmSpec create(ConfigContext const&) = 0;
8585
};
8686
// Allow fetching inputs from the context using a string literal.
8787
template <StringLiteral lit, typename T>

Framework/Core/include/Framework/PluginManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ struct PluginManager {
5151
/// the DPLPluginHandle provided by the library.
5252
static void load(std::vector<PluginInfo>& infos, const char* dso, std::function<void(DPLPluginHandle*)>& onSuccess);
5353
/// Load an called @plugin from a library called @a library and
54-
/// return the associtated AlgorithmSpec.
55-
static auto loadAlgorithmFromPlugin(std::string library, std::string plugin) -> AlgorithmSpec;
54+
/// @return the associated AlgorithmSpec.
55+
/// The config @a context can be used to determine the workflow options which affect such plugin.
56+
static auto loadAlgorithmFromPlugin(std::string library, std::string plugin, ConfigContext const& context) -> AlgorithmSpec;
5657
/// Wrap an algorithm with some lambda @wrapper which will be called
5758
/// with the original callback and the ProcessingContext.
5859
static auto wrapAlgorithm(AlgorithmSpec const& spec, WrapperProcessCallback&& wrapper) -> AlgorithmSpec;

Framework/Core/src/PluginManager.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ void PluginManager::load(std::vector<PluginInfo>& libs, const char* dso, std::fu
101101
onSuccess(pluginInstance);
102102
}
103103

104-
auto PluginManager::loadAlgorithmFromPlugin(std::string library, std::string plugin) -> AlgorithmSpec
104+
auto PluginManager::loadAlgorithmFromPlugin(std::string library, std::string plugin, ConfigContext const& context) -> AlgorithmSpec
105105
{
106106
std::shared_ptr<AlgorithmSpec> algorithm{nullptr};
107-
return AlgorithmSpec{[algorithm, library, plugin](InitContext& ic) mutable -> AlgorithmSpec::ProcessCallback {
107+
return AlgorithmSpec{[algorithm, library, plugin, &context](InitContext& ic) mutable -> AlgorithmSpec::ProcessCallback {
108108
if (algorithm.get()) {
109109
return algorithm->onInit(ic);
110110
}
@@ -134,7 +134,7 @@ auto PluginManager::loadAlgorithmFromPlugin(std::string library, std::string plu
134134
if (!creator) {
135135
LOGP(fatal, "Could not find the {} plugin in {}.", plugin, libName);
136136
}
137-
algorithm = std::make_shared<AlgorithmSpec>(creator->create());
137+
algorithm = std::make_shared<AlgorithmSpec>(creator->create(context));
138138
return algorithm->onInit(ic);
139139
}};
140140
};

Framework/Core/src/WorkflowHelpers.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
432432
auto mctracks2aod = std::find_if(workflow.begin(), workflow.end(), [](auto const& x) { return x.name == "mctracks-to-aod"; });
433433
if (mctracks2aod == workflow.end()) {
434434
// add normal reader
435-
auto&& algo = PluginManager::loadAlgorithmFromPlugin("O2FrameworkAnalysisSupport", "ROOTFileReader");
435+
auto&& algo = PluginManager::loadAlgorithmFromPlugin("O2FrameworkAnalysisSupport", "ROOTFileReader", ctx);
436436
if (internalRateLimiting) {
437437
aodReader.algorithm = CommonDataProcessors::wrapWithRateLimiting(algo);
438438
} else {
@@ -520,7 +520,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
520520
}
521521

522522
// Load the CCDB backend from the plugin
523-
ccdbBackend.algorithm = PluginManager::loadAlgorithmFromPlugin("O2FrameworkCCDBSupport", "CCDBFetcherPlugin");
523+
ccdbBackend.algorithm = PluginManager::loadAlgorithmFromPlugin("O2FrameworkCCDBSupport", "CCDBFetcherPlugin", ctx);
524524
extraSpecs.push_back(ccdbBackend);
525525
} else {
526526
// If there is no CCDB requested, but we still ask for a FLP/DISTSUBTIMEFRAME/0xccdb

0 commit comments

Comments
 (0)