All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
13 #include "art/Framework/Services/Registry/ActivityRegistry.h"
14 #include "art/Framework/Services/Registry/ServiceDeclarationMacros.h"
15 #include "art/Framework/Services/Registry/ServiceHandle.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
80  std::string fDBHostName;
81  std::string fDBName;
82  std::string fDBUser;
83  std::string fTableName;
84  int fPort;
85  std::string fPassword;
88 
91  void LoadUBChannelMap(int data_taking_timestamp = -1 , int swizzling_timestamp = -1 );
92 
93  }; // class DatabaseUtil
94 } //namespace util
95 
96 DECLARE_ART_SERVICE(util::DatabaseUtil, LEGACY)
97 #endif
int GetTriggerOffsetFromDB(int run, double &T0_real)
std::string fPassword
Definition: DatabaseUtil.h:85
int GetEfieldValuesFromDB(int run, std::vector< double > &efield)
std::string fDBName
Definition: DatabaseUtil.h:81
double POT
const bool operator<(const UBDaqID &rhs) const
Definition: DatabaseUtil.h:32
UBChannelMap_t GetUBChannelMap(int data_taking_timestamp=-1, int swizzling_timestamp=-1)
UBChannelReverseMap_t GetUBChannelReverseMap(int data_taking_timestamp=-1, int swizzling_timestamp=-1)
int SelectSingleFieldByQuery(std::vector< std::string > &value, const char *query)
std::string fDBHostName
Definition: DatabaseUtil.h:80
int GetPOTFromDB(int run, long double &POT)
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
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo W echo The symbol is a weak symbol that has not been specifically echo tagged as a weak object symbol When a weak defined symbol echo is linked with a normal defined the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo echo The symbol is a stabs symbol in an a out object file In echo this the next values printed are the stabs other field
char connection_str[200]
Definition: DatabaseUtil.h:77
int GetLifetimeFromDB(int run, double &lftime_real)
DatabaseUtil(fhicl::ParameterSet const &pset)
Definition: DatabaseUtil.cc:19
createEngine this
void reconfigure(fhicl::ParameterSet const &pset)
Definition: DatabaseUtil.cc:70
std::string fTableName
Definition: DatabaseUtil.h:83
void LoadUBChannelMap(int data_taking_timestamp=-1, int swizzling_timestamp=-1)
int SelectFieldByName(std::vector< std::string > &value, const char *field, const char *condition, const char *table)
std::map< UBDaqID, UBLArSoftCh_t > UBChannelMap_t
Definition: DatabaseUtil.h:48
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
int Connect(int conn_wait=0)
Definition: DatabaseUtil.cc:28
bool ShouldConnect() const
Definition: DatabaseUtil.h:70
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
temporary value
std::map< UBLArSoftCh_t, UBDaqID > UBChannelReverseMap_t
Definition: DatabaseUtil.h:49
std::string fDBUser
Definition: DatabaseUtil.h:82
UBChannelReverseMap_t fChannelReverseMap
Definition: DatabaseUtil.h:90
int GetTemperatureFromDB(int run, double &temp_real)
UBChannelMap_t fChannelMap
Definition: DatabaseUtil.h:89