Hello!
I have this message and can’t save canvas in file.
[attachment=3]Screenshot_1.png[/attachment]
Let’s save .root file (part1)
#include <iostream>
#include "TFile.h"
#include "TObjArray.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TChain.h"
#include "TROOT.h"
using namespace std;
int main(int argc, char *argv[])
{
//save
TFile f_tree("D:\\Data_work\\test_folder\\test_save.root", "RECREATE");
TTree tree("t1", "Parser tree save");
TCanvas canv("c", "c", 0, 0, 1900, 1000);
tree.Branch("canvas_tr", "TCanvas", &canv);
tree.Fill();
tree.Write();
f_tree.Close();
////read
//TObjArray Hlist_gr(0);
//Hlist_gr.SetOwner(kTRUE);
//TCanvas* canv_read = 0;
//TChain chain("t1");
//chain.Add("D:\\Data_work\\test_folder\\test_save.root");
//chain.SetBranchAddress("canvas_tr", &canv_read);
//chain.GetEntry(0);
//Hlist_gr.Add(canv_read->Clone());
//TFile ofile_Hlist_gr("D:\\Data_work\\test_folder\\test_result.root", "RECREATE");
//Hlist_gr.Write();
//ofile_Hlist_gr.Close();
system("pause");
return 0;
}
Let’s read.root file and save canvas in another file (part2)
[code]#include
#include “TFile.h”
#include “TObjArray.h”
#include “TTree.h”
#include “TCanvas.h”
#include “TChain.h”
#include “TROOT.h”
using namespace std;
int main(int argc, char *argv[])
{
////save
//TFile f_tree(“D:\Data_work\test_folder\test_save.root”, “RECREATE”);
//TTree tree(“t1”, “Parser tree save”);
//TCanvas canv(“c”, “c”, 0, 0, 1900, 1000);
//tree.Branch(“canvas_tr”, “TCanvas”, &canv);
//tree.Fill();
//tree.Write();
//f_tree.Close();
//read
TObjArray Hlist_gr(0);
Hlist_gr.SetOwner(kTRUE);
TCanvas* canv_read = 0;
TChain chain("t1");
chain.Add("D:\\Data_work\\test_folder\\test_save.root");
chain.SetBranchAddress("canvas_tr", &canv_read);
chain.GetEntry(0);
Hlist_gr.Add(canv_read->Clone());
TFile ofile_Hlist_gr("D:\\Data_work\\test_folder\\test_result.root", "RECREATE");
Hlist_gr.Write();
ofile_Hlist_gr.Close();
system("pause");
return 0;
}
[/code]
Somethimes part2 works and somethimes does not.
I do not undestand why.
When I have warning message my file test_result.root is empty.
My VS:
[attachment=2]Screenshot_2.png[/attachment]
My root:
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 5.34/36 5 April 2016 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
ROOT 5.34/36 (v5-34-36@v5-34-36, Apr 05 2016, 10:25:45 on win32)
CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
I installed root from this file root_v5.34.36.win32.vc12.debug.exe
I compile code in Debug mode:
[attachment=1]Screenshot_3.png[/attachment]
The VS project in attachment.
Could you help?
Best regards, Vladislav.