Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFriendInfo.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2022, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
10#include <iterator> // std::back_inserter
11
12namespace ROOT {
13namespace TreeUtils {
14
15RFriendInfo::RFriendInfo(const RFriendInfo &other)
16{
17 *this = other;
18}
19
20RFriendInfo &RFriendInfo::operator=(const RFriendInfo &other)
21{
26
27 for (const auto &idxInfo : other.fTreeIndexInfos)
28 fTreeIndexInfos.emplace_back(static_cast<TVirtualIndex *>(idxInfo ? idxInfo->Clone() : nullptr));
29
30 return *this;
31}
32
33/// Construct a RFriendInfo object from its components.
34RFriendInfo::RFriendInfo(std::vector<std::pair<std::string, std::string>> friendNames,
35 std::vector<std::vector<std::string>> friendFileNames,
36 std::vector<std::vector<std::string>> friendChainSubNames,
37 std::vector<std::vector<Long64_t>> nEntriesPerTreePerFriend,
38 std::vector<std::unique_ptr<TVirtualIndex>> treeIndexInfos)
39 : fFriendNames(std::move(friendNames)),
40 fFriendFileNames(std::move(friendFileNames)),
41 fFriendChainSubNames(std::move(friendChainSubNames)),
42 fNEntriesPerTreePerFriend(std::move(nEntriesPerTreePerFriend)),
43 fTreeIndexInfos(std::move(treeIndexInfos))
44{
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// \brief Add information of a single friend.
49///
50/// \param[in] treeName Name of the tree.
51/// \param[in] fileNameGlob Path to the file. Refer to TChain::Add for globbing rules.
52/// \param[in] alias Alias for this friend.
53/// \param[in] nEntries Number of entries for this friend.
54/// \param[in] indexInfo Tree index info for this friend.
55void RFriendInfo::AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias,
56 Long64_t nEntries, TVirtualIndex *indexInfo)
57{
58 fFriendNames.emplace_back(std::make_pair(treeName, alias));
59 fFriendFileNames.emplace_back(std::vector<std::string>{fileNameGlob});
60 fFriendChainSubNames.emplace_back();
61 fNEntriesPerTreePerFriend.push_back(std::vector<Long64_t>({nEntries}));
62 fTreeIndexInfos.emplace_back(static_cast<TVirtualIndex *>(indexInfo ? indexInfo->Clone() : nullptr));
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// \brief Add information of a single friend.
67///
68/// \param[in] treeName Name of the tree.
69/// \param[in] fileNameGlobs Paths to the files. Refer to TChain::Add for globbing rules.
70/// \param[in] alias Alias for this friend.
71/// \param[in] nEntriesVec Number of entries for each file of this friend.
72/// \param[in] indexInfo Tree index info for this friend.
73void RFriendInfo::AddFriend(const std::string &treeName, const std::vector<std::string> &fileNameGlobs,
74 const std::string &alias, const std::vector<Long64_t> &nEntriesVec,
75 TVirtualIndex *indexInfo)
76{
77 fFriendNames.emplace_back(std::make_pair(treeName, alias));
78 fFriendFileNames.emplace_back(fileNameGlobs);
79 fFriendChainSubNames.emplace_back(std::vector<std::string>(fileNameGlobs.size(), treeName));
81 nEntriesVec.empty() ? std::vector<Long64_t>(fileNameGlobs.size(), std::numeric_limits<Long64_t>::max())
82 : nEntriesVec);
83 fTreeIndexInfos.emplace_back(static_cast<TVirtualIndex *>(indexInfo ? indexInfo->Clone() : nullptr));
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// \brief Add information of a single friend.
88///
89/// \param[in] treeAndFileNameGlobs Pairs of (treename, filename). Refer to TChain::Add for globbing rules.
90/// \param[in] alias Alias for this friend.
91/// \param[in] nEntriesVec Number of entries for each file of this friend.
92/// \param[in] indexInfo Tree index info for this friend.
93void RFriendInfo::AddFriend(const std::vector<std::pair<std::string, std::string>> &treeAndFileNameGlobs,
94 const std::string &alias, const std::vector<Long64_t> &nEntriesVec,
95 TVirtualIndex *indexInfo)
96{
97 fFriendNames.emplace_back(std::make_pair("", alias));
98
99 fFriendFileNames.emplace_back();
100 fFriendChainSubNames.emplace_back();
101
102 auto &theseFileNames = fFriendFileNames.back();
103 auto &theseChainSubNames = fFriendChainSubNames.back();
104 auto nPairs = treeAndFileNameGlobs.size();
105 theseFileNames.reserve(nPairs);
106 theseChainSubNames.reserve(nPairs);
107
108 auto fSubNamesIt = std::back_inserter(theseChainSubNames);
109 auto fNamesIt = std::back_inserter(theseFileNames);
110
111 for (const auto &names : treeAndFileNameGlobs) {
112 *fSubNamesIt = names.first;
113 *fNamesIt = names.second;
114 }
116 nEntriesVec.empty() ? std::vector<Long64_t>(treeAndFileNameGlobs.size(), std::numeric_limits<Long64_t>::max())
117 : nEntriesVec);
118 fTreeIndexInfos.emplace_back(static_cast<TVirtualIndex *>(indexInfo ? indexInfo->Clone() : nullptr));
119}
120
121} // namespace TreeUtils
122} // namespace ROOT
long long Long64_t
Definition RtypesCore.h:80
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition TNamed.cxx:74
Abstract interface for Tree Index.
Different standalone functions to work with trees and tuples, not reqiuired to be a member of any cla...
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.
std::vector< std::pair< std::string, std::string > > fFriendNames
Pairs of names and aliases of each friend tree/chain.
std::vector< std::vector< std::string > > fFriendChainSubNames
Names of the subtrees of a friend TChain.
std::vector< std::unique_ptr< TVirtualIndex > > fTreeIndexInfos
Information on the friend's TTreeIndexes.
std::vector< std::vector< std::string > > fFriendFileNames
Names of the files where each friend is stored.
std::vector< std::vector< Long64_t > > fNEntriesPerTreePerFriend
Number of entries contained in each tree of each friend.