Skip to content
Snippets Groups Projects
Commit 212e988a authored by adrien-matta's avatar adrien-matta
Browse files

* Adding Messenger for Primary generator action

  - Reload the current generator
  - Load a different one
  - Adding corresponding button in the GUI
parent 1af83b88
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
NPSimulation/icons/aperture.png

3.39 KiB

NPSimulation/icons/bolt.png

2.48 KiB

...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
// NPTool headers // NPTool headers
#include "VEventGenerator.hh" #include "VEventGenerator.hh"
#include "DetectorConstruction.hh" #include "DetectorConstruction.hh"
#include "PrimaryGeneratorActionMessenger.hh"
using namespace std; using namespace std;
using namespace CLHEP; using namespace CLHEP;
...@@ -47,6 +48,7 @@ class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction{ ...@@ -47,6 +48,7 @@ class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction{
public: public:
void ReadEventGeneratorFile(string Path); void ReadEventGeneratorFile(string Path);
void ClearEventGenerator();
public: public:
void SetTarget(); void SetTarget();
...@@ -54,6 +56,7 @@ class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction{ ...@@ -54,6 +56,7 @@ class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction{
private: private:
DetectorConstruction* m_detector; DetectorConstruction* m_detector;
vector<VEventGenerator*> m_EventGenerator; vector<VEventGenerator*> m_EventGenerator;
PrimaryGeneratorActionMessenger* m_Messenger;
}; };
#endif #endif
#ifndef PrimaryGeneratorActionMessenger_h
#define PrimaryGeneratorActionMessenger_h 1
/*****************************************************************************
* Copyright (C) 2009-2013 this file is part of the NPTool Project *
* *
* For the licensing terms see $NPTOOL/Licence/NPTool_Licence *
* For the list of contributors see $NPTOOL/Licence/Contributors *
*****************************************************************************/
/*****************************************************************************
* Original Author: Adrien MATTA contact address: a.matta@surrey.ac.uk *
* *
* Creation Date : November 2014 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class describe the PrimaryGeneratorAction Messenger *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
*****************************************************************************/
///....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "globals.hh"
#include "G4UImessenger.hh"
class PrimaryGeneratorAction;
class G4UIdirectory;
class G4UICommand;
class G4UIcmdWithAString;
class G4UIcmdWithAnInteger;
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithoutParameter;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class PrimaryGeneratorActionMessenger: public G4UImessenger{
public:
PrimaryGeneratorActionMessenger(PrimaryGeneratorAction* );
~PrimaryGeneratorActionMessenger();
void SetNewValue(G4UIcommand*, G4String);
private:
PrimaryGeneratorAction* PGA;
G4UIdirectory* GenDir;
G4UIcmdWithoutParameter* UpdateCmd;
G4UIcmdWithAString* OpenCmd;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
/gui/addIcon "nptool" user_icon "/gui/system {gui_nptool}" icons/NPToolLogo.png /gui/addIcon "nptool" user_icon "/gui/system {gui_nptool}" icons/NPToolLogo.png
/gui/addIcon "Exit" user_icon "{gui_exit}" icons/power.png /gui/addIcon "Exit" user_icon "{gui_exit}" icons/power.png
/gui/addIcon "Update geometry" user_icon "{gui_update}" icons/recycle.png /gui/addIcon "Update geometry" user_icon "{gui_update}" icons/recycle.png
/gui/addIcon "Update generator" user_icon "/gen/update" icons/bolt.png
/gui/addIcon "Open generator" user_icon "/gen/open" icons/folder.png
/gui/addIcon "There is nothing here" user_icon "{gui_empty}" icons/empty.png /gui/addIcon "There is nothing here" user_icon "{gui_empty}" icons/empty.png
/gui/addIcon "Run beam on" user_icon "/run/beamOn" icons/rocket.png /gui/addIcon "Run beam on" user_icon "/run/beamOn" icons/rocket.png
/gui/addIcon "One event" user_icon "{gui_beamon}" icons/play.png /gui/addIcon "One event" user_icon "{gui_beamon}" icons/play.png
......
...@@ -58,7 +58,7 @@ PrimaryGeneratorAction::~PrimaryGeneratorAction(){ ...@@ -58,7 +58,7 @@ PrimaryGeneratorAction::~PrimaryGeneratorAction(){
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* det): m_detector(det){ PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* det): m_detector(det){
m_Messenger = new PrimaryGeneratorActionMessenger(this);
} }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
...@@ -180,6 +180,16 @@ void PrimaryGeneratorAction::ReadEventGeneratorFile(string Path){ ...@@ -180,6 +180,16 @@ void PrimaryGeneratorAction::ReadEventGeneratorFile(string Path){
EventGeneratorFile.close(); EventGeneratorFile.close();
} }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void PrimaryGeneratorAction::ClearEventGenerator(){
unsigned int mysize = m_EventGenerator.size();
for (unsigned int i = 0 ; i < mysize; i++) {
delete m_EventGenerator[i];
}
m_EventGenerator.clear();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void PrimaryGeneratorAction::SetTarget(){ void PrimaryGeneratorAction::SetTarget(){
for (unsigned int i = 0 ; i < m_EventGenerator.size(); i++) { for (unsigned int i = 0 ; i < m_EventGenerator.size(); i++) {
m_EventGenerator[i]->SetTarget(m_detector->GetTarget()); m_EventGenerator[i]->SetTarget(m_detector->GetTarget());
......
/*****************************************************************************
* Copyright (C) 2009-2013 this file is part of the NPTool Project *
* *
* For the licensing terms see $NPTOOL/Licence/NPTool_Licence *
* For the list of contributors see $NPTOOL/Licence/Contributors *
*****************************************************************************/
/*****************************************************************************
* Original Author: Adrien MATTA contact address: a.matta@surrey.ac.uk *
* *
* Creation Date : November 2014 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class describe the PrimaryGeneratorAction Messenger *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
*****************************************************************************/
///....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "PrimaryGeneratorActionMessenger.hh"
#include "PrimaryGeneratorAction.hh"
#include "G4UIparameter.hh"
#include "G4UIcommand.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "NPOptionManager.h"
#include <dirent.h>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorActionMessenger::PrimaryGeneratorActionMessenger(PrimaryGeneratorAction* Gen):PGA(Gen){
GenDir = new G4UIdirectory("/gen/");
GenDir->SetGuidance("event generator control");
UpdateCmd = new G4UIcmdWithoutParameter("/gen/update",this);
UpdateCmd->SetGuidance("Update the event generator");
UpdateCmd->SetGuidance("Apply this command after editing your event generator file ");
UpdateCmd->AvailableForStates(G4State_Idle);
DIR *dir;
struct dirent *ent;
string path = getenv("NPTOOL");
path += "/Inputs/EventGenerator/";
string choices;
if ((dir = opendir (path.c_str())) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
choices += ent->d_name ;
choices += " " ;
}
closedir (dir);
}
OpenCmd = new G4UIcmdWithAString("/gen/open",this);
OpenCmd->SetGuidance("Open a new event generator");
OpenCmd->SetCandidates(choices.c_str());
OpenCmd->AvailableForStates(G4State_Idle);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorActionMessenger::~PrimaryGeneratorActionMessenger(){
delete UpdateCmd;
delete OpenCmd;
delete GenDir;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void PrimaryGeneratorActionMessenger::SetNewValue(G4UIcommand* command,G4String newValue){
if( command == UpdateCmd ){
PGA->ClearEventGenerator();
PGA->ReadEventGeneratorFile(NPOptionManager::getInstance()->GetReactionFile());
}
else if( command == OpenCmd ){
PGA->ClearEventGenerator();
NPOptionManager::getInstance()->SetReactionFile(newValue);
PGA->ReadEventGeneratorFile(NPOptionManager::getInstance()->GetReactionFile());
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment