G3DetTable.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 #include "globals.hh"
00030 #include "G3DetTable.hh"
00031 
00032 typedef std::map<G4String, G3DetTableEntry*, std::less<G4String> >
00033 ::iterator DTDiterator;
00034 
00035 G4String 
00036 G3DetTable::MakeHash(G4String& set, G4String& det){;
00037   return set+" "+det;
00038 }
00039 
00040 G3DetTable::G3DetTable(){
00041 }
00042 
00043 G3DetTable::~G3DetTable(){
00044   if (DTD.size() > 0) {
00045     //    G4cout << "Deleting DTD" << G4endl;
00046     for (DTDiterator i=DTD.begin(); i != DTD.end(); i++) {
00047       delete (*i).second;
00048     }
00049     DTD.clear();
00050   }
00051 }
00052 
00053 G4VSensitiveDetector* 
00054 G3DetTable::GetSD(G4String& set, G4String& det){
00055 
00056   // make hash ID
00057   const G4String ShashID = MakeHash(set, det);
00058 
00059   // search the map
00060   DTDiterator i = DTD.find(ShashID);
00061   G3DetTableEntry* DTE = (*i).second;
00062   if (DTE != 0) {
00063     return DTE->GetSD();
00064   } else {
00065     return 0;
00066   }  
00067 }
00068 
00069 G4int 
00070 G3DetTable::GetID(G4String& set, G4String& det){
00071 
00072   // make hash ID
00073   G4String ShashID = MakeHash(set, det);
00074 
00075   // search the Hash Dictionary
00076   DTDiterator i = DTD.find(ShashID);
00077   G3DetTableEntry* DTE = (*i).second;
00078   if (DTE != 0) {
00079     return DTE->GetID();
00080   } else {
00081     return 0;
00082   }
00083 }
00084 
00085 void 
00086 G3DetTable::Put(G4String& set, G4String& det, G4int id, 
00087                 G4VSensitiveDetector* D){
00088   // make hash ID
00089   G4String ShashID = MakeHash(set, det);
00090   G3DetTableEntry* DTE = new G3DetTableEntry(set, det, id, D);
00091   G4cout << "Inserted DTE with id " << ShashID << G4endl;
00092   DTD[ShashID] = DTE;
00093 }
00094 
00095 void
00096 G3DetTable::PrintAll(){
00097   if (DTD.size()>0){
00098     G4int count=0;
00099     G4cout << "Dump of DTD - " << DTD.size() << " entries:" << G4endl;
00100     for (DTDiterator i=DTD.begin(); i != DTD.end(); i++) {
00101       count++;
00102       G3DetTableEntry* DTE = (*i).second;
00103       G4cout << "DTD entry " << std::setw(3) << count << " sensitive detector name: " 
00104              << DTE->GetSD()->GetName() << G4endl;
00105     }
00106   }
00107 }
00108 
00109 
00110 
00111 
00112 

Generated on Mon May 27 17:47:35 2013 for Geant4 by  doxygen 1.4.7