Logo ROOT  
Reference Guide
Go to the documentation of this file.
1// Author: Enrico Guiraud, Danilo Piparo CERN 9/2017
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 *************************************************************************/
14#include "ROOT/RDataFrame.hxx"
15#include "ROOT/RDataSource.hxx"
16#include <TChain.h>
18#include <memory>
20namespace ROOT {
22namespace Internal {
24namespace RDF {
26/// This class is unused and it has only been implemented as a proof of concept.
27/// It shows how to implement the RDataSource API for a complex kind of source such as TTrees.
28class RRootDS final : public ROOT::RDF::RDataSource {
30 unsigned int fNSlots = 0U;
31 std::string fTreeName;
32 std::string fFileNameGlob;
33 mutable TChain fModelChain; // Mutable needed for getting the column type name
34 std::vector<double *> fAddressesToFree;
35 std::vector<std::string> fListOfBranches;
36 std::vector<std::pair<ULong64_t, ULong64_t>> fEntryRanges;
37 std::vector<std::vector<void *>> fBranchAddresses; // first container-> slot, second -> column;
38 std::vector<std::unique_ptr<TChain>> fChains;
40 std::vector<void *> GetColumnReadersImpl(std::string_view, const std::type_info &);
43 std::string AsString() { return "ROOT data source"; };
46 RRootDS(std::string_view treeName, std::string_view fileNameGlob);
47 ~RRootDS();
48 std::string GetTypeName(std::string_view colName) const;
49 const std::vector<std::string> &GetColumnNames() const;
50 bool HasColumn(std::string_view colName) const;
51 void InitSlot(unsigned int slot, ULong64_t firstEntry);
52 void FinalizeSlot(unsigned int slot);
53 std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges();
54 bool SetEntry(unsigned int slot, ULong64_t entry);
55 void SetNSlots(unsigned int nSlots);
56 void Initialize();
57 std::string GetLabel();
60} // ns RDF
62} // ns Internal
64} // ns ROOT
unsigned long long ULong64_t
Definition: RtypesCore.h:81
This class is unused and it has only been implemented as a proof of concept.
Definition: RRootDS.hxx:28
void FinalizeSlot(unsigned int slot)
Convenience method called at the end of the data processing associated to a slot.
Definition: RRootDS.cxx:120
bool HasColumn(std::string_view colName) const
Checks if the dataset has a certain column.
Definition: RRootDS.cxx:88
const std::vector< std::string > & GetColumnNames() const
Returns a reference to the collection of the dataset's column names.
Definition: RRootDS.cxx:83
std::string GetLabel()
Return a string representation of the datasource type.
Definition: RRootDS.cxx:166
std::string GetTypeName(std::string_view colName) const
Type of a column as a string, e.g.
Definition: RRootDS.cxx:67
RRootDS(std::string_view treeName, std::string_view fileNameGlob)
Definition: RRootDS.cxx:48
std::vector< std::vector< void * > > fBranchAddresses
Definition: RRootDS.hxx:37
std::vector< std::unique_ptr< TChain > > fChains
Definition: RRootDS.hxx:38
std::vector< void * > GetColumnReadersImpl(std::string_view, const std::type_info &)
type-erased vector of pointers to pointers to column values - one per slot
Definition: RRootDS.cxx:26
void SetNSlots(unsigned int nSlots)
Inform RDataSource of the number of processing slots (i.e.
Definition: RRootDS.cxx:137
std::vector< std::string > fListOfBranches
Definition: RRootDS.hxx:35
std::vector< double * > fAddressesToFree
Definition: RRootDS.hxx:34
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
Definition: RRootDS.cxx:125
void Initialize()
Convenience method called before starting an event-loop.
Definition: RRootDS.cxx:150
void InitSlot(unsigned int slot, ULong64_t firstEntry)
Convenience method called at the start of the data processing associated to a slot.
Definition: RRootDS.cxx:95
std::vector< std::pair< ULong64_t, ULong64_t > > fEntryRanges
Definition: RRootDS.hxx:36
bool SetEntry(unsigned int slot, ULong64_t entry)
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
Definition: RRootDS.cxx:131
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
A chain is a collection of files containing TTree objects.
Definition: TChain.h:33
basic_string_view< char > string_view
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.