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

StDbTableDescriptor Class Reference

#include <StDbTableDescriptor.h>

Inheritance diagram for StDbTableDescriptor:

StTableDescriptorI List of all members.

Public Member Functions

 StDbTableDescriptor ()
 StDbTableDescriptor (int structID, int schemaID)
 StDbTableDescriptor (StDbTableDescriptor &d)
virtual ~StDbTableDescriptor ()
virtual void fillElement (StDbBuffer *buff, int tableID)
virtual StTableDescriptorIgetCpy ()
virtual tableDescriptorgetTableDescriptor () const
virtual unsigned int getNumElements () const
virtual unsigned int getTotalSizeInBytes () const
virtual char * getElementName (int elementNum) const
virtual unsigned int getElementOffset (int elementNum) const
virtual unsigned int getElementSize (int elementNum) const
virtual StTypeE getElementType (int elementNum) const
virtual unsigned int * getElementDimensions (int elementNum) const
virtual unsigned int getElementLength (int elementNum) const
virtual unsigned int getElementNumDimensions (int elementNum) const
virtual unsigned int getElementIndexLength (int elementNum, int dimensionNum) const
int getSchemaID () const
int getStructID () const
void setSchemaID (int id)
void setStructID (int id)
bool IsValid () const
int getCurrentInternalSize ()
int getTrowSize ()
void endRowPadding ()
void storeRowSize (int rowSize)

Protected Member Functions

void init ()
virtual void reSize ()
virtual void fillSizeAndOffset (char *length, int elementNum)
virtual void fillLengths (char *length, int elementNum)
virtual StTypeE getType (char *type)
virtual unsigned int getSize (StTypeE type)

Protected Attributes

unsigned int mnumElements
unsigned int mtableSize
int offsetToNextEmptyByte
int offsetToLast4Bytes
StTypeE lastType
int padsize
tableDescriptormcols
int mMax
int mCur
int mstructID
int mschemaID
bool misValid
bool mhasDouble

Static Protected Attributes

int rowSizeTT = 0

Constructor & Destructor Documentation

StDbTableDescriptor::StDbTableDescriptor  ) 
 

Definition at line 137 of file StDbTableDescriptor.cc.

00137 { init(); }

StDbTableDescriptor::StDbTableDescriptor int  structID,
int  schemaID
 

Definition at line 141 of file StDbTableDescriptor.cc.

00141 { 00142 00143 init(); 00144 mstructID=structID; 00145 mschemaID=schemaID; 00146 00147 };

StDbTableDescriptor::StDbTableDescriptor StDbTableDescriptor d  ) 
 

Definition at line 172 of file StDbTableDescriptor.cc.

00172 { 00173 00174 mCur = (int)d.getNumElements()-1; 00175 mMax = d.getCurrentInternalSize(); 00176 offsetToNextEmptyByte = 0; 00177 offsetToLast4Bytes = 0; 00178 mcols = d.getTableDescriptor(); 00179 mnumElements=d.getNumElements(); 00180 mtableSize = d.getTotalSizeInBytes(); 00181 mschemaID=d.getSchemaID(); 00182 mstructID=d.getStructID(); 00183 misValid=d.IsValid(); 00184 mhasDouble=d.mhasDouble; 00185 00186 }

virtual StDbTableDescriptor::~StDbTableDescriptor  )  [inline, virtual]
 

Definition at line 111 of file StDbTableDescriptor.h.

00111 {if(mcols) delete [] mcols; }


Member Function Documentation

void StDbTableDescriptor::endRowPadding  ) 
 

Definition at line 407 of file StDbTableDescriptor.cc.

