ROOT  6.06/09
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 
96  TString branchName, TBranchDescriptor *parent = 0, Bool_t isLeaf = kTRUE);
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
UInt_t AnalyzeOldLeaf(TLeaf *leaf, Int_t nleaves)
Analyze the leaf and add the variables found.
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
Ssiz_t Length() const
Definition: TString.h:390
const char Option_t
Definition: RtypesCore.h:62
void AnalyzeTree(TTree *tree)
Analyze tree and extract readers.
TTreeReaderGenerator(TTree *tree, const char *classname, Option_t *option)
Constructor. Analyzes the tree and writes selector.
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
UInt_t AnalyzeBranches(TBranchDescriptor *desc, TBranchElement *branch, TVirtualStreamerInfo *info)
Analyse sub-branches of 'branch' recursively and extract readers.
void WriteSelector()
Generate code for selector class.
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
A Branch for the case of an object.
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
int type
Definition: TGX11.cxx:120
void ParseOptions()
Parse the user options.
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
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...
A TTree object has a header with a name and a title.
Definition: TTree.h:94
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.
UInt_t AnalyzeOldBranch(TBranch *branch)
Analyze branch and add the variables found.
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