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

**URL:** <https://root-forum.cern.ch/t/automatic-schema-evolution-and-moving-a-member-from-a-base-class-to-a-derived-class/51004>\
**Category:** ROOT\
**Tags:** io\
**Created:** [July 29, 2022, 5:18am UTC](https://root-forum.cern.ch/t/automatic-schema-evolution-and-moving-a-member-from-a-base-class-to-a-derived-class/51004 "2022-07-29T05:18:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_cozzyd](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/_cozzyd/32/30440_2.png) [@\_cozzyd](https://root-forum.cern.ch/u/_cozzyd)\
**Post date:** [July 29, 2022, 5:18am UTC](https://root-forum.cern.ch/t/automatic-schema-evolution-and-moving-a-member-from-a-base-class-to-a-derived-class/51004/1 "2022-07-29T05:18:56Z")

</div>

_ROOT Version:_ 6.26/04  
_Platform:_ Fedora 35  
_Compiler:_ gcc 11.3

* * *

At one point, we were producing something like:

```auto
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:

```auto
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, rendering`IFoo` useless.

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

```auto
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:

```auto
#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?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 29, 2022, 7:07am UTC](https://root-forum.cern.ch/t/automatic-schema-evolution-and-moving-a-member-from-a-base-class-to-a-derived-class/51004/2 "2022-07-29T07:07:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [August 11, 2022, 5:11pm UTC](https://root-forum.cern.ch/t/automatic-schema-evolution-and-moving-a-member-from-a-base-class-to-a-derived-class/51004/3 "2022-08-11T17:11:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [August 25, 2022, 5:12pm UTC](https://root-forum.cern.ch/t/automatic-schema-evolution-and-moving-a-member-from-a-base-class-to-a-derived-class/51004/4 "2022-08-25T17:12:49Z")

</div>

Closed on August 25, 2022, 5:12pm UTC

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