CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 20 of file ALIFileIn.h.

Constructor & Destructor Documentation

ALIFileIn::ALIFileIn ( )
inline

Definition at line 22 of file ALIFileIn.h.

Referenced by getInstance().

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

Definition at line 23 of file ALIFileIn.h.

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

Definition at line 26 of file ALIFileIn.h.

26 : theName(name) {}
const ALIstring & name()
Definition: ALIFileIn.h:43
ALIstring theName
Name of file.
Definition: ALIFileIn.h:63

Member Function Documentation

void ALIFileIn::close ( )

Definition at line 218 of file ALIFileIn.cc.

References theCurrentFile, and theFiles.

Referenced by eof(), esMonitoring.AsyncLineReaderMixin::handle_close(), esMonitoring.FDJsonServer::handle_close(), and Model::readSystemDescription().

218  {
219  //- std::cout << " close " << theCurrentFile << " size " << theFiles.size() << std::endl;
220  /* if( theCurrentFile+1 != 0 ) {
221  ErrorInLine();
222  std::cerr << "trying to close file while reading other files included in it " << theCurrentFile+1 << std::endl;
223  // exit(0);
224  } else { */
225  theFiles[theCurrentFile + 1]->close();
226  theFiles.pop_back();
227  // }
228 }
int theCurrentFile
Definition: ALIFileIn.h:56
std::vector< std::ifstream * > theFiles
Definition: ALIFileIn.h:52
ALIbool ALIFileIn::eof ( )

Definition at line 201 of file ALIFileIn.cc.

References close(), theCurrentFile, and theFiles.

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

201  {
202  ALIbool isok = theFiles[theCurrentFile]->eof();
203  if (isok) {
204  //std::cout << " eof theCurrentFile " << theCurrentFile << std::endl;
205  theCurrentFile--;
206  if (theCurrentFile != -1)
207  close(); // last file will be closed by the user
208  }
209  //only real closing if all files are closed
210  //- std::cout << " eof " << isok << " " << theCurrentFile << std::endl;
211  if (theCurrentFile != -1) {
212  return false;
213  } else {
214  return isok;
215  }
216 }
int theCurrentFile
Definition: ALIFileIn.h:56
bool ALIbool
Definition: CocoaGlobals.h:19
void close()
Definition: ALIFileIn.cc:218
std::vector< std::ifstream * > theFiles
Definition: ALIFileIn.h:52
void ALIFileIn::ErrorInLine ( )
ALIFileIn & ALIFileIn::getInstance ( const ALIstring name)
static

Definition at line 22 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().

22  {
23  for (auto vfc : theInstances) {
24  if (vfc->name() == filename) {
25  return *vfc;
26  }
27  }
28 
30  instance->theCurrentFile = -1;
31  instance->openNewFile(filename.c_str());
32  theInstances.push_back(instance);
33 
34  return *instance;
35 }
static std::vector< ALIFileIn * > theInstances
Definition: ALIFileIn.h:60
static PFTauRenderPlugin instance
int theCurrentFile
Definition: ALIFileIn.h:56
tuple filename
Definition: lut2db_cfg.py:20
void openNewFile(const char *filename)
Definition: ALIFileIn.cc:38
ALIFileIn()
Definition: ALIFileIn.h:22
ALIFileIn & ALIFileIn::getInstanceOpened ( const ALIstring name)
static

Definition at line 60 of file ALIFileIn.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, beamvalidation::exit(), lut2db_cfg::filename, getInstance(), and name().

60  {
62  if (filein.name() != filename) {
63  std::cerr << "Error: file not opened yet " << filename << std::endl;
64  exit(0);
65  } else {
66  return filein;
67  }
68 }
const ALIstring & name()
Definition: ALIFileIn.h:43
static ALIFileIn & getInstance(const ALIstring &name)
Definition: ALIFileIn.cc:22
tuple filename
Definition: lut2db_cfg.py:20
ALIint ALIFileIn::getWordsInLine ( std::vector< ALIstring > &  wl)

Definition at line 74 of file ALIFileIn.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, eof(), ErrorInLine(), beamvalidation::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().

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

Definition at line 41 of file ALIFileIn.h.

References theCurrentFile, and theLineNo.

Referenced by Model::readSystemDescription().

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

Definition at line 38 of file ALIFileIn.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, beamvalidation::exit(), groupFilesInBlocks::fin, theCurrentFile, theFiles, theLineNo, and theNames.

Referenced by getInstance(), and getWordsInLine().

38  {
40  std::ifstream* fin = new std::ifstream(filename);
41  theFiles.push_back(fin);
42 
43  //- ALIint lineno = new ALIint;
44  //- ALIint lineno = 0;
45  theLineNo.push_back(0);
46 
47  theNames.push_back(filename);
48 
49 #ifndef OS_SUN_4_2
50  if (!fin->is_open()) {
51  std::cerr << "!!!! Input file does not exist: " << filename << std::endl;
52  exit(1);
53  }
54 #endif
55 }
std::vector< ALIstring > theNames
Definition: ALIFileIn.h:55
std::vector< ALIint > theLineNo
Definition: ALIFileIn.h:54
int theCurrentFile
Definition: ALIFileIn.h:56
std::vector< std::ifstream * > theFiles
Definition: ALIFileIn.h:52
tuple filename
Definition: lut2db_cfg.py:20

Member Data Documentation

int ALIFileIn::theCurrentFile
private

Definition at line 56 of file ALIFileIn.h.

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

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

Definition at line 52 of file ALIFileIn.h.

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

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

Definition at line 60 of file ALIFileIn.h.

Referenced by getInstance().

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

Definition at line 54 of file ALIFileIn.h.

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

ALIstring ALIFileIn::theName
private

Name of file.

Definition at line 63 of file ALIFileIn.h.

Referenced by name().

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

Definition at line 55 of file ALIFileIn.h.

Referenced by ErrorInLine(), and openNewFile().