// ESAF : Euso Simulation and Analysis Framework
// $Id: OADBConverter.hh,v 1.4 2004/06/16 13:35:16 thea Exp $
// A.Thea, J.Watts created Mar, 22 2004

#ifndef __OADBCONVERTER_HH_
#define __OADBCONVERTER_HH_

#include "TObject.h"
#include "OADBTree.hh"
#include <Riostream.h>
#include <string>

class OADBHeader;
class OADBPhotons;


enum OAEKeyType { kBegin, kEnd, kHeader, kPhotons, kWavelength, kAngle };

class OADBConverter : public TObject {
private:
//    enum OAEKeyType { kBegin, kEnd, kHeader, kPhotons, kWavelength, kAngle };
public:
    // ctor
    OADBConverter( OADBTree* );

    // dtor
    virtual ~OADBConverter();

    // convert oatree into a binary ESAF-readable file
    void SaveBinary( const char* );

    // checks binary
    void CheckBinary( const char* );

    static string KeyWord( OAEKeyType );

private:
    // helper functions
    // writing 
    void WriteHeader();
    void WritePhotons();
    void InsertBegin( OAEKeyType );
    void InsertEnd( OAEKeyType );
    //reading
    void Read();
    
    
    OADBTree *fTree;

    OADBHeader *fHeader;
    OADBPhotons *fPhotons;

    fstream *fBinFile;
    // length of the keywords
    size_t fKeyLength;

    ClassDef(OADBConverter,1)
};

#endif  /* __OADBCONVERTER_HH_ */