#ifndef __JDB_JRUNS__
#define __JDB_JRUNS__

#include <TROOT.h>
#include <TObject.h>

#include <string>

/**
 * \author mdejong
 */
namespace JDATABASE {}
namespace JPP { using namespace JDATABASE; }

namespace JDATABASE {

  struct JRuns :
    public TObject
  {
    static const char* const getName() { return "runs"; } //!< Table name

    int           DETID;                   ///< constraint
    int           RUN;
    long long int UNIXSTARTTIME;
    char          STARTTIME_DEFINED;
    std::string   RUNSETUPID;
    std::string   RUNSETUPNAME;
    std::string   T0_CALIBSETID;
    std::string   POS_CALIBSETID;
    std::string   ROT_CALIBSETID;
    std::string   RUNJOBID;
    std::string   JOBTARGET;
    int           JOBPRIORITY;
    long long int UNIXJOBSTART;
    long long int UNIXJOBEND;

    /**
     * Get start time of run.
     *
     * \return             time [s]
     */
    inline double getRunStartTime() const
    {
      return UNIXSTARTTIME * 1.0e-3;
    }

    ClassDef(JRuns, 2);
  };


  /**
   * Less-than operator.
   *
   * \param  first         first  run
   * \param  second        second run
   * \return               true if first run less than second; else false
   */
  inline bool operator<(const JRuns& first, 
                        const JRuns& second)
  {
    if (first.DETID == second.DETID)
      return first.RUN   < second.RUN;
    else
      return first.DETID < second.DETID;
  }
}

#endif