source: trunk/source/g3tog4/src/clparse.cc @ 817

Last change on this file since 817 was 817, checked in by garnier, 16 years ago

import all except CVS

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