Logo ROOT  
Reference Guide
RDatasetSpec.cxx
Go to the documentation of this file.
1// Author: Vincenzo Eduardo Padulano CERN/UPV, Ivan Kabadzhov CERN 06/2022
2
3/*************************************************************************
4 * Copyright (C) 1995-2022, 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
12#include <stdexcept> // std::logic_error
13
14namespace ROOT {
15
16namespace RDF {
17
18namespace Experimental {
19
21
23
24RDatasetSpec::REntryRange::REntryRange(Long64_t begin, Long64_t end) : fBegin(begin), fEnd(end)
25{
26 if (fBegin > fEnd)
27 throw std::logic_error("The starting entry cannot be larger than the ending entry in the "
28 "creation of a dataset specification.");
29}
30
31/**
32 * \class ROOT::RDF::Experimental::RDatasetSpec
33 * \ingroup dataframe
34 * \brief A dataset specification for RDataFrame.
35 **/
36
37////////////////////////////////////////////////////////////////////////////
38/// \brief Construct an RDatasetSpec for one or more samples with the same tree name.
39/// \param[in] treeName Name of the tree
40/// \param[in] fileNameGlob Single file name or glob expression for the files where the tree(s) are stored
41/// \param[in] entryRange The global entry range to be processed, {begin (inclusive), end (exclusive)}
42///
43/// The filename glob supports the same type of expressions as TChain::Add().
44RDatasetSpec::RDatasetSpec(const std::string &treeName, const std::string &fileNameGlob, const REntryRange &entryRange)
45 : fTreeNames({treeName}), fFileNameGlobs({fileNameGlob}), fEntryRange(entryRange)
46{
47}
48
49////////////////////////////////////////////////////////////////////////////
50/// \brief Construct an RDatasetSpec for one or more samples with the same tree name.
51/// \param[in] treeName Name of the tree
52/// \param[in] fileNameGlobs A vector of file names or glob expressions for the files where the trees are stored
53/// \param[in] entryRange The global entry range to be processed, {begin (inclusive), end (exclusive)}
54///
55/// The filename glob supports the same type of expressions as TChain::Add().
56RDatasetSpec::RDatasetSpec(const std::string &treeName, const std::vector<std::string> &fileNameGlobs,
57 const REntryRange &entryRange)
58 : fTreeNames({treeName}), fFileNameGlobs(fileNameGlobs), fEntryRange(entryRange)
59{
60}
61
62////////////////////////////////////////////////////////////////////////////
63/// \brief Construct an RDatasetSpec for a chain of several trees (possibly having different names).
64/// \param[in] treeAndFileNameGlobs A vector of pairs of tree names and their corresponding file names/globs
65/// \param[in] entryRange The global entry range to be processed, {begin (inclusive), end (exclusive)}
66///
67/// The filename glob supports the same type of expressions as TChain::Add().
68///
69/// ### Example usage:
70/// ~~~{.py}
71/// spec = ROOT.RDF.Experimental.RDatasetSpec([("tree1", "a.root"), ("tree2", "b.root")], (5, 10))
72/// df = ROOT.RDataFrame(spec)
73/// ~~~
74RDatasetSpec::RDatasetSpec(const std::vector<std::pair<std::string, std::string>> &treeAndFileNameGlobs,
75 const REntryRange &entryRange)
76 : fEntryRange(entryRange)
77{
78 fTreeNames.reserve(treeAndFileNameGlobs.size());
79 fFileNameGlobs.reserve(treeAndFileNameGlobs.size());
80 for (auto &p : treeAndFileNameGlobs) {
81 fTreeNames.emplace_back(p.first);
82 fFileNameGlobs.emplace_back(p.second);
83 }
84}
85
86////////////////////////////////////////////////////////////////////////////
87/// \brief Add a friend tree or chain with the same tree name to the dataset specification.
88/// \param[in] treeName Name of the tree
89/// \param[in] fileNameGlob Single file name or glob expression for the files where the tree(s) are stored
90/// \param[in] alias String to refer to the particular friend
91///
92/// The filename glob supports the same type of expressions as TChain::Add().
93void RDatasetSpec::AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias)
94{
95 fFriendInfo.AddFriend(treeName, fileNameGlob, alias);
96}
97
98////////////////////////////////////////////////////////////////////////////
99/// \brief Add a friend tree or chain with the same tree name to the dataset specification.
100/// \param[in] treeName Name of the tree
101/// \param[in] fileNameGlobs A vector of file names or glob expressions for the files where the trees are stored
102/// \param[in] alias String to refer to the particular friend
103///
104/// The filename glob supports the same type of expressions as TChain::Add().
105void RDatasetSpec::AddFriend(const std::string &treeName, const std::vector<std::string> &fileNameGlobs,
106 const std::string &alias)
107{
108 fFriendInfo.AddFriend(treeName, fileNameGlobs, alias);
109}
110
111////////////////////////////////////////////////////////////////////////////
112/// \brief Add a friend tree or chain (possibly with different tree names) to the dataset specification.
113/// \param[in] treeAndFileNameGlobs A vector of pairs of tree names and their corresponding file names/globs
114/// \param[in] alias String to refer to the particular friend
115///
116/// The filename glob supports the same type of expressions as TChain::Add().
117///
118/// ### Example usage:
119/// ~~~{.py}
120/// spec = ROOT.RDF.Experimental.RDatasetSpec("tree", "file.root")
121/// spec.AddFriend([("tree1", "a.root"), ("tree2", "b.root")], "alias")
122/// df = ROOT.RDataFrame(spec)
123/// ~~~
124void RDatasetSpec::AddFriend(const std::vector<std::pair<std::string, std::string>> &treeAndFileNameGlobs,
125 const std::string &alias)
126{
127 fFriendInfo.AddFriend(treeAndFileNameGlobs, alias);
128}
129
130const std::vector<std::string> &RDatasetSpec::GetTreeNames() const
131{
132 return fTreeNames;
133}
134
135const std::vector<std::string> &RDatasetSpec::GetFileNameGlobs() const
136{
137 return fFileNameGlobs;
138}
139
141{
142 return fEntryRange.fBegin;
143}
144
146{
147 return fEntryRange.fEnd;
148}
149
151{
152 return fFriendInfo;
153}
154
155} // namespace Experimental
156} // namespace RDF
157} // namespace ROOT
long long Long64_t
Definition: RtypesCore.h:80
winID h TVirtualViewer3D TVirtualGLPainter p
REntryRange fEntryRange
Start (inclusive) and end (exclusive) entry for the dataset processing.
RDatasetSpec(const std::string &treeName, const std::string &fileNameGlob, const REntryRange &entryRange={})
Construct an RDatasetSpec for one or more samples with the same tree name.
const std::vector< std::string > & GetFileNameGlobs() const
const ROOT::TreeUtils::RFriendInfo & GetFriendInfo() const
std::vector< std::string > fFileNameGlobs
A list of file names.
const std::vector< std::string > & GetTreeNames() const
void AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias="")
Add a friend tree or chain with the same tree name to the dataset specification.
std::vector< std::string > fTreeNames
A list of names of trees.
ROOT::TreeUtils::RFriendInfo fFriendInfo
List of friends.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Information about friend trees of a certain TTree or TChain object.
Definition: RFriendInfo.hxx:34
void AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias="")
Add information of a single friend.
Definition: RFriendInfo.cxx:21