00407 { 00408 00409 //simple item for solaris & use of doubles & longlong. 00410 // if the struct contains such an entity, it's size must 00411 // be divisable by 8. 00412 00413 #ifndef __linux__ 00414 if(mhasDouble){ 00415 int checkPadding=mtableSize%8; 00416 if(checkPadding>0 && checkPadding<5)mtableSize+=4; 00417 } 00418 #endif 00419 00420 };

void StDbTableDescriptor::fillElement StDbBuffer buff,
int  tableID
[virtual]
 

Definition at line 211 of file StDbTableDescriptor.cc.

00211 { 00212 00213 //bool ClientMode; 00214 // if(!(ClientMode=buff->IsClientMode()))buff->SetClientMode(); 00215 int schemaID; 00216 if(tableID){ // mask off elements if tableID is non-zero 00217 if(!(buff->ReadScalar(schemaID,"schemaID") && (schemaID==tableID)) ){ 00218 // skip this one 00219 return; 00220 } 00221 } 00222 00223 reSize(); // increase array if needed 00224 int i = mCur; 00225 char* mtype = 0; 00226 char* mname = 0; 00227 buff->ReadScalar(mname,"name"); 00228 if(mname)strcpy(mcols[i].name,mname); 00229 if(mname) delete [] mname; 00230 if(buff->ReadScalar(mtype,"type")){ 00231 mcols[i].type = getType(mtype); 00232 if(mtype)delete [] mtype; 00233 char* length=0; 00234 if(buff->ReadScalar(length,"length"))fillSizeAndOffset(length,i); 00235 if(length) delete [] length; 00236 } 00237 00238 if(mcols[i].type==Stlonglong || mcols[i].type==Stdouble ) mhasDouble=true; 00239 00240 mCur++; 00241 mnumElements++; 00242 00243 // for multiple rows, add padding as needed at end of structure (tableSize) 00244 int rowpad; 00245 if((rowpad=offsetToNextEmptyByte%2))rowpad=2-rowpad; 00246 00247 mtableSize = offsetToNextEmptyByte+rowpad; 00248 00249 //if(!ClientMode)buff->SetStorageMode(); // reset to StorageMode 00250 00251 misValid=true; 00252 00253 }

void StDbTableDescriptor::fillLengths char *  length,
int  elementNum
[protected, virtual]
 

Definition at line 277 of file StDbTableDescriptor.cc.

00277 { 00278 00279 int ip = 0; 00280 int i=elementNum; 00281 char* id= strstr(length,","); 00282 00283 // preset lengths to 1; 00284 00285 int k= (int)(sizeof(mcols[i].dimensionlen)/sizeof(ip)); 00286 for(int j=0;j<k;j++)mcols[i].dimensionlen[j]=1; 00287 00288 while (id && ip<3) { 00289 id[0]='\0'; 00290 mcols[i].dimensionlen[ip] = atoi(length); 00291 ip++; 00292 id++; 00293 length=id; 00294 id= strstr(length,","); 00295 } 00296 mcols[i].dimensionlen[ip]=atoi(length); 00297 00298 }

void StDbTableDescriptor::fillSizeAndOffset char *  length,
int  elementNum
[protected, virtual]
 

Definition at line 303 of file StDbTableDescriptor.cc.

00303 { 00304 00305 00306 int i = elementNum; 00307 fillLengths(length,i); 00308 int space = 4-(offsetToNextEmptyByte-offsetToLast4Bytes); 00309 00310 int j,jj; 00311 StTypeE type = mcols[i].type; 00312 j=0; 00313 mcols[i].size = getSize(mcols[i].type); 00314 int k= (int)(sizeof(mcols[i].dimensionlen)/sizeof(j)); 00315 for(j=0;j<k;j++)mcols[i].size*=mcols[i].dimensionlen[j]; 00316 00317 if(offsetToLast4Bytes < 0){ 00318 00319 mcols[i].offset = 0; 00320 offsetToNextEmptyByte = mcols[i].offset+mcols[i].size; 00321 j = 4* ((int) floor ( (float) (mcols[i].size-1)/4 )); 00322 offsetToLast4Bytes = mcols[i].offset + j;// + 4; 00323 00324 00325 } else if(type==Stchar || type==Stuchar){ 00326 00327 mcols[i].offset=offsetToNextEmptyByte; 00328 offsetToNextEmptyByte = mcols[i].offset+mcols[i].size; 00329 jj=mcols[i].offset+mcols[i].size-offsetToLast4Bytes; 00330 if(jj>1) 00331 j = 4* ((int) floor ((float) (jj-1)/4 )); 00332 // j= number of bytes (in 4s) past last offset 00333 if(j) 00334 offsetToLast4Bytes = offsetToLast4Bytes+j; 00335 00336 } else if( (space>=2) && (type == Stshort || type == Stushort) ){ 00337 00338 mcols[i].offset=offsetToLast4Bytes+2; 00339 j = 4* ((int) floor ((float) (mcols[i].size-2-1)/4 )); // note the 2 00340 offsetToNextEmptyByte=mcols[i].offset+mcols[i].size; 00341 jj=mcols[i].offset+mcols[i].size-offsetToLast4Bytes; 00342 if(jj>1) 00343 j = 4* ((int) floor ((float) (jj-1)/4 )); 00344 // j= number of bytes (in 4s) past last offset 00345 if(j) 00346 offsetToLast4Bytes = offsetToLast4Bytes+j; 00347 00348 } else { 00349 00350 00351 if( (type==Stdouble || type==Stlonglong) && 00352 (lastType != Stdouble) && (lastType != Stlonglong) && padsize < 8){ 00353 offsetToLast4Bytes+=padsize; 00354 offsetToNextEmptyByte+=padsize; 00355 } 00356 00357 mcols[i].offset=offsetToLast4Bytes+4; 00358 offsetToNextEmptyByte = mcols[i].offset + mcols[i].size; 00359 j = 4* ((int) floor ((float) (mcols[i].size-1)/4 )); 00360 offsetToLast4Bytes = mcols[i].offset + j;// + 4; 00361 00362 } 00363 00364 if(offsetToLast4Bytes<0)offsetToLast4Bytes=0; 00365 00366 #ifdef __linux__ 00367 lastType=Stdouble; 00368 #else 00369 if(type==Stdouble || type==Stlonglong )padsize = 0; 00370 lastType=type; 00371 00372 unsigned int onesize = getSize(mcols[i].type); 00373 for(j=0;j<k;j++){ 00374 if(mcols[i].dimensionlen[j]==1 && j>0)continue; 00375 for(int jk=0; jk< (int)mcols[i].dimensionlen[j]; jk++){ 00376 padsize=padsize+(int)onesize; 00377 if(padsize>=8)padsize=padsize-8; 00378 } 00379 } 00380 if(padsize>0 && padsize<=4) padsize=4; 00381 // padsize = 4* ((int) floor ((float) (padsize)/4 )); 00382 00383 #endif 00384 }

StTableDescriptorI * StDbTableDescriptor::getCpy  )  [virtual]
 

Implements StTableDescriptorI.

Definition at line 202 of file StDbTableDescriptor.cc.

00202 { 00203 00204 StTableDescriptorI* dScr = new StDbTableDescriptor(*this); 00205 return dScr; 00206 00207 }

int StDbTableDescriptor::getCurrentInternalSize  )  [inline]
 

Definition at line 207 of file StDbTableDescriptor.h.

00207 { return mMax; };

unsigned int * StDbTableDescriptor::getElementDimensions int  elementNum  )  const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 167 of file StDbTableDescriptor.h.

00167 { 00168 return &mcols[elementNum].dimensionlen[0]; 00169 }

unsigned int StDbTableDescriptor::getElementIndexLength int  elementNum,
int  dimensionNum
const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 197 of file StDbTableDescriptor.h.

00197 { 00198 return mcols[elementNum].dimensionlen[dimensionNum]; 00199 }

unsigned int StDbTableDescriptor::getElementLength int  elementNum  )  const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 174 of file StDbTableDescriptor.h.

00174 { 00175 00176 int retVal=1; 00177 int j; 00178 int k= (int)(sizeof(mcols[elementNum].dimensionlen)/sizeof(j)); 00179 for(j=0;j<k;j++)retVal *= mcols[elementNum].dimensionlen[j]; 00180 return retVal; 00181 }

char * StDbTableDescriptor::getElementName int  elementNum  )  const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 147 of file StDbTableDescriptor.h.

00147 { 00148 char* retVal = new char[strlen(mcols[elementNum].name)+1]; 00149 strcpy(retVal,mcols[elementNum].name); 00150 return retVal; 00151 }

unsigned int StDbTableDescriptor::getElementNumDimensions int  elementNum  )  const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 186 of file StDbTableDescriptor.h.

00186 { 00187 int retVal=1; 00188 int j; 00189 int k= (int)(sizeof(mcols[elementNum].dimensionlen)/sizeof(j)); 00190 for(j=0;j<k;j++){ 00191 if(mcols[elementNum].dimensionlen[j]>1)retVal=j+1; // last dimension >1 00192 } 00193 return retVal; 00194 }

unsigned int StDbTableDescriptor::getElementOffset int  elementNum  )  const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 154 of file StDbTableDescriptor.h.

00154 { 00155 return mcols[elementNum].offset; 00156 }

unsigned int StDbTableDescriptor::getElementSize int  elementNum  )  const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 158 of file StDbTableDescriptor.h.

00158 { 00159 return mcols[elementNum].size; 00160 }

StTypeE StDbTableDescriptor::getElementType int  elementNum  )  const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 162 of file StDbTableDescriptor.h.

00162 { 00163 return mcols[elementNum].type; 00164 }

unsigned int StDbTableDescriptor::getNumElements  )  const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 141 of file StDbTableDescriptor.h.

