Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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_RTRIVIALDS
12#define ROOT_RTRIVIALDS
13
15#include "ROOT/RDataSource.hxx"
16
17namespace ROOT::Internal::RDF {
18class R__CLING_PTRCHECK(off) RTrivialDSColumnReader final : public ROOT::Detail::RDF::RColumnReaderBase {
20 void *GetImpl(Long64_t) final { return fValuePtr; }
21
22public:
23 RTrivialDSColumnReader(ULong64_t *valuePtr) : fValuePtr(valuePtr) {}
24};
25} // namespace ROOT::Internal::RDF
26
27namespace ROOT {
28
29namespace RDF {
30
31/// \brief A simple data-source implementation, for demo purposes.
32///
33/// Constructing an RDataFrame as `RDataFrame(nEntries)` is a superior alternative.
34/// If size is std::numeric_limits<ULong64_t>::max(), this acts as an infinite data-source:
35/// it returns entries from GetEntryRanges forever or until a Range stops the event loop (for test purposes).
36class RTrivialDS final : public ROOT::RDF::RDataSource {
37private:
39 bool fSkipEvenEntries = false;
40 std::vector<std::pair<ULong64_t, ULong64_t>> fEntryRanges;
41 std::vector<std::string> fColNames{"col0"};
42 std::vector<ULong64_t> fCounter;
43 std::vector<ULong64_t *> fCounterAddr;
44 std::vector<void *> GetColumnReadersImpl(std::string_view name, const std::type_info &) final;
45
46protected:
47 std::string AsString() final { return "trivial data source"; };
48
49public:
50 RTrivialDS(ULong64_t size, bool skipEvenEntries = false);
51 /// This ctor produces a data-source that returns infinite entries
52 RTrivialDS();
53 // Rule of five
54 RTrivialDS(const RTrivialDS &) = delete;
55 RTrivialDS &operator=(const RTrivialDS &) = delete;
56 RTrivialDS(RTrivialDS &&) = delete;
58 ~RTrivialDS() final = default;
59
60 const std::vector<std::string> &GetColumnNames() const final;
61 bool HasColumn(std::string_view colName) const final;
62 std::string GetTypeName(std::string_view) const final;
63 std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() final;
64 bool SetEntry(unsigned int slot, ULong64_t entry) final;
65 void SetNSlots(unsigned int nSlots) final;
66 void Initialize() final;
67 std::string GetLabel() final;
68
70 GetColumnReaders(unsigned int slot, std::string_view colName, const std::type_info &tid) final;
71};
72
73/// \brief Make a RDF wrapping a RTrivialDS with the specified amount of entries.
74///
75/// Constructing an RDataFrame as `RDataFrame(nEntries)` is a superior alternative.
76/// If size is std::numeric_limits<ULong64_t>::max(), this acts as an infinite data-source:
77/// it returns entries from GetEntryRanges forever or until a Range stops the event loop (for test purposes).
78RInterface<RDFDetail::RLoopManager> MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries = false);
79/// \brief Make a RDF wrapping a RTrivialDS with infinite entries, for demo purposes.
81
82} // ns RDF
83
84} // ns ROOT
85
86#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Definition RtypesCore.h:84
char name[80]
Definition TGX11.cxx:148
The head node of a RDF computation graph.
Pure virtual base class for all column reader types.
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
The public interface to the RDataFrame federation of classes.
std::string GetTypeName(std::string_view) const final
Type of a column as a string, e.g.
bool HasColumn(std::string_view colName) const final
Checks if the dataset has a certain column.
void SetNSlots(unsigned int nSlots) final
Inform RDataSource of the number of processing slots (i.e.
~RTrivialDS() final=default
RTrivialDS & operator=(const RTrivialDS &)=delete
RTrivialDS & operator=(RTrivialDS &&)=delete
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
std::string GetLabel() final
Return a string representation of the datasource type.
RTrivialDS(RTrivialDS &&)=delete
std::vector< ULong64_t * > fCounterAddr
std::vector< void * > GetColumnReadersImpl(std::string_view name, const std::type_info &) final
type-erased vector of pointers to pointers to column values - one per slot
std::vector< ULong64_t > fCounter
std::vector< std::string > fColNames
bool SetEntry(unsigned int slot, ULong64_t entry) final
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
std::string AsString() final
RTrivialDS()
This ctor produces a data-source that returns infinite entries.
RTrivialDS(const RTrivialDS &)=delete
std::unique_ptr< ROOT::Detail::RDF::RColumnReaderBase > GetColumnReaders(unsigned int slot, std::string_view colName, const std::type_info &tid) final
If the other GetColumnReaders overload returns an empty vector, this overload will be called instead.
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges() final
Return ranges of entries to distribute to tasks.
RTrivialDS(ULong64_t size, bool skipEvenEntries=false)
const std::vector< std::string > & GetColumnNames() const final
Returns a reference to the collection of the dataset's column names.
void Initialize() final
Convenience method called before starting an event-loop.
STL class.
STL class.
STL class.
STL class.
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...
Definition TObject.h:395
RInterface< RDFDetail::RLoopManager > MakeTrivialDataFrame(ULong64_t size, bool skipEvenEntries=false)
Make a RDF wrapping a RTrivialDS with the specified amount of entries.