CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DBlmapReader.cc
Go to the documentation of this file.
1 // Aram Avetisyan; Brown University; February 15, 2008
2 
4 
5 using namespace std;
6 using namespace oracle::occi;
7 using namespace hcal;
8 
9 int i, j;
10 vector<int> tempVector;
11 stringstream sstemp;
12 
14 
15  std::cout<<"Hello"<<std::endl;
16  return;
17 }
18 
19 VectorLMAP* DBlmapReader::GetLMAP(int LMversion = 30){
20  HCALConfigDB * db = new HCALConfigDB();
21  const std::string _accessor = "occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22";
22  db -> connect( _accessor );
23 
24  oracle::occi::Connection * myConn = db -> getConnection();
25 
26  int CHAcount = 0;
27  VectorLMAP* lmapHBEFO = new VectorLMAP();
28 
29  sstemp.str("");
30  sstemp<<"'"<<LMversion<<"'";
31  std::string verstring = sstemp.str();
32  sstemp.str("");
33 
34  try {
35  Statement* stmt = myConn -> createStatement();
36 
37  std::string query = (" SELECT C.VERSION, ");
38  query += " H.SIDE, H.ETA, H.PHI, ";
39  query += " H.DELTA_PHI, H.DEPTH, H.SUBDETECTOR, H.RBX, H.WEDGE, ";
40  query += " H.SECTOR, H.RM_SLOT, H.HPD_PIXEL, H.QIE_SLOT, H.ADC, ";
41  query += " H.RM_FIBER, H.FIBER_CHANNEL, H.LETTER_CODE, H.CRATE, H.HTR_SLOT, ";
42  query += " H.HTR_FPGA, H.HTR_FIBER, H.DCC_SL, H.SPIGOT, H.DCC_SLOT, ";
43  query += " H.SLB_SITE, H.SLB_CHANNEL, H.SLB_CHANNEL2, H.SLB_CABLE, H.RCT_CRATE, ";
44  query += " H.RCT_CARD, H.RCT_CONNECTOR, H.RCT_NAME, H.FED_ID ";
45  query += " FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 H inner join ";
46  query += " CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS C ";
47  query += " on C.CONDITION_DATA_SET_ID=H.CONDITION_DATA_SET_ID ";
48  query += " inner join CMS_HCL_CORE_CONDITION_OWNER.KINDS_OF_CONDITIONS K ";
49  query += " on K.KIND_OF_CONDITION_ID=C.KIND_OF_CONDITION_ID ";
50  query += " where C.IS_RECORD_DELETED='F' and K.IS_RECORD_DELETED='F' ";
51  query += " and K.NAME='HCAL hardware logical channel maps v3' ";
52  query += " and C.VERSION=";
53  query += verstring;
54 
55  //SELECT
56  ResultSet *rs = stmt->executeQuery(query.c_str());
57 
58  while (rs->next() && CHAcount < 10000) {
59 
60  lmapHBEFO -> versionC . push_back( rs -> getInt(1) );
61  lmapHBEFO -> sideC . push_back( rs -> getInt(2) );
62  lmapHBEFO -> etaC . push_back( rs -> getInt(3) );
63  lmapHBEFO -> phiC . push_back( rs -> getInt(4) );
64  lmapHBEFO -> dphiC . push_back( rs -> getInt(5) );
65 
66  lmapHBEFO -> depthC . push_back( rs -> getInt(6) );
67  lmapHBEFO -> detC . push_back( rs -> getString(7) );
68  lmapHBEFO -> rbxC . push_back( rs -> getString(8) );
69  lmapHBEFO -> wedgeC . push_back( rs -> getInt(9) );
70  lmapHBEFO -> sectorC . push_back( rs -> getInt(10) );
71 
72  lmapHBEFO -> rmC . push_back( rs -> getInt(11) );
73  lmapHBEFO -> pixelC . push_back( rs -> getInt(12) );
74  lmapHBEFO -> qieC . push_back( rs -> getInt(13) );
75  lmapHBEFO -> adcC . push_back( rs -> getInt(14) );
76  lmapHBEFO -> rm_fiC . push_back( rs -> getInt(15) );
77 
78  lmapHBEFO -> fi_chC . push_back( rs -> getInt(16) );
79  lmapHBEFO -> let_codeC . push_back( rs -> getString(17) );
80  lmapHBEFO -> crateC . push_back( rs -> getInt(18) );
81  lmapHBEFO -> htrC . push_back( rs -> getInt(19) );
82  lmapHBEFO -> fpgaC . push_back( rs -> getString(20) );
83 
84  lmapHBEFO -> htr_fiC . push_back( rs -> getInt(21) );
85  lmapHBEFO -> dcc_slC . push_back( rs -> getInt(22) );
86  lmapHBEFO -> spigoC . push_back( rs -> getInt(23) );
87  lmapHBEFO -> dccC . push_back( rs -> getInt(24) );
88  lmapHBEFO -> slbC . push_back( rs -> getInt(25) );
89 
90  lmapHBEFO -> slbinC . push_back( rs -> getString(26) );
91  lmapHBEFO -> slbin2C . push_back( rs -> getString(27) );
92  lmapHBEFO -> slnamC . push_back( rs -> getString(28) );
93  lmapHBEFO -> rctcraC . push_back( rs -> getInt(29) );
94  lmapHBEFO -> rctcarC . push_back( rs -> getInt(30) );
95 
96  lmapHBEFO -> rctconC . push_back( rs -> getInt(31) );
97  lmapHBEFO -> rctnamC . push_back( rs -> getString(32) );
98  lmapHBEFO -> fedidC . push_back( rs -> getInt(33) );
99 
100  lmapHBEFO -> orderC . push_back( CHAcount );
101 
102  CHAcount++;
103  }
104  //Always terminate statement
105  myConn -> terminateStatement(stmt);
106  }
107  catch (SQLException& e) {
108  std::cout<<"Couldn't get statement"<<std::endl;
109  }
110  db -> disconnect();
111 
112  return lmapHBEFO;
113 }
114 
115 void DBlmapReader::PrintLMAP(FILE* HBEFmap, FILE* HOmap, VectorLMAP* lmapHBEFO){
116 
117  int CHAcount = lmapHBEFO->orderC.size();
118 
119  lmapHBEFO = SortByHardware(lmapHBEFO);
120  for (i = 0; i < CHAcount; i++){
121  if (lmapHBEFO -> orderC[i] >= CHAcount){
122  std::cout<<"Bad order vector";
123  break;
124  }
125 
126  if (lmapHBEFO -> detC[lmapHBEFO -> orderC[i]] != "HO") printHBHEHF(i, HBEFmap, lmapHBEFO);
127  }
128 
129  lmapHBEFO = SortByGeometry(lmapHBEFO);
130  for (i = 0; i < CHAcount; i++){
131  if (lmapHBEFO -> orderC[i] >= CHAcount){
132  std::cout<<"Bad order vector";
133  break;
134  }
135  if (lmapHBEFO -> detC[lmapHBEFO -> orderC[i]] == "HO") printHO(i, HOmap, lmapHBEFO);
136  }
137 
138  std::cout<<CHAcount<<std::endl;
139  return;
140 }
141 
142 void DBlmapReader::PrintEMAPfromLMAP(FILE* emap, VectorLMAP* lmapHBEFO){
143 
144  int CHAcount = lmapHBEFO->orderC.size();
145 
146  lmapHBEFO = SortByHardware(lmapHBEFO);
147  for (i = 0; i < CHAcount; i++){
148  if (lmapHBEFO ->detC[lmapHBEFO -> orderC[i]] != "HO") printEMAProw(i, emap, lmapHBEFO);
149  }
150 
151  lmapHBEFO = SortByGeometry(lmapHBEFO);
152  for (i = 0; i < CHAcount; i++){
153  if (lmapHBEFO -> detC[lmapHBEFO -> orderC[i]] == "HO") printEMAProw(i, emap, lmapHBEFO);
154  }
155 
156  return;
157 }
158 
159 
160 void printHBHEHF(int channel, FILE * HBEFmap, VectorLMAP * lmap){
161 
162  if (channel % 21 == 0){
163  fprintf(HBEFmap,"# side eta phi dphi depth det rbx wedge rm pixel qie adc");
164  fprintf(HBEFmap," rm_fi fi_ch crate htr fpga htr_fi dcc_sl spigo dcc slb slbin slbin2");
165  fprintf(HBEFmap," slnam rctcra rctcar rctcon rctnam fedid\n");
166  }
167 
168  j = lmap -> orderC[channel];
169 
170  fprintf(HBEFmap,"%6d %6d %6d %6d %6d ", lmap->sideC[j], lmap->etaC[j], lmap->phiC[j], lmap->dphiC[j], lmap -> depthC[j]);
171  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]);
172  fprintf(HBEFmap,"%6d %6d %6d %6d %6d ", lmap->qieC[j], lmap->adcC[j], lmap->rm_fiC[j], lmap->fi_chC[j], lmap->crateC[j]);
173  fprintf(HBEFmap,"%6d %6s%8d %7d ", lmap->htrC[j], lmap->fpgaC[j].c_str(), lmap->htr_fiC[j], lmap->dcc_slC[j]);
174  fprintf(HBEFmap,"%6d %6d %6d %6s", lmap->spigoC[j], lmap->dccC[j], lmap->slbC[j], lmap->slbinC[j].c_str());
175  fprintf(HBEFmap,"%8s %15s %6d %6d ", lmap->slbin2C[j].c_str(), lmap->slnamC[j].c_str(), lmap->rctcraC[j], lmap->rctcarC[j]);
176  fprintf(HBEFmap,"%6d %20s %6d\n", lmap->rctconC[j], lmap->rctnamC[j].c_str(), lmap->fedidC[j]);
177 }
178 
179 void printHO(int channel, FILE * HOmap, VectorLMAP * lmap){
180  //HO goes last, after 6912 entries; 6912 % 21 = 3
181  if (channel % 21 == 3){
182  fprintf(HOmap,"# side eta phi dphi depth det rbx sector rm pixel qie adc");
183  fprintf(HOmap," rm_fi fi_ch let_code crate htr fpga htr_fi dcc_sl spigo dcc slb slbin slbin2");
184  fprintf(HOmap," slnam rctcra rctcar rctcon rctnam fedid\n");
185  }
186 
187  j = lmap -> orderC[channel];
188 
189  fprintf(HOmap,"%6d %6d %6d %6d %6d ", lmap->sideC[j], lmap->etaC[j], lmap->phiC[j], lmap->dphiC[j], lmap -> depthC[j]);
190  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]);
191  fprintf(HOmap,"%6d %6d %6d ", lmap->qieC[j], lmap->adcC[j], lmap->rm_fiC[j]);
192  fprintf(HOmap,"%6d %8s %6d ", lmap->fi_chC[j], lmap->let_codeC[j].c_str(), lmap->crateC[j]);
193  fprintf(HOmap,"%6d %6s%8d %7d ", lmap->htrC[j], lmap->fpgaC[j].c_str(), lmap->htr_fiC[j], lmap->dcc_slC[j]);
194  fprintf(HOmap,"%6d %6d %6d\n", lmap->spigoC[j], lmap->dccC[j], lmap->fedidC[j]);
195 
196 
197  // New Format (will update as soon as database update is complete
198 
199 // fprintf(HOmap,"# side eta phi dphi depth det rbx sector rm pixel qie adc");
200 // fprintf(HOmap," rm_fi fi_ch let_code crate htr fpga htr_fi dcc_sl spigo dcc fedid geo block lc\n");
201 // fprintf(HOmap,"%6d %6d %6d %6d %6d %6s %7s %6d %6d %6d",iside,ieta,iphi,idphi,idepth,det.c_str(),rbx.c_str(),isector,irm,ipixel);
202 // fprintf(HOmap,"%6d %6d %6d %6d %8s %6d %6d %6s",iqie,iadc,irm_fi,ifi_ch,letter.c_str(),icrate,ihtr,fpga.c_str());
203 // fprintf(HOmap,"%8d %7d %6d %6d %6d %6d %6d %6d\n",ihtr_fi,idcc_sl,ispigot,idcc,ifed,geo,block,lc);
204 
205 }
206 
207 void printEMAProw(int channel, FILE * emap, VectorLMAP * lmap){
208  j = lmap -> orderC[channel];
209 
210  HcalSubdetector _subdet;
211  if ( lmap->detC[j] == "HB" ) _subdet = HcalBarrel;
212  else if ( lmap->detC[j] == "HE" ) _subdet = HcalEndcap;
213  else if ( lmap->detC[j] == "HO" ) _subdet = HcalOuter;
214  else if ( lmap->detC[j] == "HF" ) _subdet = HcalForward;
215  else{
216  _subdet = HcalBarrel;
217  std::cerr<<"Bad Subdet"<<std::endl;
218  }
219  HcalDetId _hcaldetid( _subdet, (lmap->sideC[j])*(lmap->etaC[j]), lmap->phiC[j], lmap->depthC[j] );
220  int hcalID = _hcaldetid . rawId();
221 
222  char tb = lmap->fpgaC[j][0];
223  fprintf(emap,"%10d %3d %3d %2c %4d %5d",hcalID, lmap->crateC[j], lmap->htrC[j], tb, (lmap->fedidC[j] - 700), lmap->spigoC[j]);
224  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]);
225 
226  return;
227 }
228 
229 bool SortComp(int x, int y){
230  return tempVector[x] < tempVector[y];
231 }
232 
234 
235  int CHAcount = lmapHBEFO->orderC.size();
236  tempVector.clear();
237 
238  //Sort by fiber channel
239  for (i = 0; i < CHAcount; i++){
240  tempVector.push_back (lmapHBEFO -> fi_chC[i]);
241  }
242  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
243  tempVector.clear();
244 
245  //Sort by HTR fiber
246  for (i = 0; i < CHAcount; i++){
247  tempVector.push_back (lmapHBEFO -> htr_fiC[i]);
248  }
249  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
250  tempVector.clear();
251 
252  //Sort by FPGA
253  for (i = 0; i < CHAcount; i++){
254  if (lmapHBEFO -> fpgaC[i] == "top") tempVector.push_back (0);
255  else tempVector.push_back (1);
256  }
257  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
258  tempVector.clear();
259 
260  //Sort by HTR
261  for (i = 0; i < CHAcount; i++){
262  tempVector.push_back (lmapHBEFO -> htrC[i]);
263  }
264  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
265  tempVector.clear();
266 
267  //Sort by crate
268  for (i = 0; i < CHAcount; i++){
269  tempVector.push_back (lmapHBEFO -> crateC[i]);
270  }
271  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
272  tempVector.clear();
273 
274  //Sort by subdetector
275  for (i = 0; i < CHAcount; i++){
276  if (lmapHBEFO -> detC[i] == "HB" || lmapHBEFO -> detC[i] == "HE") tempVector.push_back (0);
277  else if (lmapHBEFO -> detC[i] == "HF") tempVector.push_back (1);
278  else tempVector.push_back (2);
279  }
280  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
281  tempVector.clear();
282 
283  return lmapHBEFO;
284 }
285 
287 
288  int CHAcount = lmapHBEFO->orderC.size();
289  tempVector.clear();
290 
291  //Sort by eta
292  for (i = 0; i < CHAcount; i++){
293  tempVector.push_back (lmapHBEFO -> etaC[i]);
294  }
295  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
296  tempVector.clear();
297 
298  //Sort by phi
299  for (i = 0; i < CHAcount; i++){
300  tempVector.push_back (lmapHBEFO -> phiC[i]);
301  }
302  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
303  tempVector.clear();
304 
305  //Sort by side
306  for (i = 0; i < CHAcount; i++){
307  tempVector.push_back (lmapHBEFO -> sideC[i]);
308  }
309  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
310  tempVector.clear();
311 
312  //Sort by subdetector
313  for (i = 0; i < CHAcount; i++){
314  if (lmapHBEFO -> detC[i] == "HB" || lmapHBEFO -> detC[i] == "HE") tempVector.push_back (0);
315  else if (lmapHBEFO -> detC[i] == "HF") tempVector.push_back (1);
316  else tempVector.push_back (2);
317  }
318  stable_sort(lmapHBEFO -> orderC.begin( ), lmapHBEFO -> orderC.end( ), SortComp);
319  tempVector.clear();
320 
321  return lmapHBEFO;
322 }
323 
VectorLMAP * SortByGeometry(VectorLMAP *lmapHBEFO)
std::vector< int > sectorC
Definition: DBlmapReader.h:35
int i
Definition: DBlmapReader.cc:9
void PrintEMAPfromLMAP(FILE *emap, VectorLMAP *lmapHBEFO)
void printEMAProw(int channel, FILE *emap, VectorLMAP *lmap)
std::vector< int > spigoC
Definition: DBlmapReader.h:50
std::vector< int > etaC
Definition: DBlmapReader.h:26
tuple db
Definition: EcalCondDB.py:151
std::vector< int > wedgeC
Definition: DBlmapReader.h:33
int getInt(ResultSet *rset, int ipar)
void printHO(int channel, FILE *HOmap, VectorLMAP *lmap)
void printHBHEHF(int channel, FILE *HBEFmap, VectorLMAP *lmap)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
std::vector< int > slbC
Definition: DBlmapReader.h:53
std::vector< int > orderC
Definition: DBlmapReader.h:68
std::vector< int > fedidC
Definition: DBlmapReader.h:62
VectorLMAP * GetLMAP(int version)
Definition: DBlmapReader.cc:19
std::vector< int > crateC
Definition: DBlmapReader.h:44
std::vector< int > pixelC
Definition: DBlmapReader.h:37
std::vector< int > rmC
Definition: DBlmapReader.h:36
std::vector< int > htr_fiC
Definition: DBlmapReader.h:48
std::vector< std::string > rctnamC
Definition: DBlmapReader.h:61
bool SortComp(int x, int y)
void PrintLMAP(FILE *HBEFmap, FILE *HOmap, VectorLMAP *lmapHBEFO)
std::vector< std::string > slbinC
Definition: DBlmapReader.h:54
HcalSubdetector
Definition: HcalAssistant.h:32
int j
Definition: DBlmapReader.cc:9
std::vector< int > sideC
Definition: DBlmapReader.h:25
std::vector< std::string > let_codeC
Definition: DBlmapReader.h:43
std::vector< std::string > rbxC
Definition: DBlmapReader.h:32
std::vector< int > qieC
Definition: DBlmapReader.h:38
std::vector< int > depthC
Definition: DBlmapReader.h:30
VectorLMAP * SortByHardware(VectorLMAP *lmapHBEFO)
std::vector< int > rm_fiC
Definition: DBlmapReader.h:41
Gather config data from online DB.
Definition: HCALConfigDB.h:21
std::vector< std::string > fpgaC
Definition: DBlmapReader.h:47
std::vector< int > dccC
Definition: DBlmapReader.h:51
std::vector< int > rctcraC
Definition: DBlmapReader.h:57
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
void lrTestFunction(void)
Definition: DBlmapReader.cc:13
std::vector< int > rctcarC
Definition: DBlmapReader.h:59
std::vector< int > dphiC
Definition: DBlmapReader.h:29
std::vector< int > phiC
Definition: DBlmapReader.h:27
std::vector< int > htrC
Definition: DBlmapReader.h:45
tuple query
Definition: o2o.py:269
std::vector< int > rctconC
Definition: DBlmapReader.h:60
tuple cout
Definition: gather_cfg.py:121
std::vector< std::string > detC
Definition: DBlmapReader.h:31
x
Definition: VDTMath.h:216
std::vector< int > dcc_slC
Definition: DBlmapReader.h:49
std::vector< std::string > slnamC
Definition: DBlmapReader.h:56
vector< int > tempVector
Definition: DBlmapReader.cc:10
std::vector< std::string > slbin2C
Definition: DBlmapReader.h:55
stringstream sstemp
Definition: DBlmapReader.cc:11
std::vector< int > adcC
Definition: DBlmapReader.h:39
std::vector< int > fi_chC
Definition: DBlmapReader.h:42