Logo ROOT  
Reference Guide
RTrivialDS.hxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, Danilo Piparo CERN 9/2017
2
3/*************************************************************************
4 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_RTRIVIALTDS
12#define ROOT_RTRIVIALTDS
13
15#include "ROOT/RDataSource.hxx"
16
17namespace ROOT {
18
19namespace RDF {
20
21/// \brief A simple data-source implementation, for demo purposes.
22///
23/// Constructing an RDataFrame as `RDataFrame(nEntries)` is a superior alternative.
24/// If size is std::numeric_limits<ULong64_t>::max(), this acts as an infinite data-source:
25/// it returns entries from GetEntryRanges forever or until a Range stops the event loop (for test purposes).
26class RTrivialDS final : public ROOT::RDF::RDataSource {
27private:
28 unsigned int fNSlots = 0U;
30 bool fSkipEvenEntries = false;
31 std::vector<std::pair<ULong64_t, ULong64_t>> fEntryRanges;
32 std::vector<std::string> fColNames{"col0"};
33 std::vector<ULong64_t> fCounter;
34 std::vector<ULong64_t *> fCounterAddr;
35 std::vector<void *> GetColumnReadersImpl(std::string_view name, const std::type_info &);
36
37protected:
38 std::string AsString() { return "trivial data source"; };
39
40public:
41 RTrivialDS(ULong64_t size, bool skipEvenEntries = false);
42 /// This ctor produces a data-source that returns infinite entries
43 RTrivialDS();
45 const std::vector<std::string> &GetColumnNames() const;
46 bool HasColumn(std::string_view colName) const;
47 std::string GetTypeName(std::string_view) const;
48 std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges();
49 bool SetEntry(unsigned int slot, ULong64_t entry);
50 void SetNSlots(unsigned int nSlots);
51 void Initialize();
52 std::string GetLabel();
53};
54
55/// \brief Make a RDF wrapping a RTrivialDS with the specified amount of entries.
56///
57/// Constructing an RDataFrame as `RDataFrame(nEntries)` is a superior alternative.
58/// If size is std::numeric_limits<ULong64_t>::max(), this acts as an infinite data-source:
59/// it returns entries from GetEntryRanges forever or until a Range stops the event loop (for test purposes).
60RInterface<RDFDetail::RLoopManager> MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries = false);
61/// \brief Make a RDF wrapping a RTrivialDS with infinite entries, for demo purposes.
62RInterface<RDFDetail::RLoopManager> MakeTrivialDataFrame();
63
64} // ns RDF
65
66} // ns ROOT
67
68#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned long long ULong64_t
Definition: RtypesCore.h:81
char name[80]
Definition: TGX11.cxx:110
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
A simple data-source implementation, for demo purposes.
Definition: RTrivialDS.hxx:26
std::string GetLabel()
Return a string representation of the datasource type.
Definition: RTrivialDS.cxx:119
void Initialize()
Convenience method called before starting an event-loop.
Definition: RTrivialDS.cxx:98
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
Definition: RTrivialDS.cxx:62
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:31
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:34
std::vector< ULong64_t > fCounter
Definition: RTrivialDS.hxx:33
std::vector< std::string > fColNames
Definition: RTrivialDS.hxx:32
RTrivialDS()
This ctor produces a data-source that returns infinite entries.
Definition: RTrivialDS.cxx:39
unsigned int fNSlots
Definition: RTrivialDS.hxx:28
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
std::string AsString()
Definition: RTrivialDS.hxx:38
basic_string_view< char > string_view
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
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.