Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4NtupleMessenger Class Reference

#include <G4NtupleMessenger.hh>

+ Inheritance diagram for G4NtupleMessenger:

Public Member Functions

 G4NtupleMessenger (G4VAnalysisManager *manager)
 
virtual ~G4NtupleMessenger ()
 
virtual void SetNewValue (G4UIcommand *command, G4String value) final
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool operator!= (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (G4String s)
 
G4long StoL (G4String s)
 
G4double StoD (G4String s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 

Detailed Description

Definition at line 45 of file G4NtupleMessenger.hh.

Constructor & Destructor Documentation

◆ G4NtupleMessenger()

G4NtupleMessenger::G4NtupleMessenger ( G4VAnalysisManager manager)
explicit

Definition at line 59 of file G4NtupleMessenger.cc.

60 : G4UImessenger(),
61 fManager(manager),
62 fSetActivationCmd(nullptr),
63 fSetActivationAllCmd(nullptr),
64 fSetFileNameCmd(nullptr),
65 fSetFileNameAllCmd(nullptr)
66{
67 fNtupleDir = G4Analysis::make_unique<G4UIdirectory>("/analysis/ntuple/");
68 fNtupleDir->SetGuidance("ntuple control");
69
70 SetActivationCmd();
71 SetActivationToAllCmd();
72 SetFileNameCmd();
73 SetFileNameToAllCmd();
74}

◆ ~G4NtupleMessenger()

G4NtupleMessenger::~G4NtupleMessenger ( )
virtual

Definition at line 77 of file G4NtupleMessenger.cc.

78{
79}

Member Function Documentation

◆ SetNewValue()

void G4NtupleMessenger::SetNewValue ( G4UIcommand command,
G4String  value 
)
finalvirtual

Reimplemented from G4UImessenger.

Definition at line 150 of file G4NtupleMessenger.cc.

151{
152 if ( command == fSetActivationCmd.get() ) {
153 // tokenize parameters in a vector
154 std::vector<G4String> parameters;
155 G4Analysis::Tokenize(newValues, parameters);
156 // check consistency
157 if ( parameters.size() == command->GetParameterEntries() ) {
158 auto counter = 0;
159 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
160 auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
161 fManager->SetNtupleActivation(id, activation);
162 }
163 else {
164 // Should never happen but let's check anyway for consistency
165 WrongParametersException(command->GetCommandName(),
166 parameters.size(),command->GetParameterEntries());
167 }
168 }
169 else if ( command == fSetActivationAllCmd.get() ) {
170 auto activation = fSetActivationAllCmd->GetNewBoolValue(newValues);
171 fManager->SetNtupleActivation(activation);
172 }
173 else if ( command == fSetFileNameCmd.get() ) {
174 // tokenize parameters in a vector
175 std::vector<G4String> parameters;
176 G4Analysis::Tokenize(newValues, parameters);
177 // check consistency
178 if ( parameters.size() == command->GetParameterEntries() ) {
179 auto counter = 0;
180 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
181 auto fileName = parameters[counter++];
182 fManager->SetNtupleFileName(id, fileName);
183 }
184 else {
185 // Should never happen but let's check anyway for consistency
186 WrongParametersException(command->GetCommandName(),
187 parameters.size(),command->GetParameterEntries());
188 }
189 }
190 else if ( command == fSetFileNameAllCmd.get() ) {
191 auto fileName = newValues;
192 fManager->SetNtupleFileName(fileName);
193 }
194}
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:543
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:530
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:137
void SetNtupleFileName(const G4String &fileName)
void SetNtupleActivation(G4bool activation)
void Tokenize(const G4String &line, std::vector< G4String > &tokens)

The documentation for this class was generated from the following files: