00001 /*************************************************************************** 00002 * 00003 * $Id: StDbTableDescriptor.h,v 1.9 2005/09/07 22:04:02 deph Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: Class implement table-descriptor (memory/name of data-elements) 00009 * this descriptor is loaded from database 00010 * 00011 *************************************************************************** 00012 * 00013 * $Log: StDbTableDescriptor.h,v $ 00014 * Revision 1.9 2005/09/07 22:04:02 deph 00015 * update to correct padding issue for packed tables 00016 * 00017 * Revision 1.8 2001/12/05 17:16:35 porter 00018 * stand-alone make file no longer had "DLINUX" in compile but this is still needed 00019 * and returned. Also retrieve elementID list in query by whereClause for plotting 00020 * many row instances. 00021 * 00022 * Revision 1.7 2001/01/22 18:38:00 porter 00023 * Update of code needed in next year running. This update has little 00024 * effect on the interface (only 1 method has been changed in the interface). 00025 * Code also preserves backwards compatibility so that old versions of 00026 * StDbLib can read new table structures. 00027 * -Important features: 00028 * a. more efficient low-level table structure (see StDbSql.cc) 00029 * b. more flexible indexing for new systems (see StDbElememtIndex.cc) 00030 * c. environment variable override KEYS for each database 00031 * d. StMessage support & clock-time logging diagnostics 00032 * -Cosmetic features 00033 * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access 00034 * f. removed codes that have been obsolete for awhile (e.g. db factories) 00035 * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI 00036 * and mysqlAccessor became StDbSql) 00037 * 00038 * Revision 1.6 2000/03/28 17:03:19 porter 00039 * Several upgrades: 00040 * 1. configuration by timestamp for Conditions 00041 * 2. query by whereClause made more systematic 00042 * 3. conflict between db-stored comments & number lists resolved 00043 * 4. ensure endtime is correct for certain query falures 00044 * 5. dbstl.h->handles ObjectSpace & RogueWave difference (Online vs Offline) 00045 * 00046 * Revision 1.5 1999/12/03 19:02:02 porter 00047 * modified descriptor to accept tableDescriptor once this St_base object 00048 * has been updated to have longer name lengths. 00049 * 00050 * Revision 1.4 1999/10/19 14:30:40 porter 00051 * modifications relevant to use with StDbBroker and future merging with 00052 * "params" database structure + some docs + suppressing diagnostics messages 00053 * 00054 * Revision 1.3 1999/09/30 02:06:10 porter 00055 * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor) 00056 * allow multiple rows (StDbTable), & Added the comment sections at top of 00057 * each header and src file 00058 * 00059 **************************************************************************/ 00060 #ifndef STDBTABLEDESCRIPTOR_HH 00061 #define STDBTABLEDESCRIPTOR_HH 00062 00063 #include <string.h> 00064 #include "StTableDescriptorI.h" 00065 #include "StDbBuffer.h" 00066 00067 struct tableDescriptor { 00068 StTypeE type; // enumerated basic type 00069 char name[60]; // element name 00070 unsigned int size; // element size in bytes 00071 unsigned int offset; // byte offset in table to this element 00072 unsigned int dimensionlen[4]; // len per dimension if multi-D array 00073 }; 00074 00075 00076 class StDbTableDescriptor : public StTableDescriptorI { 00077 00078 protected: 00079 00080 unsigned int mnumElements; 00081 unsigned int mtableSize; 00082 int offsetToNextEmptyByte; 00083 int offsetToLast4Bytes; 00084 StTypeE lastType; 00085 int padsize; 00086 00087 tableDescriptor* mcols; 00088 int mMax; 00089 int mCur; 00090 00091 // db unique ids 00092 int mstructID; 00093 int mschemaID; 00094 //MPD 00095 static int rowSizeTT; 00096 bool misValid; // schema has been filled 00097 bool mhasDouble; 00098 00099 void init(); 00100 virtual void reSize(); 00101 virtual void fillSizeAndOffset(char* length, int elementNum); 00102 virtual void fillLengths(char* length, int elementNum); 00103 virtual StTypeE getType(char* type); 00104 virtual unsigned int getSize(StTypeE type); 00105 00106 public: 00107 00108 StDbTableDescriptor(); 00109 StDbTableDescriptor(int structID, int schemaID); 00110 StDbTableDescriptor(StDbTableDescriptor& d); 00111 virtual ~StDbTableDescriptor() {if(mcols) delete [] mcols; } 00112 virtual void fillElement(StDbBuffer* buff, int tableID); 00113 00114 virtual StTableDescriptorI* getCpy(); 00115 virtual tableDescriptor* getTableDescriptor() const; 00116 virtual unsigned int getNumElements() const; 00117 virtual unsigned int getTotalSizeInBytes() const; 00118 virtual char* getElementName(int elementNum) const; 00119 virtual unsigned int getElementOffset(int elementNum) const; 00120 virtual unsigned int getElementSize(int elementNum) const; 00121 virtual StTypeE getElementType(int elementNum) const; 00122 virtual unsigned int* getElementDimensions(int elementNum) const; 00123 virtual unsigned int getElementLength(int elementNum) const; 00124 virtual unsigned int getElementNumDimensions(int elementNum) const; 00125 virtual unsigned int getElementIndexLength(int elementNum, int dimensionNum) const; 00126 00127 00128 int getSchemaID() const; 00129 int getStructID() const; 00130 void setSchemaID(int id); 00131 void setStructID(int id); 00132 bool IsValid() const; 00133 int getCurrentInternalSize(); 00134 int getTrowSize() ; 00135 void endRowPadding(); 00136 void storeRowSize(int rowSize); 00137 00138 }; 00139 00140 inline unsigned int 00141 StDbTableDescriptor::getNumElements() const {return mnumElements;} 00142 00143 inline unsigned int 00144 StDbTableDescriptor::getTotalSizeInBytes() const {return mtableSize;} 00145 00146 inline char* 00147 StDbTableDescriptor::getElementName(int elementNum) const { 00148 char* retVal = new char[strlen(mcols[elementNum].name)+1]; 00149 strcpy(retVal,mcols[elementNum].name); 00150 return retVal; 00151 } 00152 00153 inline unsigned int 00154 StDbTableDescriptor::getElementOffset(int elementNum) const { 00155 return mcols[elementNum].offset; 00156 } 00157 00158 inline unsigned int StDbTableDescriptor::getElementSize(int elementNum) const{ 00159 return mcols[elementNum].size; 00160 } 00161 00162 inline StTypeE StDbTableDescriptor::getElementType(int elementNum) const { 00163 return mcols[elementNum].type; 00164 } 00165 00166 inline unsigned int* 00167 StDbTableDescriptor::getElementDimensions(int elementNum) const { 00168 return &mcols[elementNum].dimensionlen[0]; 00169 } 00170 00172 00173 inline unsigned int 00174 StDbTableDescriptor::getElementLength(int elementNum) const { 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 } 00182 00184 00185 inline unsigned int 00186 StDbTableDescriptor::getElementNumDimensions(int elementNum) const { 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 } 00195 00196 inline unsigned int 00197 StDbTableDescriptor::getElementIndexLength(int elementNum, int dimensionNum) const { 00198 return mcols[elementNum].dimensionlen[dimensionNum]; 00199 } 00200 00201 inline unsigned int StDbTableDescriptor::getSize(StTypeE type){ return mycsize[type];} 00202 inline int StDbTableDescriptor::getSchemaID() const { return mschemaID; } 00203 inline int StDbTableDescriptor::getStructID() const { return mstructID; } 00204 inline void StDbTableDescriptor::setSchemaID(int id) { mschemaID=id; } 00205 inline void StDbTableDescriptor::setStructID(int id) { mstructID=id; } 00206 inline bool StDbTableDescriptor::IsValid() const { return misValid; } 00207 inline int StDbTableDescriptor::getCurrentInternalSize() { return mMax; }; 00208 inline void StDbTableDescriptor::storeRowSize(int rowSize) { rowSizeTT = rowSize; } 00209 inline int StDbTableDescriptor::getTrowSize() { return rowSizeTT; }; 00210 00211 00212 #endif 00213 00214 00215 00216 00217 00218