00001
00002
00003 #include "CaloOnlineTools/HcalOnlineDb/interface/DBlmapReader.h"
00004
00005 using namespace std;
00006 using namespace oracle::occi;
00007 using namespace hcal;
00008
00009 int i, j;
00010 vector<int> tempVector;
00011 stringstream sstemp;
00012
00013 void DBlmapReader::lrTestFunction(void){
00014
00015 std::cout<<"Hello"<<std::endl;
00016 return;
00017 }
00018
00019 VectorLMAP* DBlmapReader::GetLMAP(int LMversion = 30){
00020 HCALConfigDB * db = new HCALConfigDB();
00021 const std::string _accessor = "occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22";
00022 db -> connect( _accessor );
00023
00024 oracle::occi::Connection * myConn = db -> getConnection();
00025
00026 int CHAcount = 0;
00027 VectorLMAP* lmapHBEFO = new VectorLMAP();
00028
00029 sstemp.str("");
00030 sstemp<<"'"<<LMversion<<"'";
00031 std::string verstring = sstemp.str();
00032 sstemp.str("");
00033
00034 try {
00035 Statement* stmt = myConn -> createStatement();
00036
00037 std::string query = (" SELECT C.VERSION, ");
00038 query += " H.SIDE, H.ETA, H.PHI, ";
00039 query += " H.DELTA_PHI, H.DEPTH, H.SUBDETECTOR, H.RBX, H.WEDGE, ";
00040 query += " H.SECTOR, H.RM_SLOT, H.HPD_PIXEL, H.QIE_SLOT, H.ADC, ";
00041 query += " H.RM_FIBER, H.FIBER_CHANNEL, H.LETTER_CODE, H.CRATE, H.HTR_SLOT, ";
00042 query += " H.HTR_FPGA, H.HTR_FIBER, H.DCC_SL, H.SPIGOT, H.DCC_SLOT, ";
00043 query += " H.SLB_SITE, H.SLB_CHANNEL, H.SLB_CHANNEL2, H.SLB_CABLE, H.RCT_CRATE, ";
00044 query += " H.RCT_CARD, H.RCT_CONNECTOR, H.RCT_NAME, H.FED_ID ";
00045 query += " FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 H inner join ";
00046 query += " CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS C ";
00047 query += " on C.CONDITION_DATA_SET_ID=H.CONDITION_DATA_SET_ID ";
00048 query += " inner join CMS_HCL_CORE_CONDITION_OWNER.KINDS_OF_CONDITIONS K ";
00049 query += " on K.KIND_OF_CONDITION_ID=C.KIND_OF_CONDITION_ID ";
00050 query += " where C.IS_RECORD_DELETED='F' and K.IS_RECORD_DELETED='F' ";
00051 query += " and K.NAME='HCAL hardware logical channel maps v3' ";
00052 query += " and C.VERSION=";
00053 query += verstring;
00054
00055
00056 ResultSet *rs = stmt->executeQuery(query.c_str());
00057
00058 while (rs->next() && CHAcount < 10000) {
00059
00060 lmapHBEFO -> versionC . push_back( rs -> getInt(1) );
00061 lmapHBEFO -> sideC . push_back( rs -> getInt(2) );
00062 lmapHBEFO -> etaC . push_back( rs -> getInt(3) );
00063 lmapHBEFO -> phiC . push_back( rs -> getInt(4) );
00064 lmapHBEFO -> dphiC . push_back( rs -> getInt(5) );
00065
00066 lmapHBEFO -> depthC . push_back( rs -> getInt(6) );
00067 lmapHBEFO -> detC . push_back( rs -> getString(7) );
00068 lmapHBEFO -> rbxC . push_back( rs -> getString(8) );
00069 lmapHBEFO -> wedgeC . push_back( rs -> getInt(9) );
00070 lmapHBEFO -> sectorC . push_back( rs -> getInt(10) );
00071
00072 lmapHBEFO -> rmC . push_back( rs -> getInt(11) );
00073 lmapHBEFO -> pixelC . push_back( rs -> getInt(12) );
00074 lmapHBEFO -> qieC . push_back( rs -> getInt(13) );
00075 lmapHBEFO -> adcC . push_back( rs -> getInt(14) );
00076 lmapHBEFO -> rm_fiC . push_back( rs -> getInt(15) );
00077
00078 lmapHBEFO -> fi_chC . push_back( rs -> getInt(16) );
00079 lmapHBEFO -> let_codeC . push_back( rs -> getString(17) );
00080 lmapHBEFO -> crateC . push_back( rs -> getInt(18) );
00081 lmapHBEFO -> htrC . push_back( rs -> getInt(19) );
00082 lmapHBEFO -> fpgaC . push_back( rs -> getString(20) );
00083
00084 lmapHBEFO -> htr_fiC . push_back( rs -> getInt(21) );
00085 lmapHBEFO -> dcc_slC . push_back( rs -> getInt(22) );
00086 lmapHBEFO -> spigoC . push_back( rs -> getInt(23) );
00087 lmapHBEFO -> dccC . push_back( rs -> getInt(24) );
00088 lmapHBEFO -> slbC . push_back( rs -> getInt(25) );
00089
00090 lmapHBEFO -> slbinC . push_back( rs -> getString(26) );
00091 lmapHBEFO -> slbin2C . push_back( rs -> getString(27) );
00092 lmapHBEFO -> slnamC . push_back( rs -> getString(28) );
00093 lmapHBEFO -> rctcraC . push_back( rs -> getInt(29) );
00094 lmapHBEFO -> rctcarC . push_back( rs -> getInt(30) );
00095
00096 lmapHBEFO -> rctconC . push_back( rs -> getInt(31) );
00097 lmapHBEFO -> rctnamC . push_back( rs -> getString(32) );
00098 lmapHBEFO -> fedidC . push_back( rs -> getInt(33) );
00099
00100 lmapHBEFO -> orderC . push_back( CHAcount );
00101
00102 CHAcount++;
00103 }
00104
00105 myConn -> terminateStatement(stmt);
00106 }
00107 catch (SQLException& e) {
00108 std::cout<<"Couldn't get statement"<<std::endl;
00109 }
00110 db -> disconnect();
00111
00112 return lmapHBEFO;
00113 }
00114
00115 void DBlmapReader::PrintLMAP(FILE* HBEFmap, FILE* HOmap, VectorLMAP* lmapHBEFO){
00116
00117 int CHAcount = lmapHBEFO->orderC.size();
00118
00119 lmapHBEFO = SortByHardware(lmapHBEFO);
00120 for (i = 0; i < CHAcount; i++){
00121 if (lmapHBEFO -> orderC[i] >= CHAcount){
00122 std::cout<<"Bad order vector";
00123 break;
00124 }
00125
00126 if (lmapHBEFO -> detC[lmapHBEFO -> orderC[i]] != "HO") printHBHEHF(i, HBEFmap, lmapHBEFO);
00127 }
00128
00129 lmapHBEFO = SortByGeometry(lmapHBEFO);
00130 for (i = 0; i < CHAcount; i++){
00131 if (lmapHBEFO -> orderC[i] >= CHAcount){
00132 std::cout<<"Bad order vector";
00133 break;
00134 }
00135 if (lmapHBEFO -> detC[lmapHBEFO -> orderC[i]] == "HO") printHO(i, HOmap, lmapHBEFO);
00136 }
00137
00138 std::cout<<CHAcount<<std::endl;
00139 return;
00140 }
00141
00142 void DBlmapReader::PrintEMAPfromLMAP(FILE* emap, VectorLMAP* lmapHBEFO){
00143
00144 int CHAcount = lmapHBEFO->orderC.size();
00145
00146 lmapHBEFO = SortByHardware(lmapHBEFO);
00147 for (i = 0; i < CHAcount; i++){
00148 if (lmapHBEFO ->detC[lmapHBEFO -> orderC[i]] != "HO") printEMAProw(i, emap, lmapHBEFO);
00149 }
00150
00151 lmapHBEFO = SortByGeometry(lmapHBEFO);
00152 for (i = 0; i < CHAcount; i++){
00153 if (lmapHBEFO -> detC[lmapHBEFO -> orderC[i]] == "HO") printEMAProw(i, emap, lmapHBEFO);
00154 }
00155
00156 return;
00157 }
00158
00159
00160 void printHBHEHF(int channel, FILE * HBEFmap, VectorLMAP * lmap){
00161
00162 if (channel % 21 == 0){
00163 fprintf(HBEFmap,"# side eta phi dphi depth det rbx wedge rm pixel qie adc");
00164 fprintf(HBEFmap," rm_fi fi_ch crate htr fpga htr_fi dcc_sl spigo dcc slb slbin slbin2");
00165 fprintf(HBEFmap," slnam rctcra rctcar rctcon rctnam fedid\n");
00166 }
00167
00168 j = lmap -> orderC[channel];
00169
00170 fprintf(HBEFmap,"%6d %6d %6d %6d %6d ", lmap->sideC[j], lmap->etaC[j], lmap->phiC[j], lmap->dphiC[j], lmap -> depthC[j]);
00171 fprintf(HBEFmap,"%6s %7s %6d %6d %6d", lmap->detC[j].c_str(), lmap->rbxC[j].c_str(), lmap->wedgeC[j], lmap->rmC[j], lmap->pixelC[j]);
00172 fprintf(HBEFmap,"%6d %6d %6d %6d %6d ", lmap->qieC[j], lmap->adcC[j], lmap->rm_fiC[j], lmap->fi_chC[j], lmap->crateC[j]);
00173 fprintf(HBEFmap,"%6d %6s%8d %7d ", lmap->htrC[j], lmap->fpgaC[j].c_str(), lmap->htr_fiC[j], lmap->dcc_slC[j]);
00174 fprintf(HBEFmap,"%6d %6d %6d %6s", lmap->spigoC[j], lmap->dccC[j], lmap->slbC[j], lmap->slbinC[j].c_str());
00175 fprintf(HBEFmap,"%8s %15s %6d %6d ", lmap->slbin2C[j].c_str(), lmap->slnamC[j].c_str(), lmap->rctcraC[j], lmap->rctcarC[j]);
00176 fprintf(HBEFmap,"%6d %20s %6d\n", lmap->rctconC[j], lmap->rctnamC[j].c_str(), lmap->fedidC[j]);
00177 }
00178
00179 void printHO(int channel, FILE * HOmap, VectorLMAP * lmap){
00180
00181 if (channel % 21 == 3){
00182 fprintf(HOmap,"# side eta phi dphi depth det rbx sector rm pixel qie adc");
00183 fprintf(HOmap," rm_fi fi_ch let_code crate htr fpga htr_fi dcc_sl spigo dcc slb slbin slbin2");
00184 fprintf(HOmap," slnam rctcra rctcar rctcon rctnam fedid\n");
00185 }
00186
00187 j = lmap -> orderC[channel];
00188
00189 fprintf(HOmap,"%6d %6d %6d %6d %6d ", lmap->sideC[j], lmap->etaC[j], lmap->phiC[j], lmap->dphiC[j], lmap -> depthC[j]);
00190 fprintf(HOmap,"%6s %7s %6d %6d %6d", lmap->detC[j].c_str(), lmap->rbxC[j].c_str(), lmap->sectorC[j], lmap->rmC[j], lmap->pixelC[j]);
00191 fprintf(HOmap,"%6d %6d %6d ", lmap->qieC[j], lmap->adcC[j], lmap->rm_fiC[j]);
00192 fprintf(HOmap,"%6d %8s %6d ", lmap->fi_chC[j], lmap->let_codeC[j].c_str(), lmap->crateC[j]);
00193 fprintf(HOmap,"%6d %6s%8d %7d ", lmap->htrC[j], lmap->fpgaC[j].c_str(), lmap->htr_fiC[j], lmap->dcc_slC[j]);
00194 fprintf(HOmap,"%6d %6d %6d\n", lmap->spigoC[j], lmap->dccC[j], lmap->fedidC[j]);
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 }
00206
00207 void printEMAProw(int channel, FILE * emap, VectorLMAP * lmap){
00208 j = lmap -> orderC[channel];
00209
00210 HcalSubdetector _subdet;
00211 if ( lmap->detC[j] == "HB" ) _subdet = HcalBarrel;
00212 else if ( lmap->detC[j] == "HE" ) _subdet = HcalEndcap;
00213 else if ( lmap->detC[j] == "HO" ) _subdet = HcalOuter;
00214 else if ( lmap->detC[j] == "HF" ) _subdet = HcalForward;
00215 else{
00216 _subdet = HcalBarrel;
00217 std::cerr<<"Bad Subdet"<<std::endl;
00218 }
00219 HcalDetId _hcaldetid( _subdet, (lmap->sideC[j])*(lmap->etaC[j]), lmap->phiC[j], lmap->depthC[j] );
00220 int hcalID = _hcaldetid . rawId();
00221
00222 char tb = lmap->fpgaC[j][0];
00223 fprintf(emap,"%10d %3d %3d %2c %4d %5d",hcalID, lmap->crateC[j], lmap->htrC[j], tb, (lmap->fedidC[j] - 700), lmap->spigoC[j]);
00224 fprintf(emap,"%5d %8d %8s %5d %4d %6d\n", lmap->htr_fiC[j], lmap->fi_chC[j], lmap->detC[j].c_str(), (lmap->etaC[j]*lmap->sideC[j]), lmap->phiC[j], lmap->depthC[j]);
00225
00226 return;
00227 }
00228
00229 bool SortComp(int x, int y){
00230 return tempVector[x] < tempVector[y];
00231 }
00232
00233 VectorLMAP* SortByHardware(VectorLMAP* lmapHBEFO){
00234
00235 int CHAcount = lmapHBEFO->orderC.size();
00236 tempVector.clear();
00237
00238
00239 for (i = 0; i < CHAcount; i++){
00240 tempVector.push_back (lmapHBEFO -> fi_chC[i]);
00241 }
00242 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00243 tempVector.clear();
00244
00245
00246 for (i = 0; i < CHAcount; i++){
00247 tempVector.push_back (lmapHBEFO -> htr_fiC[i]);
00248 }
00249 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00250 tempVector.clear();
00251
00252
00253 for (i = 0; i < CHAcount; i++){
00254 if (lmapHBEFO -> fpgaC[i] == "top") tempVector.push_back (0);
00255 else tempVector.push_back (1);
00256 }
00257 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00258 tempVector.clear();
00259
00260
00261 for (i = 0; i < CHAcount; i++){
00262 tempVector.push_back (lmapHBEFO -> htrC[i]);
00263 }
00264 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00265 tempVector.clear();
00266
00267
00268 for (i = 0; i < CHAcount; i++){
00269 tempVector.push_back (lmapHBEFO -> crateC[i]);
00270 }
00271 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00272 tempVector.clear();
00273
00274
00275 for (i = 0; i < CHAcount; i++){
00276 if (lmapHBEFO -> detC[i] == "HB" || lmapHBEFO -> detC[i] == "HE") tempVector.push_back (0);
00277 else if (lmapHBEFO -> detC[i] == "HF") tempVector.push_back (1);
00278 else tempVector.push_back (2);
00279 }
00280 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00281 tempVector.clear();
00282
00283 return lmapHBEFO;
00284 }
00285
00286 VectorLMAP* SortByGeometry(VectorLMAP* lmapHBEFO){
00287
00288 int CHAcount = lmapHBEFO->orderC.size();
00289 tempVector.clear();
00290
00291
00292 for (i = 0; i < CHAcount; i++){
00293 tempVector.push_back (lmapHBEFO -> etaC[i]);
00294 }
00295 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00296 tempVector.clear();
00297
00298
00299 for (i = 0; i < CHAcount; i++){
00300 tempVector.push_back (lmapHBEFO -> phiC[i]);
00301 }
00302 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00303 tempVector.clear();
00304
00305
00306 for (i = 0; i < CHAcount; i++){
00307 tempVector.push_back (lmapHBEFO -> sideC[i]);
00308 }
00309 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00310 tempVector.clear();
00311
00312
00313 for (i = 0; i < CHAcount; i++){
00314 if (lmapHBEFO -> detC[i] == "HB" || lmapHBEFO -> detC[i] == "HE") tempVector.push_back (0);
00315 else if (lmapHBEFO -> detC[i] == "HF") tempVector.push_back (1);
00316 else tempVector.push_back (2);
00317 }
00318 stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
00319 tempVector.clear();
00320
00321 return lmapHBEFO;
00322 }
00323