00141 {return mnumElements;}

int StDbTableDescriptor::getSchemaID  )  const [inline]
 

Definition at line 202 of file StDbTableDescriptor.h.

00202 { return mschemaID; }

unsigned int StDbTableDescriptor::getSize StTypeE  type  )  [inline, protected, virtual]
 

Definition at line 201 of file StDbTableDescriptor.h.

00201 { return mycsize[type];}

int StDbTableDescriptor::getStructID  )  const [inline]
 

Definition at line 203 of file StDbTableDescriptor.h.

00203 { return mstructID; }

tableDescriptor * StDbTableDescriptor::getTableDescriptor  )  const [virtual]
 

Definition at line 191 of file StDbTableDescriptor.cc.

00191 { 00192 00193 tableDescriptor* dScr = new tableDescriptor[mMax]; 00194 memset(dScr,0,(mMax)*sizeof(tableDescriptor)); 00195 memcpy(dScr,mcols,(mMax)*sizeof(tableDescriptor)); 00196 00197 return dScr; 00198 }

unsigned int StDbTableDescriptor::getTotalSizeInBytes  )  const [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 144 of file StDbTableDescriptor.h.

00144 {return mtableSize;}

int StDbTableDescriptor::getTrowSize  )  [inline, virtual]
 

Implements StTableDescriptorI.

Definition at line 209 of file StDbTableDescriptor.h.

00209 { return rowSizeTT; };

StTypeE StDbTableDescriptor::getType char *  type  )  [protected, virtual]
 

Definition at line 389 of file StDbTableDescriptor.cc.

00389 { 00390 00391 StTypeE retVal=Stchar; 00392 00393 //char* typenames[] = {"Stchar","Stuchar","Stshort","Stushort","Stint","Stuint","Stlong","Stulong","Stfloat","Stdouble","Stascii","Ststring"}; 00394 const char* typenames[] = {"char","uchar","short","ushort","int","uint","long","ulong","longlong","float","double","ascii","string"}; 00395 00396 for(int i=0; i<12;i++){ 00397 if(strcmp(type,typenames[i])==0){ 00398 retVal=(StTypeE)i; 00399 break; 00400 } 00401 } 00402 00403 return retVal; 00404 }

void StDbTableDescriptor::init  )  [protected]
 

