#include <ALIFileIn.h>
Public Member Functions | |
ALIFileIn () | |
void | close () |
ALIbool | eof () |
void | ErrorInLine () |
ALIint | getWordsInLine (std::vector< ALIstring > &wl) |
const ALIstring & | name () |
const ALIint | nline () |
~ALIFileIn () | |
Static Public Member Functions | |
static ALIFileIn & | getInstance (const ALIstring &name) |
static ALIFileIn & | getInstanceOpened (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< ALIint > | theLineNo |
ALIstring | theName |
Name of file. | |
std::vector< ALIstring > | theNames |
Static Private Attributes | |
static std::vector< ALIFileIn * > | theInstances |
Definition at line 21 of file ALIFileIn.h.
ALIFileIn::ALIFileIn | ( | ) | [inline] |
ALIFileIn::~ALIFileIn | ( | ) | [inline] |
Definition at line 25 of file ALIFileIn.h.
{}
ALIFileIn::ALIFileIn | ( | const ALIstring & | name | ) | [inline, private] |
Definition at line 27 of file ALIFileIn.h.
void ALIFileIn::close | ( | ) |
Definition at line 236 of file ALIFileIn.cc.
References theCurrentFile, and theFiles.
Referenced by eof(), and Model::readSystemDescription().
{ //- std::cout << " close " << theCurrentFile << " size " << theFiles.size() << std::endl; /* if( theCurrentFile+1 != 0 ) { ErrorInLine(); std::cerr << "trying to close file while reading other files included in it " << theCurrentFile+1 << std::endl; // exit(0); } else { */ theFiles[theCurrentFile+1]->close(); theFiles.pop_back(); // } }
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().
{ ALIbool isok = theFiles[theCurrentFile]->eof(); if( isok ) { //std::cout << " eof theCurrentFile " << theCurrentFile << std::endl; theCurrentFile--; if( theCurrentFile != -1 ) close(); // last file will be closed by the user } //only real closing if all files are closed //- std::cout << " eof " << isok << " " << theCurrentFile << std::endl; if( theCurrentFile != -1 ) { return 0; } else { return isok; } }
void ALIFileIn::ErrorInLine | ( | ) |
Definition at line 211 of file ALIFileIn.cc.
References ExpressReco_HICollisions_FallBack::cerr, theCurrentFile, theLineNo, and theNames.
Referenced by MeasurementDiffEntry::buildOptONamesList(), OpticalObject::createComponentOptOs(), Entry::fill(), Entry::fillFromInputFileQuality(), Entry::fillFromInputFileSigma(), Entry::fillFromInputFileValue(), getWordsInLine(), OpticalObject::readCoordinates(), Model::readMeasurementsFromFile(), Model::readSystemDescription(), and GlobalOptionMgr::setGlobalOption().
{ std::cerr << "!! EXITING: ERROR IN LINE No " << theLineNo[theCurrentFile] << " file: " << theNames[theCurrentFile] << " : "; }
Definition at line 23 of file ALIFileIn.cc.
References ALIFileIn(), lut2db_cfg::filename, openNewFile(), theCurrentFile, and theInstances.
Referenced by MeasurementDiffEntry::buildOptONamesList(), CocoaDaqReaderText::CocoaDaqReaderText(), OpticalObject::construct(), Measurement::construct(), Entry::fill(), OptOSensor2D::fillExtraEntry(), Entry::fillFromInputFileQuality(), Entry::fillFromInputFileSigma(), Entry::fillFromInputFileValue(), FittedEntriesReader::FittedEntriesReader(), getInstanceOpened(), Model::readMeasurementsFromFile(), and Model::readSystemDescription().
{ std::vector<ALIFileIn*>::const_iterator vfcite; for( vfcite = theInstances.begin(); vfcite != theInstances.end(); vfcite++) { if( (*vfcite)->name() == filename) { return *(*vfcite); } } ALIFileIn* instance = 0; if( vfcite == theInstances.end() ) { instance = new ALIFileIn( filename ); instance->theCurrentFile = -1; instance->openNewFile( filename.c_str() ); theInstances.push_back( instance ); } return *instance; }
Definition at line 73 of file ALIFileIn.cc.
References ExpressReco_HICollisions_FallBack::cerr, cmsRelvalreport::exit, lut2db_cfg::filename, getInstance(), and name().
Definition at line 90 of file ALIFileIn.cc.
References ExpressReco_HICollisions_FallBack::cerr, comment, eof(), ErrorInLine(), cmsRelvalreport::exit, openNewFile(), theCurrentFile, theFiles, and theLineNo.
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().
{ ALIint isok = 1; //---------- Read a line of file: //@@@@--- Cannot be read with a istream_iterator, becasuse it uses std::cout, and then doesn't read '\n' //----- Clear wordlist ALIint wsiz = wordlist.size(); ALIint ii; for (ii = 0; ii < wsiz; ii++) { wordlist.pop_back(); } //---------- Loop lines while there is an ending '\' or line is blank const ALIint NMAXLIN = 1000; char ltemp[NMAXLIN]; //there won't be lines longer than NMAXLIN characters for (;;) { (theLineNo[theCurrentFile])++; for( ii = 0; ii < NMAXLIN; ii++) ltemp[ii] = ' '; theFiles[theCurrentFile]->getline( ltemp, NMAXLIN ); //---------- Check for lines longer than NMAXLIN character ALIint ii; for ( ii=0; ii < NMAXLIN; ii++) { if ( ltemp[ii] == '\0' ) break; } if ( ii == NMAXLIN-1 ) { ErrorInLine(); std::cerr << "!!!! line longer than " << NMAXLIN << " characters" << std::endl << " please split it putting a '\\' at the end of line" << std::endl; exit(0); } //---------- End of file //- if ( theFiles[theCurrentFile]->eof() ) { if ( eof() ) { //t exit(0); return 0; } //---------- Convert line read to istrstream to split it in words std::istrstream istr_line(ltemp); //--------- count how many words are there in ltemp (this sohuld not be needed, but sun compiler has problems) !! this has to be nvestigated... ALIint NoWords = 0; char* tt = ltemp; ALIstring stemp(ltemp); do{ if( *tt != ' ' && *(tt) != '\0' ) { if( tt == ltemp) { NoWords++; // std::cout << "dNoWords" << NoWords << ltemp << std::endl; } else if( *(tt-1) == ' ' || *(tt-1) == '\015' || *(tt-1) == '\t') { NoWords++; // std::cout << "NoWords" << NoWords << ltemp << std::endl; } } tt++; }while(*tt != '\0' && stemp.length()!=0); ALIstring stempt (ltemp); if(stempt.length() == 0) NoWords = 0; //--------- Read words from istr_line and write them into wordlist // ALIint stre = 1; for( ii=0; ii < NoWords; ii++) { ALIstring stemp = ""; istr_line >> stemp; //?? gives warning in Insure++ if ( stemp.length() == 0 ) break; ALIint comment = stemp.find(ALIstring("//") ); // std::cout << "!!!COMMENT" << comment << stemp.c_str() << std::endl; if ( comment == 0 ) { break; } else if ( comment > 0 ) { stemp = stemp.substr( 0, comment ); wordlist.push_back(stemp); break; //- for( int jj=0; jj < stemp.length()-comment; jj++) stemp.pop_back(); } wordlist.push_back(stemp); } //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??) // istream_iterator<ALIstring, ptrdiff_t> ALIstring_iter(istr_line); // istream_iterator<ALIstring, ptrdiff_t> eosl; // copy(ALIstring_iter, eosl, back_inserter(wordlist)); // typedef istream_iterator<ALIstring, ptrdiff_t> ALIstring_iter; // copy(ALIstring_iter(istr_line), ALIstring_iter(), back_inserter(wordlist)); if ( wordlist.size() != 0 ) { if( (*(wordlist.end()-1)).compare("\\") == 0 ) { //use '\' to mark continuing line wordlist.pop_back(); } else { break; } } } //or why not like this?: //typedef istream_iterator<ALIstring, ptrdiff_t> string_iter; //copy(string_iter(istr_line), string_iter(), back_inserter(wordlist)); //- std::cout << " checking for include " << wordlist[0] << std::endl; // check if including a new file if( wordlist[0] == "#include" ) { if( wordlist.size() != 2 ) { ErrorInLine(); std::cerr << "'#include' should have as second argument the filename " << std::endl; exit(0); } //- std::cout << "include found " << std::endl; openNewFile( wordlist[1].c_str() ); isok = getWordsInLine( wordlist); } return isok; }
const ALIstring& ALIFileIn::name | ( | ) | [inline] |
Definition at line 44 of file ALIFileIn.h.
References theName.
Referenced by getInstanceOpened(), and DeviationsFromFileSensor2D::readFile().
{ return theName; }
const ALIint ALIFileIn::nline | ( | ) | [inline] |
Definition at line 42 of file ALIFileIn.h.
References theCurrentFile, and theLineNo.
Referenced by Model::readSystemDescription().
{ return theLineNo[theCurrentFile]; }
void ALIFileIn::openNewFile | ( | const char * | filename | ) | [private] |
Definition at line 48 of file ALIFileIn.cc.
References ExpressReco_HICollisions_FallBack::cerr, cmsRelvalreport::exit, theCurrentFile, theFiles, theLineNo, and theNames.
Referenced by getInstance(), and getWordsInLine().
{ theCurrentFile++; std::ifstream* fin = new std::ifstream(filename); theFiles.push_back(fin); //- ALIint lineno = new ALIint; //- ALIint lineno = 0; theLineNo.push_back( 0 ); theNames.push_back( filename ); #ifndef OS_SUN_4_2 if( !fin->is_open()) { std::cerr << "!!!! Input file does not exist: " << filename << std::endl; exit(1); } #endif }
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 [static, private] |
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] |
std::vector<ALIstring> ALIFileIn::theNames [private] |
Definition at line 56 of file ALIFileIn.h.
Referenced by ErrorInLine(), and openNewFile().