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: 03 Dec, 2010
From: michel maire <michel maire>

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.
> 
> Peter
> 

 Another possible way is shown in examples/novice/N03 : pass the pointer of MyDetectorConstruction to MyPrimaryGeneratorAction via its constructor.

 Here is the code in exampleN03.cc :

  // Set mandatory initialization classes
  //
  DetectorConstruction* detector = new DetectorConstruction;
  runManager->SetUserInitialization(detector);

  // Set user action classes
  //
  PrimaryGeneratorAction* gen_action = 
                          new PrimaryGeneratorAction(detector);
  runManager->SetUserAction(gen_action); 

     Michel

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Feedback: Re: Getting UserDetectorConstruction Instance   (Michael Rinaldi - 03 Dec, 2010)
 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 ]