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

StDbConfigNode.cc

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * 00003 * $Id: StDbConfigNode.cc,v 1.25 2004/01/15 00:02:25 fisyak Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: Node (directory) to hold list of dbtables 00009 * 00010 *************************************************************************** 00011 * 00012 * $Log: StDbConfigNode.cc,v $ 00013 * Revision 1.25 2004/01/15 00:02:25 fisyak 00014 * Replace ostringstream => StString, add option for alpha 00015 * 00016 * Revision 1.24 2003/09/16 22:44:17 porter 00017 * got rid of all ostrstream objects; replaced with StString+string. 00018 * modified rules.make and added file stdb_streams.h for standalone compilation 00019 * 00020 * Revision 1.23 2003/09/02 17:57:49 perev 00021 * gcc 3.2 updates + WarnOff 00022 * 00023 * Revision 1.22 2003/01/10 04:19:20 porter 00024 * added feature of getting timestamp list (but no data) for a table. 00025 * fixed 2 features sometimes used in online in query-by-whereclause. 00026 * removed a stray 'cout' in a routine that is rarely accessed 00027 * 00028 * Revision 1.21 2001/10/26 16:35:28 porter 00029 * improved directory search 00030 * 00031 * Revision 1.20 2001/01/22 18:37:52 porter 00032 * Update of code needed in next year running. This update has little 00033 * effect on the interface (only 1 method has been changed in the interface). 00034 * Code also preserves backwards compatibility so that old versions of 00035 * StDbLib can read new table structures. 00036 * -Important features: 00037 * a. more efficient low-level table structure (see StDbSql.cc) 00038 * b. more flexible indexing for new systems (see StDbElememtIndex.cc) 00039 * c. environment variable override KEYS for each database 00040 * d. StMessage support & clock-time logging diagnostics 00041 * -Cosmetic features 00042 * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access 00043 * f. removed codes that have been obsolete for awhile (e.g. db factories) 00044 * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI 00045 * and mysqlAccessor became StDbSql) 00046 * 00047 * Revision 1.19 2000/06/30 01:57:01 porter 00048 * fixed a delete bug & small memory leak found by Akio via Insure++ , 00049 * updated SetTable() method for containing idList, corrected enumeration 00050 * map to rhic domain for Conditions_rhic database 00051 * 00052 * Revision 1.18 2000/04/25 18:26:02 porter 00053 * added flavor & production time as settable query fields in 00054 * table &/or node. Associated SQL updated in mysqlAccessor. 00055 * Flavor key supports "+" as an OR symbol. 00056 * 00057 * Revision 1.17 2000/03/28 17:03:18 porter 00058 * Several upgrades: 00059 * 1. configuration by timestamp for Conditions 00060 * 2. query by whereClause made more systematic 00061 * 3. conflict between db-stored comments & number lists resolved 00062 * 4. ensure endtime is correct for certain query falures 00063 * 5. dbstl.h->handles ObjectSpace & RogueWave difference (Online vs Offline) 00064 * 00065 * Revision 1.16 2000/03/01 20:56:15 porter 00066 * 3 items: 00067 * 1. activated reConnect for server timeouts 00068 * 2. activated connection sharing; better resource utilization but poorer 00069 * logging 00070 * 3. made rollback method in mysqlAccessor more robust (affects writes only) 00071 * 00072 * Revision 1.15 2000/02/15 20:27:44 porter 00073 * Some updates to writing to the database(s) via an ensemble (should 00074 * not affect read methods & haven't in my tests. 00075 * - closeAllConnections(node) & closeConnection(table) method to mgr. 00076 * - 'NullEntry' version to write, with setStoreMode in table; 00077 * - updated both StDbTable's & StDbTableDescriptor's copy-constructor 00078 * 00079 * Revision 1.14 2000/01/27 05:54:33 porter 00080 * Updated for compiling on CC5 + HPUX-aCC + KCC (when flags are reset) 00081 * Fixed reConnect()+transaction model mismatch 00082 * added some in-code comments 00083 * 00084 * Revision 1.13 2000/01/19 20:20:04 porter 00085 * - finished transaction model needed by online 00086 * - fixed CC5 compile problem in StDbNodeInfo.cc 00087 * - replace TableIter class by StDbTableIter to prevent name problems 00088 * 00089 * Revision 1.12 2000/01/14 14:50:52 porter 00090 * expanded use of verbose mode & fixed inconsistency in 00091 * StDbNodeInfo::getElementID 00092 * 00093 * Revision 1.11 2000/01/10 20:37:53 porter 00094 * expanded functionality based on planned additions or feedback from Online work. 00095 * update includes: 00096 * 1. basis for real transaction model with roll-back 00097 * 2. limited SQL access via the manager for run-log & tagDb 00098 * 3. balance obtained between enumerated & string access to databases 00099 * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose 00100 * 5. restructured Node model for better XML support 00101 * 00102 * Revision 1.10 1999/12/28 21:31:41 porter 00103 * added 'using std::vector' and 'using std::list' for Solaris CC5 compilation. 00104 * Also fixed some warnings arising from the CC5 compiles 00105 * 00106 * Revision 1.9 1999/12/03 22:24:00 porter 00107 * expanded functionality used by online, fixed bug in 00108 * mysqlAccessor::getElementID(char*), & update StDbDataSet to 00109 * conform to changes in Xml reader & writer 00110 * 00111 * Revision 1.8 1999/09/30 02:06:03 porter 00112 * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor) 00113 * allow multiple rows (StDbTable), & Added the comment sections at top of 00114 * each header and src file 00115 * 00116 **************************************************************************/ 00117 00118 #include "stdb_streams.h" 00119 #include <string.h> 00120 00121 #include "StDbConfigNode.hh" 00122 #include "StDbManager.hh" 00123 #include "StDbTable.h" 00124 00125 #ifdef __ROOT__ 00126 ClassImp(StDbConfigNode) 00127 #endif 00128 00129 #define __CLASS__ "StDbConfigNode" 00130 00132 00133 StDbConfigNode::StDbConfigNode(StDbConfigNode* parent, const char* nodeName, const char* configName): StDbNode(nodeName,configName) { 00134 00135 zeroNodes(); 00136 setParentNode(parent); 00137 setDbName(parent->printDbName()); 00138 setDbType(parent->getDbType()); 00139 setDbDomain(parent->getDbDomain()); 00140 } 00141 00143 StDbConfigNode::StDbConfigNode(StDbConfigNode* parent, StDbNode& node): StDbNode(node) { 00144 zeroNodes(); 00145 setParentNode(parent); 00146 } 00147 00149 StDbConfigNode::StDbConfigNode(StDbType type, StDbDomain domain, const char* nodeName, const char* configName): StDbNode(nodeName,configName) { 00150 00151 zeroNodes(); 00152 mdbType = type; 00153 mdbDomain = domain; 00154 } 00155 00157 StDbConfigNode::~StDbConfigNode(){ deleteChildren();}; 00158 00160 void StDbConfigNode::zeroNodes() { 00161 mfirstChildNode=0; 00162 mnextNode=0; 00163 mparentNode=0; 00164 mhasData=false; 00165 mbranchID=0; 00166 misDbNode=false; 00167 }; 00168 00169 00171 void 00172 StDbConfigNode::setFlavor(const char* flavor){ 00173 00174 setTablesFlavor(flavor); 00175 if(mfirstChildNode)mfirstChildNode->setFlavor(flavor); 00176 if(mnextNode)mnextNode->setFlavor(flavor); 00177 00178 } 00179 00181 void 00182 StDbConfigNode::setProdTime(unsigned int ptime){ 00183 setTablesProdTime(ptime); 00184 if(mfirstChildNode)mfirstChildNode->setProdTime(ptime); 00185 if(mnextNode)mnextNode->setProdTime(ptime); 00186 } 00187 00188 00190 00191 void 00192 StDbConfigNode::deleteTree(){ 00193 00194 if(mfirstChildNode)delete mfirstChildNode; 00195 if(mnextNode){ 00196 mnextNode->deleteTree(); 00197 delete mnextNode; 00198 } 00199 } 00200 00202 void 00203 StDbConfigNode::deleteChildren(){ 00204 00205 StDbConfigNode* nextChild = mfirstChildNode; 00206 while(nextChild){ 00207 StDbConfigNode* node=nextChild->getNextNode(); 00208 delete nextChild; 00209 nextChild=node; 00210 } 00211 mfirstChildNode=0; 00212 } 00213 00215 00216 StDbConfigNode* 00217 StDbConfigNode::findConfigNode(StDbType type, StDbDomain domain, const char* subPath){ 00218 StDbConfigNode* node=findConfigNode(type,domain); 00219 return node->findConfigNode(subPath); 00220 } 00221 00223 00224 StDbConfigNode* 00225 StDbConfigNode::findConfigNode(StDbType type, StDbDomain domain){ 00226 00227 // Searches for the "highest" node of type & domain 00228 // e.g. if request Calibrations , tpc & node is of that 00229 // type & domain it checks parent 1st and if it is also 00230 // that type & domain returns this call to the parent node 00231 // .. else continue down the tree ... 00232 00233 StDbConfigNode* node = 0; 00234 00235 // search parent & this 00236 if(isNode(type,domain)){ 00237 if(mparentNode && mparentNode->isNode(type,domain)) 00238 return mparentNode->findConfigNode(type,domain); 00239 return this; 00240 } 00241 00242 // search children & sibs 00243 if(hasChildren())node=mfirstChildNode->findConfigNode(type,domain); 00244 if(!node && mnextNode)node = mnextNode->findConfigNode(type,domain); 00245 00246 return node; 00247 } 00248 00250 00251 StDbConfigNode* 00252 StDbConfigNode::findConfigNode(const char* subPath){ 00253 00254 // tries to find a node below (in the child sense) 00255 // where nodeName/nodeName/nodeName/... = subPath 00256 // 00257 // returns null pointer if not found 00258 00259 StDbConfigNode* node=0; 00260 if(!subPath) return node; 00261 char* path = mstrDup(subPath); 00262 00263 if(path[0]=='/')path++; 00264 char* id=strstr(path,"/"); 00265 if(id){ *id='\0'; id++; } 00266 char* nextNodeName=mstrDup(path); 00267 node=getFirstChildNode(); 00268 00269 if(node){ 00270 bool found = false; 00271 while(!found){ 00272 if(!node->checkName(nextNodeName)){ 00273 node=node->getNextNode(); 00274 if(!node) found=true; 00275 } else { 00276 found=true; 00277 } 00278 } 00279 00280 } 00281 00282 if(node && id) { 00283 node=node->findConfigNode(id); 00284 *id='/'; // make path whole again 00285 } 00286 00287 delete [] path; 00288 delete [] nextNodeName; 00289 00290 return node; 00291 } 00292 00294 StDbConfigNode* 00295 StDbConfigNode::findChildConfigNode(const char* name){ 00296 00297 StDbConfigNode* retVal=0; 00298 if(!name) return retVal; 00299 retVal=getFirstChildNode(); 00300 while(retVal){ 00301 if(retVal->checkName(name)) break; 00302 retVal=retVal->getNextNode(); 00303 } 00304 return retVal; 00305 } 00306 00308 void StDbConfigNode::setParentNode(StDbConfigNode* parent){ 00309 mparentNode = parent; 00310 parent->setChildNode(this); 00311 } 00312 00314 void StDbConfigNode::appendNode(StDbConfigNode* node){ 00315 if(mnextNode){ 00316 mnextNode->appendNode(node); 00317 } else { 00318 mnextNode = node; 00319 } 00320 } 00321 00323 void 00324 StDbConfigNode::setChildNode(StDbConfigNode* node){ 00325 if(mfirstChildNode) { 00326 mfirstChildNode->appendNode(node); 00327 } else { 00328 mfirstChildNode = node; 00329 } 00330 } 00331 00333 void 00334 StDbConfigNode::setFirstChildNode(StDbConfigNode* node){ 00335 if(mfirstChildNode)node->appendNode(mfirstChildNode); 00336 mfirstChildNode = 0; 00337 setChildNode(node); 00338 } 00339 00340 00342 00343 void 00344 StDbConfigNode::printTree(int depth){ 00345 00346 if(!depth)cout<<endl<<"************* Node Structure ****************" <<endl<<endl; 00347 00348 if(StDbManager::Instance()->IsVerbose()){ 00349 for(int k=0;k<depth;k++)cout<<" "; 00350 cout<<"Node=" << mname <<" VersionKey = " << mversion <<endl; 00351 if(mhasData) { 00352 int depth2 = depth+4; 00353 printTables(depth2); 00354 } 00355 } 00356 int depth3=depth+4; 00357 if(mfirstChildNode)mfirstChildNode->printTree(depth3); 00358 if(mnextNode)mnextNode->printTree(depth); 00359 00360 if(!depth)cout<<endl<<"*********************************************" << endl; 00361 00362 } 00363 #undef __CLASS__

Generated on Thu Aug 24 14:45:25 2006 for Doxygen by doxygen 1.3.7