Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

StDbModifier Class Reference

#include <StDbModifier.h>

List of all members.

Public Member Functions

 StDbModifier ()
virtual ~StDbModifier ()
virtual Int_t ReadDataFromDB ()
virtual Int_t WriteDataToDB ()
virtual void SetTime (unsigned int timestamp)
virtual void SetDateTime (const char *timestamp)
virtual void SetDbName (const char *dbname)
virtual void SetFlavor (const char *flavorname)
virtual void SetInputFileName (const char *inputfilename)
virtual void SetOutputFileName (const char *outputfilename)
virtual void SetTableName (const char *tablename)
virtual void SetVersionName (const char *versionname)
virtual void SetDebug ()
virtual void SetDebug (Int_t debug)

Private Attributes

char * fDbName
Int_t fDebug
char * fTableName
unsigned int funixTime
char * fTimestamp
char * fVersionName
char * fOutputFileName
char * fInputFileName
char * fFlavorName


Constructor & Destructor Documentation

StDbModifier::StDbModifier  ) 
 

StDbModifier::~StDbModifier  )  [virtual]
 

Definition at line 83 of file StDbModifier.cxx.

00084 { 00085 // destructor of StDbModifier 00086 if(fTimestamp) delete [] fTimestamp; 00087 00088 }


Member Function Documentation

Int_t StDbModifier::ReadDataFromDB  )  [virtual]
 

Definition at line 91 of file StDbModifier.cxx.

00092 { 00093 // This funciton will connect database server, get informaion of table and 00094 // make a file that contains data of table in database. 00095 00096 if( funixTime==0 && !(fTimestamp)) { 00097 cout<< " No timestamp specified " << endl; 00098 return 0; 00099 } 00100 00101 if ( fDbName == 0 ){ 00102 cout << " StDbModifier; Set Database name by " << endl; 00103 cout << " StDbModifier::setDbName(TString dbname)"; 00104 cout << endl; 00105 return 0; 00106 } 00107 if ( fTableName == 0 ){ 00108 cout << " StDbModifier; Set table name by " << endl; 00109 cout << " StDbModifier::setTableName(TString tablename)"; 00110 cout << endl; 00111 return 0; 00112 } 00113 00114 StDbManager* mgr = StDbManager::Instance(); // Get the singleton manager 00115 if ( fDebug == 1 ){ 00116 bool isVerbose = true; 00117 mgr->setVerbose(isVerbose); // Set verbose mode for debuging for fDebug=1 00118 } 00119 00120 StDbConfigNode* configNode = mgr -> initConfig(fDbName); // Connect to the db & get an empty container 00121 00122 StDbTable* dbtable; 00123 if ( fVersionName == 0 ){ 00124 dbtable = configNode -> addDbTable(fTableName); 00125 // Add a table to the container with descriptor given by Database with wsing version name as "default" 00126 }else{ 00127 dbtable = configNode -> addDbTable(fTableName,fVersionName); 00128 // Add a table to the container with descriptor given by Database with wsing version name specified . 00129 } 00130 if ( dbtable == 0 ){ // If table asigned by fTableName does not exist in Dababase 00131 cout << " No Table : " << fTableName << endl; // program is stoped and exit from this function. 00132 return 0; // 00133 } 00134 00135 if ( fFlavorName != 0 ){ 00136 dbtable -> setFlavor(fFlavorName); 00137 cout << "Flavor is set as " << fFlavorName << " by StDbTable::setFlavor." << endl; 00138 }else{ 00139 cout << "Flavor is NOT assigned. Default value is set as 'ofl'. " << endl; 00140 dbtable -> setFlavor("ofl"); 00141 } 00142 00143 00144 if(funixTime) { 00145 mgr->setRequestTime(funixTime); 00146 } else { 00147 mgr->setRequestTime(fTimestamp); 00148 } 00149 00150 // mgr -> setRequestTime(fTimestamp); // Set the request time 00151 mgr -> fetchDbTable(dbtable); // Fetch the data from Database 00152 00153 void* cstruct = dbtable -> GetTableCpy(); // Get pointer of table and copy to c-structure 00154 Int_t nrows = dbtable -> GetNRows(); // Get number of raws in the table 00155 00156 TTable* table = TTable::New(fTableName,fTableName,cstruct,nrows); 00157 // Create new TTable object for c-structure 00158 00159 ofstream ofs(fOutputFileName); // Open a file 00160 table -> SavePrimitive(ofs,0); // Write information of c-structure from object of TTable to the file 00161 ofs.close(); // Close the file 00162 00163 return 1; 00164 }

void StDbModifier::SetDateTime const char *  timestamp  )  [virtual]
 

