Skip to content

Commit

Permalink
feat(sim): Update FairMCApplication states
Browse files Browse the repository at this point in the history
Added few states as well as few checks.
Previous state order: `kUnknownState` -> `kConstructGeometry` -> `kUnknownState` -> `kInitGeometry` -> `kUnknownState`
Currently: `kPreInit` -> `kConstructGeometry` -> `kInit` -> `kInitGeometry` -> `kInit` -> `kPostInit` -> `kRun`.
  • Loading branch information
karabowi committed Aug 28, 2024
1 parent 00898f9 commit b4a2bfc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
16 changes: 9 additions & 7 deletions fairroot/base/sim/FairMCApplication.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ FairMCApplication::FairMCApplication(const char* name, const char* title, TObjAr
, fMC(nullptr)
, fRun(FairRunSim::Instance())
, fSaveCurrentEvent(kTRUE)
, fState(FairMCApplicationState::kUnknownState)
, fRunInfo()
, fGeometryIsInitialized(kFALSE)
, fOwnedModules()
Expand Down Expand Up @@ -153,7 +152,6 @@ FairMCApplication::FairMCApplication(const FairMCApplication& rhs, std::unique_p
, listDetectors()
, fMC(nullptr)
, fSaveCurrentEvent(kTRUE)
, fState(FairMCApplicationState::kUnknownState)
, fRunInfo()
, fGeometryIsInitialized(kFALSE)
, fOwnedModules()
Expand Down Expand Up @@ -227,7 +225,6 @@ FairMCApplication::FairMCApplication()
, listDetectors()
, fMC(nullptr)
, fSaveCurrentEvent(kTRUE)
, fState(FairMCApplicationState::kUnknownState)
, fRunInfo()
, fGeometryIsInitialized(kFALSE)
, fOwnedModules()
Expand Down Expand Up @@ -284,13 +281,16 @@ void FairMCApplication::InitMC(const char*, const char*)
}

InitFinalizer();
fState = FairMCApplicationState::kPostInit;

LOG(info) << "Monte Carlo Engine Initialisation with: " << MCName.Data();
}

//_____________________________________________________________________________
void FairMCApplication::RunMC(Int_t nofEvents)
{
fState = FairMCApplicationState::kRun;

// Reset the time for FairRunInfo. Otherwise the time of the
// first event will include the time needed for initilization.
fRunInfo.Reset();
Expand Down Expand Up @@ -637,8 +637,8 @@ void FairMCApplication::FinishEvent()
LOG(debug) << "[" << fRootManager->GetInstanceId()
<< " FairMCMCApplication::FinishEvent: " << fMCEventHeader->GetEventID() << " (MC "
<< gMC->CurrentEvent() << ")";
if (gMC->IsMT()
&& fRun->GetSink()->GetSinkType() == kONLINESINK) { // fix the rare case when running G4 multithreaded on MQ
if (gMC->IsMT() && fRun->GetSink()->GetSinkType() == kONLINESINK)
{ // fix the rare case when running G4 multithreaded on MQ
fMCEventHeader->SetEventID(gMC->CurrentEvent() + 1);
}

Expand Down Expand Up @@ -820,7 +820,7 @@ void FairMCApplication::ConstructGeometry()

gGeoManager->RefreshPhysicalNodes(kFALSE);

fState = FairMCApplicationState::kUnknownState;
fState = FairMCApplicationState::kInit;
}

// ____________________________________________________________________________
Expand All @@ -834,6 +834,8 @@ Bool_t FairMCApplication::MisalignGeometry()
//_____________________________________________________________________________
void FairMCApplication::InitGeometry()
{
if (FairMCApplicationState::kInit != fState)
LOG(fatal) << "InitGeometry possible in kInit state only";
fState = FairMCApplicationState::kInitGeometry;

LOG(info) << "FairMCApplication::InitGeometry: " << fRootManager->GetInstanceId();
Expand Down Expand Up @@ -917,7 +919,7 @@ void FairMCApplication::InitGeometry()

fGeometryIsInitialized = kTRUE;

fState = FairMCApplicationState::kUnknownState;
fState = FairMCApplicationState::kInit;
}

//_____________________________________________________________________________
Expand Down
9 changes: 6 additions & 3 deletions fairroot/base/sim/FairMCApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ class TTask;

enum class FairMCApplicationState
{
kUnknownState,
kPreInit,
kConstructGeometry,
kInitGeometry
kInit,
kInitGeometry,
kPostInit,
kRun
};

/**
Expand Down Expand Up @@ -323,7 +326,7 @@ class FairMCApplication : public TVirtualMCApplication
Bool_t fSaveCurrentEvent;

/** Current state */
FairMCApplicationState fState; //!
FairMCApplicationState fState{FairMCApplicationState::kPreInit}; //!

ClassDefOverride(FairMCApplication, 5);

Expand Down

0 comments on commit b4a2bfc

Please sign in to comment.