Project
Loading...
Searching...
No Matches
test_MakeDPLObjects.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.
16#include <TH1F.h>
17#include <TNamed.h>
18#include <gsl/gsl>
19
20using namespace o2::framework;
21
22struct XYZ {
23 float x;
24 float y;
25 float z;
26};
27
29{
30 return WorkflowSpec{
32 "source",
33 Inputs{},
34 {OutputSpec{"TST", "HISTO"},
35 OutputSpec{"TST", "POINT"},
36 OutputSpec{"TST", "POINTS"},
37 OutputSpec{"TST", "VECTOR"},
38 OutputSpec{"TST", "LINEARIZED"},
39 OutputSpec{"TST", "OBJECT"}},
41 [](ProcessingContext& ctx) {
42 // A new message with 1 XYZ instance in it
43 auto& x = ctx.outputs().make<XYZ>(Output{"TST", "POINT", 0});
44 // A new message with a gsl::span<XYZ> with 1000 items
45 auto& y = ctx.outputs().make<XYZ>(Output{"TST", "POINTS", 0}, 1000);
46 y[0] = XYZ{1, 2, 3};
47 y[999] = XYZ{1, 2, 3};
48 // A new message with a TH1F inside
49 auto& h = ctx.outputs().make<TH1F>(Output{"TST", "HISTO"}, "h", "test", 100, -10., 10.);
50 // A snapshot for an std::vector
51 std::vector<XYZ> v{1000};
52 v[0] = XYZ{1, 2, 3};
53 v[999] = XYZ{1, 2, 3};
54 ctx.outputs().snapshot(Output{"TST", "VECTOR"}, v);
55 v[999] = XYZ{2, 3, 4};
56
57 // A snapshot for an std::vector of pointers to objects
58 // simply make a vector of pointers, snapshot will include the latest
59 // change, but not the one which is done after taking the snapshot
60 std::vector<XYZ*> p;
61 for (auto& i : v) {
62 p.push_back(&i);
63 }
64 ctx.outputs().snapshot(Output{"TST", "LINEARIZED"}, p);
65 v[999] = XYZ{3, 4, 5};
66
67 TNamed named("named", "a named test object");
68 ctx.outputs().snapshot(Output{"TST", "OBJECT"}, named);
69 }}},
71 "dest",
72 Inputs{
73 InputSpec{"point", "TST", "POINT"},
74 InputSpec{"points", "TST", "POINTS"},
75 InputSpec{"histo", "TST", "HISTO"},
76 InputSpec{"vector", "TST", "VECTOR"},
77 InputSpec{"linearized", "TST", "LINEARIZED"},
78 InputSpec{"object", "TST", "OBJECT"},
79 },
80 {},
82 [](ProcessingContext& ctx) {
83 // A new message with a TH1F inside
84 auto h = ctx.inputs().get<TH1F*>("histo");
85 // A new message with 1 XYZ instance in it
86 XYZ const& x = ctx.inputs().get<XYZ>("point");
87 // A new message with a gsl::span<XYZ> with 1000 items
88 auto ref1 = ctx.inputs().get("points");
89 gsl::span<XYZ> c = DataRefUtils::as<XYZ>(ref1);
90 assert(c[0].x == 1);
91 assert(c[0].y == 2);
92 assert(c[0].z == 3);
93 assert(c[999].x == 1);
94 assert(c[999].y == 2);
95 assert(c[999].z == 3);
96 auto ref2 = ctx.inputs().get("vector");
97 gsl::span<XYZ> c2 = DataRefUtils::as<XYZ>(ref2);
98 assert(c2[0].x == 1);
99 assert(c2[0].y == 2);
100 assert(c2[0].z == 3);
101 assert(c2[999].x == 1);
102 assert(c2[999].y == 2);
103 assert(c2[999].z == 3);
104 auto ref3 = ctx.inputs().get("linearized");
105 gsl::span<XYZ> c3 = DataRefUtils::as<XYZ>(ref3);
106 assert(c3[0].x == 1);
107 assert(c3[0].y == 2);
108 assert(c3[0].z == 3);
109 assert(c3[999].x == 2);
110 assert(c3[999].y == 3);
111 assert(c3[999].z == 4);
112 ctx.services().get<ControlService>().readyToQuit(QuitRequest::All);
113 auto o = ctx.inputs().get<TNamed*>("object");
114 assert(strcmp(o->GetName(), "named") == 0 &&
115 strcmp(o->GetTitle(), "a named test object") == 0);
116 }}}};
117}
int32_t i
bool o
bool const GPUTPCGMMerger::trackCluster const clcomparestruct * c2
uint32_t c
Definition RawData.h:2
Class for time synchronization of RawReader instances.
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< DataProcessorSpec > WorkflowSpec
std::vector< InputSpec > Inputs
WorkflowSpec defineDataProcessing(ConfigContext const &)
This function hooks up the the workflow specifications into the DPL driver.