TBranchProxyDescriptor.cxx

Go to the documentation of this file.
00001 // @(#)root/treeplayer:$Id: TBranchProxyDescriptor.cxx 37410 2010-12-08 17:22:07Z pcanal $
00002 // Author: Philippe Canal 06/06/2004
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers and al.        *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TBranchProxyDescriptor                                               //
00015 //                                                                      //
00016 // Hold the processed information about a TBranch while                 //
00017 // TTreeProxyGenerator is parsing the TTree information.                //
00018 // Also contains the routine use to generate the appropriate code       //
00019 // fragment in the result of MakeProxy.                                 //
00020 //                                                                      //
00021 //////////////////////////////////////////////////////////////////////////
00022 
00023 #include "TBranchProxyDescriptor.h"
00024 
00025 #include "TClonesArray.h"
00026 #include "TError.h"
00027 #include "TROOT.h"
00028 
00029 #include "TTreeFormula.h"
00030 #include "TFormLeafInfo.h"
00031 #include <ctype.h>
00032 
00033 ClassImp(ROOT::TBranchProxyDescriptor);
00034 
00035 namespace ROOT {
00036 
00037    TBranchProxyDescriptor::TBranchProxyDescriptor(const char *dataname, 
00038                                                   const char *type, 
00039                                                   const char *branchname, 
00040                                                   Bool_t split,
00041                                                   Bool_t skipped,
00042                                                   Bool_t isleaflist) :
00043       TNamed(dataname,type),fBranchName(branchname),fIsSplit(split),fBranchIsSkipped(skipped),fIsLeafList(isleaflist)
00044    {
00045       // Constructor.
00046 
00047       fDataName = GetName();
00048       if (fDataName.Length() && fDataName[fDataName.Length()-1]=='.') fDataName.Remove(fDataName.Length()-1);
00049 
00050       fDataName.ReplaceAll(".","_");
00051       fDataName.ReplaceAll(":","_");
00052       fDataName.ReplaceAll("<","_");
00053       fDataName.ReplaceAll(">","_");
00054       if (!isalpha(fDataName[0])) fDataName.Insert(0,"_");
00055       fDataName.ReplaceAll(" ","");
00056       fDataName.ReplaceAll("*","st");
00057       fDataName.ReplaceAll("&","rf");
00058 
00059    }
00060    
00061    const char *TBranchProxyDescriptor::GetDataName() 
00062    { 
00063       // Get the name of the data member.
00064       return fDataName; 
00065    }
00066 
00067    const char *TBranchProxyDescriptor::GetTypeName() 
00068    { 
00069       // Get the name of the type of the data member
00070       return GetTitle(); 
00071    }
00072    
00073    const char *TBranchProxyDescriptor::GetBranchName() 
00074    { 
00075       // Get the branch name.
00076       return fBranchName.Data(); 
00077    }
00078 
00079    Bool_t TBranchProxyDescriptor::IsEquivalent(const TBranchProxyDescriptor *other,
00080                                                Bool_t inClass) 
00081    {
00082       // Return true if this description is the 'same' as the other decription.
00083 
00084       if ( !other ) return false;
00085       if ( other == this ) return true;
00086 
00087       if ( inClass ) {
00088          // If this description belong to a class, the branchname will be 
00089          // stripped.
00090       } else {
00091          if ( fBranchName != other->fBranchName ) return false;
00092       }
00093       if ( fIsSplit != other->fIsSplit ) return false;
00094       if ( fBranchIsSkipped != other->fBranchIsSkipped) return false;
00095       if ( strcmp(GetName(),other->GetName()) ) return false;
00096       if ( strcmp(GetTitle(),other->GetTitle()) ) return false;
00097       return true;
00098    }
00099 
00100    Bool_t TBranchProxyDescriptor::IsSplit() const 
00101    { 
00102       // Return true if the branch is split
00103       return fIsSplit; 
00104    }
00105 
00106    void TBranchProxyDescriptor::OutputDecl(FILE *hf, int offset, UInt_t maxVarname)
00107    {
00108       // Output the declaration corresponding to this proxy
00109       fprintf(hf,"%-*s%-*s %s;\n",  offset," ",  maxVarname, GetTypeName(), GetDataName()); // might want to add a comment
00110    }
00111 
00112    void TBranchProxyDescriptor::OutputInit(FILE *hf, int offset, 
00113                                            UInt_t maxVarname,
00114                                            const char *prefix) 
00115    {
00116       // Output the initialization corresponding to this proxy
00117       if (fIsSplit) {
00118          const char *subbranchname = GetBranchName();
00119          const char *above = "";
00120          if (strncmp(prefix,subbranchname,strlen(prefix))==0
00121              && strcmp(prefix,subbranchname)!=0)  {
00122             subbranchname += strlen(prefix)+1; // +1 for the dot "."
00123             above = "ffPrefix, ";
00124          }
00125 
00126          if (fBranchIsSkipped) {
00127            fprintf(hf,"\n%-*s      %-*s(director, obj.GetProxy(), \"%s\", %s\"%s\")",
00128                    offset," ", maxVarname, GetDataName(), GetDataName(), above, subbranchname);
00129          } else {
00130             if (fIsLeafList) {
00131                if (above[0]=='\0') {
00132                   fprintf(hf,"\n%-*s      %-*s(director, \"%s\", \"\", \"%s\")",
00133                           offset," ", maxVarname, GetDataName(), subbranchname, GetDataName());
00134                } else {
00135                   fprintf(hf,"\n%-*s      %-*s(director, %s\"%s\", \"%s\")",
00136                           offset," ", maxVarname, GetDataName(), above, subbranchname, GetDataName());
00137                }
00138             } else {
00139                fprintf(hf,"\n%-*s      %-*s(director, %s\"%s\")",
00140                        offset," ", maxVarname, GetDataName(), above, subbranchname);
00141             }
00142          }
00143       } else {
00144 
00145          fprintf(hf,"\n%-*s      %-*s(director, obj.GetProxy(), \"%s\")",
00146                  offset," ", maxVarname, GetDataName(), GetBranchName() );
00147 
00148          //fprintf(hf,"\n%-*s      %-*s(director, ffPrefix, \"\", \"%s\")",
00149          //        offset," ", maxVarname, GetName(), GetBranchName() );
00150 
00151       }
00152    }
00153 }

Generated on Tue Jul 5 15:42:57 2011 for ROOT_528-00b_version by  doxygen 1.5.1