Read tree with variable branch size from file

Hello,

I would like to read a tree from a file. The tree (in this simplified example) consists of a array of doubles. If the array size is fixed there is no problem doing this (TestFixed.C):

{ TTree* Tree = new TTree( "Test", "Test" ); Long64_t RetVal = Tree->ReadFile( "Array1.txt" ); Tree->SetScanField( 0 ); gROOT->ProcessLine("Tree->Scan( \"Len:Array\" ); > Array1.dat"); }

on Array1.txt which has the following content:

Len/I:Array[2]/D
2  1.1  2.1
2  3.1  4.1
2  5.1  6.1

But I would like to read in a tree that contains an array with variable size. Unfortunately the small modification does not work. If I run the upper procedure (TestVariable.C) on Array2.txt:

Len/I:Array[Len]/D
1  1.1
2  2.1  3.1
3  4.1  5.1  6.1

the produced output “Array2.dat” looks like this:

***********************************************
*    Row   * Instance *       Len *     Array *
***********************************************
*        0 *        0 *         1 *       1.1 *
*        1 *        0 *         2 *       2.1 *
*        1 *        1 *         2 * 2.35e-310 *
*        2 *        0 *         3 *       4.1 *
*        2 *        1 *         3 * 2.35e-310 *
*        2 *        2 *         3 *         0 *
***********************************************

Seems if the array is only allocated once and if the length is not known in advance it is set to 1. But on the other hand TTree::ReadFile does not complain about the branch descriptor “Len/I:Array[Len]/D”.

Would it be possible to make this example work?

ps: So far I have tested it on ROOT 5.20 and 5.24. System was linuxx8664
TestVariable.C (226 Bytes)
TestFixed.C (238 Bytes)
Array2.txt (49 Bytes)
Array1.txt (47 Bytes)

1 Like