Saved cut file, hoho.c and "cutg_hello.root"

Hi guys I am trying to save the cut and read it and again create a root file using:

if( DoesFileExist("cutg_hello.root") ) { f_cut = new TFile("cutg_hello.root","RECREATE"); Skip = true; cout << "getting the cut"<< endl;cutg = (TCutG*)f_cut->Get("CUTG"); cout << "got the cut"<< endl; cutg->SaveAs("hoho.c");

and after running my code I cannot find the data inside cutg_hello.root file and a saved hoho.c file thanks in advance.

You “RECREATE” the file, which means that it becomes empty.

Thank you Wile for your reply, I think I posted an old part of the code, this is the right part were I do’nt recreate :slightly_smiling_face:

if (!Skip) {
f_cut = new TFile(“cutg_hello.root”);
cutg = (TCutG*) gPad->WaitPrimitive(“CUTG”, “CUTG”); // making cut, store to CUTG
cout << “\n … finished graphical cut … rereading the ntuple using that g-cut \n”;
cutg->SaveAs(“hoho.c”); // just testing
cout << "Area is … " << cutg->Area() << endl;

And I only get the saved hoho.c file saved when I open the “cutg_hello.root” I get thie following error: Error in TFile::ReadBuffer: error reading all requested bytes from file cutg_hello.root, got 226 of 300

Error in TFile::Init: cutg_hello.root failed to read the file type data.

(TFile *) nullptr

If you open your (existing) file for “READ” then you cannot write to it.

Noted! thanks Wile .