Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4FieldManagerStore implementation 26 // G4FieldManagerStore implementation 27 // 27 // 28 // Author: J.Apostolakis, 07.12.2007 - Adapted 28 // Author: J.Apostolakis, 07.12.2007 - Adapted from G4LogicalVolumeStore 29 // ------------------------------------------- 29 // -------------------------------------------------------------------- 30 30 31 #include "G4Types.hh" 31 #include "G4Types.hh" 32 #include "G4FieldManagerStore.hh" 32 #include "G4FieldManagerStore.hh" 33 #include "G4ChordFinder.hh" 33 #include "G4ChordFinder.hh" 34 34 35 // ******************************************* 35 // *************************************************************************** 36 // Static class variables 36 // Static class variables 37 // ******************************************* 37 // *************************************************************************** 38 // 38 // 39 G4ThreadLocal G4FieldManagerStore* G4FieldMana 39 G4ThreadLocal G4FieldManagerStore* G4FieldManagerStore::fgInstance = nullptr; 40 G4ThreadLocal G4bool G4FieldManagerStore::lock 40 G4ThreadLocal G4bool G4FieldManagerStore::locked = false; 41 41 42 // ******************************************* 42 // *************************************************************************** 43 // Protected constructor: Construct underlying 43 // Protected constructor: Construct underlying container with 44 // initial size of 100 entries 44 // initial size of 100 entries 45 // ******************************************* 45 // *************************************************************************** 46 // 46 // 47 G4FieldManagerStore::G4FieldManagerStore() 47 G4FieldManagerStore::G4FieldManagerStore() >> 48 : std::vector<G4FieldManager*>() 48 { 49 { 49 reserve(100); 50 reserve(100); 50 } 51 } 51 52 52 // ******************************************* 53 // *************************************************************************** 53 // Destructor 54 // Destructor 54 // ******************************************* 55 // *************************************************************************** 55 // 56 // 56 G4FieldManagerStore::~G4FieldManagerStore() 57 G4FieldManagerStore::~G4FieldManagerStore() 57 { 58 { 58 Clean(); 59 Clean(); 59 fgInstance = nullptr; 60 fgInstance = nullptr; 60 } 61 } 61 62 62 // ******************************************* 63 // *************************************************************************** 63 // Delete all elements from the store 64 // Delete all elements from the store 64 // ******************************************* 65 // *************************************************************************** 65 // 66 // 66 void G4FieldManagerStore::Clean() 67 void G4FieldManagerStore::Clean() 67 { 68 { 68 // Locks store for deletion of field manager 69 // Locks store for deletion of field managers. De-registration will be 69 // performed at this stage. G4FieldManagers 70 // performed at this stage. G4FieldManagers will not de-register themselves. 70 // 71 // 71 locked = true; 72 locked = true; 72 73 >> 74 size_t i=0; 73 G4FieldManagerStore* store = GetInstance(); 75 G4FieldManagerStore* store = GetInstance(); 74 76 75 for(const auto & pos : *store) << 77 for(auto pos=store->cbegin(); pos!=store->cend(); ++pos) 76 { 78 { 77 delete pos; << 79 if (*pos) { delete *pos; } >> 80 i++; 78 } 81 } 79 82 >> 83 #ifdef G4GEOMETRY_DEBUG >> 84 if (store->size() < i-1) >> 85 { >> 86 G4cout << "No field managers deleted. Already deleted by user ?" << G4endl; >> 87 } >> 88 else >> 89 { >> 90 G4cout << i-1 << " field managers deleted !" << G4endl; >> 91 } >> 92 #endif >> 93 80 locked = false; 94 locked = false; 81 store->clear(); 95 store->clear(); 82 } 96 } 83 97 84 // ******************************************* 98 // *************************************************************************** 85 // Add field manager to container 99 // Add field manager to container 86 // ******************************************* 100 // *************************************************************************** 87 // 101 // 88 void G4FieldManagerStore::Register(G4FieldMana 102 void G4FieldManagerStore::Register(G4FieldManager* pFieldManager) 89 { 103 { 90 GetInstance()->push_back(pFieldManager); 104 GetInstance()->push_back(pFieldManager); 91 } 105 } 92 106 93 // ******************************************* 107 // *************************************************************************** 94 // Remove volume from container 108 // Remove volume from container 95 // ******************************************* 109 // *************************************************************************** 96 // 110 // 97 void G4FieldManagerStore::DeRegister(G4FieldMa 111 void G4FieldManagerStore::DeRegister(G4FieldManager* pFieldMgr) 98 { 112 { 99 if (!locked) // Do not de-register if loc 113 if (!locked) // Do not de-register if locked ! 100 { 114 { 101 for (auto i=GetInstance()->cbegin(); i!=Ge 115 for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i) 102 { 116 { 103 if (*i==pFieldMgr) // For LogVol was 117 if (*i==pFieldMgr) // For LogVol was **i == *pLogVolume ... Reason? 104 { 118 { 105 GetInstance()->erase(i); 119 GetInstance()->erase(i); 106 break; 120 break; 107 } 121 } 108 } 122 } 109 } 123 } 110 } 124 } 111 125 112 // ******************************************* 126 // *************************************************************************** 113 // Return ptr to Store, setting if necessary 127 // Return ptr to Store, setting if necessary 114 // ******************************************* 128 // *************************************************************************** 115 // 129 // 116 G4FieldManagerStore* G4FieldManagerStore::GetI 130 G4FieldManagerStore* G4FieldManagerStore::GetInstance() 117 { 131 { 118 if (fgInstance == nullptr) 132 if (fgInstance == nullptr) 119 { 133 { 120 fgInstance = new G4FieldManagerStore; 134 fgInstance = new G4FieldManagerStore; 121 } 135 } 122 return fgInstance; 136 return fgInstance; 123 } 137 } 124 138 125 // ******************************************* 139 // *************************************************************************** 126 // Return ptr to Store 140 // Return ptr to Store 127 // ******************************************* 141 // *************************************************************************** 128 // 142 // 129 G4FieldManagerStore* G4FieldManagerStore::GetI 143 G4FieldManagerStore* G4FieldManagerStore::GetInstanceIfExist() 130 { 144 { 131 return fgInstance; 145 return fgInstance; 132 } 146 } 133 147 134 // ******************************************* 148 // *************************************************************************** 135 // Globally reset the state 149 // Globally reset the state 136 // ******************************************* 150 // *************************************************************************** 137 // 151 // 138 void 152 void 139 G4FieldManagerStore::ClearAllChordFindersState 153 G4FieldManagerStore::ClearAllChordFindersState() 140 { 154 { 141 G4ChordFinder* pChordFnd; 155 G4ChordFinder* pChordFnd; 142 156 143 for (const auto & mgr : *GetInstance()) << 157 for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i) 144 { 158 { 145 pChordFnd = mgr->GetChordFinder(); << 159 pChordFnd = (*i)->GetChordFinder(); 146 if( pChordFnd != nullptr ) 160 if( pChordFnd != nullptr ) 147 { 161 { 148 pChordFnd->ResetStepEstimate(); 162 pChordFnd->ResetStepEstimate(); 149 } 163 } 150 } 164 } 151 } 165 } 152 166