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

StDbTable.h

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * 00003 * $Id: StDbTable.h,v 1.26 2005/09/07 22:04:02 deph Exp $ 00004 * 00005 * Author: R. Jeff Porter 00006 *************************************************************************** 00007 * 00008 * Description: Class that holds data, descriptor, & db-address 00009 * & performs streamer of db-data into data-memory 00010 * 00011 *************************************************************************** 00012 * 00013 * $Log: StDbTable.h,v $ 00014 * Revision 1.26 2005/09/07 22:04:02 deph 00015 * update to correct padding issue for packed tables 00016 * 00017 * Revision 1.25 2004/01/15 00:02:25 fisyak 00018 * Replace ostringstream => StString, add option for alpha 00019 * 00020 * Revision 1.24 2003/09/16 22:44:18 porter 00021 * got rid of all ostrstream objects; replaced with StString+string. 00022 * modified rules.make and added file stdb_streams.h for standalone compilation 00023 * 00024 * Revision 1.23 2003/09/02 17:57:49 perev 00025 * gcc 3.2 updates + WarnOff 00026 * 00027 * Revision 1.22 2003/04/11 22:47:36 porter 00028 * Added a fast multi-row write model specifically needed by the daqEventTag 00029 * writer. Speed increased from about 100Hz to ~3000Hz. It is only invoked if 00030 * the table is marked as Non-Indexed (daqTags & scalers). For non-indexed tables 00031 * which include binary stored data (we don't have any yet), the fast writer has 00032 * to invoke a slower buffer so that the rates are a bit slower (~500Hz at 50 rows/insert). 00033 * 00034 * Revision 1.21 2003/02/12 22:12:45 porter 00035 * moved warning message about null columns (checked in 2 days ago) from the 00036 * depths of the mysql coding into the StDbTable code. This suppresses confusing 00037 * warnings from tables that have had elements removed but their storage columns 00038 * still exist in the database. 00039 * 00040 * Revision 1.20 2003/01/10 04:19:21 porter 00041 * added feature of getting timestamp list (but no data) for a table. 00042 * fixed 2 features sometimes used in online in query-by-whereclause. 00043 * removed a stray 'cout' in a routine that is rarely accessed 00044 * 00045 * Revision 1.19 2002/01/30 15:40:48 porter 00046 * changed limits on flavor tag & made defaults retrieving more readable 00047 * 00048 * Revision 1.18 2001/12/21 04:54:46 porter 00049 * sped up table definition for emc and changed some ostrstream usage for 00050 * insure tests 00051 * 00052 * Revision 1.17 2001/10/24 04:05:20 porter 00053 * added long long type to I/O and got rid of obsolete dataIndex table 00054 * 00055 * Revision 1.16 2001/02/09 23:06:25 porter 00056 * replaced ostrstream into a buffer with ostrstream creating the 00057 * buffer. The former somehow clashed on Solaris with CC5 iostream (current .dev) 00058 * 00059 * Revision 1.15 2001/01/22 18:38:00 porter 00060 * Update of code needed in next year running. This update has little 00061 * effect on the interface (only 1 method has been changed in the interface). 00062 * Code also preserves backwards compatibility so that old versions of 00063 * StDbLib can read new table structures. 00064 * -Important features: 00065 * a. more efficient low-level table structure (see StDbSql.cc) 00066 * b. more flexible indexing for new systems (see StDbElememtIndex.cc) 00067 * c. environment variable override KEYS for each database 00068 * d. StMessage support & clock-time logging diagnostics 00069 * -Cosmetic features 00070 * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access 00071 * f. removed codes that have been obsolete for awhile (e.g. db factories) 00072 * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI 00073 * and mysqlAccessor became StDbSql) 00074 * 00075 * Revision 1.14 2000/06/30 01:57:02 porter 00076 * fixed a delete bug & small memory leak found by Akio via Insure++ , 00077 * updated SetTable() method for containing idList, corrected enumeration 00078 * map to rhic domain for Conditions_rhic database 00079 * 00080 * Revision 1.13 2000/06/02 13:37:37 porter 00081 * built up list of minor changes: 00082 * - made buffer more robust for certain null inputs 00083 * - fixed small leak in StDbTables & restructure call to createMemory 00084 * - added dbRhic as a database domain in StDbDefs 00085 * - added setUser() in StDbManager 00086 * - added more diagnostic printouts in mysqlAccessor.cc 00087 * 00088 * Revision 1.12 2000/04/25 18:26:03 porter 00089 * added flavor & production time as settable query fields in 00090 * table &/or node. Associated SQL updated in mysqlAccessor. 00091 * Flavor key supports "+" as an OR symbol. 00092 * 00093 * Revision 1.11 2000/02/15 20:27:45 porter 00094 * Some updates to writing to the database(s) via an ensemble (should 00095 * not affect read methods & haven't in my tests. 00096 * - closeAllConnections(node) & closeConnection(table) method to mgr. 00097 * - 'NullEntry' version to write, with setStoreMode in table; 00098 * - updated both StDbTable's & StDbTableDescriptor's copy-constructor 00099 * 00100 * Revision 1.10 2000/01/27 05:54:35 porter 00101 * Updated for compiling on CC5 + HPUX-aCC + KCC (when flags are reset) 00102 * Fixed reConnect()+transaction model mismatch 00103 * added some in-code comments 00104 * 00105 * Revision 1.9 2000/01/19 20:20:07 porter 00106 * - finished transaction model needed by online 00107 * - fixed CC5 compile problem in StDbNodeInfo.cc 00108 * - replace TableIter class by StDbTableIter to prevent name problems 00109 * 00110 * Revision 1.8 2000/01/10 20:37:55 porter 00111 * expanded functionality based on planned additions or feedback from Online work. 00112 * update includes: 00113 * 1. basis for real transaction model with roll-back 00114 * 2. limited SQL access via the manager for run-log & tagDb 00115 * 3. balance obtained between enumerated & string access to databases 00116 * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose 00117 * 5. restructured Node model for better XML support 00118 * 00119 * Revision 1.7 1999/12/03 19:02:01 porter 00120 * modified descriptor to accept tableDescriptor once this St_base object 00121 * has been updated to have longer name lengths. 00122 * 00123 * Revision 1.6 1999/10/19 14:30:39 porter 00124 * modifications relevant to use with StDbBroker and future merging with 00125 * "params" database structure + some docs + suppressing diagnostics messages 00126 * 00127 * Revision 1.5 1999/09/30 02:06:10 porter 00128 * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor) 00129 * allow multiple rows (StDbTable), & Added the comment sections at top of 00130 * each header and src file 00131 * 00132 **************************************************************************/ 00133 #ifndef StDbTable_HH 00134 #define StDbTable_HH 00135 00136 #include "StDbNode.hh" 00137 #include "StDbTime.h" 00138 //#include "typeAcceptor.hh" 00139 #include "StTableDescriptorI.h" 00140 //#include "StDbBufferI.h" 00141 #include "StDbStoreInfo.hh" 00142 #include <string.h> 00143 00144 class StDbBufferI; 00145 class StDbBuffer; 00146 class typeAcceptor; 00147 00148 #ifdef __ROOT__ 00149 #include "TROOT.h" 00150 #endif 00151 00152 class StDbTable : public StDbNode { 00153 00154 protected: 00155 00156 char* mflavor; 00157 bool mdefaultFlavor; 00158 unsigned int mprodTime; 00159 00161 StDbTime mbeginTime; 00162 StDbTime mendTime; 00163 StDbTime mendStoreTime; // for writing null endTimes 00164 00165 // DB storage information 00166 char* mstructName; 00167 char* melementName; 00168 bool mIsBaseLine; 00169 bool mIsBinary; 00170 bool mIsIndexed; 00171 char* mdataTable; 00172 00173 int mschemaID; 00174 int* melementID; 00175 00177 StDbStoreInfo mstoredData; 00178 00180 bool mhasDescriptor; 00181 StTableDescriptorI* mdescriptor; 00182 00184 char* mdata; 00185 int mrows; 00186 int mrowNumber; 00187 bool mhasData; 00188 int mrowsRequested; // for query by where clause 00189 unsigned int* mtimeVals; 00190 00191 virtual void ReadElement(char*& ptr, char* name, int length, StTypeE type, StDbBuffer* buff); 00192 virtual void WriteElement(char* ptr, char* name, int length, StTypeE type, StDbBuffer* buff); 00193 virtual void PassOutElement(char* ptr, char* name, int length, StTypeE type, typeAcceptor* accept); 00194 virtual void PassInElement(char* ptr, char* name, int length, StTypeE type, typeAcceptor* accept); 00195 virtual void getElementSpecs(int elementNum, char*& c, char*& name, unsigned int& length,StTypeE& type); 00196 00197 bool createMemory(); 00198 bool createMemory(int nrows); 00199 char* duplicateData(); 00200 void init(); 00201 void printNoDataReturned(const char* elementName); 00202 00203 00204 public: 00205 00206 StDbTable(const char* tableName); 00207 StDbTable(const char* tableName, int schemaID); 00208 StDbTable(StDbTable& table); 00209 00210 virtual ~StDbTable(){ if(melementID) delete [] melementID; 00211 if(mdescriptor)delete mdescriptor; 00212 if(mdata) delete [] mdata; 00213 if(mdataTable) delete [] mdataTable; 00214 if(mstructName) delete [] mstructName; 00215 if(melementName) delete [] melementName; 00216 if(mtimeVals) delete [] mtimeVals; 00217 if(mflavor) delete [] mflavor; 00218 }; 00219 00220 virtual bool IsTable() const; 00221 virtual void setNodeInfo(StDbNode* node); 00222 virtual unsigned int getTableSize() const; 00223 virtual char* getCstructName(); 00224 virtual char* printCstructName(); 00225 virtual void setCstructName(const char* name); 00226 virtual void setDataTable(const char* name); 00227 virtual char* getDataTable(); 00228 virtual char* printDataTable(); 00229 00230 // flavor is "ofl", "onl", "sim", .... it is an char[16] array. 00231 // 16 char is enough to later have "ofl|onl" type syntax 00232 00233 virtual char* getFlavor(); 00234 virtual char* printFlavor(); 00235 virtual void setFlavor(const char* flavor); 00236 virtual bool defaultFlavor() const; 00237 virtual void setDefaultFlavor(); 00238 00239 virtual unsigned int getProdTime(); 00240 virtual void setProdTime(unsigned int ptime); 00241 00242 virtual unsigned int getEndTime() const ; 00243 virtual char* getEndDateTime(); 00244 virtual void setEndTime(unsigned int time); 00245 virtual void setEndTime(const char* time); 00246 00247 virtual unsigned int getBeginTime() const ; 00248 virtual char* getBeginDateTime(); 00249 virtual void setBeginTime(unsigned int time) ; 00250 virtual void setBeginTime(const char* time); 00251 00252 virtual unsigned int getEndStoreTime() const; 00253 virtual char* getEndStoreDateTime(); 00254 virtual void setEndStoreTime(unsigned int time); 00255 virtual void setEndStoreTime(const char* time); 00256 00257 virtual int* getElementID(int& nrows); 00258 virtual int getRowID(int rowNumber) const ; 00259 virtual char* getElementName(); 00260 virtual char* printElementName(); 00261 virtual void setElementName(const char* ename); 00262 virtual void setElementID(int* elements, int nrows); 00263 00264 virtual void setBaseLine(bool baseLine); 00265 virtual void setIndexed(bool indexed); 00266 virtual void setBinary(bool abinary); 00267 virtual bool IsBaseLine() const; 00268 virtual bool IsIndexed() const; 00269 virtual bool IsBinary() const; 00270 00271 virtual int getSchemaID() const ; 00272 virtual void setSchemaID(int id) ; 00273 00274 // storage of dataIDs 00275 virtual void addWrittenRows(int* dataID,int numRows,bool canRollBack=false); 00276 virtual int* getWrittenRows(int& numRows); 00277 virtual void commitData(); 00278 virtual void clearStoreInfo(); 00279 virtual unsigned int* getTimeValues(); 00280 virtual unsigned int getMaxTime(); 00281 virtual void setTimeValues(unsigned int* timeValues); 00282 00283 // c-struct descriptor & schema 00284 // set by 1st call to db 00285 00286 virtual StTableDescriptorI* getDescriptorCpy() const; 00287 virtual StTableDescriptorI* getDescriptor(); 00288 virtual void setDescriptor(StTableDescriptorI* descriptor); 00289 virtual bool hasDescriptor() const; 00290 void checkDescriptor(); 00291 00292 // access to date via this table or c-struct 00293 00294 virtual StDbTable* Clone(); 00295 virtual char* GetTable(); 00296 virtual void* GetTableCpy(); 00297 virtual void SetTable(char* data, int nrows, int* idList=0); 00298 virtual void AddRows(char* data, int nrows); 00299 // virtual void AddRowsAt(int rowNumber, char* data, int nrows); 00300 virtual int GetNRows() const; 00301 virtual void setRowNumber(int row=0); 00302 virtual bool hasData() const; 00303 virtual void* getDataValue(const char* name,int rowNumber=0); 00304 00305 // memory management for query by where clause 00306 virtual int getRowLimit() const; 00307 virtual void setRowLimit(int nrows); 00308 virtual void addNRows(int newRows); 00309 00311 virtual void addNElements(int* elements, int newRows); 00312 virtual void resizeNumRows(int nrows); 00313 virtual void resizeElementID(int numRows); 00314 00315 // methods for reading & writing to Db & to file 00316 virtual void StreamAccessor(typeAcceptor* accept, bool isReading); 00317 virtual void dbStreamer(typeAcceptor* accept, bool isReading); 00318 virtual void StreamAccessor(StDbBufferI* buff, bool isReading); 00319 virtual void dbStreamer(StDbBufferI* buff, bool isReading); 00320 virtual void dbStreamerWrite(StDbBufferI* buff); 00321 virtual void dbTableStreamer(StDbBufferI* buff, const char* name, bool isReading); 00322 #ifdef __ROOT__ 00323 ClassDef(StDbTable,0) 00324 #endif 00325 }; 00326 00327 inline bool StDbTable::IsTable() const { return true; }; 00328 inline unsigned int StDbTable::getTableSize() const { 00329 if(mhasDescriptor && !mdescriptor->getTrowSize()) return mdescriptor->getTotalSizeInBytes(); 00330 if(mhasDescriptor) return mdescriptor->getTrowSize(); 00331 return 0; 00332 } 00333 inline char* StDbTable::printCstructName() { return mstructName; } 00334 inline char* StDbTable::printDataTable() { return mdataTable; } 00335 inline char* StDbTable::printFlavor() { return mflavor; } 00336 inline bool StDbTable::defaultFlavor() const {return mdefaultFlavor;} 00337 inline void StDbTable::setProdTime(unsigned int ptime) { mprodTime=ptime; } 00338 inline unsigned int StDbTable::getProdTime() { return mprodTime; } 00339 inline unsigned int StDbTable::getEndTime() const {return mendTime.munixTime; } 00340 inline char* StDbTable::getEndDateTime() { return mendTime.mdateTime; } 00341 inline void StDbTable::setEndTime(unsigned int time){ mendTime.munixTime=time;} 00342 inline void StDbTable::setEndTime(const char* time){mendTime.setDateTime(time);} 00343 inline unsigned int StDbTable::getBeginTime() const {return mbeginTime.munixTime; } 00344 inline char* StDbTable::getBeginDateTime() {return mbeginTime.mdateTime; } 00345 inline void StDbTable::setBeginTime(unsigned int time){mbeginTime.munixTime = time; } 00346 inline void StDbTable::setBeginTime(const char* time){ mbeginTime.setDateTime(time); } 00347 inline unsigned int StDbTable::getEndStoreTime() const { return mendStoreTime.munixTime; } 00348 inline char* StDbTable::getEndStoreDateTime() { return mendStoreTime.mdateTime; } 00349 inline void StDbTable::setEndStoreTime(unsigned int time) {mendStoreTime.munixTime = time; } 00350 inline void StDbTable::setEndStoreTime(const char* time){ mendStoreTime.setDateTime(time); } 00351 inline int* StDbTable::getElementID(int& nrows) { nrows = mrows; return melementID; } 00352 00353 inline int StDbTable::getRowID(int rowNumber) const { 00354 if(rowNumber<mrows)return melementID[rowNumber]; 00355 return 0; 00356 } 00357 inline unsigned int* StDbTable::getTimeValues(){ return mtimeVals; } 00358 inline void StDbTable::setTimeValues(unsigned int* timeValues){ 00359 if(mtimeVals) delete [] mtimeVals; 00360 mtimeVals=timeValues; 00361 } 00362 inline unsigned int StDbTable::getMaxTime() { 00363 unsigned int retVal=0; 00364 for(int i=0; i<mrows;i++)if(mtimeVals[i]>retVal)retVal=mtimeVals[i]; 00365 return retVal; 00366 } 00367 inline char* StDbTable::printElementName() { return melementName; } 00368 inline int StDbTable::getSchemaID() const { return mschemaID; } 00369 inline void StDbTable::setSchemaID(int id) {mschemaID = id; } 00370 inline StTableDescriptorI* StDbTable::getDescriptor() { return mdescriptor; } 00371 inline bool StDbTable::hasDescriptor() const { return mhasDescriptor; } 00372 inline StDbTable* StDbTable::Clone() {return (new StDbTable(*this));} 00373 inline int StDbTable::GetNRows() const { return mrows; } 00374 inline void StDbTable::setRowLimit(int nrows) { mrowsRequested=nrows; }; 00375 inline int StDbTable::getRowLimit() const { return mrowsRequested; }; 00376 inline void StDbTable::setRowNumber(int row){if(row < mrows)mrowNumber = row;} 00377 inline bool StDbTable::hasData() const { return mhasData; }; 00378 inline void StDbTable::setBinary(bool abinary) { mIsBinary=abinary; } 00379 inline void StDbTable::setBaseLine(bool baseLine) { mIsBaseLine=baseLine; } 00380 inline void StDbTable::setIndexed(bool indexed) { mIsIndexed=indexed; } 00381 inline bool StDbTable::IsBinary() const { return mIsBinary; } 00382 inline bool StDbTable::IsBaseLine() const { return mIsBaseLine; } 00383 inline bool StDbTable::IsIndexed() const { return mIsIndexed; } 00384 00385 #endif

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