Re: Read TTree from file

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Thu, 14 Jan 2010 16:53:44 -0600


Hi Thomas,

This problem is solved by revision 32023 of the trunk.

Note that ReadFile was also creating the 'wrong' branch names in v5.20 but a deficiency in TTree::Scan
was actually leading tree->Scan to nonetheless appear to work correctly.

Cheers,
Philippe.

Thomas Lauf wrote:
> Ok, that's what I feared.
> Its a pity that the way via the in-file branch descriptor is not
> working for arrays. With this method you could create a large variety
> of trees with a simple script just by modifying the input file (very
> handy for testing). Guess I have to go the way you proposed and put
> the flexibility into the macro
>
> Thanks
>
> Rene Brun wrote:
>> TTree::ReadFile is using the names that you specify in the branch
>> descriptor.
>> If you want to have the branch name with a different name, procedd as
>> follows:
>> TTree* Tree = new TTree( "Test", "Test" );
>> int Len;
>> double ar[2];
>> Tree->Branch("Len",&Len,"Len/I");
>> Tree->Branch("Array",ar,"Array[2]/D");
>> Tree->ReadFile( "Array2.txt");
>>
>> in this case you should remove the branch descriptor line from your
>> Array1.txt
>>
>> Rene Brun
>>
>> Thomas Lauf wrote:
>>> 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)
>>> ************************************
>>> * Row * Len * Array[2]. *
>>> ************************************
>>> * 0 * 2 * *
>>> * 1 * 2 * *
>>> * 2 * 2 * *
>>> ************************************
>>> (Long64_t)3
>>>
>>> but only under ROOT 5.25, using 5.20 I get
>>> root [3] Tree->Scan()
>>> ***********************************************
>>> * Row * Instance * Len * Array *
>>> ***********************************************
>>> * 0 * 0 * 2 * 1.1 *
>>> * 0 * 1 * 2 * 2.1 *
>>> * 1 * 0 * 2 * 3.1 *
>>> * 1 * 1 * 2 * 4.1 *
>>> * 2 * 0 * 2 * 5.1 *
>>> * 2 * 1 * 2 * 6.1 *
>>> ***********************************************
>>> (Long64_t)6
>>>
>>>
>>> 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
>>>>>
>>>>
>>>
>>>
>>
>
>
Received on Thu Jan 14 2010 - 23:53:49 CET

This archive was generated by hypermail 2.2.0 : Mon Jan 18 2010 - 17:50:01 CET