Project
Loading...
Searching...
No Matches
test_SimpleRDataFrameProcessing.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 "Framework/Logger.h"
21#include <Monitoring/Monitoring.h>
22#include <ROOT/RDataFrame.hxx>
23#include <ROOT/RArrowDS.hxx>
24#include <memory>
25
26using namespace o2::framework;
27
30{
31 return WorkflowSpec{
32 //
34 "rdataframe_producer", //
35 Inputs{}, //
36 {
37 OutputSpec{{"xz"}, "TES", "RFRAME"}, //
38 },
40 // We ask the framework for something which can build a Table
41 auto out = outputs.make<TableBuilder>(Output{"TES", "RFRAME"});
42 // We use RDataFrame to create a few columns with 100 rows.
43 // The final action is the one which allows the user to create the
44 // output message.
45 //
46 // FIXME: bloat in the code I'd like to get rid of:
47 //
48 // * I need to specify the types for the columns
49 // * I need to specify the names of the columns twice
50 ROOT::RDataFrame rdf(100);
51 auto t = rdf.Define("x", "1.f")
52 .Define("y", "2.f")
53 .Define("z", "x+y");
54 t.ForeachSlot(out->persist<float, float>({"x", "z"}), {"x", "z"});
55 })} //
56 }, //
58 "rdataframe_consumer", //
59 {
60 InputSpec{"xz", "TES", "RFRAME"}, //
61 }, //
62 Outputs{}, //
65 [](InputRecord& inputs, ControlService& control) {
67 auto s = inputs.get<TableConsumer>("xz");
68
74 auto table = s->asArrowTable();
75 if (table->num_rows() != 100) {
76 LOG(error) << "Wrong number of entries for the arrow table" << table->num_rows();
77 }
78
79 if (table->num_columns() != 2) {
80 LOG(error) << "Wrong number of columns for the arrow table" << table->num_columns();
81 }
82
83 auto source = std::make_unique<ROOT::RDF::RArrowDS>(s->asArrowTable(), std::vector<std::string>{});
84 ROOT::RDataFrame rdf(std::move(source));
85
86 if (*rdf.Count() != 100) {
87 LOG(error) << "Wrong number of entries for the DataFrame" << *rdf.Count();
88 }
89
90 if (*rdf.Mean("z") - 3.f > 0.1f) {
91 LOG(error) << "Wrong average for z";
92 }
93
94 control.readyToQuit(QuitRequest::All);
95 }) //
96 } //
97 } //
98 };
99}
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
char error[CURL_ERROR_SIZE]
void readyToQuit(bool all)
Compatibility with old API.
decltype(auto) make(const Output &spec, Args... args)
The input API of the Data Processing Layer This class holds the inputs which are valid for processing...
decltype(auto) get(R binding, int part=0) const
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< DataProcessorSpec > WorkflowSpec
AlgorithmSpec::ProcessCallback adaptStateless(LAMBDA l)
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
WorkflowSpec defineDataProcessing(ConfigContext const &)
Example of how to use ROOT::RDataFrame using DPL.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"