Geant4  10.02.p03
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 typedef std::unique_ptr<std::set<G4double> > RecordedTimes;
79 typedef std::set<G4double>::iterator RecordedTimesIterator;
80 
82 {
83 public:
84  typedef std::map<G4MolecularConfiguration*,
86  typedef std::unique_ptr<std::vector<G4MolecularConfiguration*> > RecordedMolecules;
87 
88 protected:
90  virtual ~G4MoleculeCounter();
92 
93  CounterMapType fCounterMap;
94  std::map<const G4MoleculeDefinition*, G4bool> fDontRegister;
95  static G4bool fUse;
96 
99 
100  struct Search
101  {
103  {
104  fLowerBoundSet = false;
105  }
106  CounterMapType::iterator fLastMoleculeSearched;
107  NbMoleculeAgainstTime::iterator fLowerBoundTime;
109  };
110 
111  std::unique_ptr<Search> fpLastSearch;
112 
113 #ifdef MOLECULE_COUNTER_TESTING
114 public:
115 #else
116 protected:
117 #endif
118 
119  friend class G4Molecule;
120 
121 public:
122  virtual void AddAMoleculeAtTime(G4MolecularConfiguration*,
123  G4double time,
124  int number = 1);
125  virtual void RemoveAMoleculeAtTime(G4MolecularConfiguration*,
126  G4double time,
127  int number = 1);
128 
129 public:
130  static void DeleteInstance();
131  static G4MoleculeCounter* Instance();
132  static G4MoleculeCounter* GetMoleculeCounter();
133  void Initialize();
134  static void InitializeInstance();
135 
136  G4bool SearchTimeMap(G4MolecularConfiguration* molecule);
137  int SearchUpperBoundTime(double time, bool sameTypeOfMolecule);
138 
139  int GetNMoleculesAtTime(G4MolecularConfiguration* molecule, double time);
140  inline const NbMoleculeAgainstTime&
141  GetNbMoleculeAgainstTime(G4MolecularConfiguration* molecule);
142 
143  RecordedMolecules GetRecordedMolecules();
144  RecordedTimes GetRecordedTimes();
145 
146  /*
147  * The dynamics of the given molecule won't be saved into memory.
148  */
149  inline virtual void DontRegister(const G4MoleculeDefinition*);
150  inline virtual bool IsRegistered(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  static void Use(G4bool flag = true);
159  static G4bool InUse();
160 
161  inline void SetVerbose(G4int);
162  inline G4int GetVerbose();
163 
164  /*
165  * It sets the min time difference in between two time slices.
166  */
167  void SetTimeSlice(double);
168 
169  virtual void ResetCounter();
170 
171  void Dump();
172 
174  {
175  return fCheckTimeIsConsistentWithScheduler;
176  }
177 
178  inline void CheckTimeForConsistency(G4bool flag)
179  {
180  fCheckTimeIsConsistentWithScheduler = flag;
181  }
182 };
183 
185 {
186  if(fVerbose)
187  {
188  G4cout << " ---> G4MoleculeCounter::ResetCounter" << G4endl;
189  }
190  fCounterMap.clear();
191  fpLastSearch.reset(0);
192 }
193 
194 inline const NbMoleculeAgainstTime&
196 {
197  return fCounterMap[molecule];
198 }
199 
201 {
202  fVerbose = level;
203 }
204 
206 {
207  return fVerbose;
208 }
209 
211 {
212  fDontRegister[molDef] = true;
213 }
214 
216 {
217  if(fDontRegister.find(molDef) == fDontRegister.end()) return true;
218  return false;
219 }
220 
222 {
223  fDontRegister.clear();
224 }
225 
226 #endif
void CheckTimeForConsistency(G4bool flag)
bool operator()(const double &a, const double &b) const
void Initialize()
Definition: errprop.cc:101
CounterMapType fCounterMap
std::set< G4double >::iterator RecordedTimesIterator
#define G4ThreadLocal
Definition: tls.hh:89
std::unique_ptr< std::vector< G4MolecularConfiguration * > > RecordedMolecules
int G4int
Definition: G4Types.hh:78
std::map< const G4MoleculeDefinition *, G4bool > fDontRegister
std::unique_ptr< Search > fpLastSearch
virtual void RegisterAll()
virtual void DontRegister(const G4MoleculeDefinition *)
const NbMoleculeAgainstTime & GetNbMoleculeAgainstTime(G4MolecularConfiguration *molecule)
G4bool IsTimeCheckedForConsistency() const
G4GLOB_DLL std::ostream G4cout
std::map< G4MolecularConfiguration *, NbMoleculeAgainstTime > CounterMapType
bool G4bool
Definition: G4Types.hh:79
CounterMapType::iterator fLastMoleculeSearched
virtual void ResetCounter()
std::unique_ptr< std::set< G4double > > RecordedTimes
virtual bool IsRegistered(const G4MoleculeDefinition *)
static G4ThreadLocal double fPrecision
NbMoleculeAgainstTime::iterator fLowerBoundTime
static G4ThreadLocal G4MoleculeCounter * fpInstance
std::map< G4double, G4int, compDoubleWithPrecision > NbMoleculeAgainstTime
#define G4endl
Definition: G4ios.hh:61
G4bool fCheckTimeIsConsistentWithScheduler
double G4double
Definition: G4Types.hh:76