Skip to content

Commit

Permalink
remember how to get the memory layout exptected for oldObj->fObject
Browse files Browse the repository at this point in the history
  • Loading branch information
jblomer committed Nov 30, 2024
1 parent 9d85030 commit 7830114
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rules/02_coordinate_transformation/Event_v3_LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#pragma link C++ class Event+;

#pragma read sourceClass = "Event" source = "float fX; float fY" version = "[2]" targetClass = \
"Event" target = "fR" target = "fPhi" code = "{ newObj->SetFromEuclidian(onfile.fX, onfile.fY); }"
"Event" target = "fR" target = "fPhi" include = "iostream" code = "{ std::cout << offset_Onfile_Event_fX << std::endl; newObj->SetFromEuclidian(onfile.fX, onfile.fY); std::cout << oldObj->fClass->GetClassVersion() << std::endl; }"

#endif

53 changes: 53 additions & 0 deletions rules/02_coordinate_transformation/getOnDiskClass.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
void getOnDiskClass()
{
gSystem->Load("./libEvent_v3.so");

auto cl = TClass::GetClass("Event", true, true);
std::cout << " ... TClass class version: " << cl->GetClassVersion() << std::endl;

auto f = TFile::Open("data.root");

// Get the streamer info directly from TClass:
auto versionedInfo = cl->GetStreamerInfo(2);
std::cout << " ... versioned streamer info class version: " << versionedInfo->GetClassVersion() << std::endl;

// The versioned streamer info knows about the old _and_ the new layout
versionedInfo->GetElements()->ls();

// The first element is "Event@@2 @@alloc"
cl = versionedInfo->GetElement(0)->GetClassPointer();
std::cout << " ... old class version: " << cl->GetClassVersion() << std::endl;

// The first element is "Event@@2 @@alloc"
cl = versionedInfo->GetElement(0)->GetClassPointer();
std::cout << " ... old class version: " << cl->GetClassVersion() << std::endl;

// The data member offsets, however, are strange!
// These are the offsets expected for oldObj->fObject in the schema evolution snippet
std::cout << "TClass offset of fX and fY: " << cl->GetDataMemberOffset("fX") << " "
<< cl->GetDataMemberOffset("fY")<< std::endl;

// for (auto si : TRangeDynCast<TStreamerInfo>(*f->GetStreamerInfoList())) {
// if (!si || (std::string(si->GetName()) != "Event"))
// continue;
//
// std::cout << " ... streamer info class version: " << si->GetClassVersion() << std::endl;
//
// auto versionedInfo = cl->GetStreamerInfo(si->GetClassVersion());
// std::cout << " ... versioned streamer info class version: " << versionedInfo->GetClassVersion() << std::endl;
//
// // The versioned streamer info knows about the old _and_ the new layout
// versionedInfo->GetElements()->ls();
//
// // The first element is "Event@@2 @@alloc"
// cl = versionedInfo->GetElement(0)->GetClassPointer();
// std::cout << " ... old class version: " << cl->GetClassVersion() << std::endl;
//
// // The data member offsets, however, are strange!
// // These are the offsets expected for oldObj->fObject in the schema evolution snippet
// std::cout << "TClass offset of fX and fY: " << cl->GetDataMemberOffset("fX") << " "
// << cl->GetDataMemberOffset("fY")<< std::endl;
//
// si->ls();
// }
}
1 change: 1 addition & 0 deletions rules/03_update_private_member/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Can the schema update function somehow be a friend of the target class?

0 comments on commit 7830114

Please sign in to comment.