Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MoleculeCounter Class Reference

#include <G4MoleculeCounter.hh>

Public Member Functions

const NbMoleculeAgainstTimeGetNbMoleculeAgainstTime (const G4Molecule &molecule)
 
std::auto_ptr< vector< G4Molecule > > GetRecordedMolecules ()
 
virtual void AddAMoleculeAtTime (const G4Molecule &, G4double)
 
virtual void RemoveAMoleculeAtTime (const G4Molecule &, G4double)
 
virtual void DontRegister (const G4MoleculeDefinition *)
 
virtual void ResetDontRegister ()
 
void Use (G4bool flag=true)
 
G4bool InUse ()
 
void SetVerbose (G4int)
 
G4int GetVerbose ()
 
virtual void ResetCounter ()
 

Static Public Member Functions

static void DeleteInstance ()
 
static G4MoleculeCounterGetMoleculeCounter ()
 

Protected Types

typedef std::map< G4Molecule, NbMoleculeAgainstTimeCounterMapType
 

Protected Member Functions

 G4MoleculeCounter ()
 
virtual ~G4MoleculeCounter ()
 

Protected Attributes

CounterMapType fCounterMap
 
std::map< const G4MoleculeDefinition *, G4boolfDontRegister
 
G4bool fUse
 
G4int fVerbose
 

Static Protected Attributes

static G4MoleculeCounterfpInstance = 0
 

Detailed Description

Definition at line 55 of file G4MoleculeCounter.hh.

Member Typedef Documentation

◆ CounterMapType

Definition at line 61 of file G4MoleculeCounter.hh.

Constructor & Destructor Documentation

◆ G4MoleculeCounter()

G4MoleculeCounter::G4MoleculeCounter ( )
protected

Definition at line 35 of file G4MoleculeCounter.cc.

36{
37 fUse = FALSE;
38 fVerbose = 0 ;
39}
#define FALSE
Definition: globals.hh:52

Referenced by GetMoleculeCounter().

◆ ~G4MoleculeCounter()

virtual G4MoleculeCounter::~G4MoleculeCounter ( )
inlineprotectedvirtual

Definition at line 59 of file G4MoleculeCounter.hh.

59{;}

Member Function Documentation

◆ AddAMoleculeAtTime()

void G4MoleculeCounter::AddAMoleculeAtTime ( const G4Molecule molecule,
G4double  time 
)
virtual

Definition at line 60 of file G4MoleculeCounter.cc.

61{
62 if(fVerbose > 1)
63 {
64 G4cout<<"G4MoleculeCounter::AddAMoleculeAtTime : "<< molecule.GetName()
65 << " at time : " << G4BestUnit(time, "Time") <<G4endl;
66 }
67
68 if(fDontRegister[molecule.GetDefinition()]) return ;
69
70 // G4double pstime = time/picosecond;
71 //
72 // G4double fractpart=-1, intpart=-1;
73 // fractpart = modf (pstime , &intpart);
74 //
75 // if(pstime<10.1)
76 // {
77 // fractpart *= 10 ;
78 // fractpart = floor(fractpart)/10;
79 // pstime = intpart+fractpart;
80 // }
81 //
82 // else
83 // {
84 // pstime = intpart;
85 // }
86 // time = pstime*picosecond ;
87
88 if(fVerbose)
89 {
90 G4cout<<"-------------------------"<<G4endl ;
91 G4cout << "G4MoleculeCounter::AddAMoleculeAtTime " << G4endl;
92 G4cout<<"!! Molecule = " << molecule.GetName() << G4endl;
93 G4cout<<"!! At Time = "<< G4BestUnit(time, "Time") <<G4endl;
94 }
95
96 CounterMapType::iterator counterMap_i = fCounterMap.find(molecule) ;
97
98 if(counterMap_i == fCounterMap.end())
99 {
100 if(fVerbose) G4cout << " !! ***** Map is empty " << G4endl;
101 fCounterMap[molecule][time] = 1;
102 }
103 else if(counterMap_i->second.empty())
104 {
105 if(fVerbose) G4cout << " !! ***** Map is empty " << G4endl;
106 counterMap_i->second[time] = 1;
107 }
108 else
109 {
110 NbMoleculeAgainstTime::iterator end = counterMap_i->second.end();
111 end--;
112
113 if(fVerbose)
114 G4cout<<"!! End Time = "<< G4BestUnit(end->first, "Time") <<G4endl;
115
116 if(end->first <= time)
117 {
118 counterMap_i->second[time]=end->second + 1;
119 }
120 else
121 {
122 NbMoleculeAgainstTime::iterator it = counterMap_i->second.lower_bound(time);
123
124 while(it->first > time && it!=counterMap_i->second.begin())
125 {
126 if(fVerbose)
127 G4cout<<"!! ********** Is going back!!!!"<<G4endl;
128 it--;
129 }
130
131 if(it==counterMap_i->second.begin() && it->first > time)
132 {
133 if(fVerbose)
134 G4cout<<"!! ********** Illegal !!!!"<<G4endl;
135 return ;
136 }
137
138 if(fVerbose)
139 {
140 G4cout<<"!! PREVIOUS NB = "<< it->second <<G4endl;
141 G4cout<<"!! PREVIOUS TIME = "<< G4BestUnit(it->first,"Time") <<G4endl;
142 }
143 counterMap_i->second[time]=it->second + 1;
144 }
145 }
146
147 if(fVerbose)
148 G4cout<<"!! NB = "<< fCounterMap[molecule][time]<<G4endl;
149}
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
std::map< const G4MoleculeDefinition *, G4bool > fDontRegister
CounterMapType fCounterMap
const G4String & GetName() const
Definition: G4Molecule.cc:259
const G4MoleculeDefinition * GetDefinition() const
Definition: G4Molecule.cc:395

