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.

22 {};

Referenced by getInstance().

◆ ~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) {}

Member Function Documentation

◆ close()

void ALIFileIn::close ( )

Definition at line 218 of file ALIFileIn.cc.

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 }

References theCurrentFile, and theFiles.

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

◆ eof()

ALIbool ALIFileIn::eof ( )

Definition at line 201 of file ALIFileIn.cc.

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 }

References close(), theCurrentFile, and theFiles.

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

◆ ErrorInLine()

void ALIFileIn::ErrorInLine ( )

◆ getInstance()

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

◆ getInstanceOpened()

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

Definition at line 60 of file ALIFileIn.cc.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, beamvalidation::exit(), corrVsCorr::filename, getInstance(), and name().

◆ getWordsInLine()

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

Definition at line 74 of file ALIFileIn.cc.

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 }

References beam_dqm_sourceclient-live_cfg::cerr, comment, 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(), Model::readMeasurementsFromFile(), and Model::readSystemDescription().

◆ name()

const ALIstring& ALIFileIn::name ( )
inline

◆ nline()

const ALIint ALIFileIn::nline ( )
inline

Definition at line 41 of file ALIFileIn.h.

41 { return theLineNo[theCurrentFile]; }

References theCurrentFile, and theLineNo.

Referenced by Model::readSystemDescription().

◆ openNewFile()

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

Definition at line 38 of file ALIFileIn.cc.

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 }

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

Referenced by getWordsInLine().

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().

ALIbool
bool ALIbool
Definition: CocoaGlobals.h:19
ALIFileIn::openNewFile
void openNewFile(const char *filename)
Definition: ALIFileIn.cc:38
ALIFileIn::theLineNo
std::vector< ALIint > theLineNo
Definition: ALIFileIn.h:54
ALIFileIn::theFiles
std::vector< std::ifstream * > theFiles
Definition: ALIFileIn.h:52
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
ALIstring
std::string ALIstring
Definition: CocoaGlobals.h:9
ALIFileIn::theInstances
static std::vector< ALIFileIn * > theInstances
Definition: ALIFileIn.h:60
groupFilesInBlocks.fin
fin
Definition: groupFilesInBlocks.py:94
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
ALIFileIn::theNames
std::vector< ALIstring > theNames
Definition: ALIFileIn.h:55
ALIFileIn::getInstance
static ALIFileIn & getInstance(const ALIstring &name)
Definition: ALIFileIn.cc:22
ALIFileIn::ErrorInLine
void ErrorInLine()
Definition: ALIFileIn.cc:196
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
ALIFileIn::ALIFileIn
ALIFileIn()
Definition: ALIFileIn.h:22
ALIFileIn::close
void close()
Definition: ALIFileIn.cc:218
ALIFileIn::eof
ALIbool eof()
Definition: ALIFileIn.cc:201
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
comment
#define comment(par)
Definition: vmac.h:163
ALIint
int ALIint
Definition: CocoaGlobals.h:15
ALIFileIn::name
const ALIstring & name()
Definition: ALIFileIn.h:43
ALIFileIn::getWordsInLine
ALIint getWordsInLine(std::vector< ALIstring > &wl)
Definition: ALIFileIn.cc:74
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
ALIFileIn::theName
ALIstring theName
Name of file.
Definition: ALIFileIn.h:63
ALIFileIn::theCurrentFile
int theCurrentFile
Definition: ALIFileIn.h:56
cuy.ii
ii
Definition: cuy.py:590
ALIFileIn
Definition: ALIFileIn.h:20