TLeaf::GetLeafCounter does not behave as documented

The documentation for TLeaf::GetLeafCounter(Int_t& countval) is incorrect in the case the TLeaf is NOT of an array, but instead a simple type. I would actually prefer if the code works as documented, but instead it returns countval=1 in two cases: if it not an array or if it is a fixed length array of size 1.

The in-line comments state:

// – Return a pointer to the counter of this leaf.
//
// If leaf name has the form var[nelem], where nelem is alphanumeric, then
// If nelem is a leaf name, return countval = 1 and the pointer to
// the leaf named nelem.
// If leaf name has the form var[nelem], where nelem is a digit, then
// return countval = nelem and a null pointer.
// Otherwise return countval=0 and a null pointer.
//

The documentation also ignores the case where the leaf is for a multi-dimensional array, in which case countval goes as the product of the array’s dimensions.

I’m writing up a helper class to check that array dimensions for code prepared by TTree::MakeClass() are appropriate, since this code often then is run on other TTree’s/TChain’s, and GetLeafCounter is being used to differentiate between dynamic arrays, fixed-length arrays, and simple types.

Hi,

I updated the documentation as follow: // -- Return a pointer to the counter of this leaf. // // If leaf name has the form var[nelem], where nelem is alphanumeric, then // If nelem is a leaf name, return countval = 1 and the pointer to // the leaf named nelem. // If leaf name has the form var[nelem], where nelem is a digit, then // return countval = nelem and a null pointer. // If leaf name has the form of a multi dimenantion array (eg var[nelem][nelem2] // where nelem and nelem2 are digits) then // return countval = product of all dimension size and a null pointer. // If leaf name has the form var[... (and do not match the previous 2 // cases) return countval = -1 and null pointer; // Otherwise return countval=1 and a null pointer. //

We can not return 0 in the case of a non array since this is supposed to be the number of values hold by the variable. In addition an array can legally be of size 0.

So in order to know that this is not array you need to check for countval==1 and ‘[’ being one of the charater of the title

Cheers,
Philippe

Thank you for making the change and for the suggestion.