Skip to content

Commit f044f6f

Browse files
committed
DPL: add simple helper to reproduce the calibration workflow
1 parent 97c3e51 commit f044f6f

File tree

5 files changed

+118
-3
lines changed

5 files changed

+118
-3
lines changed

Framework/TestWorkflows/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ o2_add_dpl_workflow(simple-sink
119119
SOURCES src/o2SimpleSink.cxx
120120
COMPONENT_NAME TestWorkflows)
121121

122+
o2_add_dpl_workflow(simple-processor
123+
SOURCES src/o2SimpleProcessor.cxx
124+
COMPONENT_NAME TestWorkflows)
125+
122126
o2_add_dpl_workflow(analysis-workflow
123127
SOURCES src/o2AnalysisWorkflow.cxx
124128
COMPONENT_NAME TestWorkflows)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#/bin/sh -ex
2+
export DPL_SIGNPOSTS="calibration"
3+
stage/bin/o2-dpl-raw-proxy --exit-transition-timeout 20 --data-processing-timeout 10 --dataspec "tst:TST/A/0" --channel-config "readout-proxy:address=tcp://0.0.0.0:4200,method=connect,type=pair" | \
4+
stage/bin/o2-testworkflows-simple-processor --exit-transition-timeout 20 --data-processing-timeout 10 --name reconstruction --processing-delay 5000 --eos-dataspec tst3:TST/C/0 --in-dataspec "tst2:TST/A/0" --out-dataspec "tst:TST/B/0" | \
5+
stage/bin/o2-testworkflows-simple-processor --exit-transition-timeout 20 --data-processing-timeout 10 --name calibration --processing-delay 1000 --in-dataspec "tst2:TST/C/0?lifetime=sporadic" --out-dataspec "tst:TCL/C/0?lifetime=sporadic" | \
6+
stage/bin/o2-testworkflows-simple-sink --exit-transition-timeout 20 --data-processing-timeout 10 --name calibration-publisher --dataspec "tst2:TCL/C/0?lifetime=sporadic" | \
7+
stage/bin/o2-testworkflows-simple-sink --exit-transition-timeout 20 --data-processing-timeout 10 --dataspec "tst:TST/B/0"
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
#include "Framework/ConfigParamSpec.h"
12+
#include "Framework/RawDeviceService.h"
13+
14+
#include <thread>
15+
#include <chrono>
16+
#include <vector>
17+
#include <fairmq/Device.h>
18+
19+
using namespace o2::framework;
20+
21+
void customize(std::vector<ConfigParamSpec>& workflowOptions)
22+
{
23+
workflowOptions.emplace_back(
24+
ConfigParamSpec{"in-dataspec", VariantType::String, "", {"DataSpec for the outputs"}});
25+
workflowOptions.emplace_back(
26+
ConfigParamSpec{"out-dataspec", VariantType::String, "", {"DataSpec for the outputs"}});
27+
workflowOptions.emplace_back(
28+
ConfigParamSpec{"eos-dataspec", VariantType::String, "", {"DataSpec for the outputs during EoS"}});
29+
workflowOptions.emplace_back(
30+
ConfigParamSpec{"processing-delay", VariantType::Int, 0, {"How long the processing takes"}});
31+
workflowOptions.emplace_back(
32+
ConfigParamSpec{"eos-delay", VariantType::Int, 0, {"How long the takes to do eos"}});
33+
workflowOptions.emplace_back(
34+
ConfigParamSpec{"name", VariantType::String, "test-processor", {"Name of the processor"}});
35+
}
36+
#include "Framework/runDataProcessing.h"
37+
38+
// This is how you can define your processing in a declarative way
39+
WorkflowSpec defineDataProcessing(ConfigContext const& ctx)
40+
{
41+
// Get the dataspec option and creates OutputSpecs from it
42+
auto inDataspec = ctx.options().get<std::string>("in-dataspec");
43+
auto outDataspec = ctx.options().get<std::string>("out-dataspec");
44+
// For data created at the End-Of-Stream
45+
auto eosDataspec = ctx.options().get<std::string>("eos-dataspec");
46+
47+
auto processingDelay = ctx.options().get<int>("processing-delay");
48+
auto eosDelay = ctx.options().get<int>("eos-delay");
49+
50+
std::vector<InputSpec> inputs = select(inDataspec.c_str());
51+
52+
for (auto& input : inputs) {
53+
LOGP(info, "{} : lifetime {}", DataSpecUtils::describe(input), (int)input.lifetime);
54+
}
55+
56+
std::vector<InputSpec> matchers = select(outDataspec.c_str());
57+
std::vector<std::string> outputRefs;
58+
std::vector<OutputSpec> outputs;
59+
60+
for (auto const& matcher : matchers) {
61+
outputRefs.emplace_back(matcher.binding);
62+
outputs.emplace_back(DataSpecUtils::asOutputSpec(matcher));
63+
}
64+
65+
std::vector<InputSpec> eosMatchers = select(eosDataspec.c_str());
66+
std::vector<std::string> eosRefs;
67+
std::vector<OutputSpec> eosOutputs;
68+
69+
for (auto const& matcher : eosMatchers) {
70+
eosRefs.emplace_back(matcher.binding);
71+
auto eosOut = DataSpecUtils::asOutputSpec(matcher);
72+
eosOut.lifetime = Lifetime::Sporadic;
73+
outputs.emplace_back(eosOut);
74+
}
75+
76+
AlgorithmSpec algo = adaptStateful([outputRefs, eosRefs, processingDelay, eosDelay](CallbackService& service) {
77+
service.set<o2::framework::CallbackService::Id::EndOfStream>([eosRefs, eosDelay](EndOfStreamContext&) {
78+
LOG(info) << "Creating objects on end of stream reception.";
79+
std::this_thread::sleep_for(std::chrono::seconds(eosDelay));
80+
});
81+
82+
return adaptStateless(
83+
[outputRefs, processingDelay](InputRecord& inputs, DataAllocator& outputs) {
84+
LOG(info) << "Received " << inputs.size() << " messages. Converting.";
85+
auto i = 0;
86+
std::this_thread::sleep_for(std::chrono::milliseconds(processingDelay));
87+
for (auto& ref : outputRefs) {
88+
LOGP(info, "Creating {}.", ref);
89+
outputs.make<int>(ref, ++i);
90+
}
91+
});
92+
});
93+
94+
return WorkflowSpec{
95+
{.name = ctx.options().get<std::string>("name"),
96+
.inputs = inputs,
97+
.outputs = outputs,
98+
.algorithm = algo}};
99+
}

