42G4ThreadLocal std::vector<G4tgrFileIn*>* G4tgrFileIn::theInstances =
nullptr;
47 if(theInstances ==
nullptr)
49 theInstances =
new std::vector<G4tgrFileIn*>;
57 theInstances =
nullptr;
70 if(theInstances ==
nullptr)
72 theInstances =
new std::vector<G4tgrFileIn*>;
75 std::vector<G4tgrFileIn*>::const_iterator vfcite;
76 for(vfcite = theInstances->cbegin(); vfcite != theInstances->cend(); ++vfcite)
78 if((*vfcite)->GetName() == filename)
85 if(vfcite == theInstances->cend())
89 instance->theCurrentFile = -1;
92 theInstances->push_back(instance);
102 std::ifstream* fin =
new std::ifstream(filename);
103 theFiles.push_back(fin);
105 theLineNo.push_back(0);
107 theNames.push_back(filename);
123 if(filein.
GetName() != filename)
125 G4String ErrMessage =
"File not opened yet: " + filename;
126 G4Exception(
"G4tgrFileIn::GetInstanceOpened()",
"InvalidInput",
145 G4int wsiz = wordlist.size();
147 for(ii = 0; ii < wsiz; ++ii)
153 const G4int NMAXLIN = 1000;
157 (theLineNo[theCurrentFile])++;
158 for(ii = 0; ii < NMAXLIN; ++ii)
162 theFiles[theCurrentFile]->getline(ltemp, NMAXLIN);
165 for(ii = 0; ii < NMAXLIN; ++ii)
167 if(ltemp[ii] ==
'\0')
172 if(ii == NMAXLIN - 1)
175 G4String ErrMessage =
"Too long line. Please split it " +
176 G4String(
"putting a '\\' at the end!");
177 G4Exception(
"G4tgrFileIn::GetWordsInLine()",
"InvalidInput",
188 std::istringstream istr_line(ltemp);
198 if(*tt !=
' ' && *(tt) !=
'\0')
206 G4cout <<
"G4tgrFileIn::GetWordsInLine() - NoWords" << NoWords
211 else if(*(tt - 1) ==
' ' || *(tt - 1) ==
'\015' || *(tt - 1) ==
'\t')
217 G4cout <<
"G4tgrFileIn::GetWordsInLine() - NoWords" << NoWords
224 }
while((*tt !=
'\0') && (stemp.length() != 0));
226 if(stemp.length() == 0)
232 for(ii = 0; ii < NoWords; ++ii)
236 if(stemp.length() == 0)
244 G4cout <<
"!!!COMMENT" << comment << stemp.c_str() <<
G4endl;
253 stemp = stemp.substr(0, comment);
254 wordlist.push_back(stemp);
257 wordlist.push_back(stemp);
269 if(wordlist.size() != 0)
271 if((*(wordlist.end() - 1)).compare(
"\\") == 0)
284 std::vector<G4String> wordlist2;
286 unsigned int imerge = 0;
287 for(std::size_t jj = 0; jj < wordlist.size(); ++jj)
289 if(wordlist[jj].substr(0, 1) ==
"\"")
293 if(wordlist[jj][wordlist[jj].size() - 1] ==
'\"')
297 G4String err1 =
" word with trailing '\"' while there is no";
298 G4String err2 =
" previous word with leading '\"' in line ";
306 wordlist2.push_back(wordlist[jj]);
312 wordq.
append(wordlist[jj].substr(1, wordlist[jj].size()));
316 wordq.
append(wordlist[jj].substr(0, wordlist[jj].size()));
324 wordq.
append(wordlist[jj].substr(1, wordlist[jj].size() - 2));
328 wordq.
append(wordlist[jj].substr(0, wordlist[jj].size() - 1));
330 wordlist2.push_back(wordq);
337 G4String err1 =
" word with leading '\"' in line while there is no";
338 G4String err2 =
" later word with trailing '\"' in line ";
343 wordlist = wordlist2;
350 if(wordlist[0] ==
"#include")
352 if(wordlist.size() != 2)
356 "'#include' should have as second argument, the filename !";
357 G4Exception(
"G4tgrFileIn::GetWordsInLine()",
"InvalidInput",
364 G4cout <<
" G4tgrFileIn::GetWordsInLine() - Include found !" <<
G4endl;
377 G4cerr <<
"!! EXITING: ERROR IN LINE No " << theLineNo[theCurrentFile]
378 <<
" file: " << theNames[theCurrentFile] <<
" : ";
384 G4bool isok = theFiles[theCurrentFile]->eof();
390 G4cout <<
" G4tgrFileIn::EndOfFile() - EOF: " << theCurrentFile <<
G4endl;
394 if(theCurrentFile != -1)
404 G4cout <<
" G4tgrFileIn::EndOfFile() - EOF: " << isok <<
" "
405 << theCurrentFile <<
G4endl;
408 if(theCurrentFile != -1)
424 G4cout <<
"G4tgrFileIn::Close() - " << theCurrentFile <<
", size "
425 << theFiles.size() <<
G4endl;
429 theFiles[theCurrentFile + 1]->close();
436 G4String Err1 = sent +
" in file " + theName;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4String & append(const G4String &)
static G4String ConvertToString(G4bool boolVal)
void OpenNewFile(const char *filename)
const G4String & GetName()
G4int GetWordsInLine(std::vector< G4String > &wl)
static G4tgrFileIn & GetInstanceOpened(const G4String &name)
static G4tgrFileIn & GetInstance(const G4String &name)
void DumpException(const G4String &sent)
static G4int GetVerboseLevel()