AEMDBInterface.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////
00002 /// $Id: AEMDBInterface.h,v 1.5 2005/08/15 17:31:32 hmeyer Exp $
00003 /// 
00004 /// Class which defines interface to database, taken from RunControl
00005 ///
00006 /// hmeyer@fnal.gov
00007 ////////////////////////////////////////////////////////////////////////
00008 
00009 #ifndef AEM_DB_INTERFACE_H
00010 #define AEM_DB_INTERFACE_H
00011 
00012 extern "C" {
00013 #include <libpq-fe.h>
00014 }
00015 #include <string>
00016 #include <vector>
00017 
00018 //----------------------------------------------------------------------
00019 
00020 class DBRunEntry {
00021  public:
00022   DBRunEntry();
00023   //DBRunEntry(fRun);
00024   ~DBRunEntry() {}
00025 
00026   void dump();
00027   int    Run() {return run;}
00028   
00029   long   RunTime() {return fRunTime;}
00030   double SpillLength() {return fSpillLength;}
00031   double Spills() {return fSpills;}
00032   double SpillTime() {return fSpillTime;}
00033   int    SpillEvents() {return fSpillEvents;}
00034   double DAQRate() {return fDAQRate;}
00035 
00036 
00037   int run;
00038   int nsubrun;
00039   int nevent;
00040   std::string target;
00041   double momentum;
00042   std::string datestart, dateend;
00043   long epochstart, epochend; // as epoch, seconds since 1-jan-1970 GMT
00044   // We are at CST, GMT+6: select DATE_PART('epoch','1-jan-1970'::date)/60/60; returns 6.
00045   // daylight savings and other complications apply
00046 
00047   int nspill, nemptyspill, nbeamspill;
00048   int trigcount[20];
00049   int goodrun;
00050 
00051   long   fRunTime;    //Run clock-time (start-end)
00052   double fSpillLength;//Spill length in seconds
00053   int    fSpills;     //Number of beam-spills
00054   double fSpillTime;  //Beam-spills times spill-length (seconds)
00055   int    fSpillEvents;//Number of events 
00056   double fDAQRate;    //Events per second
00057 };
00058 
00059 typedef std::vector<DBRunEntry> DBRunEntries;
00060 
00061 class AEMDBInterface {
00062  public:
00063   AEMDBInterface(std::string const Host);
00064   ~AEMDBInterface();
00065 
00066   int  GetRunNumber();             //return current run number
00067   int  GetnSubrun(int const fRun); //return number of subruns for run
00068   int  GetnSpill(int const fRun);  //return number of spills with beam for run
00069   int  GetnEvent(int const fRun);  //return number of in-spill events for run
00070   DBRunEntry GetRunEntry(int const fRun);
00071   DBRunEntries GetRunEntry(int const fRunMin, int const fRunMax);
00072   long GetRunEntry(std::string const fDateStart, DBRunEntries& fDBRuns);
00073   void GetRunEntry(DBRunEntries& fDBRuns);
00074 
00075  private:
00076   void Open();
00077 
00078   PGresult* ExecQuery(const char* query);
00079   void      ExecCommand(const char* command);
00080 
00081   void PutQueryToVector(PGresult* res, DBRunEntries& vec);
00082 
00083  private:
00084   // Object through which we interface to DB
00085   PGconn      *fDBConn;  
00086   std::string fDBHost;
00087 
00088 };
00089 
00090 #endif // AEM_DB_INTERFACE_H
00091 
00092 ////////////////////////////////////////////////////////////////////////

Generated on Mon Nov 23 08:01:43 2009 for MIPP(E907) by  doxygen 1.4.7