41namespace MoleculeCounter {
86 while ((mol_iterator)())
88 if (
IsRegistered(mol_iterator.value()->GetDefinition()) ==
false)
141 bool sameTypeOfMolecule)
155 if (sameTypeOfMolecule ==
true)
164 if (upperToLast == timeMap.end())
169 if (upperToLast->first > time)
177 auto up_time_it = timeMap.upper_bound(time);
179 if (up_time_it == timeMap.end())
181 NbMoleculeAgainstTime::reverse_iterator last_time = timeMap.rbegin();
182 return last_time->second;
184 if (up_time_it == timeMap.begin())
220 G4cout <<
"G4MoleculeCounter::AddAMoleculeAtTime : " << molecule->
GetName()
230 else if (counterMap_i->second.empty())
232 counterMap_i->second[time] = number;
236 NbMoleculeAgainstTime::reverse_iterator end = counterMap_i->second.rbegin();
238 if (end->first <= time ||
243 double newValue = end->second + number;
244 counterMap_i->second[time] = newValue;
252 errMsg <<
"Time of species "
253 << molecule->
GetName() <<
" is "
255 <<
" global time is "
258 G4Exception(
"G4MoleculeCounter::AddAMoleculeAtTime",
280 G4cout <<
"G4MoleculeCounter::RemoveAMoleculeAtTime : "
291 errMsg <<
"Time of species "
292 << pMolecule->
GetName() <<
" is "
294 <<
" global time is "
297 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
305 if (nbMolPerTime.empty())
310 "You are trying to remove molecule " + pMolecule->
GetName() +
311 " from the counter while this kind of molecules has not been registered yet";
312 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
"",
319 NbMoleculeAgainstTime::reverse_iterator it = nbMolPerTime.rbegin();
321 if (it == nbMolPerTime.rend())
326 "There was no " + pMolecule->
GetName() +
" recorded at the time or even before the time asked";
327 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
"",
335 errMsg <<
"Is time going back?? " << pMolecule->
GetName()
336 <<
" is being removed at time " <<
G4BestUnit(time,
"Time")
337 <<
" while last recorded time was "
339 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
340 "RETURN_TO_THE_FUTUR",
345 double finalN = it->second - number;
351 errMsg <<
"After removal of " << number <<
" species of "
352 << pMolecule->
GetName() <<
" the final number at time "
353 <<
G4BestUnit(time,
"Time") <<
" is less than zero and so not valid."
354 <<
" Global time is "
356 <<
". Previous selected time is "
359 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
364 nbMolPerTime[time] = finalN;
374 G4cout <<
"Entering in G4MoleculeCounter::RecordMolecules" <<
G4endl;
381 output->push_back(it.first);
394 for(
const auto& it2 : it.second)
397 output->insert(it2.first);
434 auto pReactant = it.first;
436 G4cout <<
" --- > For " << pReactant->GetName() <<
G4endl;
438 for (
const auto& it2 : it.second)
441 <<
" " << it2.second <<
G4endl;
452 G4cout <<
" ---> G4MoleculeCounter::ResetCounter" <<
G4endl;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::map< G4double, G4int, G4::MoleculeCounter::TimePrecision > NbMoleculeAgainstTime
std::unique_ptr< std::set< G4double > > RecordedTimes
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
const G4MoleculeDefinition * GetDefinition() const
std::unique_ptr< ReactantList > RecordedMolecules
void Initialize() override
std::map< const G4MoleculeDefinition *, G4bool > fDontRegister
const NbMoleculeAgainstTime & GetNbMoleculeAgainstTime(Reactant *molecule)
RecordedTimes GetRecordedTimes()
static void SetTimeSlice(double)
void RegisterAll() override
G4bool fCheckTimeIsConsistentWithScheduler
void DontRegister(const G4MoleculeDefinition *) override
G4bool SearchTimeMap(Reactant *molecule)
static G4MoleculeCounter * Instance()
void ResetCounter() override
int GetNMoleculesAtTime(Reactant *molecule, double time)
G4bool IsTimeCheckedForConsistency() const
std::unique_ptr< Search > fpLastSearch
CounterMapType fCounterMap
void AddAMoleculeAtTime(Reactant *, G4double time, const G4ThreeVector *position=nullptr, int number=1) override
void RemoveAMoleculeAtTime(Reactant *, G4double time, const G4ThreeVector *position=nullptr, int number=1) override
~G4MoleculeCounter() override
RecordedMolecules GetRecordedMolecules()
void CheckTimeForConsistency(G4bool flag)
int SearchUpperBoundTime(double time, bool sameTypeOfMolecule)
bool IsRegistered(const G4MoleculeDefinition *) override
std::vector< Reactant * > ReactantList
static G4MoleculeTable * Instance()
G4ConfigurationIterator GetConfigurationIterator()
static G4Scheduler * Instance()
static G4ThreadLocal G4VMoleculeCounter * fpInstance
static G4ThreadLocal double fPrecision
bool operator()(const double &a, const double &b) const