You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TClass / TDataMember do not carry enough information for bit-field members: The offset is the rounded-down byte offset, while the type is the underlying one. This leads to wrong behavior during I/O, so we should at least warn the user.
Reproducer
#include<TMemFile.h>
#include<TTree.h>
#include<ROOT/RNTupleModel.hxx>
#include<ROOT/RNTupleReader.hxx>
#include<ROOT/RNTupleWriter.hxx>using ROOT::Experimental::RNTupleModel;
using ROOT::Experimental::RNTupleReader;
using ROOT::Experimental::RNTupleWriter;
#include<iostream>structBitField {
int a : 16;
int b : 16;
int c; //!voidPrint() const {
std::cout << "a = " << a << ", b = " << b << ", c = " << std::hex << c << "\n";
}
};
voidtest_BitField() {
TMemFile f("mem.root", "RECREATE");
{
std::cout << "Writing:\n";
BitField obj{1, 2, 0x44444444};
obj.Print();
f.WriteObject(&obj, "obj");
TTree tree;
tree.Branch("obj", &obj);
tree.Fill();
f.WriteObject(&tree, "tree");
auto model = RNTupleModel::Create();
auto objPtr = model->MakeField<BitField>("obj");
auto writer = RNTupleWriter::Append(std::move(model), "ntpl", f);
*objPtr = obj;
writer->Fill();
}
std::cout << "\n";
{
std::cout << "Reading:\n";
BitField *objPtr = new BitField{0, 0, 0x55555555};
objPtr->Print();
std::cout << "(TDirectory::GetObject reallocates without freeing...)\n";
f.GetObject("obj", objPtr);
objPtr->Print();
delete objPtr;
std::cout << "\n";
TTree *treePtr = nullptr;
f.GetObject("tree", treePtr);
objPtr = new BitField{0, 0, 0x55555555};
objPtr->Print();
treePtr->SetBranchAddress("obj", &objPtr);
treePtr->GetEntry(0);
objPtr->Print();
delete objPtr;
delete treePtr;
std::cout << "\n";
std::unique_ptr<ROOT::RNTuple> ntpl(f.Get<ROOT::RNTuple>("ntpl"));
auto reader = RNTupleReader::Open(*ntpl);
objPtr = reader->GetModel().GetDefaultEntry().GetPtr<BitField>("obj").get();
*objPtr = BitField{0, 0, 0x55555555};
objPtr->Print();
reader->LoadEntry(0);
objPtr->Print();
}
}
Output:
Writing:
a = 1, b = 2, c = 44444444
Reading:
a = 0, b = 0, c = 55555555
(TDirectory::GetObject reallocates without freeing...)
a = 1, b = 2, c = 4444
a = 0, b = 0, c = 55555555
a = 1, b = 2, c = 55554444
a = 0, b = 0, c = 55555555
a = 1, b = 2, c = 55554444
The text was updated successfully, but these errors were encountered:
Description
TClass
/TDataMember
do not carry enough information for bit-field members: The offset is the rounded-down byte offset, while the type is the underlying one. This leads to wrong behavior during I/O, so we should at least warn the user.Reproducer
Output:
The text was updated successfully, but these errors were encountered: