Skip to content

Commit e225314

Browse files
authored
DPL: First step in making inputs/outputs optional
1 parent dc7a581 commit e225314

5 files changed

Lines changed: 145 additions & 16 deletions

File tree

‎Framework/Core/include/Framework/InputSpec.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ struct InputSpec {
7272

7373
enum Lifetime lifetime;
7474

75+
/// Whether the input is enabled. Disabled inputs are optional inputs
76+
/// which are not going to be used.
77+
bool enabled = true;
78+
7579
/// A set of configurables which can be used to customise the InputSpec.
7680
std::vector<ConfigParamSpec> metadata;
7781

‎Framework/Core/include/Framework/OutputSpec.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ struct OutputSpec {
3636
std::variant<ConcreteDataMatcher, ConcreteDataTypeMatcher> matcher;
3737
#endif
3838
enum Lifetime lifetime = Lifetime::Timeframe;
39+
/// Whether the output is enabled. Disabled outputs are optional outputs
40+
/// which are not going to be produced.
41+
bool enabled = true;
3942

4043
/// Build a fully qualified tuple for the OutputSpec
4144
OutputSpec(OutputLabel const& inBinding, header::DataOrigin inOrigin, header::DataDescription inDescription,

‎Framework/Core/src/WorkflowSerializationHelpers.cxx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
6666
IN_INPUT_DESCRIPTION_REF,
6767
IN_INPUT_SUBSPEC_REF,
6868
IN_INPUT_LIFETIME,
69+
IN_INPUT_ENABLED,
6970
IN_INPUT_STARTTIME,
7071
IN_INPUT_MATCHER,
7172
IN_INPUT_MATCHER_OPERATION,
@@ -78,6 +79,7 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
7879
IN_OUTPUT_DESCRIPTION,
7980
IN_OUTPUT_SUBSPEC,
8081
IN_OUTPUT_LIFETIME,
82+
IN_OUTPUT_ENABLED,
8183
IN_OUTPUT_OPTIONS,
8284
IN_OPTION,
8385
IN_OPTION_NAME,
@@ -192,6 +194,9 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
192194
case State::IN_INPUT_LIFETIME:
193195
s << "IN_INPUT_LIFETIME";
194196
break;
197+
case State::IN_INPUT_ENABLED:
198+
s << "IN_INPUT_ENABLED";
199+
break;
195200
case State::IN_INPUT_STARTTIME:
196201
s << "IN_INPUT_STARTTIME";
197202
break;
@@ -216,6 +221,9 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
216221
case State::IN_OUTPUT_LIFETIME:
217222
s << "IN_OUTPUT_LIFETIME";
218223
break;
224+
case State::IN_OUTPUT_ENABLED:
225+
s << "IN_OUTPUT_ENABLED";
226+
break;
219227
case State::IN_OUTPUT_OPTIONS:
220228
s << "IN_OUTPUT_OPTIONS";
221229
break;
@@ -371,6 +379,9 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
371379
} else {
372380
dataProcessors.back().inputs.push_back(InputSpec({binding}, std::move(*matcher), lifetime, inputOptions));
373381
}
382+
dataProcessors.back().inputs.back().enabled = enabled;
383+
// "enabled" is optional in the JSON, so reset to the default
384+
enabled = true;
374385
inputMatcherNodes.clear();
375386
inputOptions.clear();
376387

@@ -434,6 +445,9 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
434445
} else {
435446
dataProcessors.back().outputs.push_back(OutputSpec({binding}, {origin, description}, lifetime, outputOptions));
436447
}
448+
dataProcessors.back().outputs.back().enabled = enabled;
449+
// "enabled" is optional in the JSON, so reset to the default
450+
enabled = true;
437451
outputOptions.clear();
438452
outputHasSubSpec = false;
439453
} else if (in(State::IN_OPTION)) {
@@ -649,6 +663,8 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
649663
push(State::IN_INPUT_STARTTIME);
650664
} else if (in(State::IN_INPUT) && strncmp(str, "lifetime", length) == 0) {
651665
push(State::IN_INPUT_LIFETIME);
666+
} else if (in(State::IN_INPUT) && strncmp(str, "enabled", length) == 0) {
667+
push(State::IN_INPUT_ENABLED);
652668
} else if (in(State::IN_INPUT) && strncmp(str, "starttime", length) == 0) {
653669
push(State::IN_INPUT_STARTTIME);
654670
} else if (in(State::IN_INPUT) && strncmp(str, "metadata", length) == 0) {
@@ -664,6 +680,8 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
664680
outputHasSubSpec = true;
665681
} else if (in(State::IN_OUTPUT) && strncmp(str, "lifetime", length) == 0) {
666682
push(State::IN_OUTPUT_LIFETIME);
683+
} else if (in(State::IN_OUTPUT) && strncmp(str, "enabled", length) == 0) {
684+
push(State::IN_OUTPUT_ENABLED);
667685
} else if (in(State::IN_OUTPUT) && strncmp(str, "metadata", length) == 0) {
668686
push(State::IN_OUTPUT_OPTIONS);
669687
} else if (in(State::IN_DATAPROCESSOR) && strncmp(str, "name", length) == 0) {
@@ -848,6 +866,18 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
848866
return true;
849867
}
850868

