Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTreeGeneratorBase.cxx
Go to the documentation of this file.
1// @(#)root/treeplayer:$Id$
2// Author: Akos Hajdu 13/08/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#include "TTreeGeneratorBase.h"
13
14#include "TBranchElement.h"
15#include "TClass.h"
16#include "TClassEdit.h"
17#include "TClonesArray.h"
18#include "TDirectory.h"
19#include "TFile.h"
20#include "TStreamerElement.h"
21#include "TStreamerInfo.h"
22#include "TTree.h"
23#include "TError.h"
26
27namespace ROOT {
28namespace Internal {
29
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Constructor.
32
33 TTreeGeneratorBase::TTreeGeneratorBase(TTree *tree, const char *option) : fTree(tree), fOptionStr(option) { }
34
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Add a header inclusion request. If the header is already included it will
37 /// not be included again.
38
40 {
41 if (cl==0) return;
42
43 // Check if already included
45 if (obj) return;
46
47 TString directive;
48
49 // Extract inner class from collection
52 }
53
54 // Construct directive
55 Int_t stlType;
56 if (0 == strcmp(cl->GetName(), "string")) { // Check if it is a string
57 directive = "#include <string>\n";
58 } else if (cl->GetCollectionProxy() && (stlType = cl->GetCollectionType())) { // Check if it is an STL container
59 const char *what = "";
60 switch(stlType) {
61 case ROOT::kSTLvector: what = "vector"; break;
62 case ROOT::kSTLlist: what = "list"; break;
63 case ROOT::kSTLforwardlist: what = "forward_list"; break;
64 case -ROOT::kSTLdeque: // same as positive
65 case ROOT::kSTLdeque: what = "deque"; break;
66 case -ROOT::kSTLmap: // same as positive
67 case ROOT::kSTLmap: what = "map"; break;
68 case -ROOT::kSTLmultimap: // same as positive
69 case ROOT::kSTLmultimap: what = "map"; break;
70 case -ROOT::kSTLset: // same as positive
71 case ROOT::kSTLset: what = "set"; break;
72 case -ROOT::kSTLmultiset: // same as positive
73 case ROOT::kSTLmultiset: what = "set"; break;
74 case -ROOT::kSTLunorderedset: // same as positive
75 case ROOT::kSTLunorderedset: what = "unordered_set"; break;
76 case -ROOT::kSTLunorderedmultiset: // same as positive
77 case ROOT::kSTLunorderedmultiset: what = "unordered_multiset"; break;
78 case -ROOT::kSTLunorderedmap: // same as positive
79 case ROOT::kSTLunorderedmap: what = "unordered_map"; break;
80 case -ROOT::kSTLunorderedmultimap: // same as positive
81 case ROOT::kSTLunorderedmultimap: what = "unordered_multimap"; break;
82 }
83 if (what[0]) {
84 directive = "#include <";
85 directive.Append(what);
86 directive.Append(">\n");
87 }
88 } else if (cl->GetDeclFileName() && strlen(cl->GetDeclFileName()) ) { // Custom file
89 const char *filename = cl->GetDeclFileName();
90
91 if (!filename) return;
92
93#ifdef R__WIN32
94 TString inclPath("include;prec_stl"); // GetHtml()->GetIncludePath());
95#else
96 TString inclPath("include:prec_stl"); // GetHtml()->GetIncludePath());
97#endif
98 Ssiz_t posDelim = 0;
99 TString inclDir;
100 TString sIncl(filename);
101#ifdef R__WIN32
102 const char* pdelim = ";";
103 static const char ddelim = '\\';
104#else
105 const char* pdelim = ":";
106 static const char ddelim = '/';
107#endif
108 while (inclPath.Tokenize(inclDir, posDelim, pdelim))
109 {
110 if (sIncl.BeginsWith(inclDir)) {
111 filename += inclDir.Length();
112 if (filename[0] == ddelim || filename[0] == '/') {
113 ++filename;
114 }
115 break;
116 }
117 }
118 directive = Form("#include \"%s\"\n",filename);
119 } else if (TClassEdit::IsStdPair(cl->GetName())) {
120 TClassEdit::TSplitType split(cl->GetName());
121 // 4 elements expected: "pair", "first type name", "second type name", "trailing stars"
122 // However legacy code had a test for 3, we will leave it here until
123 // a test is developed (or found :) ) that exercise these lines of code.
124 if (split.fElements.size() == 3 || split.fElements.size() == 4) {
125 for (int arg = 1; arg < 3; ++arg) {
126 TClass* clArg = TClass::GetClass(split.fElements[arg].c_str());
127 if (clArg) AddHeader(clArg);
128 }
129 }
130 }
131 // Add directive (if it is not added already)
132 if (directive.Length()) {
133 TIter i( &fListOfHeaders );
134 for(TNamed *n = (TNamed *)i(); n; n = (TNamed*)i()) {
135 if (directive == n->GetTitle()) {
136 return;
137 }
138 }
139 fListOfHeaders.Add(new TNamed(cl->GetName(), directive.Data()));
140 }
141 }
142
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Add a header inclusion request. If the header is already included it will
145 /// not be included again.
146
147 void TTreeGeneratorBase::AddHeader(const char *classname)
148 {
149 AddHeader(TClass::GetClass(classname));
150 }
151
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Get name of class inside a container.
154
156 {
157 TString cname = branch->GetClonesName();
158 if (cname.Length()==0) {
159 // We may have any unsplit clones array
160 Long64_t i = branch->GetTree()->GetReadEntry();
161 if (i<0) i = 0;
162 branch->GetEntry(i);
163 char *obj = branch->GetObject();
164
165 TBranchElement *parent = (TBranchElement*)branch->GetMother()->GetSubBranch(branch);
166 const char *pclname = parent->GetClassName();
167
168 TClass *clparent = TClass::GetClass(pclname);
169 // TClass *clm = TClass::GetClass(GetClassName());
170 Int_t lOffset = 0; // offset in the local streamerInfo.
171 if (clparent) {
172 const char *ename = 0;
173 if (element) {
174 ename = element->GetName();
175 lOffset = clparent->GetStreamerInfo()->GetOffset(ename);
176 } else {
177 lOffset = 0;
178 }
179 }
180 else Error("AnalyzeBranch", "Missing parent for %s.", branch->GetName());
181
182 TClonesArray *arr;
183 if (ispointer) {
184 arr = (TClonesArray*)*(void**)(obj+lOffset);
185 } else {
186 arr = (TClonesArray*)(obj+lOffset);
187 }
188 cname = arr->GetClass()->GetName();
189 }
190 if (cname.Length()==0) {
191 Error("AnalyzeBranch",
192 "Introspection of TClonesArray in older file not implemented yet.");
193 }
194 return cname;
195 }
196
197 ////////////////////////////////////////////////////////////////////////////////
198 /// Check if element is a base class and if yes, return the base class.
199
201 {
202 TStreamerBase *base = dynamic_cast<TStreamerBase*>(element);
203 if (base) {
205 if (info) return info;
206 }
207 return 0;
208 }
209
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Return the correct TStreamerInfo of class 'cl' in the list of branches
212 /// (current) [Assuming these branches correspond to a flattened version of
213 /// the class.]
214
216 {
217 TVirtualStreamerInfo *objInfo = 0;
218 TBranchElement *b = 0;
219 TString cname = cl->GetName();
220
221 while( ( b = (TBranchElement*)current() ) ) {
222 if ( cname == b->GetInfo()->GetName() ) {
223 objInfo = b->GetInfo();
224 break;
225 }
226 }
227 if (objInfo == 0 && branch->GetTree()->GetDirectory()->GetFile()) {
228 const TList *infolist = branch->GetTree()->GetDirectory()->GetFile()->GetStreamerInfoCache();
229 if (infolist) {
231 if (i) {
232 // NOTE: Is this correct for Foreigh classes?
234 }
235 }
236 }
237 if (objInfo == 0) {
238 // We still haven't found it ... this is likely to be an STL collection .. anyway, use the current StreamerInfo.
239 objInfo = cl->GetStreamerInfo();
240 }
241 return objInfo;
242 }
243
244} // namespace Internal
245} // namespace ROOT
#define b(i)
Definition RSha256.hxx:100
long long Long64_t
Definition RtypesCore.h:73
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
char * Form(const char *fmt,...)
void AddHeader(TClass *cl)
Add a header inclusion request.
TVirtualStreamerInfo * GetStreamerInfo(TBranch *branch, TIter current, TClass *cl)
Return the correct TStreamerInfo of class 'cl' in the list of branches (current) [Assuming these bran...
TVirtualStreamerInfo * GetBaseClass(TStreamerElement *element)
Check if element is a base class and if yes, return the base class.
TString GetContainedClassName(TBranchElement *branch, TStreamerElement *element, Bool_t ispointer)
Get name of class inside a container.
TTreeGeneratorBase(TTree *tree, const char *option)
Constructor.
A Branch for the case of an object.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any.
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of a BranchElement and return total number of bytes.
char * GetObject() const
Return a pointer to our object.
virtual const char * GetClonesName() const
A TTree is a list of TBranches.
Definition TBranch.h:89
TTree * GetTree() const
Definition TBranch.h:248
TBranch * GetSubBranch(const TBranch *br) const
Find the parent branch of child.
Definition TBranch.cxx:2102
TBranch * GetMother() const
Get our top-level parent branch in the tree.
Definition TBranch.cxx:2065
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
ROOT::ESTLType GetCollectionType() const
Return the 'type' of the STL the TClass is representing.
Definition TClass.cxx:2875
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0, Bool_t isTransient=kFALSE) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
Definition TClass.cxx:4576
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition TClass.cxx:2886
const char * GetDeclFileName() const
Return name of the file containing the declaration of this class.
Definition TClass.cxx:3440
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2957
An array of clone (identical) objects.
TClass * GetClass() const
virtual TFile * GetFile() const
Definition TDirectory.h:174
const TList * GetStreamerInfoCache()
Returns the cached list of StreamerInfos used in this file.
Definition TFile.cxx:1284
A doubly linked list.
Definition TList.h:44
virtual void Add(TObject *obj)
Definition TList.h:87
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition TList.cxx:578
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:37
TVirtualStreamerInfo * GetBaseStreamerInfo() const
Basic string class.
Definition TString.h:136
Ssiz_t Length() const
Definition TString.h:410
const char * Data() const
Definition TString.h:369
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2217
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:615
TString & Append(const char *cs)
Definition TString.h:564
A TTree represents a columnar dataset.
Definition TTree.h:79
TDirectory * GetDirectory() const
Definition TTree.h:459
virtual Long64_t GetReadEntry() const
Definition TTree.h:506
virtual TClass * GetValueClass() const =0
Abstract Interface class describing Streamer information for one class.
virtual Int_t GetOffset(const char *) const =0
virtual Int_t GetClassVersion() const =0
const Int_t n
Definition legend1.C:16
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
@ kSTLmap
Definition ESTLType.h:33
@ kSTLunorderedmultiset
Definition ESTLType.h:43
@ kSTLset
Definition ESTLType.h:35
@ kSTLmultiset
Definition ESTLType.h:36
@ kSTLdeque
Definition ESTLType.h:32
@ kSTLvector
Definition ESTLType.h:30
@ kSTLunorderedmultimap
Definition ESTLType.h:45
@ kSTLunorderedset
Definition ESTLType.h:42
@ kSTLlist
Definition ESTLType.h:31
@ kSTLforwardlist
Definition ESTLType.h:41
@ kSTLunorderedmap
Definition ESTLType.h:44
@ kSTLmultimap
Definition ESTLType.h:34
bool IsStdPair(std::string_view name)
Definition TClassEdit.h:190
Definition tree.py:1
static const char * what
Definition stlLoader.cc:6
std::vector< std::string > fElements
Definition TClassEdit.h:140