StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbTableDescriptor.h
1 /***************************************************************************
2  *
3  * $Id: StDbTableDescriptor.h,v 1.13 2016/05/25 20:17:51 dmitry Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Class implement table-descriptor (memory/name of data-elements)
9  * this descriptor is loaded from database
10  *
11  ***************************************************************************
12  *
13  * $Log: StDbTableDescriptor.h,v $
14  * Revision 1.13 2016/05/25 20:17:51 dmitry
15  * coverity - uninit ctor
16  *
17  * Revision 1.12 2009/09/28 19:14:10 dmitry
18  * row size is not *static* anymore, tables have different row sizes
19  *
20  * Revision 1.11 2009/09/10 18:06:08 dmitry
21  * struct alignment fix, does not rely on fixed 4 byte cap anymore - runtime align calculation is now in use
22  *
23  * Revision 1.10 2007/09/03 05:39:03 fisyak
24  * Anti Cint corrections
25  *
26  * Revision 1.9 2005/09/07 22:04:02 deph
27  * update to correct padding issue for packed tables
28  *
29  * Revision 1.8 2001/12/05 17:16:35 porter
30  * stand-alone make file no longer had "DLINUX" in compile but this is still needed
31  * and returned. Also retrieve elementID list in query by whereClause for plotting
32  * many row instances.
33  *
34  * Revision 1.7 2001/01/22 18:38:00 porter
35  * Update of code needed in next year running. This update has little
36  * effect on the interface (only 1 method has been changed in the interface).
37  * Code also preserves backwards compatibility so that old versions of
38  * StDbLib can read new table structures.
39  * -Important features:
40  * a. more efficient low-level table structure (see StDbSql.cc)
41  * b. more flexible indexing for new systems (see StDbElememtIndex.cc)
42  * c. environment variable override KEYS for each database
43  * d. StMessage support & clock-time logging diagnostics
44  * -Cosmetic features
45  * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access
46  * f. removed codes that have been obsolete for awhile (e.g. db factories)
47  * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI
48  * and mysqlAccessor became StDbSql)
49  *
50  * Revision 1.6 2000/03/28 17:03:19 porter
51  * Several upgrades:
52  * 1. configuration by timestamp for Conditions
53  * 2. query by whereClause made more systematic
54  * 3. conflict between db-stored comments & number lists resolved
55  * 4. ensure endtime is correct for certain query falures
56  * 5. dbstl.h->handles ObjectSpace & RogueWave difference (Online vs Offline)
57  *
58  * Revision 1.5 1999/12/03 19:02:02 porter
59  * modified descriptor to accept tableDescriptor once this St_base object
60  * has been updated to have longer name lengths.
61  *
62  * Revision 1.4 1999/10/19 14:30:40 porter
63  * modifications relevant to use with StDbBroker and future merging with
64  * "params" database structure + some docs + suppressing diagnostics messages
65  *
66  * Revision 1.3 1999/09/30 02:06:10 porter
67  * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor)
68  * allow multiple rows (StDbTable), & Added the comment sections at top of
69  * each header and src file
70  *
71  **************************************************************************/
72 #ifndef STDBTABLEDESCRIPTOR_HH
73 #define STDBTABLEDESCRIPTOR_HH
74 
75 #include <string.h>
76 #include "StTableDescriptorI.h"
77 #ifndef __CINT__
78 #include "StDbBuffer.h"
79 #else
80 class StDbBuffer;
81 #endif
83  StTypeE type = Stchar; // enumerated basic type
84  char name[60]; // element name
85  unsigned int size = 0; // element size in bytes
86  unsigned int offset = 0; // byte offset in table to this element
87  unsigned int dimensionlen[4]; // len per dimension if multi-D array
88 };
89 
90 
92 
93 protected:
94 
95  unsigned int mnumElements = 0;
96  unsigned int mtableSize = 0;
97  int offsetToNextEmptyByte = 0;
98  int offsetToLast4Bytes = 0;
99  StTypeE lastType = Stchar;
100  int padsize = 0;
101 
102  unsigned int mAlign[Stmaxtype];
103 
104  tableDescriptor* mcols = 0;
105  int mMax = 0;
106  int mCur = 0;
107 
108  // db unique ids
109  int mstructID = 0;
110  int mschemaID = 0;
111  int rowSizeTT = 0;
112  bool misValid = false; // schema has been filled
113  bool mhasDouble = false;
114  unsigned int maxAlign = 0;
115 
116  void init();
117  virtual void reSize();
118  virtual void fillSizeAndOffset(char* length, int elementNum);
119  virtual void fillLengths(char* length, int elementNum);
120  virtual StTypeE getType(char* type);
121  virtual unsigned int getSize(StTypeE type);
122  virtual unsigned int getAlign(StTypeE type);
123 
124 public:
125 
127  StDbTableDescriptor(int structID, int schemaID);
129  virtual ~StDbTableDescriptor() {if(mcols) delete [] mcols; }
130  virtual void fillElement(StDbBuffer* buff, int tableID);
131 
132  virtual StTableDescriptorI* getCpy();
133  virtual tableDescriptor* getTableDescriptor() const;
134  virtual unsigned int getNumElements() const;
135  virtual unsigned int getTotalSizeInBytes() const;
136  virtual char* getElementName(int elementNum) const;
137  virtual unsigned int getElementOffset(int elementNum) const;
138  virtual unsigned int getElementSize(int elementNum) const;
139  virtual StTypeE getElementType(int elementNum) const;
140  virtual unsigned int* getElementDimensions(int elementNum) const;
141  virtual unsigned int getElementLength(int elementNum) const;
142  virtual unsigned int getElementNumDimensions(int elementNum) const;
143  virtual unsigned int getElementIndexLength(int elementNum, int dimensionNum) const;
144 
145 
146  int getSchemaID() const;
147  int getStructID() const;
148  void setSchemaID(int id);
149  void setStructID(int id);
150  bool IsValid() const;
151  int getCurrentInternalSize();
152  int getTrowSize() ;
153  void endRowPadding();
154  void storeRowSize(int rowSize);
155  unsigned int getMaxAlign();
156 
157 };
158 #ifndef __CINT__
159 inline unsigned int
160 StDbTableDescriptor::getNumElements() const {return mnumElements;}
161 
162 inline unsigned int
163 StDbTableDescriptor::getTotalSizeInBytes() const {return mtableSize;}
164 
165 inline char*
166 StDbTableDescriptor::getElementName(int elementNum) const {
167 char* retVal = new char[strlen(mcols[elementNum].name)+1];
168 strcpy(retVal,mcols[elementNum].name);
169 return retVal;
170 }
171 
172 inline unsigned int
173 StDbTableDescriptor::getElementOffset(int elementNum) const {
174 return mcols[elementNum].offset;
175 }
176 
177 inline unsigned int StDbTableDescriptor::getElementSize(int elementNum) const{
178 return mcols[elementNum].size;
179 }
180 
181 inline StTypeE StDbTableDescriptor::getElementType(int elementNum) const {
182 return mcols[elementNum].type;
183 }
184 
185 inline unsigned int*
186 StDbTableDescriptor::getElementDimensions(int elementNum) const {
187 return &mcols[elementNum].dimensionlen[0];
188 }
189 
191 
192 inline unsigned int
193 StDbTableDescriptor::getElementLength(int elementNum) const {
194 
195 int retVal=1;
196 int j;
197  int k= (int)(sizeof(mcols[elementNum].dimensionlen)/sizeof(j));
198  for(j=0;j<k;j++)retVal *= mcols[elementNum].dimensionlen[j];
199 return retVal;
200 }
201 
203 
204 inline unsigned int
205 StDbTableDescriptor::getElementNumDimensions(int elementNum) const {
206 int retVal=1;
207 int j;
208  int k= (int)(sizeof(mcols[elementNum].dimensionlen)/sizeof(j));
209  for(j=0;j<k;j++){
210  if(mcols[elementNum].dimensionlen[j]>1)retVal=j+1; // last dimension >1
211  }
212 return retVal;
213 }
214 
215 inline unsigned int
216 StDbTableDescriptor::getElementIndexLength(int elementNum, int dimensionNum) const {
217 return mcols[elementNum].dimensionlen[dimensionNum];
218 }
219 
220 inline unsigned int StDbTableDescriptor::getSize(StTypeE type){ return mycsize[type];}
221 inline unsigned int StDbTableDescriptor::getAlign(StTypeE type){ return mAlign[type];}
222 inline int StDbTableDescriptor::getSchemaID() const { return mschemaID; }
223 inline int StDbTableDescriptor::getStructID() const { return mstructID; }
224 inline void StDbTableDescriptor::setSchemaID(int id) { mschemaID=id; }
225 inline void StDbTableDescriptor::setStructID(int id) { mstructID=id; }
226 inline bool StDbTableDescriptor::IsValid() const { return misValid; }
227 inline int StDbTableDescriptor::getCurrentInternalSize() { return mMax; };
228 inline void StDbTableDescriptor::storeRowSize(int rowSize) { rowSizeTT = rowSize; }
229 inline int StDbTableDescriptor::getTrowSize() { return rowSizeTT; };
230 inline unsigned int StDbTableDescriptor::getMaxAlign() { return maxAlign; };
231 #endif
232 
233 #endif
234 
235 
236 
237 
238 
239