TPad::SaveAs() enhancement

Hi there,

Canvases often need to be saved in several formatscanvas->SaveAs("foo.png") ; canvas->SaveAs("foo.eps") ; canvas->SaveAs("foo.root") ;
It would be nice to have a one-line mechanism doing the same job, e.g.canvas->SaveAs("foo.<gif,eps,root>") ;
Cheers,
Z

[quote=“Zesp”]Hi there,

Canvases often need to be saved in several formatscanvas->SaveAs("foo.png") ; canvas->SaveAs("foo.eps") ; canvas->SaveAs("foo.root") ;
It would be nice to have a one-line mechanism doing the same job, e.g.canvas->SaveAs("foo.<gif,eps,root>") ;
Cheers,
Z[/quote]
In shell script, we often use “foo.{gif,eps,root}” instead of “foo.<gif,eps,root>”. So, maybe brace is better. :slight_smile:

Maybe not since any filename can contain the following charaters ‘{’, ‘}’, ‘[’, ‘]’, ‘(’, ‘)’ whereas you are not allowed to use ‘<’ or ‘>’.
It may therefore be easier/safer to use ‘<’ and ‘>’ whilst parsing the SaveAs() argument.
Cheers, Z

You can also make a small generic script doing that and instead of writing these 3 lines simply execute this script. This script should have one parameter: a pointer to the canvas you want to print. So there is not need to invent a new syntax.

Actually, this is what I’m doing but I’m a bit tired of copy-pasting old bits of code to any new one.
Such a syntax could ease the rooter’s life.
This is just a proposal.
Have a nice day,
Z

Create the macro:

void Save(TPad *p)
{ 
   p->SaveAs("a.ps");
   p->SaveAs("a.gif");   
   p->SaveAs("a.root");   
}

In your rootlogon.C file do:
gROOT->LoadMacro(“Save.C”);
then you can to things like:

root [0] hpx->Draw()
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root [1] Save(gPad);
Info in <TCanvas::Print>: ps file a.ps has been created
Info in <TCanvas::Print>: GIF file a.gif has been created
Info in <TCanvas::SaveAs>: ROOT file a.root has been created

Ok, thanks Olivier.

An improved version of the above, so that you can select the name of the files you want to create would be something this. Add it to your rootlogon.C and call it like:

root [0] savefigure(“thename”)

Cheers,
Juande

[code]void savefigure(char* name) {
char name_eps[20];
sprintf(name_eps,"%s.eps",name);

char name_gif[20];
sprintf(name_gif,"%s.gif",name);

char name_root[20];
sprintf(name_root,"%s.root",name);

char name_C[20];
sprintf(name_C,"%s.C",name);

gPad->GetCanvas()->Print(name_eps);
gPad->SaveAs(name_gif);
gPad->SaveAs(name_root);
gPad->SaveAs(name_C);

}
[/code]