Getting a TGraphAsymmErrors from a root file

dear rooters,

i tried to access a TGraphAsymmErrors from a root file in the following way (root 5.18, directly in CINT):

TFile newFile; newFile.Open("MyFile.root"); TGraphAsymmErrors* graph = (TGraphAsymmErrors*) newFile.Get("MyTGraph");

this leads to a segmentation fault (error message below).

if i do the same thing but using a pointer to a TFile instead of TFile directly, it works!?!

TFile* newFile; newFile = new TFile("MyFile.root"); TGraphAsymmErrors* graph = (TGraphAsymmErrors*) newFile->Get("MyTGraph");

can someone explain to me why?

cheers,
axel.

ps: here’s the error message:

0x00a7f7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2 #1 0x0090a7e3 in __waitpid_nocancel () from /lib/tls/libc.so.6 #2 0x008b4649 in do_system () from /lib/tls/libc.so.6 #3 0x008798bd in system () from /lib/tls/libpthread.so.0 #4 0x002d4633 in TUnixSystem::Exec () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #5 0x002d9f75 in TUnixSystem::StackTrace () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #6 0x002d6ce6 in TUnixSystem::DispatchSignals () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #7 0x002d6d74 in SigHandler () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #8 0x002d5fd9 in sighandler () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #9 <signal handler called> #10 0x00ea3fef in TDirectoryFile::Get () from /opt/products/root/5.18.00/lib/libRIO.so #11 0x0034b36f in G__G__Base1_158_0_32 () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #12 0x00ad2adb in Cint::G__ExceptionWrapper () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #13 0x00b8f317 in G__call_cppfunc () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #14 0x00b74959 in G__interpret_func () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #15 0x00b62a50 in G__getfunction () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #16 0x00c215dd in G__getstructmem () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #17 0x00c19302 in G__getvariable () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #18 0x00b469ea in G__getitem () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #19 0x00b4997b in G__getexpr () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #20 0x00b6209b in G__getfunction () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #21 0x00b46d34 in G__getitem () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #22 0x00b4997b in G__getexpr () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #23 0x00b623ae in G__getfunction () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #24 0x00b46d34 in G__getitem () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #25 0x00b4997b in G__getexpr () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #26 0x00b391e8 in G__define_var () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #27 0x00bb63bc in G__exec_statement () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #28 0x00b34b84 in G__exec_tempfile_core () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #29 0x00b35ebf in G__exec_tempfile_fp () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #30 0x00bc67c4 in G__process_cmd () from /opt/products/root/5.18.00/lib/libCint.so.5.18 #31 0x002a7ba3 in TCint::ProcessLine () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #32 0x00215bd6 in TApplication::ProcessLine () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #33 0x00757210 in TRint::HandleTermInput () from /opt/products/root/5.18.00/lib/libRint.so.5.18 #34 0x007558a8 in TTermInputHandler::Notify () from /opt/products/root/5.18.00/lib/libRint.so.5.18 #35 0x00757abe in TTermInputHandler::ReadNotify () from /opt/products/root/5.18.00/lib/libRint.so.5.18 #36 0x002d2fbe in TUnixSystem::CheckDescriptors () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #37 0x002d71c4 in TUnixSystem::DispatchOneEvent () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #38 0x0026ad2c in TSystem::InnerLoop () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #39 0x0026aaf2 in TSystem::Run () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #40 0x00215cc2 in TApplication::Run () from /opt/products/root/5.18.00/lib/libCore.so.5.18 #41 0x0075601a in TRint::Run () from /opt/products/root/5.18.00/lib/libRint.so.5.18 #42 0x08048dba in main ()

Coukld you send the shortest possible RUNNING script (and the data file) reproducing this problem? Note that instead of

TFile newFile; newFile.Open("MyFile.root"); it is better to do:

TFile newFile("MyFile.root");
Rene

hi rene,

thanks for the quick reply.

i noticed that, as you said,

TFile newFile("MyFile.root"); TGraphAsymmErrors* graph = (TGraphAsymmErrors*) newFile.Get("S61 Trigger Eff. ElecE"); graph->Draw("ap");
works, but

TFile newFile; newFile.Open("MyFile.root"); TGraphAsymmErrors* graph = (TGraphAsymmErrors*) newFile.Get("S61 Trigger Eff. ElecE"); graph->Draw("ap");
doesn’t work. i thought that TFile::Open(…) is used in the contructor, so i didn’t try it out.

in the attachment you’ll find the root file and two scripts, one which is working and one which isn’t.

cheers,
axel.
rottScriptNotWorking.C (166 Bytes)
rootScriptWorking.C (166 Bytes)
FileWithTGraph.root (6.72 KB)

Hi,

The codeTFile newFile; newFile.Open("MyFile.root"); is NOT doing what you expect. TFile::Open is a static method and hence does NOT update ‘newFile’ in this example (and hence for the rest of your function it is as if you did not call Open at all. Instead use:TFile *newfile = TFile::Open("MyFile.root");

Alternatively you could also doTFile newFile("MyFile.root");

Cheers,
Philippe.

Hi,

Correct me if I’m wrong, but this open command

[quote=“pcanal”]TFile *newfile = TFile::Open("MyFile.root"); // preferred
[/quote]

is actually much more powerful than this one:

[quote=“pcanal”]Alternatively you could also doTFile newFile("MyFile.root"); // not as powerful
[/quote]

since the former will do the right thing when you are opening files with different protocals (e.g., dccp://, etc) where as the latter will not.

Right?

Thanks,
Charles

Hi Charles,

[quote]since the former will do the right thing when you are opening files with different protocals (e.g., dccp://, etc) where as the latter will not. [/quote]You are absolutely correct.

Cheers,
Philippe.