Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GenericMessenger::Command Struct Reference

#include <G4GenericMessenger.hh>

+ Inheritance diagram for G4GenericMessenger::Command:

Public Types

enum  UnitSpec { UnitCategory , UnitDefault }
 

Public Member Functions

 Command (G4UIcommand *cmd, const std::type_info &ti)
 
 Command ()=default
 
CommandSetStates (G4ApplicationState s0)
 
CommandSetStates (G4ApplicationState s0, G4ApplicationState s1)
 
CommandSetStates (G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2)
 
CommandSetStates (G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3)
 
CommandSetStates (G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3, G4ApplicationState s4)
 
CommandSetRange (const G4String &range)
 
CommandSetGuidance (const G4String &s0)
 
CommandSetUnit (const G4String &, UnitSpec=UnitDefault)
 
CommandSetUnitCategory (const G4String &u)
 
CommandSetDefaultUnit (const G4String &u)
 
CommandSetParameterName (const G4String &, G4bool, G4bool=false)
 
CommandSetParameterName (G4int pIdx, const G4String &, G4bool, G4bool=false)
 
CommandSetParameterName (const G4String &, const G4String &, const G4String &, G4bool, G4bool=false)
 
CommandSetDefaultValue (const G4String &)
 
CommandSetDefaultValue (G4int pIdx, const G4String &)
 
CommandSetCandidates (const G4String &)
 
CommandSetCandidates (G4int pIdx, const G4String &)
 
CommandSetToBeBroadcasted (G4bool s0)
 
CommandSetToBeFlushed (G4bool s0)
 
CommandSetWorkerThreadOnly (G4bool s0)
 

Public Attributes

G4UIcommandcommand = nullptr
 
const std::type_info * type = nullptr
 

Detailed Description

Definition at line 65 of file G4GenericMessenger.hh.

Member Enumeration Documentation

◆ UnitSpec

Enumerator
UnitCategory 
UnitDefault 

Definition at line 67 of file G4GenericMessenger.hh.

Constructor & Destructor Documentation

◆ Command() [1/2]

G4GenericMessenger::Command::Command ( G4UIcommand * cmd,
const std::type_info & ti )
inline

Definition at line 72 of file G4GenericMessenger.hh.

72: command(cmd), type(&ti) {}

◆ Command() [2/2]

G4GenericMessenger::Command::Command ( )
default

Member Function Documentation

◆ SetCandidates() [1/2]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetCandidates ( const G4String & candList)

Definition at line 407 of file G4GenericMessenger.cc.

408{
409 return SetCandidates(0, candList);
410}
Command & SetCandidates(const G4String &)

◆ SetCandidates() [2/2]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetCandidates ( G4int pIdx,
const G4String & candList )

Definition at line 412 of file G4GenericMessenger.cc.

414{
415 if (pIdx < 0 || pIdx >= (G4int)(command->GetParameterEntries())) {
416 G4cerr << "Invalid parameter index : " << pIdx << "\nMethod ignored." << G4endl;
417 return *this;
418 }
419 G4UIparameter* theParam = command->GetParameter(pIdx);
420 theParam->SetParameterCandidates(candList);
421 return *this;
422}
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
std::size_t GetParameterEntries() const
G4UIparameter * GetParameter(G4int i) const
void SetParameterCandidates(const char *theString)

◆ SetDefaultUnit()

Command & G4GenericMessenger::Command::SetDefaultUnit ( const G4String & u)
inline

Definition at line 114 of file G4GenericMessenger.hh.

114{ return SetUnit(u, UnitDefault); }
Command & SetUnit(const G4String &, UnitSpec=UnitDefault)

◆ SetDefaultValue() [1/2]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetDefaultValue ( const G4String & defVal)

Definition at line 424 of file G4GenericMessenger.cc.

425{
426 return SetDefaultValue(0, defVal);
427}
Command & SetDefaultValue(const G4String &)

◆ SetDefaultValue() [2/2]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetDefaultValue ( G4int pIdx,
const G4String & defVal )

Definition at line 429 of file G4GenericMessenger.cc.

431{
432 if (pIdx < 0 || pIdx >= (G4int)(command->GetParameterEntries())) {
433 G4cerr << "Invalid parameter index : " << pIdx << "\nMethod ignored." << G4endl;
434 return *this;
435 }
436 G4UIparameter* theParam = command->GetParameter(pIdx);
437 theParam->SetDefaultValue(defVal);
438 return *this;
439}
void SetDefaultValue(const char *theDefaultValue)

◆ SetGuidance()

Command & G4GenericMessenger::Command::SetGuidance ( const G4String & s0)
inline

