LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
DatabaseUtil.h
Go to the documentation of this file.
1 // DatabaseUtil.h
3 //
4 // functions to talk to the Database
5 //
6 // andrzej.szelc@yale.edu
7 //
9 #ifndef DATABASEUTIL_H
10 #define DATABASEUTIL_H
11 
12 #include "fhiclcpp/ParameterSet.h"
16 #include <libpq-fe.h>
17 
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:
55  ~DatabaseUtil();
56 
57  void reconfigure(fhicl::ParameterSet const& pset);
58 
59  int GetLifetimeFromDB(int run,double &lftime_real);
60  int GetTriggerOffsetFromDB(int run,double &T0_real);
61  int GetTemperatureFromDB(int run,double &temp_real);
62  int GetEfieldValuesFromDB(int run,std::vector<double> &efield);
63  int GetPOTFromDB(int run,long double &POT);
64  UBChannelMap_t GetUBChannelMap(int data_taking_timestamp = -1 , int swizzling_timestamp = -1 );
65  UBChannelReverseMap_t GetUBChannelReverseMap(int data_taking_timestamp = -1 , int swizzling_timestamp = -1 );
66 
67  int SelectFieldByName(std::vector<std::string> &value,const char * field,const char * condition,const char * table);
68  std::vector<std::string> & split(const std::string &s, char delim, std::vector<std::string> &elems);
69 
70  bool ToughErrorTreatment() const { return fToughErrorTreatment; }
71  bool ShouldConnect() const { return fShouldConnect; }
72 
73  private:
74 
75  int SelectSingleFieldByQuery(std::vector<std::string> &value,const char * query);
76  int Connect(int conn_wait=0);
77  int DisConnect();
78  char connection_str[200];
79 
80  PGconn *conn; // database connection handle
81  std::string fDBHostName;
82  std::string fDBName;
83  std::string fDBUser;
84  std::string fTableName;
85  int fPort;
86  std::string fPassword;
89 
90  UBChannelMap_t fChannelMap;
91  UBChannelReverseMap_t fChannelReverseMap;
92  void LoadUBChannelMap(int data_taking_timestamp = -1 , int swizzling_timestamp = -1 );
93 
94  }; // class DatabaseUtil
95 } //namespace util
96 
98 #endif
Float_t s
Definition: plot.C:23
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:17
std::string fPassword
Definition: DatabaseUtil.h:86
std::string fDBName
Definition: DatabaseUtil.h:82
#define DECLARE_ART_SERVICE(svc, scope)
Definition: ServiceMacros.h:91
const bool operator<(const UBDaqID &rhs) const
Definition: DatabaseUtil.h:32
std::string fDBHostName
Definition: DatabaseUtil.h:81
UBDaqID(int _crate, int _card, int _channel)
Definition: DatabaseUtil.h:24
int UBLArSoftCh_t
Definition: DatabaseUtil.h:46
bool ToughErrorTreatment() const
Definition: DatabaseUtil.h:70
pg_conn PGconn
Definition: Table.h:17
std::string fTableName
Definition: DatabaseUtil.h:84
std::string value(boost::any const &)
std::map< UBDaqID, UBLArSoftCh_t > UBChannelMap_t
Definition: DatabaseUtil.h:48
bool ShouldConnect() const
Definition: DatabaseUtil.h:71
std::map< UBLArSoftCh_t, UBDaqID > UBChannelReverseMap_t
Definition: DatabaseUtil.h:49
std::string fDBUser
Definition: DatabaseUtil.h:83
UBChannelReverseMap_t fChannelReverseMap
Definition: DatabaseUtil.h:91
UBChannelMap_t fChannelMap
Definition: DatabaseUtil.h:90