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
#include "StDbNode.hh"
00074
#include "StDbDefaults.hh"
00075
#include "stdb_streams.h"
00076
#include <stdlib.h>
00077
00078
#ifdef __ROOT__
00079
ClassImp(
StDbNode)
00080 #endif
00081
00083
00084 StDbNode::StDbNode(
const char* name,
const char* versionKey): mname(0), mversion(0), mdbName(0), mnodeID(0),mnodeType(0){
00085
00086
setName(name);
00087
setVersion(versionKey);
00088
misConfigured =
false;
00089
mcanRollBack =
false;
00090 }
00091
00093 StDbNode::StDbNode(
const char* name ): mname(0), mversion(0), mdbName(0), mnodeID(0) ,mnodeType(0){
00094
setName(name);
00095
setVersion(StDbDefaults::Instance()->
printVersion());
00096
misConfigured =
false;
00097
mcanRollBack =
false;
00098 }
00099
00101 StDbNode::StDbNode(
StDbNode& node){
00102
00103
mname = node.
getName();
00104
mversion = node.
getVersion();
00105
mdbName = node.
getDbName();
00106
mdbType = node.
getDbType();
00107
mdbDomain = node.
getDbDomain();
00108
mnodeID = node.
getNodeID();
00109
mnodeType = node.
getNodeType();
00110
misConfigured = node.
IsConfigured();
00111
mcanRollBack = node.
canRollBack();
00112 }
00113
00115 StDbNode::~StDbNode(){
00116
if(
mname)
delete []
mname;
00117
if(
mversion)
delete []
mversion;
00118
if(
mdbName)
delete []
mdbName;
00119
if(
mnodeType)
delete []
mnodeType;
00120 }
00121
00123
00124 char*
StDbNode::getName() {
return mstrDup((
const char*)
mname); };
00125 char*
StDbNode::getVersion() {
return mstrDup((
const char*)
mversion); }
00126 char*
StDbNode::getDbName() {
return mstrDup((
const char*)
mdbName); }
00127 char*
StDbNode::getNodeType() {
return mstrDup(
mnodeType); }
00128
00129 void StDbNode::setName(
const char* nodeName) {
00130
if(
mname)
delete []
mname;
00131
mname=
mstrDup(nodeName);
00132 }
00133 void StDbNode::setVersion(
const char* version){
00134
if(
mversion)
delete []
mversion;
00135
mversion=
mstrDup(version);
00136 }
00137 void StDbNode::setDbName(
const char* dbName) {
00138
if(
mdbName)
delete []
mdbName;
00139
mdbName=
mstrDup(dbName);
00140 }
00141 void StDbNode::setNodeType(
const char* type) {
00142
if(
mnodeType)
delete []
mnodeType;
00143
mnodeType=
mstrDup(type);
00144 }
00145
00147 int*
StDbNode::decodeElementID(
const char* elemID,
int& numRows) {
00148
00149 numRows=1;
00150
int * retVal = 0;
00151
char*
id=strstr((
char*)elemID,
"None");
00152
00153
if(
id){
00154 numRows=1;
00155
int* e =
new int[1]; *e=0;
00156
return e;
00157 }
00158
00159
char* tmpName =
new char[strlen(elemID)+1];
00160 strcpy(tmpName,elemID);
00161
00162
int numElements = 1;
00163
id = strstr(tmpName,
",");
00164
char* id1;
00165
char* id2;
00166
00167 id2 = strstr(tmpName,
"-");
00168
StString sl;
00169
00170
if(id2 && ( (
id && id2<
id) || !
id)){
00171
id=id2;
00172
id[0]=
',';
00173 sl<<
"r";
00174 }
else {
00175 sl<<
"l";
00176 }
00177
00178
int numEntries = 1;
00179
if(
id)
id++;
00180
while(
id){
00181
00182 numEntries++;
00183 id1=strstr(
id,
",");
00184 id2=strstr(
id,
"-");
00185
id = id1;
00186
if(
id && id2 && id2<
id){
00187
id=id2;
00188
id[0]=
',';
00189 sl<<
"r";
00190 }
else {
00191 sl<<
"l";
00192 }
00193
if(
id)
id++;
00194 }
00195
char* islist=
new char[strlen((sl.
str()).c_str())+1];
00196 strcpy(islist,(sl.
str()).c_str());
00197
00198
00199
00200
int* tmpElements =
new int[100000];
00201
char* p1=&tmpName[0];
00202
char* anID=0;
00203 anID =
getNextID(p1);
00204 tmpElements[0] = atoi(anID);
00205
if(anID)
delete [] anID;
00206 numElements = 1;
00207
int iEnd, iStart, k;
00208
for(
int ient=1;ient<numEntries;ient++){
00209 anID = getNextID(p1);
00210
if(islist[ient-1]==
'r'){
00211 iEnd = atoi(anID);
00212 iStart = tmpElements[numElements-1];
00213
int irange=iEnd-iStart;
00214
for(
int ir=1;ir<=irange;ir++){
00215 numElements++;
00216 tmpElements[numElements-1]=iStart+ir;
00217 }
00218 }
else {
00219 numElements++;
00220 tmpElements[numElements-1]=atoi(anID);
00221 }
00222
if(anID)
delete [] anID;
00223 }
00224
00225 retVal =
new int[numElements];
00226
for(k=0;k<numElements;k++)retVal[k]=tmpElements[k];
00227 numRows = numElements;
00228
00229
delete [] islist;
00230
delete [] tmpElements;
00231
delete [] tmpName;
00232
00233
return retVal;
00234 }
00235
00237
char*
00238 StDbNode::getNextID(
char*& currentElement)
const {
00239
00240
char* nextID = 0;
00241
if(!currentElement)
return nextID;
00242
00243
char*
id = strstr(currentElement,
",");
00244
00245
if(!
id) {
00246 nextID =
new char[strlen(currentElement)+1];
00247 strcpy(nextID,currentElement);
00248 currentElement = 0;
00249 }
else {
00250
int iloc =
id-currentElement;
00251 nextID =
new char[iloc+1];
00252 strncpy(nextID,currentElement,iloc);
00253 nextID[iloc]=
'\0';
00254 currentElement =
id; currentElement++;
00255 }
00256
00257
return nextID;
00258 }
00259
00261 char*
StDbNode::mstrDup(
const char* s2) {
00262
00263
char* s1=0;
00264
if(!s2)
return s1;
00265 s1 =
new char[strlen(s2)+1];
00266 strcpy(s1,s2);
00267
return s1;
00268 }
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281