16 gSystem->Load(
"libStDb_Tables");
17 Char_t *mysql =
"libmysqlclient";
18 Char_t *libs[] = {
"",
"/usr/mysql/lib/",
"/usr/lib/mysql/",
"/usr/lib/", 0};
24 lib = gSystem->ExpandPathName(lib.Data());
25 if (gSystem->DynamicPathName(lib,kTRUE)) {
26 gSystem->Load(lib.Data()); cout <<
" + " << lib.Data() << endl;
31 gSystem->Load(
"liblog4cxx.so");
32 gSystem->Load(
"libSt_base");
33 gSystem->Load(
"libStStarLogger.so");
34 gROOT->ProcessLine(
"StLoggerManager::StarLoggerInit();");
35 gSystem->Load(
"StDbLib");
40 void put2DB(
const char* file=
41 "$STAR/StarDb/Geometry/svt/svtWafersPosition.20050101.000200.C"
49 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
53 TString bName(gSystem->BaseName(file));
54 Int_t indx = bName.Index(
".");
55 TString TName(bName.Data(),indx); cout <<
"Table name " << TName << endl;
56 TString Time(bName.Data()+indx+1);
57 Time.ReplaceAll(
"C",
"");
58 Time.ReplaceAll(
"root",
"");
64 Int_t n = sscanf(Time.Data(),
"%d.%d",&d,&t);
67 n = sscanf(Time.Data(),
"%s",&tag);
69 d = StMaker::AliasDate(tag);
70 t = StMaker::AliasTime(tag);
71 cout <<
"n = " << n <<
" tag: " << tag <<
" d = " << d <<
" t = " << t << endl;
74 TDatime Date(d,t); cout <<
" Date " << Date.GetDate() <<
"\tTime " << Date.GetTime() << endl;
75 TString dName(gSystem->DirName(file));
77 Int_t indx = dName.Index(
"StarDb/");
79 DB = dName.Data()+indx+7;
80 DB.ReplaceAll(
"/",
"_");
84 TString fName(file); cout <<
"Load " << fName <<
" to DB: " << DB << endl;
86 if (gClassTable->GetID(
"StDbManager") < 0) Load();
87 if (fName.EndsWith(
".root")) {
88 TFile *f =
new TFile(file);
89 table = (
TTable *) f->Get(TName.Data());
92 gROOT->LoadMacro(file);
93 table = (
TTable *) CreateTable();
96 cout <<
"Table has not been found" << endl;
100 TType += table->GetTitle(); cout <<
"\t" << TType << endl;
101 if (TType.EndsWith(
"_st")) {
102 TType = TString(TType,TType.Length()-3);
103 cout <<
"\t" << TType << endl;
105 cout <<
"name = " << table->GetName() <<
"\ttype = " << TType << endl;
106 cout <<
"ProcessLine(\"" << Form(
"%s *myTable = (%s *) table",TType.Data(),TType.Data()) <<
"\");" << endl;
107 gInterpreter->ProcessLine(Form(
"%s *myTable = (%s *) table",TType.Data(),TType.Data()));
108 if (! myTable)
return;
109 cout<<
" --- Save to DB "<<endl;
110 Int_t rowSize = myTable -> GetRowSize();
112 TD->storeRowSize(rowSize);
114 mgr->setVerbose(kTRUE);
118 dbTable=node->addDbTable(TName.Data());
119 cout <<
" --- Store table " << TName << endl;
120 dbTable->checkDescriptor();
121 Int_t N = myTable->GetNRows();
123 if (NN > 10) NN = 10;
125 if ( myTable->IsA()->InheritsFrom(
"St_tpcCorrection" ) ) {
127 const Int_t Nmax = 50;
128 if (N > Nmax) {cout <<
"Table has " << N <<
" more than " << Nmax <<
" rows. Possible BUG " << endl;
return;}
129 myTable->ReAllocate(Nmax);
130 tpcCorrection_st row;
131 memset(&row, 0,
sizeof(tpcCorrection_st));
132 for (Int_t i = N; i < Nmax; i++) myTable->AddAt(&row);
133 tpcCorrection_st *r = myTable->GetTable();
134 for (Int_t i = 0; i < N; i++, r++) {
138 myTable->Print(0,N+1);
141 if ( myTable->IsA()->InheritsFrom(
"St_svtHybridDriftVelocity" ) ) {
143 const Int_t Nmax = 432;
144 if (N > Nmax) {cout <<
"Table has " << N <<
" more than " << Nmax <<
" rows. Possible BUG " << endl;
return;}
145 myTable->ReAllocate(Nmax);
146 svtHybridDriftVelocity_st row;
147 memset(&row, 0,
sizeof(svtHybridDriftVelocity_st));
148 for (Int_t i = N; i < Nmax; i++) myTable->AddAt(&row);
149 svtHybridDriftVelocity_st *r = myTable->GetTable();
150 for (Int_t i = 0; i < N; i++, r++) {
154 myTable->Print(0,N+1);
157 Int_t *rowIDs =
new Int_t[N];
159 if (N == 1) offset = 0;
160 if (TName.Contains(
"tpcDriftVelocity") ||TName.Contains(
"ssdConfiguration") || TName.Contains(
"trgTimeOffset")) offset = 0;
161 #ifndef _SvtIndexMap_h
162 if (TName.Contains(
"svtWafersPosition")) {cout <<
"Un comment SvtIndexMap include" << endl;
return;}
163 for(Int_t ti=0;ti<N;ti++) rowIDs[ti]=ti + offset;
165 if (TName.Contains(
"svtWafersPosition")) {
167 St_svtWafersPosition *S = (St_svtWafersPosition *) table;
168 svtWafersPosition_st *s = S->GetTable();
169 for(Int_t ti=0;ti<N;ti++, s++) {
170 Int_t elementID = -1;
171 for (Int_t j = 0; j < N; j++) {
172 Int_t layer = 2*SvtMap[j].Barrel - 1 + SvtMap[j].Ladder%2;
173 Int_t Id = 1000*layer + 100*SvtMap[j].Wafer + SvtMap[j].Ladder;
174 if (Id != SvtMap[j].Id) {
175 cout <<
"Mismatch for ID " << s->ID
177 << SvtMap[j].name <<
"\t"
178 << SvtMap[j].Id <<
"\t"
179 << SvtMap[j].Index <<
"\t"
180 << SvtMap[j].elementID <<
"\t"
181 << SvtMap[j].Barrel <<
"\t"
182 << SvtMap[j].Ladder <<
"\t"
183 << SvtMap[j].Wafer << endl;
187 cout <<
"Found match for ID " << s->ID
189 << SvtMap[j].name <<
"\t"
190 << SvtMap[j].Id <<
"\t"
191 << SvtMap[j].Index <<
"\t"
192 << SvtMap[j].elementID <<
"\t"
193 << SvtMap[j].Barrel <<
"\t"
194 << SvtMap[j].Ladder <<
"\t"
195 << SvtMap[j].Wafer << endl;
197 elementID = SvtMap[j].elementID;
202 cout <<
"Don't find match for ID " << s->ID << endl;
205 rowIDs[ti]= elementID;
208 for(Int_t ti=0;ti<N;ti++) rowIDs[ti]=ti + offset;
211 Char_t* gstr = (Char_t*) myTable->GetTable();
216 for (Int_t i = 0; i < maxIter; i++) {
217 TString TimeStamp(Form(
"%8d.%06d",d,t+i)); cout <<
"TimeStamp " << TimeStamp << endl;
222 mgr->setStoreTime(DT);
223 status = mgr->storeDbTable(dbTable);
225 if (i+1 < maxIter) cout<<
" ------> error storing in DB --> try to change TimeStamp by 1 sec"<<endl;
228 if (status) cout <<
" ------> Done" << endl;
229 else cout <<
" ------> Failed" << endl;
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc'd version of data for StRoot
static StDbManager * Instance()
strdup(..) is not ANSI