Geant4 11.1.1
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)
 
G4int DoIt (G4String parameterList) override
 
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 ()=default
 
 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 ()
 
CommandType GetCommandType () const
 
void SetCommandType (CommandType)
 
void SetDefaultSortFlag (G4bool val)
 

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 (const G4ThreeVector &vec)
 
static G4String ConvertToString (const 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

- Public Types inherited from G4UIcommand
enum  CommandType {
  BaseClassCmd , WithoutParameterCmd , WithABoolCmd , WithAnIntegerCmd ,
  WithALongIntCmd , WithADoubleCmd , WithADoubleAndUnitCmd , With3VectorCmd ,
  With3VectorAndUnitCmd , WithAStringCmd , CmdDirectory = -1
}
 
- 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 = ""
 
G4bool ifSort = false
 

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 auto* dblParam = new G4UIparameter('d');
44 SetParameter(dblParam);
45 auto* untParam = new G4UIparameter('s');
46 untParam->SetParameterName("Unit");
47 SetParameter(untParam);
49}
G4UIcommand()=default
void SetCommandType(CommandType)
Definition: G4UIcommand.cc:89
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
@ WithADoubleAndUnitCmd
Definition: G4UIcommand.hh:201

Member Function Documentation

◆ ConvertToStringWithBestUnit()

G4String G4UIcmdWithADoubleAndUnit::ConvertToStringWithBestUnit ( G4double  val)

Definition at line 126 of file G4UIcmdWithADoubleAndUnit.cc.

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

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

◆ ConvertToStringWithDefaultUnit()

G4String G4UIcmdWithADoubleAndUnit::ConvertToStringWithDefaultUnit ( G4double  val)

Definition at line 140 of file G4UIcmdWithADoubleAndUnit.cc.

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

◆ DoIt()

G4int G4UIcmdWithADoubleAndUnit::DoIt ( G4String  parameterList)
overridevirtual

Reimplemented from G4UIcommand.

Definition at line 52 of file G4UIcmdWithADoubleAndUnit.cc.

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

◆ GetNewDoubleRawValue()

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

Definition at line 100 of file G4UIcmdWithADoubleAndUnit.cc.

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

◆ GetNewDoubleValue()

◆ GetNewUnitValue()

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

Definition at line 113 of file G4UIcmdWithADoubleAndUnit.cc.

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

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 180 of file G4UIcmdWithADoubleAndUnit.cc.

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

Referenced by SetUnitCategory().

◆ SetUnitCategory()


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