Geant4 Cross Reference

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

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

Diff markup

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


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