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

StDbConfigNodeImpl Class Reference

#include <StDbConfigNodeImpl.hh>

Inheritance diagram for StDbConfigNodeImpl:

StDbConfigNode StDbNode List of all members.

Public Member Functions

 StDbConfigNodeImpl (StDbConfigNode *parent, const char *nodeName, const char *configName)
 StDbConfigNodeImpl (StDbConfigNode *parent, StDbNode &node)
 StDbConfigNodeImpl (StDbType type, StDbDomain domain, const char *nodeName, const char *configName="none")
virtual ~StDbConfigNodeImpl ()
virtual void addChildren (dbEnvList *elist)
virtual void resetConfig (const char *config, int opt=0)
virtual int buildTree (int opt=0)
virtual StDbElementIndexgetElementIndex ()
virtual void setElementIndexInfo (const char *indexName, int indexID)
virtual void getElementIndexInfo (char *&indexname, int &indexID)
virtual int getNumIndeces () const
virtual StDbTableaddDbTable (const char *tableName, const char *version="default")
virtual StDbTableaddTable (const char *tableName, const char *version="default")
virtual StDbTableaddTable (StDbNode *node)
virtual StDbTablefindTable (const char *name, const char *subPath="/")
virtual StDbTablefindLocalTable (const char *name)
virtual void removeTable (StDbTable *table)
virtual StDbTableItergetStDbTableIter ()
virtual bool compareTables (StDbTable *tab1, StDbTable *tab2)
virtual void printTables (int depth)
virtual void printNumberStats ()
virtual void getNumberStats (unsigned int &nNodes, unsigned int &ntables, unsigned int &numBytes)
virtual void setTablesFlavor (const char *flavor)
virtual void setTablesProdTime (unsigned int ptime)

Protected Member Functions

void deleteTables ()
void updateDbInfo ()
void updateDbTables (int opt=0)
void updateDbTable (StDbTable *table, int opt=0)

Protected Attributes

StDbElementIndexmelementIndex
int mindexRef
TableList mTables

Constructor & Destructor Documentation

StDbConfigNodeImpl::StDbConfigNodeImpl StDbConfigNode parent,
const char *  nodeName,
const char *  configName
 

Definition at line 65 of file StDbConfigNodeImpl.cc.

00065 : StDbConfigNode(parent,nodeName,configName), mindexRef(-1) { 00066 melementIndex = new StDbElementIndex(); 00067 setConfigured(false); 00068 mcanRollBack=false; 00069 updateDbInfo(); 00070 }

StDbConfigNodeImpl::StDbConfigNodeImpl StDbConfigNode parent,
StDbNode node
 

Definition at line 74 of file StDbConfigNodeImpl.cc.

00074 : StDbConfigNode(parent,node), mindexRef(-1) { 00075 melementIndex = new StDbElementIndex(); 00076 updateDbInfo(); 00077 }

StDbConfigNodeImpl::StDbConfigNodeImpl StDbType  type,
StDbDomain  domain,
const char *  nodeName,
const char *  configName = "none"
 

Definition at line 81 of file StDbConfigNodeImpl.cc.

00081 : StDbConfigNode(type,domain,nodeName,configName), mindexRef(-1) { 00082 melementIndex = new StDbElementIndex(); 00083 updateDbInfo(); 00084 }

StDbConfigNodeImpl::~StDbConfigNodeImpl  )  [virtual]
 

Definition at line 88 of file StDbConfigNodeImpl.cc.

00088 { 00089 deleteTables(); 00090 delete melementIndex; 00091 };


Member Function Documentation

void StDbConfigNodeImpl::addChildren dbEnvList elist  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 385 of file StDbConfigNodeImpl.cc.

