00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <iostream>
00018 #include <fstream>
00019 #include <string>
00020 #include "iomanip.h"
00021 using namespace std;
00022
00023
00024 void storetofZbCorr(const Bool_t mTest = 1)
00025 {
00026 const int mNTray = 120;
00027 const int mNTDIG = 8;
00028 const int mNVPD = 19;
00029 const int mNMODULE = 32;
00030 const int mNCELL = 6;
00031 const int mNMODPERBOARD = 4;
00032
00033
00034 gSystem->Load("St_base");
00035 gSystem->Load("StChain");
00036 gSystem->Load("StUtilities");
00037 gSystem->Load("St_Tables.so");
00038
00039 gSystem->Load("StDbLib.so");
00040 gSystem->Load("libStDb_Tables.so");
00041
00042
00043 StDbManager* dbManager = StDbManager::Instance();
00044
00045
00046 StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
00047
00048
00049
00050
00051
00052
00053
00054
00055 ifstream inTime;
00056 inTime.open("input/timestamp");
00057 string time;
00058 if (inTime.is_open()) {
00059 getline(inTime, time);
00060 inTime.close();
00061 } else {
00062 cout << " Unable to open the TimeStamp file! EXIT! " << endl;
00063 return;
00064 }
00065 TString StoreTime = time;
00066 cout << " Store Time " << StoreTime.Data() << endl;
00067
00068
00069 StDbTable* tofZbCorr = configNode->addDbTable("tofZbCorr");
00070
00071
00072
00073 tofZbCorr_st *zcorr= new tofZbCorr_st[23040];
00074
00075
00076
00077 ifstream infile;
00078
00079
00080 Double_t X[mNTray][mNMODULE][mNCELL][60];
00081 Double_t Y[mNTray][mNMODULE][mNCELL][60];
00082
00083 infile.open("input/zCali_4DB.dat");
00084 int calibSize;
00085 infile >> calibSize;
00086 cout << "reading in " << calibSize << " calibration records ... " << endl;
00087 switch (calibSize) {
00088 case 960 :
00089 for(int i=0;i<mNTray;i++) {
00090 for(int j=0;j<mNTDIG;j++) {
00091 int tray, board, nnn;
00092 infile >> tray >> board;
00093 infile >> nnn;
00094 cout << " tray = " << tray << " board = " << board << endl;
00095 for(int k=0;k<60;k++) {
00096 if(nnn>0&&k<nnn+1) {
00097 infile >> X[tray-1][board-1][0][k];
00098 } else {
00099 X[tray-1][board-1][0][k] = 0.0;
00100 }
00101 }
00102 for(int k=0;k<60;k++) {
00103 if(nnn>0&&k<nnn+1) {
00104 infile >> Y[tray-1][board-1][0][k];
00105 } else {
00106 Y[tray-1][board-1][0][k] = 0.0;
00107 }
00108 }
00109 }
00110 }
00111 break;
00112 case 23040 :
00113 for(int i=0;i<mNTray;i++) {
00114 for(int j=0;j<mNMODULE;j++) {
00115 for(int jj=0;jj<mNCELL;jj++) {
00116 int tray, module, cell, nnn;
00117 infile >> tray >> module >> cell;
00118 infile >> nnn;
00119 cout << " tray = " << tray << " module = " << module << " cell = " << cell << endl;
00120 for(int k=0;k<60;k++) {
00121 if(nnn>0&&k<nnn+1) {
00122 infile >> X[tray-1][module-1][cell-1][k];
00123 } else {
00124 X[tray-1][module-1][cell-1][k] = 0.0;
00125 }
00126 }
00127 for(int k=0;k<60;k++) {
00128 if(nnn>0&&k<nnn+1) {
00129 infile >> Y[tray-1][module-1][cell-1][k];
00130 } else {
00131 Y[tray-1][module-1][cell-1][k] = 0.0;
00132 }
00133 }
00134 }
00135 }
00136 }
00137 break;
00138 }
00139
00140 infile.close();
00141
00142
00143 cout << "preparing database records ... " << endl;
00144 switch (calibSize) {
00145 case 960:
00146 int index=-1;
00147 for (int tray=1;tray<mNTray+1;tray++){
00148 for (int module=1;module<mNMODULE+1;module++){
00149 for (int cell=1;cell<mNCELL+1;cell++){
00150 index++;
00151 zcorr[index].trayId = (Short_t)tray;
00152 zcorr[index].moduleId = (Short_t)module;
00153 zcorr[index].cellId = (Short_t)cell;
00154 int board = ((module-1)/mNMODPERBOARD) + 1;
00155 for(int j=0;j<60;j++) {
00156 zcorr[index].z[j] = X[tray-1][board-1][0][j];
00157 zcorr[index].corr[j] = Y[tray-1][board-1][0][j];
00158 }
00159 }
00160 }
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 break;
00176 case 23040:
00177 int index=-1;
00178 for (int tray=1;tray<mNTray+1;tray++){
00179 for (int module=1;module<mNMODULE+1;module++){
00180 for (int cell=1;cell<mNCELL+1;cell++){
00181 index++;
00182 zcorr[index].trayId = tray;
00183 zcorr[index].moduleId = module;
00184 zcorr[index].cellId = cell;
00185 for(int j=0;j<60;j++) {
00186 zcorr[index].z[j] = X[tray-1][module-1][cell-1][j];
00187 zcorr[index].corr[j] = Y[tray-1][module-1][cell-1][j];
00188 }
00189 }
00190 }
00191 }
00192 break;
00193 }
00194
00195
00196 cout << "Storing records in zCorr_test.dat ... " << endl;
00197
00198
00199 int nRow = 23040;
00200 ofstream outData;
00201 outData.open("zCorr_test.dat");
00202 for(int i=0;i<nRow;i++) {
00203 outData << setw(6) << zcorr[i].trayId << setw(6) << zcorr[i].moduleId << setw(6) << zcorr[i].cellId << endl;
00204 for(int j=0;j<60;j++) {
00205 if(fabs(zcorr[i].z[j])<1.e-4 && fabs(zcorr[i].corr[j])<1.e-4) continue;
00206 outData << setw(15) << zcorr[i].z[j];
00207 }
00208 outData << endl;
00209 for(int j=0;j<60;j++) {
00210 if(fabs(zcorr[i].z[j])<1.e-4 && fabs(zcorr[i].corr[j])<1.e-4) continue;
00211 outData << setw(15) << zcorr[i].corr[j];
00212 }
00213 outData << endl;
00214 }
00215 outData.close();
00216
00217 if(!mTest) {
00218 cout<<" prepare to upload data to DB"<<endl;
00219
00220 tofZbCorr->SetTable((char*)zcorr, nRow);
00221
00222 dbManager->setStoreTime(StoreTime.Data());
00223
00224 dbManager->storeDbTable(tofZbCorr);
00225 cout<<"uploaded"<<endl;
00226
00227 }
00228 }