#include "TBranchElement.h"
#include "Api.h"
#include "TBasket.h"
#include "TBranchObject.h"
#include "TBranchRef.h"
#include "TBrowser.h"
#include "TClass.h"
#include "TClassEdit.h"
#include "TClonesArray.h"
#include "TDataMember.h"
#include "TDataType.h"
#include "TError.h"
#include "TMath.h"
#include "TFile.h"
#include "TFolder.h"
#include "TLeafElement.h"
#include "TRealData.h"
#include "TStreamerElement.h"
#include "TStreamerInfo.h"
#include "TTree.h"
#include "TVirtualCollectionProxy.h"
#include "TVirtualPad.h"
ClassImp(TBranchElement)
namespace {
   void RemovePrefix(TString& str, const char* prefix) {
      
      if (str.Length() && prefix && strlen(prefix)) {
         if (!str.Index(prefix)) {
            str.Remove(0, strlen(prefix));
         }
      }
   }
}
namespace {
   void SwitchContainer(TObjArray* branches) {
      
      const Int_t nbranches = branches->GetEntriesFast();
      for (Int_t i = 0; i < nbranches; ++i) {
         TBranchElement* br = (TBranchElement*) branches->At(i);
         switch (br->GetType()) {
            case 31: br->SetType(41); break;
            case 41: br->SetType(31); break;
         };
         
         SwitchContainer(br->GetListOfBranches());
      }
   }
}
TBranchElement::TBranchElement()
: TBranch()
, fClassName()
, fParentName()
, fClonesName()
, fCollProxy(0)
, fCheckSum(0)
, fClassVersion(0)
, fID(0)
, fType(0)
, fStreamerType(-1)
, fMaximum(0)
, fSTLtype(TClassEdit::kNotSTL)
, fNdata(1)
, fBranchCount(0)
, fBranchCount2(0)
, fInfo(0)
, fObject(0)
, fInit(kFALSE)
, fInitOffsets(kFALSE)
, fCurrentClass()
, fParentClass()
, fBranchClass()
, fBranchOffset(0)
, fBranchID(-1)
{
   
   fNleaves = 1;
}
TBranchElement::TBranchElement(TTree *tree, const char* bname, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize, Int_t splitlevel, Int_t btype)
: TBranch()
, fClassName(sinfo->GetName())
, fParentName()
, fClonesName()
, fCollProxy(0)
, fCheckSum(sinfo->GetCheckSum())
, fClassVersion(sinfo->GetClass()->GetClassVersion())
, fID(id)
, fType(0)
, fStreamerType(-1)
, fMaximum(0)
, fSTLtype(TClassEdit::kNotSTL)
, fNdata(1)
, fBranchCount(0)
, fBranchCount2(0)
, fInfo(sinfo)
, fObject(0)
, fInit(kTRUE)
, fInitOffsets(kFALSE)
, fCurrentClass()
, fParentClass()
, fBranchClass(sinfo->GetClass())
, fBranchOffset(0)
, fBranchID(-1)
{
   
   
   
   Init(tree, 0, bname,sinfo,id,pointer,basketsize,splitlevel,btype);
}
TBranchElement::TBranchElement(TBranch *parent, const char* bname, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize, Int_t splitlevel, Int_t btype)
: TBranch()
, fClassName(sinfo->GetName())
, fParentName()
, fClonesName()
, fCollProxy(0)
, fCheckSum(sinfo->GetCheckSum())
, fClassVersion(sinfo->GetClass()->GetClassVersion())
, fID(id)
, fType(0)
, fStreamerType(-1)
, fMaximum(0)
, fSTLtype(TClassEdit::kNotSTL)
, fNdata(1)
, fBranchCount(0)
, fBranchCount2(0)
, fInfo(sinfo)
, fObject(0)
, fInit(kTRUE)
, fInitOffsets(kFALSE)
, fCurrentClass()
, fParentClass()
, fBranchClass(sinfo->GetClass())
, fBranchOffset(0)
, fBranchID(-1)
{
   
   
   
   Init(parent ? parent->GetTree() : 0, parent, bname,sinfo,id,pointer,basketsize,splitlevel,btype);
}
void TBranchElement::Init(TTree *tree, TBranch *parent,const char* bname, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize, Int_t splitlevel, Int_t btype)
{
   
   
   
   TString name(bname);
   
   SetName(name);
   SetTitle(name);
   
   fSplitLevel = splitlevel;
   fTree   = tree;
   fMother = parent ? parent->GetMother() : this;
   fParent = parent;
   fDirectory = fTree->GetDirectory();
   fFileName = "";
   
   
   SetAutoDelete(kFALSE);
   fCompress = -1;
   if (fTree->GetDirectory()) {
      TFile* bfile = fTree->GetDirectory()->GetFile();
      if (bfile) {
         fCompress = bfile->GetCompressionLevel();
      }
   }
   
   
   
   if (id > -1) {
      
      ULong_t* elems = sinfo->GetElems();
      TStreamerElement* element = (TStreamerElement*) elems[id];
      fStreamerType = element->GetType();
   }
   
   
   
   
   
   
   fEntryOffsetLen = 0;
   if (btype || (fStreamerType <= TVirtualStreamerInfo::kBase) || (fStreamerType == TVirtualStreamerInfo::kCharStar) || (fStreamerType == TVirtualStreamerInfo::kBits) || (fStreamerType > TVirtualStreamerInfo::kBool)) {
      fEntryOffsetLen = 1000;
   }
   
   
   
   
   if (basketsize < (100 + fEntryOffsetLen)) {
      basketsize = 100 + fEntryOffsetLen;
   }
   fBasketSize = basketsize;
   
   
   
   fBasketBytes = new Int_t[fMaxBaskets];
   fBasketEntry = new Long64_t[fMaxBaskets];
   fBasketSeek = new Long64_t[fMaxBaskets];
   for (Int_t i = 0; i < fMaxBaskets; ++i) {
      fBasketBytes[i] = 0;
      fBasketEntry[i] = 0;
      fBasketSeek[i] = 0;
   }
   
   TBasket* basket = new TBasket(name, fTree->GetName(), this);
   fBaskets.Add(basket);
   
   
   
   TBranchElement* brOfCounter = 0;
   if (id < 0) {
      
      
      
      
      if (fBranchClass.GetClass()->InheritsFrom(TObject::Class())) {
        SetBit(kBranchObject);
      }
   } else {
      
      ULong_t* elems = sinfo->GetElems();
      TStreamerElement* element = (TStreamerElement*) elems[id];
      if ((fStreamerType == TVirtualStreamerInfo::kObject) || (fStreamerType == TVirtualStreamerInfo::kBase) || (fStreamerType == TVirtualStreamerInfo::kTNamed) || (fStreamerType == TVirtualStreamerInfo::kTObject) || (fStreamerType == TVirtualStreamerInfo::kObjectp) || (fStreamerType == TVirtualStreamerInfo::kObjectP)) {
         
         
         
         
         
         if (fBranchClass.GetClass()->InheritsFrom(TObject::Class())) {
            SetBit(kBranchObject);
         }
      }
      if (element->IsA() == TStreamerBasicPointer::Class()) {
         
         TStreamerBasicPointer *bp = (TStreamerBasicPointer *)element;
         TString countname;
         countname = bname;
         Ssiz_t dot = countname.Last('.');
         if (dot>=0) {
            countname.Remove(dot+1);
         } else {
            countname = "";
         }
         countname += bp->GetCountName();
         brOfCounter = (TBranchElement *)fTree->GetBranch(countname);
         countname.Form("%s[%s]",name.Data(),bp->GetCountName());
         SetTitle(countname);
      }
      if (splitlevel > 0) {
         
         const char* elem_type = element->GetTypeName();
         fSTLtype = TMath::Abs(TClassEdit::IsSTLCont(elem_type));
         if (element->CannotSplit()) {
            fSplitLevel = 0;
         } else if (element->IsA() == TStreamerBase::Class()) {
            
            
            
            
            
            fType = 1;
            TClass* clOfElement = TClass::GetClass(element->GetName());
            Int_t nbranches = fBranches.GetEntriesFast();
            
            
            
            
            
            if (!strcmp(name, clOfElement->GetName())) {
               
               
               
               
               
               
               
               
               Unroll("", fBranchClass.GetClass(), clOfElement, pointer, basketsize, splitlevel, 0);
               return;
            }
            
            
            
            
            
            
            
            
            
            
            
            
            
            Unroll(name, clOfElement, clOfElement, pointer, basketsize, splitlevel, 0);
            if (strchr(bname, '.')) {
               
               
               
               
               
               
               
               
               
               
               return;
            }
            if (nbranches == fBranches.GetEntriesFast()) {
               
               if (strlen(bname)) {
                  name.Form("%s.%s", bname, clOfElement->GetName());
               } else {
                  name.Form("%s", clOfElement->GetName());
               }
               SetName(name);
               SetTitle(name);
            }
            return;
         } else if (!strcmp(elem_type, "TClonesArray") || !strcmp(elem_type, "TClonesArray*")) {
            
            Bool_t ispointer = !strcmp(elem_type,"TClonesArray*");
            TClonesArray *clones;
            if (ispointer) {
               char **ppointer = (char**)(pointer);
               clones = (TClonesArray*)(*ppointer);
            } else {
               clones = (TClonesArray*)pointer;
            }
            basket->DeleteEntryOffset(); 
            fEntryOffsetLen = 0;
            
            TLeaf* leaf = new TLeafElement(this, name, fID, fStreamerType);
            fNleaves = 1;
            fLeaves.Add(leaf);
            fTree->GetListOfLeaves()->Add(leaf);
            if (!clones) return;
            TClass* clOfClones = clones->GetClass();
            if (!clOfClones) {
               return;
            }
            
            TBasket *basket2 = new TBasket(name,fTree->GetName(),this);
            fBaskets.Add(basket2);
            fType = 3;
            
            
            
            
            fClonesName = clOfClones->GetName();
            TString aname;
            aname.Form(" (%s)", clOfClones->GetName());
            TString atitle = element->GetTitle();
            if (!atitle.Contains(aname)) {
               atitle += aname;
               element->SetTitle(atitle.Data());
            }
            TString branchname( name );
            branchname += "_";
            SetTitle(branchname);
            leaf->SetName(branchname);
            leaf->SetTitle(branchname);
            Unroll(name, clOfClones, clOfClones, pointer, basketsize, splitlevel, 31);
            BuildTitle(name);
            return;
         } else if (((fSTLtype >= TClassEdit::kVector) && (fSTLtype <= TClassEdit::kMultiSet)) || ((fSTLtype >= -TClassEdit::kMultiSet) && (fSTLtype <= -TClassEdit::kVector))) {
            
            TClass* contCl = TClass::GetClass(elem_type);
            fCollProxy = contCl->GetCollectionProxy()->Generate();
            TClass* valueClass = GetCollectionProxy()->GetValueClass();
            
            Bool_t cansplit = kTRUE;
            if (!valueClass) {
               cansplit = kFALSE;
            } else if ((valueClass == TString::Class()) || (valueClass == TClass::GetClass("string"))) {
               cansplit = kFALSE;
            } else if (GetCollectionProxy()->HasPointers()) {
               cansplit = kFALSE;
            } else if (!valueClass->CanSplit()) {
               cansplit = kFALSE;
            } else if (valueClass->GetCollectionProxy()) {
               
               
               
               cansplit = kFALSE;
            }
            if (cansplit) {
               
               fType = 4;
               
               TLeaf *leaf = new TLeafElement(this, name, fID, fStreamerType);
               fNleaves = 1;
               fLeaves.Add(leaf);
               fTree->GetListOfLeaves()->Add(leaf);
               
               TBasket *basket2 = new TBasket(name,fTree->GetName(),this);
               fBaskets.Add(basket2);
               
               
               
               fClonesName = valueClass->GetName();
               TString aname;
               aname.Form(" (%s)", valueClass->GetName());
               TString atitle = element->GetTitle();
               if (!atitle.Contains(aname)) {
                  atitle += aname;
                  element->SetTitle(atitle.Data());
               }
               TString branchname (name);
               branchname += "_";
               SetTitle(branchname);
               leaf->SetName(branchname);
               leaf->SetTitle(branchname);
               
               Unroll(name, valueClass, valueClass, pointer, basketsize, splitlevel, 41);
               BuildTitle(name);
               return;
            }
         } else if (!strchr(elem_type, '*') && ((fStreamerType == TVirtualStreamerInfo::kObject) || (fStreamerType == TVirtualStreamerInfo::kAny))) {
            
            
            
            
            
            fType = 2;
            TClass* clm = TClass::GetClass(elem_type);
            Int_t err = Unroll(name, clm, clm, pointer, basketsize, splitlevel, 0);
            if (err >= 0) {
               
               
               return;
            }
         }
      }
   }
   
   
   
   TLeaf* leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
   leaf->SetTitle(GetTitle());
   fNleaves = 1;
   fLeaves.Add(leaf);
   fTree->GetListOfLeaves()->Add(leaf);
   
   
   
   
   if (brOfCounter) {
      SetBranchCount(brOfCounter);
   }
}
TBranchElement::TBranchElement(TTree *tree, const char* bname, TClonesArray* clones, Int_t basketsize, Int_t splitlevel, Int_t compress)
: TBranch()
, fClassName("TClonesArray")
, fParentName()
, fInfo((TStreamerInfo*)TClonesArray::Class()->GetStreamerInfo())
, fCurrentClass()
, fParentClass()
, fBranchClass(TClonesArray::Class())
, fBranchID(-1)
{
   
   
   
   Init(tree, 0, bname, clones, basketsize, splitlevel, compress);
}
TBranchElement::TBranchElement(TBranch *parent, const char* bname, TClonesArray* clones, Int_t basketsize, Int_t splitlevel, Int_t compress)
: TBranch()
, fClassName("TClonesArray")
, fParentName()
, fInfo((TStreamerInfo*)TClonesArray::Class()->GetStreamerInfo())
, fCurrentClass()
, fParentClass()
, fBranchClass(TClonesArray::Class())
, fBranchID(-1)
{
   
   
   
   Init(parent ? parent->GetTree() : 0, parent, bname, clones, basketsize, splitlevel, compress);
}
void TBranchElement::Init(TTree *tree, TBranch *parent, const char* bname, TClonesArray* clones, Int_t basketsize, Int_t splitlevel, Int_t compress)
{
   
   
   
   fCollProxy = 0;
   fSplitLevel    = splitlevel;
   fID            = 0;
   fInit          = kTRUE;
   fStreamerType  = -1;
   fType          = 0;
   fClassVersion  = TClonesArray::Class()->GetClassVersion();
   fCheckSum      = fInfo->GetCheckSum();
   fBranchCount   = 0;
   fBranchCount2  = 0;
   fObject        = 0;
   fMaximum       = 0;
   fBranchOffset  = 0;
   fSTLtype       = TClassEdit::kNotSTL;
   fInitOffsets   = kFALSE;
   fTree          = tree;
   fMother        = parent ? parent->GetMother() : this;
   fParent        = parent;
   fDirectory     = fTree->GetDirectory();
   fFileName      = "";
   SetName(bname);
   const char* name = GetName();
   SetTitle(name);
   
   fCompress = compress;
   if (compress == -1 && fTree->GetDirectory()) {
      TFile *bfile = fTree->GetDirectory()->GetFile();
      if (bfile) fCompress = bfile->GetCompressionLevel();
   }
   if (basketsize < 100) basketsize = 100;
   fBasketSize     = basketsize;
   fBasketBytes    = new Int_t[fMaxBaskets];
   fBasketEntry    = new Long64_t[fMaxBaskets];
   fBasketSeek     = new Long64_t[fMaxBaskets];
   for (Int_t i=0;i<fMaxBaskets;i++) {
      fBasketBytes[i] = 0;
      fBasketEntry[i] = 0;
      fBasketSeek[i]  = 0;
   }
   
   TBasket *basket = new TBasket(name, fTree->GetName(), this);
   fBaskets.Add(basket);
   
   
   SetAutoDelete(kFALSE);
   
   if (splitlevel > 0) {
      fType = 3;
      
      TLeaf* leaf = new TLeafElement(this, name, fID, fStreamerType);
      fNleaves = 1;
      fLeaves.Add(leaf);
      fTree->GetListOfLeaves()->Add(leaf);
      
      TBasket* basket = new TBasket(name, fTree->GetName(), this);
      fBaskets.Add(basket);
      
      TClass* clonesClass = clones->GetClass();
      if (!clonesClass) {
         
         return;
      }
      fClonesName = clonesClass->GetName();
      std::string branchname = name + std::string("_");
      SetTitle(branchname.c_str());
      leaf->SetName(branchname.c_str());
      leaf->SetTitle(branchname.c_str());
      Unroll(name, clonesClass, clonesClass, 0, basketsize, splitlevel, 31);
      BuildTitle(name);
      return;
   }
   SetBit(kBranchObject);
   TLeaf *leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
   leaf->SetTitle(GetTitle());
   fNleaves = 1;
   fLeaves.Add(leaf);
   fTree->GetListOfLeaves()->Add(leaf);
}
TBranchElement::TBranchElement(TTree *tree, const char* bname, TVirtualCollectionProxy* cont, Int_t basketsize, Int_t splitlevel, Int_t compress)
: TBranch()
, fClassName(cont->GetCollectionClass()->GetName())
, fParentName()
, fCurrentClass()
, fParentClass()
, fBranchClass(cont->GetCollectionClass())
, fBranchID(-1)
{
   
   
   
   Init(tree, 0, bname, cont, basketsize, splitlevel, compress);
}
TBranchElement::TBranchElement(TBranch *parent, const char* bname, TVirtualCollectionProxy* cont, Int_t basketsize, Int_t splitlevel, Int_t compress)
: TBranch()
, fClassName(cont->GetCollectionClass()->GetName())
, fParentName()
, fCurrentClass()
, fParentClass()
, fBranchClass(cont->GetCollectionClass())
, fBranchID(-1)
{
   
   
   
   Init(parent ? parent->GetTree() : 0, parent, bname, cont, basketsize, splitlevel, compress);
}
void TBranchElement::Init(TTree *tree, TBranch *parent, const char* bname, TVirtualCollectionProxy* cont, Int_t basketsize, Int_t splitlevel, Int_t compress)
{
   
   
   
   fCollProxy = cont->Generate();
   TString name( bname );
   if (name[name.Length()-1]=='.') {
      name.Remove(name.Length()-1);
   }
   fInitOffsets   = kFALSE;
   fSplitLevel    = splitlevel;
   fInfo          = 0;
   fID            = -1;
   fInit          = kTRUE;
   fStreamerType  = -1; 
   fType          = 0;
   fClassVersion  = cont->GetCollectionClass()->GetClassVersion();
   fCheckSum      = cont->GetCollectionClass()->GetCheckSum();
   fBranchCount   = 0;
   fBranchCount2  = 0;
   fObject        = 0;
   fMaximum       = 0;
   fBranchOffset  = 0;
   fSTLtype       = TClassEdit::kNotSTL;
   fTree          = tree;
   fMother        = parent ? parent->GetMother() : this;
   fParent        = parent;
   fDirectory     = fTree->GetDirectory();
   fFileName      = "";
   SetName(name);
   SetTitle(name);
   
   fCompress = compress;
   if ((compress == -1) && fTree->GetDirectory()) {
      TFile* bfile = fTree->GetDirectory()->GetFile();
      if (bfile) {
         fCompress = bfile->GetCompressionLevel();
      }
   }
   if (basketsize < 100) {
      basketsize = 100;
   }
   fBasketSize     = basketsize;
   fBasketBytes    = new Int_t[fMaxBaskets];
   fBasketEntry    = new Long64_t[fMaxBaskets];
   fBasketSeek     = new Long64_t[fMaxBaskets];
   fBasketEntry[0] = fEntryNumber;
   fBasketBytes[0] = 0;
   
   TBasket* basket = new TBasket(name, fTree->GetName(), this);
   fBaskets.Add(basket);
   
   
   SetAutoDelete(kFALSE);
   
   if ((splitlevel > 0) && fBranchClass.GetClass() && fBranchClass.GetClass()->CanSplit()) {
      fType = 4;
      
      TLeaf* leaf = new TLeafElement(this, name, fID, fStreamerType);
      fNleaves = 1;
      fLeaves.Add(leaf);
      fTree->GetListOfLeaves()->Add(leaf);
      
      TBasket* basket = new TBasket(name, fTree->GetName(), this);
      fBaskets.Add(basket);
      
      TClass* valueClass = cont->GetValueClass();
      if (!valueClass) {
         return;
      }
      fClonesName = valueClass->GetName();
      TString branchname;
      branchname += "_";
      SetTitle(branchname);
      leaf->SetName(branchname);
      leaf->SetTitle(branchname);
      Unroll(name, valueClass, valueClass, 0, basketsize, splitlevel, 41);
      BuildTitle(name);
      return;
   }
   TLeaf *leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
   leaf->SetTitle(GetTitle());
   fNleaves = 1;
   fLeaves.Add(leaf);
   fTree->GetListOfLeaves()->Add(leaf);
}
TBranchElement::~TBranchElement()
{
   
   
   
   
   
   delete[] fBranchOffset;
   fBranchOffset = 0;
   fInfo = 0;
   fBranchCount2 = 0;
   fBranchCount = 0;
   
   fCollProxy = 0;
}
TStreamerInfo* TBranchElement::GetInfo() const
{
   
   if (!fInfo || (fInfo && (!fInit || !fInfo->GetOffsets()))) {
      const_cast<TBranchElement*>(this)->InitInfo();
   }
   return fInfo;
}
void TBranchElement::Browse(TBrowser* b)
{
   
   Int_t nbranches = fBranches.GetEntriesFast();
   if (nbranches > 0) {
      TList persistentBranches;
      TBranch* branch=0;
      TIter iB(&fBranches);
      while((branch=(TBranch*)iB())) {
         if (branch->IsFolder()) persistentBranches.Add(branch);
         else {
            
            TClass* cl=0;
            if (strlen(GetClonesName()))
               
               
               cl=TClass::GetClass(GetClonesName());
            else {
               cl=TClass::GetClass(GetClassName());
               
               
               ULong_t *elems=0;
               TStreamerElement *element=0;
               TClass* clsub=0;
               if (fID>=0 && GetInfo()
                   && ((elems=GetInfo()->GetElems()))
                   && ((element=(TStreamerElement *)elems[fID]))
                   && ((clsub=element->GetClassPointer())))
                  cl=clsub;
            }
            if (cl) {
               TString strMember=branch->GetName();
               Size_t mempos=strMember.Last('.');
               if (mempos!=kNPOS)
                  strMember.Remove(0, (Int_t)mempos+1);
               mempos=strMember.First('[');
               if (mempos!=kNPOS)
                  strMember.Remove((Int_t)mempos);
               TDataMember* m=cl->GetDataMember(strMember);
               if (!m || m->IsPersistent()) persistentBranches.Add(branch);
            } else persistentBranches.Add(branch);
         } 
      }
      persistentBranches.Browse(b);
      
      if (GetBrowsables() && GetBrowsables()->GetSize())
         GetBrowsables()->Browse(b);
   } else {
      if (GetBrowsables() && GetBrowsables()->GetSize()) {
         GetBrowsables()->Browse(b);
         return;
      }
      
      
      TString slash("/");
      TString escapedSlash("\\/");
      TString name = GetName();
      Int_t pos = name.First('[');
      if (pos != kNPOS) {
         name.Remove(pos);
      }
      TString mothername;
      if (GetMother()) {
         mothername = GetMother()->GetName();
         pos = mothername.First('[');
         if (pos != kNPOS) {
            mothername.Remove(pos);
         }
         Int_t len = mothername.Length();
         if (len) {
            if (mothername(len-1) != '.') {
               
               
               
               
               TString doublename = mothername;
               doublename.Append(".");
               Int_t isthere = (name.Index(doublename) == 0);
               if (!isthere) {
                  name.Prepend(doublename);
               } else {
                  if (GetMother()->FindBranch(mothername)) {
                     doublename.Append(mothername);
                     isthere = (name.Index(doublename) == 0);
                     if (!isthere) {
                        mothername.Append(".");
                        name.Prepend(mothername);
                     }
                  } else {
                     
                     
                  }
               }
            } else {
               
               
               if (name.Index(mothername) == kNPOS) {
                  name.Prepend(mothername);
               }
            }
         }
      }
      name.ReplaceAll(slash, escapedSlash);
      GetTree()->Draw(name, "", b ? b->GetDrawOption() : "");
      if (gPad) {
         gPad->Update();
      }
   }
}
void TBranchElement::BuildTitle(const char* name)
{
   
   TString branchname;
   Int_t nbranches = fBranches.GetEntries();
   for (Int_t i = 0; i < nbranches; ++i) {
      TBranchElement* bre = (TBranchElement*) fBranches.At(i);
      if (fType == 3) {
         bre->SetType(31);
      } else if (fType == 4) {
         bre->SetType(41);
      } else {
         Error("BuildTitle", "This cannot happen, fType of parent is not 3 or 4!");
      }
      bre->fCollProxy = GetCollectionProxy();
      
      bre->BuildTitle(name);
      const char* fin = strrchr(bre->GetTitle(), '.');
      if (fin == 0) {
         continue;
      }
      
      bre->SetBranchCount(this);
      TLeafElement* lf = (TLeafElement*) bre->GetListOfLeaves()->At(0);
      
      
      branchname = fin+1;
      Ssiz_t dim = branchname.First('[');
      if (dim>=0) {
         branchname.Remove(dim);
      }
      branchname += Form("[%s_]",name);
      bre->SetTitle(branchname);
      if (lf) {
         lf->SetTitle(branchname);
      }
      
      
      
      
      
      
      
      
      
      
      
      
      Int_t stype = bre->GetStreamerType();
      
      if ((stype > 40) && (stype < 61)) {
         TString name2 (bre->GetName());
         Ssiz_t bn = name2.Last('.');
         if (bn<0) {
            continue;
         }
         TStreamerBasicPointer *el = (TStreamerBasicPointer*)bre->GetInfo()->GetElements()->FindObject(name2.Data()+bn+1);
         name2.Remove(bn+1);
         name2 += el->GetCountName();
         TBranchElement *bc2 = (TBranchElement*)fBranches.FindObject(name2);
         bre->SetBranchCount2(bc2);
      }
   }
}
Int_t TBranchElement::Fill()
{
   
   
   
   
   
   
   
   
   Int_t nbytes = 0;
   Int_t nwrite = 0;
   Int_t nerror = 0;
   Int_t nbranches = fBranches.GetEntriesFast();
   ValidateAddress();
   
   
   
   if (fID < 0) {
      if (!fObject) {
         Error("Fill", "attempt to fill branch %s while addresss is not set", GetName());
         return 0;
      }
   }
   
   
   
   
   
   if ((fType >= 0) && (fType < 10)) {
      TBranchRef* bref = fTree->GetBranchRef();
      if (bref) {
         fBranchID = bref->SetParent(this, fBranchID);
      }
   }
   if (!nbranches) {
      
      if (!TestBit(kDoNotProcess)) {
         nwrite = TBranch::Fill();
         if (nwrite < 0) {
            Error("Fill", "Failed filling branch:%s, nbytes=%d", GetName(), nwrite);
            ++nerror;
         } else {
            nbytes += nwrite;
         }
      }
   } else {
      
      if (fType == 3 || fType == 4) {
         
         nwrite = TBranch::Fill();
         if (nwrite < 0) {
            Error("Fill", "Failed filling branch:%s, nbytes=%d", GetName(), nwrite);
            ++nerror;
         } else {
            nbytes += nwrite;
         }
      } else {
         ++fEntries;
      }
      for (Int_t i = 0; i < nbranches; ++i) {
         TBranchElement* branch = (TBranchElement*) fBranches[i];
         if (!branch->TestBit(kDoNotProcess)) {
            nwrite = branch->Fill();
            if (nwrite < 0) {
               Error("Fill", "Failed filling branch:%s.%s, nbytes=%d", GetName(), branch->GetName(), nwrite);
               nerror++;
            } else {
               nbytes += nwrite;
            }
         }
      }
   }
   if (fTree->Debug() > 0) {
      
      Long64_t entry = fEntries;
      if ((entry >= fTree->GetDebugMin()) && (entry <= fTree->GetDebugMax())) {
         printf("Fill: %lld, branch=%s, nbytes=%d\n", entry, GetName(), nbytes);
      }
   }
   if (nerror != 0) {
      return -1;
   }
   return nbytes;
}
void TBranchElement::FillLeaves(TBuffer& b)
{
   
   
   
   
   ValidateAddress();
   
   
   
   if (!fObject) {
      return;
   }
   
   
   
   
   
   
   if ((fType <= 2) && TestBit(kBranchObject)) {
      
      
      
      
      
      
      b.MapObject((TObject*) fObject);
   }
   
   
   
   if (fType <= 2) {
      
      
      
      
      
      TStreamerInfo* si = GetInfo();
      if (!si) {
         Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
         return;
      }
      Int_t n = si->WriteBufferAux(b, &fObject, fID, 1, 0, 0);
      if ((fStreamerType == TVirtualStreamerInfo::kCounter) && (n > fMaximum)) {
         fMaximum = n;
      }
   } else if (fType == 3) {
      
      if (fTree->GetMakeClass()) {
         
         TClass* cl = TClass::GetClass(GetClonesName());
         
         TVirtualStreamerInfo* si = cl->GetStreamerInfo();
         if (!si) {
            Error("FillLeaves", "Cannot get streamer info for branch '%s' class '%s'", GetName(), cl->GetName());
            return;
         }
         
         si->ForceWriteInfo((TFile *) b.GetParent());
         Int_t* nptr = (Int_t*) fAddress;
         b << *nptr;
      } else {
         if (!fObject) {
            
            b << 0;
         } else {
            TClonesArray* clones = (TClonesArray*) fObject;
            Int_t n = clones->GetEntriesFast();
            if (n > fMaximum) {
               fMaximum = n;
            }
            b << n;
         }
      }
   } else if (fType == 4) {
      
      if (!fObject) {
         
         b << 0;
      } else {
         Int_t n = 0;
         {
            
            TVirtualCollectionProxy::TPushPop helper(GetCollectionProxy(), fObject);
            n = GetCollectionProxy()->Size();
         }
         if (n > fMaximum) {
            fMaximum = n;
         }
         b << n;
      }
   } else if (fType == 31) {
      
      if (fTree->GetMakeClass()) {
         
         if (!fAddress) {
            
            
            return;
         }
         Int_t atype = fStreamerType;
         if (atype > 54) {
            
            
            
            
            
            
            
            return;
         }
         Int_t* nn = (Int_t*) fBranchCount->GetAddress();
         if (!nn) {
            Error("FillLeaves", "The branch counter address was zero!");
            return;
         }
         Int_t n = *nn;
         if (atype > 40) {
            
            Error("FillLeaves", "Clonesa: %s, n=%d, sorry not supported yet", GetName(), n);
            return;
         }
         if (atype > 20) {
            atype -= 20;
            TLeafElement* leaf = (TLeafElement*) fLeaves.UncheckedAt(0);
            n = n * leaf->GetLenStatic();
         }
         switch (atype) {
            
            case TVirtualStreamerInfo::kChar     : { b.WriteFastArray((Char_t*)    fAddress, n); break; }
            case TVirtualStreamerInfo::kShort    : { b.WriteFastArray((Short_t*)   fAddress, n); break; }
            case TVirtualStreamerInfo::kInt      : { b.WriteFastArray((Int_t*)     fAddress, n); break; }
            case TVirtualStreamerInfo::kLong     : { b.WriteFastArray((Long_t*)    fAddress, n); break; }
            case TVirtualStreamerInfo::kFloat    : { b.WriteFastArray((Float_t*)   fAddress, n); break; }
            case TVirtualStreamerInfo::kCounter  : { b.WriteFastArray((Int_t*)     fAddress, n); break; }
            
            case TVirtualStreamerInfo::kDouble   : { b.WriteFastArray((Double_t*)  fAddress, n); break; }
            case TVirtualStreamerInfo::kDouble32 : {
               Double_t* xx = (Double_t*) fAddress;
               for (Int_t ii = 0; ii < n; ++ii) {
                  b << (Float_t) xx[ii];
               }
               break;
            }
            
            case TVirtualStreamerInfo::kUChar    : { b.WriteFastArray((UChar_t*)   fAddress, n); break; }
            case TVirtualStreamerInfo::kUShort   : { b.WriteFastArray((UShort_t*)  fAddress, n); break; }
            case TVirtualStreamerInfo::kUInt     : { b.WriteFastArray((UInt_t*)    fAddress, n); break; }
            case TVirtualStreamerInfo::kULong    : { b.WriteFastArray((ULong_t*)   fAddress, n); break; }
            
            case TVirtualStreamerInfo::kBits     : { b.WriteFastArray((UInt_t*)    fAddress, n); break; }
            case TVirtualStreamerInfo::kLong64   : { b.WriteFastArray((Long64_t*)  fAddress, n); break; }
            case TVirtualStreamerInfo::kULong64  : { b.WriteFastArray((ULong64_t*) fAddress, n); break; }
            case TVirtualStreamerInfo::kBool     : { b.WriteFastArray((Bool_t*)    fAddress, n); break; }
            
         }
      } else {
         if (!fObject) {
            
            return;
         } else {
            TClonesArray* clones = (TClonesArray*) fObject;
            Int_t n = clones->GetEntriesFast();
            TStreamerInfo* si = (TStreamerInfo*)GetInfo();
            if (!si) {
               Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
               return;
            }
            si->WriteBufferClones(b, clones, n, fID, fOffset);
         }
      }
   } else if (fType == 41) {
      
      if (!fObject) {
         
         return;
      } else {
         
         
         Int_t n = 0;
         TVirtualCollectionProxy::TPushPop helper(GetCollectionProxy(), fObject);
         n = GetCollectionProxy()->Size();
         
         TStreamerInfo* si = (TStreamerInfo*)GetInfo();
         if (!si) {
            Error("FillLeaves", "Cannot get streamer info for branch '%s'", GetName());
            return;
         }
         si->WriteBufferSTL(b, GetCollectionProxy(), n, fID, fOffset);
      }
   }
}
static void R__CleanName(std::string &name) 
{
   
   
   std::size_t dim = name.find_first_of("[");
   if (dim != std::string::npos) {
      name.erase(dim);
   }
   if (name[name.size()-1] != '.') {
      name += '.';
   }
}
TBranch* TBranchElement::FindBranch(const char *name)
{
   
   
   
   
   
   
   if (fID >= 0) {
      TVirtualStreamerInfo* si = GetInfo();
      TStreamerElement* se = (TStreamerElement*) si->GetElems()[fID];
      if (se && se->IsBase()) {
         
         std::string longnm(GetName());
         R__CleanName(longnm);
         longnm += name;
         std::string longnm_parent(GetMother()->GetSubBranch(this)->GetName());
         R__CleanName(longnm_parent);
         longnm_parent += name;  
         TBranch* branch = 0;
         TIter next(GetListOfBranches());
         while ((branch = (TBranch*) next())) {
            std::string brname(branch->GetName());
            std::size_t dim = brname.find_first_of("[");
            if (dim != std::string::npos) {
               brname.erase(dim);
            }
            if (name == brname) {
               return branch;
            }
            if (longnm == brname) {
               return branch;
            }
            if (longnm_parent == brname) {
               return branch;
            }
         }
         return 0;
      }
   }
   TBranch *result = TBranch::FindBranch(name);
   if (!result) {
      
      for(Int_t i = 0; i < GetListOfBranches()->GetEntries(); ++i) {
         TBranchElement *br = (TBranchElement*)GetListOfBranches()->At(i);
         TVirtualStreamerInfo* si = br->GetInfo();
         if (br->GetID() >= 0) {
            TStreamerElement* se = (TStreamerElement*) si->GetElems()[br->GetID()];
            if (se && se->IsBase()) {
               result = br->FindBranch(name);
            }
         }
      }
   }
   return result;
}
TLeaf* TBranchElement::FindLeaf(const char *name)
{
   
   TLeaf *leaf = TBranch::FindLeaf(name);
   if (leaf==0 && GetListOfLeaves()->GetEntries()==1) {
      TBranchElement *parent = (TBranchElement*)GetMother()->GetSubBranch(this);
      if (parent==this || parent->GetID()<0 ) return 0;
      TVirtualStreamerInfo* si = parent->GetInfo();
      TStreamerElement* se = (TStreamerElement*) si->GetElems()[parent->GetID()];
      if (! se->IsBase() ) return 0;
      TBranchElement *grand_parent = (TBranchElement*)GetMother()->GetSubBranch(parent);
      std::string longname( grand_parent->GetName() );
      R__CleanName(longname);
      longname += name;
      std::string leafname( GetListOfLeaves()->At(0)->GetName() );
      if ( longname == leafname ) {
         return (TLeaf*)GetListOfLeaves()->At(0);
      }
   }
   return leaf;
}
char* TBranchElement::GetAddress() const
{
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   ValidateAddress();
   return fAddress;
}
void TBranchElement::InitInfo()
{
   
   if (!fInfo) {
      
      TClass* cl = fBranchClass.GetClass();
      if (cl) {
         if (cl == TClonesArray::Class()) {
            fClassVersion = TClonesArray::Class()->GetClassVersion();
         }
         Bool_t optim = TVirtualStreamerInfo::CanOptimize();
         TVirtualStreamerInfo::Optimize(kFALSE);
         fInfo = (TStreamerInfo*)cl->GetStreamerInfo(fClassVersion);
         TVirtualStreamerInfo::Optimize(optim);
         
         
         
         if (fCheckSum && (cl->IsForeign() || (!cl->IsLoaded() && (fClassVersion == 1) && cl->GetStreamerInfos()->At(1) && (fCheckSum != ((TVirtualStreamerInfo*) cl->GetStreamerInfos()->At(1))->GetCheckSum())))) {
            
            
            
            Int_t ninfos = cl->GetStreamerInfos()->GetEntriesFast();
            for (Int_t i = 1; i < ninfos; ++i) {
               TVirtualStreamerInfo* info = (TVirtualStreamerInfo*) cl->GetStreamerInfos()->At(i);
               if (!info) {
                  continue;
               }
               if (info->GetCheckSum() == fCheckSum) {
                  fClassVersion = i;
                  Bool_t optim = TVirtualStreamerInfo::CanOptimize();
                  TVirtualStreamerInfo::Optimize(kFALSE);
                  fInfo = (TStreamerInfo*)cl->GetStreamerInfo(fClassVersion);
                  TVirtualStreamerInfo::Optimize(optim);
                  break;
               }
            }
         }
      }
   }
   
   
   
   
   if (fInfo) {
      if (!fInfo->GetOffsets()) {
         
         
         
         Bool_t optim = TVirtualStreamerInfo::CanOptimize();
         TVirtualStreamerInfo::Optimize(kFALSE);
         fInfo->Compile();
         TVirtualStreamerInfo::Optimize(optim);
      }
      if (!fInit) {
         
         
         
         
         
         if (GetID() > -1) {
            
            std::string s(GetName());
            size_t pos = s.rfind('.');
            if (pos != std::string::npos) {
               s = s.substr(pos+1);
            }
            while ((pos = s.rfind('[')) != std::string::npos) {
               s = s.substr(0, pos);
            }
            int offset = 0;
            TStreamerElement* elt = fInfo->GetStreamerElement(s.c_str(), offset);
            if (elt) {
               size_t ndata = fInfo->GetNdata();
               ULong_t* elems = fInfo->GetElems();
               for (size_t i = 0; i < ndata; ++i) {
                  if (((TStreamerElement*) elems[i]) == elt) {
                     fID = i;
                     break;
                  }
               }
            }
         }
         fInit = kTRUE;
      }
   }
}
TVirtualCollectionProxy* TBranchElement::GetCollectionProxy()
{
   
   if (fCollProxy) {
      return fCollProxy;
   }
   TBranchElement* thiscast = const_cast<TBranchElement*>(this);
   if (fType == 4) {
      
      const char* className = 0;
      if (fID < 0) {
         
         if (fBranchClass.GetClass()) {
           className = fBranchClass.GetClass()->GetName();
         }
      } else {
         
         TVirtualStreamerInfo* si = thiscast->GetInfo();
         TStreamerElement* se = (TStreamerElement*) si->GetElems()[fID];
         className = se->GetTypeName();
      }
      TClass* cl = TClass::GetClass(className);
      TVirtualCollectionProxy* proxy = cl->GetCollectionProxy();
      fCollProxy = proxy->Generate();
      fSTLtype = TClassEdit::IsSTLCont(className);
      if (fSTLtype < 0) {
        fSTLtype = -fSTLtype;
      }
   } else if (fType == 41) {
      
      thiscast->fCollProxy = fBranchCount->fCollProxy;
   }
   return fCollProxy;
}
TClass* TBranchElement::GetCurrentClass()
{
   
   TClass* cl = fCurrentClass;
   if (cl) {
      return cl;
   }
   TVirtualStreamerInfo* brInfo = GetInfo();
   if (!brInfo) {
      cl = TClass::GetClass(GetClassName());
      R__ASSERT(cl && cl->GetCollectionProxy());
      fCurrentClass = cl;
      return cl;
   }
   TClass* motherCl = brInfo->GetClass();
   if (motherCl->GetCollectionProxy()) {
      cl = motherCl->GetCollectionProxy()->GetCollectionClass();
      if (cl) {
         fCurrentClass = cl;
      }
      return cl;
   }
   TStreamerElement* currentStreamerElement = ((TStreamerElement*) brInfo->GetElems()[GetID()]);
   TDataMember* dm = (TDataMember*) motherCl->GetListOfDataMembers()->FindObject(currentStreamerElement->GetName());
   TString newType;
   if (!dm) {
      
      if (! motherCl->IsLoaded()) {
         TVirtualStreamerInfo* newInfo = motherCl->GetStreamerInfo();
         if (newInfo != brInfo) {
            TStreamerElement* newElems = (TStreamerElement*) newInfo->GetElements()->FindObject(currentStreamerElement->GetName());
            newType = newElems->GetClassPointer()->GetName();
         }
      }
   } else {
      newType = dm->GetTypeName();
   }
   cl = TClass::GetClass(newType);
   if (cl) {
      fCurrentClass = cl;
   }
   return cl;
}
Int_t TBranchElement::GetEntry(Long64_t entry, Int_t getall)
{
   
   
   
   
   
   
   
   
   
   
   
   
   fReadEntry = entry;
   
   
   
   
   
   TBranchRef* bref = fTree->GetBranchRef();
   if (bref) {
      fBranchID = bref->SetParent(this, fBranchID);
      bref->SetReadEntry(entry);
   }
   Int_t nbytes = 0;
   SetupAddresses();
   Int_t nbranches = fBranches.GetEntriesFast();
   if (nbranches) {
      
      
      
      
      if ((fType == 3) || (fType == 4)) {
         Int_t nb = TBranch::GetEntry(entry, getall);
         if (nb < 0) {
            return nb;
         }
         nbytes += nb;
      }
      switch(fSTLtype) {
         case TClassEdit::kSet:
         case TClassEdit::kMultiSet:
         case TClassEdit::kMap:
         case TClassEdit::kMultiMap:
            break;
         default:
            for (Int_t i = 0; i < nbranches; ++i) {
               TBranch* branch = (TBranch*) fBranches[i];
               Int_t nb = branch->GetEntry(entry, getall);
               if (nb < 0) {
                  return nb;
               }
               nbytes += nb;
            }
            break;
      }
   } else {
      
      if (fBranchCount && (fBranchCount->GetReadEntry() != entry)) {
         Int_t nb = fBranchCount->TBranch::GetEntry(entry, getall);
         if (nb < 0) {
            return nb;
         }
         nbytes += nb;
      }
      Int_t nb = TBranch::GetEntry(entry, getall);
      if (nb < 0) {
         return nb;
      }
      nbytes += nb;
   }
   if (fTree->Debug() > 0) {
      if ((entry >= fTree->GetDebugMin()) && (entry <= fTree->GetDebugMax())) {
         Info("GetEntry", "%lld, branch=%s, nbytes=%d", entry, GetName(), nbytes);
      }
   }
   return nbytes;
}
const char* TBranchElement::GetIconName() const
{
   
   if (IsFolder()) {
      return "TBranchElement-folder";
   } else {
      return "TBranchElement-leaf";
   }
}
Int_t TBranchElement::GetMaximum() const
{
   
   if (fBranchCount) {
      return fBranchCount->GetMaximum();
   }
   return fMaximum;
}
char* TBranchElement::GetObject() const
{
   
   ValidateAddress();
   return fObject;
}
TClass* TBranchElement::GetParentClass()
{
   
   return fParentClass.GetClass();
}
const char* TBranchElement::GetTypeName() const
{
   
   if (fType == 3  || fType == 4) {
      return "Int_t";
   }
   
   if ((fStreamerType < 1) || (fStreamerType > 59)) {
      if (fBranchClass.GetClass()) {
         return fBranchClass.GetClass()->GetName();
      } else {
         return 0;
      }
   }
   const char *types[19] = {
      "",
      "Char_t",
      "Short_t",
      "Int_t",
      "Long_t",
      "Float_t",
      "Int_t",
      "",
      "Double_t",
      "Double32_t",
      "",
      "UChar_t",
      "UShort_t",
      "UInt_t",
      "ULong_t",
      "UInt_t",
      "Long64_t",
      "ULong64_t",
      "Bool_t"
   };
   Int_t itype = fStreamerType % 20;
   return types[itype];
}
Double_t TBranchElement::GetValue(Int_t j, Int_t len, Bool_t subarr) const
{
   
   
   
   
   
   
   
   
   
   ValidateAddress();
   if (!j && fBranchCount) {
      Int_t entry = fTree->GetReadEntry();
      fBranchCount->TBranch::GetEntry(entry);
      if (fBranchCount2) {
         fBranchCount2->TBranch::GetEntry(entry);
      }
   }
   if (fTree->GetMakeClass()) {
      if (!fAddress) {
         return 0;
      }
      if ((fType == 3) || (fType == 4)) {
         
         return (Double_t) fNdata;
      } else if ((fType == 31) || (fType == 41)) {
         
         Int_t atype = fStreamerType;
         if (atype < 20) {
            atype += 20;
         }
         return GetInfo()->GetValue(fAddress, atype, j, 1);
      } else if (fType <= 2) {
         
         
         if ((fStreamerType > 40) && (fStreamerType < 55)) {
            Int_t atype = fStreamerType - 20;
            return GetInfo()->GetValue(fAddress, atype, j, 1);
         } else {
            return GetInfo()->GetValue(fObject, fID, j, -1);
         }
      }
   }
   if (fType == 31) {
      TClonesArray* clones = (TClonesArray*) fObject;
      if (subarr) {
         return GetInfo()->GetValueClones(clones, fID, j, len, fOffset);
      }
      return GetInfo()->GetValueClones(clones, fID, j/len, j%len, fOffset);
   } else if (fType == 41) {
      TVirtualCollectionProxy::TPushPop helper(((TBranchElement*) this)->GetCollectionProxy(), fObject);
      if (subarr) {
         return GetInfo()->GetValueSTL(((TBranchElement*) this)->GetCollectionProxy(), fID, j, len, fOffset);
      }
      return GetInfo()->GetValueSTL(((TBranchElement*) this)->GetCollectionProxy(), fID, j/len, j%len, fOffset);
   } else {
      if (GetInfo()) {
         return GetInfo()->GetValue(fObject, fID, j, -1);
      }
      return 0;
   }
}
void* TBranchElement::GetValuePointer() const
{
   
   
   ValidateAddress();
   if (fBranchCount) {
      Int_t entry = fTree->GetReadEntry();
      fBranchCount->TBranch::GetEntry(entry);
      if (fBranchCount2) fBranchCount2->TBranch::GetEntry(entry);
   }
   if (fTree->GetMakeClass()) {
      if (!fAddress) {
         return 0;
      }
      if (fType == 3) {    
         
         return 0;
      } else if (fType == 4) {    
         
         return 0;
      } else if (fType == 31) {    
         
         
         
         return 0;
      } else if (fType == 41) {    
         
         
         
         return 0;
      } else if (fType <= 2) {     
         
         if (fStreamerType > 40 && fStreamerType < 55) {
            
            
            return 0;
         } else {
            
            return 0;
         }
      }
   }
   if (fType == 31) {
      return 0;
   } else if (fType == 41) {
      return 0;
   } else {
      
      if (!GetInfo() || !fObject) return 0;
      char **val = (char**)(fObject+GetInfo()->GetOffsets()[fID]);
      return *val;
   }
}
void TBranchElement::InitializeOffsets()
{
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   Int_t nbranches = fBranches.GetEntriesFast();
   if (nbranches) {
      
      delete[] fBranchOffset;
      fBranchOffset = 0;
      fBranchOffset = new Int_t[nbranches];
      
      if (!fBranchClass.GetClass()) {
         Warning("InitializeOffsets", "No branch class set for branch: %s", GetName());
         fInitOffsets = kTRUE;
         return;
      }
      
      if (!GetInfo()) {
         Warning("InitializeOffsets", "No streamer info available for branch: %s of class: %s", GetName(), fBranchClass.GetClass()->GetName());
         fInitOffsets = kTRUE;
         return;
      }
      
      
      
      
      
      TStreamerElement* branchElem = 0;
      Int_t localOffset = 0;
      TClass* branchClass = fBranchClass.GetClass();
      if (fID > -1) {
         
         
         
         
         
         
         TVirtualStreamerInfo* si = GetInfo();
         
         ULong_t* elems = si->GetElems();
         if (!elems) {
            Warning("InitializeOffsets", "Streamer info for branch: %s has no elements array!", GetName());
            fInitOffsets = kTRUE;
            return;
         }
         
         branchElem = (TStreamerElement*) elems[fID];
         if (!branchElem) {
            Warning("InitializeOffsets", "Cannot get streamer element for branch: %s!", GetName());
            fInitOffsets = kTRUE;
            return;
         }
         localOffset = branchElem->GetOffset();
         branchClass = branchElem->GetClassPointer();
      }
      if (!branchClass) {
         Error("InitializeOffsets", "Could not find class for branch: %s", GetName());
         fInitOffsets = kTRUE;
         return;
      }
      
      for (Int_t subBranchIdx = 0; subBranchIdx < nbranches; ++subBranchIdx) {
         fBranchOffset[subBranchIdx] = 0;
         TBranch* aSubBranch = (TBranch*) fBranches[subBranchIdx];
         
         if (!aSubBranch->InheritsFrom(TBranchElement::Class())) {
            
            continue;
         }
         TBranchElement* subBranch = (TBranchElement*) aSubBranch;
         TVirtualStreamerInfo* sinfo = subBranch->GetInfo();
         if (!sinfo) {
            Warning("InitializeOffsets", "No streamer info for branch: %s subbranch: %s", GetName(), subBranch->GetName());
            fInitOffsets = kTRUE;
            return;
         }
         ULong_t* subBranchElems = sinfo->GetElems();
         if (!subBranchElems) {
            Warning("InitializeOffsets", "No elements array for branch: %s subbranch: %s", GetName(), subBranch->GetName());
            fInitOffsets = kTRUE;
            return;
         }
         
         TStreamerElement* subBranchElement = (TStreamerElement*) subBranchElems[subBranch->fID];
         if (!subBranchElement) {
            Warning("InitializeOffsets", "No streamer element for branch: %s subbranch: %s", GetName(), subBranch->GetName());
            fInitOffsets = kTRUE;
            return;
         }
         Int_t localOffset = subBranchElement->GetOffset();
         
         TBranch* mother = GetMother();
         if (!mother) {
            Warning("InitializeOffsets", "Branch '%s' has no mother!", GetName());
            fInitOffsets = kTRUE;
            return;
         }
         TString motherName(mother->GetName());
         Bool_t motherDot = kFALSE;
         if (motherName.Length() && strchr(motherName.Data(), '.')) {
            motherDot = kTRUE;
         }
         Bool_t motherDotAtEnd = kFALSE;
         if (motherName.Length() && (motherName[motherName.Length()-1] == '.')) {
            motherDotAtEnd = kTRUE;
         }
         Bool_t isBaseSubBranch = kFALSE;
         if ((subBranch->fType == 1) || (subBranchElement->IsBase())) {
            
            
            
            
            
            
            
            isBaseSubBranch = kTRUE;
         }
         Bool_t isContDataMember = kFALSE;
         if ((subBranch->fType == 31) || (subBranch->fType == 41)) {
            
            isContDataMember = kTRUE;
         }
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         TString dataName(subBranch->GetName());
         if (motherDotAtEnd) {
            
            dataName.Remove(0, motherName.Length());
         } else if (motherDot) {
            
            
            
            
            
            
            
            
            if ((fID < 0) && (subBranchElement->IsA() == TStreamerBase::Class())) {
               
               
               
               
               if (dataName.Length() == motherName.Length()) {
                  dataName.Remove(0, motherName.Length());
               }
            } else {
               
               if (dataName.Length() > motherName.Length()) {
                  dataName.Remove(0, motherName.Length() + 1);
               }
            }
         }
         if (isBaseSubBranch) {
            
            
            TString pattern(subBranchElement->GetName());
            if (pattern.Length() <= dataName.Length()) {
               if (!strcmp(dataName.Data() + (dataName.Length() - pattern.Length()), pattern.Data())) {
                  
                  
                  
                  dataName.Remove(dataName.Length() - pattern.Length());
               }
            }
            
            if (dataName.Length()) {
               if (dataName[0] == '.') {
                  dataName.Remove(0, 1);
               }
            }
            
            
         }
         
         TString parentName(GetName());
         if (motherDotAtEnd) {
            
            parentName.Remove(0, motherName.Length());
         } else if (motherDot) {
            
            
            
            
            
            
            
            
            if ((fID > -1) && (mother == mother->GetSubBranch(this)) && (branchElem->IsA() == TStreamerBase::Class())) {
               
               
               
               
               if (parentName.Length() == motherName.Length()) {
                  parentName.Remove(0, motherName.Length());
               }
            } else {
               
               if (parentName.Length() > motherName.Length()) {
                  parentName.Remove(0, motherName.Length() + 1);
               }
            }
         }
         
         if (fType == 1) {
            
            if (mother != mother->GetSubBranch(this)) {
               
               
               
               TString pattern(branchElem->GetName());
               if (pattern.Length() <= parentName.Length()) {
                  if (!strcmp(parentName.Data() + (parentName.Length() - pattern.Length()), pattern.Data())) {
                     
                     
                     
                     parentName.Remove(parentName.Length() - pattern.Length());
                  }
               }
            }
            
            
         }
         
         
         
         if (fID > -1) {
           RemovePrefix(dataName, parentName);
         }
         
         if (dataName.Length()) {
            if (dataName[0] == '.') {
               dataName.Remove(0, 1);
            }
         }
         
         if (dataName.Length()) {
            if (dataName[dataName.Length()-1] == '.') {
               dataName.Remove(dataName.Length() - 1, 1);
            }
         }
         
         
         
         
         
         
         
         
         
         
         Int_t offset = 0;
         if (dataName.Length()) {
            
            
            TClass* pClass = 0;
            
            if (fType == 1) {
               
               
               pClass = branchElem->GetClassPointer();
            } else {
               
               
               pClass = subBranch->GetParentClass();
            }
            if (!pClass) {
               
               
               
               if (GetClonesName() && (strlen(GetClonesName()) != 0)) {
                  pClass = TClass::GetClass(GetClonesName());
                  Warning("InitializeOffsets", "subBranch: '%s' has no parent class!  Assuming parent class is: '%s'.", subBranch->GetName(), pClass->GetName());
               }
               if (fBranchCount && fBranchCount->fCollProxy && fBranchCount->fCollProxy->GetValueClass()) {
                  pClass = fBranchCount->fCollProxy->GetValueClass();
                  Warning("InitializeOffsets", "subBranch: '%s' has no parent class!  Assuming parent class is: '%s'.", subBranch->GetName(), pClass->GetName());
               }
               if (!pClass) {
                  
                  
                  pClass = branchClass;
                  
                  
               }
            }
            
            
            
            TRealData* rd = pClass->GetRealData(dataName);
            if (rd) {
               
               offset = rd->GetThisOffset();
            } else {
               
               
               
            }
         } else {
            
            if (isBaseSubBranch) {
               
            } else {
               Warning("InitializeOffsets", "Could not find the data member name for branch '%s' with parent branch '%s', assuming offset is zero!", subBranch->GetName(), GetName());
            }
         }
         
         
         
         if (isContDataMember) {
            if (isBaseSubBranch) {
               TClass* pClass = subBranch->GetParentClass();
               TClass* thisclass = subBranchElement->GetClassPointer();
               if (pClass && thisclass) {
                  Int_t boffs = pClass->GetBaseClassOffset (thisclass);
                  if (boffs >= 0) offset += boffs;
               }
            }
            
            
            
            
            
            
            subBranch->fOffset = offset - localOffset;
         } else {
            
            Int_t numOfSubSubBranches = subBranch->GetListOfBranches()->GetEntriesFast();
            if (numOfSubSubBranches) {
               if (isBaseSubBranch) {
                  
                  
                  fBranchOffset[subBranchIdx] = offset + localOffset;
               } else {
                  
                  
                  
                  fBranchOffset[subBranchIdx] = offset;
               }
            } else {
               if (isBaseSubBranch) {
                  
                  
                  fBranchOffset[subBranchIdx] = offset;
               } else {
                  
                  
                  fBranchOffset[subBranchIdx] = offset - localOffset;
               }
            }
         }
      }
   }
   fInitOffsets = kTRUE;
}
Bool_t TBranchElement::IsFolder() const
{
   
   Int_t nbranches = fBranches.GetEntriesFast();
   if (nbranches >= 1) {
      return kTRUE;
   }
   TList* browsables = const_cast<TBranchElement*>(this)->GetBrowsables();
   return browsables && browsables->GetSize();
}
Bool_t TBranchElement::IsMissingCollection() const
{
   
   
   
   
   
   
   Bool_t ismissing = kFALSE;
   TBasket* basket = (TBasket*) fBaskets.UncheckedAt(fReadBasket);
   if (basket && fTree) {
      Int_t entry = fTree->GetReadEntry();
      Int_t first  = fBasketEntry[fReadBasket];
      Int_t last;
      if (fReadBasket == fWriteBasket) {
         last = fEntryNumber - 1;
      } else {
         last = fBasketEntry[fReadBasket+1] - 1;
      }
      Int_t* entryOffset = basket->GetEntryOffset();
      Int_t bufbegin;
      Int_t bufnext;
      if (entryOffset) {
         bufbegin = entryOffset[entry-first];
         if (entry < last) {
            bufnext = entryOffset[entry+1-first];
         } else {
            bufnext = basket->GetLast();
         }
         if (bufnext == bufbegin) {
            ismissing = kTRUE;
         } else {
            
            if (basket->GetNevBufSize() == 0) {
               ismissing = kTRUE;
            }
         }
      }
   }
   return ismissing;
}
void TBranchElement::Print(Option_t* option) const
{
   
   Int_t nbranches = fBranches.GetEntriesFast();
   if (strncmp(option,"debugAddress",strlen("debugAddress"))==0) {
      if (strlen(option)==strlen("debugAddress")) {
         Printf("%-24s %-16s %2s %4s %-16s %-16s %8s %8s %s\n",
                "Branch Name", "Streamer Class", "ID", "Type", "Class", "Parent", "pOffset", "fOffset", "fObject");
      }
      TBranchElement *parent = (TBranchElement*) GetMother()->GetSubBranch(this);
      Int_t ind = parent->GetListOfBranches()->IndexOf(this);
      if (strlen(GetName())>24) Printf("%-24s\n%-24s ", GetName(),"");
      else Printf("%-24s ", GetName());
      Printf("%-16s %2d %4d %-16s %-16s %8x %8x %8x\n",
             ((TBranchElement*)this)->GetInfo()->GetName(), GetID(), GetType(),
             GetClassName(), GetParentName(),
             (fBranchOffset&&parent) ? parent->fBranchOffset[ind] : 0,
             GetOffset(), GetObject());
      TObjArray* brl = ((TBranchElement*)this)->GetListOfBranches();
      Int_t nbranches = brl->GetEntriesFast();
      for (Int_t i = 0; i < nbranches; ++i) {
         TBranchElement* subbranch = (TBranchElement*)brl->At(i);
         subbranch->Print("debugAddressSub");
      }
      return;
   }
   if (nbranches) {
      if (fID == -2) {
         if (strcmp(GetName(),GetTitle()) == 0) {
            Printf("*Branch  :%-66s *",GetName());
         } else {
            Printf("*Branch  :%-9s : %-54s *",GetName(),GetTitle());
         }
         Printf("*Entries : %8d : BranchElement (see below)                              *",Int_t(fEntries));
         Printf("*............................................................................*");
      }
      if (fType >= 2) {
         TBranch::Print(option);
      }
      for (Int_t i=0;i<nbranches;i++) {
         TBranch *branch = (TBranch*)fBranches.At(i);
         branch->Print(option);
      }
   } else {
      TBranch::Print(option);
   }
}
void TBranchElement::PrintValue(Int_t lenmax) const
{
   
   ValidateAddress();
   if (fTree->GetMakeClass()) {
      if (!fAddress) {
         return;
      }
      if (fType == 3 || fType == 4) {
         
         printf(" %-15s = %d\n", GetName(), fNdata);
         return;
      } else if (fType == 31 || fType == 41) {
         
         Int_t n = TMath::Min(10, fNdata);
         Int_t atype = fStreamerType + TVirtualStreamerInfo::kOffsetL;
         if (fStreamerType == TVirtualStreamerInfo::kChar) {
            
            
            
            atype = TVirtualStreamerInfo::kOffsetL + TVirtualStreamerInfo::kUChar;
         }
         if (atype > 54) {
            
            printf(" %-15s = %d\n", GetName(), fNdata);
            return;
         }
         if (fStreamerType > 20) {
            atype -= 20;
            TLeafElement* leaf = (TLeafElement*) fLeaves.UncheckedAt(0);
            n = n * leaf->GetLenStatic();
         }
         if (GetInfo()) {
            GetInfo()->PrintValue(GetName(), fAddress, atype, n, lenmax);
         }
         return;
      } else if (fType <= 2) {
         
         
         if ((fStreamerType > 40) && (fStreamerType < 55)) {
            Int_t atype = fStreamerType - 20;
            TBranchElement* counterElement = (TBranchElement*) fBranchCount;
            Int_t n = (Int_t) counterElement->GetValue(0, 0);
            if (GetInfo()) {
               GetInfo()->PrintValue(GetName(), fAddress, atype, n, lenmax);
            }
         } else {
            if (GetInfo()) {
               GetInfo()->PrintValue(GetName(), fObject, fID, -1, lenmax);
            }
         }
         return;
      }
   } else if (fType == 3) {
      printf(" %-15s = %d\n", GetName(), fNdata);
   } else if (fType == 31) {
      TClonesArray* clones = (TClonesArray*) fObject;
      if (GetInfo()) {
         GetInfo()->PrintValueClones(GetName(), clones, fID, fOffset, lenmax);
      }
   } else if (fType == 41) {
      TVirtualCollectionProxy::TPushPop helper(((TBranchElement*) this)->GetCollectionProxy(), fObject);
      if (GetInfo()) {
         GetInfo()->PrintValueSTL(GetName(), ((TBranchElement*) this)->GetCollectionProxy(), fID, fOffset, lenmax);
      }
   } else {
      if (GetInfo()) {
         GetInfo()->PrintValue(GetName(), fObject, fID, -1, lenmax);
      }
   }
}
void TBranchElement::ReadLeaves(TBuffer& b)
{
   
   ValidateAddress();
   if (fTree->GetMakeClass()) {
      if (fType == 3 || fType == 4) {
         
         Int_t *n = (Int_t*) fAddress;
         b >> n[0];
         if ((n[0] < 0) || (n[0] > fMaximum)) {
            if (IsMissingCollection()) {
               n[0] = 0;
               b.SetBufferOffset(b.Length() - sizeof(n));
            } else {
               Error("ReadLeaves", "Incorrect size read for the container in %s\nThe size read is %d when the maximum is %d\nThe size is reset to 0 for this entry (%d)", GetName(), n, fMaximum, GetReadEntry());
               n[0] = 0;
            }
         }
         fNdata = n[0];
         if ( fType == 4)   {
            Int_t i, nbranches = fBranches.GetEntriesFast();
            switch(fSTLtype) {
               case TClassEdit::kSet:
               case TClassEdit::kMultiSet:
               case TClassEdit::kMap:
               case TClassEdit::kMultiMap:
                  for (i=0;i<nbranches;i++) {
                     TBranch *branch = (TBranch*)fBranches[i];
                     Int_t    nb = branch->GetEntry(GetReadEntry(), 1);
                     if (nb < 0) break;
                  }
                  break;
               default:
                  break;
            }
         }
         return;
      } else if (fType == 31 || fType == 41) {    
         fNdata = fBranchCount->GetNdata();
         Int_t atype = fStreamerType;
         
         if (atype > 54) return;
         if (!fAddress) {
            return;
         }
         Int_t n = fNdata;
         if (atype>40) {
            atype -= 40;
            if (!fBranchCount2) return;
            const char *len_where = (char*)fBranchCount2->fAddress;
            if (!len_where) return;
            Int_t len_atype = fBranchCount2->fStreamerType;
            Int_t length;
            Int_t k;
            Char_t isArray;
            for( k=0; k<n; k++) {
               char **where = &(((char**)fAddress)[k]);
               delete [] *where;
               *where = 0;
               switch(len_atype) {
                  case  1:  {length = ((Char_t*)   len_where)[k]; break;}
                  case  2:  {length = ((Short_t*)  len_where)[k]; break;}
                  case  3:  {length = ((Int_t*)    len_where)[k]; break;}
                  case  4:  {length = ((Long_t*)   len_where)[k]; break;}
                     
                  case  6:  {length = ((Int_t*)    len_where)[k]; break;}
                   
                  case 11:  {length = ((UChar_t*)  len_where)[k]; break;}
                  case 12:  {length = ((UShort_t*) len_where)[k]; break;}
                  case 13:  {length = ((UInt_t*)   len_where)[k]; break;}
                  case 14:  {length = ((ULong_t*)  len_where)[k]; break;}
                  case 15:  {length = ((UInt_t*)   len_where)[k]; break;}
                  case 16:  {length = ((Long64_t*) len_where)[k]; break;}
                  case 17:  {length = ((ULong64_t*)len_where)[k]; break;}
                  case 18:  {length = ((Bool_t*)   len_where)[k]; break;}
                  default: continue;
               }
               b >> isArray;
               if (length <= 0)  continue;
               if (isArray == 0) continue;
               switch (atype) {
                  case  1:  {*where=new char[sizeof(Char_t)*length]; b.ReadFastArray((Char_t*) *where, length); break;}
                  case  2:  {*where=new char[sizeof(Short_t)*length]; b.ReadFastArray((Short_t*) *where, length); break;}
                  case  3:  {*where=new char[sizeof(Int_t)*length]; b.ReadFastArray((Int_t*)   *where, length); break;}
                  case  4:  {*where=new char[sizeof(Long_t)*length]; b.ReadFastArray((Long_t*)  *where, length); break;}
                  case  5:  {*where=new char[sizeof(Float_t)*length]; b.ReadFastArray((Float_t*) *where, length); break;}
                  case  6:  {*where=new char[sizeof(Int_t)*length]; b.ReadFastArray((Int_t*)   *where, length); break;}
                  case  8:  {*where=new char[sizeof(Double_t)*length]; b.ReadFastArray((Double_t*)*where, length); break;}
                  case 11:  {*where=new char[sizeof(UChar_t)*length]; b.ReadFastArray((UChar_t*) *where, length); break;}
                  case 12:  {*where=new char[sizeof(UShort_t)*length]; b.ReadFastArray((UShort_t*)*where, length); break;}
                  case 13:  {*where=new char[sizeof(UInt_t)*length]; b.ReadFastArray((UInt_t*)  *where, length); break;}
                  case 14:  {*where=new char[sizeof(ULong_t)*length]; b.ReadFastArray((ULong_t*) *where, length); break;}
                  case 15:  {*where=new char[sizeof(UInt_t)*length]; b.ReadFastArray((UInt_t*)  *where, length); break;}
                  case 16:  {*where=new char[sizeof(Long64_t)*length]; b.ReadFastArray((Long64_t*)  *where, length); break;}
                  case 17:  {*where=new char[sizeof(ULong64_t)*length]; b.ReadFastArray((ULong64_t*)*where, length); break;}
                  case 18:  {*where=new char[sizeof(Bool_t)*length]; b.ReadFastArray((Bool_t*) *where, length); break;}
               }
            }
            return;
         }
         if (atype > 20) {
            atype -= 20;
            TLeafElement *leaf = (TLeafElement*)fLeaves.UncheckedAt(0);
            n *= leaf->GetLenStatic();
         }
         switch (atype) {
            case  1:  {b.ReadFastArray((Char_t*)  fAddress, n); break;}
            case  2:  {b.ReadFastArray((Short_t*) fAddress, n); break;}
            case  3:  {b.ReadFastArray((Int_t*)   fAddress, n); break;}
            case  4:  {b.ReadFastArray((Long_t*)  fAddress, n); break;}
            case  5:  {b.ReadFastArray((Float_t*) fAddress, n); break;}
            case  6:  {b.ReadFastArray((Int_t*)   fAddress, n); break;}
            case  8:  {b.ReadFastArray((Double_t*)fAddress, n); break;}
            case 11:  {b.ReadFastArray((UChar_t*) fAddress, n); break;}
            case 12:  {b.ReadFastArray((UShort_t*)fAddress, n); break;}
            case 13:  {b.ReadFastArray((UInt_t*)  fAddress, n); break;}
            case 14:  {b.ReadFastArray((ULong_t*) fAddress, n); break;}
            case 15:  {b.ReadFastArray((UInt_t*)  fAddress, n); break;}
            case 16:  {b.ReadFastArray((Long64_t*)fAddress, n); break;}
            case 17:  {b.ReadFastArray((ULong64_t*)fAddress, n); break;}
            case 18:  {b.ReadFastArray((Bool_t*)  fAddress, n); break;}
            case  9:  {
               Double_t *xx = (Double_t*) fAddress;
               Float_t afloat;
               for (Int_t ii=0;ii<n;ii++) {
                  b >> afloat; xx[ii] = Double_t(afloat);
               }
               break;
            }
         }
         return;
      } else if (fType <= 2) {     
         
         if (fStreamerType > 40 && fStreamerType < 55) {
            Int_t atype = fStreamerType - 40;
            Int_t n;
            if (fBranchCount==0) {
               
               TString countname( GetName() );
               Ssiz_t dot = countname.Last('.');
               if (dot>=0) {
                  countname.Remove(dot+1);
               } else {
                  countname = "";
               }
               TString counter( GetTitle() );
               Ssiz_t loc = counter.Last('[');
               if (loc>=0) {
                  counter.Remove(0,loc+1);
               }
               loc = counter.Last(']');
               if (loc>=0) {
                  counter.Remove(loc);
               }
               countname += counter;
               SetBranchCount((TBranchElement *)fTree->GetBranch(countname));
            }
            if (fBranchCount) {
               n = (Int_t)fBranchCount->GetValue(0,0);
            } else {
               Warning("ReadLeaves","Missing fBranchCount for %s.  Data will not be read correctly by the MakeClass mode.",GetName());
               n = 0;
            }
            fNdata = n;
            Char_t isArray;
            b >> isArray;
            switch (atype) {
               case  1:  {b.ReadFastArray((Char_t*)  fAddress, n); break;}
               case  2:  {b.ReadFastArray((Short_t*) fAddress, n); break;}
               case  3:  {b.ReadFastArray((Int_t*)   fAddress, n); break;}
               case  4:  {b.ReadFastArray((Long_t*)  fAddress, n); break;}
               case  5:  {b.ReadFastArray((Float_t*) fAddress, n); break;}
               case  6:  {b.ReadFastArray((Int_t*)   fAddress, n); break;}
               case  8:  {b.ReadFastArray((Double_t*)fAddress, n); break;}
               case 11:  {b.ReadFastArray((UChar_t*) fAddress, n); break;}
               case 12:  {b.ReadFastArray((UShort_t*)fAddress, n); break;}
               case 13:  {b.ReadFastArray((UInt_t*)  fAddress, n); break;}
               case 14:  {b.ReadFastArray((ULong_t*) fAddress, n); break;}
               case 15:  {b.ReadFastArray((UInt_t*)  fAddress, n); break;}
               case 16:  {b.ReadFastArray((Long64_t*) fAddress, n); break;}
               case 17:  {b.ReadFastArray((ULong64_t*)fAddress, n); break;}
               case 18:  {b.ReadFastArray((Bool_t*)   fAddress, n); break;}
               case  9:  {
                  Double_t *xx = (Double_t*)fAddress;
                  Float_t afloat;
                  for (Int_t ii=0;ii<n;ii++) {
                     b>> afloat; xx[ii] = Double_t(afloat);
                  }
                  break;
               }
            }
         } else {
            fNdata = 1;
            if (fAddress) {
               GetInfo()->ReadBuffer(b, (char**) &fObject, fID);
            } else {
               fNdata = 0;
            }
         }
         return;
      }
   }
   
   
   
   
   
   
   if ((fType <= 2) && TestBit(kBranchObject) && fBranchClass->IsLoaded()) {
      b.MapObject((TObject*) fObject);
   }
   if (fType == 4) {
      
      Int_t n;
      b >> n;
      if ((n < 0) || (n > fMaximum)) {
         if (IsMissingCollection()) {
            n = 0;
            b.SetBufferOffset(b.Length()-sizeof(n));
         } else {
            Error("ReadLeaves", "Incorrect size read for the container in %s\n\tThe size read is %d while the maximum is %d\n\tThe size is reset to 0 for this entry (%d)", GetName(), n, fMaximum, GetReadEntry());
            n = 0;
         }
      }
      fNdata = n;
      if (!fObject) {
         return;
      }
      
      
      
      
      
      
      
      TVirtualCollectionProxy* proxy = GetCollectionProxy();
      TVirtualCollectionProxy::TPushPop helper(proxy, fObject);
      
      void* env = proxy->Allocate(fNdata, true);
      Int_t i, nbranches = fBranches.GetEntriesFast();
      switch (fSTLtype) {
         case TClassEdit::kSet:
         case TClassEdit::kMultiSet:
         case TClassEdit::kMap:
         case TClassEdit::kMultiMap:
            for (i = 0; i < nbranches; ++i) {
               TBranch* branch = (TBranch*) fBranches[i];
               Int_t nb = branch->GetEntry(GetReadEntry(), 1);
               if (nb < 0) {
                  
                  
                  break;
               }
            }
            break;
         default:
            break;
      }
      proxy->Commit(env);
   } else if (fType == 41) {
      
      fNdata = fBranchCount->GetNdata();
      if (!fObject) {
         return;
      }
      TVirtualCollectionProxy::TPushPop helper(GetCollectionProxy(), fObject);
      GetInfo()->ReadBufferSTL(b, GetCollectionProxy(), fNdata, fID, fOffset);
   } else if (fType == 3) {
      
      Int_t n;
      b >> n;
      if ((n < 0) || (n > fMaximum)) {
         if (IsMissingCollection()) {
            n = 0;
            b.SetBufferOffset(b.Length()-sizeof(n));
         } else {
            Error("ReadLeaves", "Incorrect size read for the container in %s\n\tThe size read is %d while the maximum is %d\n\tThe size is reset to 0 for this entry (%d)", GetName(), n, fMaximum, GetReadEntry());
            n = 0;
         }
      }
      fNdata = n;
      TClonesArray* clones = (TClonesArray*) fObject;
      if (!clones) {
         return;
      }
      if (clones->IsZombie()) {
         return;
      }
      clones->Clear();
      clones->ExpandCreateFast(fNdata);
   } else if (fType == 31) {
      
      fNdata = fBranchCount->GetNdata();
      TClonesArray* clones = (TClonesArray*) fObject;
      if (!clones) {
         return;
      }
      if (clones->IsZombie()) {
         return;
      }
      GetInfo()->ReadBufferClones(b, clones, fNdata, fID, fOffset);
   } else if (fType <= 2) {
      
      if (fBranchCount) {
         fNdata = (Int_t) fBranchCount->GetValue(0, 0);
      } else {
         fNdata = 1;
      }
      if (!GetInfo()) {
         return;
      }
      GetInfo()->ReadBuffer(b, (char**) &fObject, fID);
      if (fStreamerType == TVirtualStreamerInfo::kCounter) {
         fNdata = (Int_t) GetValue(0, 0);
      }
   }
}
void TBranchElement::ReleaseObject()
{
   
   
   
   
   
   
   return; 
   if (fID < 0) {
      
      if (fAddress && (*((char**) fAddress) != fObject)) {
         
         
         if (TestBit(kDeleteObject)) {
            Warning("ReleaseObject", "branch: %s, You have overwritten the pointer to an object which I owned!", GetName());
            Warning("ReleaseObject", "This is a memory leak.  Please use SetAddress() to change the pointer instead.");
            ResetBit(kDeleteObject);
         }
      }
   }
   
   if (fObject && TestBit(kDeleteObject)) {
      ResetBit(kDeleteObject);
      if (fType == 3) {
         
         TClonesArray::Class()->Destructor(fObject);
         fObject = 0;
         if ((fStreamerType == TVirtualStreamerInfo::kObjectp) ||
             (fStreamerType == TVirtualStreamerInfo::kObjectP)) {
            
            
            *((char**) fAddress) = 0;
         }
      } else if (fType == 4) {
         
         TVirtualCollectionProxy* proxy = GetCollectionProxy();
         if (!proxy) {
            Warning("ResetAddress", "Cannot delete allocated STL container because I do not have a proxy!  branch: %s", GetName());
            fObject = 0;
         } else {
            proxy->Destructor(fObject);
            fObject = 0;
         }
         if (fStreamerType == TVirtualStreamerInfo::kSTLp) {
            
            
            *((char**) fAddress) = 0;
         }
      } else {
         
         TClass* cl = fBranchClass.GetClass();
         if (!cl) {
            Warning("ResetAddress", "Cannot delete allocated object because I cannot instantiate a TClass object for its class!  branch: '%s' class: '%s'", GetName(), fBranchClass.GetClassName());
            fObject = 0;
         } else {
            cl->Destructor(fObject);
            fObject = 0;
         }
      }
   }
}
void TBranchElement::Reset(Option_t* option)
{
   
   
   
   
   
   
   
   
   
   
   
   
   Int_t nbranches = fBranches.GetEntriesFast();
   for (Int_t i = 0; i < nbranches; ++i) {
      TBranch* branch = (TBranch*) fBranches[i];
      branch->Reset(option);
   }
   TBranch::Reset(option);
}
void TBranchElement::ResetAddress()
{
   
   
   ValidateAddress();
   for (Int_t i = 0; i < fNleaves; ++i) {
      TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(i);
      leaf->SetAddress(0);
   }
   
   
   
   Int_t nbranches = fBranches.GetEntriesFast();
   for (Int_t i = 0; i < nbranches; ++i)  {
      TBranch* br = (TBranch*) fBranches[i];
      br->ResetAddress();
   }
   
   
   
   ReleaseObject();
   fAddress = 0;
   fObject = 0;
}
void TBranchElement::ResetDeleteObject()
{
   
   ResetBit(kDeleteObject);
   Int_t nb = fBranches.GetEntriesFast();
   for (Int_t i = 0; i < nb; ++i)  {
      TBranch* br = (TBranch*) fBranches[i];
      
      
      if (br->InheritsFrom("TBranchElement")) {
         ((TBranchElement*) br)->ResetDeleteObject();
      }
   }
}
void TBranchElement::SetAddress(void* add)
{
   
   
   
   
   
   if (TestBit(kDoNotProcess)) {
      return;
   }
   
   
   
   if (fType < 0) {
      return;
   }
   
   
   
   if (Long_t(add) == -1) {
      
      fAddress = (char*) -1;
      fObject = (char*) -1;
      ResetBit(kDeleteObject);
      return;
   }
   
   
   
   fReadEntry = -1;
   
   
   
   TClass* clOfBranch = fBranchClass.GetClass();
   
   
   
   GetInfo();
   
   
   
   
   ReleaseObject();
   
   
   
   fAddress = (char*) add;
   fObject = 0;
   ResetBit(kDeleteObject);
   
   
   
   
   if (fTree->GetMakeClass()) {
      if (fID > -1) {
         
         if (!GetInfo()) {
            
            
            fObject = fAddress;
         } else {
            
            
            fObject = fAddress - GetInfo()->GetOffsets()[fID];
         }
         return;
      }
   }
   
   
   
   
   
   if (fType == 3) {
      
      TClass* clm = TClass::GetClass(fClonesName.Data());
      if (clm) {
         
         clm->BuildRealData();
         clm->GetStreamerInfo();
      }
      TClass* newType = GetCurrentClass();
      if (newType && (newType != TClonesArray::Class())) {
         
         
         
         Bool_t matched = kFALSE;
         if (newType->GetCollectionProxy()) {
            TClass *content = newType->GetCollectionProxy()->GetValueClass();
            if (clm == content) {
               matched = kTRUE;
            } else {
               Warning("SetAddress", "The type of %s was changed from TClonesArray to %s but the content do not match (was %s)!", GetName(), newType->GetName(), fClonesName.Data());
            }
         } else {
            Warning("SetAddress", "The type of the %s was changed from TClonesArray to %s but we do not have a TVirtualCollectionProxy for that container type!", GetName(), newType->GetName());
         }
         if (matched) {
            
            SetType(4);
            SwitchContainer(GetListOfBranches());
            
            fSTLtype = TMath::Abs(TClassEdit::IsSTLCont(newType->GetName()));
            fCollProxy = newType->GetCollectionProxy()->Generate();
         } else {
            
            fAddress = 0;
         }
      }
   } else if (fType == 4) {
      
      TClass* newType = GetCurrentClass();
      if (newType && (newType != GetCollectionProxy()->GetCollectionClass())) {
         
         TVirtualCollectionProxy* newProxy = newType->GetCollectionProxy();
         TVirtualCollectionProxy* oldProxy = GetCollectionProxy();
         if (newProxy && (oldProxy->GetValueClass() == newProxy->GetValueClass()) && ((!oldProxy->GetValueClass() && (oldProxy->GetType() == newProxy->GetType())) || (oldProxy->GetValueClass() && (oldProxy->HasPointers() == newProxy->HasPointers())))) {
            if (fSTLtype == TClassEdit::kNotSTL) {
               fSTLtype = TMath::Abs(TClassEdit::IsSTLCont(newType->GetName()));
            }
            fCollProxy = newType->GetCollectionProxy()->Generate();
         } else {
            
            
            
            
            if ((newType == TClonesArray::Class()) && (oldProxy->GetValueClass() && !oldProxy->HasPointers() && oldProxy->GetValueClass()->InheritsFrom(TObject::Class()))) {
               
               
               
               
               SetType(3);
               SwitchContainer(GetListOfBranches());
               
               fSTLtype = kNone;
               switch(fStreamerType) {
                  case TVirtualStreamerInfo::kAny:
                  case TVirtualStreamerInfo::kSTL:
                     fStreamerType = TVirtualStreamerInfo::kObject;
                     break;
                  case TVirtualStreamerInfo::kAnyp:
                  case TVirtualStreamerInfo::kSTLp:
                     fStreamerType = TVirtualStreamerInfo::kObjectp;
                     break;
                  case TVirtualStreamerInfo::kAnyP:
                     fStreamerType = TVirtualStreamerInfo::kObjectP;
                     break;
               }
               fClonesName = oldProxy->GetValueClass()->GetName();
               delete fCollProxy;
               fCollProxy = 0;
               TClass* clm = TClass::GetClass(fClonesName);
               if (clm) {
                  clm->BuildRealData(); 
                  clm->GetStreamerInfo();
               }
            } else {
               
               fAddress = 0;
            }
         }
      }
   }
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   if (fType == 3) {
      
      if (fAddress) {
         
         if (fStreamerType == TVirtualStreamerInfo::kObject) {
            
            
            fObject = fAddress;
            
            TClonesArray* clones = (TClonesArray*) fObject;
            if (!clones->GetClass()) {
               new(fObject) TClonesArray(fClonesName.Data());
            }
         } else {
            
            
            if ((fStreamerType != -1) &&
                (fStreamerType != TVirtualStreamerInfo::kObjectp) &&
                (fStreamerType != TVirtualStreamerInfo::kObjectP)) {
               Error("SetAddress", "TClonesArray with fStreamerType: %d", fStreamerType);
            } else if (fStreamerType == -1) {
               
               TClonesArray** pp = (TClonesArray**) fAddress;
               if (!*pp) {
                  SetBit(kDeleteObject);
                  *pp = new TClonesArray(fClonesName.Data());
               }
               fObject = (char*) *pp;
            } else {
               
               
               
               TClonesArray** pp = (TClonesArray**) fAddress;
               if (!*pp) {
                  SetBit(kDeleteObject);
                  *pp = new TClonesArray(fClonesName.Data());
               }
               fObject = (char*) *pp;
            }
         }
      } else {
         
         if (fStreamerType == TVirtualStreamerInfo::kObject) {
            
            
            Error("SetAddress", "Embedded TClonesArray given a zero address for branch '%s'", GetName());
         } else {
            
            
            if ((fStreamerType != -1) &&
                (fStreamerType != TVirtualStreamerInfo::kObjectp) &&
                (fStreamerType != TVirtualStreamerInfo::kObjectP)) {
               Error("SetAddress", "TClonesArray with fStreamerType: %d", fStreamerType);
            } else if (fStreamerType == -1) {
               
               
               SetBit(kDeleteObject);
               fObject = (char*) new TClonesArray(fClonesName.Data());
               fAddress = (char*) &fObject;
            } else {
               
               Error("SetAddress", "Embedded pointer to a TClonesArray given a zero address for branch '%s'", GetName());
            }
         }
      }
   } else if (fType == 4) {
      
      
      
      TVirtualCollectionProxy* proxy = GetCollectionProxy();
      if (fAddress) {
         
         if ((fStreamerType == TVirtualStreamerInfo::kObject) ||
             (fStreamerType == TVirtualStreamerInfo::kAny) ||
             (fStreamerType == TVirtualStreamerInfo::kSTL)) {
            
            
            fObject = fAddress;
         } else {
            
            
            if ((fStreamerType != -1) && (fStreamerType != TVirtualStreamerInfo::kSTLp)) {
               Error("SetAddress", "STL container with fStreamerType: %d", fStreamerType);
            } else if (fStreamerType == -1) {
               
               void** pp = (void**) fAddress;
               if (!*pp) {
                  SetBit(kDeleteObject);
                  *pp = proxy->New();
                  if (!(*pp)) {
                     Error("SetAddress", "Failed to allocate STL container for branch '%s'", GetName());
                     
                     
                     
                     fAddress = 0;
                  }
               }
               fObject = (char*) *pp;
            } else {
               
               
               
               void** pp = (void**) fAddress;
               if (!*pp) {
                  SetBit(kDeleteObject);
                  *pp = proxy->New();
                  if (!(*pp)) {
                     Error("SetAddress", "Failed to allocate STL container for branch '%s'", GetName());
                     
                     
                     
                     fAddress = 0;
                  }
               }
               fObject = (char*) *pp;
            }
         }
      } else {
         
         if ((fStreamerType == TVirtualStreamerInfo::kObject) ||
             (fStreamerType == TVirtualStreamerInfo::kAny) ||
             (fStreamerType == TVirtualStreamerInfo::kSTL)) {
            
            
            Error("SetAddress", "Embedded STL container given a zero address for branch '%s'", GetName());
         } else {
            
            
            if ((fStreamerType != -1) && (fStreamerType != TVirtualStreamerInfo::kSTLp)) {
               Error("SetAddress", "STL container with fStreamerType: %d", fStreamerType);
            } else if (fStreamerType == -1) {
               
               SetBit(kDeleteObject);
               fObject = (char*) proxy->New();
               if (fObject) {
                  fAddress = (char*) &fObject;
               } else {
                  Error("SetAddress", "Failed to allocate STL container for branch '%s'", GetName());
                  
                  
                  
                  fAddress = 0;
               }
            } else {
               
               Error("SetAddress", "Embedded pointer to an STL container given a zero address for branch '%s'", GetName());
            }
         }
      }
   } else if (fType == 41) {
      
      
      GetCollectionProxy();
      
      fObject = fAddress;
   } else if (fID < 0) {
      
      char** pp = (char**) fAddress;
      if (pp && *pp) {
         
         fObject = *pp;
      } else {
         
         if (clOfBranch) {
            SetBit(kDeleteObject);
            
            
            
            
            
            
            
            
            fObject = (char*) clOfBranch->New();
            if (pp) {
               *pp = fObject;
            } else {
               fAddress = (char*) &fObject;
            }
         } else {
            Error("SetAddress", "I have no TClass for branch %s, so I cannot allocate an I/O buffer!", GetName());
            if (pp) {
               fObject = 0;
               *pp = 0;
            }
         }
      }
   } else {
      
      fObject = fAddress;
   }
   if (!GetInfo()) {
      
      return;
   }
   
   
   if (!fInitOffsets) {
      InitializeOffsets();
   }
   
   
   
   Int_t nbranches = fBranches.GetEntriesFast();
   for (Int_t i = 0; i < nbranches; ++i) {
      TBranch* abranch = (TBranch*) fBranches[i];
      
      abranch->SetAddress(fObject + fBranchOffset[i]);
   }
}
void TBranchElement::SetBasketSize(Int_t buffsize)
{
   
   TBranch::SetBasketSize(buffsize);
   Int_t nbranches = fBranches.GetEntriesFast();
   for (Int_t i = 0; i < nbranches; ++i) {
      TBranch* branch = (TBranch*) fBranches[i];
      branch->SetBasketSize(fBasketSize);
   }
}
void TBranchElement::SetBranchCount(TBranchElement* brOfCounter)
{
   
   fBranchCount = brOfCounter;
   if (fBranchCount==0) return;
   TLeafElement* leafOfCounter  = (TLeafElement*) brOfCounter->GetListOfLeaves()->At(0);
   TLeafElement* leaf = (TLeafElement*) GetListOfLeaves()->At(0);
   if (leafOfCounter && leaf) {
      leaf->SetLeafCount(leafOfCounter);
   } else {
      if (!leafOfCounter) {
         Warning("SetBranchCount", "Counter branch %s for branch %s has no leaves!", brOfCounter->GetName(), GetName());
      }
      if (!leaf) {
         Warning("SetBranchCount", "Branch %s has no leaves!", GetName());
      }
   }
}
void TBranchElement::SetupAddresses()
{
   
   
   
   
   ValidateAddress();
   if (fAddress || fTree->GetMakeClass()) {
      
      return;
   }
   if (TestBit(kDoNotProcess)) {
      
      return;
   }
   TBranchElement* mother = (TBranchElement*) GetMother();
   TClass* cl = TClass::GetClass(mother->GetClassName());
   
   if (GetInfo() && GetInfo()->GetOffsets()) {
      
      
      
      GetInfo()->BuildOld();
   }
   if (!mother || !cl) {
      return;
   }
   if (!mother->GetAddress()) {
      
      Bool_t motherStatus = mother->TestBit(kDoNotProcess);
      mother->ResetBit(kDoNotProcess);
      
      mother->SetAddress(0);
      mother->SetBit(kDoNotProcess, motherStatus);
   }
}
void TBranchElement::Streamer(TBuffer& R__b)
{
   
   if (R__b.IsReading()) {
      R__b.ReadClassBuffer(TBranchElement::Class(), this);
      fParentClass.SetName(fParentName);
      fBranchClass.SetName(fClassName);
      
      
      ResetBit(kDeleteObject);
      
      if ((fType == 0) && (fLeaves.GetEntriesFast() == 0)) {
         TLeaf* leaf = new TLeafElement(this, GetTitle(), fID, fStreamerType);
         leaf->SetTitle(GetTitle());
         fNleaves = 1;
         fLeaves.Add(leaf);
         fTree->GetListOfLeaves()->Add(leaf);
      }
   } else {
      TDirectory *dirsav = fDirectory;
      fDirectory = 0;  
      
      
      
      
      R__b.WriteClassBuffer(TBranchElement::Class(), this);
      
      
      if (GetInfo()) {
         GetInfo()->ForceWriteInfo((TFile *)R__b.GetParent(), kTRUE);
      }
      
      
      if (!dirsav) {
         return;
      }
      if (!dirsav->IsWritable()) {
         fDirectory = dirsav;
         return;
      }
      TDirectory* pdirectory = fTree->GetDirectory();
      if (!pdirectory) {
         fDirectory = dirsav;
         return;
      }
      const char* treeFileName = pdirectory->GetFile()->GetName();
      TBranch* mother = GetMother();
      const char* motherFileName = treeFileName;
      if (mother && (mother != this)) {
         motherFileName = mother->GetFileName();
      }
      if ((fFileName.Length() > 0) && strcmp(motherFileName, fFileName.Data())) {
         TDirectory::TContext ctxt(dirsav);
         Write();
      }
      fDirectory = dirsav;
   }
}
Int_t TBranchElement::Unroll(const char* name, TClass* clParent, TClass* cl, char* ptr, Int_t basketsize, Int_t splitlevel, Int_t btype)
{
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   TString branchname;
   if ((cl == TObject::Class()) && clParent->CanIgnoreTObjectStreamer()) {
      return 0;
   }
   
   
   
   
   
   
   
   Bool_t optim = TVirtualStreamerInfo::CanOptimize();
   if (splitlevel > 0) {
      TVirtualStreamerInfo::Optimize(kFALSE);
   }
   TStreamerInfo* sinfo = fTree->BuildStreamerInfo(cl);
   TVirtualStreamerInfo::Optimize(optim);
   
   
   
   if (!sinfo) {
      return 0;
   }
   Int_t ndata = sinfo->GetNdata();
   ULong_t* elems = sinfo->GetElems();
   if ((ndata == 1) && cl->GetCollectionProxy() && !strcmp(((TStreamerElement*) elems[0])->GetName(), "This")) {
      
      
      
      return 1;
   }
   for (Int_t elemID = 0; elemID < ndata; ++elemID) {
      
      TStreamerElement* elem = (TStreamerElement*) elems[elemID];
      Int_t offset = elem->GetOffset();
      
      
      if (elem->IsA() == TStreamerBase::Class()) {
         
         TClass* clOfBase = TClass::GetClass(elem->GetName());
         if ((clOfBase->Property() & kIsAbstract) && cl->InheritsFrom("TCollection")) {
            
            
            return -1;
         }
         if ((btype == 31) || (btype == 41)) {
            
            
            
            
            
            
            
            
            
            Int_t unroll = Unroll(name, clParent, clOfBase, ptr + offset, basketsize, splitlevel-1, btype);
            if (unroll < 0) {
               
               if (strlen(name)) {
                  branchname.Form("%s.%s", name, elem->GetFullName());
               } else {
                  branchname.Form("%s", elem->GetFullName());
               }
               TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, 0, basketsize, 0, btype);
               branch->SetParentClass(clParent);
               fBranches.Add(branch);
            }
         } else if (clOfBase->GetListOfRealData()->GetSize()) {
            
            if (strlen(name)) {
               branchname.Form("%s.%s", name, elem->GetFullName());
               
               
               
               
               
               TBranchElement* branch = new TBranchElement(this, name, sinfo, elemID, ptr + offset, basketsize, splitlevel, btype);
               
               branch->SetName(branchname);
               branch->SetTitle(branchname);
               branch->SetParentClass(clParent);
               fBranches.Add(branch);
            } else {
               branchname.Form("%s", elem->GetFullName());
               TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, splitlevel, btype);
               branch->SetParentClass(clParent);
               fBranches.Add(branch);
            }
         }
      } else {
         
         if (strlen(name)) {
            branchname.Form("%s.%s", name, elem->GetFullName());
         } else {
            branchname.Form("%s", elem->GetFullName());
         }
         if ((splitlevel > 1) && ((elem->IsA() == TStreamerObject::Class()) || (elem->IsA() == TStreamerObjectAny::Class()))) {
            
            
            
            
            
            TClass* elemClass = TClass::GetClass(elem->GetTypeName());
            if (elemClass->Property() & kIsAbstract) {
               return -1;
            }
            if (elem->CannotSplit()) {
               
               TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, 0, btype);
               branch->SetParentClass(clParent);
               fBranches.Add(branch);
            } else if (elemClass->InheritsFrom(TClonesArray::Class())) {
               
               Int_t subSplitlevel = splitlevel-1;
               if (btype == 31 || btype == 41 || elem->CannotSplit()) {
                  
                  subSplitlevel = 0;
               }
               TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, subSplitlevel, btype);
               branch->SetParentClass(clParent);
               fBranches.Add(branch);
            } else {
               
               
               
               
               
               
               
               Int_t unroll = Unroll(branchname, clParent, elemClass, ptr + offset, basketsize, splitlevel-1, btype);
               if (unroll < 0) {
                  
                  TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, 0, btype);
                  branch->SetParentClass(clParent);
                  fBranches.Add(branch);
               }
            }
         } else if ((elem->IsA() == TStreamerSTL::Class()) && !elem->IsaPointer()) {
            
            
            Int_t subSplitlevel = splitlevel - 1;
            if ((btype == 31) || (btype == 41) || elem->CannotSplit()) {
               
               subSplitlevel = 0;
            }
            TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, subSplitlevel, btype);
            branch->SetParentClass(clParent);
            fBranches.Add(branch);
         } else if (((btype != 31) && (btype != 41)) && ptr && ((elem->GetClassPointer() == TClonesArray::Class()) || ((elem->IsA() == TStreamerSTL::Class()) && !elem->CannotSplit()))) {
            
            
            
            
            
            TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, ptr + offset, basketsize, splitlevel-1, btype);
            branch->SetParentClass(clParent);
            fBranches.Add(branch);
         } else {
            
            TBranchElement* branch = new TBranchElement(this, branchname, sinfo, elemID, 0, basketsize, 0, btype);
            branch->SetType(btype);
            branch->SetParentClass(clParent);
            fBranches.Add(branch);
         }
      }
   }
   return 1;
}
void TBranchElement::ValidateAddress() const
{
   
   if (fID < 0) {
      
      if (fAddress && (*((char**) fAddress) != fObject)) {
         
         
         
         
	 
         if (false && TestBit(kDeleteObject)) {
            Warning("ValidateAddress", "branch: %s, You have overwritten the pointer to an object which I owned!", GetName());
            Warning("ValidateAddress", "This is a memory leak.  Please use SetAddress() to change the pointer instead.");
            const_cast<TBranchElement*>(this)->ResetBit(kDeleteObject);
         }
         const_cast<TBranchElement*>(this)->SetAddress(fAddress);
      }
   }
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.