////////////////////////////////////////////////////////////////////////
//
// $Id: Spect.h,v 1.3 2001/11/28 21:25:31 bviren Exp $
//
// Spect
//
// Package: elbo
//
// Encapsulate a spectrum
//
// Contact: bv@bnl.gov
//
// Created on: Mon Nov 19 13:15:20 2001
//
////////////////////////////////////////////////////////////////////////

#ifndef SPECT_H
#define SPECT_H

#include <vector>

class InterFunc;

class Spect
{

public:

    Spect();
    ~Spect();

    // from text file, format: <energy in ev> <flux in neutrinos/cm^2/s>
    bool LoadDataFile(int id, int nutype, double baseline, double angle,
                  const char* filename);

    // from DB, needs ID# 
    bool LoadDataDB(int id, const char* db_host=0, 
                  const char* db_user=0, const char* db_pass=0);

    // get any data stored
    void GetData(int& id, int& nutype, double& baseline, double& angle,
                 vector<double>& evec, 
                 vector<double>& flux);
    
    // Set with external data
    void SetData(int id, int nutype, double baseline, double angle,
                 vector<double>& evec, 
                 vector<double>& flux);

    // Store into file
    bool StoreDataFile(const char* filename);
    // Store into DB
    bool StoreDataDB(const char* db_host, const char* db_user, 
                   const char* db_pass);

    InterFunc* CreateFunc();

    // Get available ids and descriptions
    static bool GetAvailable(const char* db_host, 
                             const char* db_user, const char* db_pass,
                             vector<int>& id, 
                             vector<int>& nutype,
                             vector<double>& baseline,
                             vector<double>& angle);
    // return Id of matching entry (doubles are compared to w/in 1%)
    // or 0 if not found
    static int GetId(int nutype, double baseline, double angle,
                     const char* db_host=0, 
                     const char* db_user=0, const char* db_pass=0);

private:

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

    int fId;
    int fNutype;                // 1,2,3=e,mu,tau, negative->antinu
    double fBaseline;           // in cm (1e-5km)
    double fAngle;              // in radians
    vector<double> fEnergy, fFlux;

};                              // end of class Spect

#endif  // SPECT_H