Definition at line 152 of file StDbTableDescriptor.cc.

00152 { 00153 00154 mtableSize=0; 00155 mCur = 0; 00156 mMax = 100; 00157 offsetToNextEmptyByte = 0; 00158 offsetToLast4Bytes = -4; 00159 mnumElements = 0; 00160 lastType=Stdouble; 00161 padsize = 0; 00162 mcols = new tableDescriptor[mMax]; 00163 memset(mcols,0,mMax*sizeof(tableDescriptor)); 00164 mschemaID=mstructID=0; 00165 misValid=false; 00166 mhasDouble=false; 00167 00168 }

bool StDbTableDescriptor::IsValid  )  const [inline]
 

Definition at line 206 of file StDbTableDescriptor.h.

00206 { return misValid; }

void StDbTableDescriptor::reSize  )  [protected, virtual]
 

Definition at line 259 of file StDbTableDescriptor.cc.

00259 { 00260 00261 // simply add 10 elements 00262 00263 if(mCur<mMax) return; 00264 00265 int newMax = mMax+10; 00266 tableDescriptor* dScr = new tableDescriptor[newMax]; 00267 memcpy(dScr,mcols,(mMax)*sizeof(tableDescriptor)); 00268 if(mcols)delete [] mcols; 00269 mcols=dScr; 00270 mMax=newMax; 00271 00272 }

void StDbTableDescriptor::setSchemaID int  id  )  [inline]
 

Definition at line 204 of file StDbTableDescriptor.h.

00204 { mschemaID=id; }

void StDbTableDescriptor::setStructID int  id  )  [inline]
 

Definition at line 205 of file StDbTableDescriptor.h.

00205 { mstructID=id; }

void StDbTableDescriptor::storeRowSize int  rowSize  )  [inline]
 

Definition at line 208 of file StDbTableDescriptor.h.

00208 { rowSizeTT = rowSize; }


Member Data Documentation

StTypeE StDbTableDescriptor::lastType [protected]
 

Definition at line 84 of file StDbTableDescriptor.h.

tableDescriptor* StDbTableDescriptor::mcols [protected]
 

Definition at line 87 of file StDbTableDescriptor.h.

int StDbTableDescriptor::mCur [protected]
 

Definition at line 89 of file StDbTableDescriptor.h.

bool StDbTableDescriptor::mhasDouble [protected]
 

Definition at line 97 of file StDbTableDescriptor.h.

bool StDbTableDescriptor::misValid [protected]
 

Definition at line 96 of file StDbTableDescriptor.h.

int StDbTableDescriptor::mMax [protected]
 

Definition at line 88 of file StDbTableDescriptor.h.

unsigned int StDbTableDescriptor::mnumElements [protected]
 

Definition at line 80 of file StDbTableDescriptor.h.

int StDbTableDescriptor::mschemaID [protected]
 

Definition at line 93 of file StDbTableDescriptor.h.

int StDbTableDescriptor::mstructID [protected]
 

Definition at line 92 of file StDbTableDescriptor.h.

unsigned int StDbTableDescriptor::mtableSize [protected]
 

Definition at line 81 of file StDbTableDescriptor.h.

int StDbTableDescriptor::offsetToLast4Bytes [protected]
 

Definition at line 83 of file StDbTableDescriptor.h.

int StDbTableDescriptor::offsetToNextEmptyByte [protected]
 

Definition at line 82 of file StDbTableDescriptor.h.

int StDbTableDescriptor::padsize [protected]
 

Definition at line 85 of file StDbTableDescriptor.h.

int StDbTableDescriptor::rowSizeTT = 0 [static, protected]
 

Definition at line 133 of file StDbTableDescriptor.cc.


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