Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RTrivialDS.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#include <ROOT/RDF/Utils.hxx>
10#include <ROOT/TSeq.hxx>
11#include <ROOT/RTrivialDS.hxx>
12
13#include <limits>
14#include <memory>
15
16namespace ROOT {
17
18namespace RDF {
19
20std::vector<void *> RTrivialDS::GetColumnReadersImpl(std::string_view, const std::type_info &ti)
21{
22 // We know we have only one column and that it's holding ULong64_t's
23 if (ti != typeid(ULong64_t)) {
24 throw std::runtime_error("The type specified for the column \"col0\" is not ULong64_t.");
25 }
26 std::vector<void *> ret;
27 for (auto i : ROOT::TSeqU(fNSlots)) {
28 fCounterAddr[i] = &fCounter[i];
29 ret.emplace_back((void *)(&fCounterAddr[i]));
30 }
31 return ret;
32}
33
34RTrivialDS::RTrivialDS(ULong64_t size, bool skipEvenEntries) : fSize(size), fSkipEvenEntries(skipEvenEntries)
35{
36}
37
38RTrivialDS::RTrivialDS() : fSize(std::numeric_limits<ULong64_t>::max()), fSkipEvenEntries(false)
39{
40}
41
42const std::vector<std::string> &RTrivialDS::GetColumnNames() const
43{
44 return fColNames;
45}
46
47bool RTrivialDS::HasColumn(std::string_view colName) const
48{
49 return colName == fColNames[0];
50}
51
52std::string RTrivialDS::GetTypeName(std::string_view) const
53{
54 return "ULong64_t";
55}
56
57std::vector<std::pair<ULong64_t, ULong64_t>> RTrivialDS::GetEntryRanges()
58{
59 if (fSize == std::numeric_limits<ULong64_t>::max()) {
60 auto currentEntry = *std::max_element(fCounter.begin(), fCounter.end());
61 // infinite source, just make some ranges up
62 std::vector<std::pair<ULong64_t, ULong64_t>> ranges(fNSlots);
63 for (auto &range : ranges) {
64 range = std::make_pair(currentEntry, currentEntry + 10);
65 currentEntry += 10;
66 }
67 return ranges;
68 }
69
70 // empty fEntryRanges so we'll return an empty vector on subsequent calls
71 auto ranges = std::move(fEntryRanges);
72 return ranges;
73}
74
75bool RTrivialDS::SetEntry(unsigned int slot, ULong64_t entry)
76{
77 if (fSkipEvenEntries && 0 == entry % 2) {
78 return false;
79 }
80 fCounter[slot] = entry;
81 return true;
82}
83
84void RTrivialDS::SetNSlots(unsigned int nSlots)
85{
86 assert(0U == fNSlots && "Setting the number of slots even if the number of slots is different from zero.");
87
88 fNSlots = nSlots;
89 fCounter.resize(fNSlots);
90 fCounterAddr.resize(fNSlots);
91}
92
93void RTrivialDS::Initialize()
94{
95 if (fSize == std::numeric_limits<ULong64_t>::max()) {
96 // infinite source, nothing to do here
97 return;
98 }
99
100 // initialize fEntryRanges
101 const auto chunkSize = fSize / fNSlots;
102 auto start = 0UL;
103 auto end = 0UL;
104 for (auto i : ROOT::TSeqUL(fNSlots)) {
105 start = end;
106 end += chunkSize;
107 fEntryRanges.emplace_back(start, end);
108 (void)i;
109 }
110 // TODO: redistribute reminder to all slots
111 fEntryRanges.back().second += fSize % fNSlots;
112}
113
114std::string RTrivialDS::GetLabel()
115{
116 return "TrivialDS";
117}
118
120{
121 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(size, skipEvenEntries),
123 return RInterface<RDFDetail::RLoopManager>(std::move(lm));
124}
125
127{
128 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(), RDFInternal::ColumnNames_t{});
129 return RInterface<RDFDetail::RLoopManager>(std::move(lm));
130}
131
132} // ns RDF
133
134} // ns ROOT
dim_t fSize
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned long long ULong64_t
Definition RtypesCore.h:70
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 > MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries=false)
Make a RDF wrapping a RTrivialDS with the specified amount of entries.
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:206
TSeq< unsigned int > TSeqU
Definition TSeq.hxx:204