G4DigiManager.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 
00030 #include "G4DigiManager.hh"
00031 #include "G4Event.hh"
00032 #include "G4VHitsCollection.hh"
00033 #include "G4VDigiCollection.hh"
00034 #include "G4DMmessenger.hh"
00035 #include "G4DCofThisEvent.hh"
00036 #include "G4RunManager.hh"
00037 #include "G4SDManager.hh"
00038 #include "G4ios.hh"
00039 
00040 
00041 G4DigiManager* G4DigiManager::fDManager = 0;
00042 
00043 G4DigiManager* G4DigiManager::GetDMpointer()
00044 {
00045   if(!fDManager)
00046   {
00047     fDManager = new G4DigiManager;
00048   }
00049   return fDManager;
00050 }
00051 
00052 G4DigiManager* G4DigiManager::GetDMpointerIfExist()
00053 { return fDManager; }
00054 
00055 G4DigiManager::G4DigiManager():verboseLevel(0)
00056 { 
00057   theMessenger = new G4DMmessenger(this); 
00058   runManager = G4RunManager::GetRunManager();
00059   SDManager = G4SDManager::GetSDMpointer();
00060   DCtable = new G4DCtable;
00061 }
00062 
00063 G4DigiManager::~G4DigiManager()
00064 {
00065   //DMtable.clearAndDestroy();
00066   for(G4int i=0;i<int(DMtable.size());i++)
00067   { delete DMtable[i]; }
00068   DMtable.clear();
00069   delete DCtable;
00070   delete theMessenger;
00071 }
00072 
00073 void G4DigiManager::AddNewModule(G4VDigitizerModule* DM)
00074 {
00075   G4String DMname = DM->GetName();
00076   for(int j=0;j<int(DMtable.size());j++)
00077   {
00078     if(DMtable[j]==DM)
00079     { 
00080       G4cout << "<" << DMname << "> has already been registored." << G4endl; 
00081       return;
00082     }
00083   }
00084   if( verboseLevel > 0 )
00085   {
00086     G4cout << "New DigitizerModule <" << DMname
00087          << "> is registored." << G4endl;
00088   }
00089   DMtable.push_back(DM);
00090 
00091   G4int numberOfCollections = DM->GetNumberOfCollections();
00092   for(int i=0;i<numberOfCollections;i++)
00093   {
00094     G4String DCname = DM->GetCollectionName(i);
00095     if( DCtable->Registor(DMname,DCname) < 0 )
00096     { 
00097       G4cout << "DigiCollection <" << DCname 
00098            << "> has already been registored with "
00099            << DMname << " DigitizerModule." << G4endl;
00100     }
00101     else if( verboseLevel > 0 )
00102     {
00103       G4cout << "DigiCollection " << DCname 
00104            << " is registored. " << G4endl;
00105     }
00106   }
00107   
00108   runManager->SetDCtable(DCtable);
00109 }
00110 
00111 void G4DigiManager::Digitize(G4String mName)
00112 {
00113   G4VDigitizerModule* aDM = FindDigitizerModule(mName);
00114   if(aDM)
00115   { aDM->Digitize(); }
00116   else
00117   { G4cout << "Unknown digitizer module <" << mName << ">. Digitize() ignored." << G4endl; }
00118 }
00119 
00120 G4VDigitizerModule* G4DigiManager::FindDigitizerModule(G4String mName)
00121 {
00122   for(G4int i=0;i<int(DMtable.size());i++)
00123   {
00124     if(DMtable[i]->GetName() == mName) return DMtable[i];
00125   }
00126   return NULL;
00127 }
00128 
00129 const G4VHitsCollection* G4DigiManager::GetHitsCollection(G4int HCID,G4int eventID)
00130 {
00131   const G4Event* evt = NULL;
00132   if(eventID==0)
00133   { evt = runManager->GetCurrentEvent(); }
00134   else
00135   { evt = runManager->GetPreviousEvent(eventID); }
00136   if(evt==NULL) return NULL;
00137   
00138   G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
00139   if(HCE==NULL) return NULL;
00140 
00141   return HCE->GetHC(HCID);
00142 }
00143 
00144 const G4VDigiCollection* G4DigiManager::GetDigiCollection(G4int DCID,G4int eventID)
00145 {
00146   const G4Event* evt = NULL;
00147   if(eventID==0)
00148   { evt = runManager->GetCurrentEvent(); }
00149   else
00150   { evt = runManager->GetPreviousEvent(eventID); }
00151   if(evt==NULL) return NULL;
00152   
00153   G4DCofThisEvent* DCE = evt->GetDCofThisEvent();
00154   if(DCE==NULL) return NULL;
00155 
00156   return DCE->GetDC(DCID);
00157 }
00158 
00159 G4int G4DigiManager::GetHitsCollectionID(G4String HCname)
00160 {
00161   return SDManager->GetCollectionID(HCname);
00162 }
00163 
00164 G4int G4DigiManager::GetDigiCollectionID(G4String DCname)
00165 {
00166   G4int i = DCtable->GetCollectionID(DCname);
00167   if(i==-2)
00168   { G4cout << "< " << DCname << "> is ambegious." << G4endl; }
00169   return i;
00170 }
00171 
00172 void G4DigiManager::SetDigiCollection(G4int DCID,G4VDigiCollection* aDC)
00173 {
00174   const G4Event* consEvt = runManager->GetCurrentEvent();
00175   if(consEvt==NULL) 
00176   {
00177     G4cout << "G4DigiManager::SetDigiCollection --- "
00178          << "Event object is not available." << G4endl;
00179     return;
00180   }
00181   
00182   G4Event* evt = (G4Event*)consEvt;
00183   G4DCofThisEvent* DCE = evt->GetDCofThisEvent();
00184   if(DCE==NULL)
00185   {
00186     DCE = new G4DCofThisEvent(DCtable->entries());
00187     evt->SetDCofThisEvent(DCE);
00188     if(verboseLevel>0)
00189     { G4cout << "DCofThisEvent object is added to current G4Event." << G4endl; }
00190   }
00191 
00192   DCE->AddDigiCollection(DCID,aDC);
00193 
00194   if(verboseLevel>0)
00195   {
00196     G4cout << aDC->GetName() << " is stored at " << DCID 
00197          << "-th slot of G4DCofThisEvent." << G4endl;
00198   }
00199 }
00200   
00201 void G4DigiManager::SetVerboseLevel(G4int val)
00202 {
00203   verboseLevel = val;
00204   for(G4int i=0;i<int(DMtable.size());i++)
00205   { DMtable[i]->SetVerboseLevel(val); }
00206 }
00207 
00208 void G4DigiManager::List() const
00209 {
00210   for(G4int i=0;i<int(DMtable.size());i++)
00211   { G4cout << "   " << i << " : " << DMtable[i]->GetName() << G4endl; }
00212 }
00213 
00214 
00215 

Generated on Mon May 27 17:48:01 2013 for Geant4 by  doxygen 1.4.7