Multiple Canvases in batch

Dear ROOTers,
I’m writing a class in which I would like to include two canvases as datamember. Also I need the two canvases not to show, never, like when working in batch mode. For this purpose I create them with no name.

c1 = new TCanvas("",“c1”);

The problem is that the first canvas is deleted when I create the second, as in the following trivial example:

root [0] a = new TCanvas("",“AAA”)
(class TCanvas*)0x498d000
root [1] b = new TCanvas("",“BBB”)
(class TCanvas*)0x498de00
root [2] delete a

*** Break *** bus error

Do you have any suggesiton?

Regards,
Alessandro

Hi Alessandro,

[quote]Also I need the two canvases not to show, never[/quote] the best way (probable): gROOT->SetBatch(kTRUE); a = new TCanvas("aaa","AAA"); b = new TCanvas("bbb","BBB"); gROOT->SetBatch(kFALSE);in your case:a = new TCanvas("","AAA"); // create canvas with name = "" b = new TCanvas("","BBB"); // create canvas with to same name = "" !!! previous canvas was delete !!!
maybe this help: a = new TCanvas("","AAA"); a->SetName("aaa"); b = new TCanvas("","BBB"); b->SetName("bbb");
I hope this help, Jan

Hi Jan,
your workaroud could work, more or less.
But then creating two instances of the same class would result in multiple canvases with the same name in the global canvas list

root [0] a = new TCanvas("",“AAA”)
(class TCanvas*)0x48fe800
root [1] a->SetName(“aaa”)
root [2] b = new TCanvas("",“AAA”)
(class TCanvas*)0x4938400
root [3] b->SetName(“aaa”)
root [4] gROOT->GetListOfCanvases()->ls()
Canvas Name=aaa Title=AAA Option=
TCanvas fXlowNDC=0 fYlowNDC=0 fWNDC=1 fHNDC=1 Name= aaa Title= AAA Option=
Canvas Name=aaa Title=AAA Option=
TCanvas fXlowNDC=0 fYlowNDC=0 fWNDC=1 fHNDC=1 Name= aaa Title= AAA Option=

That generates some confusion when handling the canvases.
Beside, when I first checked the TCanvas code I thought that creating a batch canvas with no name would have prevented it to be included in the gROOT TCanvas list and therefore could have been used as a local/private object.

As far as I understand, a workaround to detatch the canvas could be something like

cX = new TCanvas("",“cX”);
gROOT->GetListOfCanvases()->Remove(cx);

but it’s not clear to me if it has some unwanted consequences.

In general, I don’t understand the purpose of the restriction to one no-name batch canvas and how to use it properly. Some help would be most welcome.

Alessandro