Re: Read TTree from file

From: Thomas Lauf <thl_at_hll.mpg.de>
Date: Tue, 12 Jan 2010 13:29:19 +0100


Thanks for the quick answer!
I can reproduce your lines also on my machine, no problem here. But a thing that does not work is this:

root [0] TTree* Tree = new TTree( "Test", "Test" );
root [1] Long64_t RetVal = Tree->ReadFile( "Array1.txt" );
root [2] Double_t Array[2];
root [2] Tree->SetBranchAddress( "Array", &Array )
Error in <TTree::SetBranchAddress>: unknown branch -> Array

I can read out the tree branch this way
root [3] Tree->SetBranchAddress( "Array[2]", &Array ) root [4] for( Int_t i=0; i<3; ++i ) {

            Tree->GetEntry(i);
            cout << Array[0] << " " << Array[1] << endl;
          }
1.1 2.1

3.1 4.1
5.1 6.1

Somehow the name of the branch gets handled differently. When the branch descriptor is "Array[2]", it is displayed this way under TTree::Print(), but not under TTree::Show(). TTree::Scan() delivers in my case:

root [5] Tree->Scan()
Error in <TTreeFormula::TTreeFormula>: Index 2 for dimension #1 in Array[2].Array[2].Array is too high (max is 1)


but only under ROOT 5.25, using 5.20 I get root [3] Tree->Scan()


Thomas

Rene Brun wrote:
> I cannot reproduce your problem with any version of ROOT (I tried
> 5.22,5.25 and 5.26).
> The result of your 2 commands = tree.Print gives
>
> root [0] TTree* Tree = new TTree( "Test", "Test" );
> root [1] Long64_t RetVal = Tree->ReadFile( "Array1.txt" );
> root [2] Tree.Print()
> ******************************************************************************
>
> *Tree :Test :
> Test *
> *Entries : 3 : Total = 1621 bytes File Size
> = 0 *
> * : : Tree compression factor =
> 1.00 *
> ******************************************************************************
>
> *Br 0 :Len :
> Len/I *
> *Entries : 3 : Total Size= 634 bytes One basket in
> memory *
> *Baskets : 0 : Basket Size= 32000 bytes Compression=
> 1.00 *
> *............................................................................*
>
> *Br 1 :Array[2] :
> Array[2]/D *
> *Entries : 3 : Total Size= 705 bytes One basket in
> memory *
> *Baskets : 0 : Basket Size= 32000 bytes Compression=
> 1.00 *
> *............................................................................*
>
>
>
> and if you do, eg
> root [3] Tree.Show(0)
> ======> EVENT:0
> Len = 2
> Array = 1.1,
> 2.1
> everything is Ok
>
> Rene Brun
>
> Thomas Lauf wrote:

>> Hello,
>>
>> if I apply this little script
>>
>> {
>>   TTree* Tree = new TTree( "Test", "Test" );
>>   Long64_t RetVal = Tree->ReadFile( "Array1.txt" );
>>   gROOT->ProcessLine("Tree->Print(\"toponly\"); > Array3.dat");
>> }
>>
>> on the file Array1.txt which looks like this
>>
>> Len/I:Array[2]/D
>> 2 1.1 2.1
>> 2 3.1 4.1
>> 2 5.1 6.1
>>
>> I would expect the resulting tree to have 2 branches named 'Len' and 
>> 'Array' of which the second one is an array of doubles with length 2 
>> and the file Array3.dat should look like this:
>>
>> ************************************************************************
>> *Tree    :Test      : Test                                             *
>> *Entries :        3 : Total =            1601 bytes  File  Size =    0 *
>> *        :          : Tree compression factor =   1.00                 *
>> ************************************************************************
>> branch: Len                          0
>> branch: Array                        0
>>
>> The script passes with no errors but the branch containing the array 
>> does not have the expected name, it is named 'Array[2]' as one can see 
>> in the real output:
>>
>> ************************************************************************
>> *Tree    :Test      : Test                                             *
>> *Entries :        3 : Total =            1601 bytes  File  Size =    0 *
>> *        :          : Tree compression factor =   1.00                 *
>> ************************************************************************
>> branch: Len                          0
>> branch: Array[2]                     0
>>
>> What went wrong? How can I get ROOT to name the branch 'Array'?
>> My research in the documentation so far was futile...
>>
>> I am using ROOT 5.20/00 on linux. I have tested this example also under
>> ROOT 5.25/02, but it failed there too.
>>
>> Thanks for any advice
>>
>> Thomas
>>

>
-- 
Dipl.Phys. Thomas Lauf
MPI Halbleiterlabor
Otto-Hahn-Ring 6
81739 Muenchen

Tel. : +49 89 839400 - 59
Fax. : +49 89 839400 - 13
Received on Tue Jan 12 2010 - 13:29:51 CET

This archive was generated by hypermail 2.2.0 : Tue Jan 12 2010 - 17:50:01 CET