TTree ReadFile with variable size arrays

I have the same problem as illustrated in this post:

[url]Read tree with variable branch size from file

It was never responded to so I hope to pick up the topic. To paraphrase, the following works:

==== sample.txt ====
Len/I:Array[2]/D
2  1.1  2.1
2  3.1  4.1
2  5.1  6.1

root [0] TTree *tree = new TTree()
root [1] tree->ReadFile("sample.txt")
root [2] t->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

Changing the array size to be variable does not work:

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

root [0] TTree *tree = new TTree()
root [1] tree->ReadFile("sample.txt")
root [2] t->Scan()
***********************************************
*    Row   * Instance *       Len *     Array *
***********************************************
*        0 *        0 *         1 *       1.1 *
*        1 *        0 *         2 *       2.1 *
*        1 *        1 *         2 * 6.95e-310 *
*        2 *        0 *         3 *       4.1 *
*        2 *        1 *         3 * 6.95e-310 *
*        2 *        2 *         3 * 2.24e-314 *
***********************************************
(Long64_t)6

The ultimate goal is for a way to write waveforms to an ascii a format (like “nsamples/I:x[nsamples]:y[nsamples]”) that can be easily sucked up by root. I’ve spent enough time on this that I could have written a ascii->tree parser like everyone else does… but now this is just bothering me! Thanks.

Hi,

Could you see if you can upgrade TTree::ReadStream to do what is missing?

Thanks,
Philippe.

Hi Philippe,

Do you mean to ask if I can take the TTree:ReadStream source code and alter it include the ability to read variable sized arrays? It is a possibility, but the solution to my problem may be to simply write a custom ascii parser. If I do generalize the ReadStream code I will post back.

Hi,

Yes, I am suggesting that you provide us with a patch for TTree:ReadStream so that instead of spending time on a one-time custom ascii parser, you spent it upgrading the code for all users :slight_smile:

Thanks,
Philippe.