Message: Re: Getting UserDetectorConstruction Instance Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Getting UserDetectorConstruction Instance 

Forum: Run Management
Re: Question Getting UserDetectorConstruction Instance (Michael Rinaldi)
Re: Feedback Re: Getting UserDetectorConstruction Instance (Gumplinger Peter)
Date: 02 Dec, 2010
From: Michael H. Kelsey <Michael H. Kelsey>

On Fri, 03 Dec 2010 04:54:40 GMT, Gumplinger Peter wrote:
> Hi Mike
> > G4RunManager *runManager = G4RunManager::GetRunManager(); const
> > G4VUserDetectorConstruction* myDet =
> > runManager->GetUserDetectorConstruction();
> > 
> > But this does not return my object since some of the methods in my
> > Detectorconstruction object were not defined.
> try this:
> const MyDetectorConstruction* myDet =
> (const MyDetectorConstruction*)
> (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
> or put after your code:
> const MyDetectorConstruction* myDetector = dynamic_cast<const
> MyDetectorConstruction *>(myDet);
> and now use the pointer to your derived class - myDetector; e.g. your
> myDet is a pointer to the base class and hence can only invoke base
> class methods. Indeed, a C++ question.

A C++ question, indeed. For the purists, you should check the above to make sure that "myDetector" is not a null pointer -- if the detector-construction returned was not actually your class, the dynamic_cast<> will return zero.

 Add Message Add Message
to: "Re: Getting UserDetectorConstruction Instance"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]