CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
ALIFileIn Class Reference

#include <ALIFileIn.h>

Public Member Functions

 ALIFileIn ()
 
void close ()
 
ALIbool eof ()
 
void ErrorInLine ()
 
ALIint getWordsInLine (std::vector< ALIstring > &wl)
 
const ALIstringname ()
 
const ALIint nline ()
 
 ~ALIFileIn ()
 

Static Public Member Functions

static ALIFileIngetInstance (const ALIstring &name)
 
static ALIFileIngetInstanceOpened (const ALIstring &name)
 

Private Member Functions

 ALIFileIn (const ALIstring &name)
 
void openNewFile (const char *filename)
 

Private Attributes

int theCurrentFile
 
std::vector< std::ifstream * > theFiles
 
std::vector< ALIinttheLineNo
 
ALIstring theName
 Name of file. More...
 
std::vector< ALIstringtheNames
 

Static Private Attributes

static std::vector< ALIFileIn * > theInstances
 

Detailed Description

Definition at line 21 of file ALIFileIn.h.

Constructor & Destructor Documentation

ALIFileIn::ALIFileIn ( )
inline

Definition at line 24 of file ALIFileIn.h.

Referenced by getInstance().

24 {};
ALIFileIn::~ALIFileIn ( )
inline

Definition at line 25 of file ALIFileIn.h.

25 {}
ALIFileIn::ALIFileIn ( const ALIstring name)
inlineprivate

Definition at line 27 of file ALIFileIn.h.

27 : theName(name){}
const ALIstring & name()
Definition: ALIFileIn.h:44
ALIstring theName
Name of file.
Definition: ALIFileIn.h:64

Member Function Documentation

void ALIFileIn::close ( )

Definition at line 236 of file ALIFileIn.cc.

References theCurrentFile, and theFiles.

Referenced by eof(), lumiQTWidget.ApplicationWindow::fileQuit(), Vispa.Gui.BoxContentDialog.BoxContentDialog::keyPressEvent(), Vispa.Gui.FindDialog.FindDialog::keyPressEvent(), and Model::readSystemDescription().

237 {
238  //- std::cout << " close " << theCurrentFile << " size " << theFiles.size() << std::endl;
239  /* if( theCurrentFile+1 != 0 ) {
240  ErrorInLine();
241  std::cerr << "trying to close file while reading other files included in it " << theCurrentFile+1 << std::endl;
242  // exit(0);
243  } else { */
244  theFiles[theCurrentFile+1]->close();
245  theFiles.pop_back();
246  // }
247 }
int theCurrentFile
Definition: ALIFileIn.h:57
std::vector< std::ifstream * > theFiles
Definition: ALIFileIn.h:53
ALIbool ALIFileIn::eof ( )

Definition at line 218 of file ALIFileIn.cc.

References close(), theCurrentFile, and theFiles.

Referenced by getWordsInLine(), DeviationsFromFileSensor2D::readFile(), Model::readMeasurementsFromFile(), and Model::readSystemDescription().

219 {
220  ALIbool isok = theFiles[theCurrentFile]->eof();
221  if( isok ) {
222  //std::cout << " eof theCurrentFile " << theCurrentFile << std::endl;
223  theCurrentFile--;
224  if( theCurrentFile != -1 ) close(); // last file will be closed by the user
225  }
226  //only real closing if all files are closed
227  //- std::cout << " eof " << isok << " " << theCurrentFile << std::endl;
228  if( theCurrentFile != -1 ) {
229  return 0;
230  } else {
231  return isok;
232  }
233 }
int theCurrentFile
Definition: ALIFileIn.h:57
bool ALIbool
Definition: CocoaGlobals.h:19
void close()
Definition: ALIFileIn.cc:236
std::vector< std::ifstream * > theFiles
Definition: ALIFileIn.h:53
void ALIFileIn::ErrorInLine ( )
ALIFileIn & ALIFileIn::getInstance ( const ALIstring name)
static

Definition at line 23 of file ALIFileIn.cc.

