Project
Loading...
Searching...
No Matches
test_AlgorithmWrapper.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.
18#include <Monitoring/Monitoring.h>
19
20using namespace o2::framework;
21
23 float x;
24 float y;
25 float z;
26 float q;
27};
28
29struct Summary {
32};
33
34static bool wrapperCalled = false;
35
36// This is how you can define your processing in a declarative way
37std::vector<DataProcessorSpec> defineDataProcessing(ConfigContext const&)
38{
39 auto algo = adaptStateless([](DataAllocator& outputs, ControlService& control, RawDeviceService& service) {
40 assert(wrapperCalled == true);
41 // Creates a new message of size 1000 which
42 // has "TPC" as data origin and "CLUSTERS" as data description.
43 auto& tpcClusters = outputs.make<FakeCluster>(Output{"TPC", "CLUSTERS", 0}, 1000);
44 int i = 0;
45
46 for (auto& cluster : tpcClusters) {
47 assert(i < 1000);
48 cluster.x = i;
49 cluster.y = i;
50 cluster.z = i;
51 cluster.q = i;
52 i++;
53 }
54
55 auto& itsClusters = outputs.make<FakeCluster>(Output{"ITS", "CLUSTERS", 0}, 1000);
56 i = 0;
57 for (auto& cluster : itsClusters) {
58 assert(i < 1000);
59 cluster.x = i;
60 cluster.y = i;
61 cluster.z = i;
62 cluster.q = i;
63 i++;
64 }
65 control.readyToQuit(QuitRequest::All);
66 });
67
68 auto realAlgo = PluginManager::wrapAlgorithm(algo, [](AlgorithmSpec::ProcessCallback& callback, ProcessingContext& ctx) -> void {
69 wrapperCalled = true;
70 callback(ctx);
71 });
72
73 assert(wrapperCalled == false);
74 return {
76 "simple",
77 Inputs{},
78 {OutputSpec{"TPC", "CLUSTERS"},
79 OutputSpec{"ITS", "CLUSTERS"}},
80 realAlgo}};
81}
int32_t i
void readyToQuit(bool all)
Compatibility with old API.
decltype(auto) make(const Output &spec, Args... args)
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
AlgorithmSpec::ProcessCallback adaptStateless(LAMBDA l)
std::vector< InputSpec > Inputs
std::function< void(ProcessingContext &)> ProcessCallback
static auto wrapAlgorithm(AlgorithmSpec const &spec, WrapperProcessCallback &&wrapper) -> AlgorithmSpec
std::vector< DataProcessorSpec > defineDataProcessing(ConfigContext const &)
This function hooks up the the workflow specifications into the DPL driver.