Disabling streaming of a datamember at runtime

Hi, I was wondering if there is any way to disable the streaming of an object datamember at runtime, assuming that in the header file one has not put the //! comment originally (ie the info exists in the streamer). Thanks,
filimon

As far as I know, the answer is no.

I’m assuming you want to do so to reduce size of file on disk. If that is the case, filling the member data in question with 0 or “” (or whatever is equivalent) will have almost the same effect (Root is very smart about compressing the branches and if they all have the same variable, it almost makes it disappear in terms of size on disk).

Cheers,
Charles

The following should work

TClass::GetClass("myclass")->GetDataMember("membername")->SetBit(TObject::kWriteDelete,0);
Rene

Thanks to both, I guess when one has a pointer data member the most convenient and fast is to make sure that it is 0 (nullptr) otherwise if it is an object, Rene’s solution might be better since it may take time to nullify the object itself. Rene, I assume your solution will do the proper thing when reading back the object from a file regardless of whether the user uses this piece of code on the reading application (my guess is that it will return a default-constructed object in the place of the object that has not actually been saved)?

Hi,

An alternative to do the same as Rene is:Class::GetClass("myclass")->GetDataMember("membername")->SetBit(TDataMember::kObjIsPersistent,0);which indeed does the right thing both on read and write as long as you executed this before any I/O operation has been made.

[quote](my guess is that it will return a default-constructed object in the place of the object that has not actually been saved)?[/quote]The data member will be left untouched by the I/O (i.e. has what ever value the default constructor puts in).

Cheers,
Philippe.

Thanks, the use-case I have in mind is that I switch off some datamember, write a file and then distribute this file along with the library (source or bin) that contains the description of the whole class. The recipient should be able in any case to read back the data without knowing whether I switched off or not some datamember at runtime, using the same ClassDef version of course (same checksum). Indeed the expected behaviour is to get whatever the default ctor puts there.

Cheers,
Philippe.