00385 { 00386 #define __METHOD__ "addChildren(dbEnvList*)" 00387 00388 for(int i=0; i<elist->num; i++){ 00389 char* id=strstr(elist->envVar[i],"_"); 00390 if(id){ 00391 id++; 00392 if(strcmp(id,mname) && !findChildConfigNode(id)){ 00393 StString nm; 00394 nm<<" Adding DataBase="<<elist->envVar[i]<<" with KEY="; 00395 nm<<elist->envDef[i]<<" from Environment variable definition"; 00396 StDbManager::Instance()->printInfo((nm.str()).c_str(),dbMWarn,__LINE__,__CLASS__,__METHOD__); 00397 //VP delete [] nMes; 00398 new StDbConfigNodeImpl(this,id,elist->envDef[i]); 00399 } 00400 } 00401 } 00402 #undef __METHOD__ 00403 }

StDbTable * StDbConfigNodeImpl::addDbTable const char *  tableName,
const char *  version = "default"
[virtual]
 

Implements StDbConfigNode.

Definition at line 204 of file StDbConfigNodeImpl.cc.

00204 { 00205 00206 // just like addTable but also loads the descriptor from the database 00207 StDbTable* table = addTable(tableName,version); 00208 updateDbTable(table); 00209 return table; 00210 }

StDbTable * StDbConfigNodeImpl::addTable StDbNode node  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 229 of file StDbConfigNodeImpl.cc.

00229 { 00230 00231 StDbTable* table = StDbManager::Instance()->newDbTable(node); 00232 if(table){ 00233 mTables.push_back(table); 00234 mhasData=true; 00235 } 00236 00237 return table; 00238 }

StDbTable * StDbConfigNodeImpl::addTable const char *  tableName,
const char *  version = "default"
[virtual]
 

Implements StDbConfigNode.

Definition at line 215 of file StDbConfigNodeImpl.cc.

00215 { 00216 00217 StDbTable* table = StDbManager::Instance()->newDbTable(mdbName,tableName); 00218 if(table) mTables.push_back(table); 00219 table->setVersion((char*)version); 00220 table->setNodeType("table"); 00221 00222 StDataBaseI* db = StDbManager::Instance()->findDb(mdbType, mdbDomain); 00223 if(db && table && db->QueryDb((StDbNode*)table))mhasData=true; 00224 return table; 00225 }

int StDbConfigNodeImpl::buildTree int  opt = 0  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 138 of file StDbConfigNodeImpl.cc.

00138 { 00139 #define __METHOD__ "buildTree(int opt)" 00140 00141 StDataBaseI *db = StDbManager::Instance()->findDb(mdbType, mdbDomain); 00142 00143 if(!db) 00144 return StDbManager::Instance()->printInfo(" No DB found for Node=",mname,dbMErr,__LINE__,__CLASS__,__METHOD__); 00145 00146 if(db->QueryDb(this)){ 00147 // check if we should connect via environment variables 00148 if(isDbNode() && mdbDomain==dbStar){ 00149 dbEnvList* elist = StDbManager::Instance()->getEnvList(mname); 00150 if(elist){ 00151 addChildren(elist); 00152 delete elist; 00153 } 00154 } 00155 // load descriptors & element structure as needed 00156 updateDbTables(opt); 00157 if(mfirstChildNode)mfirstChildNode->buildTree(opt); 00158 } 00159 00160 if(mnextNode)mnextNode->buildTree(opt); 00161 00162 return 1; 00163 #undef __METHOD__ 00164 }

bool StDbConfigNodeImpl::compareTables StDbTable tab1,
StDbTable tab2
[virtual]
 

Implements StDbConfigNode.

Definition at line 309 of file StDbConfigNodeImpl.cc.

00309 { 00310 00311 bool retVal=false; 00312 // compare name & version 00313 if((strcmp(tab1->printName(),tab2->printName())!=0)) return retVal; 00314 if((strcmp(tab1->printVersion(),tab2->printVersion())!=0)) return retVal; 00315 // compare each row identifier 00316 int nRows1; int nRows2; 00317 int* elements1 = tab1->getElementID(nRows1); 00318 int* elements2 = tab2->getElementID(nRows2); 00319 if(nRows1 != nRows2) return retVal; 00320 int i; 00321 for(i=0;i<nRows1;i++)if(elements1[i] != elements2[i])break; 00322 if(i==nRows1)retVal=true; 00323 return retVal; 00324 }

void StDbConfigNodeImpl::deleteTables  )  [protected]
 

Definition at line 369 of file StDbConfigNodeImpl.cc.

00369 { 00370 00371 TableList::iterator itr; 00372 StDbTable* table; 00373 do { for(itr = mTables.begin(); itr!=mTables.end(); ++itr){ 00374 table=*itr; 00375 mTables.erase(itr); 00376 delete table; 00377 break; 00378 } 00379 } while (mTables.begin() != mTables.end()); 00380 mhasData=false; 00381 }

StDbTable * StDbConfigNodeImpl::findLocalTable const char *  name  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 257 of file StDbConfigNodeImpl.cc.

00257 { 00258 00259 TableList::iterator itr; 00260 StDbTable* table=0; 00261 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){ 00262 if((*itr)->checkName(name)){ 00263 table=*itr; 00264 break; 00265 } 00266 } 00267 return table; 00268 }

StDbTable * StDbConfigNodeImpl::findTable const char *  name,
const char *  subPath = "/"
[virtual]
 

Implements StDbConfigNode.

Definition at line 242 of file StDbConfigNodeImpl.cc.

00242 { 00243 00244 if(subPath && (strcmp(subPath,"/")==0))return findLocalTable(name); 00245 00246 StDbConfigNode* node = findConfigNode(subPath); 00247 if(node)return node->findLocalTable(name); 00248 00249 // if we got here then we can't find it 00250 StDbTable* table=0; 00251 return table; 00252 }

StDbElementIndex * StDbConfigNodeImpl::getElementIndex  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 327 of file StDbConfigNodeImpl.cc.

00327 {return melementIndex; }

void StDbConfigNodeImpl::getElementIndexInfo char *&  indexname,
int &  indexID
[virtual]
 

Implements StDbConfigNode.

Definition at line 337 of file StDbConfigNodeImpl.cc.

00337 { 00338 00339 if(mindexRef < 0){ indexName=0; return; } 00340 indexName=melementIndex->getIndexName(mindexRef); 00341 indexID =melementIndex->getIndexVal(mindexRef); 00342 }

void StDbConfigNodeImpl::getNumberStats unsigned int &  nNodes,
unsigned int &  ntables,
unsigned int &  numBytes
[virtual]
 

Implements StDbConfigNode.

Definition at line 450 of file StDbConfigNodeImpl.cc.

00450 { 00451 00452 numNodes++; 00453 StDbTableIter* itr = getStDbTableIter(); 00454 StDbTable* table; 00455 while((itr) && !(itr->done())){ 00456 table=itr->next(); 00457 numTables++; 00458 numBytes+=(table->getTableSize()*table->GetNRows()); 00459 } 00460 if(itr)delete itr; 00461 if(mfirstChildNode)mfirstChildNode->getNumberStats(numNodes,numTables,numBytes); 00462 if(mnextNode)mnextNode->getNumberStats(numNodes,numTables,numBytes); 00463 }

int StDbConfigNodeImpl::getNumIndeces  )  const [virtual]
 

Implements StDbConfigNode.

Definition at line 346 of file StDbConfigNodeImpl.cc.

00346 { return melementIndex->getNumIndeces();}

StDbTableIter * StDbConfigNodeImpl::getStDbTableIter  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 350 of file StDbConfigNodeImpl.cc.

00350 { 00351 StDbTableIter* itr = new StDbTableIterImpl(this); 00352 return itr; 00353 }

void StDbConfigNodeImpl::printNumberStats  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 428 of file StDbConfigNodeImpl.cc.

00428 { 00429 #define __METHOD__ "printNumberStats()" 00430 00431 unsigned int numNodes, numTables, numBytes; 00432 numNodes=numTables=numBytes=0; 00433 getNumberStats(numNodes,numTables, numBytes); 00434 double kbs = ((double)numBytes)/1000.0; 00435 StString cos; 00436 cos<<"******************** Number Stats ******************** "<<stendl; 00437 cos<<"Total Number of Nodes = "<<numNodes <<stendl; 00438 cos<<"Total Number of Tables = "<<numTables <<stendl; 00439 cos<<"Total Size of Data in Tables = "<<kbs<<" kBytes" <<stendl; 00440 cos<<"******************************************************" <<stendl; 00441 00442 StDbManager::Instance()->printInfo((cos.str()).c_str(),dbMConnect,__LINE__,__CLASS__,__METHOD__); 00443 //VP delete [] nstats; 00444 00445 #undef __METHOD__ 00446 }

void StDbConfigNodeImpl::printTables int  depth  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 407 of file StDbConfigNodeImpl.cc.

00407 { 00408 00409 if(StDbManager::Instance()->IsVerbose()){ 00410 StString os; 00411 for(int k=0;k<depth;k++)os<<" "; 00412 00413 string pdepth=os.str(); 00414 TableList::iterator itr; 00415 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){ 00416 cout<<pdepth<<"Table="<<(*itr)->printName()<<", Version="<<(*itr)->printVersion(); 00417 int nRows; 00418 int* eIDs=(*itr)->getElementID(nRows); 00419 cout <<", numRows="<<nRows; 00420 if(nRows==1)cout<<", elementID="<<eIDs[0]; 00421 cout<<endl; 00422 } 00423 //VP delete [] pdepth; 00424 } 00425 }

void StDbConfigNodeImpl::removeTable StDbTable table  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 272 of file StDbConfigNodeImpl.cc.

00272 { 00273 00274 if(!table)return; 00275 TableList::iterator itr; 00276 StDbTable* myTable=0; 00277 00278 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){ 00279 myTable=*itr; 00280 if(myTable && compareTables(myTable,table)){ 00281 mTables.erase(itr); break; 00282 } 00283 myTable=0; 00284 } 00285 }

void StDbConfigNodeImpl::resetConfig const char *  config,
int  opt = 0
[virtual]
 

Implements StDbConfigNode.

Definition at line 358 of file StDbConfigNodeImpl.cc.

00358 { 00359 00360 if(mfirstChildNode)mfirstChildNode->deleteTree(); 00361 if(mhasData)deleteTables(); 00362 setVersion(configName); 00363 buildTree(opt); 00364 }

void StDbConfigNodeImpl::setElementIndexInfo const char *  indexName,
int  indexID
[virtual]
 

Implements StDbConfigNode.

Definition at line 331 of file StDbConfigNodeImpl.cc.

00331 { 00332 mindexRef=melementIndex->addNameValuePair(indexName,indexID); 00333 }

void StDbConfigNodeImpl::setTablesFlavor const char *  flavor  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 289 of file StDbConfigNodeImpl.cc.

00289 { 00290 00291 TableList::iterator itr; 00292 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){ 00293 if((*itr))(*itr)->setFlavor(flavor); 00294 } 00295 }

void StDbConfigNodeImpl::setTablesProdTime unsigned int  ptime  )  [virtual]
 

Implements StDbConfigNode.

Definition at line 299 of file StDbConfigNodeImpl.cc.

00299 { 00300 00301 TableList::iterator itr; 00302 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){ 00303 if((*itr))(*itr)->setProdTime(ptime); 00304 } 00305 }

