G4FieldManagerStore.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: G4FieldManagerStore.cc 69786 2013-05-15 09:38:51Z gcosmo $
00028 //
00029 // G4FieldManagerStore
00030 //
00031 // Implementation for singleton container
00032 //
00033 // History:
00034 // 07.12.07 J.Apostolakis Adapted from G4LogicalVolumeStore
00035 // --------------------------------------------------------------------
00036 
00037 #include "G4Types.hh"
00038 #include "G4FieldManagerStore.hh"
00039 #include "G4ChordFinder.hh" 
00040 
00041 // ***************************************************************************
00042 // Static class variables
00043 // ***************************************************************************
00044 //
00045 G4FieldManagerStore* G4FieldManagerStore::fgInstance = 0;
00046 G4bool G4FieldManagerStore::locked = false;
00047 
00048 // ***************************************************************************
00049 // Protected constructor: Construct underlying container with
00050 // initial size of 100 entries
00051 // ***************************************************************************
00052 //
00053 G4FieldManagerStore::G4FieldManagerStore()
00054  : std::vector<G4FieldManager*>()
00055 {
00056   reserve(100);
00057 }
00058 
00059 // ***************************************************************************
00060 // Destructor
00061 // ***************************************************************************
00062 //
00063 G4FieldManagerStore::~G4FieldManagerStore()
00064 {
00065   Clean();
00066 }
00067 
00068 // ***************************************************************************
00069 // Delete all elements from the store
00070 // ***************************************************************************
00071 //
00072 void G4FieldManagerStore::Clean()
00073 {
00074   // Locks store for deletion of field managers. De-registration will be
00075   // performed at this stage. G4FieldManagers will not de-register themselves.
00076   //
00077   locked = true;  
00078 
00079   size_t i=0;
00080   G4FieldManagerStore* store = GetInstance();
00081 
00082   for(iterator pos=store->begin(); pos!=store->end(); pos++)
00083   {
00084     if (*pos) { delete *pos; }
00085     i++;
00086   }
00087 
00088 #ifdef G4GEOMETRY_DEBUG
00089   if (store->size() < i-1)
00090     { G4cout << "No field managers deleted. Already deleted by user ?" << G4endl; }
00091   else
00092     { G4cout << i-1 << " field managers deleted !" << G4endl; }
00093 #endif
00094 
00095   locked = false;
00096   store->clear();
00097 }
00098 
00099 // ***************************************************************************
00100 // Add field manager to container
00101 // ***************************************************************************
00102 //
00103 void G4FieldManagerStore::Register(G4FieldManager* pFieldManager)
00104 {
00105   GetInstance()->push_back(pFieldManager);
00106 }
00107 
00108 // ***************************************************************************
00109 // Remove volume from container
00110 // ***************************************************************************
00111 //
00112 void G4FieldManagerStore::DeRegister(G4FieldManager* pFieldMgr)
00113 {
00114   if (!locked)    // Do not de-register if locked !
00115   {
00116     for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
00117     {
00118       if (*i==pFieldMgr)  //   For LogVol was **i == *pLogVolume ... Reason?
00119       {
00120         GetInstance()->erase(i);
00121         break;
00122       }
00123     }
00124   }
00125 }
00126 
00127 // ***************************************************************************
00128 // Return ptr to Store, setting if necessary
00129 // ***************************************************************************
00130 //
00131 G4FieldManagerStore* G4FieldManagerStore::GetInstance()
00132 {
00133   static G4FieldManagerStore worldStore;
00134   if (!fgInstance)
00135   {
00136     fgInstance = &worldStore;
00137   }
00138   return fgInstance;
00139 }
00140 
00141 // ***************************************************************************
00142 // Globally reset the state
00143 // ***************************************************************************
00144 //
00145 void
00146 G4FieldManagerStore::ClearAllChordFindersState()
00147 {
00148   G4ChordFinder *pChordFnd;
00149    
00150   for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
00151   {
00152     pChordFnd = (*i)->GetChordFinder();
00153     if( pChordFnd )
00154     {
00155       pChordFnd->ResetStepEstimate();
00156     }
00157   }
00158 }

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