Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <ROOT/RFriendInfo.hxx>
13#include <stdexcept> // std::logic_error
14
15namespace ROOT {
16
17namespace RDF {
18
19namespace Experimental {
20
22
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/// \brief Returns the collection of the dataset's sample names.
34const std::vector<std::string> RDatasetSpec::GetSampleNames() const
35{
36 std::vector<std::string> sampleNames;
37 sampleNames.reserve(fSamples.size());
38 for (const auto &sample : fSamples)
39 sampleNames.emplace_back(sample.GetSampleName());
40 return sampleNames;
41}
42
43////////////////////////////////////////////////////////////////////////////////
44/// \brief Returns the collection of the dataset's tree names.
45const std::vector<std::string> RDatasetSpec::GetTreeNames() const
46{
47 std::vector<std::string> treeNames;
48 for (const auto &sample : fSamples) {
49 const auto &trees = sample.GetTreeNames();
50 treeNames.insert(std::end(treeNames), std::begin(trees), std::end(trees));
51 }
52 return treeNames;
53}
54////////////////////////////////////////////////////////////////////////////////
55/// \brief Returns the collection of the dataset's paths to files, or globs if specified in input.
56const std::vector<std::string> RDatasetSpec::GetFileNameGlobs() const
57{
58 std::vector<std::string> fileNames;
59 for (const auto &sample : fSamples) {
60 const auto &files = sample.GetFileNameGlobs();
61 fileNames.insert(std::end(fileNames), std::begin(files), std::end(files));
62 }
63 return fileNames;
64}
65////////////////////////////////////////////////////////////////////////////////
66/// \brief Returns the collection of the dataset's metadata (RMetaData class objects).
67const std::vector<RMetaData> RDatasetSpec::GetMetaData() const
68{
69 std::vector<RMetaData> metaDatas;
70 metaDatas.reserve(fSamples.size());
71 for (const auto &sample : fSamples)
72 metaDatas.emplace_back(sample.GetMetaData());
73 return metaDatas;
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// \brief Returns the reference to the friend tree information.
79{
80 return *std::any_cast<ROOT::TreeUtils::RFriendInfo>(&fFriendInfo);
81}
82
84{
85 return *std::any_cast<ROOT::TreeUtils::RFriendInfo>(&fFriendInfo);
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// \brief Returns the first entry as defined by the global range provided in the specification.
90/// The first entry is inclusive.
95
96////////////////////////////////////////////////////////////////////////////////
97/// \brief Returns the last entry as defined by the global range provided in the specification.
98/// The last entry is exclusive.
103
104////////////////////////////////////////////////////////////////////////////////
105/// \brief Returns a collection of instances of the RSample class.
106/// RSample class represents a sample i.e. a grouping of trees (and their corresponding fileglobs) and, optionally, the
107/// sample's metadata.
108std::vector<RSample> RDatasetSpec::MoveOutSamples()
109{
110 return std::move(fSamples);
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// \brief Add sample (RSample class object) to the RDatasetSpec object.
115/// \param[in] sample RSample class object.
116/// RSample class represents a sample i.e. a grouping of trees (and their corresponding fileglobs) and, optionally, the
117/// sample's metadata.
118/// ### Example usage:
119/// Our goal is to create an RDataFrame from the RDatasetSpec object.
120/// In order to do that, we need to create an RSample object first.
121/// In order to make this example even fuller, before we create the RSample object,
122/// we also create the RMetaData object which will be associated with our RSample object.
123/// Note that adding this metadata information to the RSample object is optional.
124/// ~~~{.cpp}
125/// // Create the RMetaData object which will be used to create the RSample object.
126/// ROOT::RDF::Experimental::RMetaData meta;
127/// meta.Add("sample_name", "name");
128/// // Create the RSample object "mySample" with sample name "mySampleName", tree name "outputTree1",
129/// // file name "outputFile.root" and associated metadata information.
130/// ROOT::RDF::Experimental::RSample mySample("mySampleName", "outputTree1", "outputFile.root", meta);
131/// // Create the RDatasetSpec object to which we add the sample (RSample object).
132/// ROOT::RDF::Experimental::RDatasetSpec spec;
133/// spec.AddSample(mySample);
134/// // Finally, create an RDataFrame from the RDatasetSpec object.
135/// auto df = ROOT::RDataFrame(spec);
136/// ~~~
138{
139 sample.SetSampleId(fSamples.size());
140 fSamples.push_back(std::move(sample));
141 return *this;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// \brief Add friend tree to RDatasetSpec object
146/// \param[in] treeName Name of the tree.
147/// \param[in] fileNameGlob Path to the file in which the tree is stored. Refer to TChain::Add for globbing rules.
148/// \param[in] alias Alias for this friend.
149///
150/// ### Example usage:
151/// ~~~{.cpp}
152/// ROOT::RDF::Experimental::RSample s("mySample", "outputTree1", "outputFile.root");
153/// ROOT::RDF::Experimental::RDatasetSpec spec;
154/// spec.AddSample(s);
155/// // Add friend tree "outputTree2" with the alias "myTreeFriend"
156/// spec.WithGlobalFriends("outputTree2", "outputFile.root", "myTreeFriend");
157/// auto df = ROOT::RDataFrame(spec);
158/// ~~~
160RDatasetSpec::WithGlobalFriends(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias)
161{
163 return *this;
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// \brief Add friend tree to RDatasetSpec object
168///
169/// \param[in] treeName Name of the tree.
170/// \param[in] fileNameGlobs Collection of paths to the files in which the tree is stored. Refer to TChain::Add for
171/// globbing rules. \param[in] alias Alias for this friend.
173 const std::vector<std::string> &fileNameGlobs, const std::string &alias)
174{
176 return *this;
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// \brief Add friend tree to RDatasetSpec object
181/// \param[in] treeAndFileNameGlobs Collection of pairs of paths to trees and paths to files.
182/// \param[in] alias Alias for this friend.
184RDatasetSpec::WithGlobalFriends(const std::vector<std::pair<std::string, std::string>> &treeAndFileNameGlobs,
185 const std::string &alias)
186{
188 return *this;
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// \brief Add friend tree to RDatasetSpec object
193/// \param[in] treeNames Collection of paths to trees.
194/// \param[in] fileNameGlobs Collection of paths to files.
195/// \param[in] alias Alias for this friend.
197 const std::vector<std::string> &fileNameGlobs, const std::string &alias)
198{
199 if (treeNames.size() != 1 && treeNames.size() != fileNameGlobs.size())
200 throw std::logic_error("Mismatch between number of trees and file globs.");
201 std::vector<std::pair<std::string, std::string>> target;
202 target.reserve(fileNameGlobs.size());
203 for (auto i = 0u; i < fileNameGlobs.size(); ++i)
204 target.emplace_back(std::make_pair((treeNames.size() == 1u ? treeNames[0] : treeNames[i]), fileNameGlobs[i]));
206 return *this;
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// \brief Create an RDatasetSpec object for a given range of entries
211/// \param[in] entryRange
212///
213/// ## Example usage:
214/// ~~~{.cpp}
215/// ROOT::RDF::Experimental::RSample s("mySample", "outputTree1", "outputFile.root");
216/// ROOT::RDF::Experimental::RDatasetSpec spec;
217/// spec.AddSample(s);
218/// // Set the entries range to be processed: including entry 1 and excluding entry 10.
219/// spec.WithGlobalRange({1, 10});
220/// auto df = ROOT::RDataFrame(spec);
221/// ~~~
227
228} // namespace Experimental
229} // namespace RDF
230} // namespace ROOT
231
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
The dataset specification for RDataFrame.
const std::vector< std::string > GetFileNameGlobs() const
Returns the collection of the dataset's paths to files, or globs if specified in input.
std::any fFriendInfo
List of friends.
REntryRange fEntryRange
Start (inclusive) and end (exclusive) entry for the dataset processing.
RDatasetSpec & WithGlobalFriends(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias="")
Add friend tree to RDatasetSpec object.
const std::vector< std::string > GetTreeNames() const
Returns the collection of the dataset's tree names.
friend std::vector< ROOT::RDF::Experimental::RSample > ROOT::Internal::RDF::MoveOutSamples(ROOT::RDF::Experimental::RDatasetSpec &)
Long64_t GetEntryRangeBegin() const
Returns the first entry as defined by the global range provided in the specification.
const std::vector< RMetaData > GetMetaData() const
Returns the collection of the dataset's metadata (RMetaData class objects).
RDatasetSpec & AddSample(RSample sample)
Add sample (RSample class object) to the RDatasetSpec object.
ROOT::TreeUtils::RFriendInfo & GetFriendInfo()
RDatasetSpec & WithGlobalRange(const RDatasetSpec::REntryRange &entryRange={})
Create an RDatasetSpec object for a given range of entries.
std::vector< RSample > fSamples
List of samples.
const std::vector< std::string > GetSampleNames() const
Returns the collection of the dataset's sample names.
Long64_t GetEntryRangeEnd() const
Returns the last entry as defined by the global range provided in the specification.
Class representing a sample which is a grouping of trees and their fileglobs, and,...
Definition RSample.hxx:39
Namespace for new ROOT classes and functions.
Information about friend trees of a certain TTree or TChain object.
void AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias="", Long64_t nEntries=TTree::kMaxEntries, TVirtualIndex *indexInfo=nullptr)
Add information of a single friend.