CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Alignment/CocoaUtilities/interface/ALIFileIn.h

Go to the documentation of this file.
00001 //   COCOA class header file
00002 //Id:  ALIFileIn.h
00003 //CAT: Model
00004 //
00005 //   istream class for handling the reading of files
00006 // 
00007 //   History: v1.0 
00008 //   Pedro Arce
00009 
00010 #ifndef FILEIN_H
00011 #define FILEIN_H
00012 
00013 #include <fstream>
00014 #include <iostream>
00015 
00016 #include <vector>
00017 
00018 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h"
00019 
00020 
00021 class ALIFileIn 
00022 {
00023  public:
00024   ALIFileIn(){};
00025   ~ALIFileIn(){}
00026  private:
00027    ALIFileIn( const ALIstring& name ): theName(name){}
00028 
00029  public:
00030   // Get the only instance opening the file
00031   static ALIFileIn& getInstance( const ALIstring& name ); 
00032   // Get the only instance when file should be already opened
00033   static ALIFileIn& getInstanceOpened( const ALIstring& name ); 
00034 
00035   // Read a line and transform it to a vector of words 
00036   ALIint getWordsInLine( std::vector<ALIstring>& wl );
00037 
00038   // Print out an error message indicating the line being read
00039   void ErrorInLine();
00040 
00041  // Access data members
00042   const ALIint nline() { return theLineNo[theCurrentFile]; }
00043 
00044   const ALIstring& name() { return theName; }
00045 
00046   ALIbool eof();
00047   void close();
00048 
00049  private:
00050   void openNewFile( const char* filename );
00051 
00052  private:
00053   std::vector< std::ifstream* > theFiles;
00054   // Number of line being read
00055   std::vector<ALIint> theLineNo;
00056   std::vector<ALIstring> theNames;
00057   int theCurrentFile;  // index of file being read in theFiles
00058 
00059  // private DATA MEMEBERS
00060   // Vector of class instances (each one identified by its name)
00061   static std::vector<ALIFileIn*> theInstances;
00062  
00064   ALIstring theName;
00065 
00066 };
00067 
00068 #endif