35 ClassImp(TBranchObject);
40 TBranchObject::TBranchObject()
50 TBranchObject::TBranchObject(TTree *tree,
const char* name,
const char* classname,
void* addobj, Int_t basketsize, Int_t splitlevel, Int_t compress, Bool_t isptrptr )
53 Init(tree,0,name,classname,addobj,basketsize,splitlevel,compress,isptrptr);
59 TBranchObject::TBranchObject(TBranch *parent,
const char* name,
const char* classname,
void* addobj, Int_t basketsize, Int_t splitlevel, Int_t compress, Bool_t isptrptr )
62 Init(0,parent,name,classname,addobj,basketsize,splitlevel,compress,isptrptr);
68 void TBranchObject::Init(TTree *tree, TBranch *parent,
const char* name,
const char* classname,
void* addobj, Int_t basketsize, Int_t , Int_t compress, Bool_t isptrptr)
70 if (tree==0 && parent!=0) tree = parent->GetTree();
72 fMother = parent ? parent->GetMother() :
this;
75 TClass* cl = TClass::GetClass(classname);
78 Error(
"TBranchObject",
"Cannot find class:%s", classname);
83 fOldObject = (TObject*)addobj;
89 char** apointer = (
char**) addobj;
90 TObject* obj = (TObject*) (*apointer);
92 Bool_t delobj = kFALSE;
94 obj = (TObject*) cl->New();
98 tree->BuildStreamerInfo(cl, obj);
107 fCompress = compress;
108 if ((compress == -1) && tree->GetDirectory()) {
109 TFile* bfile = tree->GetDirectory()->GetFile();
111 fCompress = bfile->GetCompressionSettings();
114 if (basketsize < 100) {
117 fBasketSize = basketsize;
118 fAddress = (
char*) addobj;
119 fClassName = classname;
120 fBasketBytes =
new Int_t[fMaxBaskets];
121 fBasketEntry =
new Long64_t[fMaxBaskets];
122 fBasketSeek =
new Long64_t[fMaxBaskets];
124 for (Int_t i = 0; i < fMaxBaskets; ++i) {
130 TLeaf* leaf =
new TLeafObject(
this, name, classname);
131 leaf->SetAddress(addobj);
134 tree->GetListOfLeaves()->Add(leaf);
140 if (isptrptr) SetAutoDelete(kTRUE);
142 fDirectory = fTree->GetDirectory();
150 TBranchObject::~TBranchObject()
158 void TBranchObject::Browse(TBrowser* b)
160 Int_t nbranches = fBranches.GetEntriesFast();
164 if (GetBrowsables() && GetBrowsables()->GetSize()) {
165 GetBrowsables()->Browse(b);
172 Int_t TBranchObject::FillImpl(ROOT::Internal::TBranchIMTHelper *imtHelper)
175 Int_t nbranches = fBranches.GetEntriesFast();
179 for (Int_t i = 0; i < nbranches; ++i) {
180 TBranch* branch = (TBranch*) fBranches[i];
181 if (!branch->TestBit(kDoNotProcess)) {
182 Int_t bc = branch->FillImpl(imtHelper);
187 if (!TestBit(kDoNotProcess)) {
188 Int_t bc = TBranch::FillImpl(imtHelper);
206 Int_t TBranchObject::GetEntry(Long64_t entry, Int_t getall)
208 if (TestBit(kDoNotProcess) && !getall) {
212 Int_t nbranches = fBranches.GetEntriesFast();
220 for (Int_t i = 0; i < nbranches; ++i) {
221 TBranch* branch = (TBranch*) fBranches[i];
223 nb = branch->GetEntry(entry, getall);
231 nbytes = TBranch::GetEntry(entry, getall);
242 Int_t TBranchObject::GetExpectedType(TClass *&expectedClass,EDataType &expectedType)
245 expectedType = kOther_t;
246 TLeafObject* lobj = (TLeafObject*) GetListOfLeaves()->At(0);
248 Error(
"GetExpectedType",
"Did not find any leaves in %s",GetName());
251 expectedClass = lobj->GetClass();
258 Bool_t TBranchObject::IsFolder()
const
260 Int_t nbranches = fBranches.GetEntriesFast();
262 if (nbranches >= 1) {
266 TList* browsables =
const_cast<TBranchObject*
>(
this)->GetBrowsables();
268 return browsables && browsables->GetSize();
274 void TBranchObject::Print(Option_t* option)
const
276 Int_t nbranches = fBranches.GetEntriesFast();
278 Printf(
"*Branch :%-9s : %-54s *", GetName(), GetTitle());
279 Printf(
"*Entries : %8d : BranchObject (see below) *", Int_t(fEntries));
280 Printf(
"*............................................................................*");
281 for (Int_t i = 0; i < nbranches; ++i) {
282 TBranch* branch = (TBranch*) fBranches.At(i);
284 branch->Print(option);
288 TBranch::Print(option);
298 void TBranchObject::Reset(Option_t* option)
300 TBranch::Reset(option);
302 Int_t nbranches = fBranches.GetEntriesFast();
303 for (Int_t i = 0; i < nbranches; ++i) {
304 TBranch* branch = (TBranch*) fBranches[i];
305 branch->Reset(option);
311 void TBranchObject::ResetAfterMerge(TFileMergeInfo *info)
313 TBranch::ResetAfterMerge(info);
315 Int_t nbranches = fBranches.GetEntriesFast();
316 for (Int_t i = 0; i < nbranches; ++i) {
317 TBranch* branch = (TBranch*) fBranches[i];
318 branch->ResetAfterMerge(info);
325 void TBranchObject::SetAddress(
void* add)
327 if (TestBit(kDoNotProcess)) {
332 if (Long_t(add) == -1) {
338 Int_t nbranches = fBranches.GetEntriesFast();
340 TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(0);
342 leaf->SetAddress(add);
345 fAddress = (
char*) add;
346 char** ppointer = (
char**) add;
353 TClass* cl = TClass::GetClass(fClassName.Data());
356 for (Int_t i = 0; i < nbranches; ++i) {
357 TBranch* br = (TBranch*) fBranches[i];
363 if (ppointer && !obj) {
364 obj = (
char*) cl->New();
368 if (!cl->GetListOfRealData()) {
369 cl->BuildRealData(obj);
372 if (cl->InheritsFrom(TClonesArray::Class())) {
374 TClonesArray* clones = (TClonesArray*) *ppointer;
376 Error(
"SetAddress",
"Pointer to TClonesArray is null");
379 TClass* clm = clones->GetClass();
381 clm->BuildRealData();
382 clm->GetStreamerInfo();
393 char* fullname =
new char[200];
395 const char* bname = GetName();
398 if (bname[strlen(bname)-1] ==
'.') {
404 TIter next(cl->GetListOfRealData());
405 while ((rd = (TRealData*) next())) {
406 if (rd->TestBit(TRealData::kTransient))
continue;
408 TDataMember* dm = rd->GetDataMember();
409 if (!dm || !dm->IsPersistent()) {
412 const char* rdname = rd->GetName();
413 TDataType* dtype = dm->GetDataType();
416 code = dm->GetDataType()->GetType();
418 Int_t offset = rd->GetThisOffset();
420 pointer = obj + offset;
423 if (dm->IsaPointer()) {
425 if (!dm->IsBasic()) {
426 clobj = TClass::GetClass(dm->GetTypeName());
428 if (clobj && clobj->InheritsFrom(TClonesArray::Class())) {
430 snprintf(fullname,200,
"%s%s", bname, &rdname[1]);
432 snprintf(fullname,200,
"%s", &rdname[1]);
434 branch = (TBranch*) fBranches.FindObject(fullname);
439 const char* index = dm->GetArrayIndex();
444 snprintf(fullname,200,
"%s%s", bname, &rdname[0]);
446 snprintf(fullname,200,
"%s", &rdname[0]);
453 snprintf(fullname,200,
"%s%s", bname, &rdname[0]);
455 snprintf(fullname,200,
"%s", &rdname[0]);
460 for (cursor = 0, pos = 0; cursor < strlen(fullname); ++cursor) {
461 if (fullname[cursor] !=
'*') {
462 fullname[pos++] = fullname[cursor];
465 fullname[pos] =
'\0';
466 branch = (TBranch*) fBranches.FindObject(fullname);
468 if (!clobj->IsTObject()) {
472 snprintf(fullname,200,
"%s%s", bname, &rdname[1]);
474 snprintf(fullname,200,
"%s", &rdname[1]);
476 branch = (TBranch*) fBranches.FindObject(fullname);
482 snprintf(fullname,200,
"%s%s", bname, &rdname[0]);
484 snprintf(fullname,200,
"%s", &rdname[0]);
486 branch = (TBranch*) fBranches.FindObject(fullname);
490 branch->SetAddress(pointer);
517 void TBranchObject::SetAutoDelete(Bool_t autodel)
519 TBranch::SetAutoDelete(autodel);
521 Int_t nbranches = fBranches.GetEntriesFast();
522 for (Int_t i=0;i<nbranches;i++) {
523 TBranch *branch = (TBranch*)fBranches[i];
524 branch->SetAutoDelete(autodel);
531 void TBranchObject::SetBasketSize(Int_t buffsize)
533 TBranch::SetBasketSize(buffsize);
535 Int_t nbranches = fBranches.GetEntriesFast();
536 for (Int_t i = 0; i < nbranches; ++i) {
537 TBranch* branch = (TBranch*) fBranches[i];
538 branch->SetBasketSize(fBasketSize);
545 void TBranchObject::Streamer(TBuffer& R__b)
547 if (R__b.IsReading()) {
548 R__b.ReadClassBuffer(TBranchObject::Class(),
this);
553 TDirectory* dirsav = fDirectory;
556 R__b.WriteClassBuffer(TBranchObject::Class(),
this);
560 R__b.ForceWriteInfo(TClass::GetClass(fClassName.Data())->GetStreamerInfo(), kTRUE);
567 if (!dirsav->IsWritable()) {
571 TDirectory* pdirectory = fTree->GetDirectory();
576 const char* treeFileName = pdirectory->GetFile()->GetName();
577 TBranch* mother = GetMother();
578 const char* motherFileName = treeFileName;
579 if (mother && (mother !=
this)) {
580 motherFileName = mother->GetFileName();
582 if ((fFileName.Length() > 0) && strcmp(motherFileName, fFileName.Data())) {
583 dirsav->WriteTObject(
this);
594 void TBranchObject::SetupAddresses()
598 if (!TestBit(kWarn)) {
599 TClass* cl = TClass::GetClass(fClassName);
601 TObject** voidobj = (TObject**)
new Long_t[1];
602 *voidobj = (TObject*) cl->New();
605 Warning(
"GetEntry",
"Cannot get class: %s", fClassName.Data());
615 void TBranchObject::UpdateAddress()
617 void** ppointer = (
void**) fAddress;
621 TObject* obj = (TObject*) (*ppointer);
622 if (obj != fOldObject) {
624 SetAddress(fAddress);