54 fCheckTimeIsConsistentWithScheduler =
true;
75 while ((mol_iterator)())
77 if(IsRegistered(mol_iterator.
value()->GetDefinition()) ==
false)
84 fCounterMap[mol_iterator.
value()];
99 if (fpLastSearch.get() == 0)
101 fpLastSearch.reset(
new Search());
105 if (fpLastSearch->fLowerBoundSet &&
106 fpLastSearch->fLastMoleculeSearched->first == molecule)
110 CounterMapType::iterator mol_it = fCounterMap.find(molecule);
111 fpLastSearch->fLastMoleculeSearched = mol_it;
113 if (mol_it != fCounterMap.end())
115 fpLastSearch->fLowerBoundTime = fpLastSearch->fLastMoleculeSearched->second
117 fpLastSearch->fLowerBoundSet =
true;
121 fpLastSearch->fLowerBoundSet =
false;
130 bool sameTypeOfMolecule)
132 CounterMapType::iterator mol_it = fpLastSearch->fLastMoleculeSearched;
133 if (mol_it == fCounterMap.end())
return 0;
136 if (timeMap.empty())
return 0;
138 NbMoleculeAgainstTime::iterator end_time = timeMap.end();
140 if (sameTypeOfMolecule ==
true)
143 if (fpLastSearch->fLowerBoundSet && fpLastSearch->fLowerBoundTime
146 if (fpLastSearch->fLowerBoundTime->first < time)
148 NbMoleculeAgainstTime::iterator upperToLast = fpLastSearch
152 if (upperToLast == end_time)
154 return fpLastSearch->fLowerBoundTime->second;
157 if (upperToLast->first > time)
159 return fpLastSearch->fLowerBoundTime->second;
172 NbMoleculeAgainstTime::iterator up_time_it = timeMap.upper_bound(time);
174 if (up_time_it == end_time)
176 NbMoleculeAgainstTime::reverse_iterator last_time = timeMap.rbegin();
180 return last_time->second;
186 if (up_time_it == timeMap.begin())
198 fpLastSearch->fLowerBoundTime = up_time_it;
199 fpLastSearch->fLowerBoundSet =
true;
203 return fpLastSearch->fLowerBoundTime->second;
211 G4bool sameTypeOfMolecule = SearchTimeMap(molecule);
212 return SearchUpperBoundTime(time, sameTypeOfMolecule);
225 G4cout <<
"G4MoleculeCounter::AddAMoleculeAtTime : " << molecule->
GetName()
229 CounterMapType::iterator counterMap_i =
230 fCounterMap.find(molecule);
232 if (counterMap_i == fCounterMap.end()){
233 fCounterMap[molecule][time] = number;
235 else if (counterMap_i->second.empty()){
236 counterMap_i->second[time] = number;
239 NbMoleculeAgainstTime::reverse_iterator end = counterMap_i->second.rbegin();
241 if (end->first <= time ||
246 double newValue = end->second + number;
247 counterMap_i->second[time] = newValue;
255 errMsg <<
"Time of species "
256 << molecule->
GetName() <<
" is "
258 <<
" global time is "
261 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
281 G4cout <<
"G4MoleculeCounter::RemoveAMoleculeAtTime : "
286 if(fCheckTimeIsConsistentWithScheduler)
292 errMsg <<
"Time of species "
293 << molecule->
GetName() <<
" is "
295 <<
" global time is "
298 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
306 if (nbMolPerTime.empty())
311 "You are trying to remove molecule " + molecule->
GetName()
312 +
" from the counter while this kind of molecules has not been registered yet";
313 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
"",
320 NbMoleculeAgainstTime::reverse_iterator it = nbMolPerTime.rbegin();
322 if (it == nbMolPerTime.rend()){
326 +
" recorded at the time or even before the time asked";
327 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
"",
334 errMsg <<
"Is time going back?? " << molecule->
GetName()
335 <<
" is being removed at time " <<
G4BestUnit(time,
"Time")
336 <<
" while last recorded time was "
338 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
339 "RETURN_TO_THE_FUTUR",
344 double finalN = it->second - number;
349 errMsg <<
"After removal of " << number <<
" species of "
350 << molecule->
GetName() <<
" the final number at time "
351 <<
G4BestUnit(time,
"Time") <<
" is less than zero and so not valid."
352 <<
" Global time is "
354 <<
". Previous selected time is "
357 G4Exception(
"G4MoleculeCounter::RemoveAMoleculeAtTime",
362 nbMolPerTime[time] = finalN;
372 G4cout <<
"Entering in G4MoleculeCounter::RecordMolecules" <<
G4endl;
375 CounterMapType::iterator it;
378 for(it = fCounterMap.begin(); it != fCounterMap.end(); it++)
380 output->push_back(it->first);
393 CounterMapType::iterator it;
394 CounterMapType::const_iterator ite;
396 NbMoleculeAgainstTime::iterator it2;
397 NbMoleculeAgainstTime::const_iterator ite2;
400 for (it = fCounterMap.begin(), ite = fCounterMap.end(); it != ite; ++it)
403 for (it2 = (it->second).begin(), ite2 = (it->second).end(); it2 != ite2;
407 output->insert(it2->first);
442 CounterMapType::iterator it = fCounterMap.begin();
443 CounterMapType::iterator end = fCounterMap.end();
450 NbMoleculeAgainstTime::iterator it2 = it->second.begin();
451 NbMoleculeAgainstTime::iterator end2 = it->second.end();
453 for(;it2!=end2;++it2)
456 <<
" " << it2->second <<
G4endl;
void AddAMoleculeAtTime(G4MolecularConfiguration *, G4double time, const G4ThreeVector *position=nullptr, int number=1) override
The pointer G4MolecularConfiguration will be shared by all the molecules having the same molecule def...
void PrintState() const
Display the electronic state of the molecule.
int SearchUpperBoundTime(double time, bool sameTypeOfMolecule)
const G4String & GetName() const
Returns the name of the molecule.
std::ostringstream G4ExceptionDescription
CLHEP::Hep3Vector G4ThreeVector
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
std::unique_ptr< std::vector< G4MolecularConfiguration * > > RecordedMolecules
void RemoveAMoleculeAtTime(G4MolecularConfiguration *, G4double time, const G4ThreeVector *position=nullptr, int number=1) override
static G4Scheduler * Instance()
static constexpr double picosecond
G4bool SearchTimeMap(G4MolecularConfiguration *molecule)
int GetNMoleculesAtTime(G4MolecularConfiguration *molecule, double time)
RecordedMolecules GetRecordedMolecules()
G4GLOB_DLL std::ostream G4cout
static G4MoleculeCounter * Instance()
void Initialize() override
static G4MoleculeTable * Instance()
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
const G4MoleculeDefinition * GetDefinition() const
std::map< G4double, G4int, compDoubleWithPrecision > NbMoleculeAgainstTime
RecordedTimes GetRecordedTimes()
virtual ~G4MoleculeCounter()
void SetTimeSlice(double)