////////////////////////////////////////////////////////////////////////
//
// $Id: DBData.h,v 1.7 2001/11/18 19:36:34 bviren Exp $
//
// DBData
//
// Package: elbo
//
// Interface with MySQL to get/put a "data point".  A "data point"
// consists of all the input parameters (baseline, mixing angles,
// masses, initial neutrino, energy, etc) and the 3 output
// probabilities.
//
// Contact: bv@bnl.gov
//
// Created on: Wed Oct 31 15:43:15 2001
//
////////////////////////////////////////////////////////////////////////

#ifndef DBDATA_H
#define DBDATA_H

#include "NuoscParam.h"

#include <vector>
#include <string>

#include <mysql/mysql.h>
    

class DBData
{

public:

    
    DBData();
    DBData(const char* host, const char* user, const char* db, const char* password=0);
    ~DBData();
    
    // connect to MySQL, return false if fails.  Second constructor
    // calls this.
    bool Init(const char* host, const char* user, const char* db, 
              const char* password = 0);

    // Call to break connection with MySQL.  Done for you in destructor.
    void Close();

    // Save data point to DB.
    int AddNuoscProb(int id, const NuoscParam& np,
                     vector<double>& E,
                     vector<double>& Pnue,
                     vector<double>& Pnumu,
                     vector<double>& Pnutau);

    // Return vectors filled with Pnux(E) given other info in
    // DataPoint, ordered by increasing energy.  Returns false if
    // can't find.
    bool GetNuoscProb(const NuoscParam& np, 
                      vector<double>& E, 
                      vector<double>& Pnue,
                      vector<double>& Pnumu,
                      vector<double>& Pnutau);
    bool GetNuoscProb(int id, NuoscParam& np, 
                      vector<double>& E, 
                      vector<double>& Pnue,
                      vector<double>& Pnumu,
                      vector<double>& Pnutau);
    
    bool GetNuoscParam(vector<int>& id, vector<NuoscParam>& params);

    bool AddXsec(int id, vector<double>& evec, vector<double>& xvec,
                 const char* description);
    bool GetXsec(int id, vector<double>& evec, vector<double>& xvec,
                 char* description);
    bool GetXsecDescr(vector<int>& id, vector<string>& descr);
private:

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

    MYSQL* fMysql;
};                              // end of class DBData

#endif  // DBDATA_H
