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

#include <G4UIcmdWithADoubleAndUnit.hh>

+ Inheritance diagram for G4UIcmdWithADoubleAndUnit:

Public Member Functions

 G4UIcmdWithADoubleAndUnit (const char *theCommandPath, G4UImessenger *theMessenger)
 
virtual G4int DoIt (G4String parameterList)
 
G4String ConvertToStringWithBestUnit (G4double val)
 
G4String ConvertToStringWithDefaultUnit (G4double val)
 
void SetParameterName (const char *theName, G4bool omittable, G4bool currentAsDefault=false)
 
void SetDefaultValue (G4double defVal)
 
void SetUnitCategory (const char *unitCategory)
 
void SetUnitCandidates (const char *candidateList)
 
void SetDefaultUnit (const char *defUnit)
 
- Public Member Functions inherited from G4UIcommand
 G4UIcommand ()
 
 G4UIcommand (const char *theCommandPath, G4UImessenger *theMessenger, G4bool tBB=true)
 
virtual ~G4UIcommand ()
 
G4bool operator== (const G4UIcommand &right) const
 
G4bool operator!= (const G4UIcommand &right) const
 
virtual G4int DoIt (G4String parameterList)
 
G4String GetCurrentValue ()
 
void AvailableForStates (G4ApplicationState s1)
 
void AvailableForStates (G4ApplicationState s1, G4ApplicationState s2)
 
void AvailableForStates (G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3)
 
void AvailableForStates (G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3, G4ApplicationState s4)
 
void AvailableForStates (G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3, G4ApplicationState s4, G4ApplicationState s5)
 
G4bool IsAvailable ()
 
virtual void List ()
 
void SetRange (const char *rs)
 
const G4StringGetRange () const
 
std::size_t GetGuidanceEntries () const
 
const G4StringGetGuidanceLine (G4int i) const
 
const G4StringGetCommandPath () const
 
const G4StringGetCommandName () const
 
std::size_t GetParameterEntries () const
 
G4UIparameterGetParameter (G4int i) const
 
std::vector< G4ApplicationState > * GetStateList ()
 
G4UImessengerGetMessenger () const
 
void SetParameter (G4UIparameter *const newParameter)
 
void SetGuidance (const char *aGuidance)
 
const G4String GetTitle () const
 
void SetToBeBroadcasted (G4bool val)
 
G4bool ToBeBroadcasted () const
 
void SetToBeFlushed (G4bool val)
 
G4bool ToBeFlushed () const
 
void SetWorkerThreadOnly (G4bool val=true)
 
G4bool IsWorkerThreadOnly () const
 
void CommandFailed (G4int errCode, G4ExceptionDescription &ed)
 
void CommandFailed (G4ExceptionDescription &ed)
 
G4int IfCommandFailed ()
 
const G4StringGetFailureDescription ()
 
void ResetFailure ()
 

Static Public Member Functions

static G4double GetNewDoubleValue (const char *paramString)
 
static G4double GetNewDoubleRawValue (const char *paramString)
 
static G4double GetNewUnitValue (const char *paramString)
 
- Static Public Member Functions inherited from G4UIcommand
static G4String ConvertToString (G4bool boolVal)
 
static G4String ConvertToString (G4int intValue)
 
static G4String ConvertToString (G4long longValue)
 
static G4String ConvertToString (G4double doubleValue)
 
static G4String ConvertToString (G4double doubleValue, const char *unitName)
 
static G4String ConvertToString (G4ThreeVector vec)
 
static G4String ConvertToString (G4ThreeVector vec, const char *unitName)
 
static G4bool ConvertToBool (const char *st)
 
static G4int ConvertToInt (const char *st)
 
static G4long ConvertToLongInt (const char *st)
 
static G4double ConvertToDouble (const char *st)
 
static G4double ConvertToDimensionedDouble (const char *st)
 
static G4ThreeVector ConvertTo3Vector (const char *st)
 
static G4ThreeVector ConvertToDimensioned3Vector (const char *st)
 
static G4double ValueOf (const char *unitName)
 
static G4String CategoryOf (const char *unitName)
 
static G4String UnitsList (const char *unitCategory)
 

Additional Inherited Members

- Protected Types inherited from G4UIcommand
using yystype = G4UItokenNum::yystype
 
using tokenNum = G4UItokenNum::tokenNum
 
- Protected Member Functions inherited from G4UIcommand
G4int CheckNewValue (const char *newValue)
 
- Protected Attributes inherited from G4UIcommand
G4bool toBeBroadcasted = false
 
G4bool toBeFlushed = false
 
G4bool workerThreadOnly = false
 
G4int commandFailureCode = 0
 
G4String failureDescription = ""
 

Detailed Description

Definition at line 41 of file G4UIcmdWithADoubleAndUnit.hh.

Constructor & Destructor Documentation

◆ G4UIcmdWithADoubleAndUnit()

G4UIcmdWithADoubleAndUnit::G4UIcmdWithADoubleAndUnit ( const char *  theCommandPath,
G4UImessenger theMessenger 
)

Definition at line 39 of file G4UIcmdWithADoubleAndUnit.cc.

