Geant4  10.00.p02
G4PhysicsTable.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4PhysicsTable.hh 67970 2013-03-13 10:10:06Z gcosmo $
28 //
29 //
30 // ------------------------------------------------------------
31 // GEANT 4 class header file
32 //
33 // Class description:
34 //
35 // G4PhysicsTable is an utility class for storage of pointers
36 // to G4PhysicsVector containers. It derives all functionalities
37 // of STL vector containers with the addition of few methods for
38 // compatibility with previous implementation based on Rogue-Wave
39 // pointer collections.
40 // The constructor given the 'capacity' of the table, pre-allocates
41 // memory for the specified value by invoking the STL's reserve()
42 // function, in order to avoid reallocation during insertions.
43 // G4PhysicsTable has a vector of boolean which are used
44 // as 'recalc-needed' flags when processes calculate physics tables.
45 // ------------------------------------------------------------
46 //
47 // History:
48 // -------
49 // - First implementation, based on object model of
50 // 2nd December 1995. G.Cosmo
51 // - 1st March 1996, modified. K.Amako
52 // - 24th February 2001, migration to STL vectors. H.Kurashige
53 // - 9th March 2001, added Store/RetrievePhysicsTable. H.Kurashige
54 // - 20th August 2004, added FlagArray and related methods H.Kurashige
55 //-------------------------------------
56 
57 #ifndef G4PhysicsTable_h
58 #define G4PhysicsTable_h 1
59 
60 #include <vector>
61 #include "globals.hh"
62 #include "G4ios.hh"
63 
64 class G4PhysicsVector;
65 
66 class G4PhysicsTable : public std::vector<G4PhysicsVector*>
67 {
68 
69  typedef std::vector<G4PhysicsVector*> G4PhysCollection;
70  typedef std::vector<G4bool> G4FlagCollection;
71 
72  public: // with description
73 
75  // Default constructor.
76 
77  explicit G4PhysicsTable(size_t cap);
78  // Constructor with capacity. Reserves memory for the
79  // specified capacity.
80 
81  virtual ~G4PhysicsTable();
82  // Destructor.
83  // Does not invoke deletion of contained pointed collections.
84 
85  G4PhysicsVector*& operator()(size_t);
86  G4PhysicsVector* const& operator()(size_t) const;
87  // Access operators.
88 
89  void clearAndDestroy();
90  // Removes all items and deletes them at the same time.
91 
92  void push_back( G4PhysicsVector* );
93  void insert (G4PhysicsVector*);
94  // Pushes new element to collection.
95 
96  void insertAt (size_t, G4PhysicsVector*);
97  // insert element at the specified position in the collection.
98 
99  void resize(size_t, G4PhysicsVector* vec = (G4PhysicsVector*)(0));
100  // resize collection
101 
102  size_t entries() const;
103  size_t length() const;
104  // Return collection's size.
105 
106  G4bool isEmpty() const;
107  // Flags if collection is empty or not.
108 
109  G4bool ExistPhysicsTable(const G4String& fileName) const;
110  // Check if the specified file exists or not
111 
112  G4bool StorePhysicsTable(const G4String& filename, G4bool ascii=false);
113  // Stores PhysicsTable in a file (returns false in case of failure).
114 
115  G4bool RetrievePhysicsTable(const G4String& filename, G4bool ascii=false);
116  // Retrieves Physics from a file (returns false in case of failure).
117 
118  void ResetFlagArray();
119  // Reset the array of flags and all flags are set "true"
120  // This flag is supposed to be used as "recalc-needed" flag
121  // associated with each physics vector
122 
123  G4bool GetFlag(size_t i) const;
124  void ClearFlag(size_t i);
125  // Get/Clear the flag for the 'i-th' physics vector
126 
127  friend std::ostream& operator<<(std::ostream& out, G4PhysicsTable& table);
128 
129  protected:
130 
132  G4FlagCollection vecFlag;
133 
134  private:
135 
138  // Private copy constructor and assignment operator.
139 
140 };
141 
142 typedef G4PhysicsTable::iterator G4PhysicsTableIterator;
143 
144 #include "G4PhysicsVector.hh"
145 #include "G4PhysicsTable.icc"
146 
147 #endif
G4bool RetrievePhysicsTable(const G4String &filename, G4bool ascii=false)
void insert(G4PhysicsVector *)
void push_back(G4PhysicsVector *)
G4FlagCollection vecFlag
int G4int
Definition: G4Types.hh:78
G4bool ExistPhysicsTable(const G4String &fileName) const
G4PhysicsTable::iterator G4PhysicsTableIterator
void ClearFlag(size_t i)
bool G4bool
Definition: G4Types.hh:79
std::vector< G4bool > G4FlagCollection
G4PhysicsVector * CreatePhysicsVector(G4int type)
std::vector< G4PhysicsVector * > G4PhysCollection
void resize(size_t, G4PhysicsVector *vec=(G4PhysicsVector *)(0))
size_t length() const
G4PhysicsVector *& operator()(size_t)
G4bool isEmpty() const
friend std::ostream & operator<<(std::ostream &out, G4PhysicsTable &table)
void insertAt(size_t, G4PhysicsVector *)
G4bool StorePhysicsTable(const G4String &filename, G4bool ascii=false)
G4bool GetFlag(size_t i) const
virtual ~G4PhysicsTable()
size_t entries() const
G4PhysicsTable & operator=(const G4PhysicsTable &)
void clearAndDestroy()