Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/persistency/ascii/src/G4tgrUtils.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 /persistency/ascii/src/G4tgrUtils.cc (Version 11.3.0) and /persistency/ascii/src/G4tgrUtils.cc (Version 10.1)


  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 // G4tgrUtils implementation                   << 
 27 //                                                 26 //
 28 // Author: P.Arce, CIEMAT (November 2007)      <<  27 //
 29 // ------------------------------------------- <<  28 // class G4tgrUtils
                                                   >>  29 
                                                   >>  30 // History:
                                                   >>  31 // - Created.                                 P.Arce, CIEMAT (November 2007)
                                                   >>  32 // -------------------------------------------------------------------------
 30                                                    33 
 31 #include <iomanip>                                 34 #include <iomanip>
 32 #include <set>                                     35 #include <set>
 33                                                    36 
 34 #include "G4tgrUtils.hh"                           37 #include "G4tgrUtils.hh"
 35                                                    38 
 36 #include "geomdefs.hh"                             39 #include "geomdefs.hh"
 37 #include "G4PhysicalConstants.hh"                  40 #include "G4PhysicalConstants.hh"
 38 #include "G4tgrParameterMgr.hh"                    41 #include "G4tgrParameterMgr.hh"
 39 #include "G4tgrMessenger.hh"                       42 #include "G4tgrMessenger.hh"
 40 #include "G4UnitsTable.hh"                         43 #include "G4UnitsTable.hh"
 41 #include "G4GeometryTolerance.hh"                  44 #include "G4GeometryTolerance.hh"
 42 #include "G4UIcommand.hh"                          45 #include "G4UIcommand.hh"
 43                                                    46 
 44 G4ThreadLocal G4tgrEvaluator* G4tgrUtils::theE << 
 45                                                    47 
 46 // ------------------------------------------- <<  48 G4ThreadLocal G4tgrEvaluator* G4tgrUtils::theEvaluator  = 0 ;
                                                   >>  49 
                                                   >>  50 
                                                   >>  51 //-------------------------------------------------------------
 47 G4tgrUtils::G4tgrUtils()                           52 G4tgrUtils::G4tgrUtils()
 48 {                                                  53 {
 49   if(theEvaluator == nullptr)                  <<  54   if (!theEvaluator)  { theEvaluator= new G4tgrEvaluator; }
 50   {                                            << 
 51     theEvaluator = new G4tgrEvaluator;         << 
 52   }                                            << 
 53 }                                                  55 }
 54                                                    56 
 55 // ------------------------------------------- <<  57 
                                                   >>  58 //-------------------------------------------------------------
 56 G4tgrUtils::~G4tgrUtils()                          59 G4tgrUtils::~G4tgrUtils()
 57 {                                                  60 {
 58   delete theEvaluator;                         <<  61   delete theEvaluator; theEvaluator = 0;
 59   theEvaluator = nullptr;                      << 
 60 }                                                  62 }
 61                                                    63 
 62 // ------------------------------------------- <<  64 
 63 G4bool G4tgrUtils::IsSeparator(const char ch)  <<  65 //-------------------------------------------------------------
                                                   >>  66 G4bool G4tgrUtils::IsSeparator( const char ch)
 64 {                                                  67 {
 65   char nonCharacters[7] = { "()+-*/" };        <<  68   char nonCharacters[7] = {"()+-*/"};
 66   for(std::size_t ii = 0; ii < 6; ++ii)        <<  69   for( size_t ii = 0; ii < 6; ii++ )
 67   {                                                70   {
 68     if(ch == nonCharacters[ii])                <<  71     if( ch == nonCharacters[ii] )
 69     {                                              72     {
 70       return true;                                 73       return true;
 71     }                                              74     }
 72   }                                                75   }
 73   return false;                                    76   return false;
 74 }                                                  77 }
 75                                                    78 
 76 // ------------------------------------------- <<  79 
 77 G4bool G4tgrUtils::IsNumber(const G4String& st <<  80 //-------------------------------------------------------------
                                                   >>  81 G4bool G4tgrUtils::IsNumber( const G4String& str)
 78 {                                                  82 {
 79   G4int isnum = 1;                                 83   G4int isnum = 1;
 80   G4int numE  = 0;                             <<  84   G4int numE = 0;
 81   for(G4int ii = 0; ii < (G4int)str.length();  <<  85   for(size_t ii=0; ii<str.length(); ii++)
 82   {                                                86   {
 83     if(!isdigit(str[ii]) && (str[ii] != '.') & <<  87     if(!isdigit(str[ii]) && (str[ii]!='.') && (str[ii]!='-') && (str[ii]!='+'))
 84        (str[ii] != '+'))                       << 
 85     {                                              88     {
 86       //--- check for E(xponential)                89       //--- check for E(xponential)
 87       if(str[ii] == 'E' || str[ii] == 'e')     <<  90       if(str[ii] == 'E' || str[ii] == 'e' )
 88       {                                            91       {
 89         if(ii == 0)                            <<  92         if( ii == 0 )  { return 0; }
 90         {                                      <<  93         if(numE != 0 || ii == str.length()-1)
 91           return 0;                            << 
 92         }                                      << 
 93         if(numE != 0 || ii == G4int(str.length << 
 94         {                                          94         {
 95           isnum = 0;                               95           isnum = 0;
 96           break;                                   96           break;
 97         }                                          97         }
 98         numE++;                                    98         numE++;
 99       }                                            99       }
100       else                                        100       else
101       {                                           101       {
102         isnum = 0;                             << 102         isnum = 0; 
103         break;                                    103         break;
104       }                                           104       }
105     }                                             105     }
106   }                                               106   }
107   return isnum;                                   107   return isnum;
108 }                                                 108 }
109                                                   109 
110 // ------------------------------------------- << 110 
111 G4bool G4tgrUtils::IsInteger(const G4double va << 111 //-------------------------------------------------------------
                                                   >> 112 G4bool G4tgrUtils::IsInteger( const G4double val, const G4double precision )
112 {                                                 113 {
113   if(G4int(val) / val - 1 > precision)         << 114   if( G4int(val) / val - 1 > precision )
114   {                                            << 115   { 
115     return false;                              << 116     return 0;
116   }                                               117   }
117   else                                            118   else
118   {                                            << 119   { 
119     return true;                               << 120     return 1;
120   }                                               121   }
121 }                                                 122 }
122                                                   123 
123 // ------------------------------------------- << 124 
124 void G4tgrUtils::Dump3v(const G4ThreeVector& v << 125 //-------------------------------------------------------------
                                                   >> 126 void G4tgrUtils::Dump3v( const G4ThreeVector& vec, const char* msg) 
125 {                                                 127 {
126   G4cout << msg << std::setprecision(8) << vec << 128   G4cout << msg << std::setprecision(8)
127          << G4endl;                            << 129          << vec << std::setprecision(6) << G4endl;
128 }                                                 130 }
129                                                   131 
130 // ------------------------------------------- << 132 
131 void G4tgrUtils::Dumprm(const G4RotationMatrix << 133 //-------------------------------------------------------------
                                                   >> 134 void G4tgrUtils::Dumprm( const G4RotationMatrix& rm, const char* msg)
132 {                                                 135 {
133   G4cout << msg << G4endl << " xx=" << rm.xx() << 136   G4cout << msg << G4endl
134          << " zx=" << rm.zx() << G4endl << " x << 137        << " xx=" << rm.xx() << " yx=" << rm.yx() << " zx=" << rm.zx() << G4endl
135          << " yy=" << rm.yy() << " zy=" << rm. << 138        << " xy=" << rm.xy() << " yy=" << rm.yy() << " zy=" << rm.zy() << G4endl
136          << " xz=" << rm.xz() << " yz=" << rm. << 139        << " xz=" << rm.xz() << " yz=" << rm.yz() << " zz=" << rm.zz() << G4endl;
137          << G4endl;                            << 
138 }                                                 140 }
139                                                   141 
140 // ------------------------------------------- << 142 
141 void G4tgrUtils::DumpVS(const std::vector<G4St << 143 //-------------------------------------------------------------
142                         std::ostream& outs)    << 144 void G4tgrUtils::DumpVS( const std::vector<G4String>& wl,
                                                   >> 145                          const char* msg, std::ostream& outs ) 
143 {                                                 146 {
144   outs << msg << G4endl;                          147   outs << msg << G4endl;
145   for(auto ite = wl.cbegin(); ite != wl.cend() << 148   std::vector<G4String>::const_iterator ite;
                                                   >> 149   for( ite = wl.begin(); ite != wl.end(); ite++ )
146   {                                               150   {
147     outs << *ite << " ";                          151     outs << *ite << " ";
148   }                                               152   }
149   outs << G4endl;                                 153   outs << G4endl;
150 }                                                 154 }
151                                                   155 
152 // ------------------------------------------- << 156 
153 void G4tgrUtils::DumpVS(const std::vector<G4St << 157 //-------------------------------------------------------------
                                                   >> 158 void G4tgrUtils::DumpVS( const std::vector<G4String>& wl , const char* msg) 
154 {                                                 159 {
155   DumpVS(wl, msg, G4cout);                     << 160   DumpVS( wl, msg, G4cout);
156 }                                                 161 }
157                                                   162 
158 // ------------------------------------------- << 163 
159 G4String G4tgrUtils::SubColon(const G4String&  << 164 //-------------------------------------------------------------
                                                   >> 165 G4String G4tgrUtils::SubColon( const G4String& str ) 
160 {                                                 166 {
161   if(str.find(':') != 0)                       << 167   if( str.find(':') != 0 )
162   {                                               168   {
163     G4String ErrMessage = "Trying to subtract  << 169     G4String ErrMessage = "Trying to subtract leading colon from a word\n"
164                           G4String("that has n << 170                         + G4String("that has no leading colon: ") + str;
165     G4Exception("G4tgrUtils::SubColon()", "Par << 171     G4Exception("G4tgrUtils::SubColon()", "ParseError",
166                 ErrMessage);                   << 172                 FatalException, ErrMessage);
167   }                                               173   }
168   G4String strt = str.substr(1, str.size() - 1 << 174   G4String strt = str.substr(1,str.size()-1);
169   return strt;                                    175   return strt;
170 }                                                 176 }
171                                                   177 
172 // ------------------------------------------- << 178 
173 G4String G4tgrUtils::GetString(const G4String& << 179 //-------------------------------------------------------------
                                                   >> 180 G4String G4tgrUtils::GetString( const G4String& str ) 
174 {                                                 181 {
175   //----------- first check if it is parameter    182   //----------- first check if it is parameter
176   const char* cstr = str.c_str();                 183   const char* cstr = str.c_str();
177   if(cstr[0] == '$')                           << 184   if( cstr[0] == '$' )
178   {                                               185   {
179 #ifdef G4VERBOSE                                  186 #ifdef G4VERBOSE
180     if(G4tgrMessenger::GetVerboseLevel() >= 3) << 187     if( G4tgrMessenger::GetVerboseLevel() >= 3 )
181     {                                             188     {
182       G4cout << " G4tgrUtils::GetString() - Su    189       G4cout << " G4tgrUtils::GetString() - Substitute parameter: "
183              << G4tgrParameterMgr::GetInstance << 190              << G4tgrParameterMgr::GetInstance()
184                   str.substr(1, str.size()))   << 191                 ->FindParameter( str.substr(1,str.size())) << G4endl;
185              << G4endl;                        << 
186     }                                             192     }
187 #endif                                            193 #endif
188     return G4tgrParameterMgr::GetInstance()->F << 194     return G4tgrParameterMgr::GetInstance()
189       str.substr(1, str.size()));              << 195            ->FindParameter( str.substr(1,str.size()) );
190   }                                               196   }
191   else                                            197   else
192   {                                               198   {
193     return str;                                   199     return str;
194   }                                               200   }
195 }                                                 201 }
196                                                   202 
197 // ------------------------------------------- << 203 
198 G4double G4tgrUtils::GetDouble(const G4String& << 204 //-------------------------------------------------------------
                                                   >> 205 G4double G4tgrUtils::GetDouble( const G4String& str, G4double unitval ) 
199 {                                                 206 {
200   if(!theEvaluator)                            << 207   if (!theEvaluator)  { theEvaluator= new G4tgrEvaluator; }
201   {                                            << 
202     theEvaluator = new G4tgrEvaluator;         << 
203   }                                            << 
204 #ifdef G4VERBOSE                                  208 #ifdef G4VERBOSE
205   if(G4tgrMessenger::GetVerboseLevel() >= 3)   << 209   if( G4tgrMessenger::GetVerboseLevel() >= 3 )
206   {                                               210   {
207     G4cout << "G4tgrUtils::GetDouble() - Proce << 211     G4cout << "G4tgrUtils::GetDouble() - Processing: "
208            << " default unit " << unitval << G << 212            << str << " default unit " << unitval << G4endl;
209   }                                               213   }
210 #endif                                            214 #endif
211   if(str == "DBL_MAX")                         << 215   if( str == "DBL_MAX" ) {
212   {                                            << 
213     return DBL_MAX;                               216     return DBL_MAX;
214   }                                            << 217   }else if( str == "DBL_MIN" ) {
215   else if(str == "DBL_MIN")                    << 
216   {                                            << 
217     return DBL_MIN;                               218     return DBL_MIN;
218   }                                            << 219   }else if( str == "FLT_MAX" ) {
219   else if(str == "FLT_MAX")                    << 
220   {                                            << 
221     return FLT_MAX;                               220     return FLT_MAX;
222   }                                            << 221   }else if( str == "FLT_MIN" ) {
223   else if(str == "FLT_MIN")                    << 
224   {                                            << 
225     return FLT_MIN;                               222     return FLT_MIN;
226   }                                            << 223   }else if( str == "INT_MAX" ) {
227   else if(str == "INT_MAX")                    << 
228   {                                            << 
229     return INT_MAX;                               224     return INT_MAX;
230   }                                            << 225   }else if( str == "INT_MIN" ) {
231   else if(str == "INT_MIN")                    << 
232   {                                            << 
233     return INT_MIN;                               226     return INT_MIN;
234   }                                               227   }
235   //----- Look for arithmetic symbols, (, )       228   //----- Look for arithmetic symbols, (, )
236   const char* cstr = str.c_str();                 229   const char* cstr = str.c_str();
237   std::set<G4int> separators;                     230   std::set<G4int> separators;
238   separators.insert(-1);                          231   separators.insert(-1);
239   G4int strlen = G4int(str.length());             232   G4int strlen = G4int(str.length());
240   for(G4int ii = 0; ii < strlen; ++ii)         << 233   for(G4int ii=0; ii<strlen; ii++)
241   {                                               234   {
242     char cs = cstr[ii];                           235     char cs = cstr[ii];
243     if(cs == '*' || cs == '/' || cs == '(' ||  << 236     if( cs == '*' || cs == '/' || cs == '(' || cs == ')' )
244     {                                          << 237     {      
245       separators.insert(ii);                      238       separators.insert(ii);
246     }                                             239     }
247     else if(cs == '+' || cs == '-')            << 240     else if( cs == '+' || cs == '-' )
248     {                                             241     {
249       // Check if it is not an exponential        242       // Check if it is not an exponential
250       //                                          243       //
251       if((ii < 2) || ((cstr[ii - 1] != 'E') && << 244       if( (ii < 2)
252    !IsNumber(G4String(1,cstr[ii - 2])))        << 245        || ( (cstr[ii-1] != 'E') && (cstr[ii-1] != 'e') )
253       {                                        << 246        || !IsNumber(cstr[ii-2]) )
                                                   >> 247       { 
254         separators.insert(ii);                    248         separators.insert(ii);
255       }                                        << 249       } 
256     }                                          << 250     } 
257   }                                               251   }
258   separators.insert(strlen);                      252   separators.insert(strlen);
259   std::string strnew;  // build a new word wit << 253   std::string strnew; // build a new word with Parameters
260                        // and units substitute << 254                       // and units substituted by values
261   //----- Process words, defined as characters    255   //----- Process words, defined as characters between two separators
262   G4int nUnits = 0;                               256   G4int nUnits = 0;
263   std::set<G4int>::const_iterator site, site2;    257   std::set<G4int>::const_iterator site, site2;
264   site  = separators.cbegin();                 << 258   site = separators.begin();
265   site2 = site;                                << 259   site2 = site; site2++;
266   ++site2;                                     << 260   for( ; site2 != separators.end(); site++,site2++)
267   for(; site2 != separators.cend(); ++site, ++ << 
268   {                                               261   {
269 #ifdef G4VERBOSE                                  262 #ifdef G4VERBOSE
270     if(G4tgrMessenger::GetVerboseLevel() >= 3) << 263     if( G4tgrMessenger::GetVerboseLevel() >= 3 )
271     {                                             264     {
272       G4cout << "   Loop to find word between  << 265       G4cout << "   Loop to find word between " << *site
273              << G4endl;                        << 266              << " " << *site2 << G4endl;
274     }                                             267     }
275 #endif                                            268 #endif
276                                                   269 
277     if(*site != -1)                            << 270     if( *site != -1 )  { strnew += str.substr(*site,1); }
278     {                                          << 
279       strnew += str.substr(*site, 1);          << 
280     }                                          << 
281                                                   271 
282     G4int wlen = (*site2) - (*site) - 1;  // d << 272     G4int wlen = (*site2)-(*site)-1;   //do not count contiguous separators
283     std::string word;                             273     std::string word;
284     if(wlen != 0)                                 274     if(wlen != 0)
285     {                                             275     {
286       word = str.substr((*site) + 1, (*site2)  << 276       word = str.substr((*site)+1,(*site2)-(*site)-1);
287     }                                             277     }
288     else                                          278     else
289     {                                             279     {
290       //--- Check combination of separators       280       //--- Check combination of separators
291       //--- Check number of parentheses           281       //--- Check number of parentheses
292       continue;                                   282       continue;
293     }                                             283     }
294                                                << 284       
295 #ifdef G4VERBOSE                                  285 #ifdef G4VERBOSE
296     if(G4tgrMessenger::GetVerboseLevel() >= 3) << 286     if( G4tgrMessenger::GetVerboseLevel() >= 3 )
297     {                                             287     {
298       G4cout << "   Processing word: " << word    288       G4cout << "   Processing word: " << word << G4endl;
299     }                                             289     }
300 #endif                                            290 #endif
301     //----------- first check if it is paramet    291     //----------- first check if it is parameter
302     const char* cword = word.c_str();             292     const char* cword = word.c_str();
303     if(cword[0] == '$')                        << 293     if( cword[0] == '$' )
304     {                                             294     {
305       G4String parstr = G4tgrParameterMgr::Get << 295       G4String parstr = G4tgrParameterMgr::GetInstance()
306         word.substr(1, word.size()));          << 296                       ->FindParameter( word.substr(1,word.size()));
307       if(parstr.substr(0, 1) == "-")           << 297       if( parstr.substr(0,1) == "-" )
308       {                                           298       {
309         strnew += "(";                            299         strnew += "(";
310       }                                           300       }
311       strnew += parstr;                           301       strnew += parstr;
312       if(parstr.substr(0, 1) == "-")           << 302       if( parstr.substr(0,1) == "-" )
313       {                                           303       {
314         strnew += ")";                            304         strnew += ")";
315       }                                           305       }
316 #ifdef G4VERBOSE                                  306 #ifdef G4VERBOSE
317       if(G4tgrMessenger::GetVerboseLevel() >=  << 307       if( G4tgrMessenger::GetVerboseLevel() >= 3 )
318       {                                           308       {
319         G4cout << " G4tgrutils::GetDouble() -  << 309         G4cout << " G4tgrutils::GetDouble() - Param found: "
320                << " in string " << str << " ,  << 310                << word << " in string " << str
321                << G4endl;                      << 311                << " , substituted by " << parstr << G4endl;
322       }                                           312       }
323 #endif                                            313 #endif
324     }                                             314     }
325     else                                          315     else
326     {                                             316     {
327       //----- Get if it is a number               317       //----- Get if it is a number
328       if(IsNumber(word))                       << 318       if( IsNumber(word) )
329       {                                           319       {
330         //--- left separator cannot be ')'        320         //--- left separator cannot be ')'
331         if((*site != -1) && (cstr[*site] == ') << 321         if( (*site != -1) && (cstr[*site] == ')') )
332         {                                         322         {
333           G4String ErrMessage =                << 323           G4String ErrMessage = "There cannot be a ')' before a number: "
334             "There cannot be a ')' before a nu << 324                               + word + " in string: " + str;
335             " in string: " + str;              << 325           G4Exception("G4tgrUtils::GetDouble()", "ParseError",
336           G4Exception("G4tgrUtils::GetDouble() << 326                       FatalException, ErrMessage);
337                       ErrMessage);             << 
338         }                                         327         }
339         //--- right separator cannot be '('       328         //--- right separator cannot be '('
340         if((*site2 != strlen) && (cstr[*site2] << 329         if( (*site2 != strlen) && (cstr[*site2] == '(') )
341         {                                         330         {
342           G4String ErrMessage =                << 331           G4String ErrMessage = "There cannot be a '(' after a number: "
343             "There cannot be a '(' after a num << 332                               + word + " in string: " + str;
344             " in string: " + str;              << 333           G4Exception("G4tgrUtils::GetDouble()", "ParseError",
345           G4Exception("G4tgrUtils::GetDouble() << 334                       FatalException, ErrMessage);
346                       ErrMessage);             << 
347         }                                         335         }
348         strnew += word;                           336         strnew += word;
349                                                << 337         
350         //------ If it is an string, check if     338         //------ If it is an string, check if it is a unit
351       }                                           339       }
352       else                                        340       else
353       {                                           341       {
354         //--- First character cannot be a digi    342         //--- First character cannot be a digit
355         if(isdigit(word[0]))                   << 343         if( isdigit(word[0]) )
356         {                                         344         {
357           G4String ErrMessage =                << 345           G4String ErrMessage = "String words cannot start with a digit: "
358             "String words cannot start with a  << 346                               + word + " in string: " + str;
359             " in string: " + str;              << 347           G4Exception("G4tgrUtils::GetDouble()", "ParseError",
360           G4Exception("G4tgrUtils::GetDouble() << 348                       FatalException, ErrMessage );
361                       ErrMessage);             << 
362         }                                         349         }
363                                                << 350         
364         //----- Check if it is a function         351         //----- Check if it is a function
365         G4bool bWordOK = false;                << 352         G4bool bWordOK = false;      
366         if(G4tgrUtils::IsFunction(word))       << 353         if( G4tgrUtils::IsFunction( word ) )
367         {                                         354         {
368           //--- It must be followed by '('        355           //--- It must be followed by '('
369           if((*site2 == strlen) || (cstr[*site << 356           if( (*site2 == strlen) || (cstr[*site2] != '(') )
370           {                                       357           {
371             G4String ErrMessage =              << 358             G4String ErrMessage = "There must be a '(' after a function: "
372               "There must be a '(' after a fun << 359                                 + word + " in string: " + str;
373               " in string: " + str;            << 360             G4Exception("G4tgrUtils::GetDouble()", "ParseError",
374             G4Exception("G4tgrUtils::GetDouble << 361                         FatalException, ErrMessage );
375                         ErrMessage);           << 
376           }                                       362           }
377           strnew += word;                         363           strnew += word;
378           bWordOK = true;                      << 364           bWordOK = true;      
379           //----- Check if it is a unit        << 365         //----- Check if it is a unit      
380         }                                         366         }
381         else if(G4tgrUtils::WordIsUnit(word))  << 367         else if( G4tgrUtils::WordIsUnit( word ) )
382         {                                         368         {
383           //--- It must be preceded by a *        369           //--- It must be preceded by a *
384           if((*site == -1) || ((cstr[*site] != << 370           if( (*site == -1)
                                                   >> 371            || ( (cstr[*site] != '*') && (cstr[*site] != '/') ) )
385           {                                       372           {
386             G4String ErrMess =                 << 373             G4String ErrMess = "There must be a '*' before a unit definition: "
387               "There must be a '*' before a un << 374                                + word + " in string " + str;
388               " in string " + str;             << 375             G4Exception("G4tgrUtils::GetDouble()", "ParseError",
389             G4Exception("G4tgrUtils::GetDouble << 376                         FatalException, ErrMess );
390                         ErrMess);              << 
391           }                                       377           }
392           //--- check that it is indeed a CLHE    378           //--- check that it is indeed a CLHEP unit
393           if(G4UnitDefinition::GetValueOf(word << 379           if( G4UnitDefinition::GetValueOf(word) != 0. )
394           {                                       380           {
395             bWordOK = true;                    << 381             bWordOK = true;      
396             nUnits++;                             382             nUnits++;
397             if(nUnits > 1)                     << 383             if( nUnits > 1 )
398             {                                     384             {
399               // G4String ErrMess = "There can    385               // G4String ErrMess = "There cannot be two unit definitions: "
400               //                  + word + " i    386               //                  + word + " in string " + str;
401               // G4Exception("G4tgrUtils::GetD    387               // G4Exception("G4tgrUtils::GetDouble()", "ParseError",
402               //             FatalException, E    388               //             FatalException, ErrMess );
403             }                                     389             }
404             strnew +=                          << 390             strnew += G4UIcommand::ConvertToString( G4UnitDefinition::GetValueOf(word) );
405               G4UIcommand::ConvertToString(G4U << 
406           }                                       391           }
407         }                                         392         }
408         if(!bWordOK)                           << 393         if( !bWordOK )
409         {                                         394         {
410           G4String ErrMess = "String word is n << 395           G4String ErrMess = "String word is not a parameter, nor a unit\n";
411                              G4String("definit << 396                            + G4String("definition nor a function: ") + word
412                              G4String(" in str << 397                            + G4String(" in string: ") + str;
413           G4Exception("G4tgrUtils::GetDouble() << 398           G4Exception("G4tgrUtils::GetDouble()", "ParseError",
414                       ErrMess);                << 399                       FatalException, ErrMess );
415         }                                         400         }
416       }                                           401       }
417     }                                             402     }
418   }                                               403   }
419                                                   404 
420   G4double val = theEvaluator->evaluate(strnew << 405   G4double val = theEvaluator->evaluate( strnew.c_str() );
421   if(theEvaluator->status() != HepTool::Evalua << 406   if (theEvaluator->status() != HepTool::Evaluator::OK)
422   {                                               407   {
423     theEvaluator->print_error(theEvaluator->st    408     theEvaluator->print_error(theEvaluator->status());
424     G4String ErrMessage = "Evaluator error: "     409     G4String ErrMessage = "Evaluator error: " + strnew;
425     G4Exception("G4tgrUtils::GetDouble()", "Pa << 410     G4Exception("G4tgrUtils::GetDouble()", "ParseError",
426                 ErrMessage);                   << 411                 FatalException, ErrMessage );
427   }                                            << 
428                                                << 
429   if(nUnits == 0)                              << 
430   {                                            << 
431     val *= unitval;                            << 
432   }                                               412   }
                                                   >> 413   
                                                   >> 414   if( nUnits == 0 )  { val *= unitval; }
433                                                   415 
434 #ifdef G4VERBOSE                                  416 #ifdef G4VERBOSE
435   if(G4tgrMessenger::GetVerboseLevel() >= 3)   << 417   if( G4tgrMessenger::GetVerboseLevel() >= 3 )
436   {                                               418   {
437     G4cout << " G4tgrUtils::GetDouble() - RESU    419     G4cout << " G4tgrUtils::GetDouble() - RESULT= " << val << G4endl
438            << "   from string: " << str << " c    420            << "   from string: " << str << " converted to: " << strnew.c_str()
439            << " with unit val: " << unitval <<    421            << " with unit val: " << unitval << G4endl;
440   }                                               422   }
441 #endif                                            423 #endif
442                                                   424 
443   return val;                                     425   return val;
444 }                                                 426 }
445                                                   427 
446 // ------------------------------------------- << 428 
447 G4int G4tgrUtils::GetInt(const G4String& str)  << 429 //-------------------------------------------------------------
                                                   >> 430 G4int G4tgrUtils::GetInt( const G4String& str ) 
448 {                                                 431 {
449   //----- Convert it to a number (it can be a     432   //----- Convert it to a number (it can be a parameter)
450   G4double val = GetDouble(str);                  433   G4double val = GetDouble(str);
451                                                   434 
452   //----- Check it is an integer                  435   //----- Check it is an integer
453   if(!IsInteger(val))                          << 436   if( !IsInteger(val) )
454   {                                               437   {
455     G4String ErrMessage = G4String("Trying to  << 438     G4String ErrMessage = G4String("Trying to get the integer from a number")
456                           G4String(" which is  << 439                         + G4String(" which is not an integer ") + str;
457     G4Exception("G4tgrUtils::GetInt()", "Parse << 440     G4Exception("G4tgrUtils::GetInt()", "ParseError",
458                 ErrMessage);                   << 441                 FatalException, ErrMessage );
459   }                                               442   }
460   return G4int(val);                           << 443   return G4int( val );
461 }                                                 444 }
462                                                   445 
463 // ------------------------------------------- << 446 
464 G4bool G4tgrUtils::GetBool(const G4String& str << 447 //-------------------------------------------------------------
                                                   >> 448 G4bool G4tgrUtils::GetBool( const G4String& str ) 
465 {                                                 449 {
466   G4bool val = false;                             450   G4bool val = false;
467                                                << 451   
468   //----------- first check that it is a not n    452   //----------- first check that it is a not number
469   if((str == "ON") || (str == "TRUE"))         << 453   if( (str == "ON") || (str == "TRUE")  )
470   {                                               454   {
471     val = true;                                   455     val = true;
472   }                                               456   }
473   else if((str == "OFF") || (str == "FALSE"))  << 457   else if( (str == "OFF") || (str == "FALSE") )
474   {                                               458   {
475     val = false;                                  459     val = false;
476   }                                               460   }
477   else                                            461   else
478   {                                               462   {
479     G4String ErrMessage = G4String("Trying to  << 463     G4String ErrMessage = G4String("Trying to get a float from a string")
480                           G4String(" which is  << 464                         + G4String(" which is not 'ON'/'OFF'/'TRUE'/'FALSE' ")
481                           str;                 << 465                         + str;
482     G4Exception("G4tgrUtils::GetBool()", "Pars << 466     G4Exception("G4tgrUtils::GetBool()", "ParseError",
483                 ErrMessage);                   << 467                 FatalException, ErrMessage );
484   }                                               468   }
485                                                   469 
486   return val;                                     470   return val;
487 }                                                 471 }
488                                                   472 
489 // ------------------------------------------- << 473 
490 void G4tgrUtils::CheckWLsize(const std::vector << 474 //-------------------------------------------------------------
491                              unsigned int nWch << 475 void G4tgrUtils::CheckWLsize( const std::vector<G4String>& wl,
492                              const G4String& m << 476                               unsigned int nWcheck, WLSIZEtype st,
                                                   >> 477                               const G4String& methodName )
493 {                                                 478 {
494   G4String outStr = methodName + G4String(".      479   G4String outStr = methodName + G4String(".  Line read with number of words ");
495   unsigned int wlsize = (unsigned int)wl.size( << 480   unsigned int wlsize = wl.size();
496                                                   481 
497   G4bool isOK = CheckListSize(wlsize, nWcheck, << 482   G4bool isOK = CheckListSize( wlsize, nWcheck, st, outStr );
498                                                   483 
499   if(!isOK)                                    << 484   if( !isOK )
500   {                                            << 485   { 
501     G4String chartmp = G4UIcommand::ConvertToS << 486     G4String chartmp = G4UIcommand::ConvertToString( G4int(nWcheck) );
502     outStr += chartmp + G4String(" words");       487     outStr += chartmp + G4String(" words");
503     DumpVS(wl, outStr.c_str());                << 488     DumpVS( wl, outStr.c_str() );
504     G4String ErrMessage =                      << 489     G4String ErrMessage = " NUMBER OF WORDS: "
505       " NUMBER OF WORDS: " + G4UIcommand::Conv << 490                         + G4UIcommand::ConvertToString(G4int(wlsize));
506     G4Exception("G4tgrUtils::CheckWLsize()", " << 491     G4Exception("G4tgrUtils::CheckWLsize()", "ParseError",
507                 ErrMessage);                   << 492                 FatalException, ErrMessage);
508   }                                               493   }
509 }                                                 494 }
510                                                   495 
511 // ------------------------------------------- << 496 //-------------------------------------------------------------
512 G4bool G4tgrUtils::CheckListSize(unsigned int  << 497 G4bool G4tgrUtils::CheckListSize( unsigned int nWreal, unsigned int nWcheck,
513                                  WLSIZEtype st << 498                                   WLSIZEtype st, G4String& outStr )
514 {                                                 499 {
515   G4bool isOK = true;                             500   G4bool isOK = true;
516   switch(st)                                   << 501   switch (st)
517   {                                               502   {
518     case WLSIZE_EQ:                            << 503   case WLSIZE_EQ:
519       if(nWreal != nWcheck)                    << 504     if( nWreal != nWcheck )
520       {                                        << 505     {
521         isOK = false;                          << 506       isOK = false;
522         outStr += G4String("not equal than "); << 507       outStr += G4String("not equal than ");
523       }                                        << 508     }
524       break;                                   << 509     break;
525     case WLSIZE_NE:                            << 510   case WLSIZE_NE:
526       if(nWreal == nWcheck)                    << 511     if( nWreal == nWcheck )
527       {                                        << 512     {
528         isOK = false;                          << 513       isOK = false;
529         outStr += G4String("equal than ");     << 514       outStr += G4String("equal than ");
530       }                                        << 515     }
531       break;                                   << 516     break;
532     case WLSIZE_LE:                            << 517   case WLSIZE_LE:
533       if(nWreal > nWcheck)                     << 518     if( nWreal > nWcheck )
534       {                                        << 519     {
535         isOK = false;                          << 520       isOK = false;
536         outStr += G4String("greater than ");   << 521       outStr += G4String("greater than ");
537       }                                        << 522     }
538       break;                                   << 523     break;
539     case WLSIZE_LT:                            << 524   case WLSIZE_LT:
540       if(nWreal >= nWcheck)                    << 525     if( nWreal >= nWcheck )
541       {                                        << 526     {
542         isOK = false;                          << 527       isOK = false;
543         outStr += G4String("greater or equal t << 528       outStr += G4String("greater or equal than ");
544       }                                        << 529     }
545       break;                                   << 530     break;
546     case WLSIZE_GE:                            << 531   case WLSIZE_GE:
547       if(nWreal < nWcheck)                     << 532     if( nWreal < nWcheck )
548       {                                        << 533     {
549         isOK = false;                          << 534       isOK = false;
550         outStr += G4String("less than ");      << 535       outStr += G4String("less than ");
551       }                                        << 536     }
552       break;                                   << 537     break;
553     case WLSIZE_GT:                            << 538   case WLSIZE_GT:
554       if(nWreal <= nWcheck)                    << 539     if( nWreal <= nWcheck )
555       {                                        << 540     {
556         isOK = false;                          << 541       isOK = false;
557         outStr += G4String("less or equal than << 542       outStr += G4String("less or equal than ");
558       }                                        << 543     }
559       break;                                   << 544     break;
560     default:                                   << 545   default:
561       G4cerr << " ERROR!! - G4tgrUtils::CheckL << 546     G4cerr << " ERROR!! - G4tgrUtils::CheckListSize()" << G4endl
562              << "           Type of WLSIZE typ << 547            << "           Type of WLSIZE type not found " << st << G4endl;
563       break;                                   << 548     break;
564   }                                               549   }
565                                                   550 
566   return isOK;                                    551   return isOK;
567 }                                                 552 }
568                                                   553 
569 // ------------------------------------------- << 554 
570 G4bool G4tgrUtils::WordIsUnit(const G4String&  << 555 //-------------------------------------------------------------
                                                   >> 556 G4bool G4tgrUtils::WordIsUnit( const G4String& word ) 
571 {                                                 557 {
572   return !IsNumber(word);                         558   return !IsNumber(word);
573   if(word == "mm" || word == "cm" || word == " << 559   if(    word == "mm"
574      word == "millimeter" || word == "centimet << 560       || word == "cm"
575      word == "kilometer" || word == "parsec" | << 561       || word == "m" 
576      word == "nanometer" || word == "angstrom" << 562       || word == "km"
577      word == "nm" || word == "um" || word == " << 563       || word == "millimeter"
578      word == "milliradian" || word == "degree" << 564       || word == "centimeter"
579      word == "mrad" || word == "deg" || word = << 565       || word == "meter"
580      word == "curie")                          << 566       || word == "kilometer"
581   {                                            << 567       || word == "parsec"
                                                   >> 568       || word == "micrometer"
                                                   >> 569       || word == "nanometer"
                                                   >> 570       || word == "angstrom"
                                                   >> 571       || word == "fermi"
                                                   >> 572       || word == "nm"
                                                   >> 573       || word == "um"
                                                   >> 574       || word == "pc"
                                                   >> 575       || word == "radian"
                                                   >> 576       || word == "milliradian"
                                                   >> 577       || word == "degree"
                                                   >> 578       || word == "rad"
                                                   >> 579       || word == "mrad"
                                                   >> 580       || word == "deg"
                                                   >> 581       || word == "ns"
                                                   >> 582       || word == "becquerel"
                                                   >> 583       || word == "curie"   )
                                                   >> 584   { 
582     return true;                                  585     return true;
583   }                                               586   }
584   else                                            587   else
585   {                                            << 588   { 
586     return false;                                 589     return false;
587   }                                               590   }
588 }                                                 591 }
589                                                   592 
590 // ------------------------------------------- << 593 
591 G4bool G4tgrUtils::IsFunction(const G4String&  << 594 //-------------------------------------------------------------
                                                   >> 595 G4bool G4tgrUtils::IsFunction( const G4String& word ) 
592 {                                                 596 {
593   if(word == "sin" || word == "cos" || word == << 597   if(    word == "sin"
594      word == "acos" || word == "atan" || word  << 598       || word == "cos"
595      word == "cosh" || word == "tanh" || word  << 599       || word == "tan"
596      word == "atanh" || word == "sqrt" || word << 600       || word == "asin"
597      word == "log10" || word == "pow")         << 601       || word == "acos"
598   {                                            << 602       || word == "atan"
                                                   >> 603       || word == "atan2"
                                                   >> 604       || word == "sinh"
                                                   >> 605       || word == "cosh"
                                                   >> 606       || word == "tanh"
                                                   >> 607       || word == "asinh"
                                                   >> 608       || word == "acosh"
                                                   >> 609       || word == "atanh"
                                                   >> 610       || word == "sqrt"
                                                   >> 611       || word == "exp"
                                                   >> 612       || word == "log"
                                                   >> 613       || word == "log10" 
                                                   >> 614       || word == "pow"  )
                                                   >> 615   { 
599     return true;                                  616     return true;
600   }                                               617   }
601   else                                            618   else
602   {                                            << 619   { 
603     return false;                                 620     return false;
604   }                                               621   }
605 }                                                 622 }
606                                                   623 
607 // ------------------------------------------- << 624 
608 G4RotationMatrix G4tgrUtils::GetRotationFromDi << 625 //-------------------------------------------------------------
                                                   >> 626 G4RotationMatrix G4tgrUtils::GetRotationFromDirection( G4ThreeVector dir )
609 {                                                 627 {
610   G4RotationMatrix rotation;                      628   G4RotationMatrix rotation;
611                                                   629 
612   if(std::fabs(dir.mag() - 1.) >               << 630   if( std::fabs(dir.mag()-1.) > G4GeometryTolerance::GetInstance()
613      G4GeometryTolerance::GetInstance()->GetSu << 631                               ->GetSurfaceTolerance() )
614   {                                               632   {
615     G4String WarMessage = "Direction cosines h << 633     G4String WarMessage = "Direction cosines have been normalized to one.\n"
616                           G4String("They were  << 634                         + G4String("They were normalized to ")
617                           G4UIcommand::Convert << 635                         + G4UIcommand::ConvertToString(dir.mag());
618     G4Exception("G4tgrUtils::GetRotationFromDi    636     G4Exception("G4tgrUtils::GetRotationFromDirection()", "WrongArgument",
619                 JustWarning, WarMessage);         637                 JustWarning, WarMessage);
620     dir /= dir.mag();                             638     dir /= dir.mag();
621   }                                            << 639   } 
622   G4double angx = -std::asin(dir.y());            640   G4double angx = -std::asin(dir.y());
623                                                   641 
624   // There are always two solutions angx, angy    642   // There are always two solutions angx, angy and PI-angx,
625   // PI+angy, choose first                        643   // PI+angy, choose first
626   //                                              644   //
627   G4double angy;                                  645   G4double angy;
628   if(dir.y() == 1.)                            << 646   if( dir.y() == 1. )
629   {                                               647   {
630     angy = 0.;                                    648     angy = 0.;
631   }                                               649   }
632   else if(dir.y() == 0.)                       << 650   else if( dir.y() == 0. )
633   {                                               651   {
634     angy = 0.;                                    652     angy = 0.;
635   }                                               653   }
636   else                                            654   else
637   {                                               655   {
638     angy = std::asin(dir.x() / std::sqrt(1 - d << 656     angy = std::asin( dir.x()/std::sqrt(1-dir.y()*dir.y()) );
639   }                                               657   }
640                                                << 658   
641   // choose between  angy and PI-angy             659   // choose between  angy and PI-angy
642   if(dir.z() * std::cos(angx) * std::cos(angy) << 660   if( dir.z() * std::cos(angx)*std::cos(angy) < 0 )
643   {                                               661   {
644     angy = pi - angy;                             662     angy = pi - angy;
645   }                                               663   }
646   rotation.rotateX(angx);                      << 664   rotation.rotateX( angx );
647   rotation.rotateY(angy);                      << 665   rotation.rotateY( angy );
648                                                   666 
649   return rotation;                                667   return rotation;
650 }                                              << 668 }  
                                                   >> 669 
651                                                   670 
652 // ------------------------------------------- << 671 //-------------------------------------------------------------
653 G4bool G4tgrUtils::AreWordsEquivalent(const G4 << 672 G4bool G4tgrUtils::AreWordsEquivalent( const G4String& word1,
654                                       const G4 << 673                                        const G4String& word2 )
655 {                                                 674 {
656   G4bool bEqual = true;                           675   G4bool bEqual = true;
657   std::vector<std::pair<size_t, size_t>> strin << 676   std::vector< std::pair<size_t,size_t> > stringPairs;
658   // start of substring, number of characters  << 677     // start of substring, number of characters
659                                                   678 
660   //--- Get string limits between asterisks in    679   //--- Get string limits between asterisks in word1
661                                                   680 
662   std::size_t cStart = 0;                      << 681   size_t cStart = 0;
663   for(;;)                                      << 682   for( ;; )
664   {                                               683   {
665     size_t cAster = word1.find("*", cStart);   << 684     size_t cAster = word1.find("*",cStart);
666     if(cAster != std::string::npos)            << 685     if( cAster != std::string::npos )
667     {                                             686     {
668       if(cAster == cStart)                     << 687       if( cAster == cStart )
669       {                                           688       {
670         if(cAster != 0)                        << 689         if( cAster != 0 )
671         {                                         690         {
672           G4Exception("G4tgrUtils::AreWordsEqu    691           G4Exception("G4tgrUtils::AreWordsEquivalent()",
673                       "A word has two asterisk    692                       "A word has two asterisks together, please correct it",
674                       FatalException, ("Offend << 693                       FatalException,("Offending word is: " + word1).c_str() );
675         }                                         694         }
676         else                                      695         else
677         {                                         696         {
678           // word1 == *                           697           // word1 == *
679           if(word1.size() == 1)                << 698           if(word1.size() == 1 )  { return true; }
680           {                                    << 
681             return true;                       << 
682           }                                    << 
683         }                                         699         }
684       }                                        << 700       }     
685       if(cAster != cStart)                     << 701       if( cAster!= cStart )
686       {                                           702       {
687         stringPairs.push_back(                 << 703         stringPairs.push_back( std::pair<size_t,size_t>(cStart, cAster-cStart) );
688           std::pair<size_t, size_t>(cStart, cA << 
689       }                                           704       }
690       cStart = cAster + 1;                     << 705       cStart = cAster+1;
691     }                                             706     }
692     else                                          707     else
693     {                                             708     {
694       if(cStart == 0)                          << 709       if( cStart == 0 )
695       {                                           710       {
696         //--- If there is no asterisk check if    711         //--- If there is no asterisk check if they are the same
697         return word1 == word2;                    712         return word1 == word2;
698       }                                           713       }
699       break;                                      714       break;
700     }                                             715     }
701   }                                               716   }
702                                                << 717   
703   //---- Add characters after last asterisk as << 718   //---- Add characters after last asterisk as string pair 
704   if(cStart <= word1.length())                 << 719   if( cStart <= word1.length() )
705   {                                               720   {
706     if(word1.length() != cStart)               << 721     if( word1.length() != cStart )
707     {                                             722     {
708       stringPairs.push_back(                   << 723       stringPairs.push_back( std::pair<size_t,size_t>(cStart,
709         std::pair<size_t, size_t>(cStart, word << 724                                                     word1.length()-cStart) );
710     }                                             725     }
711   }                                               726   }
712                                                   727 
713   //--- If there are not asterisk, simple comp    728   //--- If there are not asterisk, simple comparison
714   if(stringPairs.size() == 0)                  << 729   if( stringPairs.size() == 0 )
715   {                                               730   {
716     if(word1 == word2)                         << 731     if( word1 == word2 )
717     {                                             732     {
718       return true;                                733       return true;
719     }                                             734     }
720     else                                          735     else
721     {                                             736     {
722       return false;                               737       return false;
723     }                                             738     }
724   }                                               739   }
725                                                << 740   
726   //--- Find substrings in word2, in same orde    741   //--- Find substrings in word2, in same order as in word1
727   cStart = 0;                                     742   cStart = 0;
728   for(std::size_t ii = 0; ii < stringPairs.siz << 743   for( size_t ii = 0; ii < stringPairs.size(); ii++ )
729   {                                               744   {
730     std::pair<size_t, size_t> spair = stringPa << 745     std::pair<size_t,size_t> spair = stringPairs[ii];
731     size_t sFound = word2.find(word1.substr(sp << 746     size_t sFound = word2.find(word1.substr(spair.first, spair.second),cStart);
732     if(sFound == std::string::npos)            << 747     if( sFound  == std::string::npos )
733     {                                             748     {
734       bEqual = false;                             749       bEqual = false;
735       break;                                      750       break;
736     }                                             751     }
737     else                                          752     else
738     {                                             753     {
739       //---- If there is no asterisk before fi    754       //---- If there is no asterisk before first character,
740       //     the fisrt string pair found has t    755       //     the fisrt string pair found has to start at the first character
741       if(spair.first == 0 && sFound != 0)      << 756       if( spair.first == 0 && sFound != 0 )
742       {                                           757       {
743         bEqual = false;                           758         bEqual = false;
744         break;                                    759         break;
745         //---- If there is no asterisk after l    760         //---- If there is no asterisk after last character,
746         //     the last string pair found has     761         //     the last string pair found has to end at the last character
747       }                                           762       }
748       else if((spair.first + spair.second - 1  << 763       else if( (spair.first+spair.second-1 == word1.length())
749               (sFound + spair.second - 1 != wo << 764             && (sFound+spair.second-1 != word2.length()) )
750       {                                           765       {
751         bEqual = false;                           766         bEqual = false;
752         break;                                    767         break;
753       }                                           768       }
754       cStart += spair.second;                     769       cStart += spair.second;
755     }                                          << 770     } 
756   }                                               771   }
757                                                   772 
758   return bEqual;                                  773   return bEqual;
759 }                                                 774 }
760                                                   775