41 : G4UIcommand(theCommandPath, theMessenger)
42{
43 G4UIparameter* dblParam = new G4UIparameter('d');
44 SetParameter(dblParam);
45 G4UIparameter* untParam = new G4UIparameter('s');
46 SetParameter(untParam);
47 untParam->SetParameterName("Unit");
48}
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
void SetParameterName(const char *pName)

Member Function Documentation

◆ ConvertToStringWithBestUnit()

G4String G4UIcmdWithADoubleAndUnit::ConvertToStringWithBestUnit ( G4double  val)

Definition at line 125 of file G4UIcmdWithADoubleAndUnit.cc.

126{
127 G4UIparameter* unitParam = GetParameter(1);
128 G4String canList = unitParam->GetParameterCandidates();
129 G4Tokenizer candidateTokenizer(canList);
130 G4String aToken = candidateTokenizer();
131 std::ostringstream os;
132 os << G4BestUnit(val, CategoryOf(aToken));
133
134 G4String st = os.str();
135 return st;
136}
#define G4BestUnit(a, b)
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:139
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:356
const G4String & GetParameterCandidates() const

Referenced by ConvertToStringWithDefaultUnit(), and G4MoleculeShootMessenger::GetCurrentValue().

◆ ConvertToStringWithDefaultUnit()

G4String G4UIcmdWithADoubleAndUnit::ConvertToStringWithDefaultUnit ( G4double  val)

Definition at line 139 of file G4UIcmdWithADoubleAndUnit.cc.

140{
141 G4UIparameter* unitParam = GetParameter(1);
142 G4String st;
143 if(unitParam->IsOmittable())
144 {
145 st = ConvertToString(val, unitParam->GetDefaultValue());
146 }
147 else
148 {
150 }
151 return st;
152}
G4String ConvertToStringWithBestUnit(G4double val)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:430
G4bool IsOmittable() const
const G4String & GetDefaultValue() const

◆ DoIt()

G4int G4UIcmdWithADoubleAndUnit::DoIt ( G4String  parameterList)
virtual

Reimplemented from G4UIcommand.

Definition at line 51 of file G4UIcmdWithADoubleAndUnit.cc.

52{
53 std::vector<G4String> token_vector;
54 G4Tokenizer tkn(parameterList);
55 G4String str;
56 while((str = tkn()) != "")
57 {
58 token_vector.push_back(str);
59 }
60
61 // convert a value in default unit
62 G4String converted_parameter;
63 G4String default_unit = GetParameter(1)->GetDefaultValue();
64 if(default_unit != "" && token_vector.size() >= 2)
65 {
66 if(CategoryOf(token_vector[1]) != CategoryOf(default_unit))
67 {
69 }
70 G4double value_given = ValueOf(token_vector[1]);
71 G4double value_default = ValueOf(default_unit);
72 G4double value =
73 ConvertToDouble(token_vector[0]) * value_given / value_default;
74 // reconstruct parameter list
75 converted_parameter += ConvertToString(value);
76 converted_parameter += " ";
77 converted_parameter += default_unit;
78 for(std::size_t i = 2; i < token_vector.size(); ++i)
79 {
80 converted_parameter += " ";
81 converted_parameter += token_vector[i];
82 }
83 }
84 else
85 {
86 converted_parameter = parameterList;
87 }
88
89 return G4UIcommand::DoIt(converted_parameter);
90}
double G4double
Definition: G4Types.hh:83
@ fParameterOutOfCandidates
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:348
virtual G4int DoIt(G4String parameterList)
Definition: G4UIcommand.cc:135
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:561

◆ GetNewDoubleRawValue()

G4double G4UIcmdWithADoubleAndUnit::GetNewDoubleRawValue ( const char *  paramString)
static

Definition at line 99 of file G4UIcmdWithADoubleAndUnit.cc.

101{
102 G4double vl;
103 char unts[30];
104
105 std::istringstream is(paramString);
106 is >> vl >> unts;
107
108 return vl;
109}

◆ GetNewDoubleValue()

◆ GetNewUnitValue()

G4double G4UIcmdWithADoubleAndUnit::GetNewUnitValue ( const char *  paramString)
static

Definition at line 112 of file G4UIcmdWithADoubleAndUnit.cc.

113{
114 G4double vl;
115 char unts[30];
116
117 std::istringstream is(paramString);
118 is >> vl >> unts;
119 G4String unt = unts;
120
121 return ValueOf(unt);
122}

Referenced by G4GeometryMessenger::SetNewValue().

◆ SetDefaultUnit()

◆ SetDefaultValue()

◆ SetParameterName()

void G4UIcmdWithADoubleAndUnit::SetParameterName ( const char *  theName,
G4bool  omittable,
G4bool  currentAsDefault = false 
)

◆ SetUnitCandidates()

void G4UIcmdWithADoubleAndUnit::SetUnitCandidates ( const char *  candidateList)

Definition at line 179 of file G4UIcmdWithADoubleAndUnit.cc.

180{
181 G4UIparameter* untParam = GetParameter(1);
182 G4String canList = candidateList;
183 untParam->SetParameterCandidates(canList);
184}
void SetParameterCandidates(const char *theString)

Referenced by SetUnitCategory().

◆ SetUnitCategory()


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