GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » Scientific Computing » ROOT » works interactively but not in a macro
icon5.gif  works interactively but not in a macro [message #4684] Tue, 17 July 2007 16:03 Go to next message
Olaf Hartmann is currently offline  Olaf Hartmann
Messages: 105
Registered: December 2003
Location: Wien-Alsergrund
continuous participant
From: *e12.physik.tu-muenchen.de
Hi ROOTers,

I'm quarreling with the following problem:

The sequence
root [15] partlist = TDatabasePDG::Instance();
root [16] TParticlePDG* part;
root [17] part = partlist->GetParticle("neutron");
root [18] Int_t mynumber = part.PdgCode()
root [19] mynumber
(Int_t)2112

works interactively. But inside a macro, I get the following
error message:

Error: illegal pointer to class object part 0x0 1034 FILE:conv_urqmd.C LINE:467
*** Interpreter error recovered ***

exactly at the point where the function part.PdgCode() is used.

Any idea?

Kindly,
Olaf.

Re: works interactively but not in a macro [message #4689 is a reply to message #4684] Wed, 18 July 2007 17:14 Go to previous messageGo to next message
wuestenf is currently offline  wuestenf
Messages: 138
Registered: June 2005
first-grade participant
From: *gsi.de
Hello Olaf,

root [16] TParticlePDG* part;


Is giving you the problem. You define part as a pointer to a TParticlePDG, so you should also use it as a pointer later.

So the correct line to access the memberfunction is:

Int_t mynumber = part->PdgCode()


This shouldalso work in a macro and in compiled code.

Hope this helps.

Joern


Joern Wuestenfeld
Helmholtz - Zentrum Dresden - Rossendorf
01328 Dresden
Re: works interactively but not in a macro [message #4741 is a reply to message #4689] Tue, 24 July 2007 16:08 Go to previous messageGo to next message
Olaf Hartmann is currently offline  Olaf Hartmann
Messages: 105
Registered: December 2003
Location: Wien-Alsergrund
continuous participant
From: *gsi.de
Hi Jörn,

Quote:


root [16] TParticlePDG* part;


Is giving you the problem. You define part as a pointer to a TParticlePDG, so you should also use it as a pointer later.

So the correct line to access the memberfunction is:

Int_t mynumber = part->PdgCode()


This should also work in a macro and in compiled code.



Unfortunately, in the macro it doesn't work neither. Actually
I tried it before with that syntax, the same result.
I couldn't figure out why this member function shouldn't be
accessible that way in a macro. Furthermore, the very same macro
once (some time ago) worked. So I already tried different
ROOT versions.

Cheers,
Olaf.


Re: works interactively but not in a macro [message #4760 is a reply to message #4684] Sun, 29 July 2007 10:36 Go to previous message
Ralf Kliemt is currently offline  Ralf Kliemt
Messages: 507
Registered: May 2007
Location: GSI, Darmstadt
first-grade participant

From: 141.30.239*
Hello Olaf,

I tried your macro and it runs.
{

partlist = TDatabasePDG::Instance();
TParticlePDG* part;
part = partlist->GetParticle("neutron");
Int_t mynumber = part->PdgCode();
std::cout<<mynumber<<std::endl;

}

I have root Version 5.14/00 and run on a SUSE 10.2.
Maybe you should try to catch if the pointer is not set properly. I've seen that you want to use this inside a macro for a particle generator. Maybe the TDatabasePDG is already loaded and modified by this.

Have a nice weekend,

Ralf.
Previous Topic: RootTalk Forum - HACKED!
Next Topic: ROOT and GCC3.4
Goto Forum:
  


Current Time: Fri Apr 16 20:05:10 CEST 2021

Total time taken to generate the page: 0.01844 seconds