Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate #455

Merged
merged 19 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.8.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Once installed, you can run all tests:
opengate_tests
````

**WARNING** The first time you run this command, the test data will be downloaded. If the download fails (on some systems), try to add the following command before running opengate_tests:
**WARNING** The first time you run this command, the geant4 data and the test data will be downloaded. If the download fails (on some systems), try to add the following command before running opengate_tests:
````
export GIT_SSL_NO_VERIFY=1
````
Expand Down
49 changes: 24 additions & 25 deletions core/opengate_core/opengate_lib/GateSourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ bool fUserStoppingCritReached = false;

GateSourceManager::GateSourceManager() {
fUIEx = nullptr;
fVisEx = nullptr;
fVisualizationVerboseFlag = false;
fVisualizationFlag = false;
fVisualizationTypeFlag = "qt";
fVisualizationType = "qt";
fVisualizationFile = "g4writertest.gdml";
fVerboseLevel = 0;
fUserEventInformationFlag = false;
Expand All @@ -49,10 +48,13 @@ GateSourceManager::GateSourceManager() {
l.fCurrentSimulationTime = 0;
l.fNextActiveSource = nullptr;
l.fNextSimulationTime = 0;
fExpectedNumberOfEvents = 0;
fUserStoppingCritReached = false;
fProgressBarStep = 1000;
fCurrentEvent = 0;
}

GateSourceManager::~GateSourceManager() {
delete fVisEx;
// fUIEx is already deleted
if (fProgressBarFlag) {
if (!G4Threading::IsMultithreadedApplication() ||
Expand All @@ -72,13 +74,12 @@ void GateSourceManager::Initialize(TimeIntervals simulation_times,
fOptions = options;
fVisualizationFlag = DictGetBool(options, "visu");
fVisualizationVerboseFlag = DictGetBool(options, "visu_verbose");
fVisualizationTypeFlag = DictGetStr(options, "visu_type");
fVisualizationType = DictGetStr(options, "visu_type");
fVisualizationFile = DictGetStr(options, "visu_filename");
if (fVisualizationTypeFlag == "vrml" ||
fVisualizationTypeFlag == "vrml_file_only")
if (fVisualizationType == "vrml" || fVisualizationType == "vrml_file_only")
fVisCommands = DictGetVecStr(options, "visu_commands_vrml");
else if (fVisualizationTypeFlag == "gdml" ||
fVisualizationTypeFlag == "gdml_file_only")
else if (fVisualizationType == "gdml" ||
fVisualizationType == "gdml_file_only")
fVisCommands = DictGetVecStr(options, "visu_commands_gdml");
else
fVisCommands = DictGetVecStr(options, "visu_commands");
Expand Down Expand Up @@ -134,7 +135,7 @@ void GateSourceManager::StartMasterThread() {
InitializeVisualization();
auto *uim = G4UImanager::GetUIpointer();
uim->ApplyCommand(run);
// std::cout << "Apply Beam On" << std::endl;

bool exit_sim_on_next_run = false;
for (auto &actor : fActors) {
int ret = actor->EndOfRunActionMasterThread(run_id);
Expand All @@ -151,7 +152,7 @@ void GateSourceManager::StartMasterThread() {
}
}

// progress bar
// progress bar (only thread 0)
if (fProgressBarFlag) {
if (G4Threading::IsMultithreadedApplication() &&
G4Threading::G4GetThreadId() != 0)
Expand Down Expand Up @@ -192,6 +193,8 @@ void GateSourceManager::ComputeExpectedNumberOfEvents() {
source->GetExpectedNumberOfEvents(fSimulationTimes);
}
fProgressBarStep = (long)round((double)fExpectedNumberOfEvents / 100.0);
if (fExpectedNumberOfEvents > 1e7)
fProgressBarStep = (long)round((double)fExpectedNumberOfEvents / 1000.0);
}

long int GateSourceManager::GetExpectedNumberOfEvents() const {
Expand Down Expand Up @@ -280,6 +283,7 @@ void GateSourceManager::GeneratePrimaries(G4Event *event) {
auto *vertex = new G4PrimaryVertex(p, l.fCurrentSimulationTime);
vertex->SetPrimary(particle);
event->AddPrimaryVertex(vertex);
// (allocated memory is leaked)
} else {
// shoot particle
l.fNextActiveSource->GeneratePrimaries(event, l.fCurrentSimulationTime);
Expand Down Expand Up @@ -329,15 +333,15 @@ void GateSourceManager::GeneratePrimaries(G4Event *event) {
}

void GateSourceManager::InitializeVisualization() {
if (!fVisualizationFlag || (fVisualizationTypeFlag == "gdml") ||
(fVisualizationTypeFlag == "gdml_file_only"))
if (!fVisualizationFlag || (fVisualizationType == "gdml") ||
(fVisualizationType == "gdml_file_only"))
return;

char *argv[1]; // ok on osx
// char **argv = new char*[1]; // not ok on osx
if (fVisualizationTypeFlag == "qt") {
fUIEx = new G4UIExecutive(1, argv, fVisualizationTypeFlag);
// fUIEx = new G4UIExecutive(1, argv, "qt"); // FIXME
char **argv = new char *[1]; // Allocate 1 element
argv[0] = nullptr; // Properly indicate no arguments

if (fVisualizationType == "qt") {
fUIEx = new G4UIExecutive(1, argv, fVisualizationType);
// FIXME does not always work on Linux ? only OSX for the moment
fUIEx->SetVerbose(fVisualizationVerboseFlag);
}
Expand Down Expand Up @@ -368,7 +372,7 @@ void GateSourceManager::InitializeVisualization() {

void GateSourceManager::StartVisualization() const {
#ifdef USE_GDML
if (fVisualizationTypeFlag == "gdml") {
if (fVisualizationType == "gdml") {
G4GDMLParser parser;
parser.SetRegionExport(true);
parser.Write(fVisualizationFile,
Expand All @@ -378,18 +382,13 @@ void GateSourceManager::StartVisualization() const {
->GetLogicalVolume());
}
#else
if (fVisualizationTypeFlag == "gdml") {
if (fVisualizationType == "gdml") {
std::cout << "Error: GDML is not activated with Geant4" << std::endl;
return;
}
#endif

// if (!fVisualizationFlag || (fVisualizationTypeFlag == "vrml") ||
// (fVisualizationTypeFlag == "vrml_file_only") ||
// (fVisualizationTypeFlag == "gdml") ||
// (fVisualizationTypeFlag == "gdml_file_only"))
// return;
if (fVisualizationFlag && fVisualizationTypeFlag == "qt") {
if (fVisualizationFlag && fVisualizationType == "qt") {
fUIEx->SessionStart();
delete fUIEx;
}
Expand Down
3 changes: 1 addition & 2 deletions core/opengate_core/opengate_lib/GateSourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ class GateSourceManager : public G4VUserPrimaryGeneratorAction {

bool fVisualizationFlag;
bool fVisualizationVerboseFlag;
std::string fVisualizationTypeFlag;
std::string fVisualizationType;
std::string fVisualizationFile;
G4UIExecutive *fUIEx;
G4VisExecutive *fVisEx;
std::vector<std::string> fVisCommands;
UIsessionSilent fSilent;

Expand Down
Loading
Loading