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 <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
31const std::vector<std::string> RDatasetSpec::GetSampleNames() const
32{
33 std::vector<std::string> sampleNames;
34 sampleNames.reserve(fSamples.size());
35 for (const auto &sample : fSamples)
36 sampleNames.emplace_back(sample.GetSampleName());
37 return sampleNames;
38}
39
40const std::vector<std::string> RDatasetSpec::GetTreeNames() const
41{
42 std::vector<std::string> treeNames;
43 for (const auto &sample : fSamples) {
44 const auto &trees = sample.GetTreeNames();
45 treeNames.insert(std::end(treeNames), std::begin(trees), std::end(trees));
46 }
47 return treeNames;
48}
49
50const std::vector<std::string> RDatasetSpec::GetFileNameGlobs() const
51{
52 std::vector<std::string> fileNames;
53 for (const auto &sample : fSamples) {
54 const auto &files = sample.GetFileNameGlobs();
55 fileNames.insert(std::end(fileNames), std::begin(files), std::end(files));
56 }
57 return fileNames;
58}
59
60const std::vector<RMetaData> RDatasetSpec::GetMetaData() const
61{
62 std::vector<RMetaData> metaDatas;
63 metaDatas.reserve(fSamples.size());
64 for (const auto &sample : fSamples)
65 metaDatas.emplace_back(sample.GetMetaData());
66 return metaDatas;
67}
68
70{
71 return fFriendInfo;
72}
73
75{
76 return fEntryRange.fBegin;
77}
78
80{
81 return fEntryRange.fEnd;
82}
83
84std::vector<RSample> RDatasetSpec::MoveOutSamples()
85{
86 return std::move(fSamples);
87}
88
90{
91 sample.SetSampleId(fSamples.size());
92 fSamples.push_back(std::move(sample));
93 return *this;
94}
95
97RDatasetSpec::WithGlobalFriends(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias)
98{
99 fFriendInfo.AddFriend(treeName, fileNameGlob, alias);
100 return *this;
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// \brief Add friend tree to RDatasetSpec object
105///
106/// \param[in] treeName Name of the tree.
107/// \param[in] fileNameGlob Path to the file. Refer to TChain::Add for globbing rules.
108/// \param[in] alias Alias for this friend.
109///
110/// ### Example usage:
111/// ~~~{.cpp}
112/// ROOT::RDF::Experimental::RDatasetSpec x;
113/// std::vector<std::string> files = {"outputFile.root"};
114/// //create RSample object with name myPhysicsDf and tree outputTree1
115/// ROOT::RDF::Experimental::RSample r("myPhysicsDf", "outputTree1", files);
116/// x.AddSample(r); //add RDatasetSpec to RDatasetSpec
117/// x.WithGlobalFriends("outputTree2", files); //add friend tree outputTree2
118/// ~~~
120 const std::vector<std::string> &fileNameGlobs, const std::string &alias)
121{
122 fFriendInfo.AddFriend(treeName, fileNameGlobs, alias);
123 return *this;
124}
125
127RDatasetSpec::WithGlobalFriends(const std::vector<std::pair<std::string, std::string>> &treeAndFileNameGlobs,
128 const std::string &alias)
129{
130 fFriendInfo.AddFriend(treeAndFileNameGlobs, alias);
131 return *this;
132}
133
135{
136 fEntryRange = entryRange;
137 return *this;
138}
139
140RDatasetSpec &RDatasetSpec::WithGlobalFriends(const std::vector<std::string> &treeNames,
141 const std::vector<std::string> &fileNameGlobs, const std::string &alias)
142{
143 if (treeNames.size() != 1 && treeNames.size() != fileNameGlobs.size())
144 throw std::logic_error("Mismatch between number of trees and file globs.");
145 std::vector<std::pair<std::string, std::string>> target;
146 target.reserve(fileNameGlobs.size());
147 for (auto i = 0u; i < fileNameGlobs.size(); ++i)
148 target.emplace_back(std::make_pair((treeNames.size() == 1u ? treeNames[0] : treeNames[i]), fileNameGlobs[i]));
150 return *this;
151}
152
153} // namespace Experimental
154} // namespace RDF
155} // namespace ROOT
long long Long64_t
Definition RtypesCore.h:80
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
A dataset specification for RDataFrame.
const std::vector< std::string > GetFileNameGlobs() const
std::vector< RSample > MoveOutSamples()
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="")
const std::vector< std::string > GetTreeNames() const
const ROOT::TreeUtils::RFriendInfo & GetFriendInfo() const
const std::vector< RMetaData > GetMetaData() const
RDatasetSpec & AddSample(RSample sample)
ROOT::TreeUtils::RFriendInfo fFriendInfo
List of friends.
RDatasetSpec & WithGlobalRange(const RDatasetSpec::REntryRange &entryRange={})
std::vector< RSample > fSamples
List of samples.
const std::vector< std::string > GetSampleNames() const
Class representing a sample (grouping of trees (and their fileglobs) and (optional) metadata)
Definition RSample.hxx:29
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.
void AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias="", std::int64_t nEntries=std::numeric_limits< std::int64_t >::max(), TVirtualIndex *indexInfo=nullptr)
Add information of a single friend.