Logo ROOT  
Reference Guide
TTreeReaderGenerator.h
Go to the documentation of this file.
1 // @(#)root/treeplayer:$Id$
2 // Author: Akos Hajdu 22/06/2015
3 
4 /*************************************************************************
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  *************************************************************************/
11 
12 #ifndef ROOT_TTreeReaderGenerator
13 #define ROOT_TTreeReaderGenerator
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TTreeReaderGenerator //
18 // //
19 // Generate a Selector using the TTreeReader interface //
20 // (TTreeReaderValue, TTreeReaderArray) to access the data in the tree. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TTreeGeneratorBase.h"
25 
26 #include "TNamed.h"
27 #include <vector>
28 
29 class TBranch;
30 class TBranchElement;
31 class TLeaf;
32 
33 namespace ROOT {
34 namespace Internal {
35 
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 };
39 
40  class TTreeReaderDescriptor : public TObject {
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
47 
49  fType(type),
50  fDataType(dataType),
51  fName(name),
52  fBranchName(branchName) { }
53  };
54 
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)
63 
65  const char *branchname, const char *subBranchPrefix, ELocation isclones,
66  const TString &containerName, TBranchDescriptor *parent = 0) :
67  TNamed(type,type),
68  fIsClones(isclones),
69  fContainerName(containerName),
70  fBranchName(branchname),
71  fSubBranchPrefix(subBranchPrefix),
72  fInfo(info),
73  fParent(parent)
74  {
77  }
78  }
79 
80  Bool_t IsClones() const { return fIsClones == kClones; }
81 
82  Bool_t IsSTL() const { return fIsClones == kSTL; }
83  };
84 
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
93 
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);
101 
102  void ParseOptions();
103  void AnalyzeTree(TTree *tree);
104  void WriteSelector();
105 
106  public:
107  TTreeReaderGenerator(TTree* tree, const char *classname, Option_t *option);
108  };
109 }
110 }
111 
112 #endif
ROOT::Internal::TTreeReaderDescriptor
Definition: TTreeReaderGenerator.h:40
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
ROOT::Internal::TTreeReaderDescriptor::ReaderType
ReaderType
Definition: TTreeReaderGenerator.h:42
ROOT::Internal::TBranchDescriptor::IsClones
Bool_t IsClones() const
Definition: TTreeReaderGenerator.h:80
ROOT::Internal::TTreeReaderGenerator::WriteSelector
void WriteSelector()
Generate code for selector class.
Definition: TTreeReaderGenerator.cxx:795
ROOT::Internal::TTreeReaderDescriptor::kValue
@ kValue
Definition: TTreeReaderGenerator.h:42
ROOT::Internal::TBranchDescriptor
Definition: TTreeReaderGenerator.h:55
ROOT::Internal::TTreeReaderGenerator::fClassname
TString fClassname
Definition: TTreeReaderGenerator.h:87
TBranchElement
Definition: TBranchElement.h:39
ROOT::Internal::TTreeReaderGenerator::BranchNeedsReader
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...
Definition: TTreeReaderGenerator.cxx:600
tree
Definition: tree.py:1
ROOT::Internal::TBranchDescriptor::fContainerName
TString fContainerName
Definition: TTreeReaderGenerator.h:58
TNamed.h
TTree
Definition: TTree.h:79
ROOT::Internal::TTreeReaderDescriptor::TTreeReaderDescriptor
TTreeReaderDescriptor(ReaderType type, TString dataType, TString name, TString branchName)
Definition: TTreeReaderGenerator.h:48
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
ROOT::Internal::TTreeReaderDescriptor::kArray
@ kArray
Definition: TTreeReaderGenerator.h:42
ROOT::Internal::TTreeReaderDescriptor::fName
TString fName
Definition: TTreeReaderGenerator.h:45
ROOT::Internal::kClones
@ kClones
Definition: TTreeReaderGenerator.h:38
TString
Definition: TString.h:136
ROOT::Internal::TBranchDescriptor::TBranchDescriptor
TBranchDescriptor(const char *type, TVirtualStreamerInfo *info, const char *branchname, const char *subBranchPrefix, ELocation isclones, const TString &containerName, TBranchDescriptor *parent=0)
Definition: TTreeReaderGenerator.h:64
ROOT::Internal::TTreeReaderGenerator::TTreeReaderGenerator
TTreeReaderGenerator(TTree *tree, const char *classname, Option_t *option)
Constructor. Analyzes the tree and writes selector.
Definition: TTreeReaderGenerator.cxx:53
ROOT::Internal::kSTL
@ kSTL
Definition: TTreeReaderGenerator.h:38
TVirtualStreamerInfo
Definition: TVirtualStreamerInfo.h:37
bool
ROOT::Internal::TTreeReaderGenerator::fIncludeLeaves
std::vector< TString > fIncludeLeaves
Definition: TTreeReaderGenerator.h:91
ROOT::Internal::TBranchDescriptor::fInfo
TVirtualStreamerInfo * fInfo
Definition: TTreeReaderGenerator.h:61
TBranch
Definition: TBranch.h:89
ROOT::Internal::TBranchDescriptor::fParent
TBranchDescriptor * fParent
Definition: TTreeReaderGenerator.h:62
ROOT::Internal::TBranchDescriptor::fIsClones
ELocation fIsClones
Definition: TTreeReaderGenerator.h:57
ROOT::Internal::TBranchDescriptor::fBranchName
TString fBranchName
Definition: TTreeReaderGenerator.h:59
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
ROOT::Internal::TTreeReaderGenerator::ParseOptions
void ParseOptions()
Parse the user options.
Definition: TTreeReaderGenerator.cxx:629
ROOT::Internal::TTreeGeneratorBase
Definition: TTreeGeneratorBase.h:36
TLeaf
Definition: TLeaf.h:57
ROOT::Internal::TTreeReaderGenerator::AddReader
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.
Definition: TTreeReaderGenerator.cxx:65
TString::Remove
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
TNamed
Definition: TNamed.h:29
ROOT::Internal::TTreeReaderGenerator::AnalyzeOldBranch
UInt_t AnalyzeOldBranch(TBranch *branch)
Analyze branch and add the variables found.
Definition: TTreeReaderGenerator.cxx:470
ROOT::Internal::TTreeReaderGenerator
Definition: TTreeReaderGenerator.h:85
ROOT::Internal::TTreeReaderGenerator::AnalyzeOldLeaf
UInt_t AnalyzeOldLeaf(TLeaf *leaf, Int_t nleaves)
Analyze the leaf and add the variables found.
Definition: TTreeReaderGenerator.cxx:492
TTreeGeneratorBase.h
unsigned int
ROOT::Internal::TTreeReaderDescriptor::fType
ReaderType fType
Definition: TTreeReaderGenerator.h:43
ROOT::Internal::TTreeReaderDescriptor::fDataType
TString fDataType
Definition: TTreeReaderGenerator.h:44
ROOT::Internal::ELocation
ELocation
Definition: TTreeReaderGenerator.h:38
ROOT::Internal::TTreeReaderGenerator::fListOfReaders
TList fListOfReaders
Definition: TTreeReaderGenerator.h:88
ROOT::Internal::kOut
@ kOut
Definition: TTreeReaderGenerator.h:38
ROOT::Internal::TTreeReaderDescriptor::fBranchName
TString fBranchName
Definition: TTreeReaderGenerator.h:46
ROOT::Internal::TTreeReaderGenerator::fIncludeAllTopmost
Bool_t fIncludeAllTopmost
Definition: TTreeReaderGenerator.h:90
TObject
Definition: TObject.h:37
name
char name[80]
Definition: TGX11.cxx:110
TIter
Definition: TCollection.h:233
type
int type
Definition: TGX11.cxx:121
ROOT::Internal::TTreeReaderGenerator::AnalyzeTree
void AnalyzeTree(TTree *tree)
Analyze tree and extract readers.
Definition: TTreeReaderGenerator.cxx:657
ROOT::Internal::TTreeReaderGenerator::fIncludeStruct
std::vector< TString > fIncludeStruct
Definition: TTreeReaderGenerator.h:92
ROOT::Internal::TBranchDescriptor::fSubBranchPrefix
TString fSubBranchPrefix
Definition: TTreeReaderGenerator.h:60
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Internal::TTreeReaderGenerator::AnalyzeBranches
UInt_t AnalyzeBranches(TBranchDescriptor *desc, TBranchElement *branch, TVirtualStreamerInfo *info)
Analyse sub-branches of 'branch' recursively and extract readers.
Definition: TTreeReaderGenerator.cxx:97
ROOT::Internal::TBranchDescriptor::IsSTL
Bool_t IsSTL() const
Definition: TTreeReaderGenerator.h:82
TList
Definition: TList.h:44
ROOT::Internal::TTreeReaderGenerator::fIncludeAllLeaves
Bool_t fIncludeAllLeaves
Definition: TTreeReaderGenerator.h:89
int