Schema evolution of base class member

Hi,

I have a situation where I want to change the value of the base class member fAddress when an old version of the derived class C is read from file. Class B and C also contain data members I don’t want to touch.

class C: public B {
};

class B: public A {
};

class A: public TObject {
  Int_t fAddress; 
};

I tried to add the pragma read statement

#pragma read sourceClass="C" version="[1]" targetClass="C" \
  source="Int_t fAddress" target="fAddress" \
  code="{ \
         fAddress = onfile.fAddress+100; \
         }"

in the corresponding LinkDef.h file but whatever I tried I always get a a warning that the data member specified as target does not exist.

Is such change of a base class member possible and in case it is what is the correct code to do it.

The target indeed has to be in the target Class proper. You might be able to use:

#pragma read sourceClass="C" version="[1]" targetClass="C" \
  source="Int_t fAddress" target="" \
  code="{ \
         newObj->fAddress = onfile.fAddress+100; \
         }"

If this is not working, you might need to use an arbitrary data member of C as the target and set both that member and fAddress.

Thanks for replying, @pcanal. :slight_smile:

Unfortunately your proposal does not solve the issue completely.

With the proposed change I don’t get the warning any longer.
When accessing the variable in the #pragma read statement it does not have the proper value stored in the file but has the value from the default constructor, which in my case is -1 to indicate problems.

Can you provide a complete running (and failing) test?

I will try to provide some code which demonstrates the problem next week.

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