Logo ROOT   6.12/07
Reference Guide
TTrivialDS.cxx
Go to the documentation of this file.
1 #include <ROOT/TDFUtils.hxx>
2 #include <ROOT/TSeq.hxx>
3 #include <ROOT/TTrivialDS.hxx>
4 #include <ROOT/RMakeUnique.hxx>
5 
6 namespace ROOT {
7 namespace Experimental {
8 namespace TDF {
9 
10 std::vector<void *> TTrivialDS::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 
25 {
26 }
27 
29 {
30 }
31 
32 const std::vector<std::string> &TTrivialDS::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>> TTrivialDS::GetEntryRanges()
48 {
49  auto ranges(std::move(fEntryRanges)); // empty fEntryRanges
50  return ranges;
51 }
52 
53 void TTrivialDS::SetEntry(unsigned int slot, ULong64_t entry)
54 {
55  fCounter[slot] = entry;
56 }
57 
58 void TTrivialDS::SetNSlots(unsigned int nSlots)
59 {
60  assert(0U == fNSlots && "Setting the number of slots even if the number of slots is different from zero.");
61 
62  fNSlots = nSlots;
63  fCounter.resize(fNSlots);
64  fCounterAddr.resize(fNSlots);
65 }
66 
68 {
69  const auto chunkSize = fSize / fNSlots;
70  auto start = 0UL;
71  auto end = 0UL;
72  for (auto i : ROOT::TSeqUL(fNSlots)) {
73  start = end;
74  end += chunkSize;
75  fEntryRanges.emplace_back(start, end);
76  (void)i;
77  }
78  // TODO: redistribute reminder to all slots
79  fEntryRanges.back().second += fSize % fNSlots;
80 }
81 
83 {
84  ROOT::Experimental::TDataFrame tdf(std::make_unique<TTrivialDS>(size));
85  return tdf;
86 }
87 
88 } // ns TDF
89 } // ns Experimental
90 } // ns ROOT
std::string GetTypeName(std::string_view) const
Type of a column as a string, e.g.
Definition: TTrivialDS.cxx:42
basic_string_view< char > string_view
Definition: RStringView.h:35
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
std::vector< ULong64_t * > fCounterAddr
Definition: TTrivialDS.hxx:18
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
Definition: TTrivialDS.hxx:15
const std::vector< std::string > & GetColumnNames() const
Returns a reference to the collection of the dataset&#39;s column names.
Definition: TTrivialDS.cxx:32
void SetNSlots(unsigned int nSlots)
Inform TDataSource of the number of processing slots (i.e.
Definition: TTrivialDS.cxx:58
void SetEntry(unsigned int slot, ULong64_t entry)
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot...
Definition: TTrivialDS.cxx:53
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
Definition: TTrivialDS.cxx:47
std::vector< std::string > fColNames
Definition: TTrivialDS.hxx:16
std::vector< ULong64_t > fCounter
Definition: TTrivialDS.hxx:17
void Initialise()
Convenience method called before starting an event-loop.
Definition: TTrivialDS.cxx:67
TDataFrame MakeTrivialDataFrame(ULong64_t size)
Definition: TTrivialDS.cxx:82
bool HasColumn(std::string_view colName) const
Checks if the dataset has a certain column.
Definition: TTrivialDS.cxx:37
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
unsigned long long ULong64_t
Definition: RtypesCore.h:70
typedef void((*Func_t)())
ROOT&#39;s TDataFrame offers a high level interface for analyses of data stored in TTrees.
Definition: TDataFrame.hxx:39
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: TTrivialDS.cxx:10