HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoDB.h
Go to the documentation of this file.
1 #ifndef HARPODB_H
2 #define HARPODB_H
3 //
5 // HarpoDB
6 //
7 // Harpo Database Manipulation
8 //
9 
10 #include "TList.h"
11 #include "TObjString.h"
12 #include "TString.h"
13 #include <map>
14 #include <list>
15 
16 class TSQLServer;
17 
18 // Name,valus for one row
19 typedef std::map<TString,TString> dbFields;
20 //list of pams for all resulting rows
21 typedef std::list<dbFields> dbResults;
22 
23 // One run record monipulation, fields updates
24 class HarpoDBRow {
25 
26  public:
27  HarpoDBRow() : run(0) {}
28  virtual ~HarpoDBRow() {}
29 
31  void list();
32 
34  Bool_t Lookup(const TString field);
35 
37  Bool_t GetVal(const TString field, TString &val);
38 
39  //Set value for existing field
40  Bool_t SetVal(const TString field, TString val);
41  Bool_t SetVal(const TString field, Long_t val);
42  Bool_t SetVal(const TString field, Double_t val);
43 
44  // Get Map of fields types
45  dbFields& GetFields() { return fields; }
46  // Set Map of fields types
47  void SetFields(dbFields f);
48 
49  //Erase field from map
50  void Erase(const TString &field) { fields.erase(field); }
51 
53  Long_t GetNrun() { return run; }
54  void SetRun(Long_t r) { run = r; SetVal("run",r); }
55 
56 
57  private:
58  Long_t run;
60 };
61 
62 // Work with one table , select, update, insert records, record iteretor
63 class HarpoDBTable {
64 
65 public:
68 
69  const TString GetName() { return name; }
71  Bool_t GetRunRow(Long_t nrun,HarpoDBRow &row);
72 
75  Bool_t InsertRunRow(HarpoDBRow row,const TString option="");
76 
79  Bool_t UpdateRunRow(HarpoDBRow row,const TString option="");
80 
82  Bool_t DeleteRun(Long_t run);
83 
85  Bool_t Lookup(const TString field);
86 
88  Bool_t GetType(const TString field, TString &type);
89 
91  Bool_t TypeExpression(const TString field);
92 
93  // Get Map of fields types
94  dbFields & GetFiledsTypes() { return ftypes; }
95 
96  //Erase field from map
97  void Erase(const TString &field) { ftypes.erase(field); }
98 
99  // Connect to table and read type info ( use by HarpoDB)
100  Bool_t Open(const char *dbnm, const char *tbl);
101 
102  // list rows in table
103  void list();
104  // Make root class
105  void MakeClass(TString cname,TString option="");
106 private:
107  TString name;
109 };
110 
111 // Open/Close DB, list tables , get table class pointer
112 class HarpoDB {
113 
114 public:
115  HarpoDB() : fTables(NULL) {}
116  virtual~HarpoDB() { delete fTables;}
117 
118  static void SetUser(TString u, TString p);
119  static void SetDBUrl(const TString &DbUrl) { dbUrl = DbUrl; }
120  Bool_t Open(const TString *DbUrl=NULL);
121  Bool_t Close();
122  Bool_t GetTable(const TString name,HarpoDBTable *table)
123  {return GetTable(name,*table);}
124  Bool_t GetTable(const TString name,HarpoDBTable &table);
125 
126  Bool_t ExecQuery(const TString sql,dbResults *list = NULL);
127 
128  // list tables in db
129  void list();
130  TList *GetListOfTables() { return fTables; }
131 
132  //static
133  static TSQLServer *GetDBServer() { return db; }
134  static const char *GetDBName();
135 
136 private:
137  static TSQLServer *db;
138  static TString dbUrl;
139  static TString dbuser;
140  static TString dbpw;
141  TList *fTables;
142 };
143 #endif
144 // Local Variables:
145 // mode: c++
146 // End:
Bool_t Open(const char *dbnm, const char *tbl)
Definition: HarpoDB.cxx:140
Bool_t UpdateRunRow(HarpoDBRow row, const TString option="")
Definition: HarpoDB.cxx:408
Bool_t GetRunRow(Long_t nrun, HarpoDBRow &row)
Query Table for given run information.
Definition: HarpoDB.cxx:206
~HarpoDBTable()
Definition: HarpoDB.h:67
static TSQLServer * db
Definition: HarpoDB.h:137
virtual ~HarpoDBRow()
Definition: HarpoDB.h:28
static void SetUser(TString u, TString p)
Definition: HarpoDB.cxx:60
Bool_t Lookup(const TString field)
Lookup filed exist.
Definition: HarpoDB.cxx:305
HarpoDB()
Definition: HarpoDB.h:115
virtual ~HarpoDB()
Definition: HarpoDB.h:116
void list()
Definition: HarpoDB.cxx:65
Bool_t Open(const TString *DbUrl=NULL)
Definition: HarpoDB.cxx:77
static const char * GetDBName()
Definition: HarpoDB.cxx:55
std::list< dbFields > dbResults
Definition: HarpoDB.h:21
TList * GetListOfTables()
Definition: HarpoDB.h:130
void list()
Definition: HarpoDB.cxx:286
Long_t GetNrun()
Get method for run number of this record.
Definition: HarpoDB.h:53
static TSQLServer * GetDBServer()
Definition: HarpoDB.h:133
dbFields fields
Definition: HarpoDB.h:59
Bool_t GetTable(const TString name, HarpoDBTable *table)
Definition: HarpoDB.h:122
Bool_t InsertRunRow(HarpoDBRow row, const TString option="")
Definition: HarpoDB.cxx:477
HarpoDBRow()
Definition: HarpoDB.h:27
Bool_t SetVal(const TString field, TString val)
Definition: HarpoDB.cxx:322
Bool_t DeleteRun(Long_t run)
Delete run from table.
Definition: HarpoDB.cxx:383
Bool_t Lookup(const TString field)
Lookup filed exist.
Definition: HarpoDB.cxx:299
Bool_t GetVal(const TString field, TString &val)
Return value of existing field in Tstring.
Definition: HarpoDB.cxx:311
TString name
Definition: HarpoDB.h:107
Bool_t TypeExpression(const TString field)
Mark filed as expression for insert and update.
Definition: HarpoDB.cxx:371
static int type
dbFields & GetFiledsTypes()
Definition: HarpoDB.h:94
TList * fTables
Definition: HarpoDB.h:141
static TString dbUrl
Definition: HarpoDB.h:138
Harpo Database access class. The class query MySQL database. Deal with (single !) Harpo Database and ...
Definition: HarpoDB.h:112
void SetRun(Long_t r)
Definition: HarpoDB.h:54
Bool_t ExecQuery(const TString sql, dbResults *list=NULL)
Definition: HarpoDB.cxx:170
void Erase(const TString &field)
Definition: HarpoDB.h:97
static void SetDBUrl(const TString &DbUrl)
Definition: HarpoDB.h:119
dbFields & GetFields()
Definition: HarpoDB.h:45
const TString GetName()
Definition: HarpoDB.h:69
dbFields ftypes
Definition: HarpoDB.h:108
static TString dbuser
Definition: HarpoDB.h:139
void Erase(const TString &field)
Definition: HarpoDB.h:50
static TString dbpw
Definition: HarpoDB.h:140
Long_t run
Definition: HarpoDB.h:58
void list()
list all fields with values
Definition: HarpoDB.cxx:274
std::map< TString, TString > dbFields
Definition: HarpoDB.h:16
Bool_t GetType(const TString field, TString &type)
Return Type of field in TString.
Definition: HarpoDB.cxx:360
Bool_t Close()
Definition: HarpoDB.cxx:111
void SetFields(dbFields f)
Definition: HarpoDB.cxx:345
HarpoDBTable()
Definition: HarpoDB.h:66
void MakeClass(TString cname, TString option="")
Definition: HarpoDB.cxx:569