/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/include/UTIL/lXDR.hh

Go to the documentation of this file.
00001 //// lXDR.hh
00002 //
00003 // Header file for a light-weight XDR class
00004 // This class does not support the full XDR protocol, and
00005 // neither does it work for all platforms. It was mainly 
00006 // written, in combination with lStdHep, to provide a faster
00007 // alternative to the more cumdersome methods using mcfio in
00008 // CLHEP.
00009 //
00010 // W.G.J. Langeveld, 24 May 2002
00011 //
00012 // Release notes:
00013 // - Version 1.0 (23-Oct-2003)
00014 //
00015 ////
00016 #ifndef LXDR__HH
00017 #define LXDR__HH
00018 
00019 #include <stdio.h>
00020 
00021 namespace UTIL{
00022 
00023 ////
00024 //
00025 // The main lXDR class.
00026 //
00027 ////
00028 class lXDR {
00029 private:
00030 //
00031 // The current version/revision is:
00032 //
00033    enum { MAJOR = 1, MINOR = 0, DAY = 23, MONTH = 10, YEAR = 2003 };
00034 //       ========================================================
00035 public:
00036    static int         getMajor(void) { return(MAJOR); };
00037    static int         getMinor(void) { return(MINOR); };
00038    static const char *getText(void)  {
00039       static char buff[80];
00040       sprintf(buff, "lXDR version %d.%d (%02d.%02d.%d) by W.G.J. Langeveld, SLAC",
00041               MAJOR, MINOR, DAY, MONTH, YEAR);
00042       return(buff);
00043    };
00044 public:
00045 //
00046 // Constructors, destructor
00047 // ------------------------
00048 // Constructor opens file, destructor closes file. Once opened for
00049 // reading, the file cannot be written to, and v.v.
00050 //
00051    lXDR(const char *filename = 0, bool open_for_write = false);
00052 private: // Prevent copying
00053    lXDR(const lXDR &);
00054 public:
00055    virtual ~lXDR();
00056 //
00057 // Change the file being read/written. If another file is currently
00058 // being read or written, it is first closed. The new file position
00059 // is the start of the file.
00060 //
00061    void        setFileName(const char *filename, bool open_for_write = false);
00062    const char *getFileName(void) const { return(_fileName); };
00063 //
00064 // Prevent assignment:
00065 //
00066 private:
00067    lXDR       &operator=(const lXDR &);
00068 public:
00069 //
00070 // Check for errors in the last operation.
00071 //
00072    long        getError(void) const { return(_error); };
00073 //
00074 // Read data.
00075 // ----------
00076 // The following routines read single longs floats or doubles.
00077 // Check getError() for succes or failure.
00078 //
00079    long        readLong(void);
00080    double      readFloat(void);  // Note that this returns a double!!
00081    double      readDouble(void);
00082 //
00083 // The following routines read the length of an array of char, long or double
00084 // from the file, allocate a suitably large array, and read the data from the
00085 // file. Character strings are null terminated.
00086 // Check getError() for succes or failure.
00087 //
00088    const char *readString(long &length);
00089    long       *readLongArray(long &length);
00090    double     *readFloatArray(long &length); // Note that this returns an array of doubles!!
00091    double     *readDoubleArray(long &length);
00092 //
00093 // Write data
00094 // ----------
00095 // The following routines write single longs or doubles.
00096 // They return getError().
00097 //
00098    long        writeLong(long data);
00099    long        writeDouble(double data);
00100 //
00101 // The following routines write the length of an array of char, long or double
00102 // to the file, then write the data itself.
00103 // The functions return getError().
00104 //
00105    long        writeString(const char *data);
00106    long        writeString(const char *data, long length);
00107    long        writeLongArray(const long *data, long length);
00108    long        writeDoubleArray(const double *data, long length);
00109 
00110    void        setError(long error) { _error = error; return; };
00111 //
00112 // Set or get (with no arguments) file position.
00113 //
00114    long        filePosition(long pos = -1);
00115 
00116 private:
00117    char      *_fileName;
00118    FILE      *_fp;
00119    long       _error;
00120    bool       _openForWrite;
00121 
00122    bool       _hasNetworkOrder;
00123    double     ntohd(double d) const;
00124    double     htond(double d) const { return(ntohd(d)); };
00125 
00126    long       checkRead(long *);
00127    long       checkRead(float *);
00128    long       checkRead(double *);
00129    long       checkWrite(long *);
00130    long       checkWrite(double *);
00131 };
00132 
00133 #define LXDR_SUCCESS         0
00134 #define LXDR_OPENFAILURE     1
00135 #define LXDR_READONLY        2
00136 #define LXDR_WRITEONLY       3
00137 #define LXDR_NOFILE          4
00138 #define LXDR_READERROR       5
00139 #define LXDR_WRITEERROR      6
00140 #define LXDR_SEEKERROR       7
00141  
00142 }
00143 #endif

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7