47 G4ThreadLocal std::vector<G4tgrFileIn*> *G4tgrFileIn::theInstances = 0;
51 : theCurrentFile(-1), theName(
"")
53 if (!theInstances) { theInstances =
new std::vector<G4tgrFileIn*>; }
60 delete theInstances; theInstances=0;
74 if (!theInstances) { theInstances =
new std::vector<G4tgrFileIn*>; }
76 std::vector<G4tgrFileIn*>::const_iterator vfcite;
77 for( vfcite = theInstances->begin(); vfcite != theInstances->end(); vfcite++)
79 if( (*vfcite)->GetName() == filename)
86 if( vfcite == theInstances->end() )
90 instance->theCurrentFile = -1;
93 theInstances->push_back( instance );
104 std::ifstream* fin =
new std::ifstream(filename);
105 theFiles.push_back(fin);
107 theLineNo.push_back( 0 );
109 theNames.push_back( filename );
112 if( !fin->is_open() )
126 if (filein.
GetName() != filename )
128 G4String ErrMessage =
"File not opened yet: " + filename;
149 G4int wsiz = wordlist.size();
151 for (ii = 0; ii < wsiz; ii++)
157 const G4int NMAXLIN = 1000;
161 (theLineNo[theCurrentFile])++;
162 for ( ii = 0; ii < NMAXLIN; ii++) { ltemp[ii] =
' '; }
163 theFiles[theCurrentFile]->getline( ltemp, NMAXLIN );
166 for ( ii=0; ii < NMAXLIN; ii++)
168 if ( ltemp[ii] ==
'\0' ) {
break; }
170 if ( ii == NMAXLIN-1 )
173 G4String ErrMessage =
"Too long line. Please split it "
174 +
G4String(
"putting a '\\' at the end!");
175 G4Exception(
"G4tgrFileIn::GetWordsInLine()",
"InvalidInput",
186 std::istringstream istr_line(ltemp);
196 if( *tt !=
' ' && *(tt) !=
'\0' )
204 G4cout <<
"G4tgrFileIn::GetWordsInLine() - NoWords"
205 << NoWords << ltemp <<
G4endl;
209 else if( *(tt-1) ==
' ' || *(tt-1) ==
'\015' || *(tt-1) ==
'\t')
215 G4cout <<
"G4tgrFileIn::GetWordsInLine() - NoWords"
216 << NoWords << ltemp <<
G4endl;
222 }
while((*tt !=
'\0') && (stemp.length()!=0));
224 if(stemp.length() == 0) { NoWords = 0; }
227 for( ii=0; ii < NoWords; ii++)
231 if ( stemp.length() == 0 ) {
break; }
236 G4cout <<
"!!!COMMENT" << comment << stemp.c_str() <<
G4endl;
243 else if ( comment > 0 )
245 stemp = stemp.substr( 0, comment );
246 wordlist.push_back(stemp);
249 wordlist.push_back(stemp);
261 if ( wordlist.size() != 0 )
263 if( (*(wordlist.end()-1)).compare(
"\\") == 0 )
276 std::vector<G4String> wordlist2;
278 unsigned int imerge = 0;
279 for(
size_t jj = 0; jj < wordlist.size(); jj++)
281 if( wordlist[jj].substr(0,1) ==
"\"" )
285 if( wordlist[jj][ wordlist[jj].size()-1 ] ==
'\"' )
289 G4String err1 =
" word with trailing '\"' while there is no";
290 G4String err2 =
" previous word with leading '\"' in line ";
298 wordlist2.push_back( wordlist[jj] );
300 else if( imerge == 1 )
304 wordq.
append( wordlist[jj].substr(1,wordlist[jj].size()) );
308 wordq.
append( wordlist[jj].substr(0,wordlist[jj].size()) );
312 else if( imerge == 2 )
316 wordq.
append( wordlist[jj].substr(1,wordlist[jj].size()-2));
320 wordq.
append( wordlist[jj].substr(0,wordlist[jj].size()-1) );
322 wordlist2.push_back( wordq );
329 G4String err1 =
" word with leading '\"' in line while there is no";
330 G4String err2 =
" later word with trailing '\"' in line ";
335 wordlist = wordlist2;
342 if( wordlist[0] ==
"#include" )
344 if( wordlist.size() != 2 )
348 =
"'#include' should have as second argument, the filename !";
349 G4Exception(
"G4tgrFileIn::GetWordsInLine()",
"InvalidInput",
356 G4cout <<
" G4tgrFileIn::GetWordsInLine() - Include found !" <<
G4endl;
370 G4cerr <<
"!! EXITING: ERROR IN LINE No "
371 << theLineNo[theCurrentFile] <<
" file: "
372 << theNames[theCurrentFile] <<
" : ";
379 G4bool isok = theFiles[theCurrentFile]->eof();
385 G4cout <<
" G4tgrFileIn::EndOfFile() - EOF: "
386 << theCurrentFile <<
G4endl;
390 if( theCurrentFile != -1 )
400 G4cout <<
" G4tgrFileIn::EndOfFile() - EOF: "
401 << isok <<
" " << theCurrentFile <<
G4endl;
404 if( theCurrentFile != -1 )
421 G4cout <<
"G4tgrFileIn::Close() - "
422 << theCurrentFile <<
", size " << theFiles.size() <<
G4endl;
426 theFiles[theCurrentFile+1]->close();
434 G4String Err1 = sent +
" in file " + theName;
438 G4Exception(
"G4tgrFileIn::DumpException()",
"FileError",
G4int GetWordsInLine(std::vector< G4String > &wl)
static G4tgrFileIn & GetInstanceOpened(const G4String &name)
static G4String ConvertToString(G4bool boolVal)
static G4tgrFileIn & GetInstance(const G4String &name)
G4GLOB_DLL std::ostream G4cout
static G4int GetVerboseLevel()
void DumpException(const G4String &sent)
const G4String & GetName()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
void OpenNewFile(const char *filename)
G4String & append(const G4String &)
G4GLOB_DLL std::ostream G4cerr