[817] | 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 | // |
---|
[965] | 27 | // $Id: clparse.cc,v 1.19 2008/11/17 08:33:57 gcosmo Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
[817] | 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 | |
---|
| 46 | std::ofstream ofile; |
---|
| 47 | |
---|
[965] | 48 | extern "C" |
---|
| 49 | { |
---|
[817] | 50 | #include <stdlib.h> |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | extern std::ofstream ofile; |
---|
| 54 | |
---|
| 55 | G3VolTable G3Vol; |
---|
[965] | 56 | G3MatTable G3Mat; // material G3 ID <-> G4 pointer table |
---|
| 57 | G3MedTable G3Med; // trk media G3 ID <-> G4 pointer table |
---|
| 58 | G3RotTable G3Rot; // rotation ID <-> G4 transform object table |
---|
[817] | 59 | G3PartTable G3Part; // particle ID <-> ParticleDefinition pointer |
---|
[965] | 60 | G3DetTable G3Det; // sensitive detector name <-> pointer |
---|
| 61 | G3EleTable G3Ele; // element names table |
---|
[817] | 62 | G3SensVolVector G3SensVol; // vector of sensitive logical volumes |
---|
| 63 | char gSeparator('_'); |
---|
| 64 | |
---|
| 65 | G4int narray; |
---|
| 66 | |
---|
| 67 | G4int Ipar[1000]; |
---|
| 68 | G4double Rpar[1000]; |
---|
| 69 | G4String Spar[1000]; |
---|
| 70 | |
---|
| 71 | G4int G3CLTokens(G4String *line, G4String *tokens); |
---|
| 72 | void G3CLEval(G4String *tokens, char *select); |
---|
| 73 | |
---|
| 74 | // front-end decoders for G3 routines |
---|
[965] | 75 | // |
---|
[817] | 76 | void PG4gsvolu(G4String *tokens); |
---|
| 77 | void PG4gspos (G4String *tokens); |
---|
| 78 | void PG4gsposp(G4String *tokens); |
---|
| 79 | void PG4gsatt (G4String *tokens); |
---|
| 80 | void PG4gsrotm(G4String *tokens); |
---|
| 81 | void PG4gsdvn (G4String *tokens); |
---|
| 82 | void PG4gsdvt (G4String *tokens); |
---|
| 83 | void PG4gsdvx (G4String *tokens); |
---|
| 84 | void PG4gsdvn2(G4String *tokens); |
---|
| 85 | void PG4gsdvt2(G4String *tokens); |
---|
| 86 | void PG4gsmate(G4String *tokens); |
---|
| 87 | void PG4gsmixt(G4String *tokens); |
---|
| 88 | void PG4gstmed(G4String *tokens); |
---|
| 89 | void PG4gstpar(G4String *tokens); |
---|
| 90 | void PG4gspart(G4String *tokens); |
---|
| 91 | void PG4gsdk (G4String *tokens); |
---|
| 92 | void PG4gsdet (G4String *tokens); |
---|
| 93 | void PG4gsdetv(G4String *tokens); |
---|
| 94 | void PG4gsdeta(G4String *tokens); |
---|
| 95 | void PG4gsdeth(G4String *tokens); |
---|
| 96 | void PG4gsdetd(G4String *tokens); |
---|
| 97 | void PG4gsdetu(G4String *tokens); |
---|
| 98 | void PG4ggclos(); |
---|
| 99 | |
---|
[965] | 100 | void G3CLRead(G4String & fname, char *select = 0) |
---|
| 101 | { |
---|
| 102 | // |
---|
| 103 | // G3CLRead |
---|
| 104 | // Read the call List file, parse the tokens, and pass the token |
---|
| 105 | // List to the Geant4 interpreter |
---|
| 106 | // |
---|
| 107 | // fname: call List filename |
---|
[817] | 108 | |
---|
[965] | 109 | G4String line; |
---|
| 110 | G4String tokens[1000]; |
---|
[817] | 111 | |
---|
[965] | 112 | const char* ofname = "clparse.out"; |
---|
| 113 | ofile.open(ofname); |
---|
| 114 | ofile << "Output file open\n"; |
---|
[817] | 115 | |
---|
[965] | 116 | G4int count = 0; |
---|
| 117 | G4int ntokens = 0; |
---|
| 118 | std::ifstream istr(fname); |
---|
[817] | 119 | |
---|
[965] | 120 | while (line.readLine(istr) && ! istr.eof()) |
---|
| 121 | { |
---|
| 122 | count++; |
---|
| 123 | ntokens = G3CLTokens(&line,tokens); // tokenize the line |
---|
| 124 | for (G4int i=0; i < ntokens; i++) |
---|
| 125 | { |
---|
| 126 | ofile << tokens[i] << G4endl; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | // interpret the line as a Geant call |
---|
| 130 | // |
---|
| 131 | G3CLEval(tokens, select); |
---|
| 132 | } |
---|
[817] | 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | G4int G3CLTokens(G4String *line, G4String tokens[]) |
---|
| 137 | { |
---|
[965] | 138 | // |
---|
| 139 | // G3CLTokens |
---|
| 140 | // |
---|
| 141 | // Tokenize line, returning tokens in tokens[]. Items in ".." |
---|
| 142 | // are extracted as single tokens, despite embedded spaces. |
---|
| 143 | |
---|
[817] | 144 | G4Tokenizer next(*line); |
---|
[965] | 145 | |
---|
[817] | 146 | // first tokenize using " to identify strings |
---|
[965] | 147 | // |
---|
[817] | 148 | G4int itok = 0; |
---|
| 149 | G4int ntokens = 0; |
---|
| 150 | G4String token1, token2; |
---|
| 151 | while (!(token1=next("\"")).isNull()) |
---|
[965] | 152 | { |
---|
| 153 | itok++; |
---|
| 154 | if (itok%2 == 0 ) // even: inside a string |
---|
[817] | 155 | { |
---|
[965] | 156 | tokens[ntokens++] = token1; |
---|
[817] | 157 | } |
---|
[965] | 158 | else // not in a quoted string: finish tokenization |
---|
| 159 | { |
---|
| 160 | G4Tokenizer lev2(token1); |
---|
| 161 | while (!(token2=lev2()).isNull()) |
---|
| 162 | { |
---|
| 163 | tokens[ntokens] = token2; |
---|
| 164 | ntokens++; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | } |
---|
[817] | 168 | return ntokens; |
---|
| 169 | } |
---|
| 170 | |
---|
[965] | 171 | |
---|
[817] | 172 | void G3CLEval(G4String tokens[], char *select) |
---|
| 173 | { |
---|
[965] | 174 | // |
---|
| 175 | // G3CLEval |
---|
| 176 | // |
---|
| 177 | // Evaluate the token List as a Geant3 call, and execute it as |
---|
| 178 | // a Geant4 call. |
---|
| 179 | |
---|
[817] | 180 | const char* context = tokens[0]; |
---|
| 181 | const char* routine = tokens[1]; |
---|
[965] | 182 | const char* wcard = "*"; |
---|
[817] | 183 | |
---|
[965] | 184 | // If context is selected, return unless context matches |
---|
| 185 | // |
---|
| 186 | if ((select != 0) && (select != wcard)) |
---|
| 187 | { |
---|
| 188 | if ( strcmp(select,context) ) { return; } |
---|
| 189 | } |
---|
[817] | 190 | |
---|
| 191 | // Branch on Geant3 routine name |
---|
[965] | 192 | // |
---|
[817] | 193 | ofile << "Do routine " << routine << " in context " << context << G4endl; |
---|
| 194 | |
---|
[965] | 195 | if ( !strcmp(routine,"GSVOLU") ) { PG4gsvolu(&tokens[2]); return;} |
---|
[817] | 196 | if ( !strcmp(routine,"GSPOS") ) { PG4gspos (&tokens[2]); return;} |
---|
| 197 | if ( !strcmp(routine,"GSPOSP") ) { PG4gsposp(&tokens[2]); return;} |
---|
| 198 | if ( !strcmp(routine,"GSATT") ) { PG4gsatt (&tokens[2]); return;} |
---|
| 199 | if ( !strcmp(routine,"GSROTM") ) { PG4gsrotm(&tokens[2]); return;} |
---|
| 200 | if ( !strcmp(routine,"GSDVN") ) { PG4gsdvn (&tokens[2]); return;} |
---|
| 201 | if ( !strcmp(routine,"GSDVT") ) { PG4gsdvt (&tokens[2]); return;} |
---|
| 202 | if ( !strcmp(routine,"GSDVX") ) { PG4gsdvx (&tokens[2]); return;} |
---|
| 203 | if ( !strcmp(routine,"GSDVN2") ) { PG4gsdvn2(&tokens[2]); return;} |
---|
| 204 | if ( !strcmp(routine,"GSDVT2") ) { PG4gsdvt2(&tokens[2]); return;} |
---|
| 205 | if ( !strcmp(routine,"GSMATE") ) { PG4gsmate(&tokens[2]); return;} |
---|
| 206 | if ( !strcmp(routine,"GSMIXT") ) { PG4gsmixt(&tokens[2]); return;} |
---|
| 207 | if ( !strcmp(routine,"GSTMED") ) { PG4gstmed(&tokens[2]); return;} |
---|
| 208 | if ( !strcmp(routine,"GSTPAR") ) { PG4gstpar(&tokens[2]); return;} |
---|
| 209 | if ( !strcmp(routine,"GSPART") ) { PG4gspart(&tokens[2]); return;} |
---|
| 210 | if ( !strcmp(routine,"GSDK") ) { PG4gsdk (&tokens[2]); return;} |
---|
| 211 | if ( !strcmp(routine,"GSDET") ) { PG4gsdet (&tokens[2]); return;} |
---|
| 212 | if ( !strcmp(routine,"GSDETV") ) { PG4gsdetv(&tokens[2]); return;} |
---|
| 213 | if ( !strcmp(routine,"GSDETA") ) { PG4gsdeta(&tokens[2]); return;} |
---|
| 214 | if ( !strcmp(routine,"GSDETH") ) { PG4gsdeth(&tokens[2]); return;} |
---|
| 215 | if ( !strcmp(routine,"GSDETD") ) { PG4gsdetd(&tokens[2]); return;} |
---|
| 216 | if ( !strcmp(routine,"GSDETU") ) { PG4gsdetu(&tokens[2]); return;} |
---|
| 217 | if ( !strcmp(routine,"GGCLOS") ) { PG4ggclos(); return;} |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | void G3fillParams(G4String *tokens, const char *ptypes) |
---|
| 221 | { |
---|
[965] | 222 | // |
---|
| 223 | // G3fillParams |
---|
| 224 | // |
---|
| 225 | // Interpret tokens to fill call parameters, based on parameter types ptypes |
---|
| 226 | |
---|
[817] | 227 | // loop over ptypes |
---|
[965] | 228 | // |
---|
[817] | 229 | G4int i =0, ipt = 0, k = 0; |
---|
| 230 | G4int ni =0, nr = 0, ns = 0; |
---|
| 231 | while (ptypes[i] != '\0') |
---|
[965] | 232 | { |
---|
| 233 | switch (ptypes[i]) |
---|
[817] | 234 | { |
---|
| 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++) |
---|
[965] | 250 | { |
---|
| 251 | Ipar[ni] = atoi(tokens[ipt].data()); |
---|
| 252 | ni++; ipt++; |
---|
| 253 | } |
---|
[817] | 254 | break; |
---|
| 255 | case 'R': |
---|
| 256 | for (k=0; k < narray; k++) |
---|
[965] | 257 | { |
---|
| 258 | Rpar[nr] = atof(tokens[ipt].data()); |
---|
| 259 | nr++; ipt++; |
---|
| 260 | } |
---|
[817] | 261 | break; |
---|
| 262 | case 'Q': |
---|
| 263 | // special case of reading three successive R arrays |
---|
| 264 | // into one (used in gsmixt) |
---|
[965] | 265 | // |
---|
[817] | 266 | narray = 3 * std::abs(narray); |
---|
| 267 | for (k=0; k < narray; k++) |
---|
[965] | 268 | { |
---|
| 269 | Rpar[nr] = atof(tokens[ipt].data()); |
---|
| 270 | nr++; ipt++; |
---|
| 271 | } |
---|
[817] | 272 | break; |
---|
| 273 | case 'S': |
---|
| 274 | for (k=0; k < narray; k++) |
---|
[965] | 275 | { |
---|
| 276 | Spar[ns] = tokens[ipt]; |
---|
| 277 | ns++; ipt++; |
---|
| 278 | } |
---|
[817] | 279 | break; |
---|
| 280 | default: |
---|
| 281 | ofile << "unidentified ptype '" << ptypes[i] << G4endl; |
---|
[965] | 282 | }; |
---|
| 283 | i++; |
---|
| 284 | } |
---|
[817] | 285 | } |
---|