User class branch with Uint_t member as the size of another array member

The problem is already solved, just want to post it here for others.

I created my user class to hold the event data. A very basic one with only two members. One is UInt_t variable, the other is an array with the size determined by the first (Uint_t) variable. Everything compiles and links without any error. The tree is filled and written to the file without error. But when accessing the array variable - seg fault.

So what I found out is that if one branch is used as the size for another one, which is a variable length array, it must be int (Int_t)!!! Actually if you try to make it of type long, you will get an error message during the dictionary generation and the branch will simply not be created. But for some reason for type unsigned integer the error is not generated and you have a frustrating seg fault, when trying to read the branch back.

This behaviour is easily reproducible with the tree2a.C example. Just change the nmec member type to UInt_t, and you will get a running program, but trying to access lmec and namec branches from the file will cause seg fault. If you change nmec to be long int, an error will be issued and the branch will not be created.

My ROOT version is 6.05/02

Hi,

Thanks for the very complete report, including the solution to your problem.
Root supports integers as array size presently as you correctly point out: for sizes not representable by an int, std::vector is the solution.
The absence of warning during dictionary generation when the size is an unsigned integer can be improved: I’ll keep this thread posted about the progress.

Cheers,
Danilo

Hi Danilo,

thanks for your prompt reply.
I realise that non int array size should be a very special case. In my case there was no special reason to make it unsigned. But I spent quite some time on debugging the error and did not see anything in any root documentation about this restriction. Not to mention the absence of warning. Hope if warning is introduced it could occasionally save someone’s time.

Cheers
Alex