ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIcmdWith3VectorAndUnit.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UIcmdWith3VectorAndUnit.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 //
29 
31 #include "G4Tokenizer.hh"
32 #include "G4UnitsTable.hh"
33 #include "G4UIcommandStatus.hh"
34 #include <sstream>
35 
37 (const char * theCommandPath,G4UImessenger * theMessenger)
38 :G4UIcommand(theCommandPath,theMessenger)
39 {
40  G4UIparameter * dblParamX = new G4UIparameter('d');
41  SetParameter(dblParamX);
42  G4UIparameter * dblParamY = new G4UIparameter('d');
43  SetParameter(dblParamY);
44  G4UIparameter * dblParamZ = new G4UIparameter('d');
45  SetParameter(dblParamZ);
46  G4UIparameter * untParam = new G4UIparameter('s');
47  SetParameter(untParam);
48  untParam->SetParameterName("Unit");
49 }
50 
52 {
53  std::vector<G4String> token_vector;
54  G4Tokenizer tkn(parameterList);
55  G4String str;
56  while( (str = tkn()) != "" ) {
57  token_vector.push_back(str);
58  }
59 
60  // convert a value in default unit
61  G4String converted_parameter;
62  G4String default_unit = GetParameter(3)-> GetDefaultValue();
63  if (default_unit != "" && token_vector.size() >= 4) {
64  if(CategoryOf(token_vector[3])!=CategoryOf(default_unit))
65  { return fParameterOutOfCandidates+3; }
66  G4double value_given = ValueOf(token_vector[3]);
67  G4double value_default = ValueOf(default_unit);
68  G4double x = ConvertToDouble(token_vector[0]) * value_given / value_default;
69  G4double y = ConvertToDouble(token_vector[1]) * value_given / value_default;
70  G4double z = ConvertToDouble(token_vector[2]) * value_given / value_default;
71 
72  // reconstruct parameter list
73  converted_parameter += ConvertToString(x);
74  converted_parameter += " ";
75  converted_parameter += ConvertToString(y);
76  converted_parameter += " ";
77  converted_parameter += ConvertToString(z);
78  converted_parameter += " ";
79  converted_parameter += default_unit;
80  for ( size_t i=4 ; i< token_vector.size(); i++) {
81  converted_parameter += " ";
82  converted_parameter += token_vector[i];
83  }
84  } else {
85  converted_parameter = parameterList;
86  }
87 
88  return G4UIcommand::DoIt(converted_parameter);
89 }
90 
92 {
93  return ConvertToDimensioned3Vector(paramString);
94 }
95 
97 {
98  G4double vx;
99  G4double vy;
100  G4double vz;
101  char unts[30];
102  std::istringstream is(paramString);
103  is >> vx >> vy >> vz >> unts;
104  return G4ThreeVector(vx,vy,vz);
105 }
106 
108 {
109  G4double vx;
110  G4double vy;
111  G4double vz;
112  char unts[30];
113  std::istringstream is(paramString);
114  is >> vx >> vy >> vz >> unts;
115  G4String unt = unts;
116  return ValueOf(unt);
117 }
118 
120 {
121  G4UIparameter* unitParam = GetParameter(3);
122  G4String canList = unitParam->GetParameterCandidates();
123  G4Tokenizer candidateTokenizer(canList);
124  G4String aToken = candidateTokenizer();
125 
126  std::ostringstream os;
127  os << G4BestUnit(vec,CategoryOf(aToken));
128  G4String st = os.str();
129 
130  return st;
131 }
132 
134 {
135  G4UIparameter* unitParam = GetParameter(3);
136  G4String st;
137  if(unitParam->IsOmittable())
138  { st = ConvertToString(vec,unitParam->GetDefaultValue()); }
139  else
140  { st = ConvertToStringWithBestUnit(vec); }
141  return st;
142 }
143 
145 (const char * theNameX,const char * theNameY,const char * theNameZ,
146 G4bool omittable,G4bool currentAsDefault)
147 {
148  G4UIparameter * theParamX = GetParameter(0);
149  theParamX->SetParameterName(theNameX);
150  theParamX->SetOmittable(omittable);
151  theParamX->SetCurrentAsDefault(currentAsDefault);
152  G4UIparameter * theParamY = GetParameter(1);
153  theParamY->SetParameterName(theNameY);
154  theParamY->SetOmittable(omittable);
155  theParamY->SetCurrentAsDefault(currentAsDefault);
156  G4UIparameter * theParamZ = GetParameter(2);
157  theParamZ->SetParameterName(theNameZ);
158  theParamZ->SetOmittable(omittable);
159  theParamZ->SetCurrentAsDefault(currentAsDefault);
160 }
161 
163 {
164  G4UIparameter * theParamX = GetParameter(0);
165  theParamX->SetDefaultValue(vec.x());
166  G4UIparameter * theParamY = GetParameter(1);
167  theParamY->SetDefaultValue(vec.y());
168  G4UIparameter * theParamZ = GetParameter(2);
169  theParamZ->SetDefaultValue(vec.z());
170 }
171 
172 void G4UIcmdWith3VectorAndUnit::SetUnitCategory(const char * unitCategory)
173 {
174  SetUnitCandidates(UnitsList(unitCategory));
175 }
176 
177 void G4UIcmdWith3VectorAndUnit::SetUnitCandidates(const char * candidateList)
178 {
179  G4UIparameter * untParam = GetParameter(3);
180  G4String canList = candidateList;
181  untParam->SetParameterCandidates(canList);
182 }
183 
185 {
186  G4UIparameter * untParam = GetParameter(3);
187  untParam->SetOmittable(true);
188  untParam->SetDefaultValue(defUnit);
189  SetUnitCategory(CategoryOf(defUnit));
190 }
191