- Timestamp:
- Jan 16, 2006, 9:36:21 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MEMPHYS/HEAD/applications/MEMPHYS_session.cxx
r70 r73 1 1 2 2 // Geant4: 3 #include "G4ios.hh" 4 #include "G4RunManager.hh" 5 #include "G4UImanager.hh" 3 #include <G4ios.hh> 4 #include <G4RunManager.hh> 5 #include <G4UImanager.hh> 6 #include <G4SDManager.hh> 6 7 7 8 //AIDA : … … 13 14 // Lib : 14 15 #include <Lib/Interfaces/IManager.h> 16 #include <Lib/Interfaces/ISession.h> 17 #include <Lib/Interfaces/ITypeManager.h> 18 #include <Lib/Manager.h> 15 19 #include <Lib/System.h> 20 #include <Lib/Out.h> 16 21 #include <Lib/Cast.h> 17 22 … … 19 24 #include <G4Lab/UIOnX.h> 20 25 #include <G4Lab/TrackingAction.h> 21 #include <G4Lab/ Helpers.h>26 #include <G4Lab/Interfaces/IGeant4Manager.h> 22 27 #include <G4Lab/DigitsCollectionType.h> 23 28 … … 34 39 #include "MEMPHYS/SteppingAction.hh" 35 40 #include "MEMPHYS/WCDigi.hh" 41 #include <MEMPHYS/HitsCollectionType.h> 36 42 37 43 // Create a manager to access the MEMPHYSAnalysis from the callbacks : … … 40 46 namespace MEMPHYS { 41 47 42 class A nalysisManager48 class AppManager 43 49 :public virtual IManager 44 50 ,public Analysis { … … 46 52 virtual const std::string& name() const { return fName;} 47 53 virtual void* cast(const std::string& aTo) const { 48 if(aTo=="MEMPHYS::A nalysisManager") {49 return Lib_SCast(MEMPHYS::A nalysisManager);50 } else if(aTo=="MEMPHYS::IA nalysis") {51 return Lib_SCast(MEMPHYS::IA nalysis);54 if(aTo=="MEMPHYS::AppManager") { 55 return Lib_SCast(MEMPHYS::AppManager); 56 } else if(aTo=="MEMPHYS::IAppManager") { 57 return Lib_SCast(MEMPHYS::IAppManager); 52 58 } else if(aTo=="MEMPHYS::Analysis") { 53 59 return Lib_SCast(MEMPHYS::Analysis); … … 58 64 } 59 65 } 66 public://IAppManager 67 virtual bool initialize() { 68 //GB : 69 // Used in the MEMPHYS_Initialize callback. 70 // Do all the below here because of platforms having 71 // not Geant4 shared libs. 72 IGeant4Manager* g4Manager = 73 Lib_findManager(fSession,"Geant4Manager",IGeant4Manager); 74 if(!g4Manager) { 75 Lib::Out out(fSession.printer()); 76 out << "MEMPHYS_Initialize :" 77 << " Geant4Manager not found." 78 << Lib::endl; 79 return false; 80 } 81 82 // To initialize G4Lab Types (PV, Trajectory, HitsCollection, etc.. types). 83 // To initialize G4Lab SoNodes. 84 g4Manager->initialize(); 85 86 // Overload the HitsCollectionType of G4Lab : 87 Lib::ITypeManager* typeManager = 88 Lib_findManager(fSession,"TypeManager",Lib::ITypeManager); 89 if(typeManager) { 90 G4SDManager* sdManager = g4Manager->sdManager(); 91 if(sdManager) { 92 G4HCtable* hcTable = sdManager->GetHCtable(); 93 if(hcTable) { 94 int number = hcTable->entries(); 95 for(int index=0;index<number;index++) { 96 G4String hcName = hcTable->GetHCname(index); 97 typeManager->removeType(hcName); 98 typeManager->addType 99 (new MEMPHYS::HitsCollectionType(fSession,hcName)); 100 } 101 } 102 } 103 104 typeManager->addType 105 (new G4Lab::DigitsCollectionType<MEMPHYS::WCDigi> 106 (fSession,"WCDigitizedCollection")); 107 } 108 return true; 109 } 60 110 public: 61 A nalysisManager(AIDA::IAnalysisFactory& aAIDA,bool aBatch)62 :Analysis(aAIDA,aBatch),f Name("MEMPHYS::AnalysisManager") {}63 virtual ~A nalysisManager(){}111 AppManager(ISession& aSession,AIDA::IAnalysisFactory& aAIDA,bool aBatch) 112 :Analysis(aAIDA,aBatch),fSession(aSession),fName("MEMPHYS::AppManager") {} 113 virtual ~AppManager(){} 64 114 private: 115 ISession& fSession; 65 116 std::string fName; 66 117 }; … … 83 134 G4Lab::UIOnX* session = new G4Lab::UIOnX(*runManager,gui,aArgc,aArgv); 84 135 85 MEMPHYS::A nalysisManager* analysisManager = 0;86 87 AIDA::IAnalysisFactory* aida = G4Lab::UIOnX_aida(*session);136 MEMPHYS::AppManager* appManager = 0; 137 138 AIDA::IAnalysisFactory* aida = session->findAIDA(); 88 139 if(!aida) { 89 140 std::cout << "MEMPHYS_session : AIDA not found." << std::endl; 90 141 } else { 91 analysisManager = new MEMPHYS::AnalysisManager(*aida,false); 92 session->addManager(analysisManager); 93 } 94 if(session->session()) { 95 //GB 07/12/2005 : declare DigitsCollections types. 96 //FIXME : Why can't we be generic as for hits collection ? 97 //FIXME : From G4VDigiCollection, we can't loop on G4VDigi ! 98 session->addType 99 (new G4Lab::DigitsCollectionType<MEMPHYS::WCDigi> 100 (*(session->session()),"WCDigitizedCollection")); 142 appManager = new MEMPHYS::AppManager(*session->session(),*aida,false); 143 session->addManager(appManager); 101 144 } 102 145 … … 109 152 110 153 111 //JEC 18/11/05 give the "analysis"to fill geometry ITuple154 //JEC 18/11/05 give the appManager to fill geometry ITuple 112 155 MEMPHYS::DetectorConstruction* MEMPHYSdetector = 113 new MEMPHYS::DetectorConstruction(*a nalysisManager);156 new MEMPHYS::DetectorConstruction(*appManager); 114 157 115 158 runManager->SetUserInitialization(MEMPHYSdetector); … … 127 170 128 171 129 runManager->SetUserAction(new MEMPHYS::EventAction(*a nalysisManager,172 runManager->SetUserAction(new MEMPHYS::EventAction(*appManager, 130 173 myRunAction, 131 174 MEMPHYSdetector, … … 148 191 149 192 // Main UI loop : 193 // GUI is really constructed here. 194 // Create callbacks are executed here too. 150 195 session->SessionStart(); 151 196 152 delete session; //It will delete the a nalysisManager.197 delete session; //It will delete the appManager. 153 198 154 199 delete runManager;
Note: See TracChangeset
for help on using the changeset viewer.