Referenced by G4Molecule::BuildTrack().

◆ DeleteInstance()

void G4MoleculeCounter::DeleteInstance ( )
static

Definition at line 51 of file G4MoleculeCounter.cc.

52{
53 if(fpInstance)
54 {
55 delete fpInstance;
56 fpInstance = 0;
57 }
58}
static G4MoleculeCounter * fpInstance

◆ DontRegister()

void G4MoleculeCounter::DontRegister ( const G4MoleculeDefinition molDef)
inlinevirtual

Definition at line 118 of file G4MoleculeCounter.hh.

119{
120 fDontRegister[molDef] = true ;
121}

◆ GetMoleculeCounter()

G4MoleculeCounter * G4MoleculeCounter::GetMoleculeCounter ( )
static

Definition at line 43 of file G4MoleculeCounter.cc.

44{
45 if(!fpInstance)
47
48 return fpInstance;
49}

Referenced by G4Molecule::BuildTrack(), and G4Molecule::~G4Molecule().

◆ GetNbMoleculeAgainstTime()

const NbMoleculeAgainstTime & G4MoleculeCounter::GetNbMoleculeAgainstTime ( const G4Molecule molecule)
inline

Definition at line 103 of file G4MoleculeCounter.hh.

104{
105 return fCounterMap[molecule];
106}

◆ GetRecordedMolecules()

std::auto_ptr< vector< G4Molecule > > G4MoleculeCounter::GetRecordedMolecules ( )

Definition at line 258 of file G4MoleculeCounter.cc.

259{
260 if(fVerbose > 1)
261 {
262 G4cout<<"Entering in G4MoleculeCounter::RecordMolecules"<<G4endl;
263 }
264
265 CounterMapType::iterator it;
266 std::auto_ptr< vector<G4Molecule> > output (new vector<G4Molecule>) ;
267
268 for(it = fCounterMap.begin() ; it != fCounterMap.end() ; it++)
269 {
270 output->push_back((*it).first);
271 }
272 return output;
273}

◆ GetVerbose()

G4int G4MoleculeCounter::GetVerbose ( )
inline

Definition at line 113 of file G4MoleculeCounter.hh.

114{
115 return fVerbose ;
116}

◆ InUse()

G4bool G4MoleculeCounter::InUse ( )
inline

Definition at line 87 of file G4MoleculeCounter.hh.

88 {
89 return fUse;
90 }

◆ RemoveAMoleculeAtTime()

void G4MoleculeCounter::RemoveAMoleculeAtTime ( const G4Molecule molecule,
G4double  time 
)
virtual

Definition at line 151 of file G4MoleculeCounter.cc.

