28 ClassImp(ROOT::Internal::TBranchProxyClassDescriptor);
33 void TBranchProxyClassDescriptor::NameToSymbol() {
38 fRawSymbol = TClassEdit::ShortType(GetName(),2);
39 fRawSymbol.ReplaceAll(
":",
"_");
40 fRawSymbol.ReplaceAll(
"<",
"_");
41 fRawSymbol.ReplaceAll(
">",
"_");
42 fRawSymbol.ReplaceAll(
",",
"Cm");
43 fRawSymbol.ReplaceAll(
" ",
"");
44 fRawSymbol.ReplaceAll(
"*",
"st");
45 fRawSymbol.ReplaceAll(
"&",
"rf");
47 fRawSymbol.Prepend(
"TClaPx_");
49 fRawSymbol.Prepend(
"TStlPx_");
51 fRawSymbol.Prepend(
"TPx_");
52 if (fRawSymbol.Length() && fRawSymbol[fRawSymbol.Length()-1]==
'.')
53 fRawSymbol.Remove(fRawSymbol.Length()-1);
58 TBranchProxyClassDescriptor::TBranchProxyClassDescriptor(
const char *type,
59 TVirtualStreamerInfo *info,
60 const char *branchname,
63 const TString &containerName) :
66 fContainerName(containerName),
68 fSplitLevel(splitlevel),
69 fBranchName(branchname),
70 fSubBranchPrefix(branchname),
76 R__ASSERT( strcmp(fInfo->GetName(), type)==0 );
78 if (fSubBranchPrefix.Length() && fSubBranchPrefix[fSubBranchPrefix.Length()-1]==
'.') fSubBranchPrefix.Remove(fSubBranchPrefix.Length()-1);
81 TBranchProxyClassDescriptor::TBranchProxyClassDescriptor(
const char *branchname) :
82 TNamed(branchname,branchname),
87 fBranchName(branchname),
88 fSubBranchPrefix(branchname),
95 if (fSubBranchPrefix.Length() && fSubBranchPrefix[fSubBranchPrefix.Length()-1]==
'.') fSubBranchPrefix.Remove(fSubBranchPrefix.Length()-1);
98 TBranchProxyClassDescriptor::TBranchProxyClassDescriptor(
const char *type, TVirtualStreamerInfo *info,
99 const char *branchname,
100 const char *branchPrefix, ELocation isclones,
102 const TString &containerName) :
105 fContainerName(containerName),
107 fSplitLevel(splitlevel),
108 fBranchName(branchname),
109 fSubBranchPrefix(branchPrefix),
111 fMaxDatamemberType(3)
115 R__ASSERT( strcmp(fInfo->GetName(), type)==0 );
117 if (fSubBranchPrefix.Length() && fSubBranchPrefix[fSubBranchPrefix.Length()-1]==
'.') fSubBranchPrefix.Remove(fSubBranchPrefix.Length()-1);
120 const char* TBranchProxyClassDescriptor::GetBranchName()
const
123 return fBranchName.Data();
126 const char* TBranchProxyClassDescriptor::GetSubBranchPrefix()
const
129 return fSubBranchPrefix.Data();
132 const char* TBranchProxyClassDescriptor::GetRawSymbol()
const
139 UInt_t TBranchProxyClassDescriptor::GetSplitLevel()
const {
144 Bool_t TBranchProxyClassDescriptor::IsEquivalent(
const TBranchProxyClassDescriptor* other)
148 if ( !other )
return kFALSE;
150 if ( strcmp(GetTitle(),other->GetTitle()) )
return kFALSE;
154 if (fIsClones != other->fIsClones)
return kFALSE;
155 if (fIsClones != kOut) {
156 if (fContainerName != other->fContainerName)
return kFALSE;
159 TBranchProxyDescriptor *desc;
160 TBranchProxyDescriptor *othdesc;
162 if ( fListOfBaseProxies.GetSize() != other->fListOfBaseProxies.GetSize() )
return kFALSE;
163 TIter next(&fListOfBaseProxies);
164 TIter othnext(&other->fListOfBaseProxies);
165 while ( (desc=(TBranchProxyDescriptor*)next()) ) {
166 othdesc=(TBranchProxyDescriptor*)othnext();
167 if (!desc->IsEquivalent(othdesc,kTRUE) )
return kFALSE;
170 if ( fListOfSubProxies.GetSize() != other->fListOfSubProxies.GetSize() )
return kFALSE;
171 next = &fListOfSubProxies;
172 othnext = &(other->fListOfSubProxies);
174 while ( (desc=(TBranchProxyDescriptor*)next()) ) {
175 othdesc=(TBranchProxyDescriptor*)othnext();
176 if (!desc->IsEquivalent(othdesc,kTRUE))
return kFALSE;
177 if (desc->IsSplit()) {
178 TString leftname ( desc->GetBranchName() );
179 TString rightname( othdesc->GetBranchName() );
181 if (leftname.Index(GetBranchName())==0) leftname.Remove( 0,strlen(GetBranchName()));
182 if (leftname.Length() && leftname[0]==
'.') leftname.Remove(0,1);
183 if (rightname.Index(other->GetBranchName())==0) rightname.Remove(0,strlen(other->GetBranchName()));
184 if (rightname.Length() && rightname[0]==
'.') rightname.Remove(0,1);
185 if (leftname != rightname )
return kFALSE;
191 void TBranchProxyClassDescriptor::AddDescriptor(TBranchProxyDescriptor *desc, Bool_t isBase)
197 fListOfBaseProxies.Add(desc);
199 fListOfSubProxies.Add(desc);
200 UInt_t len = strlen(desc->GetTypeName());
201 if ((len+2)>fMaxDatamemberType) fMaxDatamemberType = len+2;
206 Bool_t TBranchProxyClassDescriptor::IsLoaded()
const
209 return IsLoaded(GetTitle());
212 Bool_t TBranchProxyClassDescriptor::IsLoaded(
const char *classname)
215 TClass *cl = TClass::GetClass(classname);
217 if (cl->IsLoaded())
return kTRUE;
218 if (!cl->GetCollectionProxy())
return kFALSE;
219 if (!cl->GetCollectionProxy()->GetValueClass())
return kTRUE;
220 cl = cl->GetCollectionProxy()->GetValueClass();
225 Bool_t TBranchProxyClassDescriptor::IsClones()
const
228 return fIsClones==kClones || fIsClones==kInsideClones;
231 Bool_t TBranchProxyClassDescriptor::IsSTL()
const
234 return fIsClones==kSTL || fIsClones==kInsideSTL;
237 TBranchProxyClassDescriptor::ELocation TBranchProxyClassDescriptor::GetIsClones()
const
243 TString TBranchProxyClassDescriptor::GetContainerName()
const
246 return fContainerName;
249 void TBranchProxyClassDescriptor::OutputDecl(FILE *hf,
int offset, UInt_t )
253 TBranchProxyDescriptor *desc;
257 fprintf(hf,
"%-*sstruct %s\n", offset,
" ", GetName() );
259 if (fListOfBaseProxies.GetSize()) {
260 fprintf(hf,
"%-*s : ", offset,
" ");
262 TIter next(&fListOfBaseProxies);
264 desc = (TBranchProxyDescriptor*)next();
265 fprintf(hf,
"public %s", desc->GetTypeName());
267 while ( (desc = (TBranchProxyDescriptor*)next()) ) {
268 fprintf(hf,
",\n%-*spublic %s", offset+5,
" ", desc->GetTypeName());
273 fprintf(hf,
"%-*s{\n", offset,
" ");
277 fprintf(hf,
"%-*s %s(TBranchProxyDirector* director,const char *top,const char *mid=0) :",
278 offset,
" ", GetName());
280 Bool_t wroteFirst = kFALSE;
282 if (fListOfBaseProxies.GetSize()) {
284 TIter next(&fListOfBaseProxies);
286 desc = (TBranchProxyDescriptor*)next();
287 fprintf(hf,
"\n%-*s%-*s(director, top, mid)", offset+6,
" ", fMaxDatamemberType,desc->GetTypeName());
290 while ( (desc = (TBranchProxyDescriptor*)next()) ) {
291 fprintf(hf,
",\n%-*s%-*s(director, top, mid)", offset+6,
" ", fMaxDatamemberType,desc->GetTypeName());
295 fprintf(hf,
"%s\n%-*s %-*s(top,mid)",wroteFirst?
",":
"",offset,
" ",fMaxDatamemberType,
"ffPrefix");
298 TString objInit =
"top, mid";
299 if ( GetIsClones() == kInsideClones || GetIsClones() == kInsideSTL ) {
300 if (fListOfSubProxies.GetSize()) {
301 desc = (TBranchProxyDescriptor*)fListOfSubProxies.At(0);
302 if (desc && desc->IsSplit()) {
308 TString main = GetBranchName();
309 TString sub = desc->GetBranchName();
310 sub.Remove(0,main.Length()+1);
312 objInit =
"ffPrefix, ";
317 objInit =
"top, \"\", mid";
322 fprintf(hf,
"%s\n%-*s %-*s(director, %s)",
323 ",",offset,
" ",fMaxDatamemberType,
"obj",objInit.Data());
325 TIter next(&fListOfSubProxies);
326 while ( (desc = (TBranchProxyDescriptor*)next()) ) {
328 desc->OutputInit(hf,offset,fMaxDatamemberType,GetSubBranchPrefix());
330 fprintf(hf,
"\n%-*s {};\n",offset,
" ");
334 fprintf(hf,
"%-*s %s(TBranchProxyDirector* director, TBranchProxy *parent, const char *membername, const char *top=0, const char *mid=0) :",
335 offset,
" ", GetName());
339 if (fListOfBaseProxies.GetSize()) {
341 TIter nextbase(&fListOfBaseProxies);
344 desc = (TBranchProxyDescriptor*)nextbase();
345 fprintf(hf,
"\n%-*s%-*s(director, parent, membername, top, mid)", offset+6,
" ", fMaxDatamemberType,desc->GetTypeName());
348 while ( (desc = (TBranchProxyDescriptor*)nextbase()) ) {
349 fprintf(hf,
",\n%-*s%-*s(director, parent, membername, top, mid)", offset+6,
" ", fMaxDatamemberType,desc->GetTypeName());
353 fprintf(hf,
"%s\n%-*s %-*s(top,mid)",wroteFirst?
",":
"",offset,
" ",fMaxDatamemberType,
"ffPrefix");
356 if (
true || IsLoaded() || IsClones() || IsSTL() ) {
357 fprintf(hf,
"%s\n%-*s %-*s(director, parent, membername, top, mid)",
358 ",",offset,
" ",fMaxDatamemberType,
"obj");
362 while ( (desc = (TBranchProxyDescriptor*)next()) ) {
364 desc->OutputInit(hf,offset,fMaxDatamemberType,GetSubBranchPrefix());
366 fprintf(hf,
"\n%-*s {};\n",offset,
" ");
370 fprintf(hf,
"%-*s%-*s %s;\n", offset+3,
" ", fMaxDatamemberType,
"ROOT::Internal::TBranchProxyHelper",
"ffPrefix");
375 const char *type = GetTitle();
376 fprintf(hf,
"%-*sInjecTBranchProxyInterface();\n", offset+3,
" ");
379 fprintf(hf,
"%-*sconst %s* operator[](Int_t i) { return obj.At(i); }\n", offset+3,
" ",type);
380 fprintf(hf,
"%-*sconst %s* operator[](UInt_t i) { return obj.At(i); }\n", offset+3,
" ",type);
381 fprintf(hf,
"%-*sInt_t GetEntries() { return obj.GetEntries(); }\n",offset+3,
" ");
382 fprintf(hf,
"%-*sconst TClonesArray* operator->() { return obj.GetPtr(); }\n", offset+3,
" ");
383 fprintf(hf,
"%-*sTClaObjProxy<%s > obj;\n", offset+3,
" ", type);
384 }
else if ( IsSTL() ) {
385 if (fContainerName.Length() && IsLoaded(fContainerName)) {
386 fprintf(hf,
"%-*sconst %s& At(UInt_t i) {\n",offset+3,
" ",type);
387 TClass *stlCl = TClass::GetClass(fContainerName);
388 TClass *cl = TClass::GetClass(GetTitle());
389 if (cl->GetMethodWithPrototype(cl->GetName(),
"TRootIOCtor*")) {
390 fprintf(hf,
"%-*s static %s default_val((TRootIOCtor*)0);\n",offset+3,
" ",type);
392 fprintf(hf,
"%-*s static %s default_val;\n",offset+3,
" ",type);
394 fprintf(hf,
"%-*s if (!obj.Read()) return default_val;\n",offset+3,
" ");
395 if (stlCl->GetCollectionProxy()->GetValueClass() == cl) {
396 fprintf(hf,
"%-*s %s *temp = & obj.GetPtr()->at(i);\n",offset+3,
" ",type);
398 fprintf(hf,
"%-*s %s *temp = (%s *)( obj.GetProxy()->GetStlStart(i) );\n",offset+3,
" ",type,type);
402 fprintf(hf,
"%-*s if (temp) return *temp; else return default_val;\n",offset+3,
" ");
403 fprintf(hf,
"%-*s}\n",offset+3,
" ");
405 fprintf(hf,
"%-*sconst %s& operator[](Int_t i) { return At(i); }\n", offset+3,
" ",type);
406 fprintf(hf,
"%-*sconst %s& operator[](UInt_t i) { return At(i); }\n", offset+3,
" ",type);
407 fprintf(hf,
"%-*sInt_t GetEntries() { return obj.GetPtr()->size(); }\n",offset+3,
" ");
408 fprintf(hf,
"%-*sconst %s* operator->() { return obj.GetPtr(); }\n", offset+3,
" ",fContainerName.Data());
409 fprintf(hf,
"%-*soperator %s*() { return obj.GetPtr(); }\n", offset+3,
" ",fContainerName.Data());
410 fprintf(hf,
"%-*sTObjProxy<%s > obj;\n", offset+3,
" ", fContainerName.Data());
412 fprintf(hf,
"%-*sconst %s& operator[](Int_t i) { return obj.At(i); }\n", offset+3,
" ",type);
413 fprintf(hf,
"%-*sconst %s& operator[](UInt_t i) { return obj.At(i); }\n", offset+3,
" ",type);
414 fprintf(hf,
"%-*sInt_t GetEntries() { return obj.GetEntries(); }\n",offset+3,
" ");
415 fprintf(hf,
"%-*sTStlObjProxy<%s > obj;\n", offset+3,
" ", type);
418 fprintf(hf,
"%-*sconst %s* operator->() { return obj.GetPtr(); }\n", offset+3,
" ",type);
419 fprintf(hf,
"%-*sTObjProxy<%s > obj;\n", offset+3,
" ", type);
422 }
else if ( IsClones()) {
424 fprintf(hf,
"%-*sInjecTBranchProxyInterface();\n", offset+3,
" ");
425 fprintf(hf,
"%-*sInt_t GetEntries() { return obj.GetEntries(); }\n",offset+3,
" ");
426 fprintf(hf,
"%-*sconst TClonesArray* operator->() { return obj.GetPtr(); }\n", offset+3,
" ");
427 fprintf(hf,
"%-*sTClaProxy obj;\n", offset+3,
" ");
429 }
else if ( IsSTL()) {
431 fprintf(hf,
"%-*sInjecTBranchProxyInterface();\n", offset+3,
" ");
432 fprintf(hf,
"%-*sInt_t GetEntries() { return obj.GetEntries(); }\n",offset+3,
" ");
434 fprintf(hf,
"%-*sTStlProxy obj;\n", offset+3,
" ");
438 fprintf(hf,
"%-*sInjecTBranchProxyInterface();\n", offset+3,
" ");
439 fprintf(hf,
"%-*sTBranchProxy obj;\n", offset+3,
" ");
446 while( (desc = ( TBranchProxyDescriptor *)next()) ) {
447 desc->OutputDecl(hf,offset+3,fMaxDatamemberType);
449 fprintf(hf,
"%-*s};\n",offset,
" ");