Framework/TestWorkflows/src/o2SimpleSource.cxx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
2929
ConfigParamSpec{"name", VariantType::String, "test-source", {"Name of the source"}});
3030
workflowOptions.emplace_back(
3131
ConfigParamSpec{"timer", VariantType::String, "", {"What to use as timer intervals. Format is <period>:<validity since start>[, ...]"}});
32+
workflowOptions.emplace_back(
33+
ConfigParamSpec{"delay", VariantType::Int, 0, {"How long it takes to do the processing (in ms)"}});
3234
}
3335

3436
#include "Framework/runDataProcessing.h"
@@ -39,6 +41,8 @@ WorkflowSpec defineDataProcessing(ConfigContext const& ctx)
3941
// Get the dataspec option and creates OutputSpecs from it
4042
auto dataspec = ctx.options().get<std::string>("dataspec");
4143
auto timer = ctx.options().get<std::string>("timer");
44+
auto delay = ctx.options().get<int>("delay");
45+
4246
std::vector<InputSpec> inputs;
4347
std::vector<TimerSpec> timers;
4448
if (timer.empty() == false) {
@@ -74,13 +78,14 @@ WorkflowSpec defineDataProcessing(ConfigContext const& ctx)
7478
.inputs = inputs,
7579
.outputs = outputSpecs,
7680
.algorithm = AlgorithmSpec{adaptStateful(
77-
[outputSpecs](ConfigParamRegistry const& options) {
81+
[outputSpecs, delay](ConfigParamRegistry const& options) {
7882
// the size of the messages is also a workflow option
7983
auto dataSize = options.get<int64_t>("data-size");
8084
return adaptStateless(
81-
[outputSpecs, dataSize](DataAllocator& outputs, ProcessingContext& ctx) {
85+
[outputSpecs, dataSize, delay](DataAllocator& outputs, ProcessingContext& ctx) {
8286
for (auto const& output : outputSpecs) {
8387
auto concrete = DataSpecUtils::asConcreteDataMatcher(output);
88+
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
8489
outputs.make<char>(Output{concrete.origin, concrete.description, concrete.subSpec}, dataSize);
8590
}
8691
});

Framework/Utils/src/raw-proxy.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
2929

3030
workflowOptions.push_back(
3131
ConfigParamSpec{
32-
"dataspec", VariantType::String, "A:FLP/RAWDATA;B:FLP/DISTSUBTIMEFRAME/0", {"selection string for the data to be proxied"}});
32+
"dataspec", VariantType::String, "tst:TST/A", {"selection string for the data to be proxied"}});
3333

3434
workflowOptions.push_back(
3535
ConfigParamSpec{

0 commit comments

Comments
 (0)