On my application, I have several windows with canvases, which I organize on my screen. I then save all the canvases to a TFile and close my application.
When I want to analyse the saved results, I open the TFile with a TBrowser, and double-click on all the canvases to “restore” the original view. This can be tedious if you have 60 independent canvases.
My question:
Is it possible to reopen via the TBrowser all the canvases at once?
If not, is it possible to tell Root to save a screenshot of the monitor and save it to the TFile? Something like: “bring all my windows to the front if some of them is hidden and save the screenshot to the TFile”.
[quote=“ferhue”]- Is it possible to reopen via the TBrowser all the canvases at once?[/quote]No, this is not possible.
[quote=“ferhue”]- If not, is it possible to tell Root to save a screenshot of the monitor and save it to the TFile? Something like: “bring all my windows to the front if some of them is hidden and save the screenshot to the TFile”.[/quote]This is not possible either, but why not creating a ROOT macro to achieve what you want (reading and displaying all the canvases saved in the file)?
Here my macro for reopening the canvases, just in case someone finds it also useful.
#include "TCanvas.h"
#include "TROOT.h"
#include "TFile.h"
#include "TString.h"
#include "TKey.h"
#include <iostream>
void test_macro()
{
//Gets the current file, assuming you have opened it via a TBrowser just before.
TFile* aFile = gROOT->GetFile();
//Alternatively:
//~ TFile* aFile = TFile::Open("someFile.root");
TIter next(aFile->GetListOfKeys());
TKey *key;
TCanvas* c;
while ((key=(TKey*)next())) {
if(strcmp(key->GetClassName(),"TCanvas")==0)
{
c = ((TCanvas*)key->ReadObj());
c->Draw();
//Alternatively:
//~ c->DrawClonePad();
}
}
}
The trick now is to save the code above in a file called e.g. test_macro.cpp, and save it in our TFile as a TMacro. Then just by double-clicking on it in the TBrowser, all canvases present inside the TFile will be reopened. Example of how to save the TMacro to our TFile:
#include "TFile.h"
#include "TCanvas.h"
#include "TMacro.h"
// Here, we write to a TFile the TMacro object which opens all canvases at once.
// When opening the TFile via the TBrowser, just by double-clicking on the TMacro, it gets executed and all canvases will be shown.
void test_openAll()
{
TFile* aFile = new TFile("/tmp/test_openAll.root","RECREATE");
aFile->cd();
TCanvas* c = new TCanvas("c1","c1");
c->cd();
c->Write();
TCanvas* c2 = new TCanvas("c2","c2");
c2->cd();
c2->Write();
TMacro* ma = new TMacro("test_macro.cpp","VIEW");
ma->Write();
aFile->Write();
aFile->Close();
delete aFile;
}