152{
153 if(fVerbose > 1)
154 {
155 G4cout<<"-------------------------"<<G4endl ;
156 G4cout<<"G4MoleculeCounter::RemoveAMoleculeAtTime : "<< molecule.GetName()
157 << " at time : " << G4BestUnit(time,"Time") <<G4endl;
158 G4cout<<"-------------------------"<<G4endl ;
159 }
160
161 if(fDontRegister[molecule.GetDefinition()]) return ;
162
163 NbMoleculeAgainstTime& nbMolPerTime = fCounterMap[molecule];
164
165 if(nbMolPerTime.empty())
166 {
167 molecule.PrintState();
168 G4String errMsg = "You are trying to remove molecule "
169 + molecule.GetName()
170 +" from the counter while this kind of molecules has not been registered yet";
171 G4Exception("G4MoleculeCounter::RemoveAMoleculeAtTime","",FatalErrorInArgument, errMsg);
172
173 return;
174 }
175 else
176 {
177 NbMoleculeAgainstTime::iterator it ;
178
179 if(nbMolPerTime.size() == 1)
180 {
181 it = nbMolPerTime.begin() ;
182 if(fVerbose)
183 G4cout << "!! fCounterMap[molecule].size() == 1" << G4endl;
184 }
185 else
186 {
187 it = nbMolPerTime.lower_bound(time);
188 }
189
190 if(it==nbMolPerTime.end())
191 {
192 if(fVerbose)
193 G4cout << " ********** NO ITERATOR !!!!!!!!! " << G4endl;
194 it--;
195
196 if(time<it->first)
197 {
198 G4String errMsg = "There was no "+ molecule.GetName()
199 + " record at the time or even before the time asked";
200 G4Exception("G4MoleculeCounter::RemoveAMoleculeAtTime","",FatalErrorInArgument, errMsg);
201 }
202 }
203
204 if(fVerbose)
205 {
206// G4cout << "G4MoleculeCounter::RemoveAMoleculeAtTime " << G4endl;
207 G4cout<<"!! Molecule = " << molecule.GetName() << G4endl;
208 G4cout<<"!! At Time = "<< G4BestUnit(time,"Time") <<G4endl;
209 G4cout<<"!! PREVIOUS TIME = "<< G4BestUnit(it->first,"Time")<<G4endl;
210 G4cout<<"!! PREVIOUS Nb = "<< it->second <<G4endl;
211 }
212
213 // If valgrind problem on the line below, it means that the pointer "it"
214 // points nowhere
215 if(nbMolPerTime.value_comp()(*it, *nbMolPerTime.begin()))
216 {
217 if(fVerbose)
218 G4cout<<"!! ***** In value_comp ... " << G4endl;
219 it++;
220 if(time<it->first)
221 {
222 G4String errMsg = "There was no "+ molecule.GetName()
223 + " record at the time or even before the time asked";
224 G4Exception("G4MoleculeCounter::RemoveAMoleculeAtTime","",FatalErrorInArgument, errMsg);
225 }
226 }
227
228 while(it->first - time > compDoubleWithPrecision::fPrecision && it!=nbMolPerTime.begin())
229 {
230 if(fVerbose)
231 {
232 G4cout<<"!! ***** Is going back!!!!"<<G4endl;
233 G4cout<<"!! PREVIOUS TIME = "<< G4BestUnit(it-> first,"Time") <<G4endl;
234 }
235 it--;
236 }
237
238 if(it==nbMolPerTime.begin() && it->first > time)
239 {
240 if(fVerbose)
241 G4cout<<"!! ********** Illegal !!!!"<<G4endl;
242 return ;
243 }
244
245 if(fVerbose)
246 {
247 G4cout<<"!! PREVIOUS NB = "<< (*it).second <<G4endl;
248 G4cout<<"!! PREVIOUS TIME = "<< G4BestUnit(it->first,"Time")<<G4endl;
249 }
250 nbMolPerTime[time]=it->second - 1;
251 }
252 if(fVerbose)
253 {
254 G4cout<<"!! NB = "<< nbMolPerTime[time]<<G4endl;
255 }
256}
@ FatalErrorInArgument
map< G4double, G4int, compDoubleWithPrecision > NbMoleculeAgainstTime
void PrintState() const
Definition: G4Molecule.cc:274
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Referenced by G4Molecule::~G4Molecule().

◆ ResetCounter()

void G4MoleculeCounter::ResetCounter ( )
inlinevirtual

Definition at line 98 of file G4MoleculeCounter.hh.

99{
100 fCounterMap.clear();
101}

◆ ResetDontRegister()

void G4MoleculeCounter::ResetDontRegister ( )
inlinevirtual

Definition at line 123 of file G4MoleculeCounter.hh.

124{
125 fDontRegister.clear();
126}

◆ SetVerbose()

void G4MoleculeCounter::SetVerbose ( G4int  level)
inline

Definition at line 108 of file G4MoleculeCounter.hh.

109{
110 fVerbose = level;
111}

◆ Use()

void G4MoleculeCounter::Use ( G4bool  flag = true)
inline

Definition at line 83 of file G4MoleculeCounter.hh.

84 {
85 fUse=flag;
86 }

Member Data Documentation

◆ fCounterMap

CounterMapType G4MoleculeCounter::fCounterMap
protected

◆ fDontRegister

std::map<const G4MoleculeDefinition*, G4bool> G4MoleculeCounter::fDontRegister
protected

◆ fpInstance

G4MoleculeCounter * G4MoleculeCounter::fpInstance = 0
staticprotected

Definition at line 60 of file G4MoleculeCounter.hh.

Referenced by DeleteInstance(), and GetMoleculeCounter().

◆ fUse

G4bool G4MoleculeCounter::fUse
protected

Definition at line 66 of file G4MoleculeCounter.hh.

Referenced by G4MoleculeCounter(), InUse(), and Use().

◆ fVerbose

G4int G4MoleculeCounter::fVerbose
protected

The documentation for this class was generated from the following files: