00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <stdlib.h>
00035
00036
00037 #include "StDbLib/StDbManager.hh"
00038 #include "StDbBroker.h"
00039 #include "StDbLib/StDbDefs.hh"
00040 #include "StDbLib/StDbConfigNode.hh"
00041 #include "StDbLib/StDbTable.h"
00042 #include "StDbLib/StDbTableDescriptor.h"
00043 #include "StMessMgr.h"
00044
00045
00046
00047 extern "C" void * DbRead(unsigned int *nRows,
00048 unsigned int *datetime,
00049 const char * tableName,
00050 const char * structName,
00051 unsigned int nVar,
00052 unsigned int sizeOfStruct,
00053 StDbBroker::oldDescriptor *d,
00054 const char* database,
00055 const char* tableVersion)
00056 {
00057
00058
00059 char validFrom[20];
00060 char validTo[20];
00061 char temps[128];
00062 char row[128];
00063 char currentDateTime[20];
00064 char time[7];
00065
00066 sprintf(currentDateTime,"%.8d",datetime[0]);
00067 sprintf(time,"%.6d",datetime[1]);
00068 strcat(currentDateTime,time);
00069
00070 currentDateTime[19]='\0';
00071 currentDateTime[18]=currentDateTime[13];
00072 currentDateTime[17]=currentDateTime[12];
00073 currentDateTime[16]=':';
00074 currentDateTime[15]=currentDateTime[11];
00075 currentDateTime[14]=currentDateTime[10];
00076 currentDateTime[13]=':';
00077 currentDateTime[12]=currentDateTime[9];
00078 currentDateTime[11]=currentDateTime[8];
00079 currentDateTime[10]=' ';
00080 currentDateTime[9]=currentDateTime[7];
00081 currentDateTime[8]=currentDateTime[6];
00082 currentDateTime[7]='-';
00083 currentDateTime[6]=currentDateTime[5];
00084 currentDateTime[5]=currentDateTime[4];
00085 currentDateTime[4]='-';
00086
00087
00088 StDbManager * mgr = StDbManager::Instance();
00089
00090
00091 char dbType[64];
00092 char dbDomain[64];
00093 StDbType type;
00094 StDbDomain domain;
00095 char version[128];
00096
00097 if(!tableVersion)strcpy((char*)version,"default");
00098 if(!database){
00099 strcpy((char*)dbType,"TestScheme");
00100 strcpy((char*)dbDomain,"Star");
00101 type = mgr->getDbType(dbType);
00102 domain = mgr->getDbDomain(dbDomain);
00103 } else {
00104 char* atype;
00105 char* adomain;
00106 if(!mgr->getDataBaseInfo(database, atype, adomain)){
00107 LOG_ERROR << "StDbManager:: Database specified incorrectly" << endm;
00108 *nRows=0;
00109 return NULL;
00110 }
00111
00112 type = mgr->getDbType(atype);
00113 domain = mgr->getDbDomain(adomain);
00114
00115 }
00116
00117
00118 StDbConfigNode* node=mgr->initConfig(type,domain);
00119
00120 StDbTable* mtable=node->addDbTable(tableName,version);
00121
00122
00123 if(!mtable){
00124 *nRows=0;
00125 return NULL;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134 mgr->setRequestTime(currentDateTime);
00135 mgr->fetchDbTable(mtable);
00136
00137
00138 if (mtable->GetTable()==NULL)
00139 {
00140 *nRows=0;
00141 return NULL;
00142 }
00143
00144 *nRows = mtable->GetNRows();
00145
00146
00147
00148
00149 int latestDirDate;
00150 int latestDirTime;
00151 int ic;
00152 int i2, i3;
00153
00154
00155 strcpy(row,mtable->getBeginDateTime());
00156
00157 strncpy(validFrom,row,19);validFrom[19]='\0';
00158
00159 ic=10;
00160 for(i3=0;i3<3;i3++,++ic) {
00161 for(i2=0;i2<2;i2++,++ic) {
00162 temps[ic]=row[ic];
00163 }
00164 }
00165 temps[6]='\0';
00166 latestDirTime = atoi(temps);
00167
00168
00169
00170 strncpy(temps,validFrom,10);
00171 temps[4]=temps[5];
00172 temps[5]=temps[6];
00173 temps[6]=temps[8];
00174 temps[7]=temps[9];
00175 temps[8]='\0';
00176
00177 latestDirDate = atoi(temps);
00178
00179 int nextDirDate;
00180 int nextDirTime;
00181
00182
00183 strcpy(row,mtable->getEndDateTime());
00184 strncpy(validTo,row,19);validTo[19]='\0';
00185
00186 ic=10;
00187 for(i3=0;i3<3;i3++,++ic) {
00188 for(i2=0;i2<2;i2++,++ic) {
00189 temps[ic]=row[ic];
00190 }
00191 }
00192 temps[6]='\0';
00193 nextDirTime = atoi(temps);
00194
00195
00196 strncpy(temps,validTo,10);
00197 temps[4]=temps[5];
00198 temps[5]=temps[6];
00199 temps[6]=temps[8];
00200 temps[7]=temps[9];
00201 temps[8]='\0';
00202
00203 nextDirDate = atoi(temps);
00204
00205 datetime[0] = latestDirDate;
00206 datetime[1] = latestDirTime;
00207 datetime[2] = nextDirDate;
00208 datetime[3] = nextDirTime;
00209
00210 if (datetime[2]==19691231) datetime[2]=20380101;
00211
00212 void* data = mtable->GetTableCpy();
00213 delete node;
00214
00215
00216 return data;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227