void StDbConfigNodeImpl::updateDbInfo  )  [protected]
 

Definition at line 95 of file StDbConfigNodeImpl.cc.

00095 { 00096 #define __METHOD__ "updateDbInfo()" 00097 00098 if(mparentNode)melementIndex->addElementIndex(mparentNode->getElementIndex()); 00099 00100 // If StarDb Type, then name holds map to real Db type 00101 // while the domain may still be StarDb 00102 // Else if StarDb domain, then name holds map to real domain type 00103 // Else both type & domain are that of parent (which maybe User defined) 00104 00105 misConfigured = false; 00106 if(mparentNode){ //top level node will have type&domain set by the manager. 00107 if(mdbType==dbStDb){ 00108 mdbType=StDbManager::Instance()->getDbType(mname); 00109 } else if(mdbDomain==dbStar) { 00110 mdbDomain=StDbManager::Instance()->getDbDomain(mname); 00111 } 00112 } 00113 00114 if(!mnodeType) mnodeType=mstrDup("DB"); 00115 // replace nodetype of DB to Config moving from 1 db to another 00116 // & allow overwriting of versionkey with environment variable 00117 if(strcmp(mnodeType,"DB")==0){ 00118 setIsDbNode(true); 00119 delete [] mnodeType; 00120 mnodeType=mstrDup("Config"); 00121 setBranchID(0); 00122 char* version=StDbManager::Instance()->getExternalVersion(mdbType,mdbDomain); 00123 if(version && strcmp(version,mversion)){ 00124 StString nm; 00125 nm<<" Overriding Key="<<mversion<<" with Environment Var Key="<<version; 00126 nm<<" for DataBase="; 00127 nm<<StDbManager::Instance()->printDbName(mdbType,mdbDomain); 00128 StDbManager::Instance()->printInfo((nm.str()).c_str(),dbMWarn,__LINE__,__CLASS__,__METHOD__); 00129 setVersion(version); 00130 } 00131 } 00132 00133 #undef __METHOD__ 00134 }

void StDbConfigNodeImpl::updateDbTable StDbTable table,
int  opt = 0
[protected]
 

Definition at line 183 of file StDbConfigNodeImpl.cc.

00183 { 00184 00185 if(!table) return; 00186 StDataBaseI* db=StDbManager::Instance()->findDb(mdbType, mdbDomain); 00187 if(!db)return; 00188 00189 int nRows; 00190 char* elements=table->printElementName(); 00191 if(elements){ 00192 int* eList=db->selectElements(elements,melementIndex,nRows); 00193 if(eList){ 00194 table->setElementID(eList,nRows); 00195 delete [] eList; 00196 } 00197 } 00198 if(!opt) db->QueryDescriptor(table); 00199 }

void StDbConfigNodeImpl::updateDbTables int  opt = 0  )  [protected]
 

Definition at line 167 of file StDbConfigNodeImpl.cc.

00167 { 00168 00169 if(!mhasData)return; 00170 StDataBaseI* db=StDbManager::Instance()->findDb(mdbType, mdbDomain); 00171 if(!db) return; 00172 00173 StDbTableIter* itr = getStDbTableIter(); 00174 StDbTable* table; 00175 while((itr) && !(itr->done())){ 00176 table=itr->next(); 00177 updateDbTable(table,opt); 00178 } 00179 if(itr)delete itr; 00180 00181 }


Member Data Documentation

StDbElementIndex* StDbConfigNodeImpl::melementIndex [protected]
 

Definition at line 52 of file StDbConfigNodeImpl.hh.

int StDbConfigNodeImpl::mindexRef [protected]
 

Definition at line 53 of file StDbConfigNodeImpl.hh.

TableList StDbConfigNodeImpl::mTables [protected]
 

Definition at line 54 of file StDbConfigNodeImpl.hh.


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