/*!\class PelIO
\author Alexandre A. P. Suaide 

<p>
This class is responsible for the basic I/O between the Pelletron data files
(.FIL) and the ROOT framework. 
*/

#ifndef PelIO_HH
#define PelIO_HH

#include "stdio.h"
#include "TNamed.h"
#include "TROOT.h"
#include "TString.h"
#include "TH1.h"
#include "TString.h"
#include "TRandom.h"

#define MAXBLOCKSIZE 16384
#define MAXBLOCKSIZEWRITE 73728
#define BLOCKSIZEWRITE 65536
#define BLOCKSIZETAPE 32768
#define BLOCKSIZETAPEHEADER 256
#define STREAMSIZE 32768
#define MAXEVENTSBLOCK 16384
#define MAXOUTPUT 4
#define MAXPAR 8192

enum RetCode { kWarn, kOk, kEOF, kERR};


class PelIO : public TNamed
{
  protected:
    unsigned short     mEventsPosition[MAXEVENTSBLOCK]; ///< Position of each event in the memory block
    unsigned short     mBlock[MAXBLOCKSIZE]; ///< Event block
    unsigned short     mResidual[MAXBLOCKSIZE]; ///< Resiual from last block
    unsigned short     mDataStream[STREAMSIZE]; ///< Input data stream
    unsigned short     mResidualSize; ///< Residual size
    unsigned short     BLOCKSIZE; ///< Block size
    unsigned long      mBytesOutput[MAXOUTPUT]; ///< Bytes in the output stream
    unsigned long      mNSaved[MAXOUTPUT]; ///< Number of events saved in the output stream
    unsigned long      mNRead; ///< Number of events read
    unsigned long      mNBlockRead; ///< Number of blocks read
    char               mOutputBuffer[MAXOUTPUT][MAXBLOCKSIZEWRITE]; ///< Output buffer
    short              mParIndexTmp[MAXPAR];
    float              mParValuesTmp[MAXPAR];

    unsigned short     mCurrentPosition;
    unsigned short     mNextPosition;
    unsigned short     mLastPosition;

    FILE               *mInput; ///< pointer to the input stream    
    FILE               *mOutput[MAXOUTPUT]; ///< pointers to the output stream
    bool               mIsInputOpen;
    bool               mIsOutputOpen[MAXOUTPUT];
    int                mLastInput; // the status of the last input request

    TString            mFileName; ///< Input file name
    TString            mFileNameOutput[MAXOUTPUT]; ///< Output file names

    bool               mDebug; ///< Debug flag
    short              mCurrentSize; ///< Current event size
    int                mStat;

    int                mNAddedPar;
    unsigned short     mParAdded[STREAMSIZE]; ///< added parameters
    bool               mSaveOnlyNew;
		bool               mSmearing;


    virtual int        writeEventToOutput(int out=0); ///< Method to write event number to the output
    virtual int        readBlock(); ///< Read block from input
    virtual int        decodeBlock(int = 0); ///< Decode block
    virtual int        decodeEvent(short&,short*,float*); ///< Decode event from the input

  public:
                       PelIO(char* name="PelIO",char *title="Pelletron IO"); ///< Default constructor
    virtual            ~PelIO(); ///< Class destructor

    // Input/output methods
    virtual int        openInput(char*); ///< Open input stream
    virtual int        openOutput(char*,int out=0,int run = 0, char* comment=""); ///< Open output stream
    virtual int        closeInput(); ///< Close input stream
    virtual int        closeOutput(int out=0); ///< Close output stream
    virtual int        readEvent(short,short&,float*); ///< Read event from input stream and return the parameters in the right position
    virtual int        writeEvent(int out=0); ///< Write event to the output stream

    // general methods
    char*              getFileName()             	       { return (char*)mFileName.Data();} ///< Get input file name
    char*              getFileNameOutput(int out=0)      { return (char*)mFileNameOutput[out].Data();} ///< Get output file name
    short              getCurrentEventSize()             { return mCurrentSize; } ///< Returns current event size in bytes
    unsigned long      getNSaved(int out=0)              { return mNSaved[out]; } ///< Get number of events saved in output
    unsigned long      getNRead()                        { return mNRead; } ///< Get number of events read from input
    unsigned long      getBlockSize()                    { return BLOCKSIZE;}  ///< Get block size
    void               setDebug(bool a)                  { mDebug = a;}  ///< Set debug mode. 
    void               setBlockSize(unsigned short a)    { BLOCKSIZE = a;} ///< Set block size
		void               setSmearing(bool s)               { mSmearing = s;} ///< Set Smearing

    void               printStats();                     ///< Print statictics
    int                getMaxOutput()                    { return MAXOUTPUT;}///< Return maximum number of outputs
    bool               isInputOpen()                     { return mIsInputOpen;}
    bool               isOutputOpen(int out =0)          { return mIsOutputOpen[out];}
    bool               isDebug()                         { return mDebug;}
		bool               isSmearing()                      { return mSmearing;}

    void               saveOnlyNewPar(bool a)            { mSaveOnlyNew = a;} // if true, saves only the new parameters
    bool               isSaveOnlyNewPar()                { return mSaveOnlyNew;} // returns the way of saving parameters to the output
    void               addPar(int,float);

  ClassDef(PelIO,1)
};
#endif


ROOT page - Class index - Class Hierarchy - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.