DatabaseUtil.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // DatabaseUtil.h
3 //
4 // functions to talk to the Database
5 //
6 // andrzej.szelc@yale.edu
7 //
8 ////////////////////////////////////////////////////////////////////////
9 #ifndef DATABASEUTIL_H
10 #define DATABASEUTIL_H
11 
12 #include "fhiclcpp/ParameterSet.h"
16 #include <libpq-fe.h>
17 
18 ///General LArSoft Utilities
19 namespace util{
20 
21  class UBDaqID {
22  public:
23  UBDaqID() : crate(-1), card(-1), channel(-1) {};
24  UBDaqID( int _crate, int _card, int _channel ) :
25  crate(_crate), card(_card), channel(_channel) {};
26  ~UBDaqID() {};
27 
28  int crate;
29  int card;
30  int channel;
31 
32  const bool operator<(const UBDaqID& rhs) const {
33  bool is_less=false;
34  if (this->crate == rhs.crate &&
35  this->card == rhs.card &&
36  this->channel < rhs.channel) is_less=true;
37  else if (this->crate == rhs.crate &&
38  this->card < rhs.card) is_less=true;
39  else if (this->crate < rhs.crate) is_less=true;
40  return is_less;
41  }
42 
43  };
44 
45 
46  typedef int UBLArSoftCh_t;
47 
48  typedef std::map< UBDaqID, UBLArSoftCh_t > UBChannelMap_t;
49  typedef std::map< UBLArSoftCh_t, UBDaqID > UBChannelReverseMap_t;
50 
51 
52  class DatabaseUtil {
53  public:
54  DatabaseUtil(fhicl::ParameterSet const& pset);
55 
56  void reconfigure(fhicl::ParameterSet const& pset);
57 
58  int GetLifetimeFromDB(int run,double &lftime_real);
59  int GetTriggerOffsetFromDB(int run,double &T0_real);
60  int GetTemperatureFromDB(int run,double &temp_real);
61  int GetEfieldValuesFromDB(int run,std::vector<double> &efield);
62  int GetPOTFromDB(int run,long double &POT);
63  UBChannelMap_t GetUBChannelMap(int data_taking_timestamp = -1 , int swizzling_timestamp = -1 );
64  UBChannelReverseMap_t GetUBChannelReverseMap(int data_taking_timestamp = -1 , int swizzling_timestamp = -1 );
65 
66  int SelectFieldByName(std::vector<std::string> &value,const char * field,const char * condition,const char * table);
67  std::vector<std::string> & split(const std::string &s, char delim, std::vector<std::string> &elems);
68 
69  bool ToughErrorTreatment() const { return fToughErrorTreatment; }
70  bool ShouldConnect() const { return fShouldConnect; }
71 
72  private:
73 
74  int SelectSingleFieldByQuery(std::vector<std::string> &value,const char * query);
75  int Connect(int conn_wait=0);
76  int DisConnect();
77  char connection_str[200];
78 
79  PGconn *conn; // database connection handle
84  int fPort;
88 
89  UBChannelMap_t fChannelMap;
90  UBChannelReverseMap_t fChannelReverseMap;
91  void LoadUBChannelMap(int data_taking_timestamp = -1 , int swizzling_timestamp = -1 );
92 
93  }; // class DatabaseUtil
94 } //namespace util
95 
97 #endif
Namespace for general, non-LArSoft-specific utilities.
string delim()
Definition: fcldump.cxx:40
std::string fPassword
Definition: DatabaseUtil.h:85
std::string fDBName
Definition: DatabaseUtil.h:81
std::string string
Definition: nybbler.cc:12
const bool operator<(const UBDaqID &rhs) const
Definition: DatabaseUtil.h:32
std::string fDBHostName
Definition: DatabaseUtil.h:80
virtual void reconfigure(fhicl::ParameterSet const &pset)
#define DECLARE_ART_SERVICE(svc, scope)
UBDaqID(int _crate, int _card, int _channel)
Definition: DatabaseUtil.h:24
int UBLArSoftCh_t
Definition: DatabaseUtil.h:46
bool ToughErrorTreatment() const
Definition: DatabaseUtil.h:69
std::string fTableName
Definition: DatabaseUtil.h:83
std::map< UBDaqID, UBLArSoftCh_t > UBChannelMap_t
Definition: DatabaseUtil.h:48
bool ShouldConnect() const
Definition: DatabaseUtil.h:70
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
std::map< UBLArSoftCh_t, UBDaqID > UBChannelReverseMap_t
Definition: DatabaseUtil.h:49
query_result< Args... > query(sqlite3 *db, std::string const &ddl)
Definition: select.h:75
static QCString * s
Definition: config.cpp:1042
std::string fDBUser
Definition: DatabaseUtil.h:82
UBChannelReverseMap_t fChannelReverseMap
Definition: DatabaseUtil.h:90
UBChannelMap_t fChannelMap
Definition: DatabaseUtil.h:89