Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-03 09:17:33

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 // G4LogicalVolumeStore
0027 //
0028 // Class description:
0029 //
0030 // Container for all logical 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 function
0033 // G4LogicalVolumeStore::GetInstance()
0034 //
0035 // All logical volumes should be registered with G4LogicalVolumeStore,
0036 // and removed on their destruction.
0037 // The underlying container initially has a capacity of 100.
0038 // A map indexed by volume names is also recorded for fast search;
0039 // pointers to volumes with same name are stored in buckets.
0040 //
0041 // If much additional functionality is added, should consider containment
0042 // instead of inheritance for std::vector<T>.
0043 
0044 // Authors: Gabriele Cosmo & Paul Kent (CERN), 10.07.1995 - Initial version
0045 // --------------------------------------------------------------------
0046 #ifndef G4LOGICALVOLUMESTORE_HH
0047 #define G4LOGICALVOLUMESTORE_HH
0048 
0049 #include <vector>
0050 #include <map>
0051 
0052 #include "G4LogicalVolume.hh"
0053 #include "G4VStoreNotifier.hh"
0054 
0055 /**
0056  * @brief G4LogicalVolumeStore is a singleton class, acting as container
0057  * for all logical volumes, with functionality derived from std::vector<T>.
0058  * All logical volumes should be registered with G4LogicalVolumeStore,
0059  * and removed on their destruction. The underlying container initially has
0060  * a capacity of 100. A map indexed by volume names is also recorded for fast
0061  * search; pointers to volumes with same name are stored in buckets.
0062 */
0063 
0064 class G4LogicalVolumeStore : public std::vector<G4LogicalVolume*>
0065 {
0066   public:
0067 
0068     /**
0069      * Destructor: takes care to delete allocated logical volumes.
0070      */
0071     virtual ~G4LogicalVolumeStore();
0072 
0073     /**
0074      * Copy constructor and assignment operator not allowed.
0075      */
0076     G4LogicalVolumeStore(const G4LogicalVolumeStore&) = delete;
0077     G4LogicalVolumeStore& operator=(const G4LogicalVolumeStore&) = delete;
0078 
0079     /**
0080      * Adds the logical volume 'pVolume' to the collection.
0081      */
0082     static void Register(G4LogicalVolume* pVolume);
0083 
0084     /**
0085      * Removes the logical volume 'pVolume' from the collection.
0086      */
0087     static void DeRegister(G4LogicalVolume* pVolume);
0088 
0089     /**
0090      * Returns a pointer to the unique instance of G4LogicalVolumeStore,
0091      * creating it if necessary.
0092      */
0093     static G4LogicalVolumeStore* GetInstance();
0094 
0095     /**
0096      * Assigns a notifier for allocation/deallocation of the logical volumes.
0097      */
0098     static void SetNotifier(G4VStoreNotifier* pNotifier);
0099 
0100     /**
0101      * Deletes all volumes from the store.
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     G4LogicalVolume* GetVolume(const G4String& name, G4bool verbose=true,
0114                                G4bool reverseSearch=false) const;
0115 
0116     /**
0117      * Accessor and modifier to assess validity of the internal map.
0118      */
0119     inline G4bool IsMapValid() const { return mvalid; }
0120     inline void SetMapValid(G4bool val) { mvalid = val; }
0121 
0122     /**
0123      * Returns the internal map.
0124      */
0125     inline const std::map<G4String,
0126             std::vector<G4LogicalVolume*> >& GetMap() const { return bmap; }
0127 
0128     /**
0129      * Brings contents of the internal map up to date and resets validity flag.
0130      */
0131     void UpdateMap();
0132 
0133   protected:
0134 
0135     /**
0136      * Protected singleton constructor.
0137      */
0138     G4LogicalVolumeStore();
0139 
0140   private:
0141 
0142     static G4LogicalVolumeStore* fgInstance;
0143     static G4ThreadLocal G4VStoreNotifier* fgNotifier;
0144     static G4ThreadLocal G4bool locked;
0145 
0146     std::map<G4String, std::vector<G4LogicalVolume*> > bmap;
0147     G4bool mvalid = false;  // Flag to indicate if map is up to date or not
0148 };
0149 
0150 #endif