Changeset 73 for MEMPHYS


Ignore:
Timestamp:
Jan 16, 2006, 9:36:21 AM (18 years ago)
Author:
barrand
Message:

G.Barrand : introduce IAppManager which is more general than IAnalyis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MEMPHYS/HEAD/applications/MEMPHYS_session.cxx

    r70 r73  
    11
    22// 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>
    67
    78//AIDA :
     
    1314// Lib :
    1415#include <Lib/Interfaces/IManager.h>
     16#include <Lib/Interfaces/ISession.h>
     17#include <Lib/Interfaces/ITypeManager.h>
     18#include <Lib/Manager.h>
    1519#include <Lib/System.h>
     20#include <Lib/Out.h>
    1621#include <Lib/Cast.h>
    1722
     
    1924#include <G4Lab/UIOnX.h>
    2025#include <G4Lab/TrackingAction.h>
    21 #include <G4Lab/Helpers.h>
     26#include <G4Lab/Interfaces/IGeant4Manager.h>
    2227#include <G4Lab/DigitsCollectionType.h>
    2328
     
    3439#include "MEMPHYS/SteppingAction.hh"
    3540#include "MEMPHYS/WCDigi.hh"
     41#include <MEMPHYS/HitsCollectionType.h>
    3642
    3743// Create a manager to access the MEMPHYSAnalysis from the callbacks :
     
    4046namespace MEMPHYS {
    4147
    42 class AnalysisManager
     48class AppManager
    4349  :public virtual IManager
    4450  ,public Analysis  {
     
    4652  virtual const std::string& name() const { return fName;}
    4753  virtual void* cast(const std::string& aTo) const {
    48     if(aTo=="MEMPHYS::AnalysisManager") {
    49       return Lib_SCast(MEMPHYS::AnalysisManager);
    50     } else if(aTo=="MEMPHYS::IAnalysis") {
    51       return Lib_SCast(MEMPHYS::IAnalysis);
     54    if(aTo=="MEMPHYS::AppManager") {
     55      return Lib_SCast(MEMPHYS::AppManager);
     56    } else if(aTo=="MEMPHYS::IAppManager") {
     57      return Lib_SCast(MEMPHYS::IAppManager);
    5258    } else if(aTo=="MEMPHYS::Analysis") {
    5359      return Lib_SCast(MEMPHYS::Analysis);
     
    5864    }
    5965  }
     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  }
    60110 public:
    61   AnalysisManager(AIDA::IAnalysisFactory& aAIDA,bool aBatch)
    62     :Analysis(aAIDA,aBatch),fName("MEMPHYS::AnalysisManager") {}
    63   virtual ~AnalysisManager(){}
     111  AppManager(ISession& aSession,AIDA::IAnalysisFactory& aAIDA,bool aBatch)
     112    :Analysis(aAIDA,aBatch),fSession(aSession),fName("MEMPHYS::AppManager") {}
     113  virtual ~AppManager(){}
    64114 private:
     115  ISession& fSession;
    65116  std::string fName;
    66117};
     
    83134  G4Lab::UIOnX* session = new G4Lab::UIOnX(*runManager,gui,aArgc,aArgv);
    84135
    85   MEMPHYS::AnalysisManager* analysisManager = 0;
    86 
    87   AIDA::IAnalysisFactory* aida = G4Lab::UIOnX_aida(*session);
     136  MEMPHYS::AppManager* appManager = 0;
     137
     138  AIDA::IAnalysisFactory* aida = session->findAIDA();
    88139  if(!aida) {
    89140    std::cout << "MEMPHYS_session : AIDA not found." << std::endl;
    90141  } 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);
    101144  }
    102145
     
    109152
    110153 
    111   //JEC 18/11/05 give the "analysis" to fill geometry ITuple
     154  //JEC 18/11/05 give the appManager to fill geometry ITuple
    112155  MEMPHYS::DetectorConstruction* MEMPHYSdetector =
    113     new MEMPHYS::DetectorConstruction(*analysisManager);
     156    new MEMPHYS::DetectorConstruction(*appManager);
    114157
    115158  runManager->SetUserInitialization(MEMPHYSdetector);
     
    127170
    128171
    129   runManager->SetUserAction(new MEMPHYS::EventAction(*analysisManager,
     172  runManager->SetUserAction(new MEMPHYS::EventAction(*appManager,
    130173                                                   myRunAction,
    131174                                                   MEMPHYSdetector,
     
    148191
    149192  // Main UI loop :
     193  // GUI is really constructed here.
     194  // Create callbacks are executed here too.
    150195  session->SessionStart();
    151196
    152   delete session; //It will delete the analysisManager.
     197  delete session; //It will delete the appManager.
    153198
    154199  delete runManager;
Note: See TracChangeset for help on using the changeset viewer.