Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RSample.cxx
Go to the documentation of this file.
1// Author: Ivan Kabadzhov CERN 11/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
11#include "ROOT/RDF/RSample.hxx"
12#include "TChain.h"
13#include <stdexcept> // std::logic_error
14
15namespace ROOT {
16namespace RDF {
17namespace Experimental {
18
19RSample::RSample(const std::string &sampleName, const std::string &treeName, const std::string &fileNameGlob,
20 const RMetaData &metaData)
21 : RSample(sampleName, std::vector<std::string>{treeName}, std::vector<std::string>{fileNameGlob}, metaData)
22{
23}
24
25RSample::RSample(const std::string &sampleName, const std::string &treeName,
26 const std::vector<std::string> &fileNameGlobs, const RMetaData &metaData)
27 : RSample(sampleName, std::vector<std::string>(fileNameGlobs.size(), treeName), fileNameGlobs, metaData)
28{
29}
30
31RSample::RSample(const std::string &sampleName,
32 const std::vector<std::pair<std::string, std::string>> &treeAndFileNameGlobs,
33 const RMetaData &metaData)
34 : fSampleName(sampleName), fMetaData(metaData)
35{
36 // avoid constructing and destructing the helper TChain here if we don't need to
37 if (treeAndFileNameGlobs.empty())
38 return;
39
40 TChain chain;
41 for (const auto &p : treeAndFileNameGlobs) {
42 const auto fullpath = p.second + "?#" + p.first;
43 chain.Add(fullpath.c_str());
44 }
45 const auto &expandedNames = chain.GetListOfFiles();
46 fTreeNames.reserve(expandedNames->GetEntries());
47 fFileNameGlobs.reserve(expandedNames->GetEntries());
48 for (auto i = 0; i < expandedNames->GetEntries(); ++i) {
49 fTreeNames.emplace_back(expandedNames->At(i)->GetName());
50 fFileNameGlobs.emplace_back(expandedNames->At(i)->GetTitle());
51 }
52}
53
54RSample::RSample(const std::string &sampleName, const std::vector<std::string> &treeNames,
55 const std::vector<std::string> &fileNameGlobs, const RMetaData &metaData)
56 : fSampleName(sampleName), fMetaData(metaData)
57{
58 if (treeNames.size() != 1 && treeNames.size() != fileNameGlobs.size())
59 throw std::logic_error("Mismatch between number of trees and file globs.");
60 TChain chain;
61 for (auto i = 0u; i < fileNameGlobs.size(); ++i) {
62 const auto fullpath = fileNameGlobs[i] + "?#" + (treeNames.size() == 1u ? treeNames[0] : treeNames[i]);
63 chain.Add(fullpath.c_str());
64 }
65 const auto &expandedNames = chain.GetListOfFiles();
66 fTreeNames.reserve(expandedNames->GetEntries());
67 fFileNameGlobs.reserve(expandedNames->GetEntries());
68 for (auto i = 0; i < expandedNames->GetEntries(); ++i) {
69 fTreeNames.emplace_back(expandedNames->At(i)->GetName());
70 fFileNameGlobs.emplace_back(expandedNames->At(i)->GetTitle());
71 }
72}
73
74/// @brief Get the name of the sample (RSample object).
75const std::string &RSample::GetSampleName() const
76{
77 return fSampleName;
78}
79
80/// @brief Get the collection of the tree names associated with the sample.
81const std::vector<std::string> &RSample::GetTreeNames() const
82{
83 return fTreeNames;
84}
85
86/// @brief Get the collection of the filename globs associated with the sample.
87const std::vector<std::string> &RSample::GetFileNameGlobs() const
88{
89 return fFileNameGlobs;
90}
91
92/// @brief Get an instance of the RMetaData class.
93///
94/// Once this is done, the further access to the RMetaData information is granted, for example
95/// (given the metadata has a key "sample_name" that has an associated value of type string):
96/// ~~~{.cpp}
97/// mySample.GetMetadata().GetS("sample_name");
98/// ~~~
100{
101 return fMetaData;
102}
103
104unsigned int RSample::GetSampleId() const
105{
106 return fSampleId;
107}
108
109void RSample::SetSampleId(unsigned int id)
110{
111 fSampleId = id;
112}
113
114} // namespace Experimental
115} // namespace RDF
116} // namespace ROOT
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Class behaving as a heterogenuous dictionary to store the metadata of a dataset.
Definition RMetaData.hxx:50
Class representing a sample which is a grouping of trees and their fileglobs, and,...
Definition RSample.hxx:39
const std::string & GetSampleName() const
Get the name of the sample (RSample object).
Definition RSample.cxx:75
const std::vector< std::string > & GetFileNameGlobs() const
Get the collection of the filename globs associated with the sample.
Definition RSample.cxx:87
RMetaData fMetaData
An instance of the RMetaData class.
Definition RSample.hxx:55
std::vector< std::string > fFileNameGlobs
A list of file names.
Definition RSample.hxx:53
const std::vector< std::string > & GetTreeNames() const
Get the collection of the tree names associated with the sample.
Definition RSample.cxx:81
unsigned int fSampleId
Global sample index, set inside of the RDatasetSpec.
Definition RSample.hxx:58
std::string fSampleName
Name of the sample.
Definition RSample.hxx:41
const RMetaData & GetMetaData() const
Get an instance of the RMetaData class.
Definition RSample.cxx:99
std::vector< std::string > fTreeNames
A list of names of trees.
Definition RSample.hxx:48
A chain is a collection of files containing TTree objects.
Definition TChain.h:33
TObjArray * GetListOfFiles() const
Definition TChain.h:111
virtual Int_t Add(TChain *chain)
Add all files referenced by the passed chain to this chain.
Definition TChain.cxx:219
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...