StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbStoreInfo.cc
1 /***************************************************************************
2  *
3  * $Id: StDbStoreInfo.cc,v 1.1 2001/01/22 18:38:00 porter Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Simple integer array implementation of the database
9  * dataID fields. These are held during writes so that a
10  * many-row table or a multi-table write can be rolled back
11  * completely on failure at some point in the writing
12  *
13  ***************************************************************************
14  *
15  * $Log: StDbStoreInfo.cc,v $
16  * Revision 1.1 2001/01/22 18:38:00 porter
17  * Update of code needed in next year running. This update has little
18  * effect on the interface (only 1 method has been changed in the interface).
19  * Code also preserves backwards compatibility so that old versions of
20  * StDbLib can read new table structures.
21  * -Important features:
22  * a. more efficient low-level table structure (see StDbSql.cc)
23  * b. more flexible indexing for new systems (see StDbElememtIndex.cc)
24  * c. environment variable override KEYS for each database
25  * d. StMessage support & clock-time logging diagnostics
26  * -Cosmetic features
27  * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access
28  * f. removed codes that have been obsolete for awhile (e.g. db factories)
29  * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI
30  * and mysqlAccessor became StDbSql)
31  *
32  **************************************************************************/
33 #include "StDbStoreInfo.hh"
34 #include <string.h>
35 
36 #define N_ROWS_INCREMENT 500
37 
38 StDbStoreInfo::StDbStoreInfo() : mdataIDs(0), mnumRows(0), mMaxRows(0), mcanRollBack(false) {};
39 
40 StDbStoreInfo::~StDbStoreInfo() { resetStoreInfo(); }
41 
43 
44 void StDbStoreInfo::reSizeInternalStore(){
45 
46  int newMaxRows = mMaxRows+N_ROWS_INCREMENT;
47  int* newDataIDs = new int[newMaxRows];
48 
49  memset(newDataIDs,0,newMaxRows*sizeof(int));
50  if(mdataIDs){
51  memcpy(newDataIDs,mdataIDs,mnumRows*sizeof(int));
52  delete [] mdataIDs;
53  }
54  mdataIDs = newDataIDs;
55  mMaxRows = newMaxRows;
56 
57 }
58 
60 
61 int* StDbStoreInfo::getDataIDs(int& numRows){
62  numRows=mnumRows;
63  return mdataIDs;
64 }
65 
67 
68 void StDbStoreInfo::addWrittenRow(int dataID){
69 
70  if(mnumRows==mMaxRows)reSizeInternalStore();
71  mdataIDs[mnumRows]=dataID;
72  mnumRows++;
73 
74 };
75 
76 
77 void StDbStoreInfo::resetStoreInfo(){
78  if(mdataIDs) delete [] mdataIDs;
79  mdataIDs=0;
80  mnumRows=0;
81  mMaxRows=0;
82  mcanRollBack=false;
83 }
84