Logo ROOT  
Reference Guide
Go to the documentation of this file.
1// @(#)root/treeplayer:$Id$
2// Author: Akos Hajdu 22/06/2015
5 * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers and al. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
12#ifndef ROOT_TTreeReaderGenerator
13#define ROOT_TTreeReaderGenerator
16// //
17// TTreeReaderGenerator //
18// //
19// Generate a Selector using the TTreeReader interface //
20// (TTreeReaderValue, TTreeReaderArray) to access the data in the tree. //
21// //
24#include "TTreeGeneratorBase.h"
26#include "TNamed.h"
27#include <vector>
29class TBranch;
30class TBranchElement;
31class TLeaf;
33namespace ROOT {
34namespace Internal {
36 /// 0 for the general case, 1 when this a split clases inside a TClonesArray,
37 /// 2 when this is a split classes inside an STL container.
38 enum ELocation { kOut=0, kClones, kSTL };
41 public:
43 ReaderType fType; ///< Type of the reader: Value or Array
44 TString fDataType; ///< Data type of reader
45 TString fName; ///< Reader name
46 TString fBranchName; ///< Branch corresponding to the reader
49 fType(type),
50 fDataType(dataType),
51 fName(name),
52 fBranchName(branchName) { }
53 };
55 class TBranchDescriptor : public TNamed {
56 public:
57 ELocation fIsClones; ///< Type of container
58 TString fContainerName; ///< Name of the container
59 TString fBranchName; ///< Name of the branch
60 TString fSubBranchPrefix;///< Prefix (e.g. if the branch name is "A." the prefix is "A"
61 TVirtualStreamerInfo *fInfo; ///< Streamer info
62 TBranchDescriptor *fParent; ///< Descriptor of the parent branch (NULL for topmost)
65 const char *branchname, const char *subBranchPrefix, ELocation isclones,
66 const TString &containerName, TBranchDescriptor *parent = 0) :
68 fIsClones(isclones),
69 fContainerName(containerName),
70 fBranchName(branchname),
71 fSubBranchPrefix(subBranchPrefix),
72 fInfo(info),
73 fParent(parent)
74 {
77 }
78 }
80 Bool_t IsClones() const { return fIsClones == kClones; }
82 Bool_t IsSTL() const { return fIsClones == kSTL; }
83 };
86 {
87 TString fClassname; ///< Class name of the selector
88 TList fListOfReaders; ///< List of readers
89 Bool_t fIncludeAllLeaves; ///< Should all leaves be included
90 Bool_t fIncludeAllTopmost; ///< Should all topmost branches be included
91 std::vector<TString> fIncludeLeaves; ///< Branches whose leaves should be included
92 std::vector<TString> fIncludeStruct; ///< Branches whom should be included
95 TString branchName, TBranchDescriptor *parent = 0, Bool_t isLeaf = kTRUE);
99 UInt_t AnalyzeOldLeaf(TLeaf *leaf, Int_t nleaves);
100 Bool_t BranchNeedsReader(TString branchName, TBranchDescriptor *parent, Bool_t isLeaf);
102 void ParseOptions();
103 void AnalyzeTree(TTree *tree);
104 void WriteSelector();
106 public:
107 TTreeReaderGenerator(TTree* tree, const char *classname, Option_t *option);
108 };
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
char name[80]
Definition: TGX11.cxx:110
int type
Definition: TGX11.cxx:121
TString fBranchName
Name of the branch.
TVirtualStreamerInfo * fInfo
Streamer info.
ELocation fIsClones
Type of container.
TBranchDescriptor(const char *type, TVirtualStreamerInfo *info, const char *branchname, const char *subBranchPrefix, ELocation isclones, const TString &containerName, TBranchDescriptor *parent=0)
TBranchDescriptor * fParent
Descriptor of the parent branch (NULL for topmost)
TString fContainerName
Name of the container.
TString fSubBranchPrefix
Prefix (e.g. if the branch name is "A." the prefix is "A".
Base class for code generators like TTreeProxyGenerator and TTreeReaderGenerator.
TString fBranchName
Branch corresponding to the reader.
ReaderType fType
Type of the reader: Value or Array.
TString fDataType
Data type of reader.
TTreeReaderDescriptor(ReaderType type, TString dataType, TString name, TString branchName)
std::vector< TString > fIncludeStruct
Branches whom should be included.
void AnalyzeTree(TTree *tree)
Analyze tree and extract readers.
TString fClassname
Class name of the selector.
std::vector< TString > fIncludeLeaves
Branches whose leaves should be included.
UInt_t AnalyzeBranches(TBranchDescriptor *desc, TBranchElement *branch, TVirtualStreamerInfo *info)
Analyse sub-branches of 'branch' recursively and extract readers.
void ParseOptions()
Parse the user options.
Bool_t fIncludeAllTopmost
Should all topmost branches be included.
TTreeReaderGenerator(TTree *tree, const char *classname, Option_t *option)
Constructor. Analyzes the tree and writes selector.
void AddReader(TTreeReaderDescriptor::ReaderType type, TString dataType, TString name, TString branchName, TBranchDescriptor *parent=0, Bool_t isLeaf=kTRUE)
Add a reader to the generated code.
Bool_t BranchNeedsReader(TString branchName, TBranchDescriptor *parent, Bool_t isLeaf)
Check whether a branch should have a corresponding reader added, depending on the options provided by...
UInt_t AnalyzeOldLeaf(TLeaf *leaf, Int_t nleaves)
Analyze the leaf and add the variables found.
UInt_t AnalyzeOldBranch(TBranch *branch)
Analyze branch and add the variables found.
void WriteSelector()
Generate code for selector class.
Bool_t fIncludeAllLeaves
Should all leaves be included.
A Branch for the case of an object.
A TTree is a list of TBranches.
Definition: TBranch.h:89
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:57
A doubly linked list.
Definition: TList.h:44
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:136
Ssiz_t Length() const
Definition: TString.h:410
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
A TTree represents a columnar dataset.
Definition: TTree.h:79
Abstract Interface class describing Streamer information for one class.
0 for the general case, 1 when this a split clases inside a TClonesArray, 2 when this is a split clas...
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Definition: tree.py:1