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.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 /g3tog4/src/clparse.cc (Version 11.3.0) and /g3tog4/src/clparse.cc (Version 10.1.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
                                                   >>  27 // $Id: clparse.cc 67982 2013-03-13 10:36:03Z gcosmo $
 27 //                                                 28 //
 28 // modified by I.Hrivnacova                        29 // modified by I.Hrivnacova
 29 // added G3SensVol                                 30 // added G3SensVol
 30                                                    31 
 31 #include "globals.hh"                              32 #include "globals.hh"
 32 #include <fstream>                                 33 #include <fstream>
 33 #include "G4Tokenizer.hh"                          34 #include "G4Tokenizer.hh"
 34 #include "G3toG4.hh"                               35 #include "G3toG4.hh"
 35 #include "G3EleTable.hh"                           36 #include "G3EleTable.hh"
 36 #include "G3VolTable.hh"                           37 #include "G3VolTable.hh"
 37 #include "G3MatTable.hh"                           38 #include "G3MatTable.hh"
 38 #include "G3MedTable.hh"                           39 #include "G3MedTable.hh"
 39 #include "G3RotTable.hh"                           40 #include "G3RotTable.hh"
 40 #include "G3PartTable.hh"                          41 #include "G3PartTable.hh"
 41 #include "G3DetTable.hh"                           42 #include "G3DetTable.hh"
 42 #include "G3SensVolVector.hh"                      43 #include "G3SensVolVector.hh"
 43                                                    44 
 44 std::ofstream ofile;                               45 std::ofstream ofile;
 45                                                    46 
 46 extern "C"                                         47 extern "C"
 47 {                                                  48 {
 48 #include <stdlib.h>                                49 #include <stdlib.h>
 49 }                                                  50 }
 50                                                    51 
 51 extern std::ofstream ofile;                        52 extern std::ofstream ofile;
 52                                                    53 
 53 G3VolTable G3Vol;                                  54 G3VolTable G3Vol;
 54 G3MatTable G3Mat;   // material G3 ID <-> G4 p     55 G3MatTable G3Mat;   // material G3 ID <-> G4 pointer table
 55 G3MedTable G3Med;   // trk media G3 ID <-> G4      56 G3MedTable G3Med;   // trk media G3 ID <-> G4 pointer table
 56 G3RotTable G3Rot;   // rotation ID <-> G4 tran     57 G3RotTable G3Rot;   // rotation ID <-> G4 transform object table
 57 G3PartTable G3Part; // particle ID <-> Particl     58 G3PartTable G3Part; // particle ID <-> ParticleDefinition pointer
 58 G3DetTable G3Det;   // sensitive detector name     59 G3DetTable G3Det;   // sensitive detector name <-> pointer
 59 G3EleTable G3Ele;   // element names table         60 G3EleTable G3Ele;   // element names table
 60 G3SensVolVector G3SensVol; // vector of sensit     61 G3SensVolVector G3SensVol; // vector of sensitive logical volumes
 61 char gSeparator('_');                              62 char gSeparator('_');
 62                                                    63 
 63 G4int narray;                                      64 G4int narray;
 64                                                    65 
 65 G4int Ipar[1000];                                  66 G4int Ipar[1000];
 66 G4double Rpar[1000];                               67 G4double Rpar[1000];
 67 G4String Spar[1000];                               68 G4String Spar[1000];
 68                                                    69 
 69 G4int G3CLTokens(G4String *line, G4String *tok     70 G4int G3CLTokens(G4String *line, G4String *tokens);
 70 void G3CLEval(G4String *tokens, char *select);     71 void G3CLEval(G4String *tokens, char *select);
 71                                                    72 
 72 // front-end decoders for G3 routines              73 // front-end decoders for G3 routines
 73 //                                                 74 //
 74 void PG4gsvolu(G4String *tokens);                  75 void PG4gsvolu(G4String *tokens);
 75 void PG4gspos (G4String *tokens);                  76 void PG4gspos (G4String *tokens);
 76 void PG4gsposp(G4String *tokens);                  77 void PG4gsposp(G4String *tokens);
 77 void PG4gsatt (G4String *tokens);                  78 void PG4gsatt (G4String *tokens);
 78 void PG4gsrotm(G4String *tokens);                  79 void PG4gsrotm(G4String *tokens);
 79 void PG4gsdvn (G4String *tokens);                  80 void PG4gsdvn (G4String *tokens);
 80 void PG4gsdvt (G4String *tokens);                  81 void PG4gsdvt (G4String *tokens);
 81 void PG4gsdvx (G4String *tokens);                  82 void PG4gsdvx (G4String *tokens);
 82 void PG4gsdvn2(G4String *tokens);                  83 void PG4gsdvn2(G4String *tokens);
 83 void PG4gsdvt2(G4String *tokens);                  84 void PG4gsdvt2(G4String *tokens);
 84 void PG4gsmate(G4String *tokens);                  85 void PG4gsmate(G4String *tokens);
 85 void PG4gsmixt(G4String *tokens);                  86 void PG4gsmixt(G4String *tokens);
 86 void PG4gstmed(G4String *tokens);                  87 void PG4gstmed(G4String *tokens);
 87 void PG4gstpar(G4String *tokens);                  88 void PG4gstpar(G4String *tokens);
 88 void PG4gspart(G4String *tokens);                  89 void PG4gspart(G4String *tokens);
 89 void PG4gsdk  (G4String *tokens);                  90 void PG4gsdk  (G4String *tokens);
 90 void PG4gsdet (G4String *tokens);                  91 void PG4gsdet (G4String *tokens);
 91 void PG4gsdetv(G4String *tokens);                  92 void PG4gsdetv(G4String *tokens);
 92 void PG4gsdeta(G4String *tokens);                  93 void PG4gsdeta(G4String *tokens);
 93 void PG4gsdeth(G4String *tokens);                  94 void PG4gsdeth(G4String *tokens);
 94 void PG4gsdetd(G4String *tokens);                  95 void PG4gsdetd(G4String *tokens);
 95 void PG4gsdetu(G4String *tokens);                  96 void PG4gsdetu(G4String *tokens);
 96 void PG4ggclos();                                  97 void PG4ggclos();
 97                                                    98 
 98 void G3CLRead(G4String & fname, char *select =     99 void G3CLRead(G4String & fname, char *select = 0)
 99 {                                                 100 {
100   //                                              101   //
101   //  G3CLRead                                    102   //  G3CLRead
102   //  Read the call List file, parse the token    103   //  Read the call List file, parse the tokens, and pass the token
103   //  List to the Geant4 interpreter              104   //  List to the Geant4 interpreter
104   //                                              105   //
105   //  fname: call List filename                   106   //  fname: call List filename
106                                                   107   
107     G4String line;                                108     G4String line;
108     G4String tokens[1000];                        109     G4String tokens[1000];
109                                                   110 
110     const char* ofname = "clparse.out";           111     const char* ofname = "clparse.out";
111     ofile.open(ofname);                           112     ofile.open(ofname);
112     ofile << "Output file open\n";                113     ofile << "Output file open\n";
113                                                   114 
                                                   >> 115     G4int count = 0;
114     G4int ntokens = 0;                            116     G4int ntokens = 0;
115     std::ifstream istr(fname);                    117     std::ifstream istr(fname);
116                                                   118     
117     while (G4StrUtil::readline(istr, line) &&  << 119     while (line.readLine(istr) && ! istr.eof())
118     {                                             120     {
                                                   >> 121         count++;
119         ntokens = G3CLTokens(&line,tokens);  /    122         ntokens = G3CLTokens(&line,tokens);  // tokenize the line
120         for (G4int i=0; i < ntokens; i++)         123         for (G4int i=0; i < ntokens; i++)
121         {                                         124         {
122           ofile << tokens[i] << G4endl;           125           ofile << tokens[i] << G4endl;
123         }                                         126         }
124                                                   127 
125         // interpret the line as a Geant call     128         // interpret the line as a Geant call
126         //                                        129         //
127         G3CLEval(tokens, select);                 130         G3CLEval(tokens, select);
128     }                                             131     }
129 }                                                 132 }
130                                                   133 
131                                                   134 
132 G4int G3CLTokens(G4String *line, G4String toke    135 G4int G3CLTokens(G4String *line, G4String tokens[])
133 {                                                 136 {
134   //                                              137   //
135   // G3CLTokens                                   138   // G3CLTokens
136   //                                              139   //
137   // Tokenize line, returning tokens in tokens    140   // Tokenize line, returning tokens in tokens[]. Items in ".."
138   // are extracted as single tokens, despite e    141   // are extracted as single tokens, despite embedded spaces.
139                                                   142 
140     G4Tokenizer next(*line);                      143     G4Tokenizer next(*line);
141                                                   144 
142     // first tokenize using " to identify stri    145     // first tokenize using " to identify strings
143     //                                            146     //
144     G4int itok = 0;                               147     G4int itok = 0;
145     G4int ntokens = 0;                            148     G4int ntokens = 0;
146     G4String token1, token2;                      149     G4String token1, token2;
147     while (!(token1=next("\"")).empty())       << 150     while (!(token1=next("\"")).isNull())
148     {                                             151     {
149         itok++;                                   152         itok++;
150         if (itok%2 == 0 ) // even: inside a st    153         if (itok%2 == 0 ) // even: inside a string
151         {                                         154         {
152             tokens[ntokens++] = token1;           155             tokens[ntokens++] = token1;
153         }                                         156         }
154         else              // not in a quoted s    157         else              // not in a quoted string: finish tokenization
155         {                                         158         {
156             G4Tokenizer lev2(token1);             159             G4Tokenizer lev2(token1);
157             while (!(token2=lev2()).empty())   << 160             while (!(token2=lev2()).isNull())
158             {                                     161             {
159                 tokens[ntokens] = token2;         162                 tokens[ntokens] = token2;
160                 ntokens++;                        163                 ntokens++;
161             }                                     164             }
162         }                                         165         }
163     }                                             166     }
164     return ntokens;                               167     return ntokens;
165 }                                                 168 }
166                                                   169 
167                                                   170 
168 void G3CLEval(G4String tokens[], char *select)    171 void G3CLEval(G4String tokens[], char *select)
169 {                                                 172 {
170   //                                              173   //
171   // G3CLEval                                     174   // G3CLEval
172   //                                              175   //
173   // Evaluate the token List as a Geant3 call,    176   // Evaluate the token List as a Geant3 call, and execute it as
174   // a Geant4 call.                               177   // a Geant4 call.
175                                                   178 
176     const char* context = tokens[0];              179     const char* context = tokens[0];
177     const char* routine = tokens[1];              180     const char* routine = tokens[1];
178     const char* wcard = "*";                      181     const char* wcard = "*";
179                                                   182 
180     // If context is selected, return unless c    183     // If context is selected, return unless context matches
181     //                                            184     //
182     if ((select != 0) && (select != wcard))       185     if ((select != 0) && (select != wcard))
183     {                                             186     {
184       if ( strcmp(select,context) )  { return;    187       if ( strcmp(select,context) )  { return; }
185     }                                             188     }
186                                                   189 
187     // Branch on Geant3 routine name              190     // Branch on Geant3 routine name
188     //                                            191     //
189     ofile << "Do routine " << routine << " in     192     ofile << "Do routine " << routine << " in context " << context << G4endl;
190                                                   193     
191     if ( !strcmp(routine,"GSVOLU") ) { PG4gsvo    194     if ( !strcmp(routine,"GSVOLU") ) { PG4gsvolu(&tokens[2]); return;}
192     if ( !strcmp(routine,"GSPOS") )  { PG4gspo    195     if ( !strcmp(routine,"GSPOS") )  { PG4gspos (&tokens[2]); return;}
193     if ( !strcmp(routine,"GSPOSP") ) { PG4gspo    196     if ( !strcmp(routine,"GSPOSP") ) { PG4gsposp(&tokens[2]); return;}
194     if ( !strcmp(routine,"GSATT") )  { PG4gsat    197     if ( !strcmp(routine,"GSATT") )  { PG4gsatt (&tokens[2]); return;}
195     if ( !strcmp(routine,"GSROTM") ) { PG4gsro    198     if ( !strcmp(routine,"GSROTM") ) { PG4gsrotm(&tokens[2]); return;}
196     if ( !strcmp(routine,"GSDVN") )  { PG4gsdv    199     if ( !strcmp(routine,"GSDVN") )  { PG4gsdvn (&tokens[2]); return;}
197     if ( !strcmp(routine,"GSDVT") )  { PG4gsdv    200     if ( !strcmp(routine,"GSDVT") )  { PG4gsdvt (&tokens[2]); return;}
198     if ( !strcmp(routine,"GSDVX") )  { PG4gsdv    201     if ( !strcmp(routine,"GSDVX") )  { PG4gsdvx (&tokens[2]); return;}
199     if ( !strcmp(routine,"GSDVN2") ) { PG4gsdv    202     if ( !strcmp(routine,"GSDVN2") ) { PG4gsdvn2(&tokens[2]); return;}
200     if ( !strcmp(routine,"GSDVT2") ) { PG4gsdv    203     if ( !strcmp(routine,"GSDVT2") ) { PG4gsdvt2(&tokens[2]); return;}
201     if ( !strcmp(routine,"GSMATE") ) { PG4gsma    204     if ( !strcmp(routine,"GSMATE") ) { PG4gsmate(&tokens[2]); return;}
202     if ( !strcmp(routine,"GSMIXT") ) { PG4gsmi    205     if ( !strcmp(routine,"GSMIXT") ) { PG4gsmixt(&tokens[2]); return;}
203     if ( !strcmp(routine,"GSTMED") ) { PG4gstm    206     if ( !strcmp(routine,"GSTMED") ) { PG4gstmed(&tokens[2]); return;}
204     if ( !strcmp(routine,"GSTPAR") ) { PG4gstp    207     if ( !strcmp(routine,"GSTPAR") ) { PG4gstpar(&tokens[2]); return;}
205     if ( !strcmp(routine,"GSPART") ) { PG4gspa    208     if ( !strcmp(routine,"GSPART") ) { PG4gspart(&tokens[2]); return;}
206     if ( !strcmp(routine,"GSDK") )   { PG4gsdk    209     if ( !strcmp(routine,"GSDK") )   { PG4gsdk  (&tokens[2]); return;}
207     if ( !strcmp(routine,"GSDET") )  { PG4gsde    210     if ( !strcmp(routine,"GSDET") )  { PG4gsdet (&tokens[2]); return;}
208     if ( !strcmp(routine,"GSDETV") ) { PG4gsde    211     if ( !strcmp(routine,"GSDETV") ) { PG4gsdetv(&tokens[2]); return;}
209     if ( !strcmp(routine,"GSDETA") ) { PG4gsde    212     if ( !strcmp(routine,"GSDETA") ) { PG4gsdeta(&tokens[2]); return;}
210     if ( !strcmp(routine,"GSDETH") ) { PG4gsde    213     if ( !strcmp(routine,"GSDETH") ) { PG4gsdeth(&tokens[2]); return;}
211     if ( !strcmp(routine,"GSDETD") ) { PG4gsde    214     if ( !strcmp(routine,"GSDETD") ) { PG4gsdetd(&tokens[2]); return;}
212     if ( !strcmp(routine,"GSDETU") ) { PG4gsde    215     if ( !strcmp(routine,"GSDETU") ) { PG4gsdetu(&tokens[2]); return;}
213     if ( !strcmp(routine,"GGCLOS") ) { PG4ggcl    216     if ( !strcmp(routine,"GGCLOS") ) { PG4ggclos(); return;}
214 }                                                 217 }
215                                                   218 
216 void G3fillParams(G4String *tokens, const char    219 void G3fillParams(G4String *tokens, const char *ptypes)
217 {                                                 220 {
218   //                                              221   //
219   // G3fillParams                                 222   // G3fillParams
220   //                                              223   //
221   // Interpret tokens to fill call parameters,    224   // Interpret tokens to fill call parameters, based on parameter types ptypes
222                                                   225 
223     // loop over ptypes                           226     // loop over ptypes
224     //                                            227     //
225     G4int i =0, ipt = 0, k = 0;                   228     G4int i =0, ipt = 0, k = 0;
226     G4int ni =0, nr = 0, nq = 0;                  229     G4int ni =0, nr = 0, nq = 0;
227     while (ptypes[i] != '\0')                     230     while (ptypes[i] != '\0')
228     {                                             231     {
229         switch (ptypes[i])                        232         switch (ptypes[i])
230         {                                         233         {
231             case 'i':                             234             case 'i':
232                 Ipar[ni] = atoi(tokens[ipt].da    235                 Ipar[ni] = atoi(tokens[ipt].data());
233                 narray = Ipar[ni];                236                 narray = Ipar[ni];
234                 ni++; ipt++;                      237                 ni++; ipt++;
235                 break;                            238                 break;
236             case 'r':                             239             case 'r':
237                 Rpar[nr] = atof(tokens[ipt].da    240                 Rpar[nr] = atof(tokens[ipt].data());
238                 nr++; ipt++;                      241                 nr++; ipt++;
239                 break;                            242                 break;
240             case 's':                             243             case 's':
241                 Spar[nq] = tokens[ipt];           244                 Spar[nq] = tokens[ipt];
242                 nq++; ipt++;                      245                 nq++; ipt++;
243                 break;                            246                 break;
244             case 'I':                             247             case 'I':
245                 for (k=0; k < narray; k++)        248                 for (k=0; k < narray; k++)
246                 {                                 249                 {
247                     Ipar[ni] = atoi(tokens[ipt    250                     Ipar[ni] = atoi(tokens[ipt].data());
248                     ni++; ipt++;                  251                     ni++; ipt++;
249                 }                                 252                 }
250                 break;                            253                 break;
251             case 'R':                             254             case 'R':
252                 for (k=0; k < narray; k++)        255                 for (k=0; k < narray; k++) 
253                 {                                 256                 { 
254                     Rpar[nr] = atof(tokens[ipt    257                     Rpar[nr] = atof(tokens[ipt].data()); 
255                     nr++; ipt++;                  258                     nr++; ipt++;
256                 }                                 259                 }
257                 break;                            260                 break;
258             case 'Q':                             261             case 'Q':
259                 // special case of reading thr    262                 // special case of reading three successive R arrays 
260                 // into one (used in gsmixt)      263                 // into one (used in gsmixt)
261                 //                                264                 //
262                 narray = 3 * std::abs(narray);    265                 narray = 3 * std::abs(narray);
263                 for (k=0; k < narray; k++)        266                 for (k=0; k < narray; k++) 
264                 {                                 267                 { 
265                     Rpar[nr] = atof(tokens[ipt    268                     Rpar[nr] = atof(tokens[ipt].data()); 
266                     nr++; ipt++;                  269                     nr++; ipt++;
267                 }                                 270                 }
268                 break;                            271                 break;
269             case 'S':                             272             case 'S':
270                 for (k=0; k < narray; k++)        273                 for (k=0; k < narray; k++)
271                 {                                 274                 {
272                     Spar[nq] = tokens[ipt];       275                     Spar[nq] = tokens[ipt];
273                     nq++; ipt++;                  276                     nq++; ipt++;
274                 }                                 277                 }
275                 break;                            278                 break;
276             default:                              279             default:
277                 ofile << "unidentified ptype '    280                 ofile << "unidentified ptype '" << ptypes[i] << G4endl;
278         };                                        281         };
279         i++;                                      282         i++;
280     }                                             283     }
281 }                                                 284 }
282                                                   285