CMS 3D CMS Logo

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() [1/2]

ALIFileIn::ALIFileIn ( )
inline

Definition at line 22 of file ALIFileIn.h.

Referenced by getInstance().

22 {}

◆ ~ALIFileIn()

ALIFileIn::~ALIFileIn ( )
inline

Definition at line 23 of file ALIFileIn.h.

23 {}

◆ ALIFileIn() [2/2]

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

◆ close()

void ALIFileIn::close ( )

Definition at line 217 of file ALIFileIn.cc.

References theCurrentFile, and theFiles.

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

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

◆ eof()

ALIbool ALIFileIn::eof ( )

Definition at line 200 of file ALIFileIn.cc.

References close(), theCurrentFile, and theFiles.

Referenced by getWordsInLine(), and DeviationsFromFileSensor2D::readFile().

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

◆ ErrorInLine()

void ALIFileIn::ErrorInLine ( )

Definition at line 195 of file ALIFileIn.cc.

References DMR_cfg::cerr, theCurrentFile, theLineNo, and theNames.

Referenced by MeasurementDiffEntry::buildOptONamesList(), Entry::fill(), Entry::fillFromInputFileQuality(), Entry::fillFromInputFileSigma(), Entry::fillFromInputFileValue(), getWordsInLine(), and Model::readSystemDescription().

195  {
196  std::cerr << "!! EXITING: ERROR IN LINE No " << theLineNo[theCurrentFile] << " file: " << theNames[theCurrentFile]
197  << " : ";
198 }
std::vector< ALIstring > theNames
Definition: ALIFileIn.h:55
std::vector< ALIint > theLineNo
Definition: ALIFileIn.h:54
int theCurrentFile
Definition: ALIFileIn.h:56

◆ getInstance()

ALIFileIn & ALIFileIn::getInstance ( const ALIstring name)
static

◆ getInstanceOpened()

ALIFileIn & ALIFileIn::getInstanceOpened ( const ALIstring name)
static

Definition at line 59 of file ALIFileIn.cc.

References DMR_cfg::cerr, beamvalidation::exit(), ConfigBuilder::filein, corrVsCorr::filename, and getInstance().

59  {
61  if (filein.name() != filename) {
62  std::cerr << "Error: file not opened yet " << filename << std::endl;
63  exit(0);
64  } else {
65  return filein;
66  }
67 }
static ALIFileIn & getInstance(const ALIstring &name)
Definition: ALIFileIn.cc:21
def exit(msg="")

◆ getWordsInLine()

ALIint ALIFileIn::getWordsInLine ( std::vector< ALIstring > &  wl)

Definition at line 73 of file ALIFileIn.cc.

References DMR_cfg::cerr, eof(), ErrorInLine(), beamvalidation::exit(), cuy::ii, openNewFile(), theCurrentFile, theFiles, and theLineNo.

Referenced by OptOSensor2D::fillExtraEntry(), FittedEntriesReader::FittedEntriesReader(), DeviationsFromFileSensor2D::readFile(), and FittedEntriesReader::readFittedEntriesFromFile().

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

◆ name()

const ALIstring& ALIFileIn::name ( )
inline

Definition at line 43 of file ALIFileIn.h.

References theName.

Referenced by config.CFG::__str__(), validation.Sample::digest(), VIDSelectorBase.VIDSelectorBase::initialize(), and DeviationsFromFileSensor2D::readFile().

43 { return theName; }
ALIstring theName
Name of file.
Definition: ALIFileIn.h:63

◆ nline()

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

◆ openNewFile()

void ALIFileIn::openNewFile ( const char *  filename)
private

Definition at line 37 of file ALIFileIn.cc.

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

Referenced by getWordsInLine().

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

Member Data Documentation

◆ theCurrentFile

int ALIFileIn::theCurrentFile
private

Definition at line 56 of file ALIFileIn.h.

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

◆ theFiles

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

Definition at line 52 of file ALIFileIn.h.

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

◆ theInstances

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

Definition at line 60 of file ALIFileIn.h.

Referenced by getInstance().

◆ theLineNo

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

Definition at line 54 of file ALIFileIn.h.

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

◆ theName

ALIstring ALIFileIn::theName
private

Name of file.

Definition at line 63 of file ALIFileIn.h.

Referenced by name().

◆ theNames

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

Definition at line 55 of file ALIFileIn.h.

Referenced by ErrorInLine(), and openNewFile().