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