#ifndef MARS_MBinning
#define MARS_MBinning

#ifndef MARS_MParContainer
#include "MParContainer.h"
#endif

#ifndef ROOT_TArrayD
#include "TArrayD.h"
#endif

class TH1;

class MBinning : public MParContainer
{
private:
    TArrayD fEdges;

    Byte_t  fType;

    void StreamPrimitive(ofstream &out) const;

    enum {
        kIsDefault,
        kIsLinear,
        kIsLogarithmic,
        kIsUserArray
    };

public:
    MBinning(const char *name=NULL, const char *title=NULL);

    void SetEdges(const TArrayD &arr)
    {
        fEdges = arr;
        fType = kIsUserArray;
    }

    void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
    void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up);

    // FIXME: ROOT workaround: "operator[] const" missing
    Double_t GetEdgeLo() const { return ((TArrayD)fEdges)[0]; }
    Double_t GetEdgeHi() const { return ((TArrayD)fEdges)[fEdges.GetSize()-1]; }

    Int_t GetNumEdges() const { return fEdges.GetSize(); }
    Int_t GetNumBins() const { return fEdges.GetSize()-1; }

    Double_t *GetEdges() const { return fEdges.GetArray(); }

    Bool_t IsLinear() const { return fType==kIsLinear; }
    Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
    Bool_t IsDefault() const { return fType==kIsDefault; }
    Bool_t IsUserArray() const { return fType==kIsUserArray; }

    void Apply(TH1 &);

    ClassDef(MBinning, 1) //Container to store the binning of a histogram
};

#endif