References ALIFileIn(), lut2db_cfg::filename, instance, openNewFile(), theCurrentFile, and theInstances.

Referenced by MeasurementDiffEntry::buildOptONamesList(), CocoaDaqReaderText::CocoaDaqReaderText(), Measurement::construct(), OpticalObject::construct(), Entry::fill(), OptOSensor2D::fillExtraEntry(), Entry::fillFromInputFileQuality(), Entry::fillFromInputFileSigma(), Entry::fillFromInputFileValue(), FittedEntriesReader::FittedEntriesReader(), getInstanceOpened(), ErrorCorrelationMgr::readFromReportFile(), Model::readMeasurementsFromFile(), and Model::readSystemDescription().

24 {
25  std::vector<ALIFileIn*>::const_iterator vfcite;
26  for( vfcite = theInstances.begin(); vfcite != theInstances.end(); vfcite++) {
27  if( (*vfcite)->name() == filename) {
28  return *(*vfcite);
29  }
30  }
31 
32  ALIFileIn* instance = 0;
33  if( vfcite == theInstances.end() ) {
34  instance = new ALIFileIn( filename );
35 
36  instance->theCurrentFile = -1;
37  instance->openNewFile( filename.c_str() );
38 
39  theInstances.push_back( instance );
40  }
41 
42  return *instance;
43 
44 }
static std::vector< ALIFileIn * > theInstances
Definition: ALIFileIn.h:61
static PFTauRenderPlugin instance
int theCurrentFile
Definition: ALIFileIn.h:57
tuple filename
Definition: lut2db_cfg.py:20
void openNewFile(const char *filename)
Definition: ALIFileIn.cc:48
ALIFileIn()
Definition: ALIFileIn.h:24
ALIFileIn & ALIFileIn::getInstanceOpened ( const ALIstring name)
static

Definition at line 73 of file ALIFileIn.cc.

References dtNoiseDBValidation_cfg::cerr, cmsRelvalreport::exit, lut2db_cfg::filename, getInstance(), and name().

74 {
76  if (filein.name() != filename ) {
77  std::cerr << "Error: file not opened yet " << filename << std::endl;
78  exit(0);
79  } else {
80  return filein;
81  }
82 }
const ALIstring & name()
Definition: ALIFileIn.h:44
static ALIFileIn & getInstance(const ALIstring &name)
Definition: ALIFileIn.cc:23
tuple filename
Definition: lut2db_cfg.py:20
ALIint ALIFileIn::getWordsInLine ( std::vector< ALIstring > &  wl)

Definition at line 90 of file ALIFileIn.cc.

References dtNoiseDBValidation_cfg::cerr, comment, eof(), ErrorInLine(), cmsRelvalreport::exit, openNewFile(), theCurrentFile, theFiles, theLineNo, and groupFilesInBlocks::tt.

Referenced by Measurement::construct(), OpticalObject::createComponentOptOs(), OptOSensor2D::fillExtraEntry(), FittedEntriesReader::FittedEntriesReader(), OpticalObject::readCoordinates(), OpticalObject::readData(), OpticalObject::readExtraEntries(), DeviationsFromFileSensor2D::readFile(), FittedEntriesReader::readFittedEntriesFromFile(), ErrorCorrelationMgr::readFromReportFile(), Model::readMeasurementsFromFile(), and Model::readSystemDescription().

