Hi Volker, better than using directly gInterpreter use gROOT methods: gROOT->ProcessLineFast() is the equivalent of the Calc() method with in addition some protections to make sure the environment is correctly setup. Idem for gROOT->ProcessLine(). Cheers, Fons. On Fri, Nov 23, 2001 at 10:43:34AM +0000, Rene Brun wrote: > Hi Volker, > > Thinking a bit more to your problem, there is a good solution to it > in ROOT 3.02/04 (thanks to Philippe). > Instead of using the function ProcessLine, use Calc. > Example > > TObject *obj=(TObject*)gInterpreter.Calc("new TH1F(\"h\",\"h\",100,-3,3)") > obj->Draw(); > > Calc returns the result of the query as a Long_t. You just have to cast it > to the correct type, or simply a TObject* if you like. > > Rene Brun > > Rene Brun wrote: > > > > Hi Volker, > > > > Following a mail from Axel, I just realize that I misunderstood your question. > > > > Why do you want to call TClass::New to create a new object ? > > Why don't you call directly the class constructor? > > > > In case, you want to create an object when you know only the name ot its class > > (could be what you try to do?), you can use the interpreter ProcessLine, > > Example: > > gInterpreter.ProcessLine("new TH1F(\"h\",\"h\",100,-3,3)") > > will create a new TH1F object. In this particular case, you can retrieve > > a pointer to the created object via gDirectory->Get("h"): the TH1F constructor > > adding automatically a reference to the object in the list of objects > > of the current directory. > > You can modify your constructor to automatically register itself to some > > collection. > > > > Rene Brun > > > > Volker Hejny wrote: > > > > > > Hallo, > > > > > > if I have a class name as a string value at run time, it is possible > > > to construct a new object of this class using TClass::New(). That > > > way the standard constructor is called. Is there any way to call > > > a different constructor with a given argument? > > > > > > Best regards, > > > Volker > > > > > > -- > > > Dr. Volker Hejny Tel: 02461/616853 ** > > > Institut f. Kernphysik Fax: 02461/613930 ** > > > ---------------------------------------------------------------- ** ** --- > > > Forschungszentrum Juelich GmbH, D-52425 Juelich ** -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7679480
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:09 MET