LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 
15 #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) : crate(_crate), card(_card), channel(_channel){};
25  ~UBDaqID(){};
26 
27  int crate;
28  int card;
29  int channel;
30 
31  const bool operator<(const UBDaqID& rhs) const
32  {
33  bool is_less = false;
34  if (this->crate == rhs.crate && this->card == rhs.card && this->channel < rhs.channel)
35  is_less = true;
36  else if (this->crate == rhs.crate && this->card < rhs.card)
37  is_less = true;
38  else if (this->crate < rhs.crate)
39  is_less = true;
40  return is_less;
41  }
42  };
43 
44  typedef int UBLArSoftCh_t;
45 
46  typedef std::map<UBDaqID, UBLArSoftCh_t> UBChannelMap_t;
47  typedef std::map<UBLArSoftCh_t, UBDaqID> UBChannelReverseMap_t;
48 
49  class DatabaseUtil {
50  public:
51  DatabaseUtil(fhicl::ParameterSet const& pset);
52 
53  void reconfigure(fhicl::ParameterSet const& pset);
54 
55  int GetLifetimeFromDB(int run, double& lftime_real);
56  int GetTriggerOffsetFromDB(int run, double& T0_real);
57  int GetTemperatureFromDB(int run, double& temp_real);
58  int GetEfieldValuesFromDB(int run, std::vector<double>& efield);
59  int GetPOTFromDB(int run, long double& POT);
60  UBChannelMap_t GetUBChannelMap(int data_taking_timestamp = -1, int swizzling_timestamp = -1);
61  UBChannelReverseMap_t GetUBChannelReverseMap(int data_taking_timestamp = -1,
62  int swizzling_timestamp = -1);
63 
64  int SelectFieldByName(std::vector<std::string>& value,
65  const char* field,
66  const char* condition,
67  const char* table);
68  std::vector<std::string>& split(const std::string& s,
69  char delim,
70  std::vector<std::string>& elems);
71 
72  bool ToughErrorTreatment() const { return fToughErrorTreatment; }
73  bool ShouldConnect() const { return fShouldConnect; }
74 
75  private:
76  int SelectSingleFieldByQuery(std::vector<std::string>& value, const char* query);
77  int Connect(int conn_wait = 0);
78  int DisConnect();
79  char connection_str[200];
80 
81  PGconn* conn; // database connection handle
82  std::string fDBHostName;
83  std::string fDBName;
84  std::string fDBUser;
85  std::string fTableName;
86  int fPort;
87  std::string fPassword;
90 
91  UBChannelMap_t fChannelMap;
92  UBChannelReverseMap_t fChannelReverseMap;
93  void LoadUBChannelMap(int data_taking_timestamp = -1, int swizzling_timestamp = -1);
94 
95  }; // class DatabaseUtil
96 } //namespace util
97 
99 #endif
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:26
std::string fPassword
Definition: DatabaseUtil.h:87
std::string fDBName
Definition: DatabaseUtil.h:83
const bool operator<(const UBDaqID &rhs) const
Definition: DatabaseUtil.h:31
std::string fDBHostName
Definition: DatabaseUtil.h:82
#define DECLARE_ART_SERVICE(svc, scope)
UBDaqID(int _crate, int _card, int _channel)
Definition: DatabaseUtil.h:24
int UBLArSoftCh_t
Definition: DatabaseUtil.h:44
bool ToughErrorTreatment() const
Definition: DatabaseUtil.h:72
double value
Definition: spectrum.C:18
std::map< UBDaqID, UBLArSoftCh_t > UBChannelMap_t
Definition: DatabaseUtil.h:46
std::string fTableName
Definition: DatabaseUtil.h:85
bool ShouldConnect() const
Definition: DatabaseUtil.h:73
std::map< UBLArSoftCh_t, UBDaqID > UBChannelReverseMap_t
Definition: DatabaseUtil.h:47
pg_conn PGconn
Definition: Table.h:17
std::string fDBUser
Definition: DatabaseUtil.h:84
UBChannelReverseMap_t fChannelReverseMap
Definition: DatabaseUtil.h:92
UBChannelMap_t fChannelMap
Definition: DatabaseUtil.h:91