1    	// $Id: StStreamFile.h,v 1.7 2010/01/25 17:17:11 fine Exp $
2    	// $Log: StStreamFile.h,v $
3    	// Revision 1.7  2010/01/25 17:17:11  fine
4    	// Remove the redundant RecordSize method
5    	//
6    	// Revision 1.6  2010/01/15 21:26:51  fine
7    	// RT #1816. Eliminate the side effect from RT 1803 fix
8    	//
9    	// Revision 1.5  2010/01/07 17:37:59  fine
10   	// introduce closeFileSignal to process several DAT files at once. RT # 1794
11   	//
12   	// Revision 1.4  2010/01/06 20:42:26  fine
13   	// Fix type EventNumber shoould be RunNumber . Thanks Akio
14   	//
15   	// Revision 1.3  2010/01/06 20:09:39  fine
16   	// RT #1794. Add EventNumber method to the StStreamFile interface RT # 1794
17   	//
18   	// Revision 1.2  2009/10/13 15:44:59  fine
19   	// add the method to provide the error message
20   	//
21   	// Revision 1.1  2009/10/12 04:21:06  fine
22   	// Add abstract STAR iostream-base file interface
23   	//
24   	//
25   	  
26   	/***************************************************************************
27   	 * \Author: Valeri Fine )fine@bnl.gov)
28   	 * Description: The  base proxy class for fstream-base I/O operation 
29   	 **************************************************************************/
30   	
31   	#ifndef __StStreamFile_h__
32   	#define __StStreamFile_h__
33   	
34   	#include <fstream> 
35   	#include <errno.h>
36   	#include <string>
37   	
38   	using namespace std;
39   	
40   	class StStreamFile {
41   	private:
42   	    int mDebug;
43   	    string fFilename; //< last open file name
44   	    fstream fStream;
45   	
46   	public:
47   	  explicit StStreamFile(): mDebug(0), fStream(){}
48   	
49   	  explicit StStreamFile(const char *fileName, ios_base::openmode mode 
50   	      = ios_base::in) : mDebug(0), fStream() { open(fileName,mode); }
51   	  virtual ~StStreamFile();
52   	  int   Debug() const { return mDebug; }
53   	  void  SetDebug(int debug) {  mDebug=debug; }
54   	  void  Perror(const char * header=0) const;
55   	
56   	public: // abstract interface  
57   	  virtual fstream &Read()           = 0;
58   	  virtual char *Record()            = 0;
59   	  virtual int   Length()    const   = 0;
60   	  virtual int   Version()   const   = 0;
61   	  virtual int   RunNumber() const   = 0;
62   	  virtual int   RecordUnixTime() const   = 0;
63   	
64   	public: // fstream proxy interface   
65   	  // fstream proxy methods
66   	  void open(const char *fileName, ios_base::openmode mode = ios_base::in);
67   	  void close();
68   	  bool bad()        const { return fStream.bad();     }
69   	  bool good()       const { return fStream.good();    }
70   	  bool fail()       const { return fStream.fail();    }
71   	  bool eof()        const { return fStream.eof();     }
72   	  bool is_open()          { return fStream.is_open(); }
73   	  ios_base::iostate rdstate() const { return fStream.rdstate(); }
74   	
75   	  fstream &stream()                 { return fStream ;    }
76   	  const fstream &stream()  const    { return fStream ;    }
77   	  const string &filename() const    { return fFilename;   }
78   	  
79   	protected:
80   	  istream &read(char *s, streamsize n);
81   	  virtual bool closeFileSignal()  { return true; } //< the method to be overriden in subclass to customize the "new file has been open" status
82   	};
83   	#endif
84