00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 #ifndef STAR_StDbBroker
00114 #define STAR_StDbBroker
00115
00116 #include "Rtypes.h"
00117 #include "dbNodeArray.h"
00118 #include "dbConfig.h"
00119
00120
00121
00122
00123
00124
00125
00126
00127 #include "St_tableDescriptor.h"
00128
00129 #include <map>
00130 #include <utility>
00131
00132 class StDbConfigNode;
00133 class StDbManager;
00134 class StTableDescriptorI;
00135 class StDbTable;
00136
00137
00138 class TTable;
00139
00140
00141 class StDbBroker {
00142 public:
00143 enum EColumnType {kNAN, kFloat, kInt, kLong, kShort, kDouble, kUInt
00144 ,kULong, kUShort, kUChar, kChar };
00145
00146 typedef St_tableDescriptor Descriptor;
00147
00148
00149 struct oldDescriptor {
00150 char fColumnName[32];
00151 unsigned int fIndexArray[3];
00152 unsigned int fOffset;
00153 unsigned int fSize;
00154 unsigned int fTypeSize;
00155 unsigned int fDimensions;
00156 Int_t fType;
00157 };
00158
00159 protected:
00160 StDbTable* m_node;
00161 oldDescriptor *m_descriptor;
00162 Descriptor *mdescriptor;
00163 Char_t * m_structName;
00164 Char_t * m_tableName;
00165 UInt_t m_sizeOfStruct;
00166 UInt_t m_nElements;
00167 UInt_t m_nRows;
00168
00169 Int_t m_DateTime[2];
00170
00171 Int_t m_BeginDate;
00172 Int_t m_BeginTime;
00173 Int_t m_EndDate;
00174 Int_t m_EndTime;
00175
00176 UInt_t m_beginTimeStamp;
00177 UInt_t m_endTimeStamp;
00178 UInt_t m_requestTimeStamp;
00179
00180 Int_t m_runNumber;
00181
00182 char* m_tableVersion;
00183 char* m_database;
00184 char* m_ParentType;
00185
00186 int m_isVerbose;
00187 dbNodeArray *m_Nodes;
00188 StDbConfigNode* m_Tree;
00189
00190 char* m_flavor;
00191 unsigned int m_prodTime;
00192 std::map<std::pair<char*,char*>,unsigned int> m_prodTimeOverride;
00193
00194 dbConfig_st* buildConfig(int& numRows);
00195 int buildNodes(StDbConfigNode* node, int pID);
00196
00197 Bool_t m_isZombie;
00198
00199 void makeDateTime(const char* dateTime, Int_t & iDate, Int_t & iTime);
00200
00201 public:
00202
00203 StDbBroker();
00204 virtual ~StDbBroker();
00205
00206
00207
00208 void * Use();
00209 void SetTableFlavor(const char* flavor, int tabID, int parID);
00210 void * Use(int tabID, int parID);
00211 bool UseRunLog(StDbTable* table);
00212
00213 char **GetComments(St_Table *parentTable);
00214
00215
00216
00217
00218
00219 Int_t WriteToDb(void* pArray, int tabID);
00220
00221
00222
00223
00224
00225 Int_t WriteToDb(void* pArray, const char* fullPath, int* idList=0);
00226
00227 StDbTable* findTable(const char* databaseName);
00228
00229 UInt_t GetNRows() {return m_nRows; }
00230 Int_t GetBeginDate() {return m_BeginDate; }
00231 Int_t GetBeginTime() {return m_BeginTime; }
00232 const char *GetFlavor();
00233 Int_t GetEndDate() {return m_EndDate; }
00234 Int_t GetEndTime() {return m_EndTime; }
00235 UInt_t GetRequestTimeStamp() {return m_requestTimeStamp; }
00236 UInt_t GetBeginTimeStamp() {return m_beginTimeStamp; }
00237 UInt_t GetEndTimeStamp() {return m_endTimeStamp; }
00238 UInt_t GetProdTime() {return m_prodTime;}
00239 Bool_t IsZombie() {return m_isZombie; }
00240
00241
00242 StTableDescriptorI* GetTableDescriptor();
00243
00244 void loadOldDescriptor(){};
00245 static const Char_t * GetTypeName( EColumnType type) {
00246 switch (type)
00247 {
00248 case kFloat: return "float";
00249 case kInt: return "int";
00250 case kLong: return "long";
00251 case kShort: return "short";
00252 case kDouble: return "double";
00253 case kChar: return "char";
00254
00255 case kUInt: return "int";
00256 case kULong: return "long";
00257 case kUShort: return "short";
00258 case kUChar: return "char";
00259
00260 case kNAN: return "";
00261 default: return "";
00262 }
00263 };
00264
00265 void SetDateTime(Int_t date,Int_t time);
00266 void SetRunNumber(Int_t runNumber) {m_runNumber=runNumber;};
00267 void SetDictionary(UInt_t nElements, Descriptor *D)
00268 {m_nElements=nElements; mdescriptor = D;}
00269 void SetDictionary(Descriptor *D)
00270 {if (D) { mdescriptor = D;m_nElements=D->NumberOfColumns();}}
00271 void SetTableName(const Char_t *table_name)
00272 {if(m_tableName) delete [] m_tableName;
00273 m_tableName=new char[strlen(table_name)+1];
00274 strcpy(m_tableName,table_name);};
00275 void SetStructName(const Char_t *struct_name)
00276 {if(m_structName) delete [] m_structName;
00277 m_structName=new char[strlen(struct_name)+1];
00278 strcpy(m_structName,struct_name);};
00279 void SetVersionName(const char *version)
00280 {if(m_tableVersion) delete [] m_tableVersion;
00281 m_tableVersion= new char[strlen(version)+1];
00282 strcpy(m_tableVersion,version);}
00283 void SetDataBaseName(const char *dbName)
00284 {if(m_database) delete [] m_database;
00285 m_database= new char[strlen(dbName)+1];
00286 strcpy(m_database,dbName);}
00287
00288 void SetStructSize(UInt_t size) {m_sizeOfStruct=size; };
00289 void SetNRows(UInt_t nRows) {m_nRows = nRows; }
00290 void SetBeginDate(Int_t BeginDate) {m_BeginDate = BeginDate;}
00291 void SetBeginTime(Int_t BeginTime) {m_BeginTime = BeginTime;}
00292 void SetEndDate(Int_t EndDate) {m_EndDate = EndDate; }
00293 void SetEndTime(Int_t EndTime) {m_EndTime = EndTime; }
00294 void SetRequestTimeStamp(UInt_t utime) {m_requestTimeStamp = utime; }
00295 void SetBeginTimeStamp(UInt_t utime) {m_beginTimeStamp = utime; }
00296 void SetEndTimeStamp(UInt_t utime) {m_endTimeStamp = utime; }
00297 void SetProdTime(UInt_t ptime);
00298 void AddProdTimeOverride(UInt_t ptime, char* dbType = 0, char* dbDomain = 0);
00299 void SetFlavor(const char* flavor);
00300 void SetZombie(Bool_t zombie) { m_isZombie=true; }
00301
00302 void addBlacklistedDomain(const char* domainName);
00303
00304 static int DbInit(const char *);
00305 void setVerbose(int isVerbose) { m_isVerbose = isVerbose; }
00306 void printStatistics();
00307 void CloseAllConnections();
00308 void Release();
00309
00310
00311 dbConfig_st* InitConfig(const char* configName, int& numRows, char* versionName=0);
00312 StDbManager* mgr;
00313
00314 ClassDef(StDbBroker,0)
00315 };
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 extern "C" void *DbUse(unsigned int*,
00329 unsigned int *,
00330 const char *,
00331 const char *,
00332 unsigned int,
00333 unsigned int,
00334 StDbBroker::oldDescriptor *d);
00335
00336 extern "C" void *DbRead(unsigned int*,
00337 unsigned int *,
00338 const char *,
00339 const char *,
00340 unsigned int,
00341 unsigned int,
00342 StDbBroker::oldDescriptor *d,
00343 const char*,
00344 const char*);
00345
00346 extern "C" int DbInit(const char *);
00347
00348 #endif
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359