test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDbOmds.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Original Author: Gena Kukartsev Mar 11, 2009
4 // Adapted from HcalDbASCIIIO.cc,v 1.41
5 //
6 #include <vector>
7 #include <string>
8 
14 
19 
20 #ifdef HAVE_XDAQ
21 #include "toolbox/string.h"
22 #else
23 #include "CaloOnlineTools/HcalOnlineDb/interface/xdaq_compat.h" // Replaces toolbox::toString
24 #endif
25 
28 
29 template<class T>
30 bool HcalDbOmds::from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
31  std::istringstream iss(s);
32  return !(iss >> f >> t).fail();
33 }
34 
35 // get the proper detId from the result of the oracle query
36 // assumed that channel info comes in from of the ResultSet
37 // in the following order (some may not be filled):
38 // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
39 // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
41  std::string _name = rs->getString(1);
42  //std::cerr << "DEBUG: name - " << _name << std::endl;
43  if (rs->getString(1).find("HcalDetId")!=std::string::npos){
44  //std::cerr << "DEBUG: HcalDetId" << std::endl;
45  return HcalDetId(get_subdetector(rs->getString(2)),
46  rs->getInt(3),
47  rs->getInt(4),
48  rs->getInt(5));
49  }
50  else if (rs->getString(1).find("HcalCalibDetId")!=std::string::npos){
51  //std::cerr << "DEBUG: HcalCalibDetId" << std::endl;
52  return HcalCalibDetId(get_subdetector(rs->getString(2)),
53  rs->getInt(3),
54  rs->getInt(4),
55  rs->getInt(6));
56  }
57  else if (rs->getString(1).find("HcalTrigTowerDetId")!=std::string::npos){
58  //std::cerr << "DEBUG: HcalTrigTowerDetId" << std::endl;
59  return HcalTrigTowerDetId(rs->getInt(3),
60  rs->getInt(4));
61  }
62  else if (rs->getString(1).find("HcalZDCDetId")!=std::string::npos){
63  //std::cerr << "DEBUG: HcalZDCDetId" << std::endl;
64  return HcalZDCDetId(get_zdc_section(rs->getString(7)),
65  rs->getInt(8)>0,
66  rs->getInt(11));
67  }
68  else if (rs->getString(1).find("HcalCastorDetId")!=std::string::npos){
69  //std::cerr << "DEBUG: HcalCastorDetId" << std::endl;
70  return HcalCastorDetId(rs->getInt(8)>0,
71  rs->getInt(9)>0,
72  rs->getInt(10));
73  }
74  else return 0;
75 }
76 
77 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
78  const std::string & fTag,
79  const std::string & fVersion,
80  const int fSubversion,
81  const int fIOVBegin,
82  const std::string & fQuery,
83  HcalPedestals* fObject) {
84  bool result=true;
85  if (!fObject) return false; // fObject = new HcalPedestals;
86  int _unit=0;
87  try {
88  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
89  stmt->setString(1,fTag);
90  //stmt->setString(2,fVersion);
91  stmt->setInt(2,fIOVBegin);
92 
93  ResultSet *rs = stmt->executeQuery();
94 
95  // protection agains NULL values
96  for (int _i=1; _i!=12; _i++) rs->setMaxColumnSize(_i,128);
97 
98  RooGKCounter _row(1,100);
99  _row.setMessage("HCAL channels processed: ");
100  _row.setPrintCount(true);
101  _row.setNewLine(true);
102  //
103  // The query result must be ordered in the following way
104  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
105  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
106  // 12. is_adc_counts, 13-16. cap0-3, 17-20. variance0-3
107  //
108  while (rs->next()) {
109  _row.count();
110  DetId id = getId(rs);
111  _unit = rs->getInt(12);
112  float cap0 = rs->getFloat(13);
113  float cap1 = rs->getFloat(14);
114  float cap2 = rs->getFloat(15);
115  float cap3 = rs->getFloat(16);
116  float variance0 = rs->getFloat(17);
117  float variance1 = rs->getFloat(18);
118  float variance2 = rs->getFloat(19);
119  float variance3 = rs->getFloat(20);
120  //int ieta = rs->getInt(21);
121  //int iphi = rs->getInt(22);
122  //int depth = rs->getInt(23);
123  //HcalSubdetector subdetector = get_subdetector(rs->getString(24));
124  //HcalDetId id(subdetector,ieta,iphi,depth);
125  std::cout << "DEBUG: " << std::endl;
126  //std::cout << "DEBUG: " << id << " " << cap0 << " " << cap1 << " " << cap2 << " " << cap3 << std::endl;
127  HcalPedestal * fCondObject = new HcalPedestal(id.rawId(), cap0, cap1, cap2, cap3, variance0, variance1, variance2, variance3);
128  fObject->addValues(*fCondObject);
129  delete fCondObject;
130  }
131  //Always terminate statement
132  connection->terminateStatement(stmt);
133  } catch (SQLException& e) {
134  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
135  }
136  bool unit_is_adc = false;
137  if (_unit!=0) unit_is_adc = true;
138  fObject->setUnitADC(unit_is_adc);
139  return result;
140 }
141 
142 
143 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
144  const std::string & fTag,
145  const std::string & fVersion,
146  const int fSubversion,
147  const int fIOVBegin,
148  const std::string & fQuery,
149  HcalPedestalWidths* fObject) {
150  bool result=true;
151  if (!fObject) return false; //fObject = new HcalPedestalWidths;
152  int _unit=0;
153  try {
154  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
155  stmt->setString(1,fTag);
156  stmt->setInt(2,fIOVBegin);
157 
158  ResultSet *rs = stmt->executeQuery();
159 
160  rs->setMaxColumnSize(1,128);
161  rs->setMaxColumnSize(2,128);
162  rs->setMaxColumnSize(3,128);
163  rs->setMaxColumnSize(4,128);
164  rs->setMaxColumnSize(5,128);
165  rs->setMaxColumnSize(6,128);
166  rs->setMaxColumnSize(7,128);
167  rs->setMaxColumnSize(8,128);
168  rs->setMaxColumnSize(9,128);
169  rs->setMaxColumnSize(10,128);
170  rs->setMaxColumnSize(11,128);
171 
172  RooGKCounter _row(1,100);
173  _row.setMessage("HCAL channels processed: ");
174  _row.setPrintCount(true);
175  _row.setNewLine(true);
176  //
177  // The query result must be ordered in the following way
178  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
179  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
180  // 12. is_ADC(int), 13-28. covariance00-01-...-10-11-...33
181  //
182  while (rs->next()) {
183  _row.count();
184  DetId id = getId(rs);
185  _unit = rs->getInt(12);
186  float covariance_00 = rs->getFloat(13);
187  float covariance_01 = rs->getFloat(14);
188  float covariance_02 = rs->getFloat(15);
189  float covariance_03 = rs->getFloat(16);
190  float covariance_10 = rs->getFloat(17);
191  float covariance_11 = rs->getFloat(18);
192  float covariance_12 = rs->getFloat(19);
193  float covariance_13 = rs->getFloat(20);
194  float covariance_20 = rs->getFloat(21);
195  float covariance_21 = rs->getFloat(22);
196  float covariance_22 = rs->getFloat(23);
197  float covariance_23 = rs->getFloat(24);
198  float covariance_30 = rs->getFloat(25);
199  float covariance_31 = rs->getFloat(26);
200  float covariance_32 = rs->getFloat(27);
201  float covariance_33 = rs->getFloat(28);
202  HcalPedestalWidth * fCondObject = new HcalPedestalWidth(id);
203  fCondObject->setSigma(0,0,covariance_00);
204  fCondObject->setSigma(0,1,covariance_01);
205  fCondObject->setSigma(0,2,covariance_02);
206  fCondObject->setSigma(0,3,covariance_03);
207  fCondObject->setSigma(1,0,covariance_10);
208  fCondObject->setSigma(1,1,covariance_11);
209  fCondObject->setSigma(1,2,covariance_12);
210  fCondObject->setSigma(1,3,covariance_13);
211  fCondObject->setSigma(2,0,covariance_20);
212  fCondObject->setSigma(2,1,covariance_21);
213  fCondObject->setSigma(2,2,covariance_22);
214  fCondObject->setSigma(2,3,covariance_23);
215  fCondObject->setSigma(3,0,covariance_30);
216  fCondObject->setSigma(3,1,covariance_31);
217  fCondObject->setSigma(3,2,covariance_32);
218  fCondObject->setSigma(3,3,covariance_33);
219  fObject->addValues(*fCondObject);
220  delete fCondObject;
221  }
222  //Always terminate statement
223  connection->terminateStatement(stmt);
224  } catch (SQLException& e) {
225  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
226  }
227  bool unit_is_adc = false;
228  if (_unit!=0) unit_is_adc = true;
229  fObject->setUnitADC(unit_is_adc);
230  return result;
231 }
232 
233 
234 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
235  const std::string & fTag,
236  const std::string & fVersion,
237  const int fSubversion,
238  const int fIOVBegin,
239  const std::string & fQuery,
240  HcalGains* fObject) {
241  bool result=true;
242  if (!fObject) return false; //fObject = new HcalGains;
243  try {
244  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
245  stmt->setString(1,fTag);
246  stmt->setInt(2,fIOVBegin);
247 
248  ResultSet *rs = stmt->executeQuery();
249 
250  // protection agains NULL values
251  for (int _i=1; _i!=12; _i++) rs->setMaxColumnSize(_i,128);
252 
253  RooGKCounter _row(1,100);
254  _row.setMessage("HCAL channels processed: ");
255  _row.setPrintCount(true);
256  _row.setNewLine(true);
257  //
258  // The query result must be ordered in the following way
259  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
260  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
261  // 12-15. cap0-3
262  //
263  while (rs->next()) {
264  _row.count();
265  DetId id = getId(rs);
266  float cap0 = rs->getFloat(12);
267  float cap1 = rs->getFloat(13);
268  float cap2 = rs->getFloat(14);
269  float cap3 = rs->getFloat(15);
270  //int ieta = rs->getInt(5);
271  //int iphi = rs->getInt(6);
272  //int depth = rs->getInt(7);
273  //HcalSubdetector subdetector = get_subdetector(rs->getString(8));
274  //HcalDetId id(subdetector,ieta,iphi,depth);
275  //std::cout << "DEBUG: " << id << " " << cap0 << " " << cap1 << " " << cap2 << " " << cap3 << std::endl;
276  HcalGain * fCondObject = new HcalGain(id, cap0, cap1, cap2, cap3);
277  fObject->addValues(*fCondObject);
278  delete fCondObject;
279  }
280  //Always terminate statement
281  connection->terminateStatement(stmt);
282  } catch (SQLException& e) {
283  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
284  }
285  return result;
286 }
287 
288 
289 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
290  const std::string & fTag,
291  const std::string & fVersion,
292  const int fSubversion,
293  const int fIOVBegin,
294  const std::string & fQuery,
295  HcalGainWidths* fObject) {
296  bool result=true;
297  if (!fObject) return false; //fObject = new HcalGainWidths;
298  try {
299  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
300  stmt->setString(1,fTag);
301  stmt->setInt(2,fIOVBegin);
302 
303  ResultSet *rs = stmt->executeQuery();
304 
305  // protection agains NULL values
306  for (int _i=1; _i!=12; _i++) rs->setMaxColumnSize(_i,128);
307 
308  RooGKCounter _row(1,100);
309  _row.setMessage("HCAL channels processed: ");
310  _row.setPrintCount(true);
311  _row.setNewLine(true);
312  //
313  // The query result must be ordered in the following way
314  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
315  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
316  // 12-15. cap0-3
317  //
318  while (rs->next()) {
319  _row.count();
320  DetId id = getId(rs);
321  float cap0 = rs->getFloat(12);
322  float cap1 = rs->getFloat(13);
323  float cap2 = rs->getFloat(14);
324  float cap3 = rs->getFloat(15);
325  //int ieta = rs->getInt(5);
326  //int iphi = rs->getInt(6);
327  //int depth = rs->getInt(7);
328  //HcalSubdetector subdetector = get_subdetector(rs->getString(8));
329  //HcalDetId id(subdetector,ieta,iphi,depth);
330  //std::cout << "DEBUG: " << id << " " << cap0 << " " << cap1 << " " << cap2 << " " << cap3 << std::endl;
331  HcalGainWidth * fCondObject = new HcalGainWidth(id, cap0, cap1, cap2, cap3);
332  fObject->addValues(*fCondObject);
333  delete fCondObject;
334  }
335  //Always terminate statement
336  connection->terminateStatement(stmt);
337  } catch (SQLException& e) {
338  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
339  }
340  return result;
341 }
342 
343 
344 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
345  const std::string & fTag,
346  const std::string & fVersion,
347  const int fSubversion,
348  const int fIOVBegin,
349  const std::string & fQuery,
350  HcalQIEData* fObject) {
351  bool result=true;
352  if (!fObject) return false; //fObject = new HcalQIEData;
353  try {
354  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
355  stmt->setString(1,fTag);
356  stmt->setInt(2,fIOVBegin);
357 
358  ResultSet *rs = stmt->executeQuery();
359 
360  rs->setMaxColumnSize(1,128);
361  rs->setMaxColumnSize(2,128);
362  rs->setMaxColumnSize(3,128);
363  rs->setMaxColumnSize(4,128);
364  rs->setMaxColumnSize(5,128);
365  rs->setMaxColumnSize(6,128);
366  rs->setMaxColumnSize(7,128);
367  rs->setMaxColumnSize(8,128);
368  rs->setMaxColumnSize(9,128);
369  rs->setMaxColumnSize(10,128);
370  rs->setMaxColumnSize(11,128);
371 
372  RooGKCounter _row(1,100);
373  _row.setMessage("HCAL channels processed: ");
374  _row.setPrintCount(true);
375  _row.setNewLine(true);
376  //
377  // The query result must be ordered in the following way
378  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
379  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
380  // 13-27. cap0_range0_slope, cap0_range1_slope... 33, 28-43. cap0_range0_offset, cap0_range1_offset...
381  //
382  while (rs->next()) {
383  _row.count();
384  DetId id = getId(rs);
385  fObject->sort();
386  float items[32];
387  for (int _i=0; _i!=32; _i++) items[_i] = rs->getFloat(_i+12);
388  HcalQIECoder * fCondObject = new HcalQIECoder(id.rawId());
389  for (unsigned capid = 0; capid < 4; capid++) {
390  for (unsigned range = 0; range < 4; range++) {
391  fCondObject->setSlope (capid, range, items[capid*4+range]);
392  }
393  }
394  for (unsigned capid = 0; capid < 4; capid++) {
395  for (unsigned range = 0; range < 4; range++) {
396  fCondObject->setOffset (capid, range, items[16+capid*4+range]);
397  }
398  }
399  fObject->addCoder(*fCondObject);
400  delete fCondObject;
401  }
402  //Always terminate statement
403  connection->terminateStatement(stmt);
404  } catch (SQLException& e) {
405  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
406  }
407  return result;
408 }
409 
410 
411 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
412  const std::string & fTag,
413  const std::string & fVersion,
414  const int fSubversion,
415  const int fIOVBegin,
416  const std::string & fQuery,
417  HcalCalibrationQIEData* fObject) {
418  std::cerr << "NOT IMPLEMENTED!" << std::endl;
419  return false;
420 }
421 
422 
423 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
424  const std::string & fTag,
425  const std::string & fVersion,
426  const int fSubversion,
427  const int fIOVBegin,
428  const std::string & fQuery,
429  HcalElectronicsMap* fObject) {
430  bool result=true;
431  if (!fObject) return false; //fObject = new HcalElectronicsMap;
432  try {
433  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
434  stmt->setString(1,fTag);
435  stmt->setInt(2,fIOVBegin);
436 
437  ResultSet *rs = stmt->executeQuery();
438 
439  // protection agains NULL values
440  for (int _i=1; _i!=20; _i++) rs->setMaxColumnSize(_i,128);
441 
442  RooGKCounter _row(1,100);
443  _row.setMessage("HCAL channels processed: ");
444  _row.setPrintCount(true);
445  _row.setNewLine(true);
446  //
447  // The query result must be ordered in the following way
448  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
449  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
450  // 12. i, 13. crate, 14. slot, 15. tb, 16. dcc, 17. spigot, 18. fiber(slb), 19. fiberchan(slbchan)
451  //
452  while (rs->next()) {
453  _row.count();
454  DetId id = getId(rs);
455  std::string _obj_name = rs->getString(1);
456  int crate = rs->getInt(13);
457  int slot = rs->getInt(14);
458  int dcc = rs->getInt(16);
459  int spigot = rs->getInt(17);
460  std::string tb = rs->getString(15);
461  int top = 1;
462  if (tb.find("b")!=std::string::npos) top = 0;
463  HcalElectronicsId * fCondObject = 0;
464  if (_obj_name.find("HcalTrigTowerDetId")!=std::string::npos){
465  int slbCh = rs->getInt(19);
466  int slb = rs->getInt(18);
467  fCondObject = new HcalElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
468  }
469  else{
470  int fiberCh = rs->getInt(19);
471  int fiber = rs->getInt(18);
472  fCondObject = new HcalElectronicsId(fiberCh, fiber, spigot, dcc);
473  fCondObject->setHTR(crate,slot,top);
474  }
475  if (_obj_name.find("HcalTrigTowerDetId")!=std::string::npos){
476  fObject->mapEId2tId(*fCondObject, id);
477  }
478  else if (_obj_name.find("HcalDetId")!=std::string::npos ||
479  _obj_name.find("HcalCalibDetId")!=std::string::npos ||
480  _obj_name.find("HcalZDCDetId")!=std::string::npos){
481  fObject->mapEId2chId(*fCondObject, id);
482  }
483  else {
484  edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: "
485  << _obj_name << std::endl;
486  }
487  delete fCondObject;
488  }
489  //Always terminate statement
490  connection->terminateStatement(stmt);
491  } catch (SQLException& e) {
492  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
493  }
494  fObject->sort ();
495  return result;
496 }
497 
498 
499 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
500  const std::string & fTag,
501  const std::string & fVersion,
502  const int fSubversion,
503  const int fIOVBegin,
504  const std::string & fQuery,
505  HcalChannelQuality* fObject) {
506  std::cout << " +++++=====> HcalDbOmds::getObject" << std::endl;
507 
508  bool result=true;
509  if (!fObject) return false; //fObject = new HcalChannelQuality;
510  try {
511  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
512  stmt->setString(1,fTag);
513  stmt->setInt(2,fIOVBegin);
514 
515  ResultSet *rs = stmt->executeQuery();
516 
517  // protection agains NULL values
518  for (int _i=1; _i!=12; _i++) rs->setMaxColumnSize(_i,128);
519 
520  RooGKCounter _row(1,100);
521  _row.setMessage("HCAL channels processed: ");
522  _row.setPrintCount(true);
523  _row.setNewLine(true);
524  //
525  // The query result must be ordered in the following way
526  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
527  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel_on_off_state
528  // 12. channel_status_word
529  //
530  while (rs->next()) {
531  _row.count();
532  DetId id = getId(rs);
533  int value = rs->getInt(12);
534  //int ieta = rs->getInt(2);
535  //int iphi = rs->getInt(3);
536  //int depth = rs->getInt(4);
537  //HcalSubdetector subdetector = get_subdetector(rs->getString(5));
538  //HcalDetId id(subdetector,ieta,iphi,depth);
539  //std::cout << "DEBUG: " << std::endl;//<< id << " " << zs << std::endl;
540  HcalChannelStatus * fCondObject = new HcalChannelStatus(id, value);
541  fObject->addValues(*fCondObject);
542  delete fCondObject;
543  }
544  //Always terminate statement
545  connection->terminateStatement(stmt);
546  } catch (SQLException& e) {
547  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
548  }
549  return result;
550 }
551 
552 
553 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
554  const std::string & fTag,
555  const std::string & fVersion,
556  const int fSubversion,
557  const int fIOVBegin,
558  const std::string & fQuery,
559  HcalRespCorrs* fObject) {
560  bool result=true;
561  if (!fObject) return false; //fObject = new HcalRespCorrs;
562  try {
563  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
564  stmt->setString(1,fTag);
565  stmt->setInt(2,fIOVBegin);
566 
567  ResultSet *rs = stmt->executeQuery();
568 
569  // protection agains NULL values
570  for (int _i=1; _i!=12; _i++) rs->setMaxColumnSize(_i,128);
571 
572  RooGKCounter _row(1,100);
573  _row.setMessage("HCAL channels processed: ");
574  _row.setPrintCount(true);
575  _row.setNewLine(true);
576  //
577  // The query result must be ordered in the following way
578  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
579  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
580  // 12. value
581  //
582  while (rs->next()) {
583  _row.count();
584  DetId id = getId(rs);
585  float value = rs->getFloat(12);
586  //int ieta = rs->getInt(2);
587  //int iphi = rs->getInt(3);
588  //int depth = rs->getInt(4);
589  //HcalSubdetector subdetector = get_subdetector(rs->getString(5));
590  //HcalDetId id(subdetector,ieta,iphi,depth);
591  //std::cout << "DEBUG: " << id << " " << value << std::endl;
592  HcalRespCorr * fCondObject = new HcalRespCorr(id, value);
593  fObject->addValues(*fCondObject);
594  delete fCondObject;
595  }
596  //Always terminate statement
597  connection->terminateStatement(stmt);
598  } catch (SQLException& e) {
599  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
600  }
601  return result;
602 }
603 
604 // Oracle database connection ownership is transferred here, DO terminate after use
605 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
606  const std::string & fTag,
607  const std::string & fVersion,
608  const int fSubversion,
609  const int fIOVBegin,
610  const std::string & fQuery,
611  HcalZSThresholds* fObject) {
612  bool result=true;
613  if (!fObject) return false;// fObject = new HcalZSThresholds;
614  try {
615  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
616  stmt->setString(1,fTag);
617  stmt->setInt(2,fIOVBegin);
618 
619  ResultSet *rs = stmt->executeQuery();
620 
621  // protection agains NULL values
622  for (int _i=1; _i!=12; _i++) rs->setMaxColumnSize(_i,128);
623 
624  RooGKCounter _row(1,100);
625  _row.setMessage("HCAL channels processed: ");
626  _row.setPrintCount(true);
627  _row.setNewLine(true);
628  //
629  // The query result must be ordered in the following way
630  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
631  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
632  // 12. zs_threshold
633  //
634  while (rs->next()) {
635  _row.count();
636  DetId id = getId(rs);
637  int zs = rs->getInt(12);
638  //int ieta = rs->getInt(2);
639  //int iphi = rs->getInt(3);
640  //int depth = rs->getInt(4);
641  //HcalSubdetector subdetector = get_subdetector(rs->getString(5));
642  //HcalDetId id(subdetector,ieta,iphi,depth);
643  //std::cout << "DEBUG: " << id << " " << zs << std::endl;
644  HcalZSThreshold * fCondObject = new HcalZSThreshold(id, zs);
645  fObject->addValues(*fCondObject);
646  delete fCondObject;
647  }
648  //Always terminate statement
649  connection->terminateStatement(stmt);
650  } catch (SQLException& e) {
651  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
652  }
653  return result;
654 }
655 
656 
657 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
658  const std::string & fTag,
659  const std::string & fVersion,
660  const int fSubversion,
661  const int fIOVBegin,
662  const std::string & fQuery,
663  HcalL1TriggerObjects* fObject) {
664  bool result=true;
665  if (!fObject) return false; //fObject = new HcalL1TriggerObjects;
666  std::string _tag;
667  std::string _algo;
668  try {
669  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
670  stmt->setString(1,fTag);
671  stmt->setInt(2,fIOVBegin);
672 
673  ResultSet *rs = stmt->executeQuery();
674 
675  rs->setMaxColumnSize(1,128);
676  rs->setMaxColumnSize(2,128);
677  rs->setMaxColumnSize(3,128);
678  rs->setMaxColumnSize(4,128);
679  rs->setMaxColumnSize(5,128);
680  rs->setMaxColumnSize(6,128);
681  rs->setMaxColumnSize(7,128);
682  rs->setMaxColumnSize(8,128);
683  rs->setMaxColumnSize(9,128);
684  rs->setMaxColumnSize(10,128);
685  rs->setMaxColumnSize(11,128);
686 
687  RooGKCounter _row(1,100);
688  _row.setMessage("HCAL channels processed: ");
689  _row.setPrintCount(true);
690  _row.setNewLine(true);
691  //
692  // This is two queries in one joined by "UNION" (SQL), not ordered
693  // One of the queries returns global data: LUT tag name and algo name
694  // The global data is one raw, and it is ordered in the following way
695  // 1."fakeobjectname",
696  // 2."fakesubdetector", 3. -1, 4. -1, 5. -1, 6. -1, 7."fakesection", 8. -1, 9. -1, 10. -1, 11. -1
697  // 12. -999999.0, 13. -999999.0, 14. -999999,
698  // 15. TRIGGER_OBJECT_METADATA_NAME, 16. TRIGGER_OBJECT_METADATA_VALUE
699  //
700  // The channel query result must be ordered in the following way
701  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
702  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
703  // 12. AVERAGE_PEDESTAL, 13. RESPONSE_CORRECTED_GAIN, 14. FLAG,
704  // 15. 'fake_metadata_name', 16. 'fake_metadata_value'
705  //
706  while (rs->next()) {
707  _row.count();
708  DetId id = getId(rs);
709  float average_pedestal = rs->getFloat(12);
710  float response_corrected_gain = rs->getFloat(13);
711  int flag = rs->getInt(14);
712  std::string metadata_name = rs->getString(15);
713  if (metadata_name.find("lut_tag")!=std::string::npos){
714  _tag = rs->getString(16);
715  }
716  else if (metadata_name.find("algo_name")!=std::string::npos){
717  _algo = rs->getString(16);
718  }
719  HcalL1TriggerObject * fCondObject = new HcalL1TriggerObject(id, average_pedestal, response_corrected_gain, flag);
720  fObject->addValues(*fCondObject);
721  delete fCondObject;
722  }
723  //Always terminate statement
724  connection->terminateStatement(stmt);
725  } catch (SQLException& e) {
726  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
727  }
728  fObject->setTagString(_tag);
729  fObject->setAlgoString(_algo);
730  return result;
731 }
732 
733 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
734  const std::string & fTag,
735  const std::string & fVersion,
736  const int fSubversion,
737  const int fIOVBegin,
738  const std::string & fQuery,
739  HcalValidationCorrs* fObject) {
740  bool result=true;
741  if (!fObject) return false; //fObject = new HcalValidationCorrs;
742  try {
743  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
744  stmt->setString(1,fTag);
745  //stmt->setString(2,fVersion);
746  stmt->setInt(2,fIOVBegin);
747 
748  ResultSet *rs = stmt->executeQuery();
749 
750  // protection agains NULL values
751  for (int _i=1; _i!=12; _i++) rs->setMaxColumnSize(_i,128);
752 
753  RooGKCounter _row(1,100);
754  _row.setMessage("HCAL channels processed: ");
755  _row.setPrintCount(true);
756  _row.setNewLine(true);
757  //
758  // The query result must be ordered in the following way
759  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
760  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
761  // 12. value
762  //
763  while (rs->next()) {
764  _row.count();
765  DetId id = getId(rs);
766  float value = rs->getFloat(12);
767  //int ieta = rs->getInt(2);
768  //int iphi = rs->getInt(3);
769  //int depth = rs->getInt(4);
770  //HcalSubdetector subdetector = get_subdetector(rs->getString(5));
771  //HcalDetId id(subdetector,ieta,iphi,depth);
772  //std::cout << "DEBUG: " << id << " " << value << std::endl;
773  HcalValidationCorr * fCondObject = new HcalValidationCorr(id, value);
774  fObject->addValues(*fCondObject);
775  delete fCondObject;
776  }
777  //Always terminate statement
778  connection->terminateStatement(stmt);
779  } catch (SQLException& e) {
780  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
781  }
782  return result;
783 }
784 
785 
786 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
787  const std::string & fTag,
788  const std::string & fVersion,
789  const int fSubversion,
790  const int fIOVBegin,
791  const std::string & fQuery,
792  HcalLutMetadata* fObject) {
793  bool result=true;
794  if (!fObject) return false; //fObject = new HcalLutMetadata;
795  try {
796  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
797  stmt->setString(1,fTag);
798  //stmt->setString(2,fVersion);
799  stmt->setInt(2,fIOVBegin);
800 
801  ResultSet *rs = stmt->executeQuery();
802 
803  // protection agains NULL values
804  for (int _i=1; _i!=12; _i++) rs->setMaxColumnSize(_i,128);
805 
806  RooGKCounter _row(1,100);
807  _row.setMessage("HCAL channels processed: ");
808  _row.setPrintCount(true);
809  _row.setNewLine(true);
810  //
811  // This is two queries in one joined by "UNION" (SQL), not ordered
812  // One of the queries returns global data: RCTLSB and nominal gain.
813  // The global data is one raw, and it is ordered in the following way
814  // 1."fakeobjectname",
815  // 2."fakesubdetector", 3. -1, 4. -1, 5. -1, 6. -1, 7."fakesection", 8. -1, 9. -1, 10. -1, 11. -1
816  // 12. RCTLSB, 13. nominal_gain, 14. -1
817  //
818  // The channel query result must be ordered in the following way
819  // 1.objectname, ( values: HcalDetId, HcalCalibDetId, HcalTrigTowerDetId, HcalZDCDetId or HcalCastorDetId)
820  // 2.subdet, 3.ieta, 4.iphi, 5.depth, 6.type, 7.section, 8.ispositiveeta, 9.sector, 10.module, 11.channel
821  // 12. rec_hit_calibration, 13. lut_granularity, 14. output_lut_threshold
822  //
823  while (rs->next()) {
824  if (rs->getString(1).find("fakeobjectname")!=std::string::npos){ // global data
825  float rctlsb = rs->getFloat(12);
826  float nominal_gain = rs->getFloat(13);
827  fObject->setRctLsb(rctlsb);
828  fObject->setNominalGain(nominal_gain);
829  }
830  else{ // channel data
831  _row.count();
832  DetId id = getId(rs);
833  float rcalib = rs->getFloat(12);
834  uint32_t lut_granularity = rs->getInt(13);
835  uint32_t output_lut_threshold = rs->getInt(14);
836  HcalLutMetadatum * fCondObject = new HcalLutMetadatum(id,
837  rcalib,
838  lut_granularity,
839  output_lut_threshold);
840  fObject->addValues(*fCondObject);
841  delete fCondObject;
842  }
843  }
844  //Always terminate statement
845  connection->terminateStatement(stmt);
846  } catch (SQLException& e) {
847  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
848  }
849  return result;
850 }
851 
852 // version is needed for the DCS (unlike most other conditions)
853 bool HcalDbOmds::getObject (oracle::occi::Connection * connection,
854  const std::string & fTag,
855  const std::string & fVersion,
856  const int fSubversion,
857  const int fIOVBegin,
858  const std::string & fQuery,
859  HcalDcsValues* fObject) {
860  bool result=true;
861  if (!fObject) return false; //fObject = new HcalDcsValues;
862  try {
863  oracle::occi::Statement* stmt = connection->createStatement(fQuery);
864  stmt->setString(1,fTag);
865  stmt->setString(2,fVersion);
866  stmt->setInt(3,fSubversion);
867  stmt->setInt(4,fIOVBegin);
868 
869  std::cout << "DEBUG****** IOV=" << fIOVBegin << std::endl;
870 
871  ResultSet *rs = stmt->executeQuery();
872 
873  // protection agains NULL values
874  for (int _i=1; _i!=9; _i++) rs->setMaxColumnSize(_i,128);
875 
876  RooGKCounter _row(1,100);
877  _row.setMessage("HCAL DCS records: ");
878  _row.setPrintCount(true);
879  _row.setNewLine(true);
880  //
881  // The query for the DCS summary condition
882  //
883  // The channel query result must be ordered in the following way
884  //
885  // 1. dpname (string)
886  // 2. lumi section,
887  // 3. value,
888  // 4. upper limit,
889  // 5. lower limit,
890  // 6. subdetector (string)
891  // 7. side_ring
892  // 8. slice
893  // 9. subchannel
894  // 10. type (string)
895  //
896  while (rs->next()) {
897  _row.count();
898 
899  std::string _dpname = rs->getString(1);
900  //HcalOtherSubdetector subd = getSubDetFromDpName(_dpname);
901  //int sidering = getSideRingFromDpName(_dpname);
902  //unsigned int slice = getSliceFromDpName(_dpname);
903  //HcalDcsDetId::DcsType dcs_type = getDcsTypeFromDpName(_dpname);
904  //unsigned int subchan = getSubChannelFromDpName(_dpname);
905 
906  HcalOtherSubdetector subd = getSubDetFromString(rs->getString(6));
907  int sidering = rs->getInt(7);
908  unsigned int slice = rs->getInt(8);
909  unsigned int subchan = rs->getInt(9);
910  HcalDcsDetId::DcsType dcs_type = getDcsTypeFromString(rs->getString(10));
911 
912  HcalDcsDetId newId(subd, sidering, slice,
913  dcs_type, subchan);
914 
915  int LS = rs->getInt(2);
916  float val = rs->getFloat(3);
917  float upper = rs->getFloat(4);
918  float lower = rs->getFloat(5);
919 
920  HcalDcsValue * fCondObject = new HcalDcsValue(newId.rawId(),
921  LS,
922  val,
923  upper,
924  lower);
925 
926  if (!(fObject->addValue(*fCondObject))) {
927  edm::LogWarning("Data Error") << "Data for data point " << _dpname
928  << "\nwas not added to the HcalDcsValues object." << std::endl;
929  }
930  delete fCondObject;
931  }
932  fObject->sortAll();
933  //Always terminate statement
934  connection->terminateStatement(stmt);
935  } catch (SQLException& e) {
936  throw cms::Exception("ReadError") << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
937  }
938  return result;
939 }
940 
941 
942 bool HcalDbOmds::dumpObject (std::ostream& fOutput, const HcalZSThresholds& fObject) {
943  return true;
944 }
945 
946 
948 {
950  if ( _det.find("HB") != std::string::npos ) result = HcalBarrel;
951  else if ( _det.find("HE") != std::string::npos ) result = HcalEndcap;
952  else if ( _det.find("HF") != std::string::npos ) result = HcalForward;
953  else if ( _det.find("HO") != std::string::npos ) result = HcalOuter;
954  else result = HcalOther;
955 
956  return result;
957 }
958 
960 {
962  if ( _section.find("Unknown") != std::string::npos ) result = HcalZDCDetId::Unknown;
963  else if ( _section.find("EM") != std::string::npos ) result = HcalZDCDetId::EM;
964  else if ( _section.find("HAD") != std::string::npos ) result = HcalZDCDetId::HAD;
965  else if ( _section.find("LUM") != std::string::npos ) result = HcalZDCDetId::LUM;
966  else if ( _section.find("RPD") != std::string::npos ) result = HcalZDCDetId::RPD;
967  else result = HcalZDCDetId::Unknown;
968 
969  return result;
970 }
971 
972 
975  switch (_dpname.at(_dpname.find("HVcrate_")+9)) {
976  case 'B':
977  subd = HcalDcsBarrel;
978  break;
979  case 'E':
980  subd = HcalDcsEndcap;
981  break;
982  case 'F':
983  subd = HcalDcsForward;
984  break;
985  case 'O':
986  subd = HcalDcsOuter;
987  break;
988  default:
989  subd = HcalOtherEmpty;
990  break;
991  }
992  return subd;
993 }
994 
996  int _side_ring = 1000;
997  int _side = 10;
998  int _ring = 100;
999  switch (_dpname.at(_dpname.find("HVcrate_")+9)) {
1000  case 'B':
1001  case 'E':
1002  case 'F':
1003  if (_dpname.at(_dpname.find("HVcrate_")+10) == 'M') _side = -1;
1004  else if (_dpname.at(_dpname.find("HVcrate_")+10) == 'P') _side = +1;
1005  _ring = 1;
1006  break;
1007  case 'O':
1008  if (_dpname.at(_dpname.find("HVcrate_")+11) == 'M') _side = -1;
1009  else if (_dpname.at(_dpname.find("HVcrate_")+11) == 'P') _side = +1;
1010  _ring = atoi(&(_dpname.at(_dpname.find("HVcrate_")+10)));
1011  break;
1012  default:
1013  break;
1014  }
1015  _side_ring = _side * _ring;
1016  return _side_ring;
1017 }
1018 
1019 unsigned int HcalDbOmds::getSliceFromDpName(std::string _dpname){
1020  int result = 1000;
1021  HcalDbOmds::from_string<int>(result, _dpname.substr(_dpname.find("/S")+2,2), std::dec);
1022  return (unsigned int)result;
1023 }
1024 
1025 unsigned int HcalDbOmds::getSubChannelFromDpName(std::string _dpname){
1026  unsigned int result = 1000;
1027  HcalDbOmds::from_string<unsigned int>(result, _dpname.substr(_dpname.find("/RM")+3,1), std::dec);
1028  return result;
1029 }
1030 
1031 // FIXME: adjust to new PVSS data point naming convention
1032 // together with DcsDetId
1034  HcalDcsDetId::DcsType result = HcalDcsDetId::DcsType(15); // unknown
1035  std::string _type = _dpname.substr(_dpname.find("/RM")+4);
1036  if (_type.find("HV")!=std::string::npos) result = HcalDcsDetId::DcsType(1);
1037  return result;
1038 }
1039 
1041  HcalOtherSubdetector subd;
1042  switch (subdet.at(1)){
1043  case 'B':
1044  subd = HcalDcsBarrel;
1045  break;
1046  case 'E':
1047  subd = HcalDcsEndcap;
1048  break;
1049  case 'F':
1050  subd = HcalDcsForward;
1051  break;
1052  case 'O':
1053  subd = HcalDcsOuter;
1054  break;
1055  default:
1056  subd = HcalOtherEmpty;
1057  break;
1058  }
1059  return subd;
1060 }
1061 
1063  HcalDcsDetId::DcsType result = HcalDcsDetId::DCSUNKNOWN; // unknown
1064  if (type.find("HV")!=std::string::npos) result = HcalDcsDetId::HV;
1065  else if (type.find("BV")!=std::string::npos) result = HcalDcsDetId::BV;
1066  else if (type.find("Cath")!=std::string::npos) result = HcalDcsDetId::CATH;
1067  else if (type.find("Dyn7")!=std::string::npos) result = HcalDcsDetId::DYN7;
1068  else if (type.find("Dyn8")!=std::string::npos) result = HcalDcsDetId::DYN8;
1069  else if (type.find("RM_TEMP")!=std::string::npos) result = HcalDcsDetId::RM_TEMP;
1070  else if (type.find("CCM_TEMP")!=std::string::npos) result = HcalDcsDetId::CCM_TEMP;
1071  else if (type.find("CALIB_TEMP")!=std::string::npos) result = HcalDcsDetId::CALIB_TEMP;
1072  else if (type.find("LVTTM_TEMP")!=std::string::npos) result = HcalDcsDetId::LVTTM_TEMP;
1073  else if (type.find("TEMP")!=std::string::npos) result = HcalDcsDetId::TEMP;
1074  else if (type.find("QPLL_LOCK")!=std::string::npos) result = HcalDcsDetId::QPLL_LOCK;
1075  else if (type.find("STATUS")!=std::string::npos) result = HcalDcsDetId::STATUS;
1076  else if (type.find("DCS_MAX")!=std::string::npos) result = HcalDcsDetId::DCS_MAX;
1077  return result;
1078 }
1079 
type
Definition: HCALResponse.h:21
void setAlgoString(std::string fAlgo)
void setUnitADC(bool isADC)
Definition: HcalPedestals.h:30
HcalOtherSubdetector getSubDetFromDpName(std::string _dpname)
static int slb(const HcalTriggerPrimitiveSample &theSample)
bool getObject(oracle::occi::Connection *connection, const std::string &fTag, const std::string &fVersion, const int fSubversion, const int fIOVBegin, const std::string &fQuery, HcalPedestals *fObject)
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
HcalOtherSubdetector getSubDetFromString(std::string subdet)
void setOffset(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:58
bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
bool addCoder(const HcalQIECoder &fCoder)
Definition: HcalQIEData.h:43
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
bool setRctLsb(float rctlsb)
tuple result
Definition: mps_fire.py:84
HcalSubdetector get_subdetector(std::string _det)
void setUnitADC(bool isADC)
unsigned int getSliceFromDpName(std::string _dpname)
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
HcalOtherSubdetector
Definition: HcalAssistant.h:32
HcalDcsDetId::DcsType getDcsTypeFromString(std::string type)
HcalSubdetector
Definition: HcalAssistant.h:31
double f[11][100]
bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId)
Definition: DetId.h:18
void setHTR(int crate, int slot, int tb)
HcalDcsDetId::DcsType getDcsTypeFromDpName(std::string _dpname)
bool from_string(T &t, const std::string &s, std::ios_base &(*f)(std::ios_base &))
void sort()
Definition: HcalQIEData.h:45
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
bool addValue(HcalDcsValue const &newVal)
unsigned int getSubChannelFromDpName(std::string _dpname)
tuple cout
Definition: gather_cfg.py:145
void setTagString(std::string fTag)
bool addValues(const Item &myItem)
long double T
DetId getId(oracle::occi::ResultSet *rs)
HcalZDCDetId::Section get_zdc_section(std::string _section)
int getSideRingFromDpName(std::string _dpname)
Readout chain identification for Hcal.
void setSigma(int fCapId1, int fCapId2, float fSigma)
void setSlope(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:67
bool setNominalGain(float gain)