AraEvent/AraStationInfo.cxx
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 //Includes 00011 #include <iostream> 00012 #include <sqlite3.h> 00013 00014 //Ara Includes 00015 #include "AraStationInfo.h" 00016 #include "AraGeomTool.h" 00017 00018 00019 00020 00021 00022 ClassImp(AraStationInfo); 00023 00024 AraStationInfo::AraStationInfo() 00025 :fAntInfo(ANTS_PER_ATRI),fCalAntInfo(4) 00026 { 00027 numberRFChans=0; 00028 fNumberAntennas=0; 00029 fNumberCalAntennas=0; 00030 00031 } 00032 00033 00034 AraStationInfo::AraStationInfo(AraStationId_t stationId) 00035 :fAntInfo(ANTS_PER_ATRI),fCalAntInfo(4) 00036 { 00037 fStationId=stationId; 00038 numberRFChans=0; 00039 fNumberAntennas=0; 00040 fNumberCalAntennas=0; 00041 if(AraGeomTool::isIcrrStation(fStationId)) { 00042 readChannelMapDbIcrr(); 00043 } 00044 else { 00045 //readChannelMapDbAtri_2(); 00046 readChannelMapDbAtri(); 00047 } 00048 readCalPulserDb(); 00049 00050 } 00051 00052 00053 00054 AraStationInfo::~AraStationInfo() 00055 { 00056 00057 } 00058 00059 Double_t AraStationInfo::getCableDelay(int rfChanNum) { 00060 if(rfChanNum>=0 && rfChanNum<numberRFChans) { 00061 return fAntInfo[rfChanNum].getCableDelay(); 00062 } 00063 return 0; 00064 } 00065 00066 AraCalAntennaInfo *AraStationInfo::getCalAntennaInfo(int calAntId) { 00067 if(calAntId>=0 && calAntId<=fNumberCalAntennas) 00068 return &fCalAntInfo[calAntId]; 00069 return NULL; 00070 } 00071 00072 00073 AraAntennaInfo *AraStationInfo::getAntennaInfo(int antNum) { 00074 if(antNum>=0 && antNum<numberRFChans) { 00075 return &fAntInfo[antNum]; 00076 } 00077 return NULL; 00078 } 00079 00080 AraAntennaInfo *AraStationInfo::getNewAntennaInfo(int antNum){ 00081 //Assume this creates a new AraAntennaInfo; 00082 fNumberAntennas++; 00083 numberRFChans++; 00084 // std::cout << "getNewAntennaInfo(" << antNum << ") fNumberAntennas=" << fNumberAntennas << "\n"; 00085 //Magic lines below, may remove at some point 00086 int temp=fAntInfo[antNum].chanNum; 00087 fAntInfo[antNum].chanNum=temp; 00088 fAntInfo[antNum].fStationId=fStationId; 00089 return &fAntInfo[antNum]; 00090 } 00091 00092 00093 AraCalAntennaInfo *AraStationInfo::getNewCalAntennaInfo(int calAntId){ 00094 //Assume this creates a new AraCalAntennaInfo; 00095 fNumberCalAntennas++; 00096 // std::cout << "getNewCalAntennaInfo(" << calAntId << ") fNumberCalAntennas=" << fNumberCalAntennas << "\n"; 00097 //Magic lines below, may remove at some point 00098 // int temp=fCalAntInfo[calAntId].calAntId; 00099 fCalAntInfo[calAntId].calAntId=calAntId; 00100 fCalAntInfo[calAntId].fStationId=fStationId; 00101 return &fCalAntInfo[calAntId]; 00102 } 00103 00104 void AraStationInfo::fillAntIndexVec() { 00105 //For now will use hard coded numbers 00106 fAntIndexVec[0].resize(20); 00107 fAntIndexVec[1].resize(20); 00108 fAntIndexVec[2].resize(20); 00109 00110 Int_t countPols[3]={0}; 00111 for(int ant=0;ant<fNumberAntennas;++ant){ 00112 int polTypeInt=(int)fAntInfo[ant].polType; 00113 int antNum=fAntInfo[ant].antPolNum; 00114 int daqNum=fAntInfo[ant].daqChanNum; 00115 // std::cerr << ant << "\t" << polTypeInt << "\t" << antNum << "\t" << daqNum << "\n"; 00116 fAntIndexVec[polTypeInt][antNum]=ant;//daqNum; 00117 countPols[polTypeInt]++; 00118 } 00119 for(int pol=0;pol<3;pol++) { 00120 fAntIndexVec[pol].resize(countPols[pol]); 00121 } 00122 } 00123 00124 Int_t AraStationInfo::getRFChanByPolAndAnt(Int_t antNum, AraAntPol::AraAntPol_t polType) { 00125 //RJN will add checking here at some point 00126 if(polType>=0 && polType<=2) { 00127 if(antNum>=0 && antNum<=fAntIndexVec[polType].size()) { 00128 return fAntIndexVec[polType][antNum]; 00129 } 00130 } 00131 return -1; 00132 } 00133 00134 00135 Int_t AraStationInfo::getElecChanFromRFChan(Int_t rfChan) { 00136 //Should add error checking here 00137 if(rfChan >=fAntInfo.size()){ 00138 fprintf(stderr, "%s : rfChan %i too high\n", __FUNCTION__, rfChan); 00139 return -1; 00140 } 00141 00142 return fAntInfo[rfChan].daqChanNum; 00143 } 00144 00145 00146 00147 00148 void AraStationInfo::readChannelMapDbAtri(){ 00149 sqlite3 *db; 00150 char *zErrMsg = 0; 00151 sqlite3_stmt *stmt; 00152 // int calibIndex=getStationCalibIndex(fStationId); 00153 00154 char calibDir[FILENAME_MAX]; 00155 char fileName[FILENAME_MAX]; 00156 char *calibEnv=getenv("ARA_CALIB_DIR"); 00157 if(!calibEnv) { 00158 char *utilEnv=getenv("ARA_UTIL_INSTALL_DIR"); 00159 if(!utilEnv) 00160 sprintf(calibDir,"calib"); 00161 else 00162 sprintf(calibDir,"%s/share/araCalib",utilEnv); 00163 } 00164 else { 00165 strncpy(calibDir,calibEnv,FILENAME_MAX); 00166 } 00167 sprintf(fileName, "%s/AntennaInfo.sqlite", calibDir); 00168 00169 //open the database 00170 // int rc = sqlite3_open_v2(fileName, &db, SQLITE_OPEN_READONLY, NULL); 00171 int rc = sqlite3_open(fileName, &db);; 00172 if(rc!=SQLITE_OK){ 00173 printf("AraStationInfo::readChannelMapDbAtri() - Can't open database: %s\n", sqlite3_errmsg(db)); 00174 sqlite3_close(db); 00175 return; 00176 } 00177 00178 const char *query; 00179 00180 //This is where we decide which table to access in the database 00181 if(fStationId==ARA_STATION1B) query = "select * from ARA01"; 00182 else if(fStationId==ARA_STATION2) query = "select * from ARA02"; 00183 else if(fStationId==ARA_STATION3) query = "select * from ARA03"; 00184 else{ 00185 fprintf(stderr, "%s : fStationId %i is not ARA1-3\n", __FUNCTION__, fStationId); 00186 return; 00187 } 00188 00189 //prepare an sql statment which will be used to obtain information from the data base 00190 rc=sqlite3_prepare(db, query, strlen(query)+1, &stmt, NULL); 00191 00192 if(rc!=SQLITE_OK){ 00193 printf("AraStationInfo::readChannelMapDbAtri() : statement not prepared OK\n"); 00194 //should close the data base and exit the function 00195 sqlite3_close(db); 00196 return; 00197 } 00198 00199 00200 int row=0; 00201 while(1){ 00202 //printf("row number %i\n", row); 00203 rc=sqlite3_step(stmt); 00204 if(rc==SQLITE_DONE) break; 00205 int nColumns=sqlite3_column_count(stmt); 00206 00207 row=sqlite3_column_int(stmt, 2)-1;//forcing the row to be correct 00208 //printf("row number %i\n", row); 00209 AraAntennaInfo *thisAntInfo=this->getNewAntennaInfo(row); 00210 00211 for(int column=0;column<nColumns;column++){ 00212 00213 const char* temp; 00214 00215 switch(column){ 00216 case 0: //primary key - fStationId+labChip+channel 00217 00218 break; 00219 case 1: //antDir 00220 00221 temp = (const char*)sqlite3_column_text(stmt, column); 00222 00223 if(strcmp (temp,"kReceiver")==0){ 00224 thisAntInfo->antDir=AraAntDir::kReceiver; 00225 //printf("fStationInfoATRI[%i].fAntInfo[%i].antDir %i\n", fStationId, row, thisAntInfo->antDir); 00226 } 00227 00228 break; 00229 case 2: //chanNum 00230 00231 thisAntInfo->chanNum=sqlite3_column_int(stmt, column); 00232 00233 00234 //printf("fStationInfoATRI[%i].fAntInfo[%i].chanNum %i\n", fStationId, row, thisAntInfo->chanNum); 00235 00236 break; 00237 case 3: //daqChanType 00238 00239 temp = (const char*)sqlite3_column_text(stmt, column); 00240 if(strcmp (temp,"kDisconeChan")==0) thisAntInfo->daqChanType=AraDaqChanType::kDisconeChan; 00241 if(strcmp (temp,"kBatwingChan")==0) thisAntInfo->daqChanType=AraDaqChanType::kBatwingChan; 00242 00243 //printf("fStationInfoATRI[%i].fAntInfo[%i].daqChanType %i\n", fStationId, row, thisAntInfo->daqChanType); 00244 00245 break; 00246 case 4: //daqChanNum 00247 00248 thisAntInfo->daqChanNum=sqlite3_column_int(stmt, column); 00249 //printf("fStationInfoATRI[%i].fAntInfo[%i].daqChanNum %i\n", fStationId, row, thisAntInfo->daqChanNum); 00250 00251 break; 00252 case 5: //highPassFilterMhz 00253 00254 thisAntInfo->highPassFilterMhz=sqlite3_column_double(stmt, column); 00255 //printf("fStationInfoATRI[%i].fAntInfo[%i].highPassFilterMhz %f\n", fStationId, row, thisAntInfo->highPassFilterMhz); 00256 00257 break; 00258 case 6: //lowPassFilterMhz 00259 thisAntInfo->lowPassFilterMhz=sqlite3_column_double(stmt, column); 00260 //printf("fStationInfoATRI[%i].fAntInfo[%i].lowPassFilterMhz %f\n", fStationId, row, thisAntInfo->lowPassFilterMhz); 00261 00262 break; 00263 case 7: //daqTrigChan 00264 thisAntInfo->daqTrigChan=sqlite3_column_int(stmt, column); 00265 //printf("fStationInfoATRI[%i].fAntInfo[%i].daqTrigChan %i\n", fStationId, row, thisAntInfo->daqTrigChan); 00266 00267 break; 00268 case 8: //numLabChans 00269 00270 thisAntInfo->numLabChans=sqlite3_column_int(stmt, column); 00271 //printf("fStationInfoATRI[%i].fAntInfo[%i].numLabChans %i\n", fStationId, row, thisAntInfo->numLabChans); 00272 00273 break; 00274 case 9: //labChip 00275 00276 temp = (const char*)sqlite3_column_text(stmt, column); 00277 if(strcmp (temp,"kA")==0) thisAntInfo->labChip=AraLabChip::kA; 00278 if(strcmp (temp,"kB")==0) thisAntInfo->labChip=AraLabChip::kB; 00279 if(strcmp (temp,"kC")==0) thisAntInfo->labChip=AraLabChip::kC; 00280 00281 //printf("fStationInfoATRI[%i].fAntInfo[%i].labChip %i\n", fStationId, row, thisAntInfo->labChip); 00282 00283 break; 00284 case 10: //labChans[0] 00285 00286 thisAntInfo->labChans[0]=sqlite3_column_int(stmt, column)-1; 00287 //printf("fStationInfoATRI[%i].fAntInfo[%i].labChans[0] %i\n", fStationId, row, thisAntInfo->labChans[0]); 00288 00289 break; 00290 case 11: //labChans[1] 00291 00292 thisAntInfo->labChans[1]=sqlite3_column_int(stmt, column)-1; 00293 //printf("fStationInfoATRI[%i].fAntInfo[%i].labChans[1] %i\n", fStationId, row, thisAntInfo->labChans[1]); 00294 00295 break; 00296 case 12: //isDiplexed 00297 00298 thisAntInfo->isDiplexed=sqlite3_column_int(stmt, column); 00299 //printf("fStationInfoATRI[%i].fAntInfo[%i].isDiplexed %i\n", fStationId, row, thisAntInfo->isDiplexed); 00300 00301 break; 00302 case 13: //diplexedChans[0] 00303 00304 thisAntInfo->diplexedChans[0]=sqlite3_column_int(stmt, column); 00305 //printf("fStationInfoATRI[%i].fAntInfo[%i].diplexedChans[0] %i\n", fStationId, row, thisAntInfo->diplexedChans[0]); 00306 00307 break; 00308 case 14: //diplexedChans[1] 00309 00310 thisAntInfo->diplexedChans[1]=sqlite3_column_int(stmt, column); 00311 //printf("fStationInfoATRI[%i].fAntInfo[%i].diplexedChans[1] %i\n", fStationId, row, thisAntInfo->diplexedChans[1]); 00312 00313 break; 00314 case 15: //preAmpNum 00315 00316 thisAntInfo->preAmpNum=sqlite3_column_int(stmt, column); 00317 //printf("fStationInfoATRI[%i].fAntInfo[%i].preAmpNum %i\n", fStationId, row, thisAntInfo->preAmpNum); 00318 00319 break; 00320 case 16: //avgNoiseFigure 00321 00322 thisAntInfo->avgNoiseFigure=sqlite3_column_double(stmt, column); 00323 //printf("fStationInfoATRI[%i].fAntInfo[%i].avgNoiseFigure %f\n", fStationId, row, thisAntInfo->avgNoiseFigure); 00324 00325 break; 00326 case 17: //rcvrNum 00327 00328 thisAntInfo->rcvrNum=sqlite3_column_int(stmt, column); 00329 //printf("fStationInfoATRI[%i].fAntInfo[%i].rcvrNum %i\n", fStationId, row, thisAntInfo->rcvrNum); 00330 00331 break; 00332 case 18: //designator 00333 00334 temp = (const char*)sqlite3_column_text(stmt, column); 00335 strncpy(thisAntInfo->designator, temp, 3); 00336 //printf("fStationInfoATRI[%i].fAntInfo[%i].designator %s\n", fStationId, row, thisAntInfo->designator); 00337 00338 break; 00339 case 19: //antPolNum 00340 00341 thisAntInfo->antPolNum=sqlite3_column_int(stmt, column); 00342 //printf("fStationInfoATRI[%i].fAntInfo[%i].antPolNum %i\n", fStationId, row, thisAntInfo->antPolNum); 00343 00344 break; 00345 case 20: //antType 00346 00347 temp = (const char*)sqlite3_column_text(stmt, column); 00348 if(strcmp (temp,"kBicone")==0) thisAntInfo->antType=AraAntType::kBicone; 00349 if(strcmp (temp,"kBowtieSlot")==0) thisAntInfo->antType=AraAntType::kBowtieSlot; 00350 if(strcmp (temp,"kDiscone")==0) thisAntInfo->antType=AraAntType::kDiscone; 00351 if(strcmp (temp,"kBatwing")==0) thisAntInfo->antType=AraAntType::kBatwing; 00352 if(strcmp (temp,"kFatDipole")==0) thisAntInfo->antType=AraAntType::kFatDipole; 00353 if(strcmp (temp,"kQuadSlot")==0) thisAntInfo->antType=AraAntType::kQuadSlot; 00354 00355 //printf("fStationInfoATRI[%i].fAntInfo[%i].antType %i\n", fStationId, row, thisAntInfo->antType); 00356 00357 break; 00358 case 21: //polType 00359 00360 temp = (const char*)sqlite3_column_text(stmt, column); 00361 if(strcmp (temp,"kVertical")==0) thisAntInfo->polType=AraAntPol::kVertical; 00362 if(strcmp (temp,"kHorizontal")==0) thisAntInfo->polType=AraAntPol::kHorizontal; 00363 if(strcmp (temp,"kSurface")==0) thisAntInfo->polType=AraAntPol::kSurface; 00364 00365 //printf("fStationInfoATRI[%i].fAntInfo[%i].AraAntPol %i\n", fStationId, row, thisAntInfo->polType); 00366 00367 break; 00368 case 22: //locationName 00369 00370 temp = (const char*)sqlite3_column_text(stmt, column); 00371 strncpy(thisAntInfo->locationName, temp, 4); 00372 //printf("fStationInfoATRI[%i].fAntInfo[%i].locationName %s\n", fStationId, row, thisAntInfo->locationName); 00373 00374 00375 break; 00376 case 23: //antLocation[0] 00377 00378 thisAntInfo->antLocation[0]=sqlite3_column_double(stmt, column); 00379 //printf("fStationInfoATRI[%i].fAntInfo[%i].antLocation[0] %f\n", fStationId, row, thisAntInfo->antLocation[0]); 00380 00381 break; 00382 case 24: //antLocation[1] 00383 00384 thisAntInfo->antLocation[1]=sqlite3_column_double(stmt, column); 00385 //printf("fStationInfoATRI[%i].fAntInfo[%i].antLocation[1] %f\n", fStationId, row, thisAntInfo->antLocation[1]); 00386 00387 break; 00388 case 25: //antLocation[2] 00389 00390 thisAntInfo->antLocation[2]=sqlite3_column_double(stmt, column); 00391 //printf("fStationInfoATRI[%i].fAntInfo[%i].antLocation[2] %f\n", fStationId, row, thisAntInfo->antLocation[2]); 00392 00393 break; 00394 case 26: //cableDelay 00395 00396 thisAntInfo->cableDelay=sqlite3_column_double(stmt, column); 00397 //printf("fStationInfoATRI[%i].fAntInfo[%i].cableDelay %f\n", fStationId, row, thisAntInfo->cableDelay); 00398 00399 break; 00400 case 27: //debugHolePosition[0] 00401 00402 thisAntInfo->debugHolePosition[0]=sqlite3_column_double(stmt, column); 00403 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugHolePosition[0] %f\n", fStationId, row, thisAntInfo->debugHolePosition[0]); 00404 00405 break; 00406 case 28: //debugHolePosition[1] 00407 00408 thisAntInfo->debugHolePosition[1]=sqlite3_column_double(stmt, column); 00409 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugHolePosition[1] %f\n", fStationId, row, thisAntInfo->debugHolePosition[1]); 00410 00411 break; 00412 case 29: //debugHolePosition[2] 00413 00414 thisAntInfo->debugHolePosition[2]=sqlite3_column_double(stmt, column); 00415 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugHolePosition[2] %f\n", fStationId, row, thisAntInfo->debugHolePosition[2]); 00416 00417 break; 00418 case 30: //debugPreAmpDz 00419 00420 thisAntInfo->debugPreAmpDz=sqlite3_column_double(stmt, column); 00421 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugPreAmpDz %f\n", fStationId, row, thisAntInfo->debugPreAmpDz); 00422 00423 break; 00424 case 31: //debugHolePositionZft 00425 00426 thisAntInfo->debugHolePositionZft=sqlite3_column_double(stmt, column); 00427 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugHolePositionZft %f\n", fStationId, row, thisAntInfo->debugHolePositionZft); 00428 00429 break; 00430 case 32: //debugHolePositionZm 00431 00432 thisAntInfo->debugHolePositionZm=sqlite3_column_double(stmt, column); 00433 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugHolePositionZm %f\n", fStationId, row, thisAntInfo->debugHolePositionZm); 00434 00435 break; 00436 case 33: //debugTrueAsBuiltPosition[0] 00437 00438 thisAntInfo->debugTrueAsBuiltPositon[0]=sqlite3_column_double(stmt, column); 00439 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugTrueAsBuiltPositon[0] %f\n", fStationId, row, thisAntInfo->debugTrueAsBuiltPositon[0]); 00440 00441 break; 00442 case 34: //debugTrueAsBuiltPosition[1] 00443 00444 thisAntInfo->debugTrueAsBuiltPositon[1]=sqlite3_column_double(stmt, column); 00445 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugTrueAsBuiltPositon[1] %f\n", fStationId, row, thisAntInfo->debugTrueAsBuiltPositon[1]); 00446 00447 break; 00448 case 35: //debugTrueAsBuiltPosition[2] 00449 00450 thisAntInfo->debugTrueAsBuiltPositon[2]=sqlite3_column_double(stmt, column); 00451 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugTrueAsBuiltPositon[2] %f\n", fStationId, row, thisAntInfo->debugTrueAsBuiltPositon[2]); 00452 00453 break; 00454 case 36: //debugCableDelay2 00455 00456 thisAntInfo->debugCableDelay2=sqlite3_column_double(stmt, column); 00457 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugCableDelay2 %f\n", fStationId, row, thisAntInfo->debugCableDelay2); 00458 00459 break; 00460 case 37: //debugFeedPointDelay 00461 00462 thisAntInfo->debugFeedPointDelay=sqlite3_column_double(stmt, column); 00463 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugFeedPointDelay %f\n", fStationId, row, thisAntInfo->debugFeedPointDelay); 00464 00465 break; 00466 case 38: //debugTotalCableDelay 00467 00468 thisAntInfo->debugTotalCableDelay=sqlite3_column_double(stmt, column); 00469 //printf("fStationInfoATRI[%i].fAntInfo[%i].debugTotalCableDelay %f\n", fStationId, row, thisAntInfo->debugTotalCableDelay); 00470 00471 break; 00472 case 40: //antOrient[0] 00473 00474 thisAntInfo->antOrient[0]=sqlite3_column_double(stmt, column); 00475 //printf("fStationInfoATRI[%i].fAntInfo[%i].antOrient[0] %1.10f\n", fStationId, row, thisAntInfo->antOrient[0]); 00476 00477 break; 00478 00479 case 41: //antOrient[1] 00480 00481 thisAntInfo->antOrient[1]=sqlite3_column_double(stmt, column); 00482 //printf("fStationInfoATRI[%i].fAntInfo[%i].antOrient[1] %1.10f\n", fStationId, row, thisAntInfo->antOrient[1]); 00483 00484 break; 00485 00486 case 42: //antOrient[2] 00487 00488 thisAntInfo->antOrient[2]=sqlite3_column_double(stmt, column); 00489 //printf("fStationInfoATRI[%i].fAntInfo[%i].antOrient[2] %1.10f\n", fStationId, row, thisAntInfo->antOrient[2]); 00490 00491 break; 00492 00493 00494 default: 00495 00496 break; 00497 00498 }//switch(column) 00499 00500 }//column 00501 thisAntInfo->fillArrayCoords(); 00502 00503 }//while(1) 00504 00505 //now need to destroy the sqls statement prepared earlier 00506 rc = sqlite3_finalize(stmt); 00507 if(rc!=SQLITE_OK) printf("error finlizing sql statement\n"); 00508 // printf("sqlite3_finalize(stmt) = %i\n", rc); 00509 00510 //now close the connection to the database 00511 rc = sqlite3_close(db); 00512 if(rc!=SQLITE_OK) printf("error closing db\n"); 00513 00514 this->fillAntIndexVec(); 00515 00516 } 00517 00518 00519 //______________________________________________________________________________ 00520 00521 void AraStationInfo::readChannelMapDbIcrr(){ 00522 sqlite3 *db; 00523 char *zErrMsg = 0; 00524 sqlite3_stmt *stmt; 00525 // int calibIndex=getStationCalibIndex(fStationId); 00526 00527 char calibDir[FILENAME_MAX]; 00528 char fileName[FILENAME_MAX]; 00529 char *calibEnv=getenv("ARA_CALIB_DIR"); 00530 if(!calibEnv) { 00531 char *utilEnv=getenv("ARA_UTIL_INSTALL_DIR"); 00532 if(!utilEnv) 00533 sprintf(calibDir,"calib"); 00534 else 00535 sprintf(calibDir,"%s/share/araCalib",utilEnv); 00536 } 00537 else { 00538 strncpy(calibDir,calibEnv,FILENAME_MAX); 00539 } 00540 sprintf(fileName, "%s/AntennaInfo.sqlite", calibDir); 00541 00542 //open the database 00543 // int rc = sqlite3_open_v2(fileName, &db, SQLITE_OPEN_READONLY, NULL); 00544 int rc = sqlite3_open(fileName, &db);; 00545 if(rc!=SQLITE_OK){ 00546 printf("AraStationInfo::readChannelMapDbIcrr() - Can't open database: %s\n", sqlite3_errmsg(db)); 00547 sqlite3_close(db); 00548 return; 00549 } 00550 00551 const char *query; 00552 00553 //This is where we decide which table to access in the database 00554 if(fStationId==ARA_TESTBED) query = "select * from TestBed"; 00555 if(fStationId==ARA_STATION1) query = "select * from Station1"; 00556 00557 //prepare an sql statment which will be used to obtain information from the data base 00558 // rc=sqlite3_prepare_v2(db, query, strlen(query)+1, &stmt, NULL); 00559 rc=sqlite3_prepare(db, query, strlen(query)+1, &stmt, NULL); 00560 00561 if(rc!=SQLITE_OK){ 00562 printf("AraStationInfo::readChannelMapDbIcrr() : statement not prepared OK\n"); 00563 //should close the data base and exit the function 00564 sqlite3_close(db); 00565 return; 00566 } 00567 int row=0; 00568 while(1){ 00569 //printf("row number %i\n", row); 00570 rc=sqlite3_step(stmt); 00571 if(rc==SQLITE_DONE) break; 00572 int nColumns=sqlite3_column_count(stmt); 00573 00574 row=sqlite3_column_int(stmt, 2)-1;//forcing the row to be correct 00575 printf("row number %i\n", row); 00576 00577 AraAntennaInfo *thisAntInfo=this->getNewAntennaInfo(row); 00578 00579 for(int column=0;column<nColumns;column++){ 00580 00581 const char* temp; 00582 00583 switch(column){ 00584 case 0: //primary key - fStationId+labChip+channel 00585 00586 break; 00587 case 1: //antDir 00588 00589 temp = (const char*)sqlite3_column_text(stmt, column); 00590 00591 if(strcmp (temp,"kReceiver")==0){ 00592 thisAntInfo->antDir=AraAntDir::kReceiver; 00593 //printf("fStationInfoICRR[%i].fAntInfo[%i].antDir %i\n", fStationId, row, thisAntInfo->antDir); 00594 } 00595 00596 break; 00597 case 2: //chanNum 00598 00599 thisAntInfo->chanNum=sqlite3_column_int(stmt, column); 00600 00601 00602 //printf("fStationInfoICRR[%i].fAntInfo[%i].chanNum %i\n", fStationId, row, thisAntInfo->chanNum); 00603 00604 break; 00605 case 3: //daqChanType 00606 00607 temp = (const char*)sqlite3_column_text(stmt, column); 00608 if(strcmp (temp,"kDisconeChan")==0) thisAntInfo->daqChanType=AraDaqChanType::kDisconeChan; 00609 if(strcmp (temp,"kBatwingChan")==0) thisAntInfo->daqChanType=AraDaqChanType::kBatwingChan; 00610 00611 //printf("fStationInfoICRR[%i].fAntInfo[%i].daqChanType %i\n", fStationId, row, thisAntInfo->daqChanType); 00612 00613 break; 00614 case 4: //daqChanNum 00615 00616 thisAntInfo->daqChanNum=sqlite3_column_int(stmt, column); 00617 //printf("fStationInfoICRR[%i].fAntInfo[%i].daqChanNum %i\n", fStationId, row, thisAntInfo->daqChanNum); 00618 00619 break; 00620 case 5: //highPassFilterMhz 00621 00622 thisAntInfo->highPassFilterMhz=sqlite3_column_double(stmt, column); 00623 //printf("fStationInfoICRR[%i].fAntInfo[%i].highPassFilterMhz %f\n", fStationId, row, thisAntInfo->highPassFilterMhz); 00624 00625 break; 00626 case 6: //lowPassFilterMhz 00627 thisAntInfo->lowPassFilterMhz=sqlite3_column_double(stmt, column); 00628 //printf("fStationInfoICRR[%i].fAntInfo[%i].lowPassFilterMhz %f\n", fStationId, row, thisAntInfo->lowPassFilterMhz); 00629 00630 break; 00631 case 7: //daqTrigChan 00632 thisAntInfo->daqTrigChan=sqlite3_column_int(stmt, column); 00633 //printf("fStationInfoICRR[%i].fAntInfo[%i].daqTrigChan %i\n", fStationId, row, thisAntInfo->daqTrigChan); 00634 00635 break; 00636 case 8: //numLabChans 00637 00638 thisAntInfo->numLabChans=sqlite3_column_int(stmt, column); 00639 //printf("fStationInfoICRR[%i].fAntInfo[%i].numLabChans %i\n", fStationId, row, thisAntInfo->numLabChans); 00640 00641 break; 00642 case 9: //labChip 00643 00644 temp = (const char*)sqlite3_column_text(stmt, column); 00645 if(strcmp (temp,"kA")==0) thisAntInfo->labChip=AraLabChip::kA; 00646 if(strcmp (temp,"kB")==0) thisAntInfo->labChip=AraLabChip::kB; 00647 if(strcmp (temp,"kC")==0) thisAntInfo->labChip=AraLabChip::kC; 00648 00649 //printf("fStationInfoICRR[%i].fAntInfo[%i].labChip %i\n", fStationId, row, thisAntInfo->labChip); 00650 00651 break; 00652 case 10: //labChans[0] 00653 00654 thisAntInfo->labChans[0]=sqlite3_column_int(stmt, column)-1; 00655 //printf("fStationInfoICRR[%i].fAntInfo[%i].labChans[0] %i\n", fStationId, row, thisAntInfo->labChans[0]); 00656 00657 break; 00658 case 11: //labChans[1] 00659 00660 thisAntInfo->labChans[1]=sqlite3_column_int(stmt, column)-1; 00661 //printf("fStationInfoICRR[%i].fAntInfo[%i].labChans[1] %i\n", fStationId, row, thisAntInfo->labChans[1]); 00662 00663 break; 00664 case 12: //isDiplexed 00665 00666 thisAntInfo->isDiplexed=sqlite3_column_int(stmt, column); 00667 //printf("fStationInfoICRR[%i].fAntInfo[%i].isDiplexed %i\n", fStationId, row, thisAntInfo->isDiplexed); 00668 00669 break; 00670 case 13: //diplexedChans[0] 00671 00672 thisAntInfo->diplexedChans[0]=sqlite3_column_int(stmt, column); 00673 //printf("fStationInfoICRR[%i].fAntInfo[%i].diplexedChans[0] %i\n", fStationId, row, thisAntInfo->diplexedChans[0]); 00674 00675 break; 00676 case 14: //diplexedChans[1] 00677 00678 thisAntInfo->diplexedChans[1]=sqlite3_column_int(stmt, column); 00679 //printf("fStationInfoICRR[%i].fAntInfo[%i].diplexedChans[1] %i\n", fStationId, row, thisAntInfo->diplexedChans[1]); 00680 00681 break; 00682 case 15: //preAmpNum 00683 00684 thisAntInfo->preAmpNum=sqlite3_column_int(stmt, column); 00685 //printf("fStationInfoICRR[%i].fAntInfo[%i].preAmpNum %i\n", fStationId, row, thisAntInfo->preAmpNum); 00686 00687 break; 00688 case 16: //avgNoiseFigure 00689 00690 thisAntInfo->avgNoiseFigure=sqlite3_column_double(stmt, column); 00691 //printf("fStationInfoICRR[%i].fAntInfo[%i].avgNoiseFigure %f\n", fStationId, row, thisAntInfo->avgNoiseFigure); 00692 00693 break; 00694 case 17: //rcvrNum 00695 00696 thisAntInfo->rcvrNum=sqlite3_column_int(stmt, column); 00697 //printf("fStationInfoICRR[%i].fAntInfo[%i].rcvrNum %i\n", fStationId, row, thisAntInfo->rcvrNum); 00698 00699 break; 00700 case 18: //designator 00701 00702 temp = (const char*)sqlite3_column_text(stmt, column); 00703 strncpy(thisAntInfo->designator, temp, 3); 00704 //printf("fStationInfoICRR[%i].fAntInfo[%i].designator %s\n", fStationId, row, thisAntInfo->designator); 00705 00706 break; 00707 case 19: //antPolNum 00708 00709 thisAntInfo->antPolNum=sqlite3_column_int(stmt, column); 00710 //printf("fStationInfoICRR[%i].fAntInfo[%i].antPolNum %i\n", fStationId, row, thisAntInfo->antPolNum); 00711 00712 break; 00713 case 20: //antType 00714 00715 temp = (const char*)sqlite3_column_text(stmt, column); 00716 if(strcmp (temp,"kBicone")==0) thisAntInfo->antType=AraAntType::kBicone; 00717 if(strcmp (temp,"kBowtieSlot")==0) thisAntInfo->antType=AraAntType::kBowtieSlot; 00718 if(strcmp (temp,"kDiscone")==0) thisAntInfo->antType=AraAntType::kDiscone; 00719 if(strcmp (temp,"kBatwing")==0) thisAntInfo->antType=AraAntType::kBatwing; 00720 if(strcmp (temp,"kFatDipole")==0) thisAntInfo->antType=AraAntType::kFatDipole; 00721 if(strcmp (temp,"kQuadSlot")==0) thisAntInfo->antType=AraAntType::kQuadSlot; 00722 00723 //printf("fStationInfoICRR[%i].fAntInfo[%i].antType %i\n", fStationId, row, thisAntInfo->antType); 00724 00725 break; 00726 case 21: //polType 00727 00728 temp = (const char*)sqlite3_column_text(stmt, column); 00729 if(strcmp (temp,"kVertical")==0) thisAntInfo->polType=AraAntPol::kVertical; 00730 if(strcmp (temp,"kHorizontal")==0) thisAntInfo->polType=AraAntPol::kHorizontal; 00731 if(strcmp (temp,"kSurface")==0) thisAntInfo->polType=AraAntPol::kSurface; 00732 00733 //printf("fStationInfoICRR[%i].fAntInfo[%i].AraAntPol %i\n", fStationId, row, thisAntInfo->polType); 00734 00735 break; 00736 case 22: //locationName 00737 00738 temp = (const char*)sqlite3_column_text(stmt, column); 00739 strncpy(thisAntInfo->locationName, temp, 4); 00740 //printf("fStationInfoICRR[%i].fAntInfo[%i].locationName %s\n", fStationId, row, thisAntInfo->locationName); 00741 00742 00743 break; 00744 case 23: //antLocation[0] 00745 00746 thisAntInfo->antLocation[0]=sqlite3_column_double(stmt, column); 00747 //printf("fStationInfoICRR[%i].fAntInfo[%i].antLocation[0] %f\n", fStationId, row, thisAntInfo->antLocation[0]); 00748 00749 break; 00750 case 24: //antLocation[1] 00751 00752 thisAntInfo->antLocation[1]=sqlite3_column_double(stmt, column); 00753 //printf("fStationInfoICRR[%i].fAntInfo[%i].antLocation[1] %f\n", fStationId, row, thisAntInfo->antLocation[1]); 00754 00755 break; 00756 case 25: //antLocation[2] 00757 00758 thisAntInfo->antLocation[2]=sqlite3_column_double(stmt, column); 00759 //printf("fStationInfoICRR[%i].fAntInfo[%i].antLocation[2] %f\n", fStationId, row, thisAntInfo->antLocation[2]); 00760 00761 break; 00762 case 26: //cableDelay 00763 00764 thisAntInfo->cableDelay=sqlite3_column_double(stmt, column); 00765 //printf("fStationInfoICRR[%i].fAntInfo[%i].cableDelay %f\n", fStationId, row, thisAntInfo->cableDelay); 00766 00767 break; 00768 case 27: //debugHolePosition[0] 00769 00770 thisAntInfo->debugHolePosition[0]=sqlite3_column_double(stmt, column); 00771 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugHolePosition[0] %f\n", fStationId, row, thisAntInfo->debugHolePosition[0]); 00772 00773 break; 00774 case 28: //debugHolePosition[1] 00775 00776 thisAntInfo->debugHolePosition[1]=sqlite3_column_double(stmt, column); 00777 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugHolePosition[1] %f\n", fStationId, row, thisAntInfo->debugHolePosition[1]); 00778 00779 break; 00780 case 29: //debugHolePosition[2] 00781 00782 thisAntInfo->debugHolePosition[2]=sqlite3_column_double(stmt, column); 00783 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugHolePosition[2] %f\n", fStationId, row, thisAntInfo->debugHolePosition[2]); 00784 00785 break; 00786 case 30: //debugPreAmpDz 00787 00788 thisAntInfo->debugPreAmpDz=sqlite3_column_double(stmt, column); 00789 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugPreAmpDz %f\n", fStationId, row, thisAntInfo->debugPreAmpDz); 00790 00791 break; 00792 case 31: //debugHolePositionZft 00793 00794 thisAntInfo->debugHolePositionZft=sqlite3_column_double(stmt, column); 00795 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugHolePositionZft %f\n", fStationId, row, thisAntInfo->debugHolePositionZft); 00796 00797 break; 00798 case 32: //debugHolePositionZm 00799 00800 thisAntInfo->debugHolePositionZm=sqlite3_column_double(stmt, column); 00801 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugHolePositionZm %f\n", fStationId, row, thisAntInfo->debugHolePositionZm); 00802 00803 break; 00804 case 33: //debugTrueAsBuiltPosition[0] 00805 00806 thisAntInfo->debugTrueAsBuiltPositon[0]=sqlite3_column_double(stmt, column); 00807 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugTrueAsBuiltPositon[0] %f\n", fStationId, row, thisAntInfo->debugTrueAsBuiltPositon[0]); 00808 00809 break; 00810 case 34: //debugTrueAsBuiltPosition[1] 00811 00812 thisAntInfo->debugTrueAsBuiltPositon[1]=sqlite3_column_double(stmt, column); 00813 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugTrueAsBuiltPositon[1] %f\n", fStationId, row, thisAntInfo->debugTrueAsBuiltPositon[1]); 00814 00815 break; 00816 case 35: //debugTrueAsBuiltPosition[2] 00817 00818 thisAntInfo->debugTrueAsBuiltPositon[2]=sqlite3_column_double(stmt, column); 00819 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugTrueAsBuiltPositon[2] %f\n", fStationId, row, thisAntInfo->debugTrueAsBuiltPositon[2]); 00820 00821 break; 00822 case 36: //debugCableDelay2 00823 00824 thisAntInfo->debugCableDelay2=sqlite3_column_double(stmt, column); 00825 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugCableDelay2 %f\n", fStationId, row, thisAntInfo->debugCableDelay2); 00826 00827 break; 00828 case 37: //debugFeedPointDelay 00829 00830 thisAntInfo->debugFeedPointDelay=sqlite3_column_double(stmt, column); 00831 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugFeedPointDelay %f\n", fStationId, row, thisAntInfo->debugFeedPointDelay); 00832 00833 break; 00834 case 38: //debugTotalCableDelay 00835 00836 thisAntInfo->debugTotalCableDelay=sqlite3_column_double(stmt, column); 00837 //printf("fStationInfoICRR[%i].fAntInfo[%i].debugTotalCableDelay %f\n", fStationId, row, thisAntInfo->debugTotalCableDelay); 00838 00839 break; 00840 case 40: //antOrient[0] 00841 00842 thisAntInfo->antOrient[0]=sqlite3_column_double(stmt, column); 00843 //printf("fStationInfoICRR[%i].fAntInfo[%i].antOrient[0] %1.10f\n", fStationId, row, thisAntInfo->antOrient[0]); 00844 00845 break; 00846 00847 case 41: //antOrient[1] 00848 00849 thisAntInfo->antOrient[1]=sqlite3_column_double(stmt, column); 00850 //printf("fStationInfoICRR[%i].fAntInfo[%i].antOrient[1] %1.10f\n", fStationId, row, thisAntInfo->antOrient[1]); 00851 00852 break; 00853 00854 case 42: //antOrient[2] 00855 00856 thisAntInfo->antOrient[2]=sqlite3_column_double(stmt, column); 00857 //printf("fStationInfoICRR[%i].fAntInfo[%i].antOrient[2] %1.10f\n", fStationId, row, thisAntInfo->antOrient[2]); 00858 00859 break; 00860 00861 00862 default: 00863 00864 break; 00865 00866 }//switch(column) 00867 00868 }//column 00869 00870 00871 }//while(1) 00872 //now insert the no of rfchannels 00873 00874 // if(fStationId==ARA_TESTBED) { 00875 // fStationInfoICRR[0].setNumRFChans(RFCHANS_TESTBED); 00876 // fStationInfoICRR[0].setNumAnts(RFCHANS_TESTBED); 00877 // } 00878 // else if(fStationId==ARA_STATION1) { 00879 // fStationInfoICRR[1].setNumRFChans(RFCHANS_STATION1); 00880 // fStationInfoICRR[1].setNumAnts(RFCHANS_STATION1); 00881 // } 00882 00883 //now need to destroy the sqls statement prepared earlier 00884 rc = sqlite3_finalize(stmt); 00885 if(rc!=SQLITE_OK) printf("error finlizing sql statement\n"); 00886 // printf("sqlite3_finalize(stmt) = %i\n", rc); 00887 00888 //now close the connection to the database 00889 rc = sqlite3_close(db); 00890 if(rc!=SQLITE_OK) printf("error closing db\n"); 00891 00892 this->fillAntIndexVec(); 00893 00894 } 00895 00896 00897 // ---------------------------------------------------------------------- 00898 00899 00900 void AraStationInfo::readCalPulserDb(){ 00901 sqlite3 *db; 00902 char *zErrMsg = 0; 00903 sqlite3_stmt *stmt; 00904 00905 char calibDir[FILENAME_MAX]; 00906 char fileName[FILENAME_MAX]; 00907 char *calibEnv=getenv("ARA_CALIB_DIR"); 00908 if(!calibEnv) { 00909 char *utilEnv=getenv("ARA_UTIL_INSTALL_DIR"); 00910 if(!utilEnv) 00911 sprintf(calibDir,"calib"); 00912 else 00913 sprintf(calibDir,"%s/share/araCalib",utilEnv); 00914 } 00915 else { 00916 strncpy(calibDir,calibEnv,FILENAME_MAX); 00917 } 00918 sprintf(fileName, "%s/CalPulserInfo.sqlite", calibDir); 00919 00920 //open the database 00921 // int rc = sqlite3_open_v2(fileName, &db, SQLITE_OPEN_READONLY, NULL); 00922 int rc = sqlite3_open(fileName, &db);; 00923 if(rc!=SQLITE_OK){ 00924 printf("AraStationInfo::readCalPulserDb() - Can't open database: %s\n", sqlite3_errmsg(db)); 00925 sqlite3_close(db); 00926 return; 00927 } 00928 00929 const char *query; 00930 00931 //This is where we decide which table to access in the database 00932 if(fStationId==ARA_STATION1B) query = "select * from ARA01"; 00933 else if(fStationId==ARA_STATION2) query = "select * from ARA02"; 00934 else if(fStationId==ARA_STATION3) query = "select * from ARA03"; 00935 else{ 00936 fprintf(stderr, "%s : fStationId %i is not ARA1-3\n", __FUNCTION__, fStationId); 00937 return; 00938 } 00939 //prepare an sql statment which will be used to obtain information from the data base 00940 // rc=sqlite3_prepare_v2(db, query, strlen(query)+1, &stmt, NULL); 00941 rc=sqlite3_prepare(db, query, strlen(query)+1, &stmt, NULL); 00942 00943 if(rc!=SQLITE_OK){ 00944 printf("AraStationInfo::readCalPulserDb() statement not prepared OK\n"); 00945 //should close the data base and exit the function 00946 sqlite3_close(db); 00947 return; 00948 } 00949 00950 int calAntId=0; 00951 int row=0; 00952 while(1){ 00953 //printf("row number %i\n", row); 00954 rc=sqlite3_step(stmt); 00955 if(rc==SQLITE_DONE) break; 00956 int nColumns=sqlite3_column_count(stmt); 00957 00958 row=sqlite3_column_int(stmt, 2)-1;//forcing the row to be correct 00959 //printf("row number %i\n", row); 00960 AraCalAntennaInfo *thisAntInfo=NULL; 00961 00962 for(int column=0;column<nColumns;column++){ 00963 00964 const char* temp; 00965 00966 switch(column){ 00967 case 0: //primary key - fStationId+labChip+channel 00968 calAntId=sqlite3_column_int(stmt,column); 00969 thisAntInfo=this->getNewCalAntennaInfo(calAntId); 00970 break; 00971 case 1: //locationName 00972 temp = (const char*)sqlite3_column_text(stmt, column); 00973 strncpy(thisAntInfo->locationName, temp, 4); 00974 break; 00975 case 2: //antName 00976 temp = (const char*)sqlite3_column_text(stmt, column); 00977 strncpy(thisAntInfo->antName, temp, 4); 00978 break; 00979 case 3: //pulserName 00980 temp = (const char*)sqlite3_column_text(stmt, column); 00981 strncpy(thisAntInfo->pulserName, temp, 4); 00982 break; 00983 case 4: //antType 00984 temp = (const char*)sqlite3_column_text(stmt, column); 00985 if(strcmp (temp,"kBicone")==0) thisAntInfo->antType=AraAntType::kBicone; 00986 if(strcmp (temp,"kBowtieSlot")==0) thisAntInfo->antType=AraAntType::kBowtieSlot; 00987 if(strcmp (temp,"kDiscone")==0) thisAntInfo->antType=AraAntType::kDiscone; 00988 if(strcmp (temp,"kBatwing")==0) thisAntInfo->antType=AraAntType::kBatwing; 00989 if(strcmp (temp,"kFatDipole")==0) thisAntInfo->antType=AraAntType::kFatDipole; 00990 if(strcmp (temp,"kQuadSlot")==0) thisAntInfo->antType=AraAntType::kQuadSlot; 00991 //printf("fStationInfoATRI[%i].fAntInfo[%i].antType %i\n", fStationId, row, thisAntInfo->antType); 00992 break; 00993 case 5: //polType 00994 temp = (const char*)sqlite3_column_text(stmt, column); 00995 if(strcmp (temp,"kVertical")==0) thisAntInfo->polType=AraAntPol::kVertical; 00996 if(strcmp (temp,"kHorizontal")==0) thisAntInfo->polType=AraAntPol::kHorizontal; 00997 if(strcmp (temp,"kSurface")==0) thisAntInfo->polType=AraAntPol::kSurface; 00998 //printf("fStationInfoATRI[%i].fAntInfo[%i].AraAntPol %i\n", fStationId, row, thisAntInfo->polType); 00999 break; 01000 case 6: //antLocation[0] 01001 01002 thisAntInfo->antLocation[0]=sqlite3_column_double(stmt, column); 01003 //printf("fStationInfoATRI[%i].fAntInfo[%i].antLocation[0] %f\n", fStationId, row, thisAntInfo->antLocation[0]); 01004 01005 break; 01006 case 7: //antLocation[1] 01007 01008 thisAntInfo->antLocation[1]=sqlite3_column_double(stmt, column); 01009 //printf("fStationInfoATRI[%i].fAntInfo[%i].antLocation[1] %f\n", fStationId, row, thisAntInfo->antLocation[1]); 01010 01011 break; 01012 case 8: //antLocation[2] 01013 01014 thisAntInfo->antLocation[2]=sqlite3_column_double(stmt, column); 01015 //printf("fStationInfoATRI[%i].fAntInfo[%i].antLocation[2] %f\n", fStationId, row, thisAntInfo->antLocation[2]); 01016 01017 break; 01018 case 9: //cableDelay 01019 01020 thisAntInfo->cableDelay=sqlite3_column_double(stmt, column); 01021 //printf("fStationInfoATRI[%i].fAntInfo[%i].cableDelay %f\n", fStationId, row, thisAntInfo->cableDelay); 01022 01023 break; 01024 01025 01026 case 10: //antLocationCalib[0] 01027 01028 thisAntInfo->antLocationCalib[0]=sqlite3_column_double(stmt, column); 01029 //printf("fStationInfoATRI[%i].fAntInfo[%i].antLocationCalib[0] %f\n", fStationId, row, thisAntInfo->antLocationCalib[0]); 01030 01031 break; 01032 case 11: //antLocationCalib[1] 01033 01034 thisAntInfo->antLocationCalib[1]=sqlite3_column_double(stmt, column); 01035 //printf("fStationInfoATRI[%i].fAntInfo[%i].antLocationCalib[1] %f\n", fStationId, row, thisAntInfo->antLocationCalib[1]); 01036 01037 break; 01038 case 12: //antLocationCalib[2] 01039 01040 thisAntInfo->antLocationCalib[2]=sqlite3_column_double(stmt, column); 01041 //printf("fStationInfoATRI[%i].fAntInfo[%i].antLocationCalib[2] %f\n", fStationId, row, thisAntInfo->antLocationCalib[2]); 01042 01043 break; 01044 case 13: //cableDelayCalib 01045 01046 thisAntInfo->cableDelayCalib=sqlite3_column_double(stmt, column); 01047 //printf("fStationInfoATRI[%i].fAntInfo[%i].cableDelay %f\n", fStationId, row, thisAntInfo->cableDelay); 01048 01049 break; 01050 01051 01052 default: 01053 01054 break; 01055 01056 }//switch(column) 01057 01058 }//column 01059 thisAntInfo->fillArrayCoords(); 01060 }//while(1) 01061 01062 //now need to destroy the sqls statement prepared earlier 01063 rc = sqlite3_finalize(stmt); 01064 if(rc!=SQLITE_OK) printf("error finlizing sql statement\n"); 01065 // printf("sqlite3_finalize(stmt) = %i\n", rc); 01066 01067 //now close the connection to the database 01068 rc = sqlite3_close(db); 01069 if(rc!=SQLITE_OK) printf("error closing db\n"); 01070 01071 } 01072 01073 // ---------------------------------------------------------------------- 01074 01075 01076 void AraStationInfo::readChannelMapDbAtri_2(){ 01077 sqlite3 *db; 01078 char *zErrMsg = 0; 01079 sqlite3_stmt *stmt; 01080 01081 char calibDir[FILENAME_MAX]; 01082 char fileName[FILENAME_MAX]; 01083 char *calibEnv=getenv("ARA_CALIB_DIR"); 01084 if(!calibEnv) { 01085 char *utilEnv=getenv("ARA_UTIL_INSTALL_DIR"); 01086 if(!utilEnv) 01087 sprintf(calibDir,"calib"); 01088 else 01089 sprintf(calibDir,"%s/share/araCalib",utilEnv); 01090 } 01091 else { 01092 strncpy(calibDir,calibEnv,FILENAME_MAX); 01093 } 01094 sprintf(fileName, "%s/AntennaInfo_test.sqlite", calibDir); 01095 01096 //open the database 01097 int rc = sqlite3_open(fileName, &db);; 01098 if(rc!=SQLITE_OK){ 01099 fprintf(stderr, "%s - Can't open database: %s\n", __FUNCTION__, sqlite3_errmsg(db)); 01100 sqlite3_close(db); 01101 return; 01102 } 01103 01104 const char *query; 01105 01106 //This is where we decide which table to access in the database 01107 if(fStationId==ARA_STATION1B) query = "select * from ARA01"; 01108 else if(fStationId==ARA_STATION2) query = "select * from ARA02"; 01109 else if(fStationId==ARA_STATION3) query = "select * from ARA03"; 01110 else{ 01111 fprintf(stderr, "%s : fStationId %i is not ARA1-3\n", __FUNCTION__, fStationId); 01112 return; 01113 } 01114 01115 rc=sqlite3_prepare(db, query, strlen(query)+1, &stmt, NULL); 01116 01117 if(rc!=SQLITE_OK){ 01118 fprintf(stderr, "%s : statement not prepared OK\n", __FUNCTION__); 01119 sqlite3_close(db); 01120 return; 01121 } 01122 01123 int antId=0; 01124 AraAntennaInfo *thisAntInfo=NULL; 01125 while(1){ 01126 //printf("row number %i\n", row); 01127 rc=sqlite3_step(stmt); 01128 if(rc==SQLITE_DONE) break; 01129 int nColumns=sqlite3_column_count(stmt); 01130 01131 for(int column=0;column<nColumns;column++){ 01132 01133 const char* temp; 01134 01135 switch(column){ 01136 case 0: //primary key 01137 antId=sqlite3_column_int(stmt,column); 01138 thisAntInfo=this->getNewAntennaInfo(antId); 01139 thisAntInfo->chanNum=antId; 01140 //printf("\n\nthisAntInfo->chanNum=antId %i\n", thisAntInfo->chanNum=antId); 01141 break; 01142 case 1://holeName 01143 temp = (const char*)sqlite3_column_text(stmt, column); 01144 strncpy(thisAntInfo->holeName, temp, 6); 01145 //printf("thisAntInfo->holeName %s\n", thisAntInfo->holeName, temp); 01146 break; 01147 case 2://antName 01148 temp = (const char*)sqlite3_column_text(stmt, column); 01149 strncpy(thisAntInfo->antName, temp, 6); 01150 //printf("thisAntInfo->antName %s\n", thisAntInfo->antName, temp); 01151 break; 01152 case 3://polType 01153 temp = (const char*)sqlite3_column_text(stmt, column); 01154 if(strcmp (temp,"kVertical")==0) thisAntInfo->polType=AraAntPol::kVertical; 01155 if(strcmp (temp,"kHorizontal")==0) thisAntInfo->polType=AraAntPol::kHorizontal; 01156 if(strcmp (temp,"kSurface")==0) thisAntInfo->polType=AraAntPol::kSurface; 01157 //printf("thisAntInfo->polType %i\n", thisAntInfo->polType); 01158 break; 01159 case 4://antPolNum 01160 thisAntInfo->antPolNum=sqlite3_column_int(stmt, column); 01161 //printf("thisAntInfo->antPolNum %i\n", thisAntInfo->antPolNum); 01162 break; 01163 case 5://daqChanNum 01164 thisAntInfo->daqChanNum=sqlite3_column_int(stmt, column); 01165 //printf("thisAntInfo->daqChanNum %i\n", thisAntInfo->daqChanNum); 01166 break; 01167 case 6://daqTrigChan 01168 thisAntInfo->daqTrigChan=sqlite3_column_int(stmt, column); 01169 //printf("thisAntInfo->daqTrigChan %i\n", thisAntInfo->daqTrigChan); 01170 break; 01171 case 7://foamId 01172 thisAntInfo->foamId=sqlite3_column_int(stmt, column); 01173 //printf("thisAntInfo->foamId %i\n", thisAntInfo->foamId); 01174 break; 01175 case 8://foamChanNum 01176 thisAntInfo->foamChanNum=sqlite3_column_int(stmt, column); 01177 //printf("thisAntInfo->foamChanNum %i\n", thisAntInfo->foamChanNum); 01178 break; 01179 case 9://antType 01180 temp = (const char*)sqlite3_column_text(stmt, column); 01181 if(strcmp (temp,"kBicone")==0) thisAntInfo->antType=AraAntType::kBicone; 01182 if(strcmp (temp,"kBowtieSlot")==0) thisAntInfo->antType=AraAntType::kBowtieSlot; 01183 if(strcmp (temp,"kDiscone")==0) thisAntInfo->antType=AraAntType::kDiscone; 01184 if(strcmp (temp,"kBatwing")==0) thisAntInfo->antType=AraAntType::kBatwing; 01185 if(strcmp (temp,"kFatDipole")==0) thisAntInfo->antType=AraAntType::kFatDipole; 01186 if(strcmp (temp,"kQuadSlot")==0) thisAntInfo->antType=AraAntType::kQuadSlot; 01187 //printf("thisAntInfo->antType %s\n", AraAntType::antTypeAsString(thisAntInfo->antType)); 01188 break; 01189 case 10://antLocationX 01190 thisAntInfo->antLocation[0]=sqlite3_column_double(stmt, column); 01191 //printf("thisAntInfo->antLocation[0] %f\n", thisAntInfo->antLocation[0]); 01192 break; 01193 case 11://antLocationY 01194 thisAntInfo->antLocation[1]=sqlite3_column_double(stmt, column); 01195 //printf("thisAntInfo->antLocation[1] %f\n", thisAntInfo->antLocation[1]); 01196 break; 01197 case 12://antLocationZ 01198 thisAntInfo->antLocation[2]=sqlite3_column_double(stmt, column); 01199 //printf("thisAntInfo->antLocation[2] %f\n", thisAntInfo->antLocation[2]); 01200 break; 01201 case 13://cableDelay 01202 thisAntInfo->cableDelay=sqlite3_column_double(stmt, column); 01203 break; 01204 case 14://calibAntLocationX 01205 thisAntInfo->calibAntLocation[0]=sqlite3_column_double(stmt, column); 01206 //printf("thisAntInfo->calibAntLocation[0] %f\n", thisAntInfo->calibAntLocation[0]); 01207 break; 01208 case 15://calibAntLocationY 01209 thisAntInfo->calibAntLocation[1]=sqlite3_column_double(stmt, column); 01210 //printf("thisAntInfo->calibAntLocation[1] %f\n", thisAntInfo->calibAntLocation[1]); 01211 break; 01212 case 16://calibAntLocationZ 01213 thisAntInfo->calibAntLocation[2]=sqlite3_column_double(stmt, column); 01214 //printf("thisAntInfo->calibAntLocation[2] %f\n", thisAntInfo->calibAntLocation[2]); 01215 break; 01216 case 17://calibCableDelay 01217 thisAntInfo->calibCableDelay=sqlite3_column_double(stmt, column); 01218 break; 01219 case 18://antOrientX 01220 thisAntInfo->antOrient[0]=sqlite3_column_double(stmt, column); 01221 //printf("thisAntInfo->antOrient[0] %f\n", thisAntInfo->antOrient[0]); 01222 break; 01223 case 19://antOrientY 01224 thisAntInfo->antOrient[1]=sqlite3_column_double(stmt, column); 01225 //printf("thisAntInfo->antOrient[1] %f\n", thisAntInfo->antOrient[1]); 01226 break; 01227 case 20://antOrientZ 01228 thisAntInfo->antOrient[2]=sqlite3_column_double(stmt, column); 01229 //printf("thisAntInfo->antOrient[2] %f\n", thisAntInfo->antOrient[2]); 01230 break; 01231 case 21://highPassFilterMhz 01232 thisAntInfo->highPassFilterMhz=sqlite3_column_double(stmt, column); 01233 //printf("thisAntInfo->highPassFilterMhz %f\n", thisAntInfo->highPassFilterMhz); 01234 break; 01235 case 22://lowPassFilterMhz 01236 thisAntInfo->lowPassFilterMhz=sqlite3_column_double(stmt, column); 01237 //printf("thisAntInfo->lowPassFilterMhz %f\n", thisAntInfo->lowPassFilterMhz); 01238 break; 01239 case 23://avgNoiseFigure 01240 thisAntInfo->avgNoiseFigure=sqlite3_column_double(stmt, column); 01241 //printf("thisAntInfo->avgNoiseFigure %f\n", thisAntInfo->avgNoiseFigure); 01242 break; 01243 default: 01244 break; 01245 01246 }//switch(column) 01247 01248 }//column 01249 }//while(1) 01250 01251 rc = sqlite3_finalize(stmt); 01252 if(rc!=SQLITE_OK) fprintf(stderr, "%s : error finlizing sql statement\n", __FUNCTION__); 01253 rc = sqlite3_close(db); 01254 if(rc!=SQLITE_OK) fprintf(stderr, "%s : error closing db\n", __FUNCTION__); 01255 01256 this->fillAntIndexVec(); 01257 01258 }
Generated on Mon Jun 3 14:59:46 2013 for ARA ROOT v3.8 Software by
