51#ifdef G4_USESMARTSTACK
64 delete userStackingAction;
69 G4cout <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <<
G4endl;
71 G4cout <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <<
G4endl;
78 if(numberOfAdditionalWaitingStacks>0)
80 for(
G4int i=0; i<numberOfAdditionalWaitingStacks; ++i)
82 delete additionalWaitingStacks[i];
94 ED <<
"A track without proper process manager is pushed \
95 into the track stack.\n"
99 ED <<
"created by a primary particle generator.";
110 ED <<
"creaded by unknown process.";
113 G4Exception(
"G4StackManager::PushOneTrack",
"Event10051",
119 DefineDefaultClassification( newTrack );
121 if(userStackingAction!=
nullptr)
124 if(classification != fDefaultClassification)
129 ed <<
"UserStackingAction has changed the track classification from "
130 << fDefaultClassification <<
" to " << classification <<
". ";
131 G4Exception(
"G4StackManager::PushOneTrack",
"Event10052",
132 fExceptionSeverity,ed);
141 if( verboseLevel > 1 )
143 G4cout <<
"### Storing a track ("
146 <<
",parentID=" << newTrack->
GetParentID() <<
") ";
148 {
G4cout <<
"created by a primary particle generator "; }
155 {
G4cout <<
"creaded by unknown process "; }
161 SortOut(newStackedTrack,classification);
169 if( verboseLevel > 1 )
171 G4cout <<
"### pop requested out of "
179 if( verboseLevel > 1 )
182 <<
" waiting tracks are re-classified to" <<
G4endl;
186 if(numberOfAdditionalWaitingStacks>0)
188 for(
G4int i=0; i<numberOfAdditionalWaitingStacks; ++i)
192 additionalWaitingStacks[0]->TransferTo(waitingStack);
196 additionalWaitingStacks[i]->TransferTo(additionalWaitingStacks[i-1]);
200 if(userStackingAction !=
nullptr)
206 if( verboseLevel > 1 )
209 <<
" waiting tracks." <<
G4endl;
220 if( verboseLevel > 2 )
222 G4cout <<
"Selected G4StackedTrack : " << &selectedStackedTrack
223 <<
" with G4Track " << selectedStackedTrack.
GetTrack()
230 return selectedTrack;
238 if( userStackingAction ==
nullptr )
return;
245 DefineDefaultClassification( aStackedTrack.
GetTrack() );
247 if(userStackingAction!=
nullptr)
250 if(classification != fDefaultClassification)
255 ed <<
"UserStackingAction has changed the track classification from "
256 << fDefaultClassification <<
" to " << classification <<
". ";
257 G4Exception(
"G4StackManager::PushOneTrack",
"Event10052",
258 fExceptionSeverity,ed);
266 SortOut(aStackedTrack,classification);
272 if(userStackingAction !=
nullptr)
282 G4int n_passedFromPrevious = 0;
287 if( verboseLevel > 1 )
290 <<
" postponed tracked are now shifted to the stack." <<
G4endl;
303 DefineDefaultClassification( aTrack );
305 if(userStackingAction!=
nullptr)
308 if(classification != fDefaultClassification)
313 ed <<
"UserStackingAction has changed the track classification from "
314 << fDefaultClassification <<
" to " << classification <<
". ";
315 G4Exception(
"G4StackManager::PushOneTrack",
"Event10052",
316 fExceptionSeverity,ed);
320 if(classification!=
fKill)
323 aTrack->
SetTrackID(-(++n_passedFromPrevious));
329 SortOut(aStackedTrack,classification);
334 for(
auto& ses : subEvtStackMap)
335 { ses.second->PrepareNewEvent(currentEvent); }
337 return n_passedFromPrevious;
342 if(classification==
fKill)
347 if( verboseLevel > 1 )
349 G4cout <<
" ---> G4Track " << newTrack <<
" (trackID "
355 delete newTrajectory;
359 switch (classification)
371 if(classification < 100)
374 G4int i = classification - 10;
375 if(i<1 || i>numberOfAdditionalWaitingStacks)
378 ED <<
"invalid classification " << classification <<
G4endl;
379 G4Exception(
"G4StackManager::SortOut",
"Event0051",
384 additionalWaitingStacks[i-1]->PushToStack( aStackedTrack );
390 G4int ty = classification - 100;
391 auto ses = subEvtStackMap.find(ty);
392 if(ses==subEvtStackMap.end())
395 ED <<
"invalid classification " << classification <<
G4endl;
396 G4Exception(
"G4StackManager::SortOut",
"Event0051",
401 ses->second->PushToStack( aStackedTrack );
411 if(iAdd > numberOfAdditionalWaitingStacks)
413 for(
G4int i=numberOfAdditionalWaitingStacks; i<iAdd; ++i)
416 additionalWaitingStacks.push_back(newStack);
418 numberOfAdditionalWaitingStacks = iAdd;
420 else if (iAdd < numberOfAdditionalWaitingStacks)
422 for(
G4int i=numberOfAdditionalWaitingStacks; i>iAdd; --i)
424 delete additionalWaitingStacks[i];
433 if(origin==destination)
return;
434 if(origin==
fKill)
return;
439 originStack =
nullptr;
442 originStack = waitingStack;
445 originStack = postponeStack;
448 G4int i = origin - 10;
449 if(i<=numberOfAdditionalWaitingStacks)
451 originStack = additionalWaitingStacks[i-1];
456 ED <<
"Invalid origin stack ID " << origin;
457 G4Exception(
"G4StackManager::TransferStackedTracks",
"Stack0911",
463 if(destination==
fKill)
465 if(originStack !=
nullptr)
480 targetStack =
nullptr;
483 targetStack = waitingStack;
486 targetStack = postponeStack;
489 G4int i = destination - 10;
490 if(i<=numberOfAdditionalWaitingStacks)
492 targetStack = additionalWaitingStacks[i-1];
497 ED <<
"Invalid origin stack ID " << origin;
498 G4Exception(
"G4StackManager::TransferStackedTracks",
"Stack0911",
503 if(originStack !=
nullptr)
505 if(targetStack !=
nullptr)
526 if(origin==destination)
return;
527 if(origin==
fKill)
return;
532 originStack =
nullptr;
535 originStack = waitingStack;
538 originStack = postponeStack;
541 G4int i = origin - 10;
542 if(i<=numberOfAdditionalWaitingStacks)
544 originStack = additionalWaitingStacks[i-1];
549 ED <<
"Invalid origin stack ID " << origin;
550 G4Exception(
"G4StackManager::TransferStackedTracks",
"Stack0911",
557 if(destination==
fKill)
559 if( originStack !=
nullptr && (originStack->
GetNTrack() != 0u) )
565 else if (urgentStack->
GetNTrack() != 0u )
578 targetStack =
nullptr;
581 targetStack = waitingStack;
584 targetStack = postponeStack;
587 G4int i = destination - 10;
588 if(i<=numberOfAdditionalWaitingStacks)
590 targetStack = additionalWaitingStacks[i-1];
595 ED <<
"Invalid origin stack ID " << origin;
596 G4Exception(
"G4StackManager::TransferStackedTracks",
"Stack0911",
601 if((originStack !=
nullptr) && (originStack->
GetNTrack() != 0u))
604 if(targetStack !=
nullptr) { targetStack->
PushToStack(aStackedTrack); }
610 if(targetStack !=
nullptr) { targetStack->
PushToStack(aStackedTrack); }
621 for(
G4int i=1; i<=numberOfAdditionalWaitingStacks; ++i)
640 if(i<=numberOfAdditionalWaitingStacks)
642 additionalWaitingStacks[i-1]->clearAndDestroy();
657 for(
G4int i=1; i<=numberOfAdditionalWaitingStacks; ++i)
659 n += additionalWaitingStacks[i-1]->GetNTrack();
676 if(i<=numberOfAdditionalWaitingStacks)
678 return (
G4int)additionalWaitingStacks[i-1]->GetNTrack();
691 verboseLevel = value;
692 for(
auto& sets : subEvtStackMap)
693 { sets.second->SetVerboseLevel(value); }
698 userStackingAction = value;
699 if(userStackingAction !=
nullptr)
705void G4StackManager::DefineDefaultClassification(
const G4Track* aTrack)
707 fDefaultClassification =
fUrgent;
710 if(defClassPartDef.size()>0)
713 if(pdm!=defClassPartDef.end())
715 fDefaultClassification = pdm->second.first;
716 fExceptionSeverity = pdm->second.second;
719 else if(defClassTrackStatus.size()>0)
722 if(tsm!=defClassTrackStatus.end())
724 fDefaultClassification = tsm->second.first;
725 fExceptionSeverity = tsm->second.second;
729 { fDefaultClassification =
fWaiting; }
737 auto tsm = defClassTrackStatus.find(ts);
738 if(tsm==defClassTrackStatus.end())
739 { defClassTrackStatus[ts] = std::pair(val,es); }
742 if(tsm->second.first!=val)
745 ed <<
"Default classification for track status " << ts
746 <<
" is changed from " << tsm->second.first <<
" to "
748 G4Exception(
"G4StackManager::SetDefaultClassification",
750 tsm->second.first = val;
753 if(tsm->second.second>es) tsm->second.second = es;
760 auto pdm = defClassPartDef.find(pd);
761 if(pdm==defClassPartDef.end())
762 { defClassPartDef[pd] = std::pair(val,es); }
765 if(pdm->second.first!=val)
769 <<
" is changed from " << pdm->second.first <<
" to "
771 G4Exception(
"G4StackManager::SetDefaultClassification",
773 pdm->second.first = val;
776 if(pdm->second.second>es) pdm->second.second = es;
782 if(subEvtStackMap.find(ty)==subEvtStackMap.end())
785 subEvtTypes.push_back(ty);
787 subEvtStackMap[ty]->SetVerboseLevel(verboseLevel);
788 if( verboseLevel > 0 )
790 G4cout <<
" ---> New sub-event stack for sub-event type "
791 << ty <<
" is created. Classification id for this stack is "
792 << subEvtTypes.size() + 99 <<
"." <<
G4endl;
797 if( verboseLevel > 1 )
799 G4cout <<
" ---> Sub-event stack for sub-event type "
800 << ty <<
" already registered." <<
G4endl;
808 auto ses = subEvtStackMap.find(ty);
809 if(ses==subEvtStackMap.end())
812 ED <<
"Un-registered sub-event type " << ty <<
" requested.";
813 G4Exception(
"G4StackManager::PopSubEvent",
"SubEvt8001",
818 ses->second->ReleaseSubEvent();
G4ClassificationOfNewTrack
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cout
G4int GetParticleDefinitionID() const
const G4String & GetParticleName() const
G4int GetNTotalTrack() const
void TransferOneStackedTrack(G4ClassificationOfNewTrack origin, G4ClassificationOfNewTrack destination)
G4int GetNUrgentTrack() const
G4int GetNPostponedTrack() const
void SetNumberOfAdditionalWaitingStacks(G4int iAdd)
void SetVerboseLevel(G4int const value)
G4Track * PopNextTrack(G4VTrajectory **newTrajectory)
G4int PrepareNewEvent(G4Event *currentEvent)
G4int PushOneTrack(G4Track *newTrack, G4VTrajectory *newTrajectory=nullptr)
void RegisterSubEventType(G4int ty, G4int maxEnt)
void ClearWaitingStack(G4int i=0)
void SetDefaultClassification(G4TrackStatus, G4ClassificationOfNewTrack, G4ExceptionSeverity es=G4ExceptionSeverity::IgnoreTheIssue)
void TransferStackedTracks(G4ClassificationOfNewTrack origin, G4ClassificationOfNewTrack destination)
void SetUserStackingAction(G4UserStackingAction *value)
void ClearPostponeStack()
G4int GetNWaitingTrack(G4int i=0) const
void ReleaseSubEvent(G4int ty)
G4Track * GetTrack() const
G4VTrajectory * GetTrajectory() const
void PushToStack(const G4StackedTrack &aStackedTrack)
void TransferTo(G4TrackStack *aStack)
std::size_t GetNTrack() const
G4StackedTrack PopFromStack()
std::size_t GetMaxNTrack() const
G4TrackStatus GetTrackStatus() const
void SetTrackStatus(const G4TrackStatus aTrackStatus)
const G4ParticleDefinition * GetParticleDefinition() const
const G4VProcess * GetCreatorProcess() const
void SetTrackID(const G4int aValue)
G4int GetParentID() const
void SetParentID(const G4int aValue)
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack)
virtual void PrepareNewEvent()
void SetStackManager(G4StackManager *value)
const G4String & GetProcessName() const