Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:33

0001 //   COCOA class header file

0002 //Id:  ALIFileIn.h

0003 //CAT: Model

0004 //

0005 //   istream class for handling the reading of files

0006 //

0007 //   History: v1.0

0008 //   Pedro Arce

0009 
0010 #ifndef FILEIN_H
0011 #define FILEIN_H
0012 
0013 #include <fstream>
0014 #include <iostream>
0015 
0016 #include <vector>
0017 
0018 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h"
0019 
0020 class ALIFileIn {
0021 public:
0022   ALIFileIn(){};
0023   ~ALIFileIn() {}
0024 
0025 private:
0026   ALIFileIn(const ALIstring& name) : theName(name) {}
0027 
0028 public:
0029   // Get the only instance opening the file

0030   static ALIFileIn& getInstance(const ALIstring& name);
0031   // Get the only instance when file should be already opened

0032   static ALIFileIn& getInstanceOpened(const ALIstring& name);
0033 
0034   // Read a line and transform it to a vector of words

0035   ALIint getWordsInLine(std::vector<ALIstring>& wl);
0036 
0037   // Print out an error message indicating the line being read

0038   void ErrorInLine();
0039 
0040   // Access data members

0041   const ALIint nline() { return theLineNo[theCurrentFile]; }
0042 
0043   const ALIstring& name() { return theName; }
0044 
0045   ALIbool eof();
0046   void close();
0047 
0048 private:
0049   void openNewFile(const char* filename);
0050 
0051 private:
0052   std::vector<std::ifstream*> theFiles;
0053   // Number of line being read

0054   std::vector<ALIint> theLineNo;
0055   std::vector<ALIstring> theNames;
0056   int theCurrentFile;  // index of file being read in theFiles

0057 
0058   // private DATA MEMEBERS

0059   // Vector of class instances (each one identified by its name)

0060   static std::vector<ALIFileIn*> theInstances;
0061 
0062   /// Name of file

0063   ALIstring theName;
0064 };
0065 
0066 #endif