Automatic Schema Evolution and moving a member from a Base class to a Derived class

ROOT Version: 6.26/04
Platform: Fedora 35
Compiler: gcc 11.3


At one point, we were producing something like:

class Foo : public TObject
{
   int metadata; 
   int more_metadata; 
   int even_more_metadata; 
   short data[1000]; 
   ClassDef(Foo,1)
}; 

Then, in anticipation of having something similar but with a different datatype, we switched to:

class IFoo : public TObject
{
   int metadata; 
   int more_metadata; 
   int even_more_metadata; 
   ClassDef(IFoo,1);
}


class Foo : public IFoo
{
  short data[1000]; 
  ClassDef(Foo,2); 
}

class FloatyFoo : public IFoo
{ 
  float data[1000]; 
  ClassDef(FloatyFoo,1);
}

and thanks to automatic schema migration, things went relatively fine and we could read new and old data with no problem.

Later, we never actually used FloatyFoo so we decided we should get rid of it, renderingIFoo useless.

But then trying to remove IFoo and go back to the old data format (with an incremented version number) as

class Foo : public TObject
{
   int metadata; 
   int more_metadata; 
   int even_more_metadata; 
   short data[1000]; 
   ClassDef(Foo,3)
};

does not allow reading data written in version 2 properly (the metadata is wrong; reading data from version 1 is fine of course).
I do a bit of reading and think that using #pragma read might help, so I try something like:

#pragma read  \
sourceClass="Foo" \
version="[2]" \
targetClass="Foo"\
source="int metadata; int more_metadata; int even_more_metadata;"\
target="metadata,more_metadata,even_more_metadata"\ 
code="{ metadata=onfile.metadata; more_metadata=onfile.more_metadata; even_more_metadata=onfile.even_more_metadata; }" 

But this segfaults when calling TClass::GetRealData(). Changing the sourceClass to IFoo just doesn’t do anything at all (verified by adding a print statement in the code).

Is it possible to get rid of IFoo in this case, or are we stuck with it? (I suppose maybe there’s a solution with #pragma readraw or a custom Streamer(), but that sounds like a pain…). Or is this supposed to work but somehow is not working in my configuration?

Welcome to the ROOT forum.
I think @pcanal can help you.

I can reproduce the problem and I am looking for solution.

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