Logo ROOT  
Reference Guide
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>
4 #include <ROOT/RMakeUnique.hxx>
5 #include <TError.h>
6 
7 #include <limits>
8 
9 namespace ROOT {
10 
11 namespace RDF {
12 
13 std::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 
27 RTrivialDS::RTrivialDS(ULong64_t size, bool skipEvenEntries) : fSize(size), fSkipEvenEntries(skipEvenEntries)
28 {
29 }
30 
31 RTrivialDS::RTrivialDS() : fSize(std::numeric_limits<ULong64_t>::max()), fSkipEvenEntries(false)
32 {
33 }
34 
36 {
37 }
38 
39 const std::vector<std::string> &RTrivialDS::GetColumnNames() const
40 {
41  return fColNames;
42 }
43 
45 {
46  return colName == fColNames[0];
47 }
48 
50 {
51  return "ULong64_t";
52 }
53 
54 std::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 
72 bool 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 
81 void 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 
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 
111 std::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
RTrivialDS.hxx
ROOT::RDF::RTrivialDS::GetEntryRanges
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
Definition: RTrivialDS.cxx:54
ROOT::RDF::RTrivialDS::fSkipEvenEntries
bool fSkipEvenEntries
Definition: RTrivialDS.hxx:25
ROOT::RDF::RTrivialDS::SetEntry
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:72
ROOT::RDF::MakeTrivialDataFrame
RInterface< RDFDetail::RLoopManager, RTrivialDS > MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries=false)
Definition: RTrivialDS.cxx:116
string_view
basic_string_view< char > string_view
Definition: libcpp_string_view.h:785
Utils.hxx
ROOT::RDF::RTrivialDS::GetLabel
std::string GetLabel()
Return a string representation of the datasource type.
Definition: RTrivialDS.cxx:111
ROOT::Detail::RDF::ColumnNames_t
std::vector< std::string > ColumnNames_t
Definition: RLoopManager.hxx:53
ROOT::RDF::RTrivialDS::fEntryRanges
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
Definition: RTrivialDS.hxx:26
ROOT::RDF::RTrivialDS::GetColumnReadersImpl
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:13
ROOT::RDF::RTrivialDS::Initialise
void Initialise()
Convenience method called before starting an event-loop.
Definition: RTrivialDS.cxx:90
TSeq.hxx
ROOT::RDF::RTrivialDS::SetNSlots
void SetNSlots(unsigned int nSlots)
Inform RDataSource of the number of processing slots (i.e.
Definition: RTrivialDS.cxx:81
ROOT::RDF::RTrivialDS::fNSlots
unsigned int fNSlots
Definition: RTrivialDS.hxx:23
ROOT::RDF::RTrivialDS::GetTypeName
std::string GetTypeName(std::string_view) const
Type of a column as a string, e.g.
Definition: RTrivialDS.cxx:49
ROOT::RDF::RTrivialDS::RTrivialDS
RTrivialDS()
This ctor produces a data-source that returns infinite entries.
Definition: RTrivialDS.cxx:31
void
typedef void((*Func_t)())
ROOT::RDF::RInterface
The public interface to the RDataFrame federation of classes.
Definition: RInterface.hxx:90
ROOT::RDF::RTrivialDS::~RTrivialDS
~RTrivialDS()
Definition: RTrivialDS.cxx:35
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
ROOT::RDF::RTrivialDS::fSize
ULong64_t fSize
Definition: RTrivialDS.hxx:24
R__ASSERT
#define R__ASSERT(e)
Definition: TError.h:120
ROOT::RDF::RTrivialDS::fCounter
std::vector< ULong64_t > fCounter
Definition: RTrivialDS.hxx:28
ROOT::RDF::RTrivialDS::GetColumnNames
const std::vector< std::string > & GetColumnNames() const
Returns a reference to the collection of the dataset's column names.
Definition: RTrivialDS.cxx:39
fSize
size_t fSize
Definition: DeclareConverters.h:342
RMakeUnique.hxx
ROOT::TSeq
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::RDF::RTrivialDS::fCounterAddr
std::vector< ULong64_t * > fCounterAddr
Definition: RTrivialDS.hxx:29
ROOT::RDF::RTrivialDS::fColNames
std::vector< std::string > fColNames
Definition: RTrivialDS.hxx:27
ROOT::RDF::RTrivialDS::HasColumn
bool HasColumn(std::string_view colName) const
Checks if the dataset has a certain column.
Definition: RTrivialDS.cxx:44
TError.h