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