Do I need to update ClassDef if I change the name of a variable


Dear all

I created a class that derived from TObject, and had a unsigned int A stored.

After I change the name A to B, but remain the same type (also I changed some functionalities related to this value, but that’s another story). Do I need to change the number of ClassDef? Because memory structure is not changed I suppose I don’t need to do so?


You need to increment the version number any time the persistent data member change in type or name. As far as the I/O is concerned when you change the name of a variable, it is the same as if you removed a data member and added a completely independent one. In particular if you read an old file the value of B will not be be updated (from what it is set in the default constructor). If you need to be able to read the A on file into the B in memory you need to write an I/O customization rule. For example:

// Assuming you class is named `NameOfTheClass` and its old version number is `2` and that 
// type of the old member A is `old_type_of_A`.
#pragma read sourceClass="NameOfTheClass" targetClass="NameOfTheClass" version="[2]" source="old_type_of_A A" target="B" code="{ B = onfile.A; }"

In the code part you would need to apply any transformation needed for the A value to make sense as a B.

I see. Thank you!