TCanvas and the batch mode

Hi,

I have a problem concerning TCanvas and the batch mode (-b) running. Here’s a small program that creates a canvas and retrieves the size parameters before and after it is written to an output file. As will be seen, the value of some parameters are not kept when including the -b option.

[code]void test(){

TFile *f = new TFile(“test.root”,“RECREATE”);
TCanvas *c = new TCanvas(“c”,“c”,0,0,100,600);
TH1D *h = new TH1D(“h”,“h”,10,0,10);

h->Fill(3);
h->Draw();

cout<<"BEFORE WRITING THE CANVAS "<<endl;
cout<< "window width = " << c->GetWindowWidth()<<endl;
cout<< “window height =”<< c->GetWindowHeight()<<endl;
cout<< "window top X = "<< c->GetWindowTopX()<<endl;
cout<< "window topy = "<< c->GetWindowTopY()<<endl;
cout<< "window Ww = "<< c->GetWw()<<endl;
cout<< "Window Wh = "<< c->GetWh()<<endl;

c->Write(“testCanvas”);
gDirectory->ls();

TCanvas* myC = (TCanvas*)(gDirectory->GetKey(“testCanvas”))->ReadObj();

//PARAMETERS OF THE WRITTEN CANVAS
cout<<" AFTER WRITING THE CANVAS" <<endl;
cout<< "window width = " << myC->GetWindowWidth()<<endl;
cout<< "window height = "<< myC->GetWindowHeight()<<endl;
cout<< "window top X = "<< myC->GetWindowTopX()<<endl;
cout<< "window topy = "<< myC->GetWindowTopY()<<endl;
cout<< "window Ww = "<< myC->GetWw()<<endl;
cout<< "Window Wh = "<< myC->GetWh()<<endl;

}[/code]

When I run root -l test.C++ what I get is:

BEFORE WRITING THE CANVAS
window width = 100
window height =600
window top X = 1
window topy = 29
window Ww = 96
Window Wh = 572
TFile** test.root
TFile* test.root
OBJ: TH1D h h : 0 at: 0x1465c1f0
KEY: TCanvas testCanvas;1 c
AFTER WRITING THE CANVAS
window width = 100
window height = 600
window top X = 1
window topy = 29
window Ww = 96
Window Wh = 572

The canvas parameters are kept in the file. But when I run with root -l -b test.C++ I get:

BEFORE WRITING THE CANVAS
window width = 100
window height =600

window top X = 0
window topy = 0
window Ww = 96
Window Wh = 572
TFile** test.root
TFile* test.root
OBJ: TH1D h h : 0 at: 0xfbfa140
KEY: TCanvas testCanvas;1 c
AFTER WRITING THE CANVAS
window width = 0
window height = 0

window top X = 0
window topy = 0
window Ww = 96
Window Wh = 572

and the canvas looks now different. Specifically, the window width and height are not saved. What am I missing?

Thanks a lot.

May be the comment at the end of the doc header here : root.cern.ch/root/html/TCanvas.html
can help you ?
Let me know.

Thanks for your reply. I had already seen that, but it doesn’t seem to help really, although it is interesting to see what happens when I include that line:

That is, after the declaration of the TCanvas I do:

TCanvas *c = new TCanvas("c","c",0,0,100,600); c->SetWindowSize(100 + (100 - c->GetWw()), 600 + (600 - c->GetWh()));

Now, when I run without the batch mode, the output of the program looks like:

BEFORE WRITING THE CANVAS
window width = 104
window height =628
window top X = 1
window topy = 53
window Ww = 100
Window Wh = 600
TFile** test.root
TFile* test.root
OBJ: TH1D h h : 0 at: 0x5ccda80
KEY: TCanvas testCanvas;1 c
AFTER WRITING THE CANVAS
window width = 104
window height = 628
window top X = 1
window topy = 53
window Ww = 100
Window Wh = 600

The parameters Ww and Wh have been correctly modified and stored, while the window width and height have been automatically adapted and correctly saved. Now, if I run again with -b I get:

BEFORE WRITING THE CANVAS
window width = 100
window height =600
window top X = 0
window topy = 0
window Ww = 96
Window Wh = 572
TFile** test.root
TFile* test.root
OBJ: TH1D h h : 0 at: 0x54c42b0
KEY: TCanvas testCanvas;1 c
AFTER WRITING THE CANVAS
window width = 0
window height = 0
window top X = 0
window topy = 0
window Ww = 96
Window Wh = 572

There are two problems now, in my opinion, the first one is that the parameters of the TCanvas Ww and Wh
have NOT been changed at all, not even in the memory-resident object, and furthermore, the window width and window height of the memory-resident object have not been correctly written into the Key. When I look at what the Canvas looks like, it looks very different in one case and the other.

It is also worth mentioning that the parameters window topX and window topY acquire some values when running without the -b option, and I have no idea where they are coming from. When running with -b, no such values are seen.

I forgot to mention before, this problem persists in several root versions, this last test I did with 5.32.00.

Regards,
Elias.

Ooops, I need to correct a previous statement.

When using root 5.32.00 and using -b, I indeed get the output that I posted above. The Canvas stored in the file however, does look like the one I get when NOT using -b.

When using root 5.20.00 on the other hand, I get the same output but if I look at what the Canvas looks like when I draw it, it looks completely different. This one looks more “squared”, that is, the widht and height are very similar.

So it seems there are two kinds of issues here.

The first is that the parameters that define the Canvas are not correctly stored as a Key when using the -b option for both 5.32.00 and 5.20.00

The second one is that for 5.20.00 the Canvas looks very different from 5.32.00 with -b, despite both having the same parameters.

Regards,
Elias.

I am now looking at you 1st post using 5.32

Ok, in batch mode there is no window created thats why the window dimensions are 0.
The canvas size in pixel is given by: GetWw and GetWh with return fCw and fCh data members.
See root.cern.ch/root/html/src/TCanvas.h.html
Use these getters.