Logo ROOT  
Reference Guide
InternalTreeUtils.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2021, 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
9/**
10 \file ROOT/InternalTreeUtils.hxx
11 \ingroup tree
12 \author Enric Tejedor Saavedra
13 \author Enrico Guiraud
14 \author Vincenzo Eduardo Padulano
15 \date 2021-03
16*/
17
18#ifndef ROOT_INTERNAL_TREEUTILS_H
19#define ROOT_INTERNAL_TREEUTILS_H
20
21#include "TChain.h"
22#include "TNotifyLink.h"
23#include "TObjArray.h"
24
25#include <memory>
26#include <string>
27#include <utility> // std::pair
28#include <vector>
29
30class TTree;
31
32namespace ROOT {
33namespace Internal {
34/**
35\namespace ROOT::Internal::TreeUtils
36\ingroup tree
37\brief Namespace hosting functions and classes to retrieve tree information for internal use.
38*/
39namespace TreeUtils {
40
41using NameAlias = std::pair<std::string, std::string>; ///< A pair of name and alias of a TTree's friend tree.
42/**
43\struct ROOT::Internal::TreeUtils::RFriendInfo
44\brief Information about friend trees of a certain TTree or TChain object.
45\ingroup tree
46*/
48
49 std::vector<NameAlias> fFriendNames; ///< Pairs of names and aliases of friend trees/chains.
50 /**
51 Names of the files where each friend is stored. fFriendFileNames[i] is the
52 list of files for friend with name fFriendNames[i].
53 */
54 std::vector<std::vector<std::string>> fFriendFileNames;
55 /**
56 Names of the subtrees of a friend TChain. fFriendChainSubNames[i] is the
57 list of names of the trees that make a friend TChain whose information is
58 stored at fFriendNames[i] and fFriendFileNames[i]. If instead the friend
59 tree at position `i` is a TTree, fFriendChainSubNames[i] will be an empty
60 vector.
61 */
62 std::vector<std::vector<std::string>> fFriendChainSubNames;
63
64 void AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias = "");
65
66 void
67 AddFriend(const std::string &treeName, const std::vector<std::string> &fileNameGlobs, const std::string &alias = "");
68
69 void AddFriend(const std::vector<std::pair<std::string, std::string>> &treeAndFileNameGlobs,
70 const std::string &alias = "");
71};
72
73std::vector<std::string> GetTopLevelBranchNames(TTree &t);
74std::vector<std::string> GetFileNamesFromTree(const TTree &tree);
76std::vector<std::string> GetTreeFullPaths(const TTree &tree);
77
79
81 TChain *fChain = nullptr;
82
83public:
84 bool Notify()
85 {
86 TTree *t = fChain->GetTree();
87 TObjArray *branches = t->GetListOfBranches();
88 ClearMustCleanupBits(*branches);
89 return true;
90 }
91
93};
94
95class RNoCleanupNotifier : public TNotifyLink<RNoCleanupNotifierHelper> {
97
98public:
100
102 {
104 this->PrependLink(c);
105 }
106
108};
109
110std::unique_ptr<TChain> MakeChainForMT(const std::string &name = "", const std::string &title = "");
111
112} // namespace TreeUtils
113} // namespace Internal
114} // namespace ROOT
115
116#endif // ROOT_INTERNAL_TREEUTILS_H
#define c(i)
Definition: RSha256.hxx:101
#define ClassDef(name, id)
Definition: Rtypes.h:335
char name[80]
Definition: TGX11.cxx:110
A chain is a collection of files containing TTree objects.
Definition: TChain.h:33
virtual TTree * GetTree() const
Definition: TChain.h:118
void PrependLink(Notifier &notifier)
Definition: TNotifyLink.h:56
An array of TObjects.
Definition: TObjArray.h:31
A TTree represents a columnar dataset.
Definition: TTree.h:79
virtual TObjArray * GetListOfBranches()
Definition: TTree.h:484
Different standalone functions to work with trees and tuples, not reqiuired to be a member of any cla...
std::vector< std::string > GetTreeFullPaths(const TTree &tree)
Retrieve the full path(s) to a TTree or the trees in a TChain.
RFriendInfo GetFriendInfo(const TTree &tree)
Get and store the names, aliases and file names of the direct friends of the tree.
std::vector< std::string > GetFileNamesFromTree(const TTree &tree)
Get and store the file names associated with the input tree.
std::vector< std::string > GetTopLevelBranchNames(TTree &t)
Get all the top-level branches names, including the ones of the friend trees.
std::pair< std::string, std::string > NameAlias
A pair of name and alias of a TTree's friend tree.
std::unique_ptr< TChain > MakeChainForMT(const std::string &name="", const std::string &title="")
Create a TChain object with options that avoid common causes of thread contention.
void ClearMustCleanupBits(TObjArray &arr)
Reset the kMustCleanup bit of a TObjArray of TBranch objects (e.g.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Definition: tree.py:1
Information about friend trees of a certain TTree or TChain object.
std::vector< NameAlias > fFriendNames
Pairs of names and aliases of friend trees/chains.
std::vector< std::vector< std::string > > fFriendFileNames
Names of the files where each friend is stored.
void AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias="")
Add information of a single friend.
std::vector< std::vector< std::string > > fFriendChainSubNames
Names of the subtrees of a friend TChain.