/**
   \file
   Access to database describing overall atmospheric quality

   \author Tom Paul
   \version $Id: OverallQualityDB.h 21858 2012-09-03 20:01:41Z paul $
   \date 28 Oct 2005
*/

#ifndef _atm_OverallQualityDB_h_
#define _atm_OverallQualityDB_h_

static const char CVSId_atm_OverallQualityDB[] =
  "$Id: OverallQualityDB.h 21858 2012-09-03 20:01:41Z paul $";

#include <string>
#include <map>
#include <boost/lexical_cast.hpp>

#include <det/VManager.h>
#include <det/Detector.h>
#include <utl/AugerException.h>

// temp tp
#include <iostream>

namespace atm {

  class OverallQualityZone;


  /**
    \brief
    Access to database describing overall atmospheric quality

    For an example of using this interface, see the ReadAtmQualityLLNS::ReadAtmQualityLL example

    \author Tom Paul
    \version $Id: OverallQualityDB.h 21858 2012-09-03 20:01:41Z paul $
    \date 28 Oct 2005
    \ingroup atm
  */

  class OverallQualityDB {

  public:
    // Horizontal uniformity across the array
    //
    double GetHorizontalUniformity() const;

    // Fractional cloud coverage
    //
    double GetCloudCoverage() const;

    // height of cloud base
    //
    double GetMinCloudBase() const;

  private:
    OverallQualityDB();
    ~OverallQualityDB();

    std::string fQualityIdString;  // specifies overall_quality_id for given time and software version

    mutable double* fHorizontalUniformity;
    mutable double* fCloudCoverage;
    mutable double* fMinCloudBase;

    template<class T>
    void
    GetQualData(T*& requested, const std::string& property)
      const
    {
      requested = new T;

      det::VManager::IndexMap emptyMap;

      try {
        const det::VManager& manager =
          det::Detector::GetInstance().GetAManagerRegister().GetManager("AOverallQualitySQLManager");

        const det::VManager::Status foundFlag =
          manager.GetData(*requested, "overall_quality", property, emptyMap);

        if (foundFlag == det::VManager::eFound)
          return;
      } catch (...) {
        delete requested;
        requested = 0;
        throw;
      }

      throw utl::DataNotFoundInDBException("overall_quality", "property", emptyMap,
                                           boost::lexical_cast<std::string>(det::Detector::GetInstance().GetTime()));
    }

    friend class Atmosphere;

  };

}


#endif // _atm_OverallQualityDB_h_

// Configure (x)emacs for this file ...
// Local Variables:
// mode: c++
// compile-command: "make -C .. -k"
// End: