G4SolidStore.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 // G4SolidStore
00030 //
00031 // Implementation for singleton container
00032 //
00033 // History:
00034 // 10.07.95 P.Kent Initial version
00035 // --------------------------------------------------------------------
00036 
00037 #include "globals.hh"
00038 #include "G4SolidStore.hh"
00039 #include "G4GeometryManager.hh"
00040 
00041 // ***************************************************************************
00042 // Static class variables
00043 // ***************************************************************************
00044 //
00045 G4SolidStore* G4SolidStore::fgInstance = 0;
00046 G4VStoreNotifier* G4SolidStore::fgNotifier = 0;
00047 G4bool G4SolidStore::locked = false;
00048 
00049 // ***************************************************************************
00050 // Protected constructor: Construct underlying container with
00051 // initial size of 100 entries
00052 // ***************************************************************************
00053 //
00054 G4SolidStore::G4SolidStore()
00055   : std::vector<G4VSolid*>()
00056 {
00057   reserve(100);
00058 }
00059 
00060 // ***************************************************************************
00061 // Destructor
00062 // ***************************************************************************
00063 //
00064 G4SolidStore::~G4SolidStore() 
00065 {
00066   Clean();
00067 }
00068 
00069 // ***************************************************************************
00070 // Delete all elements from the store
00071 // ***************************************************************************
00072 //
00073 void G4SolidStore::Clean()
00074 {
00075   // Do nothing if geometry is closed
00076   //
00077   if (G4GeometryManager::GetInstance()->IsGeometryClosed())
00078   {
00079     G4cout << "WARNING - Attempt to delete the solid store"
00080            << " while geometry closed !" << G4endl;
00081     return;
00082   }
00083 
00084   // Locks store for deletion of solids. De-registration will be
00085   // performed at this stage. G4VSolids will not de-register themselves.
00086   //
00087   locked = true;  
00088 
00089   size_t i=0;
00090   G4SolidStore* store = GetInstance();
00091 
00092 #ifdef G4GEOMETRY_VOXELDEBUG
00093   G4cout << "Deleting Solids ... ";
00094 #endif
00095 
00096   for(iterator pos=store->begin(); pos!=store->end(); pos++)
00097   {
00098     if (fgNotifier) { fgNotifier->NotifyDeRegistration(); }
00099     if (*pos) { delete *pos; }
00100     i++;
00101   }
00102 
00103 #ifdef G4GEOMETRY_VOXELDEBUG
00104   if (store->size() < i-1)
00105     { G4cout << "No solids deleted. Already deleted by user ?" << G4endl; }
00106   else
00107     { G4cout << i-1 << " solids deleted !" << G4endl; }
00108 #endif
00109 
00110   locked = false;
00111   store->clear();
00112 }
00113 
00114 // ***************************************************************************
00115 // Associate user notifier to the store
00116 // ***************************************************************************
00117 //
00118 void G4SolidStore::SetNotifier(G4VStoreNotifier* pNotifier)
00119 {
00120   GetInstance();
00121   fgNotifier = pNotifier;
00122 }
00123 
00124 // ***************************************************************************
00125 // Add Solid to container
00126 // ***************************************************************************
00127 //
00128 void G4SolidStore::Register(G4VSolid* pSolid)
00129 {
00130   GetInstance()->push_back(pSolid);
00131   if (fgNotifier) { fgNotifier->NotifyRegistration(); }
00132 }
00133 
00134 // ***************************************************************************
00135 // Remove Solid from container
00136 // ***************************************************************************
00137 //
00138 void G4SolidStore::DeRegister(G4VSolid* pSolid)
00139 {
00140   if (!locked)    // Do not de-register if locked !
00141   {
00142     if (fgNotifier) { fgNotifier->NotifyDeRegistration(); }
00143     for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
00144     {
00145       if (**i==*pSolid)
00146       {
00147         GetInstance()->erase(i);
00148         break;
00149       }
00150     }
00151   }
00152 }
00153 
00154 // ***************************************************************************
00155 // Retrieve the first solid pointer in the container having that name
00156 // ***************************************************************************
00157 //
00158 G4VSolid* G4SolidStore::GetSolid(const G4String& name, G4bool verbose) const
00159 {
00160   for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
00161   {
00162     if ((*i)->GetName() == name) { return *i; }
00163   }
00164   if (verbose)
00165   {
00166      std::ostringstream message;
00167      message << "Solid " << name << " not found in store !" << G4endl
00168              << "Returning NULL pointer.";
00169      G4Exception("G4SolidStore::GetSolid()",
00170                  "GeomMgt1001", JustWarning, message);
00171   }
00172   return 0;
00173 }
00174 
00175 // ***************************************************************************
00176 // Return ptr to Store, setting if necessary
00177 // ***************************************************************************
00178 //
00179 G4SolidStore* G4SolidStore::GetInstance()
00180 {
00181   static G4SolidStore worldStore;
00182   if (!fgInstance)
00183   {
00184     fgInstance = &worldStore;
00185   }
00186   return fgInstance;
00187 }

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