Geant4 11.1.1
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 68 of file G4GenericMessenger.hh.

Member Enumeration Documentation

◆ UnitSpec

Enumerator
UnitCategory 
UnitDefault 

Definition at line 70 of file G4GenericMessenger.hh.

Constructor & Destructor Documentation

◆ Command() [1/2]

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

Definition at line 75 of file G4GenericMessenger.hh.

76 : command(cmd)
77 , type(&ti)
78 {}
const std::type_info * type

◆ Command() [2/2]

G4GenericMessenger::Command::Command ( )
default

Member Function Documentation

◆ SetCandidates() [1/2]

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

Definition at line 408 of file G4GenericMessenger.cc.

410{
411 return SetCandidates(0,candList);
412}
Command & SetCandidates(const G4String &)

◆ SetCandidates() [2/2]

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

Definition at line 414 of file G4GenericMessenger.cc.

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

◆ SetDefaultUnit()

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

Definition at line 125 of file G4GenericMessenger.hh.

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

◆ SetDefaultValue() [1/2]

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

Definition at line 428 of file G4GenericMessenger.cc.

430{
431 return SetDefaultValue(0,defVal);
432}
Command & SetDefaultValue(const G4String &)

◆ SetDefaultValue() [2/2]

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

Definition at line 434 of file G4GenericMessenger.cc.

436{
437 if(pIdx < 0 || pIdx >= (G4int)(command->GetParameterEntries()))
438 {
439 G4cerr << "Invalid parameter index : " << pIdx << "\nMethod ignored."
440 << G4endl;
441 return *this;
442 }
443 G4UIparameter* theParam = command->GetParameter(pIdx);
444 theParam->SetDefaultValue(defVal);
445 return *this;
446}
void SetDefaultValue(const char *theDefaultValue)

◆ SetGuidance()

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

Definition at line 115 of file G4GenericMessenger.hh.

116 {
117 command->SetGuidance(s0);
118 return *this;
119 }
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157

◆ 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 383 of file G4GenericMessenger.cc.

386{
387 if(*type != typeid(G4ThreeVector))
388 {
389 G4cerr << "This SetParameterName method is for G4ThreeVector!! "
390 << "Method ignored." << G4endl;
391 return *this;
392 }
393 G4UIparameter* theParam = command->GetParameter(0);
394 theParam->SetParameterName(namex);
395 theParam->SetOmittable(omittable);
396 theParam->SetCurrentAsDefault(currentAsDefault);
397 theParam = command->GetParameter(1);
398 theParam->SetParameterName(namey);
399 theParam->SetOmittable(omittable);
400 theParam->SetCurrentAsDefault(currentAsDefault);
401 theParam = command->GetParameter(2);
402 theParam->SetParameterName(namez);
403 theParam->SetOmittable(omittable);
404 theParam->SetCurrentAsDefault(currentAsDefault);
405 return *this;
406}
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 360 of file G4GenericMessenger.cc.

362{
363 return SetParameterName(0,name,omittable,currentAsDefault);
364}
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 366 of file G4GenericMessenger.cc.

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

◆ SetRange()

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

Definition at line 110 of file G4GenericMessenger.hh.

111 {
112 command->SetRange(range.c_str());
113 return *this;
114 }
void SetRange(const char *rs)
Definition: G4UIcommand.hh:121

◆ SetStates() [1/5]

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

Definition at line 81 of file G4GenericMessenger.hh.

82 {
84 return *this;
85 }
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:287

Referenced by G4SteppingVerboseWithUnits::SetManager().

◆ SetStates() [2/5]

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

Definition at line 86 of file G4GenericMessenger.hh.

87 {
89 return *this;
90 }

◆ SetStates() [3/5]

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

Definition at line 91 of file G4GenericMessenger.hh.

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

◆ SetStates() [4/5]

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

Definition at line 97 of file G4GenericMessenger.hh.

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

◆ SetStates() [5/5]

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

Definition at line 103 of file G4GenericMessenger.hh.

106 {
107 command->AvailableForStates(s0, s1, s2, s3, s4);
108 return *this;
109 }

◆ SetToBeBroadcasted()

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

Definition at line 137 of file G4GenericMessenger.hh.

138 {
140 return *this;
141 }
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:172

◆ SetToBeFlushed()

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

Definition at line 142 of file G4GenericMessenger.hh.

143 {
145 return *this;
146 }
void SetToBeFlushed(G4bool val)
Definition: G4UIcommand.hh:174

◆ SetUnit()

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

Definition at line 271 of file G4GenericMessenger.cc.

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

Referenced by SetDefaultUnit(), and SetUnitCategory().

◆ SetUnitCategory()

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

Definition at line 121 of file G4GenericMessenger.hh.

122 {
123 return SetUnit(u, UnitCategory);
124 }

◆ SetWorkerThreadOnly()

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

Definition at line 147 of file G4GenericMessenger.hh.

148 {
150 return *this;
151 }
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:176

Member Data Documentation

◆ command

G4UIcommand* G4GenericMessenger::Command::command = nullptr

◆ type

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

Definition at line 154 of file G4GenericMessenger.hh.

Referenced by SetUnit().


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