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
43{
44}
45
46const std::vector<std::string> &RTrivialDS::GetColumnNames() const
47{
48 return fColNames;
49}
50
51bool RTrivialDS::HasColumn(std::string_view colName) const
52{
53 return colName == fColNames[0];
54}
55
56std::string RTrivialDS::GetTypeName(std::string_view) const
57{
58 return "ULong64_t";
59}
60
61std::vector<std::pair<ULong64_t, ULong64_t>> RTrivialDS::GetEntryRanges()
62{
63 if (fSize == std::numeric_limits<ULong64_t>::max()) {
64 auto currentEntry = *std::max_element(fCounter.begin(), fCounter.end());
65 // infinite source, just make some ranges up
66 std::vector<std::pair<ULong64_t, ULong64_t>> ranges(fNSlots);
67 for (auto &range : ranges) {
68 range = std::make_pair(currentEntry, currentEntry + 10);
69 currentEntry += 10;
70 }
71 return ranges;
72 }
73
74 // empty fEntryRanges so we'll return an empty vector on subsequent calls
75 auto ranges = std::move(fEntryRanges);
76 return ranges;
77}
78
79bool RTrivialDS::SetEntry(unsigned int slot, ULong64_t entry)
80{
81 if (fSkipEvenEntries && 0 == entry % 2) {
82 return false;
83 }
84 fCounter[slot] = entry;
85 return true;
86}
87
88void RTrivialDS::SetNSlots(unsigned int nSlots)
89{
90 assert(0U == fNSlots && "Setting the number of slots even if the number of slots is different from zero.");
91
92 fNSlots = nSlots;
93 fCounter.resize(fNSlots);
94 fCounterAddr.resize(fNSlots);
95}
96
98{
99 if (fSize == std::numeric_limits<ULong64_t>::max()) {
100 // infinite source, nothing to do here
101 return;
102 }
103
104 // initialize fEntryRanges
105 const auto chunkSize = fSize / fNSlots;
106 auto start = 0UL;
107 auto end = 0UL;
108 for (auto i : ROOT::TSeqUL(fNSlots)) {
109 start = end;
110 end += chunkSize;
111 fEntryRanges.emplace_back(start, end);
112 (void)i;
113 }
114 // TODO: redistribute reminder to all slots
115 fEntryRanges.back().second += fSize % fNSlots;
116}
117
119{
120 return "TrivialDS";
121}
122
124{
125 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(size, skipEvenEntries),
127 return RInterface<RDFDetail::RLoopManager>(std::move(lm));
128}
129
131{
132 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(), RDFInternal::ColumnNames_t{});
133 return RInterface<RDFDetail::RLoopManager>(std::move(lm));
134}
135
136} // ns RDF
137
138} // 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:81
The public interface to the RDataFrame federation of classes.
std::string GetTypeName(std::string_view) const final
Type of a column as a string, e.g.
bool HasColumn(std::string_view colName) const final
Checks if the dataset has a certain column.
void SetNSlots(unsigned int nSlots) final
Inform RDataSource of the number of processing slots (i.e.
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
std::string GetLabel() final
Return a string representation of the datasource type.
std::vector< ULong64_t * > fCounterAddr
std::vector< void * > GetColumnReadersImpl(std::string_view name, const std::type_info &) final
type-erased vector of pointers to pointers to column values - one per slot
std::vector< ULong64_t > fCounter
std::vector< std::string > fColNames
bool SetEntry(unsigned int slot, ULong64_t entry) final
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
RTrivialDS()
This ctor produces a data-source that returns infinite entries.
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges() final
Return ranges of entries to distribute to tasks.
const std::vector< std::string > & GetColumnNames() const final
Returns a reference to the collection of the dataset's column names.
void Initialize() final
Convenience method called before starting an event-loop.
std::vector< std::string > ColumnNames_t
RInterface< RDFDetail::RLoopManager > MakeTrivialDataFrame()
Make a RDF wrapping a RTrivialDS with infinite entries, for demo purposes.
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