54 #include "TInterpreter.h"
56 #ifndef __STDB_STANDALONE__
58 #include "StMessMgr.h"
60 #define LOG_DEBUG cout
63 #define LOG_ERROR cerr
64 #define LOG_FATAL cerr
72 #include "StDbManager.hh"
73 #include "StDbConfigNode.hh"
74 #include "StDbTable.h"
75 #include "StDbDefs.hh"
76 #include "StDbTableDescriptor.h"
78 #include "StDbModifier.h"
81 ClassImp(StDbModifier)
84 StDbModifier::StDbModifier() : fDbName(0), fDebug(0), fTableName(0), funixTime(0), fTimestamp(0), fVersionName(0),
85 fOutputFileName(0), fInputFileName(0), fFlavorName(0)
106 fOutputFileName =
new char[200];
107 strcpy(fOutputFileName,
"./database_data.C");
110 fInputFileName =
new char[200];
111 strcpy(fInputFileName,
"./database_data.C");
116 StDbModifier::~StDbModifier()
119 delete [] fTimestamp;
121 delete [] fTableName;
122 delete [] fVersionName;
123 delete [] fFlavorName;
124 delete [] fOutputFileName;
125 delete [] fInputFileName;
129 Int_t StDbModifier::ReadDataFromDB()
134 if( funixTime==0 && !(fTimestamp)) {
135 cout<<
" No timestamp specified " << endl;
140 cout <<
" StDbModifier; Set Database name by " << endl;
141 cout <<
" StDbModifier::setDbName(TString dbname)";
145 if ( fTableName == 0 ){
146 cout <<
" StDbModifier; Set table name by " << endl;
147 cout <<
" StDbModifier::setTableName(TString tablename)";
154 bool isVerbose =
true;
155 mgr->setVerbose(isVerbose);
161 if ( fVersionName == 0 ){
162 dbtable = configNode -> addDbTable(fTableName);
165 dbtable = configNode -> addDbTable(fTableName,fVersionName);
169 cout <<
" No Table : " << fTableName << endl;
173 if ( fFlavorName != 0 ){
174 dbtable -> setFlavor(fFlavorName);
175 cout <<
"Flavor is set as " << fFlavorName <<
" by StDbTable::setFlavor." << endl;
177 cout <<
"Flavor is NOT assigned. Default value is set as 'ofl'. " << endl;
178 dbtable -> setFlavor(
"ofl");
183 mgr->setRequestTime(funixTime);
185 mgr->setRequestTime(fTimestamp);
189 mgr -> fetchDbTable(dbtable);
191 void* cstruct = dbtable -> GetTableCpy();
192 Int_t nrows = dbtable -> GetNRows();
197 ofstream ofs(fOutputFileName);
198 table -> SavePrimitive(ofs,0);
206 Int_t StDbModifier::WriteDataToDB()
215 if( funixTime==0 && !(fTimestamp)) {
216 cout<<
" No timestamp specified " << endl;
221 cout <<
" StDbModifier; Set Database name by " << endl;
222 cout <<
" StDbModifier::setDbName(TString dbname)";
226 if ( fTableName == 0 ){
227 cout <<
" StDbModifier; Set table name by " << endl;
228 cout <<
" StDbModifier::setTableName(TString tablename)";
235 command += fInputFileName;
237 if ( fDebug == 1 ) LOG_INFO<<
" LoadTable: "<<(
const char*)command<<endm;
239 gInterpreter->ProcessLine(command);
240 TTable* table = (
TTable*) gInterpreter->Calc(
"CreateTable()");
241 command.ReplaceAll(
".L ",
".U ");
242 gInterpreter->ProcessLine(command);
244 void* cstruct = table -> GetArray();
245 Int_t nrows = table -> GetNRows();
249 Int_t rowSize = table -> GetRowSize();
253 TD->storeRowSize(rowSize);
260 bool isVerbose =
true;
261 mgr->setVerbose(isVerbose);
266 if ( fVersionName == 0 ){
267 dbtable = configNode -> addDbTable(fTableName);
270 dbtable = configNode -> addDbTable(fTableName,fVersionName);
277 cout <<
" No Table : " << fTableName << endl;
282 if ( fFlavorName != 0 ){
283 cout <<
"set Flavor" << endl;
284 dbtable -> setFlavor(fFlavorName);
285 cout <<
"Flavor is set as " << fFlavorName <<
" by StDbTable::setFlavor." << endl;
287 cout <<
"Flavor is NOT assigned. Default value is set as 'ofl'. " << endl;
288 dbtable -> setFlavor(
"ofl");
291 int dbnrows=dbtable->GetNRows();
294 int* dbeidList=dbtable->getElementID(tmp);
296 eidList=
new int[nrows];
298 for(i=0;i<dbnrows;i++)eidList[i]=dbeidList[i];
299 for(i=dbnrows;i<nrows;i++)eidList[i]=eidList[dbnrows-1]+i;
303 dbtable -> SetTable((
char*)cstruct,nrows,eidList);
308 mgr->setStoreTime(funixTime);
310 mgr->setStoreTime(fTimestamp);
314 if(mgr -> storeDbTable(dbtable)) retVal=1;
322 void StDbModifier::SetDateTime(
const char* timestamp)
324 delete [] fTimestamp;
325 fTimestamp =
new char[strlen(timestamp)+1];
326 strcpy(fTimestamp,timestamp);
329 void StDbModifier::SetTime(
unsigned int time){ funixTime=time;}
332 void StDbModifier::SetDbName(
const char* dbname)
335 fDbName =
new char[strlen(dbname)+1];
336 strcpy(fDbName,dbname);
340 void StDbModifier::SetInputFileName(
const char* inputfilename)
342 delete [] fInputFileName;
343 fInputFileName =
new char[strlen(inputfilename)+1];
344 strcpy(fInputFileName,inputfilename);
348 void StDbModifier::SetOutputFileName(
const char* outputfilename)
350 delete [] fOutputFileName;
351 fOutputFileName =
new char[strlen(outputfilename)+1];
352 strcpy(fOutputFileName,outputfilename);
356 void StDbModifier::SetTableName(
const char* tablename)
358 delete [] fTableName;
359 fTableName =
new char[strlen(tablename)+1];
360 strcpy(fTableName,tablename);
364 void StDbModifier::SetVersionName(
const char* versionname)
366 delete [] fVersionName;
367 fVersionName =
new char[strlen(versionname)+1];
368 strcpy(fVersionName,versionname);
372 void StDbModifier::SetFlavor(
const char* flavorname)
374 delete [] fFlavorName;
375 fFlavorName =
new char[strlen(flavorname)+1];
376 strcpy(fFlavorName,flavorname);
377 cout <<
" Flavor is set " << flavorname << endl;
378 cout <<
" Flavor is set " << fFlavorName << endl;
static TTable * New(const Char_t *name, const Char_t *type, void *array, UInt_t size)
This static method creates a new TTable object if provided.
static StDbManager * Instance()
strdup(..) is not ANSI