I’m trying to save a std::vector in a root file, and it looks like it is well saved (I don’t get any error), but I don’t know how to read it again.
I copy some code reproducing the error:
TFile fout;
fout.Open("TEST.root","RECREATE");
std::vector<Double_t> xx; // I create and fill the vector to be saved.
for( int k = 0; k <3; k++ ) xx.push_back(k);
fout.WriteObject(&xx,"xx"); // I store the vector in the TFile
fout.Close();
TFile fin;
fin.Open("TEST.root","READ");
std::vector<Double_t> *yy;
fin.GetObject("xx",yy); // I try to retrieve the vector
And this is the error I get:
Error in TFile::ReadBuffer: error reading all requested bytes from file TEST.root, got 214 of 300
Error in TFile::Init: TEST.root failed to read the file type data.
TFile *fout = TFile::Open("TEST.root", "RECREATE");
std::vector<Double_t> xx; // I create and fill the vector to be saved.
for (int k = 0; k<3; k++) xx.push_back(k);
fout->WriteObject(&xx, "xx"); // I store the vector in the TFile
fout->Close();
TFile *fin = TFile::Open("TEST.root", "READ");
std::vector<Double_t> *yy;
fin->GetObject("xx", yy); // I try to retrieve the vector
for(std::vector<Double_t>::iterator it = yy->begin(); it != yy->end(); ++it) {
std::cout << *it << '\n';
}