Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:02

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 // 18.09.02, G.Cosmo - Initial version
0044 // --------------------------------------------------------------------
0045 #ifndef G4REGIONSTORE_HH
0046 #define G4REGIONSTORE_HH 1
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 class G4RegionStore : public std::vector<G4Region*>
0059 {
0060   public:
0061 
0062     static void Register(G4Region* pRegion);
0063       // Add the region to the collection.
0064     static void DeRegister(G4Region* pRegion);
0065       // Remove the region from the collection.
0066     static G4RegionStore* GetInstance();
0067       // Get a ptr to the unique G4RegionStore, creating it if necessary.
0068     static void SetNotifier(G4VStoreNotifier* pNotifier);
0069       // Assign a notifier for allocation/deallocation of regions.
0070     static void Clean();
0071       // Delete all regions from the store except for the world region.
0072 
0073     G4bool IsModified() const;
0074       // Loops through all regions to verify if a region has been
0075       // modified. It returns TRUE if just one region is modified.
0076     void ResetRegionModified();
0077       // Loops through all regions to reset flag for modification
0078       // to FALSE. Used by the run manager to notify that the
0079       // physics table has been updated.
0080 
0081     void UpdateMaterialList(G4VPhysicalVolume* currentWorld=nullptr);
0082       // Forces recomputation of material lists in all regions
0083       // in the store.
0084 
0085     G4Region* GetRegion(const G4String& name, G4bool verbose = true) const;
0086       // Returns a region through its name specification. Uses the internal
0087       // map for fast search and warns if a region in the collection is not
0088       // unique or not found.
0089 
0090     inline G4bool IsMapValid() const  { return mvalid; }
0091     inline void SetMapValid(G4bool val)  { mvalid = val; }
0092       // Accessor to assess validity of the internal map.
0093     inline const std::map<G4String,
0094             std::vector<G4Region*> >& GetMap() const { return bmap; }
0095       // Return the internal map.
0096     void UpdateMap();
0097       // Bring contents of internal map up to date and resets validity flag.
0098 
0099     G4Region* FindOrCreateRegion(const G4String& name);
0100       // Returns a region through its name specification, if it exists.
0101       // If it does not exist it will allocate one delegating ownership
0102       // to the client.
0103 
0104     void SetWorldVolume();
0105       // Set a world volume pointer to a region that belongs to it.
0106       // Scan over all world volumes.
0107       // This method should be exclusively used by G4RunManagerKernel.
0108 
0109     virtual ~G4RegionStore();
0110       // Destructor: takes care to delete allocated regions.
0111 
0112     G4RegionStore(const G4RegionStore&) = delete;
0113     G4RegionStore& operator=(const G4RegionStore&) = delete;
0114       // Forbidden copy constructor and assignment operator
0115 
0116   protected:
0117 
0118     G4RegionStore();
0119       // Protected singleton constructor.
0120 
0121   private:
0122 
0123     static G4RegionStore* fgInstance;
0124     static G4ThreadLocal G4VStoreNotifier* fgNotifier;
0125     static G4ThreadLocal G4bool locked;
0126 
0127     std::map<G4String, std::vector<G4Region*> > bmap;
0128     G4bool mvalid = false;  // Flag to indicate if map is up to date or not
0129 };
0130 
0131 #endif