Member reference type 'TCanvas *' is a pointer; maybe you meant to use '->'?

Hello,

I am trying to run a file named plot.C in root, but I got the error below. Can anyone help me see where went wrong? Thank you!


| Welcome to ROOT 6.06/02 root.cern.ch |
| © 1995-2014, The ROOT Team |
| Built for linuxx8664gcc |
| From heads/master@v6-07-02-437-gb06340c, Mar 02 2016, 19:01:57 |

Try ‘.help’, ‘.demo’, ‘.license’, ‘.credits’, ‘.quit’/’.q’

root [0]
Processing plot.C…
/home/lulu/Desktop/geant4.10.02.p01/examples/extended/medical/dna/dnaphysics/./plot.C:18:3: error:
member reference type ‘TCanvas ’ is a pointer; maybe you meant to use
’->’?
c1.Divide(2,1);
~~^
->
/home/lulu/Desktop/geant4.10.02.p01/examples/extended/medical/dna/dnaphysics/./plot.C:23:22: error:
member reference type ‘TFile’ is not a pointer; maybe you meant to use
’.’?
ntuple0 = (TNtuple
)f->Get(“ntuple0”);
~^~
.
/home/lulu/Desktop/geant4.10.02.p01/examples/extended/medical/dna/dnaphysics/./plot.C:25:3: error:
member reference type ‘TCanvas *’ is a pointer; maybe you meant to use
’->’?
c1.cd(1);
~~^
->
/home/lulu/Desktop/geant4.10.02.p01/examples/extended/medical/dna/dnaphysics/./plot.C:65:3: error:
member reference type ‘TCanvas *’ is a pointer; maybe you meant to use
’->’?
c1.cd(2);
~~^
->
root [1]

Hi,

this seems to be a mistake in the Geant4 macro at line 18. A method of tcanvas is being accessed with a “.” rather than “->” even if c1 is a pointer.

Cheers,
Danilo

Danilo is right. You should open a bug report on the Geant4 bugtracker in order to point out this problem.

Hi,

very good idea: it is through reports like this one that open source products improve.
I just stopped after proposing a workaround explaining the issue without pointing out the real solution which is fixing G4 :slight_smile:

Cheers,
Danilo

Hi,

Thank you both for helping out. I changed the plot.C file according to what it tells me, but now I’m getting another problem.


| Welcome to ROOT 6.06/02 root.cern.ch |
| © 1995-2014, The ROOT Team |
| Built for linuxx8664gcc |
| From heads/master@v6-07-02-437-gb06340c, Mar 02 2016, 19:01:57 |

Try ‘.help’, ‘.demo’, ‘.license’, ‘.credits’, ‘.quit’/’.q’

root [0]
Processing plot.C…

*** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

#0 0x00007f0cbbb2464a in __GI___waitpid (pid=2955, stat_loc=stat_loc
entry=0x7ffd1114ad80, options=options
entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:29
#1 0x00007f0cbba9dfab in do_system (line=) at …/sysdeps/posix/system.c:148
#2 0x00007f0cbcaa1784 in TUnixSystem::StackTrace() () from /home/lulu/Downloads/root-6.06.02/lib/libCore.so
#3 0x00007f0cbcaa386c in TUnixSystem::DispatchSignals(ESignals) () from /home/lulu/Downloads/root-6.06.02/lib/libCore.so
#4
#5 0x00007f0cbd016345 in ?? ()
#6 0x00007ffd1114e180 in ?? ()
#7 0x000000000224e530 in ?? ()
#8 0x00007ffd1114e180 in ?? ()
#9 0x00007ffd1114d730 in ?? ()
#10 0x000000000349fc20 in ?? ()
#11 0x0000000000000015 in ?? ()
#12 0x00007f0cbd0162d0 in ?? ()
#13 0x00007f0cb8a5db64 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#14 0x00007f0cb8a62dee in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#15 0x00007f0cb8a62f47 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::Value*, cling::Transaction**) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#16 0x00007f0cb8b172ee in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#17 0x00007f0cb8b17ab8 in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, bool) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#18 0x00007f0cb89cb30b in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#19 0x00007f0cb89bcc97 in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#20 0x00007f0cbca3cb87 in TApplication::ExecuteFile(char const*, int*, bool) () from /home/lulu/Downloads/root-6.06.02/lib/libCore.so
#21 0x00007f0cbca3dadf in TApplication::ProcessLine(char const*, bool, int*) () from /home/lulu/Downloads/root-6.06.02/lib/libCore.so
#22 0x00007f0cbc5f3c45 in TRint::ProcessLineNr(char const*, char const*, int*) () from /home/lulu/Downloads/root-6.06.02/lib/libRint.so
#23 0x00007f0cbc5f515f in TRint::Run(bool) () from /home/lulu/Downloads/root-6.06.02/lib/libRint.so
#24 0x000000000040106c in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x00007f0cbd016345 in ?? ()
#6 0x00007ffd1114e180 in ?? ()
#7 0x000000000224e530 in ?? ()
#8 0x00007ffd1114e180 in ?? ()
#9 0x00007ffd1114d730 in ?? ()
#10 0x000000000349fc20 in ?? ()
#11 0x0000000000000015 in ?? ()
#12 0x00007f0cbd0162d0 in ?? ()
#13 0x00007f0cb8a5db64 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#14 0x00007f0cb8a62dee in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#15 0x00007f0cb8a62f47 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::Value*, cling::Transaction**) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#16 0x00007f0cb8b172ee in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so
#17 0x00007f0cb8b17ab8 in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, bool) () from /home/lulu/Downloads/root-6.06.02/lib/libCling.so

