Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:10:34

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 // Authors: Gabriele Cosmo & Paul Kent (CERN), 25.07.1995 - Initial version
0044 // --------------------------------------------------------------------
0045 #ifndef G4PHYSICALVOLUMESTORE_HH
0046 #define G4PHYSICALVOLUMESTORE_HH
0047 
0048 #include <vector>
0049 #include <map>
0050 
0051 #include "G4VPhysicalVolume.hh"
0052 #include "G4VStoreNotifier.hh"
0053 
0054 /**
0055  * @brief G4PhysicalVolumeStore is a singleton class, acting as container
0056  * for all physical volumes, with functionality derived from std::vector<T>.
0057  * All physical volumes should be registered with G4PhysicalVolumeStore, and
0058  * removed on their destruction. The underlying container initially has a
0059  * capacity of 100. A map indexed by volume names is also recorded for fast
0060  * search; pointers to volumes with same name are stored in buckets.
0061 */
0062 
0063 class G4PhysicalVolumeStore : public std::vector<G4VPhysicalVolume*>
0064 {
0065   public:
0066 
0067     /**
0068      * Destructor: takes care to delete allocated physical volumes.
0069      */
0070     virtual ~G4PhysicalVolumeStore();
0071 
0072     /**
0073      * Copy constructor and assignment operator not allowed.
0074      */
0075     G4PhysicalVolumeStore(const G4PhysicalVolumeStore&) = delete;
0076     G4PhysicalVolumeStore& operator=(const G4PhysicalVolumeStore&) = delete;
0077 
0078     /**
0079      * Adds the logical volume 'pVolume' to the collection.
0080      */
0081     static void Register(G4VPhysicalVolume* pVolume);
0082 
0083     /**
0084      * Removes the logical volume 'pVolume' from the collection.
0085      */
0086     static void DeRegister(G4VPhysicalVolume* pVolume);
0087 
0088     /**
0089      * Returns a pointer to the unique instance of G4PhysicalVolumeStore,
0090      * creating it if necessary.
0091      */
0092     static G4PhysicalVolumeStore* GetInstance();
0093 
0094     /**
0095      * Assigns a notifier for allocation/deallocation of the physical volumes.
0096      */
0097     static void SetNotifier(G4VStoreNotifier* pNotifier);
0098 
0099     /**
0100      * Deletes all physical volumes from the store. Mother logical volumes
0101      * are automatically notified and have their daughters de-registered.
0102      */
0103     static void Clean();
0104 
0105     /**
0106      * Returns a pointer to the first or last volume in the collection having
0107      * that 'name'. Uses the internal map for fast search and warns if
0108      * a volume in the collection is not unique or not found.
0109      *  @param[in] name The name of the volume to search.
0110      *  @param[in] verbose Flag for enabling verbosity (default true).
0111      *  @param[in] reverseSearch Flag to enable inverse search (default false).
0112      */
0113     G4VPhysicalVolume* GetVolume(const G4String& name,
0114                                  G4bool verbose = true,
0115                                  G4bool reverseSearch = false) const;
0116 
0117     /**
0118      * Accessor and modifier to assess validity of the internal map.
0119      */
0120     inline G4bool IsMapValid() const  { return mvalid; }
0121     inline void SetMapValid(G4bool val)  { mvalid = val; }
0122 
0123     /**
0124      * Return the internal map.
0125      */
0126     inline const std::map<G4String,
0127             std::vector<G4VPhysicalVolume*> >& GetMap() const { return bmap; }
0128 
0129     /**
0130      * Brings contents of the internal map up to date and resets validity flag.
0131      */
0132     void UpdateMap();
0133 
0134   protected:
0135 
0136     /**
0137      * Protected constructor.
0138      */
0139     G4PhysicalVolumeStore();
0140 
0141   private:
0142 
0143     static G4PhysicalVolumeStore* fgInstance;
0144     static G4ThreadLocal G4VStoreNotifier* fgNotifier;
0145     static G4ThreadLocal G4bool locked;
0146 
0147     std::map<G4String, std::vector<G4VPhysicalVolume*> > bmap;
0148     G4bool mvalid = false;  // Flag to indicate if map is up to date or not
0149 };
0150 
0151 #endif