Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
7#include <limits>
8
9namespace ROOT {
10
11namespace RDF {
12
13std::vector<void *> RTrivialDS::GetColumnReadersImpl(std::string_view, const std::type_info &ti)
14{
15 // We know we have only one column and that it's holding ULong64_t's
16 if (ti != typeid(ULong64_t)) {
17 throw std::runtime_error("The type specified for the column \"col0\" is not ULong64_t.");
18 }
19 std::vector<void *> ret;
20 for (auto i : ROOT::TSeqU(fNSlots)) {
21 fCounterAddr[i] = &fCounter[i];
22 ret.emplace_back((void *)(&fCounterAddr[i]));
23 }
24 return ret;
25}
26
27RTrivialDS::RTrivialDS(ULong64_t size, bool skipEvenEntries) : fSize(size), fSkipEvenEntries(skipEvenEntries)
28{
29}
30
31RTrivialDS::RTrivialDS() : fSize(std::numeric_limits<ULong64_t>::max()), fSkipEvenEntries(false)
32{
33}
34
35RTrivialDS::~RTrivialDS()
36{
37}
38
39const std::vector<std::string> &RTrivialDS::GetColumnNames() const
40{
41 return fColNames;
42}
43
44bool RTrivialDS::HasColumn(std::string_view colName) const
45{
46 return colName == fColNames[0];
47}
48
49std::string RTrivialDS::GetTypeName(std::string_view) const
50{
51 return "ULong64_t";
52}
53
54std::vector<std::pair<ULong64_t, ULong64_t>> RTrivialDS::GetEntryRanges()
55{
56 if (fSize == std::numeric_limits<ULong64_t>::max()) {
57 auto currentEntry = *std::max_element(fCounter.begin(), fCounter.end());
58 // infinite source, just make some ranges up
59 std::vector<std::pair<ULong64_t, ULong64_t>> ranges(fNSlots);
60 for (auto &range : ranges) {
61 range = std::make_pair(currentEntry, currentEntry + 10);
62 currentEntry += 10;
63 }
64 return ranges;
65 }
66
67 // empty fEntryRanges so we'll return an empty vector on subsequent calls
68 auto ranges = std::move(fEntryRanges);
69 return ranges;
70}
71
72bool RTrivialDS::SetEntry(unsigned int slot, ULong64_t entry)
73{
74 if (fSkipEvenEntries && 0 == entry % 2) {
75 return false;
76 }
77 fCounter[slot] = entry;
78 return true;
79}
80
81void RTrivialDS::SetNSlots(unsigned int nSlots)
82{
83 R__ASSERT(0U == fNSlots && "Setting the number of slots even if the number of slots is different from zero.");
84
85 fNSlots = nSlots;
86 fCounter.resize(fNSlots);
87 fCounterAddr.resize(fNSlots);
88}
89
90void RTrivialDS::Initialise()
91{
92 if (fSize == std::numeric_limits<ULong64_t>::max()) {
93 // infinite source, nothing to do here
94 return;
95 }
96
97 // initialize fEntryRanges
98 const auto chunkSize = fSize / fNSlots;
99 auto start = 0UL;
100 auto end = 0UL;
101 for (auto i : ROOT::TSeqUL(fNSlots)) {
102 start = end;
103 end += chunkSize;
104 fEntryRanges.emplace_back(start, end);
105 (void)i;
106 }
107 // TODO: redistribute reminder to all slots
108 fEntryRanges.back().second += fSize % fNSlots;
109}
110
111std::string RTrivialDS::GetLabel()
112{
113 return "TrivialDS";
114}
115
117{
118 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(size, skipEvenEntries),
121}
122
124{
125 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(), RDFInternal::ColumnNames_t{});
127}
128
129} // ns RDF
130
131} // ns ROOT
size_t fSize
unsigned long long ULong64_t
Definition RtypesCore.h:74
#define R__ASSERT(e)
Definition TError.h:120
typedef void((*Func_t)())
The public interface to the RDataFrame federation of classes.
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
std::vector< ULong64_t * > fCounterAddr
std::vector< ULong64_t > fCounter
std::vector< std::string > fColNames
std::vector< std::string > ColumnNames_t
RInterface< RDFDetail::RLoopManager, RTrivialDS > MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries=false)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TSeq< unsigned long > TSeqUL
Definition TSeq.hxx:197
TSeq< unsigned int > TSeqU
Definition TSeq.hxx:195