Skip to content

Commit fe07b07

Browse files
committed
CCDB: also read std::array members written by libstdc++ on libc++ builds
The previous commit only handled an std::array stored as the CCDB object itself. When the array is a member of another class, ROOT has already replaced the file's libstdc++ StreamerInfo by the in-memory libc++ one by the time the object is extracted, so there was no _M_elems layout left to register, and ITS/Config/Geometry still read with Error in <TBufferFile::ReadVersion>: Could not find the StreamerInfo with a checksum of 0xac059ce7 for the class "array<bool,15>" leaving o2::its::GeometryTGeo::mLayerToWrapper at -1 for every layer, so getMatrixPath() skipped the wrapper volumes (mIsLayerITS3 read as false, right only by chance). For every array<...> the file describes, compute the checksum of its libstdc++ layout (TStreamerInfo::GetCheckSum's formula, with the member named _M_elems: 0xac059ce7 and 0x81cffd37 for ITS's arrays, 0x9189320d for TRD's array<int,540>) and register that layout under the in-memory member name when the class does not have it yet. Verified on macOS, ROOT 6.40.04-alice: ITS/Config/Geometry at 1550600800000 now reads mLayerToWrapper 0 0 0 1 1 2 2 with no errors; TRD/Calib/DCSDPsFedChamberStatus still reads 521x3 + 19x0. Still only inside #if defined(_LIBCPP_VERSION).
1 parent 1be4895 commit fe07b07

1 file changed

Lines changed: 59 additions & 20 deletions

File tree

‎Framework/Core/src/DataRefUtils.cxx‎

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,69 @@ void* extractFromTFile(TFile& file, TClass const* cl, const char* what)
8484

8585
#if defined(_LIBCPP_VERSION)
8686
// The only member of std::array<T,N> is T _M_elems[N] in libstdc++, T __elems_[N] in libc++, so
87-
// objects written on Linux carry a StreamerInfo with a checksum the libc++ class does not have.
88-
// When opening the file, ROOT drops that StreamerInfo as an alias of the in-memory one
89-
// (TStreamerInfo::BuildCheck), and the read fails with "Could not find the StreamerInfo with a
90-
// checksum", leaving the array zero-filled. Register the on-file layout as a version of its own,
87+
// objects written on Linux refer to a StreamerInfo checksum the libc++ class does not have, and
88+
// the read fails with "Could not find the StreamerInfo with a checksum", leaving the array
89+
// zero-filled (or -1 where the constructor put that). This happens for an std::array stored as
90+
// the object itself (TRD's chamber status) and as a member (ITS GeometryTGeo::mLayerToWrapper).
91+
// For each std::array the file describes, register its libstdc++ layout as a version of its own,
9192
// under the in-memory member name, so that the payload, T[N] for both, is read as usual.
92-
void DataRefUtils::registerLibstdcxxStdArray(TFile& file, TClass const* cl)
93+
namespace
9394
{
94-
auto* infos = std::strncmp(cl->GetName(), "array<", 6) == 0 ? file.GetStreamerInfoCache() : nullptr;
95-
auto* onfile = infos ? dynamic_cast<TStreamerInfo*>(infos->FindObject(cl->GetName())) : nullptr;
96-
if (!onfile || onfile->GetNelement() != 1 || std::strcmp(onfile->GetElement(0)->GetName(), "_M_elems") != 0) {
97-
return;
95+
// TStreamerInfo::GetCheckSum for a class whose only member is "name" of type T[N]
96+
UInt_t stdArrayCheckSum(TClass const* cl, TStreamerElement const* el, char const* name)
97+
{
98+
UInt_t id = 0;
99+
auto add = [&id](char const* s) { for (; *s; ++s) { id = id * 3 + *s; } };
100+
add(cl->GetName());
101+
add(name);
102+
add(el->GetTypeName());
103+
for (int i = 0; i < el->GetArrayDim(); ++i) {
104+
id = id * 3 + el->GetMaxIndex(i);
98105
}
99-
// Exists before BuildCheck, so that the on-file layout gets a version of its own
100-
auto* current = static_cast<TStreamerInfo*>(const_cast<TClass*>(cl)->GetStreamerInfo());
101-
auto* info = static_cast<TStreamerInfo*>(cl->FindStreamerInfo(onfile->GetCheckSum()));
102-
if (!info) {
103-
info = static_cast<TStreamerInfo*>(onfile->Clone());
104-
info->BuildCheck(&file);
106+
return id;
107+
}
108+
} // namespace
109+
110+
void DataRefUtils::registerLibstdcxxStdArray(TFile& file, TClass const* /*cl*/)
111+
{
112+
auto* infos = file.GetStreamerInfoCache();
113+
if (!infos) {
114+
return;
105115
}
106-
// Also when ROOT registered it itself: it then reads nothing, without any error
107-
if (std::strcmp(info->GetElement(0)->GetName(), current->GetElement(0)->GetName()) != 0) {
108-
info->GetElement(0)->SetName(current->GetElement(0)->GetName());
109-
info->Clear("build");
110-
info->BuildOld();
116+
for (auto* obj : *infos) {
117+
auto* onfile = dynamic_cast<TStreamerInfo*>(obj);
118+
if (!onfile || std::strncmp(onfile->GetName(), "array<", 6) != 0 || onfile->GetNelement() != 1) {
119+
continue;
120+
}
121+
auto* cl = TClass::GetClass(onfile->GetName());
122+
if (!cl) {
123+
continue;
124+
}
125+
// Exists before BuildCheck, so that the libstdc++ layout gets a version of its own
126+
auto* current = static_cast<TStreamerInfo*>(cl->GetStreamerInfo());
127+
if (!current || current->GetNelement() != 1) {
128+
continue;
129+
}
130+
// ROOT may already have replaced the file's layout by the in-memory one (members of other
131+
// classes): then rebuild the libstdc++ one, which differs only by the member name.
132+
auto checksum = std::strcmp(onfile->GetElement(0)->GetName(), "_M_elems") == 0 ? onfile->GetCheckSum() : stdArrayCheckSum(cl, current->GetElement(0), "_M_elems");
133+
auto* info = static_cast<TStreamerInfo*>(cl->FindStreamerInfo(checksum));
134+
if (!info) {
135+
info = static_cast<TStreamerInfo*>((std::strcmp(onfile->GetElement(0)->GetName(), "_M_elems") == 0 ? onfile : current)->Clone());
136+
info->GetElement(0)->SetName("_M_elems");
137+
info->SetCheckSum(checksum);
138+
info->BuildCheck(&file);
139+
info = static_cast<TStreamerInfo*>(cl->FindStreamerInfo(checksum));
140+
if (!info) {
141+
continue;
142+
}
143+
}
144+
// Also when ROOT registered it itself: it then reads nothing, without any error
145+
if (std::strcmp(info->GetElement(0)->GetName(), current->GetElement(0)->GetName()) != 0) {
146+
info->GetElement(0)->SetName(current->GetElement(0)->GetName());
147+
info->Clear("build");
148+
info->BuildOld();
149+
}
111150
}
112151
}
113152
#endif

0 commit comments

Comments
 (0)