41 namespace MoleculeCounter {
43 bool TimePrecision::operator()(
const double&
a,
const double&
b)
const
45 if (std::fabs(a - b) < fPrecision)
74 fCheckTimeIsConsistentWithScheduler =
true;
86 while ((mol_iterator)())
88 if (IsRegistered(mol_iterator.value()->GetDefinition()) ==
false)
93 fCounterMap[mol_iterator.value()];
108 if (fpLastSearch ==
nullptr)
110 fpLastSearch.reset(
new Search());
114 if (fpLastSearch->fLowerBoundSet &&
115 fpLastSearch->fLastMoleculeSearched->first == molecule)
121 auto mol_it = fCounterMap.find(molecule);
122 fpLastSearch->fLastMoleculeSearched = mol_it;
124 if (mol_it != fCounterMap.end())
126 fpLastSearch->fLowerBoundTime = fpLastSearch->fLastMoleculeSearched->second
128 fpLastSearch->fLowerBoundSet =
true;
132 fpLastSearch->fLowerBoundSet =
false;
141 bool sameTypeOfMolecule)
143 auto mol_it = fpLastSearch->fLastMoleculeSearched;
144 if (mol_it == fCounterMap.end())
155 if (sameTypeOfMolecule ==
true)
157 if (fpLastSearch->fLowerBoundSet && fpLastSearch->fLowerBoundTime != timeMap.end())
159 if (fpLastSearch->fLowerBoundTime->first < time)
161 auto upperToLast = fpLastSearch->fLowerBoundTime;
164 if (upperToLast == timeMap.end())
166 return fpLastSearch->fLowerBoundTime->second;
169 if (upperToLast->first > time)
171 return fpLastSearch->fLowerBoundTime->second;
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())
191 fpLastSearch->fLowerBoundTime = up_time_it;
192 fpLastSearch->fLowerBoundSet =
true;
194 return fpLastSearch->fLowerBoundTime->second;
202 G4bool sameTypeOfMolecule = SearchTimeMap(molecule);
203 return SearchUpperBoundTime(time, sameTypeOfMolecule);
220 G4cout <<
"G4MoleculeCounter::AddAMoleculeAtTime : " << molecule->
GetName()
224 auto counterMap_i = fCounterMap.find(molecule);
226 if (counterMap_i == fCounterMap.end())
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::RemoveAMoleculeAtTime",
280 G4cout <<
"G4MoleculeCounter::RemoveAMoleculeAtTime : "
285 if (fCheckTimeIsConsistentWithScheduler)
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;
379 for (
auto it : fCounterMap)
381 output->push_back(
it.first);
392 for(
const auto&
it : fCounterMap)
394 for(
const auto& it2 :
it.second)
397 output->insert(it2.first);
432 for (
auto it : fCounterMap)
434 auto pReactant =
it.first;
436 G4cout <<
" --- > For " << pReactant->GetName() <<
G4endl;
438 for (
auto it2 :
it.second)
441 <<
" " << it2.second <<
G4endl;
452 G4cout <<
" ---> G4MoleculeCounter::ResetCounter" <<
G4endl;
455 fpLastSearch.reset(0);
483 fDontRegister[molDef] =
true;
490 if (fDontRegister.find(molDef) == fDontRegister.end())
501 fDontRegister.clear();
506 return fCheckTimeIsConsistentWithScheduler;
511 fCheckTimeIsConsistentWithScheduler = flag;