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#include <TError.h>
13
14#include <limits>
15#include <memory>
16
17namespace ROOT {
18
19namespace RDF {
20
21std::vector<void *> RTrivialDS::GetColumnReadersImpl(std::string_view, const std::type_info &ti)
22{
23 // We know we have only one column and that it's holding ULong64_t's
24 if (ti != typeid(ULong64_t)) {
25 throw std::runtime_error("The type specified for the column \"col0\" is not ULong64_t.");
26 }
27 std::vector<void *> ret;
28 for (auto i : ROOT::TSeqU(fNSlots)) {
29 fCounterAddr[i] = &fCounter[i];
30 ret.emplace_back((void *)(&fCounterAddr[i]));
31 }
32 return ret;
33}
34
35RTrivialDS::RTrivialDS(ULong64_t size, bool skipEvenEntries) : fSize(size), fSkipEvenEntries(skipEvenEntries)
36{
37}
38
39RTrivialDS::RTrivialDS() : fSize(std::numeric_limits<ULong64_t>::max()), fSkipEvenEntries(false)
40{
41}
42
44{
45}
46
47const std::vector<std::string> &RTrivialDS::GetColumnNames() const
48{
49 return fColNames;
50}
51
52bool RTrivialDS::HasColumn(std::string_view colName) const
53{
54 return colName == fColNames[0];
55}
56
57std::string RTrivialDS::GetTypeName(std::string_view) const
58{
59 return "ULong64_t";
60}
61
62std::vector<std::pair<ULong64_t, ULong64_t>> RTrivialDS::GetEntryRanges()
63{
64 if (fSize == std::numeric_limits<ULong64_t>::max()) {
65 auto currentEntry = *std::max_element(fCounter.begin(), fCounter.end());
66 // infinite source, just make some ranges up
67 std::vector<std::pair<ULong64_t, ULong64_t>> ranges(fNSlots);
68 for (auto &range : ranges) {
69 range = std::make_pair(currentEntry, currentEntry + 10);
70 currentEntry += 10;
71 }
72 return ranges;
73 }
74
75 // empty fEntryRanges so we'll return an empty vector on subsequent calls
76 auto ranges = std::move(fEntryRanges);
77 return ranges;
78}
79
80bool RTrivialDS::SetEntry(unsigned int slot, ULong64_t entry)
81{
82 if (fSkipEvenEntries && 0 == entry % 2) {
83 return false;
84 }
85 fCounter[slot] = entry;
86 return true;
87}
88
89void RTrivialDS::SetNSlots(unsigned int nSlots)
90{
91 assert(0U == fNSlots && "Setting the number of slots even if the number of slots is different from zero.");
92
93 fNSlots = nSlots;
94 fCounter.resize(fNSlots);
95 fCounterAddr.resize(fNSlots);
96}
97
99{
100 if (fSize == std::numeric_limits<ULong64_t>::max()) {
101 // infinite source, nothing to do here
102 return;
103 }
104
105 // initialize fEntryRanges
106 const auto chunkSize = fSize / fNSlots;
107 auto start = 0UL;
108 auto end = 0UL;
109 for (auto i : ROOT::TSeqUL(fNSlots)) {
110 start = end;
111 end += chunkSize;
112 fEntryRanges.emplace_back(start, end);
113 (void)i;
114 }
115 // TODO: redistribute reminder to all slots
116 fEntryRanges.back().second += fSize % fNSlots;
117}
118
120{
121 return "TrivialDS";
122}
123
125{
126 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(size, skipEvenEntries),
128 return RInterface<RDFDetail::RLoopManager>(std::move(lm));
129}
130
132{
133 auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(), RDFInternal::ColumnNames_t{});
134 return RInterface<RDFDetail::RLoopManager>(std::move(lm));
135}
136
137} // ns RDF
138
139} // ns ROOT
size_t fSize
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
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 GetLabel()
Return a string representation of the datasource type.
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
void Initialise()
Convenience method called before starting an event-loop.
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
bool SetEntry(unsigned int slot, ULong64_t entry)
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
bool HasColumn(std::string_view colName) const
Checks if the dataset has a certain column.
std::vector< ULong64_t * > fCounterAddr
std::vector< ULong64_t > fCounter
std::vector< std::string > fColNames
RTrivialDS()
This ctor produces a data-source that returns infinite entries.
const std::vector< std::string > & GetColumnNames() const
Returns a reference to the collection of the dataset's column names.
void SetNSlots(unsigned int nSlots)
Inform RDataSource of the number of processing slots (i.e.
std::string GetTypeName(std::string_view) const
Type of a column as a string, e.g.
std::vector< std::string > ColumnNames_t
Definition Utils.hxx:35
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:204
TSeq< unsigned int > TSeqU
Definition TSeq.hxx:202