|
||||
Warning, file /include/Geant4/G4NavigationHistoryPool.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4NavigationHistoryPool 0027 // 0028 // Class description: 0029 // 0030 // Thread-local pool for navigation history levels collections being 0031 // allocated by G4NavigationHistory. Allows for reuse of the vectors 0032 // allocated according to lifetime of G4NavigationHistory objects. 0033 0034 // 07.05.14 G.Cosmo Initial version 0035 // -------------------------------------------------------------------- 0036 #ifndef G4NAVIGATIONHISTORYPOOL_HH 0037 #define G4NAVIGATIONHISTORYPOOL_HH 0038 0039 #include <vector> 0040 0041 #include "G4NavigationLevel.hh" 0042 0043 class G4NavigationHistoryPool 0044 { 0045 public: 0046 0047 static G4NavigationHistoryPool* GetInstance(); 0048 // Return unique instance of G4NavigationHistoryPool. 0049 0050 inline std::vector<G4NavigationLevel> * GetNewLevels(); 0051 // Return the pointer to a new collection of levels being allocated. 0052 0053 inline std::vector<G4NavigationLevel> * GetLevels(); 0054 // Return the pointer of the first available collection of levels 0055 // If none are available (i.e. empty Free vector) allocate collection. 0056 0057 inline void DeRegister(std::vector<G4NavigationLevel> * pLevels); 0058 // Deactivate levels collection in pool. 0059 0060 void Clean(); 0061 // Delete all levels stored in the pool. 0062 0063 void Print() const; 0064 // Print number of entries. 0065 0066 ~G4NavigationHistoryPool(); 0067 // Destructor: takes care to delete allocated levels. 0068 0069 private: 0070 0071 G4NavigationHistoryPool(); 0072 // Default constructor. 0073 0074 inline void Register(std::vector<G4NavigationLevel> * pLevels); 0075 // Register levels collection to pool and activate it. 0076 0077 void Reset(); 0078 // Set internal vectors content to zero. 0079 0080 private: 0081 0082 static G4ThreadLocal G4NavigationHistoryPool* fgInstance; 0083 0084 std::vector<std::vector<G4NavigationLevel> *> fPool; 0085 std::vector<std::vector<G4NavigationLevel> *> fFree; 0086 }; 0087 0088 // *************************************************************************** 0089 // Register levels collection to pool (add and/or activate) 0090 // *************************************************************************** 0091 // 0092 inline void G4NavigationHistoryPool:: 0093 Register(std::vector<G4NavigationLevel> * pLevels) 0094 { 0095 fPool.push_back(pLevels); 0096 } 0097 0098 // *************************************************************************** 0099 // Deactivate levels collection in pool 0100 // *************************************************************************** 0101 // 0102 inline void G4NavigationHistoryPool:: 0103 DeRegister(std::vector<G4NavigationLevel> * pLevels) 0104 { 0105 fFree.push_back(pLevels); 0106 } 0107 0108 // *************************************************************************** 0109 // Return the pointer of a new collection of levels allocated 0110 // *************************************************************************** 0111 // 0112 inline std::vector<G4NavigationLevel> * G4NavigationHistoryPool::GetNewLevels() 0113 { 0114 auto aLevelVec = new std::vector<G4NavigationLevel>(kHistoryMax); 0115 Register(aLevelVec); 0116 0117 return aLevelVec; 0118 } 0119 0120 // *************************************************************************** 0121 // Return the pointer of the first available collection of levels 0122 // If none are available (i.e. non active) allocate collection 0123 // *************************************************************************** 0124 // 0125 inline std::vector<G4NavigationLevel> * G4NavigationHistoryPool::GetLevels() 0126 { 0127 std::vector<G4NavigationLevel> * levels = nullptr; 0128 0129 if (!fFree.empty()) 0130 { 0131 levels = fFree.back(); 0132 fFree.pop_back(); 0133 } 0134 else 0135 { 0136 levels = GetNewLevels(); 0137 } 0138 0139 return levels; 0140 } 0141 0142 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |