Question on saving objects

Hello,

I am currently making a class that ROOT can use. I would like it if I could change the member variable for the class to save per object.

I know that the member variable can be chosen not to be saved using //! in the header file or
TClass::GetClass(“myclass”)->GetDataMember(“membername”)->SetBit(TObject::kWriteDelete,0);

But when I save a TClonesArray that holds objects and try to change whether or not a member variables of a object is saved per object, the above will not work. Is there a way to make this possible?

You can write your own “streamer”.
See “ROOT User’s Guide - Chapter 11. Input/Output”. In particular, see sections about “Streamers” (note the subsection “Streaming a TClonesArray”) and “Schema Evolution” therein.

I have already tried writing my own “streamer” but unfortunately it did not work as I expected (I think).

For example, lets say there is a class that has three member variables. (flag, fmember0, fmember1)
Then if the flag is 0 I want to write fmember0, if the flag is 1 then I want to write fmember1.

In the writing part of the streamer class I would do something like,

if(flag){
  b << fmember1
} else {
  b << fmember0
}

But when I checked the file that was saved with TBrowser, indeed the fmembers would have the values depending on the flag. But the other member that was not used in the streamer class would have a default value.
I would like it so that there would be no member(and branch) at all if it was not used to reduce the size of the file. Is this possible?

The other option I am currently using is to make multiple classes depending on what I want to save. But this makes the code to be quite complex.