|
|
|||
File indexing completed on 2026-09-21 09:11:06
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 // G4RegionStore 0027 // 0028 // Class description: 0029 // 0030 // Container for all regions, with functionality derived from 0031 // std::vector<T>. The class is a 'singleton', in that only 0032 // one can exist, and access is provided via the static method 0033 // G4RegionStore::GetInstance(). 0034 // 0035 // All regions should be registered with G4RegionStore, and removed on their 0036 // destruction. The underlying container initially has a capacity of 20. 0037 // A map indexed by volume names is also recorded for fast search; 0038 // pointers to regions with same name are stored in buckets. 0039 // 0040 // If much additional functionality is added, should consider containment 0041 // instead of inheritance for std::vector<T>. 0042 0043 // Author: Gabriele Cosmo (CERN), 18.09.2002 0044 // -------------------------------------------------------------------- 0045 #ifndef G4REGIONSTORE_HH 0046 #define G4REGIONSTORE_HH 0047 0048 #include <vector> 0049 #include <map> 0050 0051 #include "G4Types.hh" 0052 #include "G4String.hh" 0053 #include "G4VStoreNotifier.hh" 0054 0055 class G4Region; 0056 class G4VPhysicalVolume; 0057 0058 /** 0059 * @brief G4RegionStore is a singleton class, acting as container 0060 * for all geometrical regions, with functionality derived from std::vector<T>. 0061 * All regions should be registered with G4RegionStore, and removed on their 0062 * destruction. The underlying container initially has a capacity of 20. 0063 * A map indexed by volume names is also recorded for fast search; pointers 0064 * to regions with same name are stored in buckets. 0065 */ 0066 0067 class G4RegionStore : public std::vector<G4Region*> 0068 { 0069 public: 0070 0071 /** 0072 * Destructor: takes care to delete allocated regions. 0073 */ 0074 virtual ~G4RegionStore(); 0075 0076 /** 0077 * Copy constructor and assignment operator not allowed. 0078 */ 0079 G4RegionStore(const G4RegionStore&) = delete; 0080 G4RegionStore& operator=(const G4RegionStore&) = delete; 0081 0082 /** 0083 * Adds the region 'pRegion' to the collection. 0084 */ 0085 static void Register(G4Region* pRegion); 0086 0087 /** 0088 * Removes the region 'pRegion' from the collection. 0089 */ 0090 static void DeRegister(G4Region* pRegion); 0091 0092 /** 0093 * Returns a pointer to the unique instance of G4RegionStore, 0094 * creating it if necessary. 0095 */ 0096 static G4RegionStore* GetInstance(); 0097 0098 /** 0099 * Assigns a notifier for allocation/deallocation of regions. 0100 */ 0101 static void SetNotifier(G4VStoreNotifier* pNotifier); 0102 0103 /** 0104 * Deletes all regions from the store, except for the world region. 0105 */ 0106 static void Clean(); 0107 0108 /** 0109 * Loops through all regions to verify if a region has been modified. 0110 * @returns true if just one region is modified. 0111 */ 0112 G4bool IsModified() const; 0113 0114 /** 0115 * Loops through all regions to reset the flag for modification to false. 0116 * Used by the run manager to notify that the physics table has been updated. 0117 */ 0118 void ResetRegionModified(); 0119 0120 /** 0121 * Forces recomputation of the material lists in all regions in the store. 0122 */ 0123 void UpdateMaterialList(G4VPhysicalVolume* currentWorld = nullptr); 0124 0125 /** 0126 * Returns a pointer to a region through its name specification. 0127 * It uses the internal map for fast search and warns if a region in the 0128 * collection is not unique or not found. 0129 */ 0130 G4Region* GetRegion(const G4String& name, G4bool verbose = true) const; 0131 0132 /** 0133 * Accessor and modifier to assess validity of the internal map. 0134 */ 0135 inline G4bool IsMapValid() const { return mvalid; } 0136 inline void SetMapValid(G4bool val) { mvalid = val; } 0137 0138 /** 0139 * Returns the internal map. 0140 */ 0141 inline const std::map<G4String, 0142 std::vector<G4Region*> >& GetMap() const { return bmap; } 0143 0144 /** 0145 * Brings contents of the internal map up to date and resets validity flag. 0146 */ 0147 void UpdateMap(); 0148 0149 /** 0150 * Returns a pointer to a region through its name specification, if it 0151 * exists. If it does not exist, it will allocate one, delegating ownership 0152 * to the client. 0153 */ 0154 G4Region* FindOrCreateRegion(const G4String& name); 0155 0156 /** 0157 * Sets a world volume pointer to a region that belongs to it. 0158 * Scans over all world volumes. This method should be exclusively 0159 * used by G4RunManagerKernel. 0160 */ 0161 void SetWorldVolume(); 0162 0163 protected: 0164 0165 /** 0166 * Protected singleton constructor. 0167 */ 0168 G4RegionStore(); 0169 0170 private: 0171 0172 static G4RegionStore* fgInstance; 0173 static G4ThreadLocal G4VStoreNotifier* fgNotifier; 0174 static G4ThreadLocal G4bool locked; 0175 0176 std::map<G4String, std::vector<G4Region*> > bmap; 0177 G4bool mvalid = false; // Flag to indicate if map is up to date or not 0178 }; 0179 0180 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|