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 229 of file ALIFileIn.cc.

References theCurrentFile, and theFiles.

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

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

Definition at line 211 of file ALIFileIn.cc.

References close(), theCurrentFile, and theFiles.

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

212 {
213  ALIbool isok = theFiles[theCurrentFile]->eof();
214  if( isok ) {
215  //std::cout << " eof theCurrentFile " << theCurrentFile << std::endl;
216  theCurrentFile--;
217  if( theCurrentFile != -1 ) close(); // last file will be closed by the user
218  }
219  //only real closing if all files are closed
220  //- std::cout << " eof " << isok << " " << theCurrentFile << std::endl;
221  if( theCurrentFile != -1 ) {
222  return 0;
223  } else {
224  return isok;
225  }
226 }
int theCurrentFile
Definition: ALIFileIn.h:57
bool ALIbool
Definition: CocoaGlobals.h:19
void close()
Definition: ALIFileIn.cc:229
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  for (auto vfc : theInstances) {
26  if( vfc->name() == filename) {
27  return *vfc;
28  }
29  }
30 
32  instance->theCurrentFile = -1;
33  instance->openNewFile(filename.c_str());
34  theInstances.push_back(instance);
35 
36  return *instance;
37 }
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:41
ALIFileIn()
Definition: ALIFileIn.h:24
ALIFileIn & ALIFileIn::getInstanceOpened ( const ALIstring name)
static

Definition at line 66 of file ALIFileIn.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, cmsRelvalreport::exit, lut2db_cfg::filename, getInstance(), and name().

67 {
69  if (filein.name() != filename ) {
70  std::cerr << "Error: file not opened yet " << filename << std::endl;
71  exit(0);
72  } else {
73  return filein;
74  }
75 }
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 83 of file ALIFileIn.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, comment, eof(), ErrorInLine(), cmsRelvalreport::exit, cuy::ii, 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().

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

References ecal_dqm_sourceclient-live_cfg::cerr, cmsRelvalreport::exit, groupFilesInBlocks::fin, theCurrentFile, theFiles, theLineNo, and theNames.

Referenced by getInstance(), and getWordsInLine().

42 {
44  std::ifstream* fin = new std::ifstream(filename);
45  theFiles.push_back(fin);
46 
47  //- ALIint lineno = new ALIint;
48  //- ALIint lineno = 0;
49  theLineNo.push_back( 0 );
50 
51  theNames.push_back( filename );
52 
53 #ifndef OS_SUN_4_2
54  if( !fin->is_open()) {
55  std::cerr << "!!!! Input file does not exist: " << filename << std::endl;
56  exit(1);
57  }
58 #endif
59 }
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().