StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_db_Maker.h
1 // $Id: St_db_Maker.h,v 1.46 2015/05/05 21:05:52 dmitry Exp $
2 // $Log: St_db_Maker.h,v $
3 // Revision 1.46 2015/05/05 21:05:52 dmitry
4 // Updated db disconnect handling. Keep connection if less than 30 sec passed since last data retrieval
5 //
6 // Revision 1.45 2015/05/05 20:42:14 dmitry
7 // dynamic db disconnects handling
8 //
9 // Revision 1.44 2014/08/06 11:43:54 jeromel
10 // Suffix on literals need to be space (later gcc compiler makes it an error) - first wave of fixes
11 //
12 // Revision 1.43 2013/07/18 14:00:32 fisyak
13 // expand no. of possible databases from 4 to 10
14 //
15 // Revision 1.42 2012/03/16 19:36:18 dmitry
16 // converted dangled char pointers to std::string objects + fixed typo
17 //
18 // Revision 1.41 2011/11/28 17:03:09 dmitry
19 // dbv override support in StDbLib,StDbBroker,St_db_Maker
20 //
21 // Revision 1.40 2011/03/19 02:50:57 perev
22 // blacklist added
23 //
24 // Revision 1.38 2010/05/05 18:35:04 dmitry
25 // addon: single datasets also saved
26 //
27 // Revision 1.37 2010/05/05 15:25:51 dmitry
28 // refactored snapshot code, to include Valeri's patch (save .root files)
29 //
30 // Revision 1.36 2010/04/28 07:23:40 dmitry
31 // =new method to save snapshot+one subsequent dataset for each table in db
32 //
33 // Revision 1.35 2010/04/17 02:07:19 perev
34 // Method Drop added
35 //
36 // Revision 1.34 2010/01/27 21:34:20 perev
37 // GetValidity now is static
38 //
39 // Revision 1.33 2009/11/16 20:16:23 fine
40 // Make the TDatime const interfaces
41 //
42 // Revision 1.32 2008/04/02 20:22:33 perev
43 // WarnOff
44 //
45 // Revision 1.31 2008/01/09 20:44:52 perev
46 // Improve printout in Finish()
47 //
48 // Revision 1.30 2007/12/29 01:43:24 perev
49 // More dbStat
50 //
51 // Revision 1.29 2007/09/10 02:20:10 perev
52 // StDbBroker::Release used
53 //
54 // Revision 1.28 2007/07/02 19:36:40 fisyak
55 // Add parameter currenTime (== requested time) in FindLeft
56 //
57 // Revision 1.27 2007/03/09 20:01:03 perev
58 // Request by user defined time now allowed
59 //
60 // Revision 1.26 2006/08/15 21:42:21 jeromel
61 // Fix rhic -> rhic.bnl.gov
62 //
63 // Revision 1.25 2005/07/20 17:41:44 perev
64 // Cleanup
65 //
66 // Revision 1.24 2004/08/18 20:33:56 perev
67 // Timers added for MySQL and maker itself
68 //
69 // Revision 1.23 2004/07/23 17:06:58 perev
70 // AliasDate & AliasTime moved fro db maker to StMaker
71 //
72 // Revision 1.22 2004/04/08 00:28:53 perev
73 // AliasDate & AliasTime now static methods
74 //
75 // Revision 1.21 2002/12/20 03:28:37 perev
76 // Save method improved
77 //
78 // Revision 1.20 2002/11/26 02:24:45 perev
79 // new ROOT adoptation
80 //
81 // Revision 1.19 2001/10/27 21:48:32 perev
82 // SetRunNumber added
83 //
84 // Revision 1.18 2001/10/13 20:23:25 perev
85 // SetFlavor working before and after Init()
86 //
87 // Revision 1.17 2001/09/26 23:24:05 perev
88 // SetFlavor for table added
89 //
90 // Revision 1.16 2001/04/13 21:21:34 perev
91 // small fix (fine) + cons's
92 //
93 // Revision 1.15 2000/07/14 02:39:21 perev
94 // SetMaxEntryTime method added
95 //
96 // Revision 1.14 2000/06/26 20:58:41 perev
97 // multiple DBs
98 //
99 // Revision 1.13 2000/05/20 01:00:43 perev
100 // SetFlavor() added
101 //
102 // Revision 1.12 2000/04/13 02:58:47 perev
103 // Method Save is added & default CintDB loaded if exists
104 //
105 // Revision 1.11 2000/03/23 14:55:56 fine
106 // Adjusted to libSTAR and ROOT 2.24
107 //
108 // Revision 1.10 2000/02/26 01:45:04 fine
109 // CVS id has been introduced
110 //
111 //
112 #ifndef STAR_St_db_Maker
113 #define STAR_St_db_Maker
114 
116 // //
117 // St_db_Maker virtual base class for Maker //
118 // //
119 // This class is C++ implementation of the Begin_html <a href="http://www.rhic.bnl.gov/afs/rhic.bnl.gov/star/doc/www/packages_l/pro/pams/db/sdb/doc/index.html">Simple Database Manager</a> End_html //
120 // //
122 #ifndef StMaker_H
123 #include "StMaker.h"
124 #endif
125 #include "TTable.h"
126 
127 #include "TDatime.h"
128 #include "StDbBroker/dbConfig.h"
129 
130 #include <map>
131 #include <utility>
132 #include <list>
133 
134 class TFileSet;
135 class TList;
136 class TBrowser;
137 class StDbBroker;
138 class St_dbConfig;
139 class StValiSet;
140 
141 class St_db_Maker : public StMaker {
142 private:
143 
144  TDataSet *fDataBase;
145  StDbBroker *fDBBroker;
146  St_dbConfig *fHierarchy;
147  TString fDirs[10];
148  Int_t fIsDBTime;
149  TDatime fDBTime;
150  Int_t fUpdateMode;
151  UInt_t fMaxEntryTime;
152  std::map<std::pair<std::string,std::string>,UInt_t> fMaxEntryTimeOverride; // DBV override for specific subsystems
153  TStopwatch fTimer[6];
154  int fEvents[2]; // [0]=nEvents [1]=events with mysql request
155  int fDataSize[2]; // [0]=mysql data this event; [1]=total
156  time_t fQueryTs; // timestamps of recent db fetch
157 
158 // static Char_t fVersionCVS = "$Id: St_db_Maker.h,v 1.46 2015/05/05 21:05:52 dmitry Exp $";
159  protected:
160  public:
161  St_db_Maker(const char *name
162  ,const char *dir0
163  ,const char *dir1 = ""
164  ,const char *dir2 = ""
165  ,const char *dir3 = ""
166  ,const char *dir4 = ""
167  ,const char *dir5 = ""
168  ,const char *dir6 = ""
169  ,const char *dir7 = ""
170  ,const char *dir8 = ""
171  ,const char *dir9 = ""
172  );
173  virtual ~St_db_Maker();
174  virtual TDataSet *GetDataBase(const char* logInput, const TDatime *td=0);
175  virtual const TDatime &GetDateTime() const;
176  static Int_t GetValidity(const TTable *tb, TDatime *const val);
177  virtual void SetDateTime(int idat,int itim);
178  virtual void SetDateTime(const char *datalias);
179  virtual Int_t InitRun(int runumber);
180  virtual Int_t Init();
181  virtual Int_t Make();
182  virtual Int_t Save(const char *path,const TDatime *newtime=0);
183  virtual Int_t SaveSnapshotPlus(char* path, int type = 0); // snapshot mode, type: 0 = .root, 1 = .C
184  virtual void SetOff(const Char_t *path);
185  virtual void SetOn (const Char_t *path);
186  virtual void SetFlavor(const char *flav,const char *tabname=".all");
187  virtual void OnOff();
188  virtual void Clear(Option_t *opt="");
189  virtual Int_t Finish();
190  void SetMaxEntryTime(Int_t idate,Int_t itime);
191  void AddMaxEntryTimeOverride(Int_t idate,Int_t itime, char* dbType = 0, char* dbDomain = 0);
192 private:
193  virtual TDataSet* UpdateDB (TDataSet* ds);
194  virtual int UpdateTable(UInt_t parId, TTable* dat, const TDatime &req, TDatime val[2]);
195  virtual TDataSet *LoadTable(TDataSet* left);
196  virtual TDataSet *FindLeft(StValiSet *val, TDatime vals[2], const TDatime &currenTime);
197  virtual TDataSet *OpenMySQL(const char* dbname);
198  virtual Int_t SaveDataSet(TDataSet* ds, int type, bool savenext); // prepares directory and calls appropriate save method
199  virtual Int_t SaveDataSetAsCMacro(TTable* tb, TString ds_name, bool savenext); // creates [dataset_name].[beginTime].[endTime].C file
200  virtual Int_t SaveDataSetAsRootFile(TTable* tb, TString ds_name, bool savenext); // creates [dataset_name].[beginTime].[endTime].root file
201  static Int_t Drop(TDataSet *ds);
202  int Snapshot (int flag);
203 
204  static EDataSetPass UpdateDB (TDataSet* ds,void *user );
205  static EDataSetPass PrepareDB(TDataSet* ds,void *user );
206  int UpdateValiSet(StValiSet *val,const TDatime &currenTime);
207 public:
208  static TDatime Time(const char *filename);
209  static int Kind(const char *filename);
210 
211  virtual const char *GetCVS() const
212  {static const char cvs[]="Tag $Name: $ $Id: St_db_Maker.h,v 1.46 2015/05/05 21:05:52 dmitry Exp $ built " __DATE__ " " __TIME__ ; return cvs;}
213 
214  ClassDef(St_db_Maker, 0)
215 };
216 
217 class St_dbConfig : public TTable
218 {
219  ClassDefTable(St_dbConfig,dbConfig_st)
220  ClassDef(St_dbConfig,2)
221 };
222 
223 #endif
virtual void Clear(Option_t *opt="")
User defined functions.
virtual Int_t Make()
virtual Int_t Finish()
Definition: TTable.h:48