91 {
92  ALIint isok = 1;
93 
94  //---------- Read a line of file:
95  //@@@@--- Cannot be read with a istream_iterator, becasuse it uses std::cout, and then doesn't read '\n'
96  //----- Clear wordlist
97  ALIint wsiz = wordlist.size();
98  ALIint ii;
99  for (ii = 0; ii < wsiz; ii++) {
100  wordlist.pop_back();
101  }
102 
103  //---------- Loop lines while there is an ending '\' or line is blank
104  const ALIint NMAXLIN = 1000;
105  char ltemp[NMAXLIN]; //there won't be lines longer than NMAXLIN characters
106  for (;;) {
108  for( ii = 0; ii < NMAXLIN; ii++) ltemp[ii] = ' ';
109  theFiles[theCurrentFile]->getline( ltemp, NMAXLIN );
110  //---------- Check for lines longer than NMAXLIN character
111  ALIint ii;
112  for ( ii=0; ii < NMAXLIN; ii++) {
113  if ( ltemp[ii] == '\0' ) break;
114  }
115  if ( ii == NMAXLIN-1 ) {
116  ErrorInLine();
117  std::cerr << "!!!! line longer than " << NMAXLIN << " characters" <<
118  std::endl << " please split it putting a '\\' at the end of line" << std::endl;
119  exit(0);
120  }
121 
122  //---------- End of file
123  //- if ( theFiles[theCurrentFile]->eof() ) {
124  if ( eof() ) {
125  //t exit(0);
126  return 0;
127  }
128 
129  //---------- Convert line read to istrstream to split it in words
130  std::istrstream istr_line(ltemp);
131 
132  //--------- count how many words are there in ltemp (this sohuld not be needed, but sun compiler has problems) !! this has to be nvestigated...
133  ALIint NoWords = 0;
134  char* tt = ltemp;
135  ALIstring stemp(ltemp);
136  do{
137  if( *tt != ' ' && *(tt) != '\0' ) {
138  if( tt == ltemp) {
139  NoWords++;
140  // std::cout << "dNoWords" << NoWords << ltemp << std::endl;
141  } else if( *(tt-1) == ' ' || *(tt-1) == '\015' || *(tt-1) == '\t') {
142  NoWords++;
143  // std::cout << "NoWords" << NoWords << ltemp << std::endl;
144  }
145  }
146  tt++;
147  }while(*tt != '\0' && stemp.length()!=0);
148  ALIstring stempt (ltemp);
149  if(stempt.length() == 0) NoWords = 0;
150 
151  //--------- Read words from istr_line and write them into wordlist
152  // ALIint stre = 1;
153  for( ii=0; ii < NoWords; ii++) {
154  ALIstring stemp = "";
155  istr_line >> stemp; //?? gives warning in Insure++
156  if ( stemp.length() == 0 ) break;
157  ALIint comment = stemp.find(ALIstring("//") );
158  // std::cout << "!!!COMMENT" << comment << stemp.c_str() << std::endl;
159  if ( comment == 0 ) {
160  break;
161  } else if ( comment > 0 ) {
162  stemp = stemp.substr( 0, comment );
163  wordlist.push_back(stemp);
164  break;
165  //- for( int jj=0; jj < stemp.length()-comment; jj++) stemp.pop_back();
166  }
167  wordlist.push_back(stemp);
168  }
169 
170  //These two algorithms should be the more STL-like way, but they don't work for files whose lines end without '\015'=TAB (STL problem: doesn't find end of string??)
171  // istream_iterator<ALIstring, ptrdiff_t> ALIstring_iter(istr_line);
172  // istream_iterator<ALIstring, ptrdiff_t> eosl;
173  // copy(ALIstring_iter, eosl, back_inserter(wordlist));
174  // typedef istream_iterator<ALIstring, ptrdiff_t> ALIstring_iter;
175  // copy(ALIstring_iter(istr_line), ALIstring_iter(), back_inserter(wordlist));
176 
177  if ( wordlist.size() != 0 ) {
178  if( (*(wordlist.end()-1)).compare("\\") == 0 ) { //use '\' to mark continuing line
179  wordlist.pop_back();
180  } else {
181  break;
182  }
183  }
184  }
185 
186  //or why not like this?:
187  //typedef istream_iterator<ALIstring, ptrdiff_t> string_iter;
188  //copy(string_iter(istr_line), string_iter(), back_inserter(wordlist));
189 
190  //- std::cout << " checking for include " << wordlist[0] << std::endl;
191  // check if including a new file
192  if( wordlist[0] == "#include" ) {
193  if( wordlist.size() != 2 ) {
194  ErrorInLine();
195  std::cerr << "'#include' should have as second argument the filename " << std::endl;
196  exit(0);
197  }
198  //- std::cout << "include found " << std::endl;
199  openNewFile( wordlist[1].c_str() );
200  isok = getWordsInLine( wordlist);
201 
202  }
203 
204  return isok;
205 }
ALIbool eof()
Definition: ALIFileIn.cc:218
int ALIint
Definition: CocoaGlobals.h:15
std::vector< ALIint > theLineNo
Definition: ALIFileIn.h:55
int theCurrentFile
Definition: ALIFileIn.h:57
ALIint getWordsInLine(std::vector< ALIstring > &wl)
Definition: ALIFileIn.cc:90
void ErrorInLine()
Definition: ALIFileIn.cc:211
std::string ALIstring
Definition: CocoaGlobals.h:9
void openNewFile(const char *filename)
Definition: ALIFileIn.cc:48
std::vector< std::ifstream * > theFiles
Definition: ALIFileIn.h:53
#define comment(par)
Definition: vmac.h:162
const ALIstring& ALIFileIn::name ( )
inline
const ALIint ALIFileIn::nline ( )
inline

