58 fCheckTimeIsConsistentWithScheduler =
true;
94 if(fpInstance) fpInstance->Initialize();
101 while ((mol_iterator)())
105 fCounterMap[mol_iterator.
value()];
116 if (fpLastSearch.get() == 0)
118 fpLastSearch.reset(
new Search());
122 if (fpLastSearch->fLowerBoundSet &&
123 fpLastSearch->fLastMoleculeSearched->first == molecule)
127 CounterMapType::iterator mol_it = fCounterMap.find(molecule);
128 fpLastSearch->fLastMoleculeSearched = mol_it;
130 if (mol_it != fCounterMap.end())
132 fpLastSearch->fLowerBoundTime = fpLastSearch->fLastMoleculeSearched->second
134 fpLastSearch->fLowerBoundSet =
true;
138 fpLastSearch->fLowerBoundSet =
false;
145 bool sameTypeOfMolecule)
147 CounterMapType::iterator mol_it = fpLastSearch->fLastMoleculeSearched;
148 if (mol_it == fCounterMap.end())
return 0;
151 if (timeMap.empty())
return 0;
153 NbMoleculeAgainstTime::iterator end_time = timeMap.end();
155 if (sameTypeOfMolecule ==
true)
158 if (fpLastSearch->fLowerBoundSet && fpLastSearch->fLowerBoundTime
163 if (fpLastSearch->fLowerBoundTime->first < time)
165 NbMoleculeAgainstTime::iterator upperToLast = fpLastSearch
169 if (upperToLast == end_time)
171 return fpLastSearch->fLowerBoundTime->second;
174 if (upperToLast->first > time)
176 return fpLastSearch->fLowerBoundTime->second;
191 NbMoleculeAgainstTime::iterator up_time_it = timeMap.upper_bound(time);
193 if (up_time_it == end_time)
195 NbMoleculeAgainstTime::reverse_iterator last_time = timeMap.rbegin();
200 return last_time->second;
206 if (up_time_it == timeMap.begin())
218 fpLastSearch->fLowerBoundTime = up_time_it;
219 fpLastSearch->fLowerBoundSet =
true;
223 return fpLastSearch->fLowerBoundTime->second;
229 G4bool sameTypeOfMolecule = SearchTimeMap(molecule);
230 return SearchUpperBoundTime(time, sameTypeOfMolecule);
241 G4cout <<
"G4MoleculeCounter::AddAMoleculeAtTime : " << molecule->
GetName()
245 CounterMapType::iterator counterMap_i =
246 fCounterMap.find(molecule);
248 if (counterMap_i == fCounterMap.end())
252 fCounterMap[molecule][time] = number;
254 else if (counterMap_i->second.empty())
258 counterMap_i->second[time] = number;
263 NbMoleculeAgainstTime::reverse_iterator end = counterMap_i->second.rbegin();
270 if (end->first <= time ||
275 double newValue = end->second + number;
277 counterMap_i->second[time] = newValue;
288 errMsg <<
"Time of species " 289 << molecule->
GetName() <<
" is " 291 <<
" global time is " 294 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
341 G4cout <<
"G4MoleculeCounter::RemoveAMoleculeAtTime : " 346 if(fCheckTimeIsConsistentWithScheduler)
352 errMsg <<
"Time of species " 353 << molecule->
GetName() <<
" is " 355 <<
" global time is " 358 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
366 if (nbMolPerTime.empty())
371 "You are trying to remove molecule " + molecule->
GetName()
372 +
" from the counter while this kind of molecules has not been registered yet";
373 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
"",
380 NbMoleculeAgainstTime::reverse_iterator it = nbMolPerTime.rbegin();
396 if (it == nbMolPerTime.rend())
406 +
" recorded at the time or even before the time asked";
407 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
"",
455 errMsg <<
"Is time going back?? " << molecule->
GetName()
456 <<
" is being removed at time " <<
G4BestUnit(time,
"Time")
457 <<
" while last recorded time was " 459 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
460 "RETURN_TO_THE_FUTUR",
480 double finalN = it->second - number;
486 errMsg <<
"After removal of " << number <<
" species of " 487 << molecule->
GetName() <<
" the final number at time " 488 <<
G4BestUnit(time,
"Time") <<
" is less than zero and so not valid." 489 <<
" Global time is " 491 <<
". Previous selected time is " 494 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
499 nbMolPerTime[time] = finalN;
513 G4cout <<
"Entering in G4MoleculeCounter::RecordMolecules" <<
G4endl;
516 CounterMapType::iterator it;
519 for(it = fCounterMap.begin(); it != fCounterMap.end(); it++)
521 output->push_back(it->first);
532 CounterMapType::iterator it;
533 CounterMapType::const_iterator ite;
535 NbMoleculeAgainstTime::iterator it2;
536 NbMoleculeAgainstTime::const_iterator ite2;
539 for (it = fCounterMap.begin(), ite = fCounterMap.end(); it != ite; ++it)
542 for (it2 = (it->second).begin(), ite2 = (it->second).end(); it2 != ite2;
546 output->insert(it2->first);
578 CounterMapType::iterator it = fCounterMap.begin();
579 CounterMapType::iterator end = fCounterMap.end();
586 NbMoleculeAgainstTime::iterator it2 = it->second.begin();
587 NbMoleculeAgainstTime::iterator end2 = it->second.end();
589 for(;it2!=end2;++it2)
int SearchUpperBoundTime(double time, bool sameTypeOfMolecule)
std::ostringstream G4ExceptionDescription
const G4String & GetName() const
const G4MoleculeDefinition * GetDefinition() const
static G4MoleculeCounter * GetMoleculeCounter()
virtual void RemoveAMoleculeAtTime(G4MolecularConfiguration *, G4double time, int number=1)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
std::unique_ptr< std::vector< G4MolecularConfiguration * > > RecordedMolecules
static G4Scheduler * Instance()
G4bool SearchTimeMap(G4MolecularConfiguration *molecule)
int GetNMoleculesAtTime(G4MolecularConfiguration *molecule, double time)
RecordedMolecules GetRecordedMolecules()
G4GLOB_DLL std::ostream G4cout
static G4MoleculeCounter * Instance()
static G4MoleculeTable * Instance()
static void Use(G4bool flag=true)
virtual void AddAMoleculeAtTime(G4MolecularConfiguration *, G4double time, int number=1)
G4ConfigurationIterator GetConfigurationIterator()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
std::unique_ptr< std::set< G4double > > RecordedTimes
static G4ThreadLocal double fPrecision
static G4ThreadLocal G4MoleculeCounter * fpInstance
std::map< G4double, G4int, compDoubleWithPrecision > NbMoleculeAgainstTime
static void InitializeInstance()
RecordedTimes GetRecordedTimes()
static const double picosecond
virtual ~G4MoleculeCounter()
void SetTimeSlice(double)
static void DeleteInstance()