Definition at line 283 of file StDbModifier.cxx.

00284 { 00285 fTimestamp = new char[strlen(timestamp)+1]; 00286 strcpy(fTimestamp,timestamp); 00287 }

void StDbModifier::SetDbName const char *  dbname  )  [virtual]
 

Definition at line 292 of file StDbModifier.cxx.

00293 { 00294 fDbName = new char[strlen(dbname)+1]; 00295 strcpy(fDbName,dbname); 00296 }

virtual void StDbModifier::SetDebug Int_t  debug  )  [inline, virtual]
 

Definition at line 61 of file StDbModifier.h.

00061 { fDebug = debug; }

virtual void StDbModifier::SetDebug  )  [inline, virtual]
 

Definition at line 60 of file StDbModifier.h.

00060 { fDebug = 1 ; }

void StDbModifier::SetFlavor const char *  flavorname  )  [virtual]
 

Definition at line 327 of file StDbModifier.cxx.

00328 { 00329 fFlavorName = new char[strlen(flavorname)+1]; 00330 strcpy(fFlavorName,flavorname); 00331 cout << " Flavor is set " << flavorname << endl; 00332 cout << " Flavor is set " << fFlavorName << endl; 00333 }

void StDbModifier::SetInputFileName const char *  inputfilename  )  [virtual]
 

Definition at line 299 of file StDbModifier.cxx.

00300 { 00301 fInputFileName = new char[strlen(inputfilename)+1]; 00302 strcpy(fInputFileName,inputfilename); 00303 }

void StDbModifier::SetOutputFileName const char *  outputfilename  )  [virtual]
 

Definition at line 306 of file StDbModifier.cxx.

00307 { 00308 fOutputFileName = new char[strlen(outputfilename)+1]; 00309 strcpy(fOutputFileName,outputfilename); 00310 }

void StDbModifier::SetTableName const char *  tablename  )  [virtual]
 

Definition at line 313 of file StDbModifier.cxx.

00314 { 00315 fTableName = new char[strlen(tablename)+1]; 00316 strcpy(fTableName,tablename); 00317 }

void StDbModifier::SetTime unsigned int  timestamp  )  [virtual]
 

Definition at line 289 of file StDbModifier.cxx.

00289 { funixTime=time;}

void StDbModifier::SetVersionName const char *  versionname  )  [virtual]
 

Definition at line 320 of file StDbModifier.cxx.

00321 { 00322 fVersionName = new char[strlen(versionname)+1]; 00323 strcpy(fVersionName,versionname); 00324 }

Int_t StDbModifier::WriteDataToDB  )  [virtual]
 

Definition at line 168 of file StDbModifier.cxx.

