G4SDManager.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 "G4SDManager.hh"
00031 #include "G4SDmessenger.hh"
00032 #include "G4HCofThisEvent.hh"
00033 #include "G4VHitsCollection.hh"
00034 #include "G4VSensitiveDetector.hh"
00035 #include "G4ios.hh"
00036 
00037 
00038 G4SDManager* G4SDManager::fSDManager = 0;
00039 
00040 G4SDManager* G4SDManager::GetSDMpointer()
00041 {
00042   if(!fSDManager)
00043   {
00044     fSDManager = new G4SDManager;
00045   }
00046   return fSDManager;
00047 }
00048 
00049 G4SDManager* G4SDManager::GetSDMpointerIfExist()
00050 { return fSDManager; }
00051 
00052 G4SDManager::G4SDManager():verboseLevel(0)
00053 {
00054   G4String topName = "/";
00055   treeTop = new G4SDStructure(topName);
00056   theMessenger = new G4SDmessenger(this);
00057   HCtable = new G4HCtable;
00058 }
00059 
00060 G4SDManager::~G4SDManager()
00061 {
00062   delete theMessenger;
00063   delete HCtable;
00064   delete treeTop;
00065 }
00066 
00067 void G4SDManager::AddNewDetector(G4VSensitiveDetector*aSD)
00068 {
00069   G4int numberOfCollections = aSD->GetNumberOfCollections();
00070   G4String pathName = aSD->GetPathName();
00071   if( pathName(0) != '/' ) pathName.prepend("/");
00072   if( pathName(pathName.length()-1) != '/' ) pathName += "/";
00073   treeTop->AddNewDetector(aSD,pathName);
00074   if(numberOfCollections<1) return;
00075   for(G4int i=0;i<numberOfCollections;i++)
00076   {
00077     G4String SDname = aSD->GetName();
00078     G4String DCname = aSD->GetCollectionName(i);
00079     AddNewCollection(SDname,DCname);
00080   }
00081   if( verboseLevel > 0 )
00082   {
00083     G4cout << "New sensitive detector <" << aSD->GetName()
00084          << "> is registored at " << pathName << G4endl;
00085   }
00086 }
00087 
00088 void G4SDManager::AddNewCollection(G4String SDname,G4String DCname)
00089 {
00090   G4int i = HCtable->Registor(SDname,DCname);
00091   if(verboseLevel>0)
00092   {
00093     if(i<0) {
00094      G4ExceptionDescription ED;
00095      ED << "G4SDManager::AddNewCollection : the collection <"
00096       << SDname << "/" << DCname << "> has already been reginstered." << G4endl;
00097      G4Exception("G4SDManager::AddNewCollection","Det0001",JustWarning,ED);
00098     }
00099     else
00100     {
00101       G4cout << "G4SDManager::AddNewCollection : the collection <"
00102        << SDname << "/" << DCname << "> is registered at " << i << G4endl;
00103     }
00104   }
00105 }
00106 
00107 G4HCofThisEvent* G4SDManager::PrepareNewEvent()
00108 {
00109   G4HCofThisEvent* HCE = new G4HCofThisEvent(HCtable->entries());
00110   treeTop->Initialize(HCE);
00111   return HCE;
00112 }
00113 
00114 void G4SDManager::TerminateCurrentEvent(G4HCofThisEvent* HCE)
00115 {
00116   treeTop->Terminate(HCE);
00117 }
00118 
00119 void G4SDManager::Activate(G4String dName, G4bool activeFlag)
00120 {
00121   G4String pathName = dName;
00122   if( pathName(0) != '/' ) pathName.prepend("/");
00123   treeTop->Activate(pathName,activeFlag);
00124 }
00125 
00126 G4VSensitiveDetector* G4SDManager::FindSensitiveDetector(G4String dName, G4bool warning)
00127 {
00128   G4String pathName = dName;
00129   if( pathName(0) != '/' ) pathName.prepend("/");
00130   return treeTop->FindSensitiveDetector(pathName, warning);
00131 }
00132 
00133 G4int G4SDManager::GetCollectionID(G4String colName)
00134 {
00135   G4int id = HCtable->GetCollectionID(colName);
00136   if(id==-1)
00137   { G4cout << "<" << colName << "> is not found." << G4endl; }
00138   else if(id==-2)
00139   { G4cout << "<" << colName << "> is ambiguous." << G4endl; }
00140   return id;
00141 }
00142 
00143 G4int G4SDManager::GetCollectionID(G4VHitsCollection* aHC)
00144 {
00145   G4String HCname = aHC->GetSDname();
00146   HCname += "/";
00147   HCname += aHC->GetName();
00148   return GetCollectionID(HCname);
00149 }
00150 
00151 

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