Geant4  10.01.p02
G4MoleculeCounter.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 // Author: Mathieu Karamitros, kara@cenbg.in2p3.fr
27 
28 // The code is developed in the framework of the ESA AO7146
29 //
30 // We would be very happy hearing from you, send us your feedback! :)
31 //
32 // In order for Geant4-DNA to be maintained and still open-source,
33 // article citations are crucial.
34 // If you use Geant4-DNA chemistry and you publish papers about your software,
35 // in addition to the general paper on Geant4-DNA:
36 //
37 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
38 //
39 // we would be very happy if you could please also cite the following
40 // reference papers on chemistry:
41 //
42 // J. Comput. Phys. 274 (2014) 841-882
43 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508
44 
45 #ifndef G4MoleculeCounter_h
46 #define G4MoleculeCounter_h
47 
48 #include "G4Molecule.hh"
49 #include <map>
50 #include <memory>
51 #include <set>
52 
54 {
55  bool operator()(const double& a, const double& b) const
56  {
57  if (std::fabs(a - b) < fPrecision)
58  {
59  return false;
60  }
61  else
62  {
63  return a < b;
64  }
65  }
66 
67  static G4ThreadLocal double fPrecision;
68 };
69 
70 typedef std::map<G4double, G4int, compDoubleWithPrecision> NbMoleculeAgainstTime;
71 
72 #if __cplusplus > 199711L && !defined __clang__
73 #define stdunique_ptr std::unique_ptr
74 #else
75 #define stdunique_ptr std::auto_ptr
76 #endif
77 
78 typedef stdunique_ptr<std::set<G4double> > RecordedTimes;
79 typedef std::set<G4double>::iterator RecordedTimesIterator;
80 
82 {
83 public:
84  typedef std::map<G4Molecule, NbMoleculeAgainstTime> CounterMapType;
85  typedef stdunique_ptr<std::vector<G4Molecule> > RecordedMolecules;
86 
87  /*
88  #if __cplusplus > 199711L && !defined __clang__
89  typedef std::unique_ptr<std::vector<G4Molecule> > RecordedMolecules;
90  #else
91  typedef std::auto_ptr<std::vector<G4Molecule> > RecordedMolecules;
92  #endif
93  */
94 
95 protected:
98  { ;}
100 
101  CounterMapType fCounterMap;
102  std::map<const G4MoleculeDefinition*, G4bool> fDontRegister;
103  static G4bool fUse;
104 
106 
107  struct Search
108  {
110  {
111  fLowerBoundSet = false;
112  }
113  CounterMapType::iterator fLastMoleculeSearched;
114  NbMoleculeAgainstTime::iterator fLowerBoundTime;
116  };
117 
118  stdunique_ptr<Search> fpLastSearch;
119 
120 #ifdef MOLECULE_COUNTER_TESTING
121 public:
122 #else
123 protected:
124 #endif
125 
126  friend class G4Molecule;
127  virtual void AddAMoleculeAtTime(const G4Molecule&, G4double);
128  virtual void RemoveAMoleculeAtTime(const G4Molecule&, G4double);
129 
130 public:
131  static void DeleteInstance();
132  static G4MoleculeCounter* Instance();
134  void Initialize();
135  static void InitializeInstance();
136 
137  G4bool SearchTimeMap(const G4Molecule &molecule);
138  int SearchUpperBoundTime(double time, bool sameTypeOfMolecule);
139 
140  int GetNMoleculesAtTime(const G4Molecule &molecule, double time);
141  inline const NbMoleculeAgainstTime&
142  GetNbMoleculeAgainstTime(const G4Molecule &molecule);
143 
144  RecordedMolecules GetRecordedMolecules();
146 
147  /*
148  * The dynamics of the given molecule won't be saved into memory.
149  */
150  inline virtual void DontRegister(const G4MoleculeDefinition*);
151  inline virtual void RegisterAll();
152 
153  /*
154  * If the molecule counter is used, it will be called
155  * at every creation/deletion of a molecule to
156  * to increase/decrease the number at a given time.
157  */
158  void Use(G4bool flag = true)
159  {
160  fUse=flag;
161  }
163  {
164  return fUse;
165  }
166 
167  inline void SetVerbose(G4int);
168  inline G4int GetVerbose();
169 
170  /*
171  * It sets the min time difference in between two time slices.
172  */
173  void SetTimeSlice(double);
174 
175  virtual void ResetCounter();
176 };
177 
179 {
180  fCounterMap.clear();
181 }
182 
183 inline const NbMoleculeAgainstTime&
185 {
186  return fCounterMap[molecule];
187 }
188 
190 {
191  fVerbose = level;
192 }
193 
195 {
196  return fVerbose;
197 }
198 
200 {
201  fDontRegister[molDef] = true;
202 }
203 
205 {
206  fDontRegister.clear();
207 }
208 
209 #endif
stdunique_ptr< Search > fpLastSearch
int SearchUpperBoundTime(double time, bool sameTypeOfMolecule)
virtual void AddAMoleculeAtTime(const G4Molecule &, G4double)
CounterMapType fCounterMap
std::set< G4double >::iterator RecordedTimesIterator
static G4MoleculeCounter * GetMoleculeCounter()
G4double a
Definition: TRTMaterials.hh:39
G4bool SearchTimeMap(const G4Molecule &molecule)
#define G4ThreadLocal
Definition: tls.hh:89
int GetNMoleculesAtTime(const G4Molecule &molecule, double time)
int G4int
Definition: G4Types.hh:78
std::map< const G4MoleculeDefinition *, G4bool > fDontRegister
virtual void RegisterAll()
RecordedMolecules GetRecordedMolecules()
virtual void DontRegister(const G4MoleculeDefinition *)
virtual ~G4MoleculeCounter()
static G4MoleculeCounter * Instance()
bool G4bool
Definition: G4Types.hh:79
stdunique_ptr< std::set< G4double > > RecordedTimes
void Use(G4bool flag=true)
bool operator()(const double &a, const double &b) const
CounterMapType::iterator fLastMoleculeSearched
virtual void ResetCounter()
static G4ThreadLocal double fPrecision
NbMoleculeAgainstTime::iterator fLowerBoundTime
std::map< G4Molecule, NbMoleculeAgainstTime > CounterMapType
static G4ThreadLocal G4MoleculeCounter * fpInstance
stdunique_ptr< std::vector< G4Molecule > > RecordedMolecules
std::map< G4double, G4int, compDoubleWithPrecision > NbMoleculeAgainstTime
static void InitializeInstance()
RecordedTimes GetRecordedTimes()
Class Description The dynamic molecule holds all the data that change for a molecule It has a pointer...
Definition: G4Molecule.hh:93
double G4double
Definition: G4Types.hh:76
virtual void RemoveAMoleculeAtTime(const G4Molecule &, G4double)
const NbMoleculeAgainstTime & GetNbMoleculeAgainstTime(const G4Molecule &molecule)
void SetTimeSlice(double)
static void DeleteInstance()