00169 { 00170 // This funciton will make a table as object of TTable. 00171 // Data of the table will be read from a file that is generated from 00172 // StDbModifier::ReadDataFromDB(). 00173 // After data is read, connection to database server is made and data will 00174 // be stored in database. 00175 00176 00177 if( funixTime==0 && !(fTimestamp)) { 00178 cout<< " No timestamp specified " << endl; 00179 return 0; 00180 } 00181 00182 if ( fDbName == 0 ){ 00183 cout << " StDbModifier; Set Database name by " << endl; 00184 cout << " StDbModifier::setDbName(TString dbname)"; 00185 cout << endl; 00186 return 0; 00187 } 00188 if ( fTableName == 0 ){ 00189 cout << " StDbModifier; Set table name by " << endl; 00190 cout << " StDbModifier::setTableName(TString tablename)"; 00191 cout << endl; 00192 return 0; 00193 } 00194 00195 TString command; // Make a string to load Root C macro generated 00196 command = ".L "; // by ReadDataFromDB() 00197 command += fInputFileName; 00198 00199 if ( fDebug == 1 ) printf(" LoadTable: %s\n",(const char*)command); 00200 00201 gInterpreter->ProcessLine(command); // Load the file in CINT 00202 TTable* table = (TTable*) gInterpreter->Calc("CreateTable()"); // execute comand in the file 00203 command.ReplaceAll(".L ",".U "); // chage comand .L to .U 00204 gInterpreter->ProcessLine(command); // unload file from CINT 00205 00206 void* cstruct = table -> GetArray(); // Get pointer of table and copy to c-structure 00207 Int_t nrows = table -> GetNRows(); // Get number of raws in the table 00208 //MPD - below is need TTable info to correct c-array 8 byte padding issue 00209 //could have broke it out - but I chose to keep all the TTable (root) stuff together 00210 00211 Int_t rowSize = table -> GetRowSize(); // Get the size (in bytes) of each row - fixes gap/padding problem 00212 // Int_t nCols = table -> GetNumberOfColumns(); 00213 00214 StDbTableDescriptor* TD = new StDbTableDescriptor(); 00215 TD->storeRowSize(rowSize); 00216 //table -> Print(0,2); //uncomment for debugging 00217 00218 00219 00220 StDbManager* mgr = StDbManager::Instance(); // Get the singleton manager 00221 if ( fDebug == 1 ){ 00222 bool isVerbose = true; 00223 mgr->setVerbose(isVerbose); // Set verbose mode for debuging for fDebug=1 00224 } 00225 StDbConfigNode* configNode = mgr -> initConfig(fDbName); // Connect to the db & get an empty container 00226 00227 StDbTable* dbtable; 00228 if ( fVersionName == 0 ){ 00229 dbtable = configNode -> addDbTable(fTableName); 00230 // Add a table to the container with descriptor given by Database with wsing version name as "default" 00231 }else{ 00232 dbtable = configNode -> addDbTable(fTableName,fVersionName); 00233 // Add a table to the container with descriptor given by Database with wsing version name specified . 00234 } 00235 00236 00237 00238 if ( dbtable == 0 ){ // If table asigned by fTableName does not exist in Dababase, 00239 cout << " No Table : " << fTableName << endl; // program is stoped and exit from this function. 00240 return 0; // 00241 } 00242 00243 if ( fFlavorName != 0 ){ 00244 cout << "set Flavor" << endl; 00245 dbtable -> setFlavor(fFlavorName); 00246 cout << "Flavor is set as " << fFlavorName << " by StDbTable::setFlavor." << endl; 00247 }else{ 00248 cout << "Flavor is NOT assigned. Default value is set as 'ofl'. " << endl; 00249 dbtable -> setFlavor("ofl"); 00250 } 00251 00252 int dbnrows=dbtable->GetNRows(); 00253 int* eidList=0; 00254 int tmp; 00255 int* dbeidList=dbtable->getElementID(tmp); 00256 if(nrows>dbnrows){ 00257 eidList=new int[nrows]; 00258 int i; 00259 for(i=0;i<dbnrows;i++)eidList[i]=dbeidList[i]; 00260 for(i=dbnrows;i<nrows;i++)eidList[i]=eidList[dbnrows-1]+i; 00261 } 00262 00263 00264 dbtable -> SetTable((char*)cstruct,nrows,eidList); // Put data in local table on memory 00265 // dbtable -> SetNRows(nrows); // Set number of rows on table in database 00266 00267 // mgr -> setStoreTime(fTimestamp); // Set the time stamp 00268 if(funixTime) { 00269 mgr->setStoreTime(funixTime); 00270 } else { 00271 mgr->setStoreTime(fTimestamp); 00272 } 00273 00274 int retVal=0; 00275 if(mgr -> storeDbTable(dbtable)) retVal=1; // Fetch the data 00276 if(eidList) delete [] eidList; 00277 00278 00279 return retVal; 00280 }


Member Data Documentation

char* StDbModifier::fDbName [private]
 

Definition at line 32 of file StDbModifier.h.

Int_t StDbModifier::fDebug [private]
 

Definition at line 33 of file StDbModifier.h.

char* StDbModifier::fFlavorName [private]
 

Definition at line 40 of file StDbModifier.h.

char* StDbModifier::fInputFileName [private]
 

Definition at line 39 of file StDbModifier.h.

char* StDbModifier::fOutputFileName [private]
 

Definition at line 38 of file StDbModifier.h.

char* StDbModifier::fTableName [private]
 

Definition at line 34 of file StDbModifier.h.

char* StDbModifier::fTimestamp [private]
 

Definition at line 36 of file StDbModifier.h.

unsigned int StDbModifier::funixTime [private]
 

Definition at line 35 of file StDbModifier.h.

char* StDbModifier::fVersionName [private]
 

Definition at line 37 of file StDbModifier.h.


The documentation for this class was generated from the following files:
Generated on Thu Aug 24 14:45:58 2006 for Doxygen by doxygen 1.3.7