Project
Loading...
Searching...
No Matches
test_ProcessorOptions.cxx
Go to the documentation of this file.
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.
14#include "Framework/Logger.h"
15
16#include <memory>
17
18using namespace o2::framework;
19
20#define ASSERT_ERROR(condition) \
21 if ((condition) == false) { \
22 LOG(fatal) << R"(Test condition ")" #condition R"(" failed at )" << __FILE__ << ":" << __LINE__; \
23 }
24
25// This is how you can define your processing in a declarative way
27{
28 return WorkflowSpec{
30 "producer",
31 Inputs{},
32 {
33 OutputSpec{"TST", "TEST"},
34 },
36 // define init callback
37 [](InitContext& ic) {
38 auto configstring = ic.options().get<std::string>("global-config");
39 // read back the option from the command line, see CMakeLists.txt
40 ASSERT_ERROR(configstring == "require-me");
41
42 return [isReady = std::make_shared<bool>(false)](ProcessingContext& ctx) {
43 if (*isReady == true) {
44 return;
45 }
46 // there is nothing to do, simply stop the workflow but we have to send at least one message
47 // to make sure that the callback of the consumer is called
48 ctx.outputs().make<int>(Output{"TST", "TEST", 0}) = 42;
49 ctx.services().get<ControlService>().endOfStream();
50 *isReady = true;
51 };
52 },
53 },
54 {
55 ConfigParamSpec{"channel-config",
56 VariantType::String,
57 "name=foo,type=sub,method=connect,address=tcp://localhost:5450,rateLogging=1",
58 {"Out-of-band channel config"}},
59 ConfigParamSpec{"global-config", VariantType::String, {"A global config option for all processor specs"}},
60 },
61 },
63 "consumer",
64 Inputs{
65 InputSpec{"in", "TST", "TEST"},
66 },
67 {},
69 // define an init callback
70 [](InitContext& ic) {
71 // read back the option from the command line, see CMakeLists.txt
72 auto configstring = ic.options().get<std::string>("global-config");
73 auto anotheroption = ic.options().get<std::string>("local-option");
74 auto aBoolean = ic.options().get<bool>("a-boolean");
75 auto aBoolean2 = ic.options().get<bool>("a-boolean2");
76 auto aBoolean3 = ic.options().get<bool>("a-boolean3");
77 auto anInt = ic.options().get<int>("an-int");
78 auto anInt2 = ic.options().get<int>("an-int2");
79 auto anInt64 = ic.options().get<int64_t>("an-int64");
80 auto anInt64_2 = ic.options().get<int64_t>("an-int64-2");
81 auto aDouble = ic.options().get<double>("a-double");
82 auto aDouble2 = ic.options().get<double>("a-double2");
83
84 ASSERT_ERROR(aBoolean == true);
85 ASSERT_ERROR(aBoolean2 == false);
86 ASSERT_ERROR(aBoolean3 == true);
87 ASSERT_ERROR(anInt == 10);
88 ASSERT_ERROR(anInt2 == 20);
89 ASSERT_ERROR(anInt64 == 1ll);
90 ASSERT_ERROR(anInt64_2 == 50000000000000ll);
91 ASSERT_ERROR(aDouble == 11.);
92 ASSERT_ERROR(aDouble2 == 22.);
93 ASSERT_ERROR(configstring == "consumer-config");
94 ASSERT_ERROR(anotheroption == "hello-aliceo2");
95
96 auto data = std::make_shared<int>(0);
97 ic.services().get<CallbackService>().set<CallbackService::Id::EndOfStream>(
98 [data](EndOfStreamContext& context) {
99 ASSERT_ERROR(*data == 42);
100 });
101 return [data](ProcessingContext& ctx) {
102 // there is nothing to do, simply stop the workflow
103 *data = ctx.inputs().get<int>("in");
104 };
105 },
106 },
107 {
108 ConfigParamSpec{"global-config", VariantType::String, {"A global config option for all processor specs"}},
109 ConfigParamSpec{"local-option", VariantType::String, {"Option only valid for this processor spec"}},
110 ConfigParamSpec{"a-boolean", VariantType::Bool, true, {"A boolean which we pick by default"}},
111 ConfigParamSpec{"a-boolean2", VariantType::Bool, false, {"Another boolean which we pick by default"}},
112 ConfigParamSpec{"a-boolean3", VariantType::Bool, false, {"Another boolean which we pick from the outside options"}},
113 ConfigParamSpec{"an-int", VariantType::Int, 10, {"An int for which we pick up the default"}},
114 ConfigParamSpec{"an-int2", VariantType::Int, 1, {"An int for which we pick up the override"}},
115 ConfigParamSpec{"an-int64", VariantType::Int64, 1ll, {"An int64 for which we pick up the default"}},
116 ConfigParamSpec{"an-int64-2", VariantType::Int64, 2ll, {"An int64 for which we pick up the override"}},
117 ConfigParamSpec{"a-double", VariantType::Double, 11., {"A double for which we pick up the override"}},
118 ConfigParamSpec{"a-double2", VariantType::Double, 12., {"A double for which we pick up the override"}},
119 },
120 }};
121}
GLboolean * data
Definition glcorearb.h:298
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< DataProcessorSpec > WorkflowSpec
std::vector< InputSpec > Inputs
#define ASSERT_ERROR(condition)
WorkflowSpec defineDataProcessing(ConfigContext const &)
This function hooks up the the workflow specifications into the DPL driver.