# TTree write problem

**URL:** <https://root-forum.cern.ch/t/ttree-write-problem/14884>\
**Category:** ROOT\
**Created:** [September 7, 2012, 3:58am UTC](https://root-forum.cern.ch/t/ttree-write-problem/14884 "2012-09-07T03:58:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gentor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/c2a13f/32.png) [@gentor](https://root-forum.cern.ch/u/gentor)\
**Post date:** [September 7, 2012, 3:58am UTC](https://root-forum.cern.ch/t/ttree-write-problem/14884/1 "2012-09-07T03:58:24Z")

</div>

Hi,  
I’m developing a multithread application using a TList of TTree  
as shared data container between two different threads;

the first thread adds TTree to TList:

…  
while( … ) {

```
  list->Add(new TTree("T1", "Fazia data event"));
  t1 = (TTree *) list->Last();
  t1->Branch("b", "FzEvent", &ev1, 16000, 2);

  for(int j=0; j<10; j++) {

     ev1->SetRegid(1);
     ev1->SetBlkid(1);
     ev1->SetFeeid(2);
     ev1->SetTelid(2);
     ev1->SetDetid(1);
     ev1->SetGttag(3412);
     ev1->SetDettag(3390);
     ev1->SetTs(t);
     ev1->SetEc(j);
     ev1->SetDtype(n);

     for(int i=0; i<1000; i++)
        ev1->AddData((ULong_t)10 * gRandom->Rndm());

     t1->Fill();

     ev1->Clear();
  }

```

}  
…

while a second thread read TList elements (TTree) and  
invoke the Write() method:

…  
filename \<\< RUNTAG \<\< ‘-’ \<\< t \<\< ‘-’ \<\< STEPTAG \<\< “.root”;  
TFile f(filename.str().c\_str(), “recreate”, “xyz”);  
TTree \*t2;  
UInt\_t nevent = 0;

while( t2 = (TTree \*) list-\>First() ) {

```
  t2->Write();

  nevent = t2->GetEntries();

  cout << "# of events : " << nevent << endl;

  for (Int_t i=0; i<nevent; i++) {

     t2->GetEntry(i);
     cout << "Event Counter for event # " << i << " -> " << ev1->GetEc() << " TTree num: " << ev1->GetDtype() << endl;
  }

  list->Remove(t2);

```

}

f.Close();  
…

(I’m using ROOT 5.32/00)

the ROOT file is wrote correctly but instead of a single TTree "T1"  
I read in the file a lot of TTree objects “T1;1”, “T1;2”, "T1;3"  
and so on… how can I avoid this problem ?

I would like to read a single “T1” TTree from ROOT file…

Thanks in advance,  
Gennaro

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [September 7, 2012, 6:00am UTC](https://root-forum.cern.ch/t/ttree-write-problem/14884/2 "2012-09-07T06:00:56Z")

</div>

[url][Aux;1 aux;2 aux3;](https://root-forum.cern.ch/t/aux-1-aux-2-aux3/13345/1)

---

<div class="post-metadata">

**Author:** ![gentor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/c2a13f/32.png) [@gentor](https://root-forum.cern.ch/u/gentor)\
**Post date:** [September 7, 2012, 8:50am UTC](https://root-forum.cern.ch/t/ttree-write-problem/14884/3 "2012-09-07T08:50:46Z")

</div>

Thanks a lot !

Regards,  
Gennaro
