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 9.1.p1)


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