Dear experts,
I have a problem related to the deserialization of a TTree from a coral::Blob container. This I implemented some time ago following the discussion in Serialize and deserialize TTree into coral::Blob. Back then I tested it with a big TTree object and things seemed fine to me, though I cannot remember exactly if I looped through all events or not – something I’m doing now with the implementation of the function in the final code.
So to recap, the coral::Blob object, when retrieved from Oracle, merely fills some space in memory with a byte array which, interpreted as a TMemFile, makes it possible to retrieve the encoded TTree. The function to retrieve looks like this:
bool readBlobAsTTree(const coral::Blob &blob, TTree*& out){
std::string sb = reinterpret_cast<const char*>(blob.startingAddress());
std::vector<unsigned char> bdata = base64_decode(sb);
TMemFile f("buffer", reinterpret_cast<char*>(bdata.data()), static_cast<uLongf>(blob.size()));
TTree* t = (TTree*) f.Get("tree");
TTree* tt = t->CloneTree();
tt->SetDirectory(0);
f.Close();
out = tt;
return true;
}
The line TTree* tt = t->CloneTree();
actually was not in the first implementation following the thread linked above, which is strange because without it, the returned TTree does not make any sense. It contains the correct number of entries (1048576) but the values of the branches change with every iteration, there’s clearly a memory problem. Cloning the tree, gives the correct values per event, however, for selected branches and a number of entries (and different branches per entry, it’s not always the same few branches), it gives me the following errors:
Error in <TBranch::WriteBasketImpl>: basket's WriteBuffer failed.
Error in <TBranch::TBranch::Fill>: Failed to write out basket.
and also
Error in <TTree::Fill>: Failed filling branch:tree.vmm, nbytes=-1, entry=1045642
This error is symptomatic of a Tree created as a memory-resident Tree
Instead of doing:
TTree *T = new TTree(...)
TFile *f = new TFile(...)
you should do:
TFile *f = new TFile(...)
TTree *T = new TTree(...)
Reading the TTree with pyROOT does not give me the errors and all seems to work fine.
Now sharing the code is a bit difficult since this is part of a whole framework. Hence I would like to ask if there’s something obvious which I’m doing wrong and which you can spot already from the function itself? If not, I’ll try to figure out how I can make the code accessible to you.
Thank you very much and regards,
heico