44namespace MoleculeCounter {
87 while ((mol_iterator)())
89 if (!
IsRegistered(mol_iterator.value()->GetDefinition()))
142 bool sameTypeOfMolecule)
156 if (sameTypeOfMolecule)
165 if (upperToLast == timeMap.end())
170 if (upperToLast->first > time)
178 auto up_time_it = timeMap.upper_bound(time);
180 if (up_time_it == timeMap.end())
182 auto last_time = timeMap.rbegin();
183 return last_time->second;
185 if (up_time_it == timeMap.begin())
221 G4cout <<
"G4MoleculeCounter::AddAMoleculeAtTime : " << molecule->
GetName()
231 else if (counterMap_i->second.empty())
233 counterMap_i->second[time] = number;
237 auto end = counterMap_i->second.rbegin();
239 if (end->first <= time ||
244 double newValue = end->second + number;
245 counterMap_i->second[time] = newValue;
253 errMsg <<
"Time of species "
254 << molecule->
GetName() <<
" is "
256 <<
" global time is "
259 G4Exception(
"G4MoleculeCounter::AddAMoleculeAtTime",
281 G4cout <<
"G4MoleculeCounter::RemoveAMoleculeAtTime : "
292 errMsg <<
"Time of species "
293 << pMolecule->
GetName() <<
" is "
295 <<
" global time is "
298 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
306 if (nbMolPerTime.empty())
311 "You are trying to remove molecule " + pMolecule->
GetName() +
312 " from the counter while this kind of molecules has not been registered yet";
313 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
"",
319 auto 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;
373 G4cout <<
"Entering in G4MoleculeCounter::RecordMolecules" <<
G4endl;
380 output->push_back(it.first);
393 for(
const auto& it2 : it.second)
396 output->insert(it2.first);
433 auto pReactant = it.first;
435 G4cout <<
" --- > For " << pReactant->GetName() <<
G4endl;
437 for (
const auto& it2 : it.second)
440 <<
" " << it2.second <<
G4endl;
451 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