869+
bool Bool(bool b)
870+
{
871+
O2_SIGNPOST_EVENT_EMIT(workflow_importer, _o2_signpost_id_t{(int64_t)states.size()}, "import", "Bool(%s)", b ? "true" : "false");
872+
if (in(State::IN_INPUT_ENABLED)) {
873+
enabled = b;
874+
} else if (in(State::IN_OUTPUT_ENABLED)) {
875+
enabled = b;
876+
}
877+
pop();
878+
return true;
879+
}
880+
851881
bool Int(int i)
852882
{
853883
O2_SIGNPOST_EVENT_EMIT(workflow_importer, _o2_signpost_id_t{(int64_t)states.size()}, "import", "Int(%d)", i);
@@ -918,6 +948,7 @@ struct WorkflowImporter : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
918948
size_t subspec;
919949
size_t ref;
920950
Lifetime lifetime;
951+
bool enabled = true;
921952
std::string metadatumKey;
922953
std::string metadatumValue;
923954
std::string optionName;
@@ -1117,6 +1148,8 @@ void WorkflowSerializationHelpers::dump(std::ostream& out,
11171148
}
11181149
w.Key("lifetime");
11191150
w.Uint((int)input.lifetime);
1151+
w.Key("enabled");
1152+
w.Bool(input.enabled);
11201153
if (input.metadata.empty() == false) {
11211154
w.Key("metadata");
11221155
w.StartArray();
@@ -1166,6 +1199,8 @@ void WorkflowSerializationHelpers::dump(std::ostream& out,
11661199
}
11671200
w.Key("lifetime");
11681201
w.Uint((int)output.lifetime);
1202+
w.Key("enabled");
1203+
w.Bool(output.enabled);
11691204
if (output.metadata.empty() == false) {
11701205
w.Key("metadata");
11711206
w.StartArray();

‎Framework/Core/test/test_FrameworkDataFlowToDDS.cxx‎

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,16 @@ TEST_CASE("TestDDS")
169169
&quot;origin&quot;: &quot;TST&quot;,
170170
&quot;description&quot;: &quot;A1&quot;,
171171
&quot;subspec&quot;: 0,
172-
&quot;lifetime&quot;: 0
172+
&quot;lifetime&quot;: 0,
173+
&quot;enabled&quot;: true
173174
},
174175
{
175176
&quot;binding&quot;: &quot;TST/A2/0&quot;,
176177
&quot;origin&quot;: &quot;TST&quot;,
177178
&quot;description&quot;: &quot;A2&quot;,
178179
&quot;subspec&quot;: 0,
179-
&quot;lifetime&quot;: 0
180+
&quot;lifetime&quot;: 0,
181+
&quot;enabled&quot;: true
180182
}
181183
],
182184
&quot;options&quot;: [],
@@ -195,7 +197,8 @@ TEST_CASE("TestDDS")
195197
&quot;origin&quot;: &quot;TST&quot;,
196198
&quot;description&quot;: &quot;A1&quot;,
197199
&quot;subspec&quot;: 0,
198-
&quot;lifetime&quot;: 0
200+
&quot;lifetime&quot;: 0,
201+
&quot;enabled&quot;: true
199202
}
200203
],
201204
&quot;outputs&quot;: [
@@ -204,7 +207,8 @@ TEST_CASE("TestDDS")
204207
&quot;origin&quot;: &quot;TST&quot;,
205208
&quot;description&quot;: &quot;B1&quot;,
206209
&quot;subspec&quot;: 0,
207-
&quot;lifetime&quot;: 0
210+
&quot;lifetime&quot;: 0,
211+
&quot;enabled&quot;: true
208212
}
209213
],
210214
&quot;options&quot;: [],
@@ -223,7 +227,8 @@ TEST_CASE("TestDDS")
223227
&quot;origin&quot;: &quot;TST&quot;,
224228
&quot;description&quot;: &quot;A2&quot;,
225229
&quot;subspec&quot;: 0,
226-
&quot;lifetime&quot;: 0
230+
&quot;lifetime&quot;: 0,
231+
&quot;enabled&quot;: true
227232
}
228233
],
229234
&quot;outputs&quot;: [
@@ -232,7 +237,8 @@ TEST_CASE("TestDDS")
232237
&quot;origin&quot;: &quot;TST&quot;,
233238
&quot;description&quot;: &quot;C1&quot;,
234239
&quot;subspec&quot;: 0,
235-
&quot;lifetime&quot;: 0
240+
&quot;lifetime&quot;: 0,
241+
&quot;enabled&quot;: true
236242
}
237243
],
238244
&quot;options&quot;: [],
@@ -251,14 +257,16 @@ TEST_CASE("TestDDS")
251257
&quot;origin&quot;: &quot;TST&quot;,
252258
&quot;description&quot;: &quot;B1&quot;,
253259
&quot;subspec&quot;: 0,
254-
&quot;lifetime&quot;: 0
260+
&quot;lifetime&quot;: 0,
261+
&quot;enabled&quot;: true
255262
},
256263
{
257264
&quot;binding&quot;: &quot;y&quot;,
258265
&quot;origin&quot;: &quot;TST&quot;,
259266
&quot;description&quot;: &quot;C1&quot;,
260267
&quot;subspec&quot;: 0,
261-
&quot;lifetime&quot;: 0
268+
&quot;lifetime&quot;: 0,
269+
&quot;enabled&quot;: true
262270
}
263271
],
264272
&quot;outputs&quot;: [],
@@ -434,14 +442,16 @@ TEST_CASE("TestDDSExpendable")
434442
&quot;origin&quot;: &quot;TST&quot;,
435443
&quot;description&quot;: &quot;A1&quot;,
436444
&quot;subspec&quot;: 0,
437-
&quot;lifetime&quot;: 0
445+
&quot;lifetime&quot;: 0,
446+
&quot;enabled&quot;: true
438447
},
439448
{
440449
&quot;binding&quot;: &quot;TST/A2/0&quot;,
441450
&quot;origin&quot;: &quot;TST&quot;,
442451
&quot;description&quot;: &quot;A2&quot;,
443452
&quot;subspec&quot;: 0,
444-
&quot;lifetime&quot;: 0
453+
&quot;lifetime&quot;: 0,
454+
&quot;enabled&quot;: true
445455
}
446456
],
447457
&quot;options&quot;: [],
@@ -460,7 +470,8 @@ TEST_CASE("TestDDSExpendable")
460470
&quot;origin&quot;: &quot;TST&quot;,
461471
&quot;description&quot;: &quot;A1&quot;,
462472
&quot;subspec&quot;: 0,
463-
&quot;lifetime&quot;: 0
473+
&quot;lifetime&quot;: 0,
474+
&quot;enabled&quot;: true
464475
}
465476
],
466477
&quot;outputs&quot;: [
@@ -469,7 +480,8 @@ TEST_CASE("TestDDSExpendable")
469480
&quot;origin&quot;: &quot;TST&quot;,
470481
&quot;description&quot;: &quot;B1&quot;,
471482
&quot;subspec&quot;: 0,
472-
&quot;lifetime&quot;: 0
483+
&quot;lifetime&quot;: 0,
484+
&quot;enabled&quot;: true
473485
}
474486
],
475487
&quot;options&quot;: [],
@@ -488,7 +500,8 @@ TEST_CASE("TestDDSExpendable")
488500
&quot;origin&quot;: &quot;TST&quot;,
489501
&quot;description&quot;: &quot;A2&quot;,
490502
&quot;subspec&quot;: 0,
491-
&quot;lifetime&quot;: 0
503+
&quot;lifetime&quot;: 0,
504+
&quot;enabled&quot;: true
492505
}
493506
],
494507
&quot;outputs&quot;: [
@@ -497,7 +510,8 @@ TEST_CASE("TestDDSExpendable")
497510
&quot;origin&quot;: &quot;TST&quot;,
498511
&quot;description&quot;: &quot;C1&quot;,
499512
&quot;subspec&quot;: 0,
500-
&quot;lifetime&quot;: 0
513+
&quot;lifetime&quot;: 0,
514+
&quot;enabled&quot;: true
501515
}
502516
],
503517
&quot;options&quot;: [],
@@ -516,14 +530,16 @@ TEST_CASE("TestDDSExpendable")
516530
&quot;origin&quot;: &quot;TST&quot;,
517531
&quot;description&quot;: &quot;B1&quot;,
518532
&quot;subspec&quot;: 0,
519-
&quot;lifetime&quot;: 0
533+
&quot;lifetime&quot;: 0,
534+
&quot;enabled&quot;: true
520535
},
521536
{
522537
&quot;binding&quot;: &quot;y&quot;,
523538
&quot;origin&quot;: &quot;TST&quot;,
524539
&quot;description&quot;: &quot;C1&quot;,
525540
&quot;subspec&quot;: 0,
526-
&quot;lifetime&quot;: 0
541+
&quot;lifetime&quot;: 0,
542+
&quot;enabled&quot;: true
527543
}
528544
],
529545
&quot;outputs&quot;: [],

