Logo ROOT  
Reference Guide
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
53{
54 return colName == fColNames[0];
55}
56
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 R__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
#define R__ASSERT(e)
Definition: TError.h:118
std::string GetLabel()
Return a string representation of the datasource type.
Definition: RTrivialDS.cxx:119
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
Definition: RTrivialDS.cxx:62
void Initialise()
Convenience method called before starting an event-loop.
Definition: RTrivialDS.cxx:98
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:21
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:80
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
Definition: RTrivialDS.hxx:29
bool HasColumn(std::string_view colName) const
Checks if the dataset has a certain column.
Definition: RTrivialDS.cxx:52
std::vector< ULong64_t * > fCounterAddr
Definition: RTrivialDS.hxx:32
std::vector< ULong64_t > fCounter
Definition: RTrivialDS.hxx:31
std::vector< std::string > fColNames
Definition: RTrivialDS.hxx:30
RTrivialDS()
This ctor produces a data-source that returns infinite entries.
Definition: RTrivialDS.cxx:39
unsigned int fNSlots
Definition: RTrivialDS.hxx:26
const std::vector< std::string > & GetColumnNames() const
Returns a reference to the collection of the dataset's column names.
Definition: RTrivialDS.cxx:47
void SetNSlots(unsigned int nSlots)
Inform RDataSource of the number of processing slots (i.e.
Definition: RTrivialDS.cxx:89
std::string GetTypeName(std::string_view) const
Type of a column as a string, e.g.
Definition: RTrivialDS.cxx:57
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
basic_string_view< char > string_view
std::vector< std::string > ColumnNames_t
Definition: Utils.hxx:35
RInterface< RDFDetail::RLoopManager > MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries=false)
Make a RDF wrapping a RTrivialDS with the specified amount of entries.
Definition: RTrivialDS.cxx:124
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...