Message: Re: How to access to G4VSolid* in StackingAction()? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

More Re: How to access to G4VSolid* in StackingAction()? 

Forum: Event and Track Management
Re: None How to access to G4VSolid* in StackingAction()?
Re: None Re: How to access to G4VSolid* in StackingAction()?
Date: 22 Oct, 2007
From: Gumplinger Peter <Gumplinger Peter>

The problem is entirely yours and has to do with your C++ and the definition of the classes, what they contain, who owns the members, and when they go "go out of scope". What will work is:

Geo.hh

#ifndef Geo_h
#define Geo_h 1

#include "globals.hh"
#include "G4VSolid.hh"

class Geo
{
   public:

     Geo(){}
     ~Geo(){}

   public:

     G4VSolid* GetGeoSolid() {return fSolid;}
     void SetGeoSolid(G4VSolid* aSolid)
          { fSolid = aSolid; fName  = aSolid->GetName(); } 
     G4String GetGeoName() { return fName; }

   private:

     G4VSolid* fSolid;
     G4String fName;
};

#endif

UserManager.hh

#ifndef UserManager_h
#define UserManager_h 1

#include "globals.hh"

#include <vector>
#include "Geo.hh"

class UserManager
{
   public:

     UserManager();
     ~UserManager();

   public:

     std::vector<Geo*>* GetMirror() { return mirror; } 
     static UserManager* GetUserManager();

   private:

     static UserManager* fUserManager;

     std::vector<Geo*>* mirror;

};

#endif

UserManager.cc

#include "UserManager.hh"

  UserManager* UserManager::fUserManager = 0;

  UserManager::UserManager()
  {
    mirror = new std::vector<Geo*>();
  }
  UserManager::~UserManager()
  {
    if (mirror) {
       for(size_t i=0;i<mirror->size();++i){
          delete (*mirror)[i];
       }
       mirror->clear();
       delete mirror;
    }
  }

  UserManager* UserManager::GetUserManager()
  {
    if (fUserManager == 0) fUserManager = new UserManager();
    return fUserManager;
  }

and in DetectorConstruction:

  UserManager* Userman = UserManager::GetUserManager();
  std::vector<Geo*>* MirrorObj = Userman->GetMirror();
  if(MirrorObj->size()==0){
    MirrorObj->push_back(new Geo());
  }
  G4VSolid* mir_solid = blablabla;
  (*MirrorObj)[0]->SetGeoSolid(mir_solid); 

and in StackingAction:

  UserManager* Userman = UserManager::GetUserManager();
  std::vector<Geo*>* MirrorObj = Userman->GetMirror();
  if(MirrorObj->size()==1){
    G4cout<<"NewTrack solid="<<(*MirrorObj)[0]->GetGeoSolid()->GetName()<<G4endl;    G4cout<<"NewTrack solid="<<(*MirrorObj)[0]->GetGeoName()<<G4endl;
  } else {
    G4cout << "No MirrorObj" << G4endl;
  }

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

1 None: Re: How to access to G4VSolid* in StackingAction()?   (hyao@jlab.org - 23 Oct, 2007)
3 None: Re: How to access to G4VSolid* in StackingAction()?   (hyao@jlab.org - 23 Oct, 2007)
 Add Message Add Message
to: "Re: How to access to G4VSolid* in StackingAction()?"

 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 ]