00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
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
00228
00229
00230
00231
00232
00233
StDbConfigNode* node = 0;
00234
00235
00236
if(isNode(type,domain)){
00237
if(
mparentNode &&
mparentNode->
isNode(type,domain))
00238
return mparentNode->
findConfigNode(type,domain);
00239
return this;
00240 }
00241
00242
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
00255
00256
00257
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=
'/';
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__