Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/intercoms/src/G4UIcommand.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /intercoms/src/G4UIcommand.cc (Version 11.3.0) and /intercoms/src/G4UIcommand.cc (Version 10.0)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4UIcommand                                 << 
 27 //                                                 26 //
 28 // Author: Makoto Asai (SLAC), 1998            <<  27 // $Id: G4UIcommand.cc 77563 2013-11-26 09:03:18Z gcosmo $
 29 // ------------------------------------------- <<  28 //
                                                   >>  29 // 
 30                                                    30 
 31 #include "G4UIcommand.hh"                          31 #include "G4UIcommand.hh"
 32                                                << 
 33 #include "G4StateManager.hh"                   << 
 34 #include "G4Threading.hh"                      << 
 35 #include "G4Tokenizer.hh"                      << 
 36 #include "G4UIcommandStatus.hh"                << 
 37 #include "G4UImanager.hh"                      << 
 38 #include "G4UImessenger.hh"                        32 #include "G4UImessenger.hh"
 39 #include "G4UIparsing.hh"                      <<  33 #include "G4UImanager.hh"
                                                   >>  34 #include "G4UIcommandStatus.hh"
                                                   >>  35 #include "G4StateManager.hh"
 40 #include "G4UnitsTable.hh"                         36 #include "G4UnitsTable.hh"
                                                   >>  37 #include "G4Tokenizer.hh"
 41 #include "G4ios.hh"                                38 #include "G4ios.hh"
                                                   >>  39 #include <sstream>
 42                                                    40 
 43 // ------------------------------------------- <<  41 G4UIcommand::G4UIcommand()
 44 G4UIcommand::G4UIcommand(const char* theComman <<  42   : messenger(0), toBeBroadcasted(false), toBeFlushed(false), workerThreadOnly(false),
 45   : toBeBroadcasted(tBB), messenger(theMesseng <<  43     bp(0), token(IDENTIFIER), paramERR(0)
 46 {                                                  44 {
 47   G4String comStr = theCommandPath;            << 
 48   G4UIcommandCommonConstructorCode(comStr);    << 
 49   availabelStateList = {G4State_PreInit,    G4 << 
 50                         G4State_GeomClosed, G4 << 
 51 }                                                  45 }
 52                                                    46 
 53 // ------------------------------------------- <<  47 G4UIcommand::G4UIcommand(const char * theCommandPath,
 54 void G4UIcommand::G4UIcommandCommonConstructor <<  48      G4UImessenger * theMessenger, G4bool tBB)
                                                   >>  49 :messenger(theMessenger),toBeBroadcasted(tBB),toBeFlushed(false), workerThreadOnly(false),
                                                   >>  50 token(IDENTIFIER),paramERR(0)
 55 {                                                  51 {
 56   commandPath = theCommandPath;                <<  52   G4String comStr = theCommandPath;
 57   commandName = theCommandPath;                <<  53   if(!theMessenger)
 58   auto commandNameIndex = (G4int)commandName.r <<  54   { // this must be a directory
 59   commandName.erase(0, commandNameIndex + 1);  <<  55     if(comStr(comStr.length()-1)!='/')
 60 #ifdef G4MULTITHREADED                         <<  56     {
 61   if ((messenger != nullptr) && messenger->Com <<  57       G4cerr << "G4UIcommand Warning : " << G4endl;
 62       && G4Threading::IsWorkerThread())        <<  58       G4cerr << "  <" << theCommandPath << "> must be a directory." << G4endl;
 63   {                                            <<  59       G4cerr << "  '/' is appended." << G4endl;
 64     toBeBroadcasted = false;                   <<  60       comStr += "/";
 65     G4UImanager::GetMasterUIpointer()->AddNewC <<  61     }
 66   }                                            << 
 67   else {                                       << 
 68     G4UImanager::GetUIpointer()->AddNewCommand << 
 69   }                                                62   }
 70 #else                                          <<  63   G4UIcommandCommonConstructorCode (comStr);
 71   G4UImanager::GetUIpointer()->AddNewCommand(t <<  64   G4String nullString;
 72 #endif                                         <<  65   availabelStateList.clear();
                                                   >>  66   availabelStateList.push_back(G4State_PreInit);
                                                   >>  67   availabelStateList.push_back(G4State_Init);
                                                   >>  68   availabelStateList.push_back(G4State_Idle);
                                                   >>  69   availabelStateList.push_back(G4State_GeomClosed);
                                                   >>  70   availabelStateList.push_back(G4State_EventProc);
                                                   >>  71   availabelStateList.push_back(G4State_Abort);
 73 }                                                  72 }
 74                                                    73 
 75 // ------------------------------------------- <<  74 void G4UIcommand::G4UIcommandCommonConstructorCode
 76 void G4UIcommand::SetCommandType(CommandType t <<  75 (const char * theCommandPath)
 77 {                                              <<  76 { 
 78   if (messenger == nullptr) {  // this must be <<  77   commandPath = theCommandPath;
 79     if (typ != CmdDirectory) {                 <<  78   commandName = theCommandPath;
 80       G4ExceptionDescription ed;               <<  79   G4int commandNameIndex = commandName.last('/');
 81       ed << "A UI command <" << commandPath << <<  80   commandName.remove(0,commandNameIndex+1);
 82       G4Exception("G4UIcommand::SetCommandType <<  81 
 83     }                                          <<  82   G4UImanager::GetUIpointer()->AddNewCommand(this);
 84     else if (commandPath.back() != '/') {      << 
 85       G4ExceptionDescription ed;               << 
 86       ed << "G4UIcommand Warning : \n"         << 
 87          << "  <" << commandPath << "> must be << 
 88          << "  '/' is appended.";              << 
 89       G4Exception("G4UIcommand::SetCommandType << 
 90       commandPath += "/";                      << 
 91     }                                          << 
 92   }                                            << 
 93   commandType = typ;                           << 
 94 }                                                  83 }
 95                                                    84 
 96 // ------------------------------------------- << 
 97 G4UIcommand::~G4UIcommand()                        85 G4UIcommand::~G4UIcommand()
 98 {                                                  86 {
 99   G4UImanager* fUImanager = G4UImanager::GetUI     87   G4UImanager* fUImanager = G4UImanager::GetUIpointer();
100   if (fUImanager != nullptr) {                 <<  88   if(fUImanager) fUImanager->RemoveCommand(this);
101     fUImanager->RemoveCommand(this);           <<  89   
102   }                                            <<  90   G4int n_parameterEntry = parameter.size();
103                                                <<  91   for( G4int i_thParameter=0; i_thParameter < n_parameterEntry; i_thParameter++ )
104   for (const auto& p : parameter) {            <<  92   { delete parameter[i_thParameter]; }
105     delete p;                                  <<  93   parameter.clear();
106   }                                            << 
107 }                                                  94 }
108                                                    95 
109 // ------------------------------------------- <<  96 G4int G4UIcommand::operator==(const G4UIcommand &right) const
110 G4bool G4UIcommand::operator==(const G4UIcomma << 
111 {                                                  97 {
112   return (commandPath == right.GetCommandPath( <<  98   return ( commandPath == right.GetCommandPath() );
113 }                                                  99 }
114                                                   100 
115 // ------------------------------------------- << 101 G4int G4UIcommand::operator!=(const G4UIcommand &right) const
116 G4bool G4UIcommand::operator!=(const G4UIcomma << 
117 {                                                 102 {
118   return (commandPath != right.GetCommandPath( << 103   return ( commandPath != right.GetCommandPath() );
119 }                                                 104 }
120                                                   105 
121 // ------------------------------------------- << 106 #include "G4Threading.hh"
122 G4int G4UIcommand::DoIt(const G4String& parame << 107 
                                                   >> 108 G4int G4UIcommand::DoIt(G4String parameterList)
123 {                                                 109 {
124   G4String correctParameters;                     110   G4String correctParameters;
125   std::size_t n_parameterEntry = parameter.siz << 111   G4int n_parameterEntry = parameter.size();
126   if (n_parameterEntry != 0) {                 << 112   if( n_parameterEntry != 0 )
                                                   >> 113   {
127     G4String aToken;                              114     G4String aToken;
128     G4String correctToken;                        115     G4String correctToken;
129     G4Tokenizer parameterToken(parameterList); << 116     G4Tokenizer parameterToken( parameterList );
130     for (std::size_t i_thParameter = 0; i_thPa << 117     for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
131       if (i_thParameter > 0) {                 << 118     {
                                                   >> 119       if(i_thParameter > 0)
                                                   >> 120       {
132         correctParameters.append(" ");            121         correctParameters.append(" ");
133       }                                           122       }
134       aToken = parameterToken();                  123       aToken = parameterToken();
135       if (aToken.length() > 0 && aToken[0] ==  << 124       if( aToken.length()>0 && aToken(0)=='"' )
136         while (aToken.back() != '"' || (aToken << 125       {
                                                   >> 126         while( aToken(aToken.length()-1) != '"'
                                                   >> 127                || ( aToken.length()==1 && aToken(0)=='"' ))
                                                   >> 128         {
137           G4String additionalToken = parameter    129           G4String additionalToken = parameterToken();
138           if (additionalToken.empty()) {       << 130           if( additionalToken.isNull() )
139             return G4int(fParameterUnreadable  << 131           { return fParameterUnreadable+i_thParameter; }
140           }                                    << 
141           aToken += " ";                          132           aToken += " ";
142           aToken += additionalToken;              133           aToken += additionalToken;
143         }                                         134         }
144       }                                           135       }
145       else if (i_thParameter == n_parameterEnt << 136       else if(i_thParameter==n_parameterEntry-1 && parameter[i_thParameter]->GetParameterType()=='s')
146                && parameter[i_thParameter]->Ge << 
147       {                                           137       {
148         G4String anotherToken;                    138         G4String anotherToken;
149         while (!((anotherToken = parameterToke << 139         while(!((anotherToken=parameterToken()).isNull()))
150           std::size_t idxs = anotherToken.find << 140         {
151           if (idxs == std::string::npos) {     << 141           G4int idxs = anotherToken.index("#");
                                                   >> 142           if(idxs==G4int(std::string::npos))
                                                   >> 143           {
152             aToken += " ";                        144             aToken += " ";
153             aToken += anotherToken;               145             aToken += anotherToken;
154           }                                       146           }
155           else if (idxs > 0) {                 << 147           else if(idxs>0)
                                                   >> 148           {
156             aToken += " ";                        149             aToken += " ";
157             aToken += anotherToken.substr(0, i << 150             aToken += anotherToken(0,idxs);
158             break;                             << 
159           }                                    << 
160           else {                               << 
161             break;                                151             break;
162           }                                       152           }
                                                   >> 153           else
                                                   >> 154           { break; }
163         }                                         155         }
164       }                                           156       }
165                                                   157 
166       if (aToken.empty() || aToken == "!") {   << 158       if( aToken.isNull() || aToken == "!" )
167         if (parameter[i_thParameter]->IsOmitta << 159       {
168           if (parameter[i_thParameter]->GetCur << 160         if(parameter[i_thParameter]->IsOmittable())
                                                   >> 161         { 
                                                   >> 162           if(parameter[i_thParameter]->GetCurrentAsDefault())
                                                   >> 163           {
169             G4Tokenizer cvSt(messenger->GetCur    164             G4Tokenizer cvSt(messenger->GetCurrentValue(this));
170             G4String parVal;                      165             G4String parVal;
171             for (std::size_t ii = 0; ii < i_th << 166             for(G4int ii=0;ii<i_thParameter;ii++)
172               parVal = cvSt();                 << 167             {
173               if (parVal[0] == '"') {          << 168         parVal = cvSt();
174                 while (parVal.back() != '"') { << 169         if (parVal(0)=='"')
175                   G4String additionalToken = c << 170     {
176                   if (additionalToken.empty()) << 171       while( parVal(parVal.length()-1) != '"' )
177                     return G4int(fParameterUnr << 172         {
178                   }                            << 173           G4String additionalToken = cvSt();
179                   parVal += " ";               << 174           if( additionalToken.isNull() )
180                   parVal += additionalToken;   << 175       { return fParameterUnreadable+i_thParameter; }
181                 }                              << 176           parVal += " ";
182               }                                << 177           parVal += additionalToken;
183             }                                  << 178         }
184             G4String aCVToken = cvSt();        << 179     }
185             if (aCVToken[0] == '"') {          << 180       }
186               while (aCVToken.back() != '"') { << 181       G4String aCVToken = cvSt();
187                 G4String additionalToken = cvS << 182       if (aCVToken(0)=='"')
188                 if (additionalToken.empty()) { << 183       {
189                   return G4int(fParameterUnrea << 184         while( aCVToken(aCVToken.length()-1) != '"' )
190                 }                              << 185         {
191                 aCVToken += " ";               << 186     G4String additionalToken = cvSt();
192                 aCVToken += additionalToken;   << 187     if( additionalToken.isNull() )
193               }                                << 188     { return fParameterUnreadable+i_thParameter; }
194             }                                  << 189     aCVToken += " ";
                                                   >> 190     aCVToken += additionalToken;
                                                   >> 191         }
                                                   >> 192         // aCVToken.strip(G4String::both,'"');
                                                   >> 193       }
195             correctParameters.append(aCVToken)    194             correctParameters.append(aCVToken);
196           }                                       195           }
197           else {                               << 196           else
198             correctParameters.append(parameter << 197           { correctParameters.append(parameter[i_thParameter]->GetDefaultValue()); }
199           }                                    << 
200         }                                      << 
201         else {                                 << 
202           return G4int(fParameterUnreadable +  << 
203         }                                         198         }
                                                   >> 199         else
                                                   >> 200         { return fParameterUnreadable+i_thParameter; }
204       }                                           201       }
205       else {                                   << 202       else
206         G4int stat = parameter[i_thParameter]- << 203       {
207         if (stat != 0) {                       << 204         G4int stat = parameter[i_thParameter]->CheckNewValue( aToken );
208           return stat + G4int(i_thParameter);  << 205         if(stat) return stat+i_thParameter;
209         }                                      << 
210         correctParameters.append(aToken);         206         correctParameters.append(aToken);
211       }                                           207       }
212     }                                             208     }
213   }                                               209   }
214                                                   210 
215   if (CheckNewValue(correctParameters) != 0) { << 211   if(CheckNewValue( correctParameters ))
216     return fParameterOutOfRange + 99;          << 212   { return fParameterOutOfRange+99; }
217   }                                            << 
218                                                   213 
219   if (workerThreadOnly && G4Threading::IsMaste << 214   if(workerThreadOnly && !G4Threading::IsWorkerThread()) return 0;
220     return 0;                                  << 
221   }                                            << 
222                                                   215 
223   messenger->SetNewValue(this, std::move(corre << 216   messenger->SetNewValue( this, correctParameters );
224   return 0;                                       217   return 0;
225 }                                                 218 }
226                                                   219 
227 // ------------------------------------------- << 
228 G4String G4UIcommand::GetCurrentValue()           220 G4String G4UIcommand::GetCurrentValue()
229 {                                                 221 {
230   return messenger->GetCurrentValue(this);        222   return messenger->GetCurrentValue(this);
231 }                                                 223 }
232                                                   224 
233 // ------------------------------------------- << 
234 void G4UIcommand::AvailableForStates(G4Applica    225 void G4UIcommand::AvailableForStates(G4ApplicationState s1)
235 {                                                 226 {
236   availabelStateList = {s1};                   << 227   availabelStateList.clear();
                                                   >> 228   availabelStateList.push_back(s1);
237 }                                                 229 }
238                                                   230 
239 // ------------------------------------------- << 231 void G4UIcommand::AvailableForStates(G4ApplicationState s1,
240 void G4UIcommand::AvailableForStates(G4Applica << 232                                      G4ApplicationState s2)
241 {                                                 233 {
242   availabelStateList = {s1, s2};               << 234   availabelStateList.clear();
                                                   >> 235   availabelStateList.push_back(s1);
                                                   >> 236   availabelStateList.push_back(s2);
243 }                                                 237 }
244                                                   238 
245 // ------------------------------------------- << 239 void G4UIcommand::AvailableForStates(G4ApplicationState s1,
246 void G4UIcommand::AvailableForStates(G4Applica << 240                                      G4ApplicationState s2,
247                                      G4Applica    241                                      G4ApplicationState s3)
248 {                                                 242 {
249   availabelStateList = {s1, s2, s3};           << 243   availabelStateList.clear();
250 }                                              << 244   availabelStateList.push_back(s1);
251                                                << 245   availabelStateList.push_back(s2);
252 // ------------------------------------------- << 246   availabelStateList.push_back(s3);
253 void G4UIcommand::AvailableForStates(G4Applica << 247 }
254                                      G4Applica << 248 
255 {                                              << 249 void G4UIcommand::AvailableForStates(G4ApplicationState s1,
256   availabelStateList = {s1, s2, s3, s4};       << 250                                      G4ApplicationState s2,
257 }                                              << 251                                      G4ApplicationState s3,
258                                                << 252                                      G4ApplicationState s4)
259 // ------------------------------------------- << 253 {
260 void G4UIcommand::AvailableForStates(G4Applica << 254   availabelStateList.clear();
261                                      G4Applica << 255   availabelStateList.push_back(s1);
                                                   >> 256   availabelStateList.push_back(s2);
                                                   >> 257   availabelStateList.push_back(s3);
                                                   >> 258   availabelStateList.push_back(s4);
                                                   >> 259 }
                                                   >> 260 
                                                   >> 261 void G4UIcommand::AvailableForStates(G4ApplicationState s1,
                                                   >> 262                                      G4ApplicationState s2,
                                                   >> 263                                      G4ApplicationState s3,
                                                   >> 264                                      G4ApplicationState s4,
262                                      G4Applica    265                                      G4ApplicationState s5)
263 {                                                 266 {
264   availabelStateList = {s1, s2, s3, s4, s5};   << 267   availabelStateList.clear();
                                                   >> 268   availabelStateList.push_back(s1);
                                                   >> 269   availabelStateList.push_back(s2);
                                                   >> 270   availabelStateList.push_back(s3);
                                                   >> 271   availabelStateList.push_back(s4);
                                                   >> 272   availabelStateList.push_back(s5);
265 }                                                 273 }
266                                                   274 
267 // ------------------------------------------- << 
268 G4bool G4UIcommand::IsAvailable()                 275 G4bool G4UIcommand::IsAvailable()
269 {                                                 276 {
270   G4ApplicationState currentState = G4StateMan << 277   G4bool av = false;
271                                                << 278   G4ApplicationState currentState 
272   for (const auto& s : availabelStateList) {   << 279    = G4StateManager::GetStateManager()->GetCurrentState();
273     if (s == currentState) {                   << 280    
274       return true;                             << 281   G4int nState = availabelStateList.size();
275     }                                          << 282   for(G4int i=0;i<nState;i++)
                                                   >> 283   {
                                                   >> 284     if(availabelStateList[i]==currentState)
                                                   >> 285     {
                                                   >> 286       av = true;
                                                   >> 287       break;
                                                   >> 288     }
276   }                                               289   }
277                                                   290 
278   return false;                                << 291   return av;
279 }                                                 292 }
280                                                   293 
281 // ------------------------------------------- << 
282 G4double G4UIcommand::ValueOf(const char* unit    294 G4double G4UIcommand::ValueOf(const char* unitName)
283 {                                                 295 {
284   return G4UnitDefinition::GetValueOf(unitName << 296    G4double value = 0.;
                                                   >> 297    value = G4UnitDefinition::GetValueOf(unitName);
                                                   >> 298    return value;              
285 }                                                 299 }
286                                                   300 
287 // ------------------------------------------- << 
288 G4String G4UIcommand::CategoryOf(const char* u    301 G4String G4UIcommand::CategoryOf(const char* unitName)
289 {                                                 302 {
290   return G4UnitDefinition::GetCategory(unitNam << 303    return G4UnitDefinition::GetCategory(unitName);
291 }                                                 304 }
292                                                   305 
293 // ------------------------------------------- << 
294 G4String G4UIcommand::UnitsList(const char* un    306 G4String G4UIcommand::UnitsList(const char* unitCategory)
295 {                                                 307 {
                                                   >> 308   G4String retStr;
296   G4UnitsTable& UTbl = G4UnitDefinition::GetUn    309   G4UnitsTable& UTbl = G4UnitDefinition::GetUnitsTable();
297                                                << 310   size_t i;
298   auto ucatIter = std::find_if(std::cbegin(UTb << 311   for(i=0;i<UTbl.size();i++)
299     return ud->GetName() == unitCategory;      << 312   { if(UTbl[i]->GetName()==unitCategory) break; }
300   });                                          << 313   if(i==UTbl.size())
301                                                << 314   { 
302   if (ucatIter == std::cend(UTbl)) {           << 
303     G4cerr << "Unit category <" << unitCategor    315     G4cerr << "Unit category <" << unitCategory << "> is not defined." << G4endl;
304     return G4String();                         << 316     return retStr;
305   }                                               317   }
306                                                << 318   G4UnitsContainer& UCnt = UTbl[i]->GetUnitsList();
307   G4String symList;                            << 319   retStr = UCnt[0]->GetSymbol();
308   G4String nameList;                           << 320   G4int je = UCnt.size();
309   G4UnitsContainer& UCnt = (*ucatIter)->GetUni << 321   for(G4int j=1;j<je;j++)
310                                                << 322   {
311   for (const auto& uDef : UCnt) {              << 323     retStr += " ";
312     symList += uDef->GetSymbol();              << 324     retStr += UCnt[j]->GetSymbol();
313     symList += " ";                            << 325   }
314     nameList += uDef->GetName();               << 326   for(G4int k=0;k<je;k++)
315     nameList += " ";                           << 327   {
                                                   >> 328     retStr += " ";
                                                   >> 329     retStr += UCnt[k]->GetName();
316   }                                               330   }
317   symList += nameList;                         << 331   return retStr;
318   G4StrUtil::rstrip(symList);                  << 
319   return symList;                              << 
320 }                                                 332 }
321                                                << 333   
322 // ------------------------------------------- << 
323 void G4UIcommand::List()                          334 void G4UIcommand::List()
324 {                                                 335 {
325   G4cout << G4endl;                               336   G4cout << G4endl;
326   G4cout << G4endl;                               337   G4cout << G4endl;
327   if (commandPath.back() != '/') {             << 338   if(commandPath(commandPath.length()-1)!='/')
328     G4cout << "Command " << commandPath << G4e << 339   { G4cout << "Command " << commandPath << G4endl; }
329   }                                            << 340   if(workerThreadOnly)
330   if (workerThreadOnly) {                      << 341   { G4cout << "    ---- available only in worker thread" << G4endl; }
331     G4cout << "    ---- available only in work << 
332   }                                            << 
333                                                << 
334   G4cout << "Guidance :" << G4endl;               342   G4cout << "Guidance :" << G4endl;
335   for (const auto& i_thGuidance : commandGuida << 343   G4int n_guidanceEntry = commandGuidance.size();
336     G4cout << i_thGuidance << G4endl;          << 344   for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
337   }                                            << 345   { G4cout << commandGuidance[i_thGuidance] << G4endl; }
338                                                << 346   if( ! rangeString.isNull() )
339   if (!rangeExpression.empty()) {              << 347   { G4cout << " Range of parameters : " << rangeString << G4endl; }
340     G4cout << " Range of parameters : " << ran << 348   G4int n_parameterEntry = parameter.size();
341   }                                            << 349   if( n_parameterEntry > 0 )
342                                                << 350   {
343   for (const auto& i_thParameter : parameter)  << 351     for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
344     i_thParameter->List();                     << 352     { parameter[i_thParameter]->List(); }
345   }                                               353   }
346   G4cout << G4endl;                               354   G4cout << G4endl;
347 }                                                 355 }
348                                                   356 
349 // ------------------------------------------- << 
350 G4String G4UIcommand::ConvertToString(G4bool b    357 G4String G4UIcommand::ConvertToString(G4bool boolVal)
351 {                                                 358 {
352   return boolVal ? "1" : "0";                  << 359   G4String vl = "0";
                                                   >> 360   if(boolVal) vl = "1";
                                                   >> 361   return vl;
353 }                                                 362 }
354                                                   363 
355 // ------------------------------------------- << 
356 G4String G4UIcommand::ConvertToString(G4int in    364 G4String G4UIcommand::ConvertToString(G4int intValue)
357 {                                                 365 {
358   return G4UIparsing::TtoS(intValue);          << 366   std::ostringstream os;
359 }                                              << 367   os << intValue;
360                                                << 368   G4String vl = os.str();
361 // ------------------------------------------- << 369   return vl;
362 G4String G4UIcommand::ConvertToString(G4long l << 
363 {                                              << 
364   return G4UIparsing::TtoS(longValue);         << 
365 }                                                 370 }
366                                                   371 
367 // ------------------------------------------- << 
368 G4String G4UIcommand::ConvertToString(G4double    372 G4String G4UIcommand::ConvertToString(G4double doubleValue)
369 {                                                 373 {
370   std::ostringstream os;                          374   std::ostringstream os;
371   if (G4UImanager::DoublePrecisionStr()) {     << 
372     os << std::setprecision(17);               << 
373   }                                            << 
374   os << doubleValue;                              375   os << doubleValue;
375   return os.str();                             << 376   G4String vl = os.str();
                                                   >> 377   return vl;
376 }                                                 378 }
377                                                   379 
378 // ------------------------------------------- << 380 G4String G4UIcommand::ConvertToString(G4double doubleValue,const char* unitName)
379 G4String G4UIcommand::ConvertToString(G4double << 
380 {                                                 381 {
                                                   >> 382   G4String unt = unitName;
                                                   >> 383   G4double uv = ValueOf(unitName);
                                                   >> 384 
381   std::ostringstream os;                          385   std::ostringstream os;
382   if (G4UImanager::DoublePrecisionStr()) {     << 386   os << doubleValue/uv << " " << unitName;
383     os << std::setprecision(17);               << 387   G4String vl = os.str();
384   }                                            << 388   return vl;
385   os << doubleValue / ValueOf(unitName) << " " << 
386   return os.str();                             << 
387 }                                                 389 }
388                                                   390 
389 // ------------------------------------------- << 391 G4String G4UIcommand::ConvertToString(G4ThreeVector vec)
390 G4String G4UIcommand::ConvertToString(const G4 << 
391 {                                                 392 {
392   std::ostringstream os;                          393   std::ostringstream os;
393   if (G4UImanager::DoublePrecisionStr()) {     << 
394     os << std::setprecision(17);               << 
395   }                                            << 
396   os << vec.x() << " " << vec.y() << " " << ve    394   os << vec.x() << " " << vec.y() << " " << vec.z();
397   return os.str();                             << 395   G4String vl = os.str();
                                                   >> 396   return vl;
398 }                                                 397 }
399                                                   398 
400 // ------------------------------------------- << 399 G4String G4UIcommand::ConvertToString(G4ThreeVector vec,const char* unitName)
401 G4String G4UIcommand::ConvertToString(const G4 << 
402 {                                                 400 {
                                                   >> 401   G4String unt = unitName;
403   G4double uv = ValueOf(unitName);                402   G4double uv = ValueOf(unitName);
404                                                   403 
405   std::ostringstream os;                          404   std::ostringstream os;
406   if (G4UImanager::DoublePrecisionStr()) {     << 405   os << vec.x()/uv << " " << vec.y()/uv << " " << vec.z()/uv
407     os << std::setprecision(17);               << 406      << " " << unitName;
408   }                                            << 407   G4String vl = os.str();
409   os << vec.x() / uv << " " << vec.y() / uv << << 408   return vl;
410   return os.str();                             << 
411 }                                                 409 }
412                                                   410 
413 // ------------------------------------------- << 
414 G4bool G4UIcommand::ConvertToBool(const char*     411 G4bool G4UIcommand::ConvertToBool(const char* st)
415 {                                                 412 {
416   G4String v = G4StrUtil::to_upper_copy(st);   << 413   G4String v = st;
417   return (v == "Y" || v == "YES" || v == "1" | << 414   v.toUpper();
                                                   >> 415   G4bool vl = false;
                                                   >> 416   if( v=="Y" || v=="YES" || v=="1" || v=="T" || v=="TRUE" )
                                                   >> 417   { vl = true; }
                                                   >> 418   return vl;
418 }                                                 419 }
419                                                   420 
420 // ------------------------------------------- << 
421 G4int G4UIcommand::ConvertToInt(const char* st    421 G4int G4UIcommand::ConvertToInt(const char* st)
422 {                                                 422 {
423   return G4UIparsing::StoT<G4int>(st);         << 423   G4int vl;
424 }                                              << 424   std::istringstream is(st);
425                                                << 425   is >> vl;
426 // ------------------------------------------- << 426   return vl;
427 G4long G4UIcommand::ConvertToLongInt(const cha << 
428 {                                              << 
429   return G4UIparsing::StoT<G4long>(st);        << 
430 }                                                 427 }
431                                                   428 
432 // ------------------------------------------- << 
433 G4double G4UIcommand::ConvertToDouble(const ch    429 G4double G4UIcommand::ConvertToDouble(const char* st)
434 {                                                 430 {
435   return G4UIparsing::StoT<G4double>(st);      << 431   G4double vl;
                                                   >> 432   std::istringstream is(st);
                                                   >> 433   is >> vl;
                                                   >> 434   return vl;
436 }                                                 435 }
437                                                   436 
438 // ------------------------------------------- << 
439 G4double G4UIcommand::ConvertToDimensionedDoub    437 G4double G4UIcommand::ConvertToDimensionedDouble(const char* st)
440 {                                                 438 {
441   G4double vl;                                    439   G4double vl;
442   char unts[30];                                  440   char unts[30];
443                                                   441 
444   std::istringstream is(st);                      442   std::istringstream is(st);
445   is >> vl >> unts;                               443   is >> vl >> unts;
446   G4String unt = unts;                            444   G4String unt = unts;
447                                                   445 
448   return (vl * ValueOf(unt));                  << 446   return (vl*ValueOf(unt));
449 }                                                 447 }
450                                                   448 
451 // ------------------------------------------- << 
452 G4ThreeVector G4UIcommand::ConvertTo3Vector(co    449 G4ThreeVector G4UIcommand::ConvertTo3Vector(const char* st)
453 {                                                 450 {
454   G4double vx;                                    451   G4double vx;
455   G4double vy;                                    452   G4double vy;
456   G4double vz;                                    453   G4double vz;
457   std::istringstream is(st);                      454   std::istringstream is(st);
458   is >> vx >> vy >> vz;                           455   is >> vx >> vy >> vz;
459   return G4ThreeVector(vx, vy, vz);            << 456   return G4ThreeVector(vx,vy,vz);
460 }                                                 457 }
461                                                   458 
462 // ------------------------------------------- << 
463 G4ThreeVector G4UIcommand::ConvertToDimensione    459 G4ThreeVector G4UIcommand::ConvertToDimensioned3Vector(const char* st)
464 {                                                 460 {
465   G4double vx;                                    461   G4double vx;
466   G4double vy;                                    462   G4double vy;
467   G4double vz;                                    463   G4double vz;
468   char unts[30];                                  464   char unts[30];
469   std::istringstream is(st);                      465   std::istringstream is(st);
470   is >> vx >> vy >> vz >> unts;                   466   is >> vx >> vy >> vz >> unts;
471   G4String unt = unts;                            467   G4String unt = unts;
472   G4double uv = ValueOf(unt);                     468   G4double uv = ValueOf(unt);
473   return G4ThreeVector(vx * uv, vy * uv, vz *  << 469   return G4ThreeVector(vx*uv,vy*uv,vz*uv);
                                                   >> 470 }
                                                   >> 471 
                                                   >> 472 
                                                   >> 473 // ----- the following is used by CheckNewValue()  ------------
                                                   >> 474 
                                                   >> 475 
                                                   >> 476 #include <ctype.h>          // isalpha(), toupper()
                                                   >> 477 
                                                   >> 478 //#include "checkNewValue_debug.icc"
                                                   >> 479 //#define DEBUG 1
                                                   >> 480 
                                                   >> 481 G4int G4UIcommand::
                                                   >> 482 CheckNewValue(const char * newValue)
                                                   >> 483 {
                                                   >> 484    yystype result;
                                                   >> 485    // if( TypeCheck(newValue) == 0 ) return 1;
                                                   >> 486    if( ! rangeString.isNull() )
                                                   >> 487    { if( RangeCheck(newValue) == 0 ) return fParameterOutOfRange; }
                                                   >> 488    return 0;  // succeeded
                                                   >> 489 }
                                                   >> 490 
                                                   >> 491 // ------------------ type check routines -------------------
                                                   >> 492 
                                                   >> 493 G4int G4UIcommand::
                                                   >> 494 TypeCheck(const char * t)
                                                   >> 495 {
                                                   >> 496     G4String aNewValue;
                                                   >> 497     char type;
                                                   >> 498     std::istringstream is(t);
                                                   >> 499     for (unsigned i=0; i< parameter.size(); i++) {
                                                   >> 500         is >> aNewValue;
                                                   >> 501         type = toupper(parameter[i]->GetParameterType());
                                                   >> 502         switch ( type ) {
                                                   >> 503             case 'D':
                                                   >> 504                 if( IsDouble(aNewValue)==0 ){
                                                   >> 505                     G4cerr << aNewValue << ": double value expected."
                                                   >> 506                          << G4endl;
                                                   >> 507                     return 0;
                                                   >> 508                 } break;
                                                   >> 509             case 'I':
                                                   >> 510                 if( IsInt(aNewValue,20)==0 ){
                                                   >> 511                     G4cerr <<aNewValue<<": integer expected."
                                                   >> 512                          <<G4endl;
                                                   >> 513                      return 0;
                                                   >> 514                 } break;
                                                   >> 515             case 'S':
                                                   >> 516                 break;
                                                   >> 517             case 'B':
                                                   >> 518                 aNewValue.toUpper(); 
                                                   >> 519                 if (aNewValue == "Y"   || aNewValue == "N"
                                                   >> 520                   ||aNewValue == "YES" || aNewValue == "NO"
                                                   >> 521                   ||aNewValue == "1"   || aNewValue == "0"
                                                   >> 522                   ||aNewValue == "T"   || aNewValue == "F"
                                                   >> 523                   ||aNewValue == "TRUE" || aNewValue == "FALSE")
                                                   >> 524                 return 1;
                                                   >> 525                 else return 0; 
                                                   >> 526                 break;
                                                   >> 527             default:  ;
                                                   >> 528         }
                                                   >> 529     }
                                                   >> 530     return 1;
474 }                                                 531 }
475                                                   532 
476 G4int G4UIcommand::CheckNewValue(const char* n << 533 
                                                   >> 534 G4int G4UIcommand::
                                                   >> 535 IsInt(const char* buf, short maxDigits)
477 {                                                 536 {
478   if (!G4UIparsing::RangeCheck(*this, newValue << 537     const char* p= buf;
479     return fParameterOutOfRange;               << 538     G4int length=0;
480   }                                            << 539     if( *p == '+' || *p == '-') { ++p; }
481   return 0;  // succeeded                      << 540     if( isdigit( (G4int)(*p) )) {
                                                   >> 541         while( isdigit( (G4int)(*p) )) { ++p;  ++length; }
                                                   >> 542         if( *p == '\0' ) {
                                                   >> 543             if( length > maxDigits) {
                                                   >> 544                 G4cerr <<"digit length exceeds"<<G4endl;
                                                   >> 545                 return 0;
                                                   >> 546             }
                                                   >> 547             return 1;
                                                   >> 548         } else {
                                                   >> 549             // G4cerr <<"illegal character after int:"<<buf<<G4endl;
                                                   >> 550         }
                                                   >> 551     } else {
                                                   >> 552         // G4cerr <<"illegal int:"<<buf<<G4endl;
                                                   >> 553     }
                                                   >> 554     return 0;
                                                   >> 555 }
                                                   >> 556 
                                                   >> 557 
                                                   >> 558 G4int G4UIcommand::
                                                   >> 559 ExpectExponent(const char* str)   // used only by IsDouble()
                                                   >> 560 {
                                                   >> 561     G4int maxExplength;
                                                   >> 562     if( IsInt( str, maxExplength=7 )) return 1;
                                                   >> 563     else return 0;
                                                   >> 564 }
                                                   >> 565 
                                                   >> 566 
                                                   >> 567 G4int G4UIcommand::
                                                   >> 568 IsDouble(const char* buf)
                                                   >> 569 {
                                                   >> 570     const char* p= buf;
                                                   >> 571     switch( *p) {
                                                   >> 572         case '+':  case '-': ++p;
                                                   >> 573             if( isdigit(*p) ) {
                                                   >> 574                  while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 575                  switch ( *p ) {
                                                   >> 576                      case '\0':    return 1;
                                                   >> 577             // break;
                                                   >> 578                      case 'E':  case 'e':
                                                   >> 579                          return ExpectExponent(++p );
                                                   >> 580       // break;
                                                   >> 581                      case '.':  ++p;
                                                   >> 582                          if( *p == '\0' )  return 1;
                                                   >> 583                          if( *p == 'e' || *p =='E' ) return ExpectExponent(++p );
                                                   >> 584                          if( isdigit(*p) ) {
                                                   >> 585                              while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 586                              if( *p == '\0' )  return 1;
                                                   >> 587                              if( *p == 'e' || *p =='E') return ExpectExponent(++p);
                                                   >> 588                          } else return 0;   break;
                                                   >> 589                      default: return 0;
                                                   >> 590                  }
                                                   >> 591             }
                                                   >> 592             if( *p == '.' ) { ++p;
                                                   >> 593                  if( isdigit(*p) ) {
                                                   >> 594                      while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 595                      if( *p == '\0' )  return 1;
                                                   >> 596                      if( *p == 'e' || *p =='E')  return ExpectExponent(++p);
                                                   >> 597                  }
                                                   >> 598             }
                                                   >> 599             break;
                                                   >> 600         case '.':  ++p;
                                                   >> 601             if( isdigit(*p) ) {
                                                   >> 602                  while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 603                  if( *p == '\0' )  return 1;
                                                   >> 604                  if( *p == 'e' || *p =='E' )  return ExpectExponent(++p);
                                                   >> 605             }    break;
                                                   >> 606         default: // digit is expected
                                                   >> 607             if( isdigit(*p) ) {
                                                   >> 608                  while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 609                  if( *p == '\0' )  return 1;
                                                   >> 610                  if( *p == 'e' || *p =='E')  return ExpectExponent(++p);
                                                   >> 611                  if( *p == '.' ) { ++p;
                                                   >> 612                       if( *p == '\0' )  return 1;
                                                   >> 613                       if( *p == 'e' || *p =='E')  return ExpectExponent(++p);
                                                   >> 614                       if( isdigit(*p) ) {
                                                   >> 615                           while( isdigit( (G4int)(*p) )) { ++p; }
                                                   >> 616                           if( *p == '\0' )  return 1;
                                                   >> 617                           if( *p == 'e' || *p =='E') return ExpectExponent(++p);
                                                   >> 618                       }
                                                   >> 619                  }
                                                   >> 620             }
                                                   >> 621      }
                                                   >> 622      return 0;
                                                   >> 623 }
                                                   >> 624 
                                                   >> 625 
                                                   >> 626 // ------------------ range Check routines -------------------
                                                   >> 627 G4int G4UIcommand::
                                                   >> 628 RangeCheck(const char* t) {
                                                   >> 629     yystype result;
                                                   >> 630     char type;
                                                   >> 631     bp = 0;                 // reset buffer pointer for G4UIpGetc()
                                                   >> 632     std::istringstream is(t);
                                                   >> 633     for (unsigned i=0; i< parameter.size(); i++) {
                                                   >> 634         type= toupper(parameter[i]->GetParameterType());
                                                   >> 635         switch ( type ) {
                                                   >> 636             case 'D':  is >> newVal[i].D;  break;
                                                   >> 637             case 'I':  is >> newVal[i].I;  break;
                                                   >> 638             case 'S':
                                                   >> 639             case 'B':
                                                   >> 640             default:  ;
                                                   >> 641         }
                                                   >> 642    }
                                                   >> 643    // PrintToken();          // Print tokens (consumes all tokens)
                                                   >> 644    token= Yylex();
                                                   >> 645    result = Expression();
                                                   >> 646 
                                                   >> 647    if( paramERR == 1 ) return 0;
                                                   >> 648    if( result.type != CONSTINT) {
                                                   >> 649       G4cerr << "Illegal Expression in parameter range." << G4endl;
                                                   >> 650       return 0;
                                                   >> 651    }
                                                   >> 652    if ( result.I ) return 1;
                                                   >> 653    G4cerr << "parameter out of range: "<< rangeString << G4endl;
                                                   >> 654    return 0;
                                                   >> 655 }
                                                   >> 656 
                                                   >> 657 // ------------------ syntax node functions  ------------------
                                                   >> 658 yystype G4UIcommand:: 
                                                   >> 659 Expression(void)
                                                   >> 660 {
                                                   >> 661     yystype result;
                                                   >> 662     #ifdef DEBUG
                                                   >> 663         G4cerr << " Expression()" << G4endl;
                                                   >> 664     #endif
                                                   >> 665     result = LogicalORExpression();
                                                   >> 666     return result;
                                                   >> 667 }
                                                   >> 668 
                                                   >> 669 yystype G4UIcommand:: 
                                                   >> 670 LogicalORExpression(void)
                                                   >> 671 {
                                                   >> 672     yystype result;
                                                   >> 673     yystype p;
                                                   >> 674     p = LogicalANDExpression();
                                                   >> 675     if( token != LOGICALOR)  return p;
                                                   >> 676     if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 677         G4cerr << "Parameter range: illegal type at '||'" << G4endl;
                                                   >> 678         paramERR = 1;
                                                   >> 679     }
                                                   >> 680     result.I = p.I;
                                                   >> 681     while (token == LOGICALOR) 
                                                   >> 682     {  
                                                   >> 683         token = Yylex();
                                                   >> 684         p = LogicalANDExpression();
                                                   >> 685         if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 686             G4cerr << "Parameter range: illegal type at '||'" <<G4endl;
                                                   >> 687             paramERR = 1;
                                                   >> 688         }
                                                   >> 689         switch (p.type) {
                                                   >> 690             case CONSTINT: 
                                                   >> 691                 result.I  += p.I; 
                                                   >> 692                 result.type = CONSTINT;      break;
                                                   >> 693             case CONSTDOUBLE:
                                                   >> 694                 result.I += (p.D != 0.0); 
                                                   >> 695                 result.type = CONSTINT;      break;
                                                   >> 696             default: 
                                                   >> 697                 G4cerr << "Parameter range: unknown type"<<G4endl; 
                                                   >> 698                 paramERR = 1;
                                                   >> 699         } 
                                                   >> 700     }
                                                   >> 701     return result;
                                                   >> 702 }
                                                   >> 703 
                                                   >> 704 yystype G4UIcommand:: 
                                                   >> 705 LogicalANDExpression(void)
                                                   >> 706 {
                                                   >> 707     yystype result;
                                                   >> 708     yystype p;
                                                   >> 709     p = EqualityExpression();
                                                   >> 710     if( token != LOGICALAND)  return p;
                                                   >> 711     if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 712         G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
                                                   >> 713         paramERR = 1;
                                                   >> 714     }
                                                   >> 715     result.I = p.I;
                                                   >> 716     while (token == LOGICALAND)
                                                   >> 717     {
                                                   >> 718         token = Yylex();
                                                   >> 719         p = EqualityExpression();
                                                   >> 720         if( p.type == CONSTSTRING || p.type == IDENTIFIER ) {
                                                   >> 721             G4cerr << "Parameter range: illegal type at '&&'" << G4endl;
                                                   >> 722             paramERR = 1;
                                                   >> 723         }
                                                   >> 724         switch (p.type) {
                                                   >> 725             case CONSTINT:
                                                   >> 726                 result.I  *= p.I;
                                                   >> 727                 result.type = CONSTINT;      break;
                                                   >> 728             case CONSTDOUBLE:
                                                   >> 729                 result.I *= (p.D != 0.0);
                                                   >> 730                 result.type = CONSTINT;      break;
                                                   >> 731             default:
                                                   >> 732                 G4cerr << "Parameter range: unknown type."<< G4endl;
                                                   >> 733                 paramERR = 1;
                                                   >> 734         } 
                                                   >> 735     }
                                                   >> 736     return result;
                                                   >> 737 }
                                                   >> 738 
                                                   >> 739 
                                                   >> 740 yystype G4UIcommand:: 
                                                   >> 741 EqualityExpression(void)
                                                   >> 742 { 
                                                   >> 743     yystype  arg1, arg2;
                                                   >> 744     G4int operat;
                                                   >> 745     yystype result;
                                                   >> 746     #ifdef DEBUG
                                                   >> 747         G4cerr << " EqualityExpression()" <<G4endl;
                                                   >> 748     #endif
                                                   >> 749     result = RelationalExpression();
                                                   >> 750     if( token==EQ || token==NE ) {
                                                   >> 751         operat = token;
                                                   >> 752         token =  Yylex();
                                                   >> 753         arg1 = result;
                                                   >> 754         arg2 = RelationalExpression();
                                                   >> 755         result.I = Eval2( arg1, operat, arg2 );   // semantic action
                                                   >> 756         result.type = CONSTINT;
                                                   >> 757         #ifdef DEBUG
                                                   >> 758             G4cerr << " return code of Eval2(): " << result.I <<G4endl;
                                                   >> 759         #endif
                                                   >> 760     } else {
                                                   >> 761         if (result.type != CONSTINT && result.type != CONSTDOUBLE) {  
                                                   >> 762             G4cerr << "Parameter range: error at EqualityExpression"
                                                   >> 763                  << G4endl;
                                                   >> 764             paramERR = 1;
                                                   >> 765         }
                                                   >> 766     }
                                                   >> 767     return  result;
                                                   >> 768 }
                                                   >> 769 
                                                   >> 770 
                                                   >> 771 yystype G4UIcommand:: 
                                                   >> 772 RelationalExpression(void)
                                                   >> 773 { 
                                                   >> 774     yystype  arg1, arg2;
                                                   >> 775     G4int operat;
                                                   >> 776     yystype result;
                                                   >> 777     #ifdef DEBUG
                                                   >> 778         G4cerr << " RelationalExpression()" <<G4endl;
                                                   >> 779     #endif
                                                   >> 780 
                                                   >> 781     arg1 = AdditiveExpression();
                                                   >> 782     if( token==GT || token==GE || token==LT || token==LE  ) {
                                                   >> 783         operat = token;
                                                   >> 784         token =  Yylex();
                                                   >> 785         arg2 = AdditiveExpression();
                                                   >> 786         result.I = Eval2( arg1, operat, arg2 );    // semantic action
                                                   >> 787         result.type = CONSTINT;
                                                   >> 788         #ifdef DEBUG
                                                   >> 789             G4cerr << " return code of Eval2(): " << result.I << G4endl;
                                                   >> 790         #endif
                                                   >> 791     } else {
                                                   >> 792               result = arg1;
                                                   >> 793     }
                                                   >> 794     #ifdef DEBUG
                                                   >> 795        G4cerr <<" return RelationalExpression()"<< G4endl;
                                                   >> 796     #endif
                                                   >> 797     return  result;
                                                   >> 798 }
                                                   >> 799 
                                                   >> 800 yystype G4UIcommand::
                                                   >> 801 AdditiveExpression(void)
                                                   >> 802 {   yystype result;
                                                   >> 803     result = MultiplicativeExpression();
                                                   >> 804     if( token != '+' && token != '-' )  return result;
                                                   >> 805     G4cerr << "Parameter range: operator " 
                                                   >> 806          << (char)token 
                                                   >> 807          << " is not supported." << G4endl;
                                                   >> 808     paramERR = 1;
                                                   >> 809     return  result;
                                                   >> 810 }
                                                   >> 811 
                                                   >> 812 yystype G4UIcommand::
                                                   >> 813 MultiplicativeExpression(void)
                                                   >> 814 {   yystype result;
                                                   >> 815     result = UnaryExpression();
                                                   >> 816     if( token != '*' && token != '/' && token != '%' ) return result;
                                                   >> 817     G4cerr << "Parameter range: operator "
                                                   >> 818          << (char)token
                                                   >> 819          << " is not supported." << G4endl;
                                                   >> 820     paramERR = 1;
                                                   >> 821     return  result;
                                                   >> 822 }
                                                   >> 823 
                                                   >> 824 yystype G4UIcommand::
                                                   >> 825 UnaryExpression(void)
                                                   >> 826 {
                                                   >> 827     yystype result;
                                                   >> 828     yystype p;
                                                   >> 829     #ifdef DEBUG
                                                   >> 830         G4cerr <<" UnaryExpression"<< G4endl;
                                                   >> 831     #endif
                                                   >> 832     switch(token) {
                                                   >> 833         case '-':
                                                   >> 834             token = Yylex();
                                                   >> 835             p = UnaryExpression();
                                                   >> 836             if (p.type == CONSTINT) {
                                                   >> 837                 result.I = - p.I;
                                                   >> 838                 result.type = CONSTINT;
                                                   >> 839             }
                                                   >> 840             if (p.type == CONSTDOUBLE) {
                                                   >> 841                 result.D = - p.D;
                                                   >> 842                 result.type = CONSTDOUBLE;
                                                   >> 843             }                              break;
                                                   >> 844         case '+':
                                                   >> 845             token = Yylex();
                                                   >> 846             result = UnaryExpression();   break;
                                                   >> 847         case '!':
                                                   >> 848             token = Yylex();
                                                   >> 849             G4cerr << "Parameter range error: "
                                                   >> 850                  << "operator '!' is not supported (sorry)."
                                                   >> 851                  << G4endl;
                                                   >> 852             paramERR = 1;
                                                   >> 853             result = UnaryExpression();   break;
                                                   >> 854         default:
                                                   >> 855             result = PrimaryExpression();
                                                   >> 856     }
                                                   >> 857     return result;
                                                   >> 858 }
                                                   >> 859 
                                                   >> 860 
                                                   >> 861 yystype G4UIcommand:: 
                                                   >> 862 PrimaryExpression(void)
                                                   >> 863 {
                                                   >> 864      yystype result;
                                                   >> 865      #ifdef DEBUG
                                                   >> 866          G4cerr <<" primary_exp"<<G4endl;
                                                   >> 867      #endif
                                                   >> 868      switch (token) {
                                                   >> 869          case IDENTIFIER:
                                                   >> 870               result.S = yylval.S;
                                                   >> 871               result.type =  token;
                                                   >> 872               token = Yylex();           break;
                                                   >> 873          case CONSTINT:
                                                   >> 874               result.I = yylval.I;
                                                   >> 875               result.type =  token;
                                                   >> 876               token= Yylex();            break;
                                                   >> 877          case CONSTDOUBLE:
                                                   >> 878               result.D = yylval.D;
                                                   >> 879               result.type =  token;
                                                   >> 880               token = Yylex();           break;
                                                   >> 881          case '(' :
                                                   >> 882               token= Yylex();
                                                   >> 883               result = Expression();
                                                   >> 884               if( token !=  ')'  ) {
                                                   >> 885                   G4cerr << " ')' expected" << G4endl;
                                                   >> 886                   paramERR = 1;
                                                   >> 887               }
                                                   >> 888               token = Yylex();
                                                   >> 889                                          break;
                                                   >> 890          default:
                                                   >> 891          return result;
                                                   >> 892     }
                                                   >> 893     return result; // never executed
                                                   >> 894 }
                                                   >> 895 
                                                   >> 896 //---------------- semantic routines ---------------------------------
                                                   >> 897 
                                                   >> 898 G4int G4UIcommand::
                                                   >> 899 Eval2(yystype arg1, G4int op, yystype arg2)
                                                   >> 900 {
                                                   >> 901     char newValtype;
                                                   >> 902     if( (arg1.type != IDENTIFIER) && (arg2.type != IDENTIFIER)) {
                                                   >> 903         G4cerr << commandName
                                                   >> 904              << ": meaningless comparison"
                                                   >> 905              << G4endl;
                                                   >> 906         paramERR = 1;
                                                   >> 907     }
                                                   >> 908 
                                                   >> 909     if( arg1.type == IDENTIFIER) {
                                                   >> 910         unsigned i = IndexOf( arg1.S );
                                                   >> 911         newValtype = toupper(parameter[i]->GetParameterType());
                                                   >> 912         switch ( newValtype ) {
                                                   >> 913             case 'I': 
                                                   >> 914                 if( arg2.type == CONSTINT ) {
                                                   >> 915                     return CompareInt( newVal[i].I, op, arg2.I );
                                                   >> 916                 } else {
                                                   >> 917                     G4cerr << "integer operand expected for "
                                                   >> 918                          <<  rangeString 
                                                   >> 919                          << '.' << G4endl;
                                                   >> 920                 } break;
                                                   >> 921             case 'D':
                                                   >> 922                 if( arg2.type == CONSTDOUBLE ) {
                                                   >> 923                     return CompareDouble( newVal[i].D, op, arg2.D );
                                                   >> 924                 } else
                                                   >> 925                 if ( arg2.type == CONSTINT ) {  // integral promotion
                                                   >> 926                     return CompareDouble( newVal[i].D, op, arg2.I );
                                                   >> 927                 } break;
                                                   >> 928             default: ;
                                                   >> 929         }
                                                   >> 930     }
                                                   >> 931     if( arg2.type == IDENTIFIER) {
                                                   >> 932         unsigned i = IndexOf( arg2.S );
                                                   >> 933         newValtype = toupper(parameter[i]->GetParameterType());
                                                   >> 934         switch ( newValtype ) {
                                                   >> 935             case 'I': 
                                                   >> 936                 if( arg1.type == CONSTINT ) {
                                                   >> 937                     return CompareInt( arg1.I, op, newVal[i].I );
                                                   >> 938                 } else {
                                                   >> 939                     G4cerr << "integer operand expected for "
                                                   >> 940                          <<  rangeString
                                                   >> 941                          << '.' << G4endl;
                                                   >> 942                 } break;
                                                   >> 943             case 'D':
                                                   >> 944                 if( arg1.type == CONSTDOUBLE ) {
                                                   >> 945                     return CompareDouble( arg1.D, op, newVal[i].D );
                                                   >> 946                 } else
                                                   >> 947                 if ( arg1.type == CONSTINT ) {  // integral promotion
                                                   >> 948                     return CompareDouble( arg1.I, op, newVal[i].D );
                                                   >> 949                 } break;
                                                   >> 950             default: ;
                                                   >> 951         }
                                                   >> 952     }
                                                   >> 953     return 0;
                                                   >> 954 }
                                                   >> 955 
                                                   >> 956 G4int G4UIcommand::
                                                   >> 957 CompareInt(G4int arg1, G4int op, G4int arg2)
                                                   >> 958 {   
                                                   >> 959     G4int result=-1;
                                                   >> 960     G4String opr;
                                                   >> 961     switch (op) {
                                                   >> 962        case GT:  result = ( arg1 >  arg2); opr= ">" ;  break;
                                                   >> 963        case GE:  result = ( arg1 >= arg2); opr= ">=";  break;
                                                   >> 964        case LT:  result = ( arg1 <  arg2); opr= "<" ;  break;
                                                   >> 965        case LE:  result = ( arg1 <= arg2); opr= "<=";  break;
                                                   >> 966        case EQ:  result = ( arg1 == arg2); opr= "==";  break;
                                                   >> 967        case NE:  result = ( arg1 != arg2); opr= "!=";  break;
                                                   >> 968        default: 
                                                   >> 969            G4cerr << "Parameter range: error at CompareInt" << G4endl;
                                                   >> 970            paramERR = 1;
                                                   >> 971     }
                                                   >> 972     #ifdef DEBUG
                                                   >> 973         G4cerr << "CompareInt "
                                                   >> 974              << arg1 << " " << opr << arg2 
                                                   >> 975              << " result: " << result
                                                   >> 976              << G4endl;
                                                   >> 977     #endif
                                                   >> 978     return result;
                                                   >> 979 }
                                                   >> 980 
                                                   >> 981 G4int G4UIcommand::
                                                   >> 982 CompareDouble(G4double arg1, G4int op, G4double arg2)
                                                   >> 983 {   
                                                   >> 984     G4int result=-1;
                                                   >> 985     G4String opr;
                                                   >> 986     switch (op) {
                                                   >> 987         case GT:  result = ( arg1 >  arg2); opr= ">";   break;
                                                   >> 988         case GE:  result = ( arg1 >= arg2); opr= ">=";  break;
                                                   >> 989         case LT:  result = ( arg1 <  arg2); opr= "<";   break;
                                                   >> 990         case LE:  result = ( arg1 <= arg2); opr= "<=";  break;
                                                   >> 991         case EQ:  result = ( arg1 == arg2); opr= "==";  break;
                                                   >> 992         case NE:  result = ( arg1 != arg2); opr= "!=";  break;
                                                   >> 993         default:
                                                   >> 994            G4cerr << "Parameter range: error at CompareDouble"
                                                   >> 995                 << G4endl;
                                                   >> 996            paramERR = 1;
                                                   >> 997     }
                                                   >> 998     #ifdef DEBUG
                                                   >> 999         G4cerr << "CompareDouble " 
                                                   >> 1000              << arg1 <<" " << opr << " "<< arg2
                                                   >> 1001              << " result: " << result
                                                   >> 1002              << G4endl;
                                                   >> 1003     #endif
                                                   >> 1004     return result;
                                                   >> 1005 }
                                                   >> 1006 
                                                   >> 1007 unsigned G4UIcommand::
                                                   >> 1008 IndexOf(const char* nam)
                                                   >> 1009 {
                                                   >> 1010     unsigned i;
                                                   >> 1011     G4String pname;
                                                   >> 1012     for( i=0;  i<parameter.size(); i++)
                                                   >> 1013     {
                                                   >> 1014         pname = parameter[i]-> GetParameterName();
                                                   >> 1015         if( pname == nam ) {
                                                   >> 1016             return i;
                                                   >> 1017         }
                                                   >> 1018     }
                                                   >> 1019     paramERR = 1;
                                                   >> 1020     G4cerr << "parameter name:"<<nam<<" not found."<< G4endl;
                                                   >> 1021     return 0;
                                                   >> 1022 }
                                                   >> 1023 
                                                   >> 1024 
                                                   >> 1025 unsigned G4UIcommand::
                                                   >> 1026 IsParameter(const char* nam)
                                                   >> 1027 {
                                                   >> 1028     G4String pname;
                                                   >> 1029     for(unsigned i=0;  i<parameter.size(); i++)  
                                                   >> 1030     {
                                                   >> 1031         pname = parameter[i]-> GetParameterName();
                                                   >> 1032         if( pname == nam ) return 1;
                                                   >> 1033     }
                                                   >> 1034     return 0;
                                                   >> 1035 }
                                                   >> 1036 
                                                   >> 1037 
                                                   >> 1038 // --------------------- utility functions --------------------------
                                                   >> 1039 
                                                   >> 1040 tokenNum G4UIcommand::
                                                   >> 1041 Yylex()         // reads input and returns token number, KR486
                                                   >> 1042 {               // (returns EOF)
                                                   >> 1043     G4int c;             
                                                   >> 1044     G4String buf;
                                                   >> 1045 
                                                   >> 1046     while(( c= G4UIpGetc())==' '|| c=='\t' || c== '\n' )
                                                   >> 1047         ;
                                                   >> 1048     if (c== EOF)
                                                   >> 1049         return (tokenNum)EOF;            // KR488 
                                                   >> 1050     buf= "";
                                                   >> 1051     if (isdigit(c) || c== '.') {         // I or D
                                                   >> 1052         do {
                                                   >> 1053              buf += G4String((unsigned char)c);
                                                   >> 1054              c=G4UIpGetc();
                                                   >> 1055          }  while (c=='.' || isdigit(c) || 
                                                   >> 1056                    c=='e' || c=='E' || c=='+' || c=='-');
                                                   >> 1057          G4UIpUngetc(c);
                                                   >> 1058          const char* t = buf;
                                                   >> 1059    std::istringstream is(t);
                                                   >> 1060          if ( IsInt(buf.data(),20) ) {
                                                   >> 1061              is >> yylval.I;
                                                   >> 1062              return  CONSTINT;
                                                   >> 1063          } else 
                                                   >> 1064          if ( IsDouble(buf.data()) ) {
                                                   >> 1065              is >> yylval.D;
                                                   >> 1066              return  CONSTDOUBLE;
                                                   >> 1067          } else {
                                                   >> 1068              G4cerr << buf<<": numeric format error."<<G4endl;
                                                   >> 1069          }
                                                   >> 1070     }
                                                   >> 1071     buf="";
                                                   >> 1072     if (isalpha(c)|| c=='_') {           // IDENTIFIER
                                                   >> 1073         do {
                                                   >> 1074             buf += G4String((unsigned char)c); 
                                                   >> 1075         } while ((c=G4UIpGetc()) != EOF && (isalnum(c) || c=='_'));
                                                   >> 1076         G4UIpUngetc(c);
                                                   >> 1077         if( IsParameter(buf) ) {
                                                   >> 1078             yylval.S =buf;
                                                   >> 1079             return IDENTIFIER;
                                                   >> 1080         } else {
                                                   >> 1081             G4cerr << buf << " is not a parameter name."<< G4endl;
                                                   >> 1082             paramERR = 1;
                                                   >> 1083        }
                                                   >> 1084     }
                                                   >> 1085     switch (c) {
                                                   >> 1086       case '>':   return (tokenNum) Follow('=', GE,        GT);
                                                   >> 1087       case '<':   return (tokenNum) Follow('=', LE,        LT);
                                                   >> 1088       case '=':   return (tokenNum) Follow('=', EQ,        '=');
                                                   >> 1089       case '!':   return (tokenNum) Follow('=', NE,        '!');
                                                   >> 1090       case '|':   return (tokenNum) Follow('|', LOGICALOR, '|');
                                                   >> 1091       case '&':   return (tokenNum) Follow('&', LOGICALAND, '&');
                                                   >> 1092       default:
                                                   >> 1093           return (tokenNum) c;
                                                   >> 1094     }
                                                   >> 1095 }
                                                   >> 1096 
                                                   >> 1097 
                                                   >> 1098 G4int G4UIcommand::
                                                   >> 1099 Follow(G4int expect, G4int ifyes, G4int ifno)
                                                   >> 1100 {
                                                   >> 1101     G4int c = G4UIpGetc();
                                                   >> 1102     if ( c== expect)
                                                   >> 1103           return ifyes;
                                                   >> 1104     G4UIpUngetc(c);
                                                   >> 1105     return ifno;
                                                   >> 1106 }
                                                   >> 1107 
                                                   >> 1108 //------------------ low level routines -----------------------------
                                                   >> 1109 G4int G4UIcommand::
                                                   >> 1110 G4UIpGetc() {                        // emulation of getc() 
                                                   >> 1111     G4int length = rangeString.length();
                                                   >> 1112     if( bp < length)
                                                   >> 1113         return  rangeString(bp++);
                                                   >> 1114     else 
                                                   >> 1115         return EOF;
                                                   >> 1116 }
                                                   >> 1117 G4int G4UIcommand::
                                                   >> 1118 G4UIpUngetc(G4int c) {                 // emulation of ungetc() 
                                                   >> 1119     if (c<0) return -1;
                                                   >> 1120     if (bp >0 && c == rangeString(bp-1)) {
                                                   >> 1121          --bp;
                                                   >> 1122     } else {
                                                   >> 1123          G4cerr << "G4UIpUngetc() failed." << G4endl;
                                                   >> 1124          G4cerr << "bp="<<bp <<" c="<<c
                                                   >> 1125               << " pR(bp-1)=" << rangeString(bp-1)
                                                   >> 1126               << G4endl;
                                                   >> 1127          paramERR = 1;
                                                   >> 1128          return -1;
                                                   >> 1129     }
                                                   >> 1130     return 0;
482 }                                                 1131 }
483                                                   1132