Back to home page

EIC code displayed by LXR

 
 

    


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

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