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.