NdbEndfIO.h

Go to the documentation of this file.
00001 #ifndef __ENDFIO_H
00002 #define __ENDFIO_H
00003 
00004 #include <stdio.h>
00005 #include <string.h>
00006 
00007 #include <TObject.h>
00008 
00009 #include "NdbDefs.h"
00010 
00011 // I/O Options
00012 enum {
00013         TENDF_READ=1,
00014         TENDF_WRITE=2
00015 };
00016 
00017 #define TENDF_NEXT_NUMBER       -1
00018 #define TENDF_MAXREC            100 
00019 
00020 // End records
00021 enum {
00022         SEND=1,
00023         FEND=2,
00024         MEND=3,
00025         TEND=4
00026 };
00027 
00028 class NdbEndfIO : public TObject
00029 {
00030   // ================== NdbEndfIO =================== 
00031   // This class is handling all the input/output 
00032   // to an ENDF-B/VI file
00033   //
00034 protected:
00035         FILE    *f;                     //! Working file
00036         Int_t   mode;                   // Open mode
00037         Int_t   iMAT;                   // Material number
00038         Int_t   iMF;                    // Current file type
00039         Int_t   iMT;                    // Current section
00040         Int_t   lineNum;                // Keep track of current line
00041 
00042         Long_t  matStart;               // Pointer of the current
00043                                         // material starting pos
00044         Long_t  mfStart;                // Current MF starting pos
00045         Long_t  mtStart;                // Current MT starting pos
00046 
00047         Int_t   lineLen;                // Length of line
00048         char    lineTxt[TENDF_MAXREC];  // Complete line
00049         Int_t   lastNumPos;             // for readReal and readInt;
00050   static        char    _str[TENDF_MAXREC];     // Used for substrings
00051 
00052 public:
00053         NdbEndfIO()     { f=NULL; }
00054         virtual ~NdbEndfIO()
00055                 { if (f) fclose(f); }
00056 
00057         NdbEndfIO( char *filename, Int_t mode);
00058 
00059         NdbEndfIO( NdbEndfIO *endf ) {
00060                 f       = endf->f;              
00061                 mode    = endf->mode;
00062                 iMAT    = endf->iMAT;
00063                 iMF     = endf->iMF;
00064                 iMF     = endf->iMT;
00065                 matStart= endf->matStart;
00066                 mfStart = endf->mfStart;
00067                 mtStart = endf->mtStart;
00068                 lineNum = endf->lineNum;
00069                 lineLen = endf->lineLen;
00070                 strcpy(lineTxt, endf->lineTxt);
00071         }
00072 
00073 
00074         // Access functions
00075         inline Int_t    LineNumber()    const { return lineNum; }
00076         inline char     *Line()         { return lineTxt; }
00077         inline Int_t    MAT()           const { return iMAT; }
00078         inline Int_t    MF()            const { return iMF; }
00079         inline Int_t    MT()            const { return iMT; }
00080 
00081         // Is the file open?
00082         inline  Bool_t  IsOpen()        { return (f!=NULL); }
00083 
00084         // Have we reached End of file?
00085         inline  Bool_t  Eof()           { return feof(f); }
00086 
00087         // End of Section
00088         inline  Bool_t  EOMT()          { return (iMT==0); }
00089 
00090         // End of MF
00091         inline  Bool_t  EOMF()          { return (iMF==0); }
00092 
00093         // End of MATerial
00094         inline  Bool_t  EOMAT()         { return (iMAT==0); }
00095 
00096         // Find Material
00097         Bool_t          FindMAT( Int_t mat, Bool_t rewind=FALSE );
00098 
00099         // Find File inside material
00100         Bool_t          FindMATMF( Int_t mat, Int_t mf, Bool_t rewind=FALSE );
00101 
00102         // Find Section
00103         Bool_t          FindMATMFMT( Int_t mat, Int_t mf, Int_t mt,
00104                                         Bool_t rewind=FALSE );
00105 
00106         // Find the specific MF:MT file:section, for current MAT
00107         Bool_t          FindMFMT(Int_t mf, Int_t mt);
00108 
00109         // Rewind to beggining of current material
00110         Bool_t          RewindMAT()     { return fseek(f, matStart, SEEK_SET); }
00111 
00112         // Rewind to beggining of current file (MF)
00113         Bool_t          RewindMF()      { return fseek(f, mfStart, SEEK_SET); }
00114 
00115         // Rewind to beggining of current section (MT)
00116         Bool_t          RewindMT()      { return fseek(f, mtStart, SEEK_SET); }
00117                 
00118         // Read entire line
00119         Bool_t          ReadLine();
00120 
00121         // Reads one by one the real numbers from the current line
00122         Int_t           ReadInt(Bool_t *error, Int_t pos=TENDF_NEXT_NUMBER);
00123 
00124         Float_t         ReadReal(Bool_t *error, Int_t pos=TENDF_NEXT_NUMBER);
00125 
00126         // Return a substring of current line in a static variable
00127         char*           Substr(Int_t start, Int_t length);
00128 
00129 protected:
00130         Bool_t          NextNumber(Int_t pos=TENDF_NEXT_NUMBER);
00131         Int_t           SubReadInt(Int_t start, Int_t length);
00132         Float_t         SubReadReal(Int_t start, Int_t length);
00133 
00134 
00135         ClassDef(NdbEndfIO,1)
00136 
00137 }; // NdbEndfIO
00138 
00139 #endif

Generated on Tue Jul 5 15:15:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1