Rootcint and static data members

Dear ROOTers,

I’d like to write static data members of a class to a .root file. As far as I can see, rootcint does not create streamers for static data members. Is that correct? How can I convince rootcint to generate them anyway, so that I’m able to write/read the static member variables?

Many thanks,
Oliver

Hi Olivier,

Do you mean that you would like the static data member to be written along side each and every copy/instance of the class? If this the case, you will need to write a custom streamer.

Cheers,
Philippe.

Hi,

just for completeness: the problem with writing static data members is not the writing part - it’s reading the values back in a consistent way. I/O is an object-centric operation; the order is defined by requests, i.e. there is no “natural” order. Static data members are obviously non-object centric. The result you get after a series of I/O operations might not be the value you would expect, because the last object read might not be the last object written.

Anyway - if this is not an issue (e.g. because the static value is the same for each entry of a tree and because you are guaranteed to read an object of the class containing the static value for each entry so it gets updated before you read it out) then you should be fine.

An alternative and much more performant (time and space wise) solution is to hook “user info” to a TTree, see root.cern.ch/root/html/TTree#TTree:GetUserInfo.

Cheers, Axel.