Geant4-11
clparse.cc
Go to the documentation of this file.
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//
28// modified by I.Hrivnacova
29// added G3SensVol
30
31#include "globals.hh"
32#include <fstream>
33#include "G4Tokenizer.hh"
34#include "G3toG4.hh"
35#include "G3EleTable.hh"
36#include "G3VolTable.hh"
37#include "G3MatTable.hh"
38#include "G3MedTable.hh"
39#include "G3RotTable.hh"
40#include "G3PartTable.hh"
41#include "G3DetTable.hh"
42#include "G3SensVolVector.hh"
43
44std::ofstream ofile;
45
46extern "C"
47{
48#include <stdlib.h>
49}
50
51extern std::ofstream ofile;
52
54G3MatTable G3Mat; // material G3 ID <-> G4 pointer table
55G3MedTable G3Med; // trk media G3 ID <-> G4 pointer table
56G3RotTable G3Rot; // rotation ID <-> G4 transform object table
57G3PartTable G3Part; // particle ID <-> ParticleDefinition pointer
58G3DetTable G3Det; // sensitive detector name <-> pointer
59G3EleTable G3Ele; // element names table
60G3SensVolVector G3SensVol; // vector of sensitive logical volumes
61char gSeparator('_');
62
64
65G4int Ipar[1000];
68
70void G3CLEval(G4String *tokens, char *select);
71
72// front-end decoders for G3 routines
73//
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 //
101 // G3CLRead
102 // Read the call List file, parse the tokens, and pass the token
103 // List to the Geant4 interpreter
104 //
105 // fname: call List filename
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 (G4StrUtil::readline(istr, line) && ! istr.eof())
119 {
120 count++;
121 ntokens = G3CLTokens(&line,tokens); // tokenize the line
122 for (G4int i=0; i < ntokens; i++)
123 {
124 ofile << tokens[i] << G4endl;
125 }
126
127 // interpret the line as a Geant call
128 //
129 G3CLEval(tokens, select);
130 }
131}
132
133
135{
136 //
137 // G3CLTokens
138 //
139 // Tokenize line, returning tokens in tokens[]. Items in ".."
140 // are extracted as single tokens, despite embedded spaces.
141
142 G4Tokenizer next(*line);
143
144 // first tokenize using " to identify strings
145 //
146 G4int itok = 0;
147 G4int ntokens = 0;
148 G4String token1, token2;
149 while (!(token1=next("\"")).empty())
150 {
151 itok++;
152 if (itok%2 == 0 ) // even: inside a string
153 {
154 tokens[ntokens++] = token1;
155 }
156 else // not in a quoted string: finish tokenization
157 {
158 G4Tokenizer lev2(token1);
159 while (!(token2=lev2()).empty())
160 {
161 tokens[ntokens] = token2;
162 ntokens++;
163 }
164 }
165 }
166 return ntokens;
167}
168
169
170void G3CLEval(G4String tokens[], char *select)
171{
172 //
173 // G3CLEval
174 //
175 // Evaluate the token List as a Geant3 call, and execute it as
176 // a Geant4 call.
177
178 const char* context = tokens[0];
179 const char* routine = tokens[1];
180 const char* wcard = "*";
181
182 // If context is selected, return unless context matches
183 //
184 if ((select != 0) && (select != wcard))
185 {
186 if ( strcmp(select,context) ) { return; }
187 }
188
189 // Branch on Geant3 routine name
190 //
191 ofile << "Do routine " << routine << " in context " << context << G4endl;
192
193 if ( !strcmp(routine,"GSVOLU") ) { PG4gsvolu(&tokens[2]); return;}
194 if ( !strcmp(routine,"GSPOS") ) { PG4gspos (&tokens[2]); return;}
195 if ( !strcmp(routine,"GSPOSP") ) { PG4gsposp(&tokens[2]); return;}
196 if ( !strcmp(routine,"GSATT") ) { PG4gsatt (&tokens[2]); return;}
197 if ( !strcmp(routine,"GSROTM") ) { PG4gsrotm(&tokens[2]); return;}
198 if ( !strcmp(routine,"GSDVN") ) { PG4gsdvn (&tokens[2]); return;}
199 if ( !strcmp(routine,"GSDVT") ) { PG4gsdvt (&tokens[2]); return;}
200 if ( !strcmp(routine,"GSDVX") ) { PG4gsdvx (&tokens[2]); return;}
201 if ( !strcmp(routine,"GSDVN2") ) { PG4gsdvn2(&tokens[2]); return;}
202 if ( !strcmp(routine,"GSDVT2") ) { PG4gsdvt2(&tokens[2]); return;}
203 if ( !strcmp(routine,"GSMATE") ) { PG4gsmate(&tokens[2]); return;}
204 if ( !strcmp(routine,"GSMIXT") ) { PG4gsmixt(&tokens[2]); return;}
205 if ( !strcmp(routine,"GSTMED") ) { PG4gstmed(&tokens[2]); return;}
206 if ( !strcmp(routine,"GSTPAR") ) { PG4gstpar(&tokens[2]); return;}
207 if ( !strcmp(routine,"GSPART") ) { PG4gspart(&tokens[2]); return;}
208 if ( !strcmp(routine,"GSDK") ) { PG4gsdk (&tokens[2]); return;}
209 if ( !strcmp(routine,"GSDET") ) { PG4gsdet (&tokens[2]); return;}
210 if ( !strcmp(routine,"GSDETV") ) { PG4gsdetv(&tokens[2]); return;}
211 if ( !strcmp(routine,"GSDETA") ) { PG4gsdeta(&tokens[2]); return;}
212 if ( !strcmp(routine,"GSDETH") ) { PG4gsdeth(&tokens[2]); return;}
213 if ( !strcmp(routine,"GSDETD") ) { PG4gsdetd(&tokens[2]); return;}
214 if ( !strcmp(routine,"GSDETU") ) { PG4gsdetu(&tokens[2]); return;}
215 if ( !strcmp(routine,"GGCLOS") ) { PG4ggclos(); return;}
216}
217
218void G3fillParams(G4String *tokens, const char *ptypes)
219{
220 //
221 // G3fillParams
222 //
223 // Interpret tokens to fill call parameters, based on parameter types ptypes
224
225 // loop over ptypes
226 //
227 G4int i =0, ipt = 0, k = 0;
228 G4int ni =0, nr = 0, nq = 0;
229 while (ptypes[i] != '\0')
230 {
231 switch (ptypes[i])
232 {
233 case 'i':
234 Ipar[ni] = atoi(tokens[ipt].data());
235 narray = Ipar[ni];
236 ni++; ipt++;
237 break;
238 case 'r':
239 Rpar[nr] = atof(tokens[ipt].data());
240 nr++; ipt++;
241 break;
242 case 's':
243 Spar[nq] = tokens[ipt];
244 nq++; ipt++;
245 break;
246 case 'I':
247 for (k=0; k < narray; k++)
248 {
249 Ipar[ni] = atoi(tokens[ipt].data());
250 ni++; ipt++;
251 }
252 break;
253 case 'R':
254 for (k=0; k < narray; k++)
255 {
256 Rpar[nr] = atof(tokens[ipt].data());
257 nr++; ipt++;
258 }
259 break;
260 case 'Q':
261 // special case of reading three successive R arrays
262 // into one (used in gsmixt)
263 //
264 narray = 3 * std::abs(narray);
265 for (k=0; k < narray; k++)
266 {
267 Rpar[nr] = atof(tokens[ipt].data());
268 nr++; ipt++;
269 }
270 break;
271 case 'S':
272 for (k=0; k < narray; k++)
273 {
274 Spar[nq] = tokens[ipt];
275 nq++; ipt++;
276 }
277 break;
278 default:
279 ofile << "unidentified ptype '" << ptypes[i] << G4endl;
280 };
281 i++;
282 }
283}
std::vector< G4LogicalVolume * > G3SensVolVector
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G3MatTable G3Mat
Definition: clparse.cc:54
void PG4gsdk(G4String *tokens)
Definition: G4gsdk.cc:32
void PG4ggclos()
Definition: G4ggclos.cc:31
void PG4gsatt(G4String *tokens)
Definition: G4gsatt.cc:32
void G3CLEval(G4String *tokens, char *select)
G3SensVolVector G3SensVol
Definition: clparse.cc:60
void PG4gsdetd(G4String *tokens)
Definition: G4gsdetd.cc:33
void G3CLRead(G4String &fname, char *select=0)
Definition: clparse.cc:98
void PG4gsvolu(G4String *tokens)
Definition: G4gsvolu.cc:36
void PG4gsdeta(G4String *tokens)
Definition: G4gsdeta.cc:37
G4double Rpar[1000]
Definition: clparse.cc:66
void PG4gsrotm(G4String *tokens)
Definition: G4gsrotm.cc:34
G3PartTable G3Part
Definition: clparse.cc:57
G3EleTable G3Ele
Definition: clparse.cc:59
void PG4gsdvt2(G4String *tokens)
Definition: G4gsdvt2.cc:40
void PG4gsdeth(G4String *tokens)
Definition: G4gsdeth.cc:33
void PG4gsdvn2(G4String *tokens)
Definition: G4gsdvn2.cc:40
void PG4gsdvx(G4String *tokens)
Definition: G4gsdvx.cc:39
G4int narray
Definition: clparse.cc:63
G3MedTable G3Med
Definition: clparse.cc:55
void PG4gsmate(G4String *tokens)
Definition: G4gsmate.cc:41
void PG4gstmed(G4String *tokens)
Definition: G4gstmed.cc:43
G3RotTable G3Rot
Definition: clparse.cc:56
void PG4gsposp(G4String *tokens)
Definition: G4gsposp.cc:41
void G3fillParams(G4String *tokens, const char *ptypes)
Definition: clparse.cc:218
void PG4gsdetu(G4String *tokens)
Definition: G4gsdetu.cc:30
char gSeparator('_')
G4int G3CLTokens(G4String *line, G4String *tokens)
void PG4gsmixt(G4String *tokens)
Definition: G4gsmixt.cc:42
void PG4gspart(G4String *tokens)
Definition: G4gspart.cc:32
void PG4gspos(G4String *tokens)
Definition: G4gspos.cc:41
void PG4gsdvn(G4String *tokens)
Definition: G4gsdvn.cc:37
G4String Spar[1000]
Definition: clparse.cc:67
void PG4gstpar(G4String *tokens)
Definition: G4gstpar.cc:31
void PG4gsdvt(G4String *tokens)
Definition: G4gsdvt.cc:40
std::ofstream ofile
Definition: clparse.cc:44
G4int Ipar[1000]
Definition: clparse.cc:65
void PG4gsdetv(G4String *tokens)
Definition: G4gsdetv.cc:35
G3DetTable G3Det
Definition: clparse.cc:58
void PG4gsdet(G4String *tokens)
Definition: G4gsdet.cc:31
G3VolTable G3Vol
Definition: clparse.cc:53
std::istream & readline(std::istream &is, G4String &str, G4bool skipWhite=true)
Read characters into a G4String from an input stream until end-of-line.
context
Definition: g4zmq.py:11
string fname
Definition: test.py:308