Logo ROOT   6.14/05
Reference Guide
RTrivialDS.cxx
Go to the documentation of this file.
1 #include <ROOT/RDFUtils.hxx>
2 #include <ROOT/TSeq.hxx>
3 #include <ROOT/RTrivialDS.hxx>
4 #include <ROOT/RMakeUnique.hxx>
5 
6 namespace ROOT {
7 
8 namespace RDF {
9 
10 std::vector<void *> RTrivialDS::GetColumnReadersImpl(std::string_view, const std::type_info &ti)
11 {
12  // We know we have only one column and that it's holding ULong64_t's
13  if (ti != typeid(ULong64_t)) {
14  throw std::runtime_error("The type specified for the column \"col0\" is not ULong64_t.");
15  }
16  std::vector<void *> ret;
17  for (auto i : ROOT::TSeqU(fNSlots)) {
18  fCounterAddr[i] = &fCounter[i];
19  ret.emplace_back((void *)(&fCounterAddr[i]));
20  }
21  return ret;
22 }
23 
24 RTrivialDS::RTrivialDS(ULong64_t size, bool skipEvenEntries) : fSize(size), fSkipEvenEntries(skipEvenEntries)
25 {
26 }
27 
29 {
30 }
31 
32 const std::vector<std::string> &RTrivialDS::GetColumnNames() const
33 {
34  return fColNames;
35 }
36 
38 {
39  return colName == fColNames[0];
40 }
41 
43 {
44  return "ULong64_t";
45 }
46 
47 std::vector<std::pair<ULong64_t, ULong64_t>> RTrivialDS::GetEntryRanges()
48 {
49  auto ranges(std::move(fEntryRanges)); // empty fEntryRanges
50  return ranges;
51 }
52 
53 bool RTrivialDS::SetEntry(unsigned int slot, ULong64_t entry)
54 {
55  if (fSkipEvenEntries && 0 == entry % 2) {
56  return false;
57  }
58  fCounter[slot] = entry;
59  return true;
60 }
61 
62 void RTrivialDS::SetNSlots(unsigned int nSlots)
63 {
64  assert(0U == fNSlots && "Setting the number of slots even if the number of slots is different from zero.");
65 
66  fNSlots = nSlots;
67  fCounter.resize(fNSlots);
68  fCounterAddr.resize(fNSlots);
69 }
70 
72 {
73  const auto chunkSize = fSize / fNSlots;
74  auto start = 0UL;
75  auto end = 0UL;
76  for (auto i : ROOT::TSeqUL(fNSlots)) {
77  start = end;
78  end += chunkSize;
79  fEntryRanges.emplace_back(start, end);
80  (void)i;
81  }
82  // TODO: redistribute reminder to all slots
83  fEntryRanges.back().second += fSize % fNSlots;
84 }
85 
86 RDataFrame MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries)
87 {
88  ROOT::RDataFrame tdf(std::make_unique<RTrivialDS>(size, skipEvenEntries));
89  return tdf;
90 }
91 
92 } // ns RDF
93 
94 } // ns ROOT
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
Definition: RTrivialDS.hxx:26
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
Definition: RTrivialDS.cxx:47
RTrivialDS(ULong64_t size, bool skipEvenEntries=false)
Definition: RTrivialDS.cxx:24
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:53
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:10
std::vector< ULong64_t * > fCounterAddr
Definition: RTrivialDS.hxx:29
std::vector< std::string > fColNames
Definition: RTrivialDS.hxx:27
std::string GetTypeName(std::string_view) const
Type of a column as a string, e.g.
Definition: RTrivialDS.cxx:42
bool HasColumn(std::string_view colName) const
Checks if the dataset has a certain column.
Definition: RTrivialDS.cxx:37
void Initialise()
Convenience method called before starting an event-loop.
Definition: RTrivialDS.cxx:71
ROOT&#39;s RDataFrame offers a high level interface for analyses of data stored in TTrees, CSV&#39;s and other data formats.
Definition: RDataFrame.hxx:42
RDataFrame MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries=false)
Definition: RTrivialDS.cxx:86
unsigned int fNSlots
Definition: RTrivialDS.hxx:23
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
void SetNSlots(unsigned int nSlots)
Inform RDataSource of the number of processing slots (i.e.
Definition: RTrivialDS.cxx:62
unsigned long long ULong64_t
Definition: RtypesCore.h:70
basic_string_view< char > string_view
Definition: RStringView.hxx:35
typedef void((*Func_t)())
std::vector< ULong64_t > fCounter
Definition: RTrivialDS.hxx:28
const std::vector< std::string > & GetColumnNames() const
Returns a reference to the collection of the dataset&#39;s column names.
Definition: RTrivialDS.cxx:32