Problems Append'ing THStack to gDirectory

Greetings,

I am working in 5.15/08, and am having difficulty Append’ing a THStack to gDirectory. There are two unexpected behaviors:

  1. If I create a bare THStack, and Append it to gDirectory, upon a first .ls I see the THStack (though with unexpected format), but all subsequent .ls do not show the THStack or anything else for that matter! A gDirectory->GetList()->Print() before the first .ls does not show the THStack, but it does show whatever TH1’s are there both before and after .ls fails to list them. At least I am still able to find the THStack within the gDirectory:

root [0] THStack* stack = new THStack(“stack”, “my stack”)
root [1] stack
(class THStack*)0x9670e00
root [2] .ls
TROOT* Rint The ROOT of EVERYTHING
root [3] gDirectory->Append(stack)
root [4] .ls
TROOT* Rint The ROOT of EVERYTHING
THStack Name= stack Title= my stack Option=root [5]
root [5] .ls
root [6] gDirectory->FindObjectAny(“stack”)
(const class TObject*)0x9670e00

  1. However, if I Append to gDirectory a THStack to which I have Add’ed TH1’s, a .ls results in a segmentation violation:

root [0] THStack* stack = new THStack(“stack”, “my stack”)
root [1] TH1F* h1 = new TH1F(“h1”, “my hist”, 10, 0., 10.)
root [2] stack->Add(h1)
root [3] .ls
TROOT* Rint The ROOT of EVERYTHING
OBJ: TH1F h1 my hist : 0 at: 0x89f2a68
root [4] gDirectory->Append(stack)
root [5] .ls
TROOT* Rint The ROOT of EVERYTHING
OBJ: TH1F h1 my hist : 0 at: 0x89f2a68
THStack Name= stack Title= my stack Option=
*** Break *** segmentation violation

As THStack inherits from TObject I expected this to work. I can provide the entire segfault output if necessary. Any help or explanation is appreciated!

Jake

What you do is correct, buy when using the command

root[5] .ls This invokes gDirectory->ls(0), in turn calling all the objects::ls in this directory. There was a protection missing in some regular expression parsing function that I fixed in the CVS version (in TRegexp).
You can circumvent the problem by calling instead of “.ls”

root[5] gDirectory->ls();
Rene