Skip to content

Commit

Permalink
Try to debug root saving for Windows MT
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaudier committed Sep 30, 2024
1 parent a305351 commit dec8fff
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/opengate_core/opengate_lib/GatePhaseSpaceActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ G4Mutex TotalEntriesMutex = G4MUTEX_INITIALIZER;

GatePhaseSpaceActor::GatePhaseSpaceActor(py::dict &user_info)
: GateVActor(user_info, true) {
std::cout << __func__ << std::endl;
fActions.insert("StartSimulationAction");
fActions.insert("BeginOfRunAction");
fActions.insert("BeginOfEventAction");
Expand All @@ -35,10 +36,12 @@ GatePhaseSpaceActor::GatePhaseSpaceActor(py::dict &user_info)
}

GatePhaseSpaceActor::~GatePhaseSpaceActor() {
std::cout << __func__ << std::endl;
// for debug
}

void GatePhaseSpaceActor::InitializeUserInput(py::dict &user_info) {
std::cout << __func__ << std::endl;
GateVActor::InitializeUserInput(user_info);
fDigiCollectionName = DictGetStr(user_info, "name");
fUserDigiAttributeNames = DictGetVecStr(user_info, "attributes");
Expand All @@ -53,13 +56,15 @@ void GatePhaseSpaceActor::InitializeUserInput(py::dict &user_info) {
}

void GatePhaseSpaceActor::InitializeCpp() {
std::cout << __func__ << std::endl;
fHits = nullptr;
fTotalNumberOfEntries = 0;
fNumberOfAbsorbedEvents = 0;
}

// Called when the simulation start
void GatePhaseSpaceActor::StartSimulationAction() {
std::cout << __func__ << std::endl;
fHits = GateDigiCollectionManager::GetInstance()->NewDigiCollection(
fDigiCollectionName);

Expand All @@ -84,11 +89,13 @@ void GatePhaseSpaceActor::StartSimulationAction() {

// Called every time a Run starts
void GatePhaseSpaceActor::BeginOfRunAction(const G4Run *run) {
std::cout << __func__ << std::endl;
if (run->GetRunID() == 0)
fHits->RootInitializeTupleForWorker();
}

void GatePhaseSpaceActor::BeginOfEventAction(const G4Event * /*event*/) {
std::cout << __func__ << std::endl;
auto &l = fThreadLocalData.Get();
l.fFirstStepInVolume = true;
if (fStoreAbsorbedEvent) {
Expand All @@ -102,6 +109,7 @@ void GatePhaseSpaceActor::BeginOfEventAction(const G4Event * /*event*/) {
}

void GatePhaseSpaceActor::PreUserTrackingAction(const G4Track *track) {
std::cout << __func__ << std::endl;
auto &l = fThreadLocalData.Get();
l.fFirstStepInVolume = true;
if (fDebug) {
Expand All @@ -114,6 +122,7 @@ void GatePhaseSpaceActor::PreUserTrackingAction(const G4Track *track) {

// Called every time a batch of step must be processed
void GatePhaseSpaceActor::SteppingAction(G4Step *step) {
std::cout << __func__ << std::endl;
/*
Only store if the particle enters and/or exits the volume.
(We CANNOT use step->IsFirstStepInVolume() because it fails with parallel
Expand Down Expand Up @@ -185,6 +194,7 @@ void GatePhaseSpaceActor::SteppingAction(G4Step *step) {
}

void GatePhaseSpaceActor::EndOfEventAction(const G4Event *event) {
std::cout << __func__ << std::endl;
// For a given event, when no step never reach the phsp:
// if the option is on, we store a "fake" step, with the event information.
// All other attributes will be "empty" (mostly 0)
Expand Down Expand Up @@ -223,6 +233,7 @@ void GatePhaseSpaceActor::EndOfEventAction(const G4Event *event) {

// Called every time a Run ends
void GatePhaseSpaceActor::EndOfRunAction(const G4Run * /*unused*/) {
std::cout << __func__ << std::endl;
{
G4AutoLock mutex(&TotalEntriesMutex);
fTotalNumberOfEntries += fHits->GetSize();
Expand All @@ -233,19 +244,23 @@ void GatePhaseSpaceActor::EndOfRunAction(const G4Run * /*unused*/) {
// Called every time a Run ends
void GatePhaseSpaceActor::EndOfSimulationWorkerAction(
const G4Run * /*unused*/) {
std::cout << __func__ << std::endl;
fHits->Write();
}

// Called when the simulation ends
void GatePhaseSpaceActor::EndSimulationAction() {
std::cout << __func__ << std::endl;
fHits->Write();
fHits->Close();
}

int GatePhaseSpaceActor::GetNumberOfAbsorbedEvents() const {
std::cout << __func__ << std::endl;
return fNumberOfAbsorbedEvents;
}

int GatePhaseSpaceActor::GetTotalNumberOfEntries() const {
std::cout << __func__ << std::endl;
return fTotalNumberOfEntries;
}

0 comments on commit dec8fff

Please sign in to comment.