Saving a pointer in a TObject for a TTree, error with pointer member

ROOT Version: ROOT 6.26/06
Platform: Linux
Compiler: gcc-12.1.0


Background:
I have a TObject which I need to make sortable for TClonesArray with a variable parameters (maybe “ascending via property A,” or “descending via property B”, etc…) As TObject::Compare(const TObject*) and TObject::IsEqual(const TObject) are the functions to overload, and don’t allow for additional parameters, I decided to just add a single pointer (void*) to the object members. Then I can set that to point to a helper class which can be configured by the desired sorting parameters, and called by the overloaded IsEqual and Compare functions.

Problem:
The streamer doesn’t seem to know what to do with the pointer. When the object is read out, I get a message like Error in <TStreamerInfo::Build>: Jetv2, discarding: void* _sort_ptr, no [dimension].

Results:
I don’t particularly mind, in the sense that I only want to use the pointers associated with each TObject when the TClonesArray is already read out from the TTree, and then set the pointer in each object, do the sorting, and maybe put the TClonesArray into another TTree (at which point, I don’t mind if the pointers get lost again – they only matter for the duration of the sorting). However, I appear to be getting intermittent errors, and I am afraid I may sometimes corrupt reading the TObjects…

What should I do?

FWIW – a perhaps hacky way to deal with this is to put a intptr_t member in the TObject, which is basically an integer guaranteed to be big enough to hold a pointer. Therefore, the streamer can “reserve a place in each TObject for a pointer”. It takes up a little memory in each TObject, but it works.

Mark the pointer as transient:

void *Jetv2; ///<! 

The ! part of the comment is read by rootcling and indicates the member is transient.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.