‎Framework/Core/test/test_WorkflowSerialization.cxx‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Framework/WorkflowSpec.h"
1313
#include "../src/WorkflowSerializationHelpers.h"
1414
#include <catch_amalgamated.hpp>
15+
#include <regex>
1516

1617
using namespace o2::framework;
1718

@@ -169,3 +170,73 @@ TEST_CASE("TestInputOutputSpecMetadata")
169170
REQUIRE(wso[0].outputs[0].metadata[0] == wsi[0].outputs[0].metadata[0]);
170171
REQUIRE(wso[0].outputs[0].metadata[1] == wsi[0].outputs[0].metadata[1]);
171172
}
173+
174+
TEST_CASE("TestInputOutputSpecEnabled")
175+
{
176+
InputSpec i1{"i1", "TST", "INPUT1", 0};
177+
InputSpec i2{"i2", "TST", "INPUT2", 1};
178+
i2.enabled = false;
179+
// wildcard on subspec, imported via the DataDescriptorMatcher path
180+
InputSpec i3{"i3", ConcreteDataTypeMatcher{"TST", "INPUT3"}};
181+
i3.enabled = false;
182+
OutputSpec o1{OutputLabel{"o1"}, "TST", "OUTPUT1", 0};
183+
OutputSpec o2{OutputLabel{"o2"}, ConcreteDataTypeMatcher{"TST", "OUTPUT2"}};
184+
o2.enabled = false;
185+
OutputSpec o3{OutputLabel{"o3"}, "TST", "OUTPUT3", 3};
186+
o3.enabled = false;
187+
188+
WorkflowSpec wso{
189+
DataProcessorSpec{
190+
.name = "S1",
191+
.inputs = {i1, i2, i3},
192+
.outputs = {o1, o2, o3}}};
193+
194+
std::vector<DataProcessorInfo> dataProcessorInfoOut{
195+
{.name = "S1", .executable = "test_Framework_test_SerializationWorkflow"},
196+
};
197+
CommandInfo commandInfoOut{"o2-dpl-workflow -b"};
198+
199+
std::ostringstream firstDump;
200+
WorkflowSerializationHelpers::dump(firstDump, wso, dataProcessorInfoOut, commandInfoOut);
201+
202+
std::vector<DataProcessorInfo> dataProcessorInfoIn{};
203+
CommandInfo commandInfoIn;
204+
std::istringstream is;
205+
is.str(firstDump.str());
206+
WorkflowSpec wsi;
207+
REQUIRE(WorkflowSerializationHelpers::import(is, wsi, dataProcessorInfoIn, commandInfoIn));
208+
209+
REQUIRE(wsi.size() == 1);
210+
REQUIRE(wsi[0].inputs.size() == wso[0].inputs.size());
211+
REQUIRE(wsi[0].outputs.size() == wso[0].outputs.size());
212+
for (size_t i = 0; i < wso[0].inputs.size(); ++i) {
213+
REQUIRE(wsi[0].inputs[i].enabled == wso[0].inputs[i].enabled);
214+
}
215+
for (size_t i = 0; i < wso[0].outputs.size(); ++i) {
216+
REQUIRE(wsi[0].outputs[i].enabled == wso[0].outputs[i].enabled);
217+
}
218+
219+
std::ostringstream secondDump;
220+
WorkflowSerializationHelpers::dump(secondDump, wsi, dataProcessorInfoIn, commandInfoIn);
221+
REQUIRE(firstDump.str() == secondDump.str());
222+
223+
// Backward compatibility: a JSON without the "enabled" key
224+
// must import everything as enabled.
225+
auto legacy = std::regex_replace(firstDump.str(), std::regex(R"(,\s*"enabled":\s*(true|false))"), "");
226+
REQUIRE(legacy.find("\"enabled\"") == std::string::npos);
227+
std::istringstream lis;
228+
lis.str(legacy);
229+
WorkflowSpec wsl;
230+
std::vector<DataProcessorInfo> dataProcessorInfoLegacy{};
231+
CommandInfo commandInfoLegacy;
232+
REQUIRE(WorkflowSerializationHelpers::import(lis, wsl, dataProcessorInfoLegacy, commandInfoLegacy));
233+
REQUIRE(wsl.size() == 1);
234+
REQUIRE(wsl[0].inputs.size() == wso[0].inputs.size());
235+
REQUIRE(wsl[0].outputs.size() == wso[0].outputs.size());
236+
for (auto const& input : wsl[0].inputs) {
237+
REQUIRE(input.enabled);
238+
}
239+
for (auto const& output : wsl[0].outputs) {
240+
REQUIRE(output.enabled);
241+
}
242+
}

0 commit comments

Comments
 (0)