Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:55

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 // G4PhysicalVolumeStore
0027 //
0028 // Class description:
0029 //
0030 // Container for all physical volumes, 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 // G4PhysicalVolumeStore::GetInstance()
0034 //
0035 // All volumes should be registered with G4PhysicalVolumeStore, and removed on
0036 // their destruction. The underlying container initially has a capacity of 100.
0037 // A map indexed by volume names is also recorded for fast search;
0038 // pointers to volumes 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 // 25.07.95, P.Kent, G.Cosmo - Initial version
0044 // --------------------------------------------------------------------
0045 #ifndef G4PHYSICALVOLUMESTORE_HH
0046 #define G4PHYSICALVOLUMESTORE_HH 1
0047 
0048 #include <vector>
0049 #include <map>
0050 
0051 #include "G4VPhysicalVolume.hh"
0052 #include "G4VStoreNotifier.hh"
0053 
0054 class G4PhysicalVolumeStore : public std::vector<G4VPhysicalVolume*>
0055 {
0056   public:
0057 
0058     static void Register(G4VPhysicalVolume* pSolid);
0059       // Add the volume to the collection.
0060     static void DeRegister(G4VPhysicalVolume* pSolid);
0061       // Remove the volume from the collection.
0062     static G4PhysicalVolumeStore* GetInstance();
0063       // Get a ptr to the unique store instance, creating it if necessary.
0064     static void SetNotifier(G4VStoreNotifier* pNotifier);
0065       // Assign a notifier for allocation/deallocation of the physical volumes.
0066     static void Clean();
0067       // Delete all physical volumes from the store. Mother logical volumes
0068       // are automatically notified and have their daughters de-registered.
0069 
0070     G4VPhysicalVolume* GetVolume(const G4String& name,
0071                                  G4bool verbose = true,
0072                                  G4bool reverseSearch = false) const;
0073       // Return the pointer of the first or last volume in the collection having
0074       // that name. Uses the internal map for fast search and warns if
0075       // a volume in the collection is not unique or not found.
0076 
0077     inline G4bool IsMapValid() const  { return mvalid; }
0078     inline void SetMapValid(G4bool val)  { mvalid = val; }
0079       // Accessor to assess validity of the internal map.
0080     inline const std::map<G4String,
0081             std::vector<G4VPhysicalVolume*> >& GetMap() const { return bmap; }
0082       // Return the internal map.
0083     void UpdateMap();
0084       // Bring contents of internal map up to date and resets validity flag.
0085 
0086     virtual ~G4PhysicalVolumeStore();
0087       // Destructor: takes care to delete allocated physical volumes.
0088 
0089     G4PhysicalVolumeStore(const G4PhysicalVolumeStore&) = delete;
0090     G4PhysicalVolumeStore& operator=(const G4PhysicalVolumeStore&) = delete;
0091       // Forbidden copy constructor and assignment operator
0092 
0093   protected:
0094 
0095     G4PhysicalVolumeStore();
0096 
0097   private:
0098 
0099     static G4PhysicalVolumeStore* fgInstance;
0100     static G4ThreadLocal G4VStoreNotifier* fgNotifier;
0101     static G4ThreadLocal G4bool locked;
0102 
0103     std::map<G4String, std::vector<G4VPhysicalVolume*> > bmap;
0104     G4bool mvalid = false;  // Flag to indicate if map is up to date or not
0105 };
0106 
0107 #endif