Definition at line 107 of file G4GenericMessenger.hh.

108 {
109 command->SetGuidance(s0);
110 return *this;
111 }
void SetGuidance(const char *aGuidance)

◆ SetParameterName() [1/3]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetParameterName ( const G4String & namex,
const G4String & namey,
const G4String & namez,
G4bool omittable,
G4bool currentAsDefault = false )

Definition at line 381 of file G4GenericMessenger.cc.

386{
387 if (*type != typeid(G4ThreeVector)) {
388 G4cerr << "This SetParameterName method is for G4ThreeVector!! "
389 << "Method ignored." << G4endl;
390 return *this;
391 }
392 G4UIparameter* theParam = command->GetParameter(0);
393 theParam->SetParameterName(namex);
394 theParam->SetOmittable(omittable);
395 theParam->SetCurrentAsDefault(currentAsDefault);
396 theParam = command->GetParameter(1);
397 theParam->SetParameterName(namey);
398 theParam->SetOmittable(omittable);
399 theParam->SetCurrentAsDefault(currentAsDefault);
400 theParam = command->GetParameter(2);
401 theParam->SetParameterName(namez);
402 theParam->SetOmittable(omittable);
403 theParam->SetCurrentAsDefault(currentAsDefault);
404 return *this;
405}
void SetParameterName(const char *pName)
void SetOmittable(G4bool om)
void SetCurrentAsDefault(G4bool val)

◆ SetParameterName() [2/3]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetParameterName ( const G4String & name,
G4bool omittable,
G4bool currentAsDefault = false )

Definition at line 358 of file G4GenericMessenger.cc.

361{
362 return SetParameterName(0, name, omittable, currentAsDefault);
363}
Command & SetParameterName(const G4String &, G4bool, G4bool=false)

◆ SetParameterName() [3/3]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetParameterName ( G4int pIdx,
const G4String & name,
G4bool omittable,
G4bool currentAsDefault = false )

Definition at line 365 of file G4GenericMessenger.cc.

369{
370 if (pIdx < 0 || pIdx >= (G4int)(command->GetParameterEntries())) {
371 G4cerr << "Invalid parameter index : " << pIdx << "\nMethod ignored." << G4endl;
372 return *this;
373 }
374 G4UIparameter* theParam = command->GetParameter(pIdx);
375 theParam->SetParameterName(name);
376 theParam->SetOmittable(omittable);
377 theParam->SetCurrentAsDefault(currentAsDefault);
378 return *this;
379}

◆ SetRange()

Command & G4GenericMessenger::Command::SetRange ( const G4String & range)
inline

Definition at line 102 of file G4GenericMessenger.hh.

103 {
104 command->SetRange(range.c_str());
105 return *this;
106 }
void SetRange(const char *rs)

◆ SetStates() [1/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState s0)
inline

Definition at line 75 of file G4GenericMessenger.hh.

76 {
78 return *this;
79 }
void AvailableForStates(G4ApplicationState s1)

Referenced by G4SteppingVerboseWithUnits::SetManager().

◆ SetStates() [2/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState s0,
G4ApplicationState s1 )
inline

Definition at line 80 of file G4GenericMessenger.hh.

81 {
83 return *this;
84 }

◆ SetStates() [3/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState s0,
G4ApplicationState s1,
G4ApplicationState s2 )
inline

Definition at line 85 of file G4GenericMessenger.hh.

86 {
87 command->AvailableForStates(s0, s1, s2);
88 return *this;
89 }

◆ SetStates() [4/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState s0,
G4ApplicationState s1,
G4ApplicationState s2,
G4ApplicationState s3 )
inline

Definition at line 90 of file G4GenericMessenger.hh.

92 {
93 command->AvailableForStates(s0, s1, s2, s3);
94 return *this;
95 }

◆ SetStates() [5/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState s0,
G4ApplicationState s1,
G4ApplicationState s2,
G4ApplicationState s3,
G4ApplicationState s4 )
inline

Definition at line 96 of file G4GenericMessenger.hh.

98 {
99 command->AvailableForStates(s0, s1, s2, s3, s4);
100 return *this;
101 }

◆ SetToBeBroadcasted()

Command & G4GenericMessenger::Command::SetToBeBroadcasted ( G4bool s0)
inline

Definition at line 123 of file G4GenericMessenger.hh.

124 {
126 return *this;
127 }
void SetToBeBroadcasted(G4bool val)

◆ SetToBeFlushed()

Command & G4GenericMessenger::Command::SetToBeFlushed ( G4bool s0)
inline

