Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 namespace ROOT {
8 
9 namespace RDF {
10 
11 std::vector<void *> RTrivialDS::GetColumnReadersImpl(std::string_view, const std::type_info &ti)
12 {
13  // We know we have only one column and that it's holding ULong64_t's
14  if (ti != typeid(ULong64_t)) {
15  throw std::runtime_error("The type specified for the column \"col0\" is not ULong64_t.");
16  }
17  std::vector<void *> ret;
18  for (auto i : ROOT::TSeqU(fNSlots)) {
19  fCounterAddr[i] = &fCounter[i];
20  ret.emplace_back((void *)(&fCounterAddr[i]));
21  }
22  return ret;
23 }
24 
25 RTrivialDS::RTrivialDS(ULong64_t size, bool skipEvenEntries) : fSize(size), fSkipEvenEntries(skipEvenEntries)
26 {
27 }
28 
29 RTrivialDS::~RTrivialDS()
30 {
31 }
32 
33 const std::vector<std::string> &RTrivialDS::GetColumnNames() const
34 {
35  return fColNames;
36 }
37 
38 bool RTrivialDS::HasColumn(std::string_view colName) const
39 {
40  return colName == fColNames[0];
41 }
42 
43 std::string RTrivialDS::GetTypeName(std::string_view) const
44 {
45  return "ULong64_t";
46 }
47 
48 std::vector<std::pair<ULong64_t, ULong64_t>> RTrivialDS::GetEntryRanges()
49 {
50  auto ranges(std::move(fEntryRanges)); // empty fEntryRanges
51  return ranges;
52 }
53 
54 bool RTrivialDS::SetEntry(unsigned int slot, ULong64_t entry)
55 {
56  if (fSkipEvenEntries && 0 == entry % 2) {
57  return false;
58  }
59  fCounter[slot] = entry;
60  return true;
61 }
62 
63 void RTrivialDS::SetNSlots(unsigned int nSlots)
64 {
65  R__ASSERT(0U == fNSlots && "Setting the number of slots even if the number of slots is different from zero.");
66 
67  fNSlots = nSlots;
68  fCounter.resize(fNSlots);
69  fCounterAddr.resize(fNSlots);
70 }
71 
72 void RTrivialDS::Initialise()
73 {
74  const auto chunkSize = fSize / fNSlots;
75  auto start = 0UL;
76  auto end = 0UL;
77  for (auto i : ROOT::TSeqUL(fNSlots)) {
78  start = end;
79  end += chunkSize;
80  fEntryRanges.emplace_back(start, end);
81  (void)i;
82  }
83  // TODO: redistribute reminder to all slots
84  fEntryRanges.back().second += fSize % fNSlots;
85 }
86 
87 std::string RTrivialDS::GetLabel()
88 {
89  return "TrivialDS";
90 }
91 
92 RInterface<RDFDetail::RLoopManager, RTrivialDS> MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries)
93 {
94  auto lm = std::make_unique<RDFDetail::RLoopManager>(std::make_unique<RTrivialDS>(size, skipEvenEntries),
95  RDFInternal::ColumnNames_t{});
96  return RInterface<RDFDetail::RLoopManager, RTrivialDS>(std::move(lm));
97 }
98 
99 } // ns RDF
100 
101 } // ns ROOT