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

StDbBuffer.h

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * 00003 * $Id: StDbBuffer.h,v 1.9 2004/01/15 00:02:25 fisyak Exp $ 00004 * 00005 * Author: Laurent Conin 00006 *************************************************************************** 00007 * 00008 * Description: Buffer that negotiates data I/O between mysql database 00009 * 00010 *************************************************************************** 00011 * 00012 * $Log: StDbBuffer.h,v $ 00013 * Revision 1.9 2004/01/15 00:02:25 fisyak 00014 * Replace ostringstream => StString, add option for alpha 00015 * 00016 * Revision 1.8 2003/04/11 22:47:36 porter 00017 * Added a fast multi-row write model specifically needed by the daqEventTag 00018 * writer. Speed increased from about 100Hz to ~3000Hz. It is only invoked if 00019 * the table is marked as Non-Indexed (daqTags & scalers). For non-indexed tables 00020 * which include binary stored data (we don't have any yet), the fast writer has 00021 * to invoke a slower buffer so that the rates are a bit slower (~500Hz at 50 rows/insert). 00022 * 00023 * Revision 1.7 2001/10/26 20:59:46 porter 00024 * fixed new endtime flag from previous checkin. made StDataBaseI available 00025 * at root-cli. 00026 * 00027 * Revision 1.6 2001/10/24 04:05:19 porter 00028 * added long long type to I/O and got rid of obsolete dataIndex table 00029 * 00030 * Revision 1.5 2000/01/27 05:54:33 porter 00031 * Updated for compiling on CC5 + HPUX-aCC + KCC (when flags are reset) 00032 * Fixed reConnect()+transaction model mismatch 00033 * added some in-code comments 00034 * 00035 * Revision 1.4 1999/10/19 14:30:37 porter 00036 * modifications relevant to use with StDbBroker and future merging with 00037 * "params" database structure + some docs + suppressing diagnostics messages 00038 * 00039 * Revision 1.3 1999/09/30 02:06:01 porter 00040 * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor) 00041 * allow multiple rows (StDbTable), & Added the comment sections at top of 00042 * each header and src file 00043 * 00044 **************************************************************************/ 00045 #ifndef STDBBUFFER_H 00046 #define STDBBUFFER_H 00047 #ifndef __CINT__ 00048 #include "mysql.h" 00049 #include "mysql_com.h" 00050 #endif 00051 00052 #include "StDbBufferI.h" 00053 00054 enum myctype{_char,_uchar,_short,_ushort,_int,_uint,_long,_ulong,_longlong,_float,_double,_ascii,_string}; 00055 00056 const int mycsize[]={sizeof(char),sizeof(unsigned char),sizeof(short),sizeof(unsigned short),sizeof(int),sizeof(unsigned int),sizeof(long),sizeof(unsigned long),sizeof(long long),sizeof(float),sizeof(double),sizeof(char*),sizeof(char*)}; 00057 00058 #if defined(__sun) && !defined(__i386) || defined(__hpux) || defined(__alpha) && !defined(linux) 00059 const int mycswapl[]={1,1,1,1,4,4,4,4,8,4,8,1,1}; // same swapping than Solaris 00060 #else 00061 const int mycswapl[]={1,1,1,1,1,1,1,1,1,1,1,1}; 00062 #endif 00063 00064 struct column { 00065 char* name; 00066 enum myctype type; 00067 char *val; 00068 unsigned length; }; 00069 00070 enum BuffMode{Auto,Client,Storage}; 00071 00072 class StDbBuffer : public StDbBufferI { 00073 00074 00075 private: 00076 00077 int mMax; 00078 int mCur; 00079 int mLast; 00080 column *mCol; 00081 BuffMode mMode; 00082 00083 void zeroColumn(int istart, int iend); 00084 00085 public: 00086 00087 StDbBuffer(){ 00088 mCur=0; 00089 mLast=-1; 00090 mMax=100; 00091 mCol= new column[mMax+1]; 00092 zeroColumn(0,mMax); 00093 mMode=Storage; 00094 }; 00095 00096 StDbBuffer(unsigned int anum_fields, column *acol){ 00097 Init( anum_fields,acol);} 00098 00099 void Init(unsigned int anum_fields, column * acol){ 00100 mCur=0; 00101 mLast=anum_fields; 00102 mCol=acol;}; 00103 00104 ~StDbBuffer(){Raz();delete [] mCol; }; 00105 00106 virtual void SetClientMode() {mMode=Client;}; 00107 virtual void SetStorageMode() {mMode=Storage;}; 00108 virtual bool IsClientMode() {return (mMode==Client) ? true : false;}; 00109 virtual bool IsStorageMode() {return (mMode==Storage) ? true : false;}; 00110 00111 void Raz(); 00112 void Print(); 00113 00114 virtual char** WhatsIn(); // debug , not to be use 00115 00116 virtual bool ReadScalar(char &c, const char *aName) ; 00117 virtual bool ReadScalar(unsigned char &c, const char *) ; 00118 virtual bool ReadScalar(short &h, const char *) ; 00119 virtual bool ReadScalar(unsigned short &h, const char *) ; 00120 virtual bool ReadScalar(int &i, const char *) ; 00121 virtual bool ReadScalar(unsigned int &i, const char *) ; 00122 virtual bool ReadScalar(long &l, const char *) ; 00123 virtual bool ReadScalar(unsigned long &l, const char *) ; 00124 virtual bool ReadScalar(long long &l, const char *) ; 00125 virtual bool ReadScalar(float &f, const char *) ; 00126 virtual bool ReadScalar(double &d, const char *) ; 00127 virtual bool ReadScalar(char *&c, const char *) ; 00128 00129 virtual bool WriteScalar(const char c, const char *) ; 00130 virtual bool WriteScalar(const unsigned char c, const char *) ; 00131 virtual bool WriteScalar(const short h, const char *) ; 00132 virtual bool WriteScalar(const unsigned short h, const char *) ; 00133 virtual bool WriteScalar(const int i, const char *) ; 00134 virtual bool WriteScalar(const unsigned int i, const char *) ; 00135 virtual bool WriteScalar(const long l, const char *) ; 00136 virtual bool WriteScalar(const unsigned long l, const char *) ; 00137 virtual bool WriteScalar(const long long l, const char *) ; 00138 virtual bool WriteScalar(const float f, const char *) ; 00139 virtual bool WriteScalar(const double d, const char *) ; 00140 virtual bool WriteScalar(const char *c, const char *); 00141 00142 virtual bool ReadArray(char *&c, int &len, const char *); 00143 virtual bool ReadArray(unsigned char *&c, int &len, const char *); 00144 virtual bool ReadArray( short *&c, int &len, const char *); 00145 virtual bool ReadArray( unsigned short *&c, int &len, const char *); 00146 virtual bool ReadArray(int *&c, int &len, const char *); 00147 virtual bool ReadArray(unsigned int *&c, int &len, const char *); 00148 virtual bool ReadArray(long *&c, int &len, const char *); 00149 virtual bool ReadArray(unsigned long *&c, int &len, const char *); 00150 virtual bool ReadArray(long long *&c, int &len, const char *); 00151 virtual bool ReadArray(float *&c, int &len, const char *); 00152 virtual bool ReadArray(double *&c, int &len, const char *); 00153 virtual bool ReadArray(char **&c, int &len, const char *); 00154 00155 virtual bool WriteArray(char *c, int len, const char *); 00156 virtual bool WriteArray(unsigned char *c, int len, const char *); 00157 virtual bool WriteArray(short *c, int len, const char *); 00158 virtual bool WriteArray(unsigned short *c, int len, const char *); 00159 virtual bool WriteArray(int *c, int len, const char *); 00160 virtual bool WriteArray(unsigned int *c, int len, const char *); 00161 virtual bool WriteArray(long *c, int len, const char *); 00162 virtual bool WriteArray(unsigned long *c, int len, const char *); 00163 virtual bool WriteArray(long long *c, int len, const char *); 00164 virtual bool WriteArray(float *c, int len, const char *); 00165 virtual bool WriteArray(double *c, int len, const char *); 00166 virtual bool WriteArray(char **c, int len, const char *); 00167 00168 00169 00170 protected: 00171 //char* Raw_result (const char *aName); 00172 00173 bool Find_Col (const char *aName); 00174 void AddField(const char *aName, const myctype aTpe,const void* aVal,const int aLen); 00175 void ChangeField(const myctype aTpe,const void* aVal,const int aLen); 00176 00177 //bool WriteMem(char &s,void* aVal, myctype type); 00178 00179 bool WriteMem(char *s,void* aVal, myctype type); 00180 bool WriteMem(unsigned char *s,void* aVal, myctype type); 00181 bool WriteMem(short *s,void* aVal, myctype type); 00182 bool WriteMem(unsigned short *s,void* aVal, myctype type); 00183 bool WriteMem(int *s,void* aVal, myctype type); 00184 bool WriteMem(unsigned int *s,void* aVal, myctype type); 00185 bool WriteMem(long *s,void* aVal, myctype type); 00186 bool WriteMem(unsigned long *s,void* aVal, myctype type); 00187 bool WriteMem(long long *s,void* aVal, myctype type); 00188 bool WriteMem(float *s,void* aVal, myctype type); 00189 bool WriteMem(double *s,void* aVal, myctype type); 00190 bool WriteMem(char **s,void* aVal, myctype type); 00191 00192 void StrConv(char* aVal,char &s); 00193 void StrConv(char* aVal,unsigned char &s); 00194 void StrConv(char* aVal,short &s); 00195 void StrConv(char* aVal,unsigned short &s); 00196 void StrConv(char* aVal,int &s); 00197 void StrConv(char* aVal,unsigned int &s); 00198 void StrConv(char* aVal,long &s); 00199 void StrConv(char* aVal,unsigned long &s); 00200 void StrConv(char* aVal,long long &s); 00201 void StrConv(char* aVal,float &s); 00202 void StrConv(char* aVal,double &s); 00203 void StrConv(char* aVal,char* &s); 00204 00205 void MemSwapCpy(char* where,char* from,int len,int swaplen,BuffMode mode); 00206 00207 //ClassDef(StDbBuffer,0) 00208 00209 00210 }; 00211 00212 00213 00214 #endif 00215 00216 00217 00218 00219 00220

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