Definition at line 42 of file ALIFileIn.h.

References theCurrentFile, and theLineNo.

Referenced by Model::readSystemDescription().

42 { return theLineNo[theCurrentFile]; }
std::vector< ALIint > theLineNo
Definition: ALIFileIn.h:55
int theCurrentFile
Definition: ALIFileIn.h:57
void ALIFileIn::openNewFile ( const char *  filename)
private

Definition at line 48 of file ALIFileIn.cc.

References dtNoiseDBValidation_cfg::cerr, cmsRelvalreport::exit, groupFilesInBlocks::fin, theCurrentFile, theFiles, theLineNo, and theNames.

Referenced by getInstance(), and getWordsInLine().

49 {
51  std::ifstream* fin = new std::ifstream(filename);
52  theFiles.push_back(fin);
53 
54  //- ALIint lineno = new ALIint;
55  //- ALIint lineno = 0;
56  theLineNo.push_back( 0 );
57 
58  theNames.push_back( filename );
59 
60 #ifndef OS_SUN_4_2
61  if( !fin->is_open()) {
62  std::cerr << "!!!! Input file does not exist: " << filename << std::endl;
63  exit(1);
64  }
65 #endif
66 }
std::vector< ALIstring > theNames
Definition: ALIFileIn.h:56
std::vector< ALIint > theLineNo
Definition: ALIFileIn.h:55
int theCurrentFile
Definition: ALIFileIn.h:57
tuple filename
Definition: lut2db_cfg.py:20
std::vector< std::ifstream * > theFiles
Definition: ALIFileIn.h:53

Member Data Documentation

int ALIFileIn::theCurrentFile
private

Definition at line 57 of file ALIFileIn.h.

Referenced by close(), eof(), ErrorInLine(), getInstance(), getWordsInLine(), nline(), and openNewFile().

std::vector< std::ifstream* > ALIFileIn::theFiles
private

Definition at line 53 of file ALIFileIn.h.

Referenced by close(), eof(), getWordsInLine(), and openNewFile().

std::vector< ALIFileIn * > ALIFileIn::theInstances
staticprivate

Definition at line 61 of file ALIFileIn.h.

Referenced by getInstance().

std::vector<ALIint> ALIFileIn::theLineNo
private

Definition at line 55 of file ALIFileIn.h.

Referenced by ErrorInLine(), getWordsInLine(), nline(), and openNewFile().

ALIstring ALIFileIn::theName
private

Name of file.

Definition at line 64 of file ALIFileIn.h.

Referenced by twikiExport.Constituent::__str__(), twikiExport.Material::__str__(), and name().

std::vector<ALIstring> ALIFileIn::theNames
private

Definition at line 56 of file ALIFileIn.h.

Referenced by ErrorInLine(), and openNewFile().