Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBranchProxyClassDescriptor.cxx
Go to the documentation of this file.
1// @(#)root/treeplayer:$Id$
2// Author: Philippe Canal 06/06/2004
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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/** \class TBranchProxyClassDescriptor
13Hold the processed information about a TClass used in a TBranch while
14TTreeProxyGenerator is parsing the TTree information.
15Also contains the routine use to generate the appropriate code
16fragment in the result of MakeProxy.
17*/
18
21
22#include "TClass.h"
23#include "TClassEdit.h"
24#include "TError.h"
27
28
29namespace ROOT {
30namespace Internal {
31
32 ////////////////////////////////////////////////////////////////////////////////
33 /// Make the typename a proper class name without having the really deal with
34 /// namespace and templates.
35
37
38 fRawSymbol = TClassEdit::ShortType(GetName(),2); // Drop default allocator from the name.
39 fRawSymbol.ReplaceAll(":","_");
40 fRawSymbol.ReplaceAll("<","_");
41 fRawSymbol.ReplaceAll(">","_");
42 fRawSymbol.ReplaceAll(",","Cm");
43 fRawSymbol.ReplaceAll(" ","");
44 fRawSymbol.ReplaceAll("*","st");
45 fRawSymbol.ReplaceAll("&","rf");
46 if (IsClones())
47 fRawSymbol.Prepend("TClaPx_");
48 else if (IsSTL())
49 fRawSymbol.Prepend("TStlPx_");
50 else
51 fRawSymbol.Prepend("TPx_");
52 if (fRawSymbol.Length() && fRawSymbol[fRawSymbol.Length()-1]=='.')
54
56 }
57
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Constructor.
60
63 const char *branchname,
66 const TString &containerName) :
68 fIsClones(isclones),
69 fContainerName(containerName),
70 fIsLeafList(false),
71 fSplitLevel(splitlevel),
72 fBranchName(branchname),
73 fSubBranchPrefix(branchname),
74 fInfo(info),
75 fMaxDatamemberType(3)
76 {
80 }
81
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Constructor for a branch constructed from a leaf list.
84
87 fIsClones(kOut),
88 fContainerName(),
89 fIsLeafList(true),
90 fSplitLevel(0),
91 fBranchName(branchname),
92 fSubBranchPrefix(branchname),
93 fInfo(nullptr),
94 fMaxDatamemberType(3)
95 {
98 }
99
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Constructor.
102
104 const char *branchname,
105 const char *branchPrefix, ELocation isclones,
107 const TString &containerName) :
109 fIsClones(isclones),
110 fContainerName(containerName),
111 fIsLeafList(true),
112 fSplitLevel(splitlevel),
113 fBranchName(branchname),
114 fSubBranchPrefix(branchPrefix),
115 fInfo(info),
116 fMaxDatamemberType(3)
117 {
118 R__ASSERT( strcmp(fInfo->GetName(), type)==0 );
119 NameToSymbol();
121 }
122
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Get the branch name
125
127 {
128 return fBranchName.Data();
129 }
130
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Get the prefix from the branch name
133
135 {
136 return fSubBranchPrefix.Data();
137 }
138
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Get the real symbol name
141
143 {
144 return fRawSymbol;
145 }
146
147 ////////////////////////////////////////////////////////////////////////////////
148 /// Return the split level of the branch.
149
153
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Return true if this description is the 'same' as the other decription.
156
158 {
159 if ( !other ) return false;
160 // Purposely do not test on the name!
161 if ( strcmp(GetTitle(),other->GetTitle()) ) return false;
162 // if ( fBranchName != other->fBranchName ) return false;
163 // if ( fSubBranchPrefix != other->fSubBranchPrefix ) return false;
164
165 if (fIsClones != other->fIsClones) return false;
166 if (fIsClones != kOut) {
167 if (fContainerName != other->fContainerName) return false;
168 }
169
172
173 if ( fListOfBaseProxies.GetSize() != other->fListOfBaseProxies.GetSize() ) return false;
175 TIter othnext(&other->fListOfBaseProxies);
176 while ( (desc=(TBranchProxyDescriptor*)next()) ) {
178 if (!desc->IsEquivalent(othdesc,true) ) return false;
179 }
180
181 if ( fListOfSubProxies.GetSize() != other->fListOfSubProxies.GetSize() ) return false;
182 next = &fListOfSubProxies;
183 othnext = &(other->fListOfSubProxies);
184
185 while ( (desc=(TBranchProxyDescriptor*)next()) ) {
187 if (!desc->IsEquivalent(othdesc,true)) return false;
188 if (desc->IsSplit()) {
189 TString leftname ( desc->GetBranchName() );
190 TString rightname( othdesc->GetBranchName() );
191
192 if (leftname.Index(GetBranchName())==0) leftname.Remove( 0,strlen(GetBranchName()));
193 if (leftname.Length() && leftname[0]=='.') leftname.Remove(0,1);
194 if (rightname.Index(other->GetBranchName())==0) rightname.Remove(0,strlen(other->GetBranchName()));
195 if (rightname.Length() && rightname[0]=='.') rightname.Remove(0,1);
196 if (leftname != rightname ) return false;
197 }
198 }
199 return true;
200 }
201
202 ////////////////////////////////////////////////////////////////////////////////
203 /// Add a descriptor to this proxy.
204
206 {
207 if (desc) {
208 if (isBase) {
210 } else {
212 UInt_t len = strlen(desc->GetTypeName());
214 }
215 }
216 }
217
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Return true if the class needed by the branch is loaded
220
222 {
223 return IsLoaded(GetTitle());
224 }
225
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Return true if the class needed by the branch is loaded
228
229 bool TBranchProxyClassDescriptor::IsLoaded(const char *classname)
230 {
231 TClass *cl = TClass::GetClass(classname);
232 while (cl) {
233 if (cl->IsLoaded()) return true;
234 if (!cl->GetCollectionProxy()) return false;
235 if (!cl->GetCollectionProxy()->GetValueClass()) return true; // stl container of simple type are always 'loaded'
236 cl = cl->GetCollectionProxy()->GetValueClass();
237 }
238 return false;
239 }
240
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Return true if this proxy is for a TClonesArray.
243
248
249 ////////////////////////////////////////////////////////////////////////////////
250 /// Return true if this proxy is for a TClonesArray.
251
253 {
255 }
256
257 ////////////////////////////////////////////////////////////////////////////////
258 /// Return whether the branch is inside, nested in or outside of a TClonesArray
259
264
265 ////////////////////////////////////////////////////////////////////////////////
266 /// Return the name of the container holding this class, if any.
267
272
273 ////////////////////////////////////////////////////////////////////////////////
274 /// Output the declaration and implementation of this emulation class
275
277 {
279
280
281 // Start the class declaration with the eventual list of base classes
282 fprintf(hf,"%-*sstruct %s\n", offset," ", GetName() );
283
285 fprintf(hf,"%-*s : ", offset," ");
286
288
289 desc = (TBranchProxyDescriptor*)next();
290 fprintf(hf,"public %s", desc->GetTypeName());
291
292 while ( (desc = (TBranchProxyDescriptor*)next()) ) {
293 fprintf(hf,",\n%-*spublic %s", offset+5," ", desc->GetTypeName());
294 }
295
296 fprintf(hf,"\n");
297 }
298 fprintf(hf,"%-*s{\n", offset," ");
299
300
301 // Write the constructor
302 fprintf(hf,"%-*s %s(TBranchProxyDirector* director,const char *top,const char *mid=0) :",
303 offset," ", GetName());
304
305 bool wroteFirst = false;
306
308
310
311 desc = (TBranchProxyDescriptor*)next();
312 fprintf(hf,"\n%-*s%-*s(director, top, mid)", offset+6, " ", fMaxDatamemberType,desc->GetTypeName());
313 wroteFirst = true;
314
315 while ( (desc = (TBranchProxyDescriptor*)next()) ) {
316 fprintf(hf,",\n%-*s%-*s(director, top, mid)", offset+6, " ", fMaxDatamemberType,desc->GetTypeName());
317 }
318
319 }
320 fprintf(hf,"%s\n%-*s %-*s(top,mid)",wroteFirst?",":"",offset," ",fMaxDatamemberType,"ffPrefix");
321 wroteFirst = true;
322
323 TString objInit = "top, mid";
324 if ( GetIsClones() == kInsideClones || GetIsClones() == kInsideSTL ) {
327 if (desc && desc->IsSplit()) {
328
329 // In the case of a split sub object is TClonesArray, the
330 // object itself does not have its own branch, so we need to
331 // use its first (semantic) sub-branch as a proxy
332
334 TString sub = desc->GetBranchName();
335 sub.Remove(0,main.Length()+1);
336
337 objInit = "ffPrefix, ";
338 objInit += "\"";
339 objInit += sub;
340 objInit += "\"";
341
342 objInit = "top, \"\", mid";
343 }
344 }
345 }
346
347 fprintf(hf,"%s\n%-*s %-*s(director, %s)",
348 ",",offset," ",fMaxDatamemberType,"obj",objInit.Data());
349
351 while ( (desc = (TBranchProxyDescriptor*)next()) ) {
352 fprintf(hf,",");
354 }
355 fprintf(hf,"\n%-*s {};\n",offset," ");
356
357
358 // Write the 2nd constructor
359 fprintf(hf,"%-*s %s(TBranchProxyDirector* director, TBranchProxy *parent, const char *membername, const char *top=0, const char *mid=0) :",
360 offset," ", GetName());
361
362 wroteFirst = false;
363
365
367
368 // This is guarantee to return a non zero value due to the if (fListOfBaseProxies.GetSize())
370 fprintf(hf,"\n%-*s%-*s(director, parent, membername, top, mid)", offset+6, " ", fMaxDatamemberType,desc->GetTypeName());
371 wroteFirst = true;
372
373 while ( (desc = (TBranchProxyDescriptor*)nextbase()) ) {
374 fprintf(hf,",\n%-*s%-*s(director, parent, membername, top, mid)", offset+6, " ", fMaxDatamemberType,desc->GetTypeName());
375 }
376
377 }
378 fprintf(hf,"%s\n%-*s %-*s(top,mid)",wroteFirst?",":"",offset," ",fMaxDatamemberType,"ffPrefix");
379 wroteFirst = true;
380
381 if ( true || IsLoaded() || IsClones() || IsSTL() ) {
382 fprintf(hf,"%s\n%-*s %-*s(director, parent, membername, top, mid)",
383 ",",offset," ",fMaxDatamemberType,"obj");
384 }
385
386 next.Reset();
387 while ( (desc = (TBranchProxyDescriptor*)next()) ) {
388 fprintf(hf,",");
390 }
391 fprintf(hf,"\n%-*s {};\n",offset," ");
392
393
394 // Declare the data members.
395 fprintf(hf,"%-*s%-*s %s;\n", offset+3," ", fMaxDatamemberType, "ROOT::Internal::TBranchProxyHelper", "ffPrefix");
396
397 // If the real class is available, make it available via the arrow operator:
398 if (IsLoaded()) {
399
400 const char *type = GetTitle(); /* IsClones() ? "TClonesArray" : GetTitle(); */
401 fprintf(hf,"%-*sInjecTBranchProxyInterface();\n", offset+3," ");
402 //Can the real type contain a leading 'const'? If so the following is incorrect.
403 if ( IsClones() ) {
404 fprintf(hf,"%-*sconst %s* operator[](Int_t i) { return obj.At(i); }\n", offset+3," ",type);
405 fprintf(hf,"%-*sconst %s* operator[](UInt_t i) { return obj.At(i); }\n", offset+3," ",type);
406 fprintf(hf,"%-*sInt_t GetEntries() { return obj.GetEntries(); }\n",offset+3," ");
407 fprintf(hf,"%-*sconst TClonesArray* operator->() { return obj.GetPtr(); }\n", offset+3," ");
408 fprintf(hf,"%-*sTClaObjProxy<%s > obj;\n", offset+3, " ", type);
409 } else if ( IsSTL() ) {
411 fprintf(hf,"%-*sconst %s& At(UInt_t i) {\n",offset+3," ",type);
414 if (cl->GetMethodWithPrototype(cl->GetName(),"TRootIOCtor*")) {
415 fprintf(hf,"%-*s static %s default_val((TRootIOCtor*)0);\n",offset+3," ",type);
416 } else {
417 fprintf(hf,"%-*s static %s default_val;\n",offset+3," ",type);
418 }
419 fprintf(hf,"%-*s if (!obj.Read()) return default_val;\n",offset+3," ");
420 if (stlCl->GetCollectionProxy()->GetValueClass() == cl) {
421 fprintf(hf,"%-*s %s *temp = & obj.GetPtr()->at(i);\n",offset+3," ",type);
422 } else {
423 fprintf(hf,"%-*s %s *temp = (%s *)( obj.GetProxy()->GetStlStart(i) );\n",offset+3," ",type,type);
424 }
425 //fprintf(hf,"%-*s %s *temp = (%s *)( obj.GetPtr()->at(i)) + obj.GetOffset() );\n",offset+3," ",type,type);
426 //fprintf(hf,"%-*s %s *temp = (%s *)(void*)(&obj.At(i));\n",offset+3," ",type,type);
427 fprintf(hf,"%-*s if (temp) return *temp; else return default_val;\n",offset+3," ");
428 fprintf(hf,"%-*s}\n",offset+3," ");
429
430 fprintf(hf,"%-*sconst %s& operator[](Int_t i) { return At(i); }\n", offset+3," ",type);
431 fprintf(hf,"%-*sconst %s& operator[](UInt_t i) { return At(i); }\n", offset+3," ",type);
432 fprintf(hf,"%-*sInt_t GetEntries() { return obj.GetPtr()->size(); }\n",offset+3," ");
433 fprintf(hf,"%-*sconst %s* operator->() { return obj.GetPtr(); }\n", offset+3," ",fContainerName.Data());
434 fprintf(hf,"%-*soperator %s*() { return obj.GetPtr(); }\n", offset+3," ",fContainerName.Data());
435 fprintf(hf,"%-*sTObjProxy<%s > obj;\n", offset+3, " ", fContainerName.Data());
436 } else {
437 fprintf(hf,"%-*sconst %s& operator[](Int_t i) { return obj.At(i); }\n", offset+3," ",type);
438 fprintf(hf,"%-*sconst %s& operator[](UInt_t i) { return obj.At(i); }\n", offset+3," ",type);
439 fprintf(hf,"%-*sInt_t GetEntries() { return obj.GetEntries(); }\n",offset+3," ");
440 fprintf(hf,"%-*sTStlObjProxy<%s > obj;\n", offset+3, " ", type);
441 }
442 } else {
443 fprintf(hf,"%-*sconst %s* operator->() { return obj.GetPtr(); }\n", offset+3," ",type);
444 fprintf(hf,"%-*sTObjProxy<%s > obj;\n", offset+3, " ", type);
445 }
446
447 } else if ( IsClones()) {
448
449 fprintf(hf,"%-*sInjecTBranchProxyInterface();\n", offset+3," ");
450 fprintf(hf,"%-*sInt_t GetEntries() { return obj.GetEntries(); }\n",offset+3," ");
451 fprintf(hf,"%-*sconst TClonesArray* operator->() { return obj.GetPtr(); }\n", offset+3," ");
452 fprintf(hf,"%-*sTClaProxy obj;\n", offset+3," ");
453
454 } else if ( IsSTL()) {
455
456 fprintf(hf,"%-*sInjecTBranchProxyInterface();\n", offset+3," ");
457 fprintf(hf,"%-*sInt_t GetEntries() { return obj.GetEntries(); }\n",offset+3," ");
458 // fprintf(hf,"%-*sconst TClonesArray* operator->() { return obj.GetPtr(); }\n", offset+3," ");
459 fprintf(hf,"%-*sTStlProxy obj;\n", offset+3," ");
460
461 } else {
462
463 fprintf(hf,"%-*sInjecTBranchProxyInterface();\n", offset+3," ");
464 fprintf(hf,"%-*sTBranchProxy obj;\n", offset+3," ");
465
466 }
467
468 fprintf(hf,"\n");
469
470 next.Reset();
471 while( (desc = ( TBranchProxyDescriptor *)next()) ) {
473 }
474 fprintf(hf,"%-*s};\n",offset," ");
475
476 //TBranchProxyDescriptor::OutputDecl(hf,offset,maxVarname);
477 }
478
479} // namespace Internal
480} // namespace ROOT
int main()
Definition Prototype.cxx:12
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
const char * GetBranchName() const
Get the branch name.
const char * GetRawSymbol() const
Get the real symbol name.
const char * GetSubBranchPrefix() const
Get the prefix from the branch name.
ELocation GetIsClones() const
Return whether the branch is inside, nested in or outside of a TClonesArray.
bool IsClones() const
Return true if this proxy is for a TClonesArray.
TBranchProxyClassDescriptor(const TBranchProxyClassDescriptor &b)
void OutputDecl(FILE *hf, int offset, UInt_t)
Output the declaration and implementation of this emulation class.
virtual bool IsEquivalent(const TBranchProxyClassDescriptor *other)
Return true if this description is the 'same' as the other decription.
void NameToSymbol()
Make the typename a proper class name without having the really deal with namespace and templates.
bool IsSTL() const
Return true if this proxy is for a TClonesArray.
UInt_t GetSplitLevel() const
Return the split level of the branch.
TString GetContainerName() const
Return the name of the container holding this class, if any.
bool IsLoaded() const
Return true if the class needed by the branch is loaded.
void AddDescriptor(TBranchProxyDescriptor *desc, bool isBase)
Add a descriptor to this proxy.
bool IsSplit() const
Return true if the branch is split.
void OutputDecl(FILE *hf, int offset, UInt_t maxVarname)
Output the declaration corresponding to this proxy.
const char * GetBranchName()
Get the branch name.
bool IsEquivalent(const TBranchProxyDescriptor *other, bool inClass=false)
Return true if this description is the 'same' as the other description.
const char * GetTypeName()
Get the name of the type of the data member.
void OutputInit(FILE *hf, int offset, UInt_t maxVarname, const char *prefix)
Output the initialization corresponding to this proxy.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Definition TClass.cxx:4483
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
Definition TClass.cxx:5954
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition TClass.cxx:2902
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:2973
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
void Reset()
void Add(TObject *obj) override
Definition TList.h:81
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:354
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
const char * Data() const
Definition TString.h:384
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:712
TString & Prepend(const char *cs)
Definition TString.h:681
TString & Remove(Ssiz_t pos)
Definition TString.h:693
virtual TClass * GetValueClass() const =0
If the value type is a user-defined class, return a pointer to the TClass representing the value type...
Abstract Interface class describing Streamer information for one class.
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.