Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDatasetSpec.cxx
Go to the documentation of this file.
1/// \cond HIDDEN_SYMBOLS
2// Author: Vincenzo Eduardo Padulano CERN/UPV, Ivan Kabadzhov CERN 06/2022
3
4/*************************************************************************
5 * Copyright (C) 1995-2022, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
13#include <stdexcept> // std::logic_error
14
15namespace ROOT {
16
17namespace Internal {
18
19namespace RDF {
20
21RDatasetSpec::REntryRange::REntryRange() {}
22
23RDatasetSpec::REntryRange::REntryRange(Long64_t end) : fEnd(end) {}
24
25RDatasetSpec::REntryRange::REntryRange(Long64_t begin, Long64_t end) : fBegin(begin), fEnd(end)
26{
27 if (fBegin > fEnd)
28 throw std::logic_error("The starting entry cannot be larger than the ending entry in the "
29 "creation of a dataset specification.");
30}
31
32/**
33 * \class ROOT::Internal::RDF::RDatasetSpec
34 * \ingroup dataframe
35 * \brief A dataset specification for RDataFrame.
36 **/
37
38////////////////////////////////////////////////////////////////////////////
39/// \brief Construct an RDatasetSpec for one or more samples with the same tree name.
40/// \param[in] treeName Name of the tree
41/// \param[in] fileNameGlob Single file name or glob expression for the files where the tree(s) are stored
42/// \param[in] entryRange The global entry range to be processed, {begin (inclusive), end (exclusive)}
43///
44/// The filename glob supports the same type of expressions as TChain::Add().
45RDatasetSpec::RDatasetSpec(const std::string &treeName, const std::string &fileNameGlob, const REntryRange &entryRange)
46 : fTreeNames({treeName}), fFileNameGlobs({fileNameGlob}), fEntryRange(entryRange)
47{
48}
49
50////////////////////////////////////////////////////////////////////////////
51/// \brief Construct an RDatasetSpec for one or more samples with the same tree name.
52/// \param[in] treeName Name of the tree
53/// \param[in] fileNameGlobs A vector of file names or glob expressions for the files where the trees are stored
54/// \param[in] entryRange The global entry range to be processed, {begin (inclusive), end (exclusive)}
55///
56/// The filename glob supports the same type of expressions as TChain::Add().
57RDatasetSpec::RDatasetSpec(const std::string &treeName, const std::vector<std::string> &fileNameGlobs,
58 const REntryRange &entryRange)
59 : fTreeNames({treeName}), fFileNameGlobs(fileNameGlobs), fEntryRange(entryRange)
60{
61}
62
63////////////////////////////////////////////////////////////////////////////
64/// \brief Construct an RDatasetSpec for a chain of several trees (possibly having different names).
65/// \param[in] treeAndFileNameGlobs A vector of pairs of tree names and their corresponding file names/globs
66/// \param[in] entryRange The global entry range to be processed, {begin (inclusive), end (exclusive)}
67///
68/// The filename glob supports the same type of expressions as TChain::Add().
69///
70/// ### Example usage:
71/// ~~~{.py}
72/// spec = ROOT.Internal.RDF.RDatasetSpec([("tree1", "a.root"), ("tree2", "b.root")], (5, 10))
73/// df = ROOT.RDataFrame(spec)
74/// ~~~
75RDatasetSpec::RDatasetSpec(const std::vector<std::pair<std::string, std::string>> &treeAndFileNameGlobs,
76 const REntryRange &entryRange)
77 : fEntryRange(entryRange)
78{
79 fTreeNames.reserve(treeAndFileNameGlobs.size());
80 fFileNameGlobs.reserve(treeAndFileNameGlobs.size());
81 for (auto &p : treeAndFileNameGlobs) {
82 fTreeNames.emplace_back(p.first);
83 fFileNameGlobs.emplace_back(p.second);
84 }
85}
86
87////////////////////////////////////////////////////////////////////////////
88/// \brief Add a friend tree or chain with the same tree name to the dataset specification.
89/// \param[in] treeName Name of the tree
90/// \param[in] fileNameGlob Single file name or glob expression for the files where the tree(s) are stored
91/// \param[in] alias String to refer to the particular friend
92///
93/// The filename glob supports the same type of expressions as TChain::Add().
94void RDatasetSpec::AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias)
95{
96 fFriendInfo.AddFriend(treeName, fileNameGlob, alias);
97}
98
99////////////////////////////////////////////////////////////////////////////
100/// \brief Add a friend tree or chain with the same tree name to the dataset specification.
101/// \param[in] treeName Name of the tree
102/// \param[in] fileNameGlobs A vector of file names or glob expressions for the files where the trees are stored
103/// \param[in] alias String to refer to the particular friend
104///
105/// The filename glob supports the same type of expressions as TChain::Add().
106void RDatasetSpec::AddFriend(const std::string &treeName, const std::vector<std::string> &fileNameGlobs,
107 const std::string &alias)
108{
109 fFriendInfo.AddFriend(treeName, fileNameGlobs, alias);
110}
111
112////////////////////////////////////////////////////////////////////////////
113/// \brief Add a friend tree or chain (possibly with different tree names) to the dataset specification.
114/// \param[in] treeAndFileNameGlobs A vector of pairs of tree names and their corresponding file names/globs
115/// \param[in] alias String to refer to the particular friend
116///
117/// The filename glob supports the same type of expressions as TChain::Add().
118///
119/// ### Example usage:
120/// ~~~{.py}
121/// spec = ROOT.Internal.RDF.RDatasetSpec("tree", "file.root")
122/// spec.AddFriend([("tree1", "a.root"), ("tree2", "b.root")], "alias")
123/// df = ROOT.RDataFrame(spec)
124/// ~~~
125void RDatasetSpec::AddFriend(const std::vector<std::pair<std::string, std::string>> &treeAndFileNameGlobs,
126 const std::string &alias)
127{
128 fFriendInfo.AddFriend(treeAndFileNameGlobs, alias);
129}
130
131} // namespace RDF
132} // namespace Internal
133} // namespace ROOT
134/// \endcond
long long Long64_t
Definition RtypesCore.h:80
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...