Logo ROOT  
Reference Guide
RTrivialDS.cxx
Go to the documentation of this file.
1#include <ROOT/RDF/Utils.hxx>
2#include <ROOT/TSeq.hxx>
3#include <ROOT/RTrivialDS.hxx>
5#include <TError.h>
6
7namespace ROOT {
8
9namespace RDF {
10
11std::vector<void *> RTrivialDS::GetColumnReadersImpl(std::string_view, const std::type_info &ti)
12{
13 // We know we have only one column and that it's holding ULong64_t's
14 if (ti != typeid(ULong64_t)) {
15 throw std::runtime_error("The type specified for the column \"col0\" is not ULong64_t.");
16 }
17 std::vector<void *> ret;
18 for (auto i : ROOT::TSeqU(fNSlots)) {
19 fCounterAddr[i] = &fCounter[i];
20 ret.emplace_back((void *)(&fCounterAddr[i]));
21 }
22 return ret;
23}
24
25RTrivialDS::RTrivialDS(ULong64_t size, bool skipEvenEntries) : fSize(size), fSkipEvenEntries(skipEvenEntries)
26{
27}
28
30{
31}
32
33const std::vector<std::string> &RTrivialDS::GetColumnNames() const
34{
35 return fColNames;
36}
37
39{
40 return colName == fColNames[0];
41}
42
44{
45 return "ULong64_t";
46}
47
48std::vector<std::pair<ULong64_t, ULong64_t>> RTrivialDS::GetEntryRanges()
49{
50 auto ranges(std::move(fEntryRanges)); // empty fEntryRanges
51 return ranges;
52}
53
54bool RTrivialDS::SetEntry(unsigned int slot, ULong64_t entry)
55{
56 if (fSkipEvenEntries && 0 == entry % 2) {
57 return false;
58 }
59 fCounter[slot] = entry;
60 return true;
61}
62
63void RTrivialDS::SetNSlots(unsigned int nSlots)
64{
65 R__ASSERT(0U == fNSlots && "Setting the number of slots even if the number of slots is different from zero.");
66
67 fNSlots = nSlots;
68 fCounter.resize(fNSlots);
69 fCounterAddr.resize(fNSlots);
70}
71
73{
74 const auto chunkSize = fSize / fNSlots;
75 auto start = 0UL;
76 auto end = 0UL;
77 for (auto i : ROOT::TSeqUL(fNSlots)) {
78 start = end;
79 end += chunkSize;
80 fEntryRanges.emplace_back(start, end);
81 (void)i;
82 }
83 // TODO: redistribute reminder to all slots
84 fEntryRanges.back().second += fSize % fNSlots;
85}
86
88{
89 return "TrivialDS";
90}
91
93{
94 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(size, skipEvenEntries),
95 RDFInternal::ColumnNames_t{});
97}
98
99} // ns RDF
100
101} // ns ROOT
size_t fSize
unsigned long long ULong64_t
Definition: RtypesCore.h:72
#define R__ASSERT(e)
Definition: TError.h:96
typedef void((*Func_t)())
The public interface to the RDataFrame federation of classes.
Definition: RInterface.hxx:89
std::string GetLabel()
Return a string representation of the datasource type.
Definition: RTrivialDS.cxx:87
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
Definition: RTrivialDS.cxx:48
void Initialise()
Convenience method called before starting an event-loop.
Definition: RTrivialDS.cxx:72
std::vector< void * > GetColumnReadersImpl(std::string_view name, const std::type_info &)
type-erased vector of pointers to pointers to column values - one per slot
Definition: RTrivialDS.cxx:11
bool SetEntry(unsigned int slot, ULong64_t entry)
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
Definition: RTrivialDS.cxx:54
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
Definition: RTrivialDS.hxx:26
bool HasColumn(std::string_view colName) const
Checks if the dataset has a certain column.
Definition: RTrivialDS.cxx:38
std::vector< ULong64_t * > fCounterAddr
Definition: RTrivialDS.hxx:29
std::vector< ULong64_t > fCounter
Definition: RTrivialDS.hxx:28
std::vector< std::string > fColNames
Definition: RTrivialDS.hxx:27
unsigned int fNSlots
Definition: RTrivialDS.hxx:23
RTrivialDS(ULong64_t size, bool skipEvenEntries=false)
Definition: RTrivialDS.cxx:25
const std::vector< std::string > & GetColumnNames() const
Returns a reference to the collection of the dataset's column names.
Definition: RTrivialDS.cxx:33
void SetNSlots(unsigned int nSlots)
Inform RDataSource of the number of processing slots (i.e.
Definition: RTrivialDS.cxx:63
std::string GetTypeName(std::string_view) const
Type of a column as a string, e.g.
Definition: RTrivialDS.cxx:43
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
basic_string_view< char > string_view
RInterface< RDFDetail::RLoopManager, RTrivialDS > MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries=false)
Definition: RTrivialDS.cxx:92
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21