|
27 | 27 | #include "Framework/CommonServices.h" |
28 | 28 | #include "Framework/WorkflowCustomizationHelpers.h" |
29 | 29 | #include "Framework/Logger.h" // IWYU pragma: export |
| 30 | +#include "Framework/WorkflowDefinitionContext.h" |
| 31 | +#include "Framework/Plugins.h" |
30 | 32 | #include "Framework/CheckTypes.h" |
31 | 33 | #include "Framework/StructToTuple.h" |
32 | 34 | #include "ResourcePolicy.h" |
@@ -124,18 +126,6 @@ void overrideCloning(o2::framework::ConfigContext& ctx, std::vector<o2::framewor |
124 | 126 | /// Helper used to add labels to Data Processors |
125 | 127 | void overrideLabels(o2::framework::ConfigContext& ctx, std::vector<o2::framework::DataProcessorSpec>& workflow); |
126 | 128 |
|
127 | | -// This comes from the framework itself. This way we avoid code duplication. |
128 | | -int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& specs, |
129 | | - std::vector<o2::framework::ChannelConfigurationPolicy> const& channelPolicies, |
130 | | - std::vector<o2::framework::CompletionPolicy> const& completionPolicies, |
131 | | - std::vector<o2::framework::DispatchPolicy> const& dispatchPolicies, |
132 | | - std::vector<o2::framework::ResourcePolicy> const& resourcePolicies, |
133 | | - std::vector<o2::framework::CallbacksPolicy> const& callbacksPolicies, |
134 | | - std::vector<o2::framework::SendingPolicy> const& sendingPolicies, |
135 | | - std::vector<o2::framework::ConfigParamSpec> const& workflowOptions, |
136 | | - std::vector<o2::framework::ConfigParamSpec> const& detectedOptions, |
137 | | - o2::framework::ConfigContext& configContext); |
138 | | - |
139 | 129 | void doDefaultWorkflowTerminationHook(); |
140 | 130 |
|
141 | 131 | template <typename T> |
@@ -167,55 +157,81 @@ void callWorkflowTermination(T&, char const* idstring) |
167 | 157 |
|
168 | 158 | void overrideAll(o2::framework::ConfigContext& ctx, std::vector<o2::framework::DataProcessorSpec>& workflow); |
169 | 159 |
|
170 | | -o2::framework::ConfigContext createConfigContext(std::unique_ptr<o2::framework::ConfigParamRegistry>& workflowOptionsRegistry, |
171 | | - o2::framework::ServiceRegistry& configRegistry, |
172 | | - std::vector<o2::framework::ConfigParamSpec>& workflowOptions, |
173 | | - std::vector<o2::framework::ConfigParamSpec>& extraOptions, int argc, char** argv); |
| 160 | +std::unique_ptr<o2::framework::ConfigContext> createConfigContext(std::unique_ptr<o2::framework::ConfigParamRegistry>& workflowOptionsRegistry, |
| 161 | + o2::framework::ServiceRegistry& configRegistry, |
| 162 | + std::vector<o2::framework::ConfigParamSpec>& workflowOptions, |
| 163 | + std::vector<o2::framework::ConfigParamSpec>& extraOptions, int argc, char** argv); |
174 | 164 |
|
175 | 165 | std::unique_ptr<o2::framework::ServiceRegistry> createRegistry(); |
176 | 166 |
|
177 | | -int mainNoCatch(int argc, char** argv) |
178 | | -{ |
179 | | - using namespace o2::framework; |
| 167 | +char* getIdString(int argc, char** argv); |
| 168 | + |
| 169 | +#define DPL_STRINGIZE_NX(A) #A |
| 170 | +#define DPL_STRINGIZE(A) DPL_STRINGIZE_NX(A) |
| 171 | + |
| 172 | +// The workflow definition is a plugin. By default it is embedded in the |
| 173 | +// executable as DPL_WORKFLOW_PLUGIN_NAME, with an empty library name. |
| 174 | +// To build it in a DSO instead, both DPL_WORKFLOW_PLUGIN_NAME and |
| 175 | +// DPL_WORKFLOW_PLUGIN_LIBRARY must be specified at build time. |
| 176 | +#ifndef DPL_WORKFLOW_PLUGIN_NAME |
| 177 | +#define DPL_WORKFLOW_PLUGIN_NAME InternalCustomWorkflow |
| 178 | +#ifdef DPL_WORKFLOW_PLUGIN_LIBRARY |
| 179 | +#error Missing DPL_WORKFLOW_PLUGIN_NAME |
| 180 | +#endif |
| 181 | +#define DPL_WORKFLOW_PLUGIN_LIBRARY |
| 182 | +#endif |
180 | 183 |
|
181 | | - std::vector<o2::framework::ConfigParamSpec> workflowOptions; |
182 | | - UserCustomizationsHelper::userDefinedCustomization(workflowOptions); |
183 | | - auto requiredWorkflowOptions = WorkflowCustomizationHelpers::requiredWorkflowOptions(); |
184 | | - workflowOptions.insert(std::end(workflowOptions), std::begin(requiredWorkflowOptions), std::end(requiredWorkflowOptions)); |
185 | | - |
186 | | - std::vector<CompletionPolicy> completionPolicies = injectCustomizations<CompletionPolicy>(); |
187 | | - std::vector<DispatchPolicy> dispatchPolicies = injectCustomizations<DispatchPolicy>(); |
188 | | - std::vector<ResourcePolicy> resourcePolicies = injectCustomizations<ResourcePolicy>(); |
189 | | - std::vector<CallbacksPolicy> callbacksPolicies = injectCustomizations<CallbacksPolicy>(); |
190 | | - std::vector<SendingPolicy> sendingPolicies = injectCustomizations<SendingPolicy>(); |
191 | | - |
192 | | - std::unique_ptr<ServiceRegistry> configRegistry = createRegistry(); |
193 | | - std::vector<ConfigParamSpec> extraOptions; |
194 | | - std::unique_ptr<ConfigParamRegistry> workflowOptionsRegistry{nullptr}; |
195 | | - auto configContext = createConfigContext(workflowOptionsRegistry, *configRegistry, workflowOptions, extraOptions, argc, argv); |
196 | | - |
197 | | - o2::framework::WorkflowSpec specs = defineDataProcessing(configContext); |
198 | | - overrideAll(configContext, specs); |
199 | | - for (auto& spec : specs) { |
200 | | - UserCustomizationsHelper::userDefinedCustomization(spec.requiredServices); |
| 184 | +struct DPL_WORKFLOW_PLUGIN_NAME : o2::framework::WorkflowPlugin { |
| 185 | + o2::framework::WorkflowDefinition* create() override |
| 186 | + { |
| 187 | + return new o2::framework::WorkflowDefinition{ |
| 188 | + .defineWorkflow = [](int argc, char** argv) -> o2::framework::WorkflowDefinitionContext { |
| 189 | + using namespace o2::framework; |
| 190 | + WorkflowDefinitionContext workflowContext; |
| 191 | + |
| 192 | + UserCustomizationsHelper::userDefinedCustomization(workflowContext.workflowOptions); |
| 193 | + auto requiredWorkflowOptions = WorkflowCustomizationHelpers::requiredWorkflowOptions(); |
| 194 | + workflowContext.workflowOptions.insert(std::end(workflowContext.workflowOptions), std::begin(requiredWorkflowOptions), std::end(requiredWorkflowOptions)); |
| 195 | + |
| 196 | + workflowContext.completionPolicies = injectCustomizations<CompletionPolicy>(); |
| 197 | + workflowContext.dispatchPolicies = injectCustomizations<DispatchPolicy>(); |
| 198 | + workflowContext.resourcePolicies = injectCustomizations<ResourcePolicy>(); |
| 199 | + workflowContext.callbacksPolicies = injectCustomizations<CallbacksPolicy>(); |
| 200 | + workflowContext.sendingPolicies = injectCustomizations<SendingPolicy>(); |
| 201 | + |
| 202 | + workflowContext.configRegistry = createRegistry(); |
| 203 | + workflowContext.configContext = createConfigContext(workflowContext.workflowOptionsRegistry, *workflowContext.configRegistry, workflowContext.workflowOptions, workflowContext.extraOptions, argc, argv); |
| 204 | + |
| 205 | + workflowContext.specs = defineDataProcessing(*workflowContext.configContext); |
| 206 | + overrideAll(*workflowContext.configContext, workflowContext.specs); |
| 207 | + for (auto& spec : workflowContext.specs) { |
| 208 | + UserCustomizationsHelper::userDefinedCustomization(spec.requiredServices); |
| 209 | + } |
| 210 | + UserCustomizationsHelper::userDefinedCustomization(workflowContext.channelPolicies); |
| 211 | + auto defaultChannelPolicies = ChannelConfigurationPolicy::createDefaultPolicies(*workflowContext.configContext); |
| 212 | + workflowContext.channelPolicies.insert(std::end(workflowContext.channelPolicies), std::begin(defaultChannelPolicies), std::end(defaultChannelPolicies)); |
| 213 | + return workflowContext; |
| 214 | + }}; |
201 | 215 | } |
202 | | - std::vector<ChannelConfigurationPolicy> channelPolicies; |
203 | | - UserCustomizationsHelper::userDefinedCustomization(channelPolicies); |
204 | | - auto defaultChannelPolicies = ChannelConfigurationPolicy::createDefaultPolicies(configContext); |
205 | | - channelPolicies.insert(std::end(channelPolicies), std::begin(defaultChannelPolicies), std::end(defaultChannelPolicies)); |
206 | | - return doMain(argc, argv, specs, |
207 | | - channelPolicies, completionPolicies, dispatchPolicies, |
208 | | - resourcePolicies, callbacksPolicies, sendingPolicies, workflowOptions, extraOptions, configContext); |
| 216 | +}; |
| 217 | + |
| 218 | +// This is like the plugin macros, we simply do it explicitly to avoid macro inside macro expansion |
| 219 | +extern "C" { |
| 220 | +DPLPluginHandle* dpl_plugin_callback(DPLPluginHandle* previous) |
| 221 | +{ |
| 222 | + return new DPLPluginHandle{new DPL_WORKFLOW_PLUGIN_NAME{}, strdup(DPL_STRINGIZE(DPL_WORKFLOW_PLUGIN_NAME)), o2::framework::DplPluginKind::Workflow, previous}; |
| 223 | +} |
209 | 224 | } |
210 | 225 |
|
211 | | -int callMain(int argc, char** argv, int (*)(int, char**)); |
212 | | -char* getIdString(int argc, char** argv); |
| 226 | +// Loads the workflow plugin @a pluginSpec, i.e. "<library>:<plugin>", and runs it. |
| 227 | +// An empty library means the plugin embedded in the executable, found via @a embeddedPlugins. |
| 228 | +int callMain(int argc, char** argv, char const* pluginSpec, DPLPluginHandle* (*embeddedPlugins)(DPLPluginHandle*)); |
213 | 229 |
|
214 | 230 | int main(int argc, char** argv) |
215 | 231 | { |
216 | 232 | using namespace o2::framework; |
217 | 233 |
|
218 | | - int result = callMain(argc, argv, mainNoCatch); |
| 234 | + int result = callMain(argc, argv, DPL_STRINGIZE(DPL_WORKFLOW_PLUGIN_LIBRARY) ":" DPL_STRINGIZE(DPL_WORKFLOW_PLUGIN_NAME), dpl_plugin_callback); |
219 | 235 |
|
220 | 236 | char* idstring = getIdString(argc, argv); |
221 | 237 | o2::framework::OnWorkflowTerminationHook onWorkflowTerminationHook; |
|
0 commit comments