66 #include "stdb_streams.h"
68 #include "StDbConfigNodeImpl.hh"
69 #include "StDbManagerImpl.hh"
70 #include "StDbTableIterImpl.hh"
71 #include "StDbElementIndex.hh"
73 #define __CLASS__ "StDbConfigNodeImpl"
77 StDbConfigNodeImpl::StDbConfigNodeImpl(
StDbConfigNode* parent,
const char* nodeName,
const char* configName):
StDbConfigNode(parent,nodeName,configName), mindexRef(-1) {
93 StDbConfigNodeImpl::StDbConfigNodeImpl(StDbType type, StDbDomain domain,
const char* nodeName,
const char* configName):
StDbConfigNode(type,domain,nodeName,configName), mindexRef(-1) {
100 StDbConfigNodeImpl::~StDbConfigNodeImpl(){
102 delete melementIndex;
107 StDbConfigNodeImpl::updateDbInfo(){
108 #define __METHOD__ "updateDbInfo()"
110 if(mparentNode)melementIndex->addElementIndex(mparentNode->getElementIndex());
117 misConfigured =
false;
121 }
else if(mdbDomain==dbStar) {
126 if(!mnodeType) mnodeType=mstrDup(
"DB");
129 if(strcmp(mnodeType,
"DB")==0){
132 mnodeType=mstrDup(
"Config");
135 if(version && strcmp(version,mversion)){
137 nm<<
" Overriding Key="<<mversion<<
" with Environment Var Key="<<version;
138 nm<<
" for DataBase=";
150 StDbConfigNodeImpl::buildTree(
int opt){
151 #define __METHOD__ "buildTree(int opt)"
156 return StDbManager::Instance()->printInfo(
" No DB found for Node=",mname,dbMErr,__LINE__,__CLASS__,__METHOD__);
158 if(db->QueryDb(
this)){
160 if(isDbNode() && mdbDomain==dbStar){
169 if(mfirstChildNode)mfirstChildNode->buildTree(opt);
172 if(mnextNode)mnextNode->buildTree(opt);
179 void StDbConfigNodeImpl::updateDbTables(
int opt){
187 while((itr) && !(itr->done())){
189 updateDbTable(table,opt);
195 void StDbConfigNodeImpl::updateDbTable(
StDbTable* table,
int opt){
202 char* elements=table->printElementName();
204 int* eList=db->selectElements(elements,melementIndex,nRows);
206 table->setElementID(eList,nRows);
210 if(!opt) db->QueryDescriptor(table);
216 StDbConfigNodeImpl::addDbTable(
const char* tableName,
const char* version){
219 StDbTable* table = addTable(tableName,version);
220 updateDbTable(table);
227 StDbConfigNodeImpl::addTable(
const char* tableName,
const char* version){
232 mTables.push_back(table);
233 table->setVersion((
char*)version);
234 table->setNodeType(
"table");
237 if(db && table && db->QueryDb((
StDbNode*)table)) { mhasData =
true; }
243 StDbConfigNodeImpl::addTable(
StDbNode* node){
247 mTables.push_back(table);
256 StDbConfigNodeImpl::findTable(
const char* name,
const char* subPath){
258 if(subPath && (strcmp(subPath,
"/")==0))
return findLocalTable(name);
261 if(node)
return node->findLocalTable(name);
271 StDbConfigNodeImpl::findLocalTable(
const char* name){
273 TableList::iterator itr;
275 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){
276 if((*itr)->checkName(name)){
286 StDbConfigNodeImpl::removeTable(
StDbTable* table){
289 TableList::iterator itr;
292 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){
294 if(myTable && compareTables(myTable,table)){
296 mTables.erase(itr);
break;
304 StDbConfigNodeImpl::setTablesFlavor(
const char* flavor){
306 TableList::iterator itr;
307 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){
308 if((*itr))(*itr)->setFlavor(flavor);
314 StDbConfigNodeImpl::setTablesProdTime(
unsigned int ptime){
316 TableList::iterator itr;
317 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){
318 if((*itr))(*itr)->setProdTime(ptime);
324 StDbConfigNodeImpl::setTablesProdTimeOverride(
unsigned int ptime,
char*
dbType,
char*
dbDomain) {
325 TableList::iterator itr;
326 for(itr = mTables.begin(); itr!=mTables.end(); ++itr) {
327 if((*itr))(*itr)->setProdTime(ptime);
337 if((strcmp(tab1->printName(),tab2->printName())!=0))
return retVal;
338 if((strcmp(tab1->printVersion(),tab2->printVersion())!=0))
return retVal;
340 int nRows1;
int nRows2;
341 int* elements1 = tab1->getElementID(nRows1);
342 int* elements2 = tab2->getElementID(nRows2);
343 if(nRows1 != nRows2)
return retVal;
345 for(i=0;i<nRows1;i++)
if(elements1[i] != elements2[i])
break;
346 if(i==nRows1)retVal=
true;
351 StDbElementIndex* StDbConfigNodeImpl::getElementIndex(){
return melementIndex; }
355 StDbConfigNodeImpl::setElementIndexInfo(
const char* indexName,
int indexID){
356 mindexRef=melementIndex->addNameValuePair(indexName,indexID);
361 StDbConfigNodeImpl::getElementIndexInfo(
char*& indexName,
int& indexID){
363 if(mindexRef < 0){ indexName=0;
return; }
364 indexName=melementIndex->getIndexName(mindexRef);
365 indexID =melementIndex->getIndexVal(mindexRef);
370 StDbConfigNodeImpl::getNumIndeces()
const {
return melementIndex->getNumIndeces();}
374 StDbConfigNodeImpl::getStDbTableIter(){
382 StDbConfigNodeImpl::resetConfig(
const char* configName,
int opt){
384 if(mfirstChildNode)mfirstChildNode->deleteTree();
385 if(mhasData)deleteTables();
386 setVersion(configName);
393 StDbConfigNodeImpl::deleteTables(){
394 for(
auto &it : mTables )
delete it;
401 StDbConfigNodeImpl::addChildren(
dbEnvList* elist){
402 #define __METHOD__ "addChildren(dbEnvList*)"
404 for(
int i=0; i<elist->num; i++){
405 char*
id=strstr(elist->envVar[i],
"_");
408 if(strcmp(
id,mname) && !findChildConfigNode(
id)){
410 nm<<
" Adding DataBase="<<elist->envVar[i]<<
" with KEY=";
411 nm<<elist->envDef[i]<<
" from Environment variable definition";
423 StDbConfigNodeImpl::printTables(
int depth){
427 for(
int k=0;k<depth;k++)os<<
" ";
429 string pdepth=os.str();
430 TableList::iterator itr;
431 for(itr = mTables.begin(); itr!=mTables.end(); ++itr){
432 cout<<pdepth<<
"Table="<<(*itr)->printName()<<
", Version="<<(*itr)->printVersion();
434 int* eIDs=(*itr)->getElementID(nRows);
435 cout <<
", numRows="<<nRows;
436 if(nRows==1)cout<<
", elementID="<<eIDs[0];
444 StDbConfigNodeImpl::printNumberStats() {
445 #define __METHOD__ "printNumberStats()"
447 unsigned int numNodes, numTables, numBytes;
448 numNodes=numTables=numBytes=0;
449 getNumberStats(numNodes,numTables, numBytes);
450 double kbs = ((double)numBytes)/1000.0;
452 cos<<
"******************** Number Stats ******************** "<<stendl;
453 cos<<
"Total Number of Nodes = "<<numNodes <<stendl;
454 cos<<
"Total Number of Tables = "<<numTables <<stendl;
455 cos<<
"Total Size of Data in Tables = "<<kbs<<
" kBytes" <<stendl;
456 cos<<
"******************************************************" <<stendl;
466 StDbConfigNodeImpl::getNumberStats(
unsigned int& numNodes,
unsigned int& numTables,
unsigned int& numBytes){
471 while((itr) && !(itr->done())){
474 numBytes+=(table->getTableSize()*table->GetNRows());
477 if(mfirstChildNode)mfirstChildNode->getNumberStats(numNodes,numTables,numBytes);
478 if(mnextNode)mnextNode->getNumberStats(numNodes,numTables,numBytes);
void version(std::ostream &os=std::cout)
print HepMC version
static StDbManager * Instance()
strdup(..) is not ANSI