////////////////////////////////////////////////////////////////////////
//
// $Id: Ntuple.h,v 1.4 2002/04/24 18:08:51 bviren Exp $
//
// Ntuple
//
// Package: elbo
//
// Wrapper around HBOOK ntuples
//
// Currently, this is just for reading/writing RWN ntuples.  You must call
// HLIMIT before creating an Ntuple (see Hlimit() below).
// 
// Contact: bv@bnl.gov
//
// Created on: Tue Sep 25 11:02:49 2001
//
////////////////////////////////////////////////////////////////////////

#ifndef NTUPLE_H
#define NTUPLE_H

#include <map>
#include <string>
#include <vector>

class Ntuple
{

public:

    // Readonly ctor:
    Ntuple(const char* filename, int ntid, int lun = 1, 
           const char* rzpath = "INPUT");

    // Writeonly ctor:
    Ntuple(const char* filename, int ntid, const char* title, 
           vector<string>& tags, int lun = 1, const char* rzpath = "OUTPUT",
           int nwbuff=5000);

    ~Ntuple();

    // helper - just calls HLIMIT for you.
    // You better have int pawc_[]; already defined!
    static void Hlimit(int nwords);

    // write only interface
    void FillRow(float *row);

    // Read only interface
    int GetNentries(void) const { return fNentries; }
    int GetNvar() const { return fNvar; }
    int NameToIndex(const char* name) { return fIndexMap[name]; }
    vector<string>& GetNames() { return fNames; }

    // All indices start from zero.
    float* operator[](int row_index); 
    float operator()(int row_index, int column_index);
    float operator()(int row_index, const char* name);

private:

    // copy constructor, assignment:
    Ntuple(const Ntuple& rhs); // copy constructor
    Ntuple& operator=(const Ntuple& rhs); // assignment

    bool fReadOnly;             // false for writeonly mode

    int fLun;                   // LUN for ntuple file.
    int fID;                    // ID number of the ntuple
    int fOffset;                // No idea.
    int fNentries;              // number of entries (rows) in the ntuple.
    int fNvar;                  // number of entries (columns) in a row.
    
    float* fRow;                // holds current row values.
    string fRZPath;

    map<string,int> fIndexMap;  // map from name to index;
    vector<string> fNames;
};                              // end of class Ntuple

#endif  // NTUPLE_H