Definition at line 128 of file G4GenericMessenger.hh.

129 {
131 return *this;
132 }
void SetToBeFlushed(G4bool val)

◆ SetUnit()

G4GenericMessenger::Command & G4GenericMessenger::Command::SetUnit ( const G4String & unit,
UnitSpec spec = UnitDefault )

Definition at line 281 of file G4GenericMessenger.cc.

283{
284 // Change the type of command (unfortunatelly this is done a posteriory)
285 // We need to delete the old command before creating the new one and therefore
286 // we need to recover the information before the deletetion
288 G4String cmdpath = command->GetCommandPath();
290 ed << "G4GenericMessenger::Command::SetUnit() is thread-unsafe and should "
291 "not be used\n"
292 << "in multi-threaded mode. For your command <" << cmdpath << ">, use\n"
293 << " DeclarePropertyWithUnit(const G4String& name, const G4String& "
294 "defaultUnit,\n"
295 << " const G4AnyType& variable, const G4String& "
296 "doc)\n"
297 << "or\n"
298 << " DeclareMethodWithUnit(const G4String& name, const G4String& "
299 "defaultUnit,\n"
300 << " const G4AnyType& variable, const G4String& "
301 "doc)\n"
302 << "to define a command with a unit <" << unit << ">.";
303 if (spec != UnitDefault) {
304 ed << "\nPlease use a default unit instead of unit category.";
305 }
306 G4Exception("G4GenericMessenger::Command::SetUnit()", "Intercom70001", FatalException, ed);
307 return *this;
308 }
309
310 G4String cmdpath = command->GetCommandPath();
311 G4UImessenger* messenger = command->GetMessenger();
312 G4String range = command->GetRange();
313 std::vector<G4String> guidance;
315 G4bool par_omitable = command->GetParameter(0)->IsOmittable();
316 for (G4int i = 0; i < (G4int)command->GetGuidanceEntries(); ++i) {
317 guidance.push_back(command->GetGuidanceLine(i));
318 }
319 // Before deleting the command we need to add a fake one to avoid deleting
320 // the directory entry and with its guidance
321 G4UIcommand tmp((cmdpath + "_tmp").c_str(), messenger);
322 delete command;
323
324 if (*type == typeid(float) || *type == typeid(double)) {
325 auto* cmd_t = new G4UIcmdWithADoubleAndUnit(cmdpath, messenger);
326 if (spec == UnitDefault) {
327 cmd_t->SetDefaultUnit(unit);
328 }
329 else if (spec == UnitCategory) {
330 cmd_t->SetUnitCategory(unit);
331 }
332 cmd_t->SetParameterName(par_name, par_omitable);
333 command = cmd_t;
334 }
335 else if (*type == typeid(G4ThreeVector)) {
336 auto* cmd_t = new G4UIcmdWith3VectorAndUnit(cmdpath, messenger);
337 if (spec == UnitDefault) {
338 cmd_t->SetDefaultUnit(unit);
339 }
340 else if (spec == UnitCategory) {
341 cmd_t->SetUnitCategory(unit);
342 }
343 command = cmd_t;
344 }
345 else {
346 G4cerr << "Only parameters of type <double> or <float> can be associated "
347 "with units"
348 << G4endl;
349 return *this;
350 }
351 for (auto& i : guidance) {
353 }
354 command->SetRange(range);
355 return *this;
356}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
bool G4bool
Definition G4Types.hh:86
G4UImessenger * GetMessenger() const
const G4String & GetGuidanceLine(G4int i) const
const G4String & GetCommandPath() const
std::size_t GetGuidanceEntries() const
const G4String & GetRange() const
G4bool IsOmittable() const
const G4String & GetParameterName() const
G4bool IsMultithreadedApplication()

Referenced by SetDefaultUnit(), and SetUnitCategory().

◆ SetUnitCategory()

Command & G4GenericMessenger::Command::SetUnitCategory ( const G4String & u)
inline

Definition at line 113 of file G4GenericMessenger.hh.

113{ return SetUnit(u, UnitCategory); }

◆ SetWorkerThreadOnly()

Command & G4GenericMessenger::Command::SetWorkerThreadOnly ( G4bool s0)
inline

Definition at line 133 of file G4GenericMessenger.hh.

134 {
136 return *this;
137 }
void SetWorkerThreadOnly(G4bool val=true)

Member Data Documentation

◆ command

G4UIcommand* G4GenericMessenger::Command::command = nullptr

◆ type

const std::type_info* G4GenericMessenger::Command::type = nullptr

Definition at line 140 of file G4GenericMessenger.hh.

Referenced by SetUnit().


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