Geant4  10.02.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 <G4Types.hh>
49 #include <G4ios.hh>
50 #include <cmath>
51 #include <map>
52 #include <memory>
53 #include <set>
54 #include <vector>
55 
58 
60 {
61  bool operator()(const double& a, const double& b) const
62  {
63  if (std::fabs(a - b) < fPrecision)
64  {
65  return false;
66  }
67  else
68  {
69  return a < b;
70  }
71  }
72 
73  static G4ThreadLocal double fPrecision;
74 };
75 
76 typedef std::map<G4double, G4int, compDoubleWithPrecision> NbMoleculeAgainstTime;
77 
78 #if __cplusplus > 199711L && !defined __clang__
79 #define stdunique_ptr std::unique_ptr
80 #else
81 #define stdunique_ptr std::auto_ptr
82 #endif
83 
84 typedef stdunique_ptr<std::set<G4double> > RecordedTimes;
85 typedef std::set<G4double>::iterator RecordedTimesIterator;
86 
88 {
89 public:
90  typedef std::map<G4MolecularConfiguration*,
92  typedef stdunique_ptr<std::vector<G4MolecularConfiguration*> > RecordedMolecules;
93 
94  /*
95  #if __cplusplus > 199711L && !defined __clang__
96  typedef std::unique_ptr<std::vector<G4Molecule> > RecordedMolecules;
97  #else
98  typedef std::auto_ptr<std::vector<G4Molecule> > RecordedMolecules;
99  #endif
100  */
101 
102 protected:
104  virtual ~G4MoleculeCounter();
106 
107  CounterMapType fCounterMap;
108  std::map<const G4MoleculeDefinition*, G4bool> fDontRegister;
109  static G4bool fUse;
110 
113 
114  struct Search
115  {
117  {
118  fLowerBoundSet = false;
119  }
120  CounterMapType::iterator fLastMoleculeSearched;
121  NbMoleculeAgainstTime::iterator fLowerBoundTime;
123  };
124 
125  stdunique_ptr<Search> fpLastSearch;
126 
127 #ifdef MOLECULE_COUNTER_TESTING
128 public:
129 #else
130 protected:
131 #endif
132 
133  friend class G4Molecule;
134 
135 public:
136  virtual void AddAMoleculeAtTime(G4MolecularConfiguration*,
137  G4double time,
138  int number = 1);
139  virtual void RemoveAMoleculeAtTime(G4MolecularConfiguration*,
140  G4double time,
141  int number = 1);
142 
143 public:
144  static void DeleteInstance();
145  static G4MoleculeCounter* Instance();
147  void Initialize();
148  static void InitializeInstance();
149 
150  G4bool SearchTimeMap(G4MolecularConfiguration* molecule);
151  int SearchUpperBoundTime(double time, bool sameTypeOfMolecule);
152 
153  int GetNMoleculesAtTime(G4MolecularConfiguration* molecule, double time);
154  inline const NbMoleculeAgainstTime&
155  GetNbMoleculeAgainstTime(G4MolecularConfiguration* molecule);
156 
157  RecordedMolecules GetRecordedMolecules();
159 
160  /*
161  * The dynamics of the given molecule won't be saved into memory.
162  */
163  inline virtual void DontRegister(const G4MoleculeDefinition*);
164  inline virtual bool IsRegistered(const G4MoleculeDefinition*);
165  inline virtual void RegisterAll();
166 
167  /*
168  * If the molecule counter is used, it will be called
169  * at every creation/deletion of a molecule to
170  * to increase/decrease the number at a given time.
171  */
172  static void Use(G4bool flag = true);
173  static G4bool InUse();
174 
175  inline void SetVerbose(G4int);
176  inline G4int GetVerbose();
177 
178  /*
179  * It sets the min time difference in between two time slices.
180  */
181  void SetTimeSlice(double);
182 
183  virtual void ResetCounter();
184 
185  void Dump();
186 
188  {
190  }
191 
192  inline void CheckTimeForConsistency(G4bool flag)
193  {
194  fCheckTimeIsConsistentWithScheduler = flag;
195  }
196 };
197 
199 {
200  if(fVerbose)
201  {
202  G4cout << " ---> G4MoleculeCounter::ResetCounter" << G4endl;
203  }
204  fCounterMap.clear();
205  fpLastSearch.reset(0);
206 }
207 
208 inline const NbMoleculeAgainstTime&
210 {
211  return fCounterMap[molecule];
212 }
213 
215 {
216  fVerbose = level;
217 }
218 
220 {
221  return fVerbose;
222 }
223 
225 {
226  fDontRegister[molDef] = true;
227 }
228 
230 {
231  if(fDontRegister.find(molDef) == fDontRegister.end()) return true;
232  return false;
233 }
234 
236 {
237  fDontRegister.clear();
238 }
239 
240 #endif
The pointer G4MolecularConfiguration will be shared by all the molecules having the same molecule def...
void CheckTimeForConsistency(G4bool flag)
stdunique_ptr< Search > fpLastSearch
int SearchUpperBoundTime(double time, bool sameTypeOfMolecule)
CounterMapType fCounterMap
std::set< G4double >::iterator RecordedTimesIterator
static G4MoleculeCounter * GetMoleculeCounter()
G4double a
Definition: TRTMaterials.hh:39
virtual void RemoveAMoleculeAtTime(G4MolecularConfiguration *, G4double time, int number=1)
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
stdunique_ptr< std::vector< G4MolecularConfiguration * > > RecordedMolecules
G4bool SearchTimeMap(G4MolecularConfiguration *molecule)
std::map< const G4MoleculeDefinition *, G4bool > fDontRegister
int GetNMoleculesAtTime(G4MolecularConfiguration *molecule, double time)
virtual void RegisterAll()
RecordedMolecules GetRecordedMolecules()
virtual void DontRegister(const G4MoleculeDefinition *)
const NbMoleculeAgainstTime & GetNbMoleculeAgainstTime(G4MolecularConfiguration *molecule)
G4GLOB_DLL std::ostream G4cout
static G4bool InUse()
static G4MoleculeCounter * Instance()
std::map< G4MolecularConfiguration *, NbMoleculeAgainstTime > CounterMapType
bool G4bool
Definition: G4Types.hh:79
stdunique_ptr< std::set< G4double > > RecordedTimes
G4bool IsTimeCheckedForConsistency() const
static void Use(G4bool flag=true)
virtual void AddAMoleculeAtTime(G4MolecularConfiguration *, G4double time, int number=1)
bool operator()(const double &a, const double &b) const
CounterMapType::iterator fLastMoleculeSearched
virtual void ResetCounter()
virtual bool IsRegistered(const G4MoleculeDefinition *)
static G4ThreadLocal double fPrecision
NbMoleculeAgainstTime::iterator fLowerBoundTime
static G4ThreadLocal G4MoleculeCounter * fpInstance
std::map< G4double, G4int, compDoubleWithPrecision > NbMoleculeAgainstTime
static void InitializeInstance()
#define G4endl
Definition: G4ios.hh:61
G4bool fCheckTimeIsConsistentWithScheduler
RecordedTimes GetRecordedTimes()
Class Description The dynamic molecule holds all the data that change for a molecule It has a pointer...
Definition: G4Molecule.hh:94
double G4double
Definition: G4Types.hh:76
virtual ~G4MoleculeCounter()
void SetTimeSlice(double)
static void DeleteInstance()