Streamer trick when renaming member variable

Hello everyone,

Since the name of a member variable in one of our classes breaks the code on some OS’s (non standard compliant name ‘_C’) we would really like to rename this variable. But…the problem with this is that we would have to reproduce a lot of ROOT files (the new streamer would not read this variable any more).

Is there anyone who happens to know a smart trick to get around this? How feasible would it be for example to ‘fix’ the streamer info in the ROOT files, that is, to change the ‘_C’ in the streamer info in the files by ‘_Cfixed’.

Any help would be welcome.

Cheers,
Jeroen

Hi,

You have to use a partially hand coded streamer, we currently do not have (but hope to introduce it someday) an automatic way to do the translation.

Instead you need to follow the instruction in the User’s Guide, chapter 11 (Input/Output) on how to migrate to ROOT 3. In summary you need to
[ul]generate an streamer using the old I/O mechanism
copy/paste into your implementation file
modify it to keep only the read part and adding read/write using the new I/O
[/ul]
Cheers,
Philippe.

Hi Philippe,

Thanks for your reply. I think the problem with the hand-crafted streamer is that it would still contain the offending variable name so it would still not compile.

For completeness: the core of the problem is that the variable name ‘_C’ conflicts with a macro defined in ctype.h.

I was hoping for a magic solution, like updating the streamer info in the ROOT files.

Cheers,
Jeroen

[quote]Thanks for your reply. I think the problem with the hand-crafted streamer is that it would still contain the offending variable name so it would still not compile.[/quote]For the offending variable instead of doing

you would do

type_of_C temp; buf >> temp; _Cfixeed = temp;

[quote]I was hoping for a magic solution, like updating the streamer info in the ROOT files.[/quote]Well you might be able to also do that. The following is untried but might work:

TStreamerInfo *info_to_be_fixed = gROOT->GetClass("MyClass")->GetStreamerInfo(old_version); TStreamerElement *elem = (TStreamerElement*)info_to_be_fixed->GetElements()->FindObject("_C"); elem->SetName("_Cfixed"); info_to_be_fixed->BuildOld();
Cheers,
Philippe.