00001 class St_db_Maker;
00002 St_db_Maker *dbMk = 0;
00003 class TTable;
00004 TTable *table = 0;
00005
00006 void Load() {
00007 if (gClassTable->GetID("StDbManager") < 0) {
00008
00009
00010 gSystem->Load("St_base");
00011 gSystem->Load("liblog4cxx.so");
00012 gSystem->Load("StStarLogger");
00013 gSystem->Load("StChain");
00014 gSystem->Load("StUtilities");
00015
00016
00017
00018
00019 Char_t *mysql = "libmysqlclient";
00020 Char_t *libs[] = {"", "/usr/mysql/lib/","/usr/lib/", 0};
00021
00022 Int_t i = 0;
00023 while ((libs[i])) {
00024 TString lib(libs[i]);
00025 lib += mysql;
00026 lib = gSystem->ExpandPathName(lib.Data());
00027 if (gSystem->DynamicPathName(lib,kTRUE)) {
00028 gSystem->Load(lib.Data()); cout << " + " << lib.Data() << endl;
00029 break;
00030 }
00031 i++;
00032 }
00033 gSystem->Load("St_Tables.so");
00034 gSystem->Load("StDbLib.so");
00035 gSystem->Load("StDbBroker.so");
00036 gSystem->Load("St_db_Maker.so");
00037 }
00038
00039 dbMk = new St_db_Maker("db","MySQL:StarDb","$STAR/StarDb","$PWD/StarDb");
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 }
00056
00057
00058 void Db(const Char_t *tabNam =
00059 "Calibrations/svt/svtBadAnodes",
00060 Int_t date = 20091215, Int_t time = 0,
00061 Int_t debugL = 1,
00062 const Char_t *flavor="sim+ofl"
00063 ){
00064 if (dbMk == 0) Load();
00065 dbMk->SetDebug(debugL);
00066 dbMk->SetDateTime(date,time);
00067 TString TabNam(tabNam);
00068 if (TabNam.BeginsWith("StarDb/")) TabNam.ReplaceAll("StarDb/","");
00069 TString name(gSystem->BaseName(tabNam));
00070 TString Flavor(flavor);
00071 if (flavor != "") dbMk->SetFlavor(flavor,name);
00072 dbMk->Init();
00073 table = (TTable *) dbMk->GetDataBase(TabNam);
00074 if (table) {
00075 TDatime t[2];
00076 dbMk->GetValidity(table,t);
00077 cout << "==============================================" << endl;
00078 Int_t Nrows = table->GetNRows();
00079 cout << "Found table " << table->GetName() << " with NRows = " << Nrows << " in db" << endl;
00080 cout << "Validity:" << t[0].GetDate() << "/" << t[0].GetTime()
00081 << " ----- " << t[1].GetDate() << "/" << t[1].GetTime() << endl;
00082 if (Nrows > 10) Nrows = 10;
00083
00084 cout << "==============================================" << endl;
00085 #if 0
00086 name += Form(".%06i.%06i.root",t[0].GetDate(),t[0].GetTime());
00087 TFile *f = new TFile(name.Data(),"RECREATE");
00088 table->Write();
00089 delete f;
00090 #else
00091 name += Form(".%06i.%06i.C",t[0].GetDate(),t[0].GetTime());
00092 ofstream out;
00093 out.open(name, ios::out);
00094 table->SavePrimitive(out,"");
00095 #endif
00096 }
00097 else cout << "Table:" << tabNam << " has not been found" << endl;
00098
00099 }