Logo ROOT   6.08/07
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 #ifndef ROOT_TNamed
27 #include "TNamed.h"
28 #endif
29 
30 class TBranch;
31 class TBranchElement;
32 class TLeaf;
33 
34 namespace ROOT {
35 namespace Internal {
36 
37  // 0 for the general case, 1 when this a split clases inside a TClonesArray,
38  // 2 when this is a split classes inside an STL container.
39  enum ELocation { kOut=0, kClones, kSTL };
40 
41  class TTreeReaderDescriptor : public TObject {
42  public:
44  ReaderType fType; // Type of the reader: Value or Array
45  TString fDataType; // Data type of reader
46  TString fName; // Reader name
47  TString fBranchName; // Branch corresponding to the reader
48 
50  fType(type),
51  fDataType(dataType),
52  fName(name),
53  fBranchName(branchName) { }
54  };
55 
56  class TBranchDescriptor : public TNamed {
57  public:
58  ELocation fIsClones; // Type of container
59  TString fContainerName; // Name of the container
60  TString fBranchName; // Name of the branch
61  TString fSubBranchPrefix;// Prefix (e.g. if the branch name is "A." the prefix is "A"
62  TVirtualStreamerInfo *fInfo; // Streamer info
63  TBranchDescriptor *fParent; // Descriptor of the parent branch (NULL for topmost)
64 
66  const char *branchname, const char *subBranchPrefix, ELocation isclones,
67  const TString &containerName, TBranchDescriptor *parent = 0) :
68  TNamed(type,type),
69  fIsClones(isclones),
70  fContainerName(containerName),
71  fBranchName(branchname),
72  fSubBranchPrefix(subBranchPrefix),
73  fInfo(info),
74  fParent(parent)
75  {
76  if (fSubBranchPrefix.Length() && fSubBranchPrefix[fSubBranchPrefix.Length() - 1] == '.') {
77  fSubBranchPrefix.Remove(fSubBranchPrefix.Length()-1);
78  }
79  }
80 
81  Bool_t IsClones() const { return fIsClones == kClones; }
82 
83  Bool_t IsSTL() const { return fIsClones == kSTL; }
84  };
85 
87  {
88  TString fClassname; // Class name of the selector
89  TList fListOfReaders; // List of readers
90  Bool_t fIncludeAllLeaves; // Should all leaves be included
91  Bool_t fIncludeAllTopmost; // Should all topmost branches be included
92  std::vector<TString> fIncludeLeaves; // Branches whose leaves should be included
93  std::vector<TString> fIncludeStruct; // Branches whom should be included
94 
95  void AddReader(TTreeReaderDescriptor::ReaderType type, TString dataType, TString name,
96  TString branchName, TBranchDescriptor *parent = 0, Bool_t isLeaf = kTRUE);
97  UInt_t AnalyzeBranches(TBranchDescriptor *desc, TBranchElement *branch, TVirtualStreamerInfo *info);
98  UInt_t AnalyzeBranches(TBranchDescriptor *desc, TIter &branches, TVirtualStreamerInfo *info);
99  UInt_t AnalyzeOldBranch(TBranch *branch);
100  UInt_t AnalyzeOldLeaf(TLeaf *leaf, Int_t nleaves);
101  Bool_t BranchNeedsReader(TString branchName, TBranchDescriptor *parent, Bool_t isLeaf);
102 
103  void ParseOptions();
104  void AnalyzeTree(TTree *tree);
105  void WriteSelector();
106 
107  public:
108  TTreeReaderGenerator(TTree* tree, const char *classname, Option_t *option);
109  };
110 }
111 }
112 
113 #endif
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:37
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
const char Option_t
Definition: RtypesCore.h:62
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
TTreeReaderDescriptor(ReaderType type, TString dataType, TString name, TString branchName)
A doubly linked list.
Definition: TList.h:47
TBranchDescriptor(const char *type, TVirtualStreamerInfo *info, const char *branchname, const char *subBranchPrefix, ELocation isclones, const TString &containerName, TBranchDescriptor *parent=0)
unsigned int UInt_t
Definition: RtypesCore.h:42
Ssiz_t Length() const
Definition: TString.h:390
A Branch for the case of an object.
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
int type
Definition: TGX11.cxx:120
Mother of all ROOT objects.
Definition: TObject.h:37
Definition: tree.py:1
A TTree object has a header with a name and a title.
Definition: TTree.h:98
A TTree is a list of TBranches.
Definition: TBranch.h:58
Abstract Interface class describing Streamer information for one class.
const Bool_t kTRUE
Definition: Rtypes.h:91
char name[80]
Definition: TGX11.cxx:109