Geant4_10
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 #ifndef G4MoleculeCounter_h
27 #define G4MoleculeCounter_h
28 
29 #include "G4Molecule.hh"
30 #include <map>
31 #include <memory>
32 
34 {
35  bool operator() (const double& a, const double& b) const
36  {
37  if(std::fabs(a - b) < fPrecision)
38  {
39  return false;
40  }
41  else
42  {
43  return a < b;
44  }
45  }
46 
47  static G4ThreadLocal double fPrecision ;
48 };
49 
50 typedef std::map<G4double, G4int, compDoubleWithPrecision> NbMoleculeAgainstTime;
51 
53 {
54 public:
55  typedef std::map<G4Molecule, NbMoleculeAgainstTime> CounterMapType;
56 
57 #if __cplusplus > 199711L && !defined __clang__
58  typedef std::unique_ptr<std::vector<G4Molecule> > RecordedMolecules;
59 #else
60  typedef std::auto_ptr<std::vector<G4Molecule> > RecordedMolecules;
61 #endif
62 
63 protected:
65  virtual ~G4MoleculeCounter(){;}
67 
69  std::map<const G4MoleculeDefinition*, G4bool> fDontRegister ;
70  static G4bool fUse;
71 
73 
74  friend class G4Molecule;
75  virtual void AddAMoleculeAtTime(const G4Molecule&, G4double);
76  virtual void RemoveAMoleculeAtTime(const G4Molecule&, G4double);
77 
78 public:
79  static void DeleteInstance();
80 
82  inline const NbMoleculeAgainstTime& GetNbMoleculeAgainstTime(const G4Molecule &molecule);
83 
85 
86  /*
87  * The dynamics of the given molecule won't be saved into memory.
88  */
89  inline virtual void DontRegister(const G4MoleculeDefinition*);
90  inline virtual void RegisterAll();
91 
92  /*
93  * If the molecule counter is used, it will be called
94  * at every creation/deletion of a molecule to
95  * to increase/decrease the number at a given time.
96  */
97  void Use(G4bool flag = true)
98  {
99  fUse=flag;
100  }
102  {
103  return fUse;
104  }
105 
106  inline void SetVerbose(G4int);
107  inline G4int GetVerbose();
108 
109  /*
110  * It sets the min time difference in between two time slices.
111  */
112  void SetTimeSlice(double);
113 
114  virtual void ResetCounter();
115 };
116 
118 {
119  fCounterMap.clear();
120 }
121 
123 {
124  return fCounterMap[molecule];
125 }
126 
128 {
129  fVerbose = level;
130 }
131 
133 {
134  return fVerbose ;
135 }
136 
138 {
139  fDontRegister[molDef] = true ;
140 }
141 
143 {
144  fDontRegister.clear();
145 }
146 
147 #endif
tuple a
Definition: test.py:11
virtual void AddAMoleculeAtTime(const G4Molecule &, G4double)
CounterMapType fCounterMap
static G4MoleculeCounter * GetMoleculeCounter()
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
std::map< const G4MoleculeDefinition *, G4bool > fDontRegister
virtual void RegisterAll()
tuple b
Definition: test.py:12
RecordedMolecules GetRecordedMolecules()
virtual void DontRegister(const G4MoleculeDefinition *)
virtual ~G4MoleculeCounter()
bool G4bool
Definition: G4Types.hh:79
void Use(G4bool flag=true)
std::auto_ptr< std::vector< G4Molecule > > RecordedMolecules
bool operator()(const double &a, const double &b) const
virtual void ResetCounter()
static G4ThreadLocal double fPrecision
std::map< G4Molecule, NbMoleculeAgainstTime > CounterMapType
static G4ThreadLocal G4MoleculeCounter * fpInstance
std::map< G4double, G4int, compDoubleWithPrecision > NbMoleculeAgainstTime
double G4double
Definition: G4Types.hh:76
virtual void RemoveAMoleculeAtTime(const G4Molecule &, G4double)
const NbMoleculeAgainstTime & GetNbMoleculeAgainstTime(const G4Molecule &molecule)
void SetTimeSlice(double)
static void DeleteInstance()