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
74const std::string &RSample::GetSampleName() const
75{
76 return fSampleName;
77}
78
79const std::vector<std::string> &RSample::GetTreeNames() const
80{
81 return fTreeNames;
82}
83
84const std::vector<std::string> &RSample::GetFileNameGlobs() const
85{
86 return fFileNameGlobs;
87}
88
90{
91 return fMetaData;
92}
93
94unsigned int RSample::GetSampleId() const
95{
96 return fSampleId;
97}
98
99void RSample::SetSampleId(unsigned int id)
100{
101 fSampleId = id;
102}
103
104} // namespace Experimental
105} // namespace RDF
106} // 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 dataset metadata.
Definition RMetaData.hxx:40
Class representing a sample (grouping of trees (and their fileglobs) and (optional) metadata)
Definition RSample.hxx:29
const std::string & GetSampleName() const
Definition RSample.cxx:74
const std::vector< std::string > & GetFileNameGlobs() const
Definition RSample.cxx:84
std::vector< std::string > fFileNameGlobs
A list of file names.
Definition RSample.hxx:42
const std::vector< std::string > & GetTreeNames() const
Definition RSample.cxx:79
const RMetaData & GetMetaData() const
Definition RSample.cxx:89
std::vector< std::string > fTreeNames
A list of names of trees.
Definition RSample.hxx:37
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
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.