Root >

Hi,

hard to tell. Are you by chance dereferencing a null pointer or calling a method on an invalid pointer?

D

Hi,

a note about the G4 example issue.
I forwarded it to G4 experts and it has been already fixed in the trunk. The next patch release, 10.2.p02, which should be available before summer, will fix this.

Cheers,
Danilo

I tried to run the plot.C macro from my Geant4 installation (Geant 4.10.2 patch 1) with the latest ROOT version 6.06/04 and the macro wrosk fine here. This means that the script has been fixed in the latest Geant4 version.

The plot.C is as follow

[code]// -------------------------------------------------------------------
// $Id: plot.C 70323 2013-05-29 07:57:44Z gcosmo $
// -------------------------------------------------------------------
//
// *********************************************************************
// To execute this macro under ROOT after your simulation ended,
// 1 - launch ROOT (usually type ‘root’ at your machine’s prompt)
// 2 - type ‘.X plot.C’ at the ROOT session prompt
// *********************************************************************
{
gROOT->Reset();
gStyle->SetPalette(1);
gROOT->SetStyle(“Plain”);

c1 = new TCanvas (“c1”,"",20,20,1000,500);
c1->Divide(2,1);

system (“rm -rf dna.root”);
system (“hadd dna.root dna_*.root”);

TFile f(“dna.root”);

TNtuple* ntuple;
ntuple = (TNtuple*)f.Get(“dna”);

c1->cd(1);
gStyle->SetOptStat(000000);

// All
ntuple->Draw(“flagProcess”,"",“B”);
ntuple->SetFillStyle(1001);
ntuple->SetFillColor(2);

// Excitation
ntuple->Draw(“flagProcess”,“flagProcess==12||flagProcess==15||flagProcess==16||flagProcess==19||flagProcess==22||flagProcess==25||flagProcess==29”,“Bsame”);
ntuple->SetFillStyle(1001);
ntuple->SetFillColor(3);

// Elastic
ntuple->Draw(“flagProcess”,“flagProcess==11”,“Bsame”);
ntuple->SetFillStyle(1001);
ntuple->SetFillColor(4);

// Ionisation
ntuple->Draw(“flagProcess”,“flagProcess==13||flagProcess==17||flagProcess==20||flagProcess==23||flagProcess==26||flagProcess==30”,“Bsame”);
ntuple->SetFillStyle(1001);
ntuple->SetFillColor(5);

// Charge decrease
//ntuple->Draw(“flagProcess”,“flagProcess==18||flagProcess==24||flagProcess==27”,“Bsame”);
//ntuple->SetFillStyle(1001);
//ntuple->SetFillColor(6);

// Charge increase
//ntuple->Draw(“flagProcess”,“flagProcess==21||flagProcess==28||flagProcess==31”,“Bsame”);
//ntuple->SetFillStyle(1001);
//ntuple->SetFillColor(7);

gPad->SetLogy();

c1->cd(2);

ntuple->SetMarkerColor(2);
ntuple->Draw(“x:y:z/1000”,“flagParticle==1”);

//ntuple->SetMarkerColor(4);
//ntuple->SetMarkerSize(4);
//ntuple->Draw(“x:y:z/1000”,“flagParticle==4 || flagParticle==5 || flagParticle==6”,“same”);

end:
}[/code]

ummm… I got the latest versions of Geant4 and ROOT as well. Did you just do “root plot.C”?

Thank you!

Yes, just “root plot.C” in the directory where are your ROOT files.