| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4PhysicalVolumeStore.cc,v 1.19 2007/04/10 10:13:50 gcosmo Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | // G4PhysicalVolumeStore
|
|---|
| 31 | //
|
|---|
| 32 | // Implementation for singleton container
|
|---|
| 33 | //
|
|---|
| 34 | // History:
|
|---|
| 35 | // 25.07.95 P.Kent Initial version
|
|---|
| 36 | // --------------------------------------------------------------------
|
|---|
| 37 |
|
|---|
| 38 | #include "G4Types.hh"
|
|---|
| 39 | #include "G4PhysicalVolumeStore.hh"
|
|---|
| 40 | #include "G4GeometryManager.hh"
|
|---|
| 41 | #include "G4LogicalVolume.hh"
|
|---|
| 42 |
|
|---|
| 43 | // ***************************************************************************
|
|---|
| 44 | // Static class variables
|
|---|
| 45 | // ***************************************************************************
|
|---|
| 46 | //
|
|---|
| 47 | G4PhysicalVolumeStore* G4PhysicalVolumeStore::fgInstance = 0;
|
|---|
| 48 | G4VStoreNotifier* G4PhysicalVolumeStore::fgNotifier = 0;
|
|---|
| 49 | G4bool G4PhysicalVolumeStore::locked = false;
|
|---|
| 50 |
|
|---|
| 51 | // ***************************************************************************
|
|---|
| 52 | // Protected constructor: Construct underlying container with
|
|---|
| 53 | // initial size of 100 entries
|
|---|
| 54 | // ***************************************************************************
|
|---|
| 55 | //
|
|---|
| 56 | G4PhysicalVolumeStore::G4PhysicalVolumeStore()
|
|---|
| 57 | : std::vector<G4VPhysicalVolume*>()
|
|---|
| 58 | {
|
|---|
| 59 | reserve(100);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | // ***************************************************************************
|
|---|
| 63 | // Destructor
|
|---|
| 64 | // ***************************************************************************
|
|---|
| 65 | //
|
|---|
| 66 | G4PhysicalVolumeStore::~G4PhysicalVolumeStore()
|
|---|
| 67 | {
|
|---|
| 68 | Clean();
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | // ***************************************************************************
|
|---|
| 72 | // Delete all elements from the store
|
|---|
| 73 | // ***************************************************************************
|
|---|
| 74 | //
|
|---|
| 75 | void G4PhysicalVolumeStore::Clean(G4bool notifyLV)
|
|---|
| 76 | {
|
|---|
| 77 | // Do nothing if geometry is closed
|
|---|
| 78 | //
|
|---|
| 79 | if (G4GeometryManager::GetInstance()->IsGeometryClosed())
|
|---|
| 80 | {
|
|---|
| 81 | G4cout << "WARNING - Attempt to delete the physical volume store"
|
|---|
| 82 | << " while geometry closed !" << G4endl;
|
|---|
| 83 | return;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | // Locks store for deletion of volumes. De-registration will be
|
|---|
| 87 | // performed at this stage. G4VPhysicalVolumes will not de-register
|
|---|
| 88 | // themselves.
|
|---|
| 89 | //
|
|---|
| 90 | locked = true;
|
|---|
| 91 |
|
|---|
| 92 | size_t i=0;
|
|---|
| 93 | G4PhysicalVolumeStore* store = GetInstance();
|
|---|
| 94 | std::vector<G4VPhysicalVolume*>::iterator pos;
|
|---|
| 95 |
|
|---|
| 96 | #ifdef G4GEOMETRY_VOXELDEBUG
|
|---|
| 97 | G4cout << "Deleting Physical Volumes ... ";
|
|---|
| 98 | #endif
|
|---|
| 99 |
|
|---|
| 100 | if (notifyLV)
|
|---|
| 101 | {
|
|---|
| 102 | for(pos=store->begin(); pos!=store->end(); pos++)
|
|---|
| 103 | {
|
|---|
| 104 | if (*pos) { (*pos)->GetLogicalVolume()->ClearDaughters(); }
|
|---|
| 105 | }
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | for(pos=store->begin(); pos!=store->end(); pos++)
|
|---|
| 109 | {
|
|---|
| 110 | if (fgNotifier) { fgNotifier->NotifyDeRegistration(); }
|
|---|
| 111 | if (*pos) { delete *pos; }
|
|---|
| 112 | i++;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | #ifdef G4GEOMETRY_VOXELDEBUG
|
|---|
| 116 | if (store->size() < i-1)
|
|---|
| 117 | { G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
|
|---|
| 118 | else
|
|---|
| 119 | { G4cout << i-1 << " volumes deleted !" << G4endl; }
|
|---|
| 120 | #endif
|
|---|
| 121 |
|
|---|
| 122 | locked = false;
|
|---|
| 123 | store->clear();
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | // ***************************************************************************
|
|---|
| 127 | // Associate user notifier to the store
|
|---|
| 128 | // ***************************************************************************
|
|---|
| 129 | //
|
|---|
| 130 | void G4PhysicalVolumeStore::SetNotifier(G4VStoreNotifier* pNotifier)
|
|---|
| 131 | {
|
|---|
| 132 | GetInstance();
|
|---|
| 133 | fgNotifier = pNotifier;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | // ***************************************************************************
|
|---|
| 137 | // Add Volume to container
|
|---|
| 138 | // ***************************************************************************
|
|---|
| 139 | //
|
|---|
| 140 | void G4PhysicalVolumeStore::Register(G4VPhysicalVolume* pVolume)
|
|---|
| 141 | {
|
|---|
| 142 | GetInstance()->push_back(pVolume);
|
|---|
| 143 | if (fgNotifier) { fgNotifier->NotifyRegistration(); }
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | // ***************************************************************************
|
|---|
| 147 | // Remove Volume from container and update the list of daughters
|
|---|
| 148 | // of the mother's logical volume
|
|---|
| 149 | // ***************************************************************************
|
|---|
| 150 | //
|
|---|
| 151 | void G4PhysicalVolumeStore::DeRegister(G4VPhysicalVolume* pVolume)
|
|---|
| 152 | {
|
|---|
| 153 | if (!locked) // Do not de-register if locked !
|
|---|
| 154 | {
|
|---|
| 155 | if (fgNotifier) { fgNotifier->NotifyDeRegistration(); }
|
|---|
| 156 | G4LogicalVolume* motherLogical = pVolume->GetMotherLogical();
|
|---|
| 157 | if (motherLogical) { motherLogical->RemoveDaughter(pVolume); }
|
|---|
| 158 | for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
|
|---|
| 159 | {
|
|---|
| 160 | if (**i==*pVolume)
|
|---|
| 161 | {
|
|---|
| 162 | GetInstance()->erase(i);
|
|---|
| 163 | break;
|
|---|
| 164 | }
|
|---|
| 165 | }
|
|---|
| 166 | }
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | // ***************************************************************************
|
|---|
| 170 | // Retrieve the first volume pointer in the container having that name
|
|---|
| 171 | // ***************************************************************************
|
|---|
| 172 | //
|
|---|
| 173 | G4VPhysicalVolume*
|
|---|
| 174 | G4PhysicalVolumeStore::GetVolume(const G4String& name, G4bool verbose) const
|
|---|
| 175 | {
|
|---|
| 176 | for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
|
|---|
| 177 | {
|
|---|
| 178 | if ((*i)->GetName() == name) { return *i; }
|
|---|
| 179 | }
|
|---|
| 180 | if (verbose)
|
|---|
| 181 | {
|
|---|
| 182 | G4cerr << "ERROR - G4PhysicalVolumeStore::GetVolume()" << G4endl
|
|---|
| 183 | << " Volume " << name << " NOT found in store !" << G4endl
|
|---|
| 184 | << " Returning NULL pointer." << G4endl;
|
|---|
| 185 | G4Exception("G4PhysicalVolumeStore::GetVolume()", "InvalidQuery",
|
|---|
| 186 | JustWarning, "Volume NOT found in store !");
|
|---|
| 187 | }
|
|---|
| 188 | return 0;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | // ***************************************************************************
|
|---|
| 192 | // Return ptr to Store, setting if necessary
|
|---|
| 193 | // ***************************************************************************
|
|---|
| 194 | //
|
|---|
| 195 | G4PhysicalVolumeStore* G4PhysicalVolumeStore::GetInstance()
|
|---|
| 196 | {
|
|---|
| 197 | static G4PhysicalVolumeStore worldStore;
|
|---|
| 198 | if (!fgInstance)
|
|---|
| 199 | {
|
|---|
| 200 | fgInstance = &worldStore;
|
|---|
| 201 | }
|
|---|
| 202 | return fgInstance;
|
|---|
| 203 | }
|
|---|