musrSim: Get rid of manual memory management
This commit is contained in:
+20
-49
@@ -12,9 +12,6 @@
|
||||
#include "G4UIterminal.hh"
|
||||
#include "G4UItcsh.hh" //JSL: should be commented on windows ?
|
||||
|
||||
// #include <TApplication.h>
|
||||
// #include <TSystem.h>
|
||||
|
||||
// The following two lines are needed to cope with the problem of
|
||||
// "Error in <TPluginManager::FindHandler>: Cannot find plugin handler for TVirtualStreamerInfo!
|
||||
// Does $ROOTSYS/etc/plugins/TVirtualStreamerInfo exist?"
|
||||
@@ -23,20 +20,18 @@
|
||||
|
||||
#include "Randomize.hh"
|
||||
|
||||
// #include <X11/Xlib.h> //JSL
|
||||
|
||||
// #include "musrVisManager.hh"
|
||||
#include "G4VisExecutive.hh"
|
||||
#include "G4TrajectoryDrawByCharge.hh" // TS Trajectory drawing by ID or charge
|
||||
|
||||
#include "musrRootOutput.hh"
|
||||
#include "musrParameters.hh"
|
||||
#include "musrErrorMessage.hh"
|
||||
// #include "F04GlobalField.hh"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
G4String steeringFileName;
|
||||
if (argc > 1) {
|
||||
steeringFileName = argv[1];
|
||||
@@ -45,31 +40,26 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// XInitThreads();
|
||||
G4cout << "\n\n*************************************************************" << G4endl;
|
||||
G4cout << " musrSim version 1.0.5 for Geant4.10.3, released on 20 Mar 2017" << G4endl;
|
||||
G4cout << " musrSim version 1.0.5 for Geant 11.4" << G4endl;
|
||||
G4cout << " WWW: https://www.psi.ch/lmu/geant4-simulations" << G4endl;
|
||||
// choose the Random engine
|
||||
// CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); // the /musr/run/randomOption 2 does not work with
|
||||
// RanecuEngine
|
||||
CLHEP::HepRandom::setTheEngine(new CLHEP::HepJamesRandom);
|
||||
|
||||
// my Verbose output class
|
||||
G4VSteppingVerbose::SetInstance(new musrSteppingVerbose);
|
||||
|
||||
// Run manager
|
||||
G4RunManager *runManager = new G4RunManager;
|
||||
auto runManager = std::make_unique<G4RunManager>();
|
||||
|
||||
// Create class "myParameters", which is a collection of many different parameters
|
||||
musrParameters *myParameters = new musrParameters(steeringFileName);
|
||||
auto myParameters = std::make_unique<musrParameters>(steeringFileName);
|
||||
|
||||
// Create class "musrErrorMessage"
|
||||
musrErrorMessage *myErrorMessage = new musrErrorMessage();
|
||||
|
||||
// TApplication* myapp=new TApplication("myapp",0,0);
|
||||
auto myErrorMessage = std::make_unique<musrErrorMessage>();
|
||||
|
||||
// Create Root class for storing the output of the Geant simulation
|
||||
musrRootOutput *myRootOutput = new musrRootOutput();
|
||||
auto myRootOutput = std::make_unique<musrRootOutput>();
|
||||
|
||||
// The following command is needed to cope with the problem of
|
||||
// "Error in <TPluginManager::FindHandler>: Cannot find plugin handler for TVirtualStreamerInfo!
|
||||
@@ -78,22 +68,21 @@ int main(int argc, char **argv)
|
||||
gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo", "RIO", "TStreamerInfo()");
|
||||
|
||||
// UserInitialization classes (mandatory)
|
||||
// musrDetectorConstruction* musrdetector = new musrDetectorConstruction;
|
||||
if (argc > 1) {
|
||||
G4int myRunNr = atoi(argv[1]); // Get the run number from the name of the
|
||||
// parameter file, if it starts with a number.
|
||||
G4int myRunNr = std::atoi(argv[1]); // Get the run number from the name of the
|
||||
// parameter file, if it starts with a number.
|
||||
if (myRunNr > 0) {
|
||||
runManager->SetRunIDCounter(myRunNr);
|
||||
}
|
||||
// musrdetector->SetInputParameterFileName(argv[1]);
|
||||
}
|
||||
musrDetectorConstruction *musrdetector = new musrDetectorConstruction(steeringFileName);
|
||||
// Keep raw pointer for cross-object writing but in principle object should be owned by runManager
|
||||
// after the next line
|
||||
auto musrdetector = new musrDetectorConstruction(steeringFileName);
|
||||
runManager->SetUserInitialization(musrdetector);
|
||||
runManager->SetUserInitialization(new musrPhysicsList);
|
||||
|
||||
// Visualization, if you choose to have it!
|
||||
// G4VisManager* visManager = new musrVisManager;
|
||||
G4VisManager *visManager = new G4VisExecutive; // TS Trajectory drawing by ID or charge
|
||||
auto visManager = std::make_unique<G4VisExecutive>();
|
||||
visManager->Initialize();
|
||||
|
||||
// UserAction classes
|
||||
@@ -103,6 +92,7 @@ int main(int argc, char **argv)
|
||||
// Initiate musrStackingAction only if optical photons are required (otherwise not needed)
|
||||
if (musrParameters::boolG4OpticalPhotons)
|
||||
runManager->SetUserAction(new musrStackingAction);
|
||||
|
||||
runManager->SetUserAction(new musrSteppingAction);
|
||||
|
||||
// Initialize G4 kernel
|
||||
@@ -111,44 +101,25 @@ int main(int argc, char **argv)
|
||||
// get the pointer to the User Interface manager
|
||||
G4UImanager *UI = G4UImanager::GetUIpointer();
|
||||
|
||||
if (argc == 1)
|
||||
// Define (G)UI terminal for interactive mode
|
||||
{
|
||||
// G4UIterminal is a (dumb) terminal.
|
||||
G4UIsession *session = 0;
|
||||
session = new G4UIterminal();
|
||||
|
||||
if (argc == 1) {
|
||||
auto session = std::make_unique<G4UIterminal>();
|
||||
UI->ApplyCommand("/control/execute vis.mac");
|
||||
session->SessionStart();
|
||||
delete session;
|
||||
} else
|
||||
// Batch mode
|
||||
{
|
||||
} else {
|
||||
G4String command = "/control/execute ";
|
||||
G4String fileName = argv[1];
|
||||
UI->ApplyCommand(command + fileName);
|
||||
|
||||
if (argc > 2) {
|
||||
G4String SecondArgument = argv[2];
|
||||
if (SecondArgument == "idle") {
|
||||
G4UIsession *session = 0;
|
||||
session = new G4UIterminal();
|
||||
auto session = std::make_unique<G4UIterminal>();
|
||||
G4cout << "Go to idle state now:" << G4endl;
|
||||
session->SessionStart();
|
||||
delete session;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// myapp->Run(kTRUE);
|
||||
|
||||
delete visManager;
|
||||
delete myRootOutput;
|
||||
delete myErrorMessage;
|
||||
delete myParameters;
|
||||
// cks runManager->SetVerboseLevel(2); // This line can help debug crashes during the runManager delete
|
||||
delete runManager;
|
||||
// F04GlobalField* myGlobalField = F04GlobalField::getObject();
|
||||
// if (myGlobalField!=NULL) {delete myGlobalField;}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user