Possible bug: variable size array using UShort_t as index

Dear ROOT experts,

I have the following leaves in my TTree:

const UShort_t nMAX_MCTRACKs = 60000; UShort_t nMCTracks; Int_t MCTrackTID[nMAX_MCTRACKs]; tree->SetBranchAddress("nMCTracks", &nMCTracks, "nMCTracks/s"); tree->SetBranchAddress("MCTrackTID", MCTrackTID, "MCTrackTID[nMCTracks]/I");

The problem is that sometimes I get the following error

(of course with different values of len and max).

I did some debugging and I discovered that in TLeafS, the member fMaximum is declared as Short_t, so in the function TLeafS::FillBasket

[code]void TLeafS::FillBasket(TBuffer &b)
//----------Pack leaf elements in Basket output buffer------
//- ==========================================

Int_t i;
Int_t len = GetLen();
if (fPointer) fValue = *fPointer;
if (IsRange()) {
if (fValue[0] > fMaximum) fMaximum = fValue[0];
if (IsUnsigned()) {
for (i=0;i<len;i++) b << (UShort_t)fValue[i];
} else {
fMaximum is not updated in case the the value of the leaf is greater than 32767 (the maximum value stored in a Short_t).
As a result, all the events which have nMCTracks>32767 will fail to write all the elements in MCTrackTID: they will only write the first N elements, where N is the result of tree->GetLeaf("nMCTracks")->GetMaximum()


Unfortunately you are right and historically TLeafS has used a short for its limit. A work-around is (unfortunately) to use a different data type.