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