`AssertClass` for `TClonesArray`

I see that TCollection has an AssertClass member function to assert that all objects derive from some specific class. Good!
From looking at the implementation, it iterates over all elements. For the generic case, this is fine!

If I have a TClonesArray, then it should be possible to do this more efficient, right?

I guess, I could do something like

assert(clonesarray.GetClass()->InheritsFrom(expectedclass));

Is this the recommended way?


ROOT Version: master
Platform: any
Compiler: any


This is a good first steps however there are (totally unsupported) weird ways to insert objects of the wrong type into a TClonesArray.

If those weird ways are totally unsupport, then they’re that, right?

So unless I want to support those, my suggested way should be fine?

It depends. What is the purpose of calling this tests?

Purpose: Basically to assert (as in: check for programming error) in a library that a passed in TCloneArray actually has a class derived from some expected one. Especially to later on perform an efficient static_cast.

If it is an assert that is run in debug mode then I would still do the full check. If it is an on-all-the-time check then indeed the simpler check should be enough.