CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDbOnline.cc
Go to the documentation of this file.
1 
2 //
3 // F.Ratnikov (UMd), Dec 14, 2005
4 // $Id: HcalDbOnline.cc,v 1.21 2010/11/29 20:41:57 wmtan Exp $
5 //
6 #include <limits>
7 #include <string>
8 #include <iostream>
9 #include <sstream>
10 
12 
15 
16 namespace {
17 
18  HcalSubdetector hcalSubdet (const std::string& fName) {
19  return fName == "HB" ? HcalBarrel :
20  fName == "HE" ? HcalEndcap :
21  fName == "HO" ? HcalOuter :
22  fName == "HF" ? HcalForward : HcalSubdetector (0);
23  }
24 }
25 
26 HcalDbOnline::HcalDbOnline (const std::string& fDb, bool fVerbose)
27  : mConnect (0),
28  mVerbose (fVerbose)
29 {
30  mEnvironment = oracle::occi::Environment::createEnvironment (oracle::occi::Environment::OBJECT);
31  // decode connect string
32  size_t ipass = fDb.find ('/');
33  size_t ihost = fDb.find ('@');
34 
35  if (ipass == std::string::npos || ihost == std::string::npos) {
36  std::cerr << "HcalDbOnline::HcalDbOnline-> Error in connection string format: " << fDb
37  << " Expect user/password@db" << std::endl;
38  }
39  else {
40  std::string user (fDb, 0, ipass);
41  std::string pass (fDb, ipass+1, ihost-ipass-1);
42  std::string host (fDb, ihost+1);
43  // std::cout << "HcalDbOnline::HcalDbOnline-> Connecting " << user << '/' << pass << '@' << host << std::endl;
44  try {
45  mConnect = mEnvironment->createConnection(user, pass, host);
46  mStatement = mConnect->createStatement ();
47  }
48  catch (oracle::occi::SQLException& sqlExcp) {
49  std::cerr << "HcalDbOnline::HcalDbOnline exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
50  }
51  }
52 }
53 
55  delete mStatement;
56  mEnvironment->terminateConnection (mConnect);
57  oracle::occi::Environment::terminateEnvironment (mEnvironment);
58 }
59 
60 bool HcalDbOnline::getObject (HcalElectronicsMap* fObject, const std::string& fTag, IOVTime fTime) {
61  if (!fObject) return false;
62  std::string tag = fTag;
63  if (tag.empty()) {
64  tag = "9";
65  std::cout << "HcalDbOnline::getObject (HcalElectronicsMap*..)-> Using default tag: " << tag << std::endl;
66  }
67  std::string sql_query ("");
68  sql_query += "SELECT\n";
69  sql_query += " DAT2.SIDE, DAT2.ETA, DAT2.PHI, DAT2.DEPTH, DAT2.SUBDETECTOR,\n" ;
70  sql_query += " DAT2.CRATE, DAT2.HTR_SLOT, DAT2.HTR_FPGA, DAT2.DCC, DAT2.DCC_SPIGOT, DAT2.HTR_FIBER, DAT2.FIBER_CHANNEL \n" ;
71  sql_query += " FROM\n";
72  sql_query += " CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS DAT2,\n";
73  sql_query += " CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS DS2,\n";
74  sql_query += " CMS_HCL_CORE_CONDITION_OWNER.KINDS_OF_CONDITIONS KOC2\n";
75  sql_query += " WHERE\n";
76  sql_query += " DS2.CONDITION_DATA_SET_ID=DAT2.CONDITION_DATA_SET_ID\n";
77  sql_query += " AND KOC2.KIND_OF_CONDITION_ID=DS2.KIND_OF_CONDITION_ID \n";
78  sql_query += " AND KOC2.IS_RECORD_DELETED='F' AND DS2.IS_RECORD_DELETED='F' \n";
79  sql_query += " AND KOC2.EXTENSION_TABLE_NAME='HCAL_HARDWARE_LOGICAL_MAPS' \n";
80  sql_query += " AND DS2.VERSION='" + tag + "'\n";
81  try {
82  if (mVerbose) std::cout << "executing query: \n" << sql_query << std::endl;
83  // oracle::occi::Statement* stmt = mConnect->createStatement ();
84  mStatement->setPrefetchRowCount (100);
85  mStatement->setSQL (sql_query);
86  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
87  while (rset->next ()) {
88  int index = 1;
89  int z = rset->getInt (index++) > 0 ? 1 : -1;
90  int eta = rset->getInt (index++);
91  int phi = rset->getInt (index++);
92  int depth = rset->getInt (index++);
93  std::string subdet = rset->getString (index++);
94  int crate = rset->getInt (index++);
95  int slot = rset->getInt (index++);
96  int fpga = rset->getInt (index++) > 0 ? 1 : 0;
97  int dcc = rset->getInt (index++);
98  int spigot = rset->getInt (index++);
99  int fiber = rset->getInt (index++);
100  int fiberChannel = rset->getInt (index++);
101 
102  HcalElectronicsId eid (fiberChannel, fiber, spigot, dcc);
103  eid.setHTR (crate, slot, fpga);
104 
105  HcalSubdetector sub = hcalSubdet (subdet);
106  HcalDetId id (sub, z * eta, phi, depth);
107 
108 // fObject->setMapping (id, eid, HcalTrigTowerDetId ());
109  DetId detid(id);
110  fObject->mapEId2chId (eid,detid);
111  }
112  delete rset;
113  // delete stmt;
114  }
115  catch (oracle::occi::SQLException& sqlExcp) {
116  std::cerr << "HcalDbOnline::getObject exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
117  }
118  fObject->sort ();
119  return true;
120 }
121 
122 bool HcalDbOnline::getObject (HcalQIEData* fObject, const std::string& fTag, IOVTime fTime) {
123  if (!fObject) return false;
124  std::string sql_what ("");
125  sql_what += " ADC_CH.SIDE, ADC_CH.ETA, ADC_CH.PHI, ADC_CH.DEPTH, ADC_CH.SUBDETECTOR,\n" ;
126  sql_what += " DAT.CAP0_RANGE0_OFFSET, DAT.CAP0_RANGE0_SLOPE,\n" ;
127  sql_what += " DAT.CAP0_RANGE1_OFFSET, DAT.CAP1_RANGE0_SLOPE,\n" ;
128  sql_what += " DAT.CAP0_RANGE2_OFFSET, DAT.CAP2_RANGE0_SLOPE,\n" ;
129  sql_what += " DAT.CAP0_RANGE3_OFFSET, DAT.CAP3_RANGE0_SLOPE,\n" ;
130  sql_what += " DAT.CAP1_RANGE0_OFFSET, DAT.CAP0_RANGE1_SLOPE,\n" ;
131  sql_what += " DAT.CAP1_RANGE1_OFFSET, DAT.CAP1_RANGE1_SLOPE,\n" ;
132  sql_what += " DAT.CAP1_RANGE2_OFFSET, DAT.CAP2_RANGE1_SLOPE,\n" ;
133  sql_what += " DAT.CAP1_RANGE3_OFFSET, DAT.CAP3_RANGE1_SLOPE,\n" ;
134  sql_what += " DAT.CAP2_RANGE0_OFFSET, DAT.CAP0_RANGE2_SLOPE,\n" ;
135  sql_what += " DAT.CAP2_RANGE1_OFFSET, DAT.CAP1_RANGE2_SLOPE,\n" ;
136  sql_what += " DAT.CAP2_RANGE2_OFFSET, DAT.CAP2_RANGE2_SLOPE,\n" ;
137  sql_what += " DAT.CAP2_RANGE3_OFFSET, DAT.CAP3_RANGE2_SLOPE,\n" ;
138  sql_what += " DAT.CAP3_RANGE0_OFFSET, DAT.CAP0_RANGE3_SLOPE,\n" ;
139  sql_what += " DAT.CAP3_RANGE1_OFFSET, DAT.CAP1_RANGE3_SLOPE,\n" ;
140  sql_what += " DAT.CAP3_RANGE2_OFFSET, DAT.CAP2_RANGE3_SLOPE,\n" ;
141  sql_what += " DAT.CAP3_RANGE3_OFFSET, DAT.CAP3_RANGE3_SLOPE \n" ;
142 
143  // HB/HE/HO
144  std::string sql_hbheho ("");
145  sql_hbheho += " FROM \n";
146  sql_hbheho += " CMS_HCL_HCAL_CONDITION_OWNER.QIECARD_ADC_NORMMODE DAT\n";
147  sql_hbheho += " inner join CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS DS\n";
148  sql_hbheho += " on DAT.CONDITION_DATA_SET_ID=DS.CONDITION_DATA_SET_ID\n";
149  sql_hbheho += " inner join \n";
150  sql_hbheho += " ( \n";
151  sql_hbheho += " select\n";
152  sql_hbheho += " LOGMAP.SIDE,\n";
153  sql_hbheho += " LOGMAP.ETA,\n";
154  sql_hbheho += " LOGMAP.PHI,\n";
155  sql_hbheho += " LOGMAP.DEPTH,\n";
156  sql_hbheho += " LOGMAP.SUBDETECTOR,\n";
157  sql_hbheho += " ADC_CHAIN.ADC_PART_ID\n";
158  sql_hbheho += " from\n";
159  sql_hbheho += " CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V2 LOGMAP\n";
160  sql_hbheho += " inner join CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS LOGMAP_DS\n";
161  sql_hbheho += " on LOGMAP_DS.CONDITION_DATA_SET_ID=LOGMAP.CONDITION_DATA_SET_ID\n";
162  sql_hbheho += " inner join\n";
163  sql_hbheho += " (\n";
164  sql_hbheho += " select ADC.PART_ID as ADC_PART_ID, \n";
165  sql_hbheho += " SLOT.NAME_LABEL as RBX_SLOT,\n";
166  sql_hbheho += " RM.RM_SLOT as RM_SLOT,\n";
167  sql_hbheho += " QIE.QIE_SLOT as QIE_SLOT,\n";
168  sql_hbheho += " ADC.ADC_POSITION as ADC\n";
169  sql_hbheho += " from CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_READOUTBOX_SLOTS SLOT\n";
170  sql_hbheho += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_READOUTBOXS RBX\n";
171  sql_hbheho += " on RBX.PART_PARENT_ID=SLOT.PART_ID\n";
172  sql_hbheho += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_READOUTMODULES RM\n";
173  sql_hbheho += " on RM.PART_PARENT_ID=RBX.PART_ID\n";
174  sql_hbheho += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_QIECARDS QIE\n";
175  sql_hbheho += " on QIE.PART_PARENT_ID=RM.PART_ID\n";
176  sql_hbheho += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_ADCS ADC\n";
177  sql_hbheho += " on ADC.PART_PARENT_ID=QIE.PART_ID \n";
178  sql_hbheho += " ) ADC_CHAIN\n";
179  sql_hbheho += " on ADC_CHAIN.RBX_SLOT = LOGMAP.RBX_SLOT and\n";
180  sql_hbheho += " ADC_CHAIN.RM_SLOT = LOGMAP.RM_SLOT and\n";
181  sql_hbheho += " ADC_CHAIN.QIE_SLOT = LOGMAP.QIE_SLOT and\n";
182  sql_hbheho += " ADC_CHAIN.ADC = LOGMAP.ADC\n";
183  sql_hbheho += " where LOGMAP_DS.VERSION='15'\n";
184  sql_hbheho += " ) ADC_CH\n";
185  sql_hbheho += " on DS.PART_ID=ADC_CH.ADC_PART_ID\n";
186  sql_hbheho += " where DS.VERSION='3'\n";
187 
188 
189  // HF
190  std::string sql_hf ("");
191  sql_hf += " FROM \n";
192  sql_hf += " CMS_HCL_HCAL_CONDITION_OWNER.QIECARD_ADC_NORMMODE DAT\n";
193  sql_hf += " inner join CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS DS\n";
194  sql_hf += " on DAT.CONDITION_DATA_SET_ID=DS.CONDITION_DATA_SET_ID\n";
195  sql_hf += " inner join \n";
196  sql_hf += " ( \n";
197  sql_hf += " select\n";
198  sql_hf += " LOGMAP.SIDE,\n";
199  sql_hf += " LOGMAP.ETA,\n";
200  sql_hf += " LOGMAP.PHI,\n";
201  sql_hf += " LOGMAP.DEPTH,\n";
202  sql_hf += " LOGMAP.SUBDETECTOR,\n";
203  sql_hf += " ADC_CHAIN.ADC_PART_ID\n";
204  sql_hf += " from\n";
205  sql_hf += " CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V2 LOGMAP\n";
206  sql_hf += " inner join CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS LOGMAP_DS\n";
207  sql_hf += " on LOGMAP_DS.CONDITION_DATA_SET_ID=LOGMAP.CONDITION_DATA_SET_ID\n";
208  sql_hf += " inner join\n";
209  sql_hf += " (\n";
210  sql_hf += " select ADC.PART_ID as ADC_PART_ID, \n";
211  sql_hf += " SLOT.NAME_LABEL as CRATE_SLOT,\n";
212  sql_hf += " QIE.QIE_SLOT as QIE_SLOT,\n";
213  sql_hf += " ADC.ADC_POSITION as ADC\n";
214  sql_hf += " from CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_WEDGE_SLOTS SLOT\n";
215  sql_hf += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_HF_FE_CRATE CR\n";
216  sql_hf += " on CR.PART_PARENT_ID=SLOT.PART_ID\n";
217  sql_hf += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_QIECARDS QIE\n";
218  sql_hf += " on QIE.PART_PARENT_ID=CR.PART_ID\n";
219  sql_hf += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_ADCS ADC\n";
220  sql_hf += " on ADC.PART_PARENT_ID=QIE.PART_ID \n";
221  sql_hf += " ) ADC_CHAIN\n";
222  sql_hf += " on ADC_CHAIN.CRATE_SLOT = LOGMAP.RBX_SLOT and\n";
223  sql_hf += " ADC_CHAIN.QIE_SLOT = LOGMAP.QIE_SLOT and\n";
224  sql_hf += " ADC_CHAIN.ADC = LOGMAP.ADC\n";
225  sql_hf += " where LOGMAP_DS.VERSION='15'\n";
226  sql_hf += " ) ADC_CH\n";
227  sql_hf += " on DS.PART_ID=ADC_CH.ADC_PART_ID\n";
228  sql_hf += " where DS.VERSION='3'\n";
229 
230  std::string sql_query [2];
231  sql_query [0] = " SELECT \n" + sql_what + sql_hbheho;
232  sql_query [1] = " SELECT \n" + sql_what + sql_hf;
233 
234  try {
235  for (int i = 0; i < 2; i++) {
236  if (mVerbose) std::cout << "executing query: \n" << sql_query[i] << std::endl;
237  mStatement->setPrefetchRowCount (100);
238  mStatement->setSQL (sql_query [i]);
239  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
240  while (rset->next ()) {
241  int index = 1;
242  int z = rset->getInt (index++);
243  int eta = rset->getInt (index++);
244  int phi = rset->getInt (index++);
245  int depth = rset->getInt (index++);
246  std::string subdet = rset->getString (index++);
247  float offset [4][4];
248  float slope [4][4];
249  for (int capId = 0; capId < 4; capId++) {
250  for (int range = 0; range < 4; range++) {
251  offset [capId][range] = rset->getFloat (index++);
252  slope [capId][range] = rset->getFloat (index++);
253  }
254  }
255 
256  HcalSubdetector sub = hcalSubdet (subdet);
257  HcalDetId id (sub, z * eta, phi, depth);
258 
259  HcalQIECoder coder(id.rawId());
260  for (int capId = 0; capId < 4; capId++) {
261  for (int range = 0; range < 4; range++) {
262  coder.setOffset (capId, range, offset [capId][range]);
263  coder.setSlope (capId, range, slope [capId][range]);
264  }
265  }
266 
267  fObject->addCoder (coder);
268  }
269  delete rset;
270  }
271  }
272  catch (oracle::occi::SQLException& sqlExcp) {
273  std::cerr << "HcalDbOnline::getObject exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
274  }
275  fObject->sort ();
276  return true;
277 }
278 
280  if (!fObject) return false;
281  std::string sql_what ("");
282  sql_what += " ADC_CH.SIDE, ADC_CH.ETA, ADC_CH.PHI, ADC_CH.DEPTH, ADC_CH.SUBDETECTOR,\n" ;
283  sql_what += " DAT.BIN0, DAT.BIN1, DAT.BIN2, DAT.BIN3, DAT.BIN4, DAT.BIN5, DAT.BIN6, DAT.BIN7,\n";
284  sql_what += " DAT.BIN8, DAT.BIN9, DAT.BIN10, DAT.BIN11, DAT.BIN12, DAT.BIN13, DAT.BIN14, DAT.BIN15,\n";
285  sql_what += " DAT.BIN16, DAT.BIN17, DAT.BIN18, DAT.BIN19, DAT.BIN20, DAT.BIN21, DAT.BIN22, DAT.BIN23,\n";
286  sql_what += " DAT.BIN24, DAT.BIN25, DAT.BIN26, DAT.BIN27, DAT.BIN28, DAT.BIN29, DAT.BIN30, DAT.BIN31 \n";
287 
288  // HB/HE/HO
289  std::string sql_hbheho ("");
290  sql_hbheho += " FROM \n";
291  sql_hbheho += " CMS_HCL_HCAL_CONDITION_OWNER.QIECARD_ADC_CALIBMODE DAT\n";
292  sql_hbheho += " inner join CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS DS\n";
293  sql_hbheho += " on DAT.CONDITION_DATA_SET_ID=DS.CONDITION_DATA_SET_ID\n";
294  sql_hbheho += " inner join \n";
295  sql_hbheho += " ( \n";
296  sql_hbheho += " select\n";
297  sql_hbheho += " LOGMAP.SIDE,\n";
298  sql_hbheho += " LOGMAP.ETA,\n";
299  sql_hbheho += " LOGMAP.PHI,\n";
300  sql_hbheho += " LOGMAP.DEPTH,\n";
301  sql_hbheho += " LOGMAP.SUBDETECTOR,\n";
302  sql_hbheho += " ADC_CHAIN.ADC_PART_ID\n";
303  sql_hbheho += " from\n";
304  sql_hbheho += " CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V2 LOGMAP\n";
305  sql_hbheho += " inner join CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS LOGMAP_DS\n";
306  sql_hbheho += " on LOGMAP_DS.CONDITION_DATA_SET_ID=LOGMAP.CONDITION_DATA_SET_ID\n";
307  sql_hbheho += " inner join\n";
308  sql_hbheho += " (\n";
309  sql_hbheho += " select ADC.PART_ID as ADC_PART_ID, \n";
310  sql_hbheho += " SLOT.NAME_LABEL as RBX_SLOT,\n";
311  sql_hbheho += " RM.RM_SLOT as RM_SLOT,\n";
312  sql_hbheho += " QIE.QIE_SLOT as QIE_SLOT,\n";
313  sql_hbheho += " ADC.ADC_POSITION as ADC\n";
314  sql_hbheho += " from CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_READOUTBOX_SLOTS SLOT\n";
315  sql_hbheho += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_READOUTBOXS RBX\n";
316  sql_hbheho += " on RBX.PART_PARENT_ID=SLOT.PART_ID\n";
317  sql_hbheho += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_READOUTMODULES RM\n";
318  sql_hbheho += " on RM.PART_PARENT_ID=RBX.PART_ID\n";
319  sql_hbheho += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_QIECARDS QIE\n";
320  sql_hbheho += " on QIE.PART_PARENT_ID=RM.PART_ID\n";
321  sql_hbheho += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_ADCS ADC\n";
322  sql_hbheho += " on ADC.PART_PARENT_ID=QIE.PART_ID \n";
323  sql_hbheho += " ) ADC_CHAIN\n";
324  sql_hbheho += " on ADC_CHAIN.RBX_SLOT = LOGMAP.RBX_SLOT and\n";
325  sql_hbheho += " ADC_CHAIN.RM_SLOT = LOGMAP.RM_SLOT and\n";
326  sql_hbheho += " ADC_CHAIN.QIE_SLOT = LOGMAP.QIE_SLOT and\n";
327  sql_hbheho += " ADC_CHAIN.ADC = LOGMAP.ADC\n";
328  sql_hbheho += " where LOGMAP_DS.VERSION='15'\n";
329  sql_hbheho += " ) ADC_CH\n";
330  sql_hbheho += " on DS.PART_ID=ADC_CH.ADC_PART_ID\n";
331  sql_hbheho += " where DS.VERSION='3'\n";
332 
333 
334  // HF
335  std::string sql_hf ("");
336  sql_hf += " FROM \n";
337  sql_hf += " CMS_HCL_HCAL_CONDITION_OWNER.QIECARD_ADC_CALIBMODE DAT\n";
338  sql_hf += " inner join CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS DS\n";
339  sql_hf += " on DAT.CONDITION_DATA_SET_ID=DS.CONDITION_DATA_SET_ID\n";
340  sql_hf += " inner join \n";
341  sql_hf += " ( \n";
342  sql_hf += " select\n";
343  sql_hf += " LOGMAP.SIDE,\n";
344  sql_hf += " LOGMAP.ETA,\n";
345  sql_hf += " LOGMAP.PHI,\n";
346  sql_hf += " LOGMAP.DEPTH,\n";
347  sql_hf += " LOGMAP.SUBDETECTOR,\n";
348  sql_hf += " ADC_CHAIN.ADC_PART_ID\n";
349  sql_hf += " from\n";
350  sql_hf += " CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V2 LOGMAP\n";
351  sql_hf += " inner join CMS_HCL_CORE_CONDITION_OWNER.COND_DATA_SETS LOGMAP_DS\n";
352  sql_hf += " on LOGMAP_DS.CONDITION_DATA_SET_ID=LOGMAP.CONDITION_DATA_SET_ID\n";
353  sql_hf += " inner join\n";
354  sql_hf += " (\n";
355  sql_hf += " select ADC.PART_ID as ADC_PART_ID, \n";
356  sql_hf += " SLOT.NAME_LABEL as CRATE_SLOT,\n";
357  sql_hf += " QIE.QIE_SLOT as QIE_SLOT,\n";
358  sql_hf += " ADC.ADC_POSITION as ADC\n";
359  sql_hf += " from CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_WEDGE_SLOTS SLOT\n";
360  sql_hf += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_HF_FE_CRATE CR\n";
361  sql_hf += " on CR.PART_PARENT_ID=SLOT.PART_ID\n";
362  sql_hf += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_QIECARDS QIE\n";
363  sql_hf += " on QIE.PART_PARENT_ID=CR.PART_ID\n";
364  sql_hf += " inner join CMS_HCL_CORE_CONSTRUCT_OWNER.V_HCAL_ADCS ADC\n";
365  sql_hf += " on ADC.PART_PARENT_ID=QIE.PART_ID \n";
366  sql_hf += " ) ADC_CHAIN\n";
367  sql_hf += " on ADC_CHAIN.CRATE_SLOT = LOGMAP.RBX_SLOT and\n";
368  sql_hf += " ADC_CHAIN.QIE_SLOT = LOGMAP.QIE_SLOT and\n";
369  sql_hf += " ADC_CHAIN.ADC = LOGMAP.ADC\n";
370  sql_hf += " where LOGMAP_DS.VERSION='15'\n";
371  sql_hf += " ) ADC_CH\n";
372  sql_hf += " on DS.PART_ID=ADC_CH.ADC_PART_ID\n";
373  sql_hf += " where DS.VERSION='3'\n";
374 
375 
376  std::string sql_query [2];
377  sql_query [0] = " SELECT \n" + sql_what + sql_hbheho;
378  sql_query [1] = " SELECT \n" + sql_what + sql_hf;
379 
380  try {
381  for (int i = 0; i < 2; i++) {
382  if (mVerbose) std::cout << "executing query: \n" << sql_query [i] << std::endl;
383  // oracle::occi::Statement* stmt = mConnect->createStatement ();
384  mStatement->setPrefetchRowCount (100);
385  mStatement->setSQL (sql_query [i]);
386  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
387  while (rset->next ()) {
388  int index = 1;
389  int z = rset->getInt (index++);
390  int eta = rset->getInt (index++);
391  int phi = rset->getInt (index++);
392  int depth = rset->getInt (index++);
393  std::string subdet = rset->getString (index++);
394  float values [32];
395  for (unsigned bin = 0; bin < 32; bin++) values [bin] = rset->getFloat (index++);
396 
397  HcalSubdetector sub = hcalSubdet (subdet);
398  HcalDetId id (sub, z * eta, phi, depth);
399 
400  HcalCalibrationQIECoder coder(id.rawId());
401  coder.setMinCharges (values);
402 
403  fObject->addCoder (coder);
404  }
405  delete rset;
406  }
407  // delete stmt;
408  }
409  catch (oracle::occi::SQLException& sqlExcp) {
410  std::cerr << "HcalDbOnline::getObject exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
411  }
412  fObject->sort ();
413  return true;
414 }
415 
416 
417 bool HcalDbOnline::getObject (HcalPedestals* fObject, HcalPedestalWidths* fWidths, const std::string& fTag, IOVTime fTime) {
418  if (!fObject && !fWidths) return false;
419  std::ostringstream sTime;
420  sTime << fTime;
421  std::string sql_query ("");
422  sql_query += "SELECT\n";
423  sql_query += " Z, ETA, PHI, DEPTH, DETECTOR_NAME\n";
424  sql_query += " , CAPACITOR_0_VALUE, CAPACITOR_1_VALUE, CAPACITOR_2_VALUE, CAPACITOR_3_VALUE\n";
425  sql_query += " , SIGMA_0_0, SIGMA_0_1, SIGMA_0_2, SIGMA_0_3, SIGMA_1_1, SIGMA_1_2, SIGMA_1_3, SIGMA_2_2, SIGMA_2_3, SIGMA_3_3\n";
426  sql_query += " , RUN_NUMBER, INTERVAL_OF_VALIDITY_BEGIN, INTERVAL_OF_VALIDITY_END\n";
427  sql_query += "FROM V_HCAL_PEDESTALS_V2\n";
428  sql_query += "WHERE TAG_NAME='" + fTag + "'\n";
429  sql_query += "AND INTERVAL_OF_VALIDITY_BEGIN=" + sTime.str() + "\n";
430  sql_query += "AND (INTERVAL_OF_VALIDITY_END IS NULL OR INTERVAL_OF_VALIDITY_END>" + sTime.str() + ")\n";
431  try {
432  if (mVerbose) std::cout << "executing query: \n" << sql_query << std::endl;
433  mStatement->setPrefetchRowCount (100);
434  mStatement->setSQL (sql_query);
435  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
436  while (rset->next ()) {
437  int index = 1;
438  int z = rset->getInt (index++);
439  int eta = rset->getInt (index++);
440  int phi = rset->getInt (index++);
441  int depth = rset->getInt (index++);
442  std::string subdet = rset->getString (index++);
443 
444  float values [4];
445  float widths [4][4];
446  for (int i = 0; i < 4; i++) values[i] = rset->getFloat (index++);
447  for (int i = 0; i < 4; i++)
448  for (int j = i; j < 4; j++) widths [i][j] = rset->getFloat (index++);
449 
450 // unsigned long run = rset->getNumber (index++);
451 // unsigned long iovBegin = rset->getNumber (index++);
452 // unsigned long iovEnd = rset->getNumber (index++);
453 
454  HcalSubdetector sub = hcalSubdet (subdet);
455  HcalDetId id (sub, z * eta, phi, depth);
456 
457  if (fObject) {
458  if (fObject->exists(id) )
459  std::cerr << "HcalDbOnline::getObject-> Ignore data to redefine channel " << id.rawId() << std::endl;
460  else
461  {
462  HcalPedestal myped(id,values[0],values[1],values[2],values[3]);
463  fObject->addValues(myped);
464  }
465  }
466  if (fWidths) {
467  if (fWidths->exists(id) )
468  std::cerr << "HcalDbOnline::getObject-> Ignore data to redefine channel " << id.rawId() << std::endl;
469  else
470  {
471  HcalPedestalWidth mywidth(id);
472  for (int i = 0; i < 4; i++)
473  for (int j = i; j < 4; j++) mywidth.setSigma (i, j, widths [i][j]);
474  fWidths->addValues(mywidth);
475  }
476  }
477  }
478  delete rset;
479  }
480  catch (oracle::occi::SQLException& sqlExcp) {
481  std::cerr << "HcalDbOnline::getObject exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
482  }
483  // if (fObject) fObject->sort ();
484  // if (fWidths) fWidths->sort ();
485  return true;
486 }
487 
488 bool HcalDbOnline::getObject (HcalPedestals* fObject, const std::string& fTag, IOVTime fTime) {
489  return getObject (fObject, (HcalPedestalWidths*)0, fTag, fTime);
490 }
491 
492 bool HcalDbOnline::getObject (HcalPedestalWidths* fObject, const std::string& fTag, IOVTime fTime) {
493  return getObject ((HcalPedestals*)0, fObject, fTag, fTime);
494 }
495 
496 bool HcalDbOnline::getObject (HcalGains* fObject, HcalGainWidths* fWidths, const std::string& fTag, IOVTime fTime) {
497  if (!fObject && !fWidths) return false;
498  std::ostringstream sTime;
499  sTime << fTime;
500  std::string sql_query ("");
501  sql_query += "SELECT\n";
502  sql_query += " Z, ETA, PHI, DEPTH, DETECTOR_NAME\n";
503  sql_query += " , CAPACITOR_0_VALUE, CAPACITOR_1_VALUE, CAPACITOR_2_VALUE, CAPACITOR_3_VALUE\n";
504  sql_query += " , CAPACITOR_0_ERROR, CAPACITOR_1_ERROR, CAPACITOR_2_ERROR, CAPACITOR_3_ERROR\n";
505  sql_query += " , RUN_NUMBER, INTERVAL_OF_VALIDITY_BEGIN, INTERVAL_OF_VALIDITY_END\n";
506  sql_query += "FROM V_HCAL_GAIN_CALIBRATIONS\n";
507  sql_query += "WHERE TAG_NAME='" + fTag + "'\n";
508  sql_query += "AND INTERVAL_OF_VALIDITY_BEGIN=" + sTime.str() + "\n";
509  sql_query += "AND (INTERVAL_OF_VALIDITY_END IS NULL OR INTERVAL_OF_VALIDITY_END>" + sTime.str() + ")\n";
510  try {
511  if (mVerbose) std::cout << "executing query: \n" << sql_query << std::endl;
512  mStatement->setPrefetchRowCount (100);
513  mStatement->setSQL (sql_query);
514  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
515  std::cout << "query is executed... " << std::endl;
516  while (rset->next ()) {
517  int index = 1;
518  int z = rset->getInt (index++);
519  int eta = rset->getInt (index++);
520  int phi = rset->getInt (index++);
521  int depth = rset->getInt (index++);
522  std::string subdet = rset->getString (index++);
523 
524  float values [4];
525  for (int i = 0; i < 4; i++) values[i] = rset->getFloat (index++);
526  for (int i = 0; i < 4; i++) rset->getFloat (index++);
527 // unsigned long run = rset->getNumber (index++);
528 // unsigned long iovBegin = rset->getNumber (index++);
529 // unsigned long iovEnd = rset->getNumber (index++);
530 
531  HcalSubdetector sub = hcalSubdet (subdet);
532  HcalDetId id (sub, z * eta, phi, depth);
533 
534  if (fObject) {
535  if (fObject->exists(id) )
536  std::cerr << "HcalDbOnline::getObject-> Ignore data to redefine channel " << id.rawId() << std::endl;
537  else
538  {
539  HcalGain mygain(id,values[0],values[1],values[2],values[3]);
540  fObject->addValues (mygain);
541  }
542  }
543  if (fWidths) {
544  if (fWidths->exists(id) )
545  std::cerr << "HcalDbOnline::getObject-> Ignore data to redefine channel " << id.rawId() << std::endl;
546  else
547  {
548  HcalGainWidth mywid(id,values[0],values[1],values[2],values[3]);
549  fWidths->addValues(mywid);
550  }
551  }
552  }
553  delete rset;
554  }
555  catch (oracle::occi::SQLException& sqlExcp) {
556  std::cerr << "HcalDbOnline::getObject exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
557  }
558  // if (fObject) fObject->sort ();
559  // if (fWidths) fWidths->sort ();
560  return true;
561 }
562 
563 bool HcalDbOnline::getObject (HcalGains* fObject, const std::string& fTag, IOVTime fTime) {
564  return getObject (fObject, (HcalGainWidths*) 0, fTag, fTime);
565 }
566 
567 bool HcalDbOnline::getObject (HcalGainWidths* fWidths, const std::string& fTag, IOVTime fTime) {
568  return getObject ((HcalGains*) 0, fWidths, fTag, fTime);
569 }
570 
571 std::vector<std::string> HcalDbOnline::metadataAllTags () {
572  std::vector<std::string> result;
573  std::string sql_query ("");
574  sql_query += "SELECT unique TAG_NAME from V_TAG_IOV_CONDDATASET order by TAG_NAME\n";
575  try {
576  if (mVerbose) std::cout << "executing query: \n" << sql_query << std::endl;
577  mStatement->setPrefetchRowCount (100);
578  mStatement->setSQL (sql_query);
579  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
580  while (rset->next ()) {
581  std::string tag = rset->getString (1);
582  result.push_back (tag);
583  }
584  }
585  catch (oracle::occi::SQLException& sqlExcp) {
586  std::cerr << "HcalDbOnline::metadataAllTags exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
587  }
588  return result;
589 }
590 
591 std::vector<HcalDbOnline::IntervalOV> HcalDbOnline::getIOVs (const std::string& fTag) {
592  std::vector<IntervalOV> result;
593  std::string sql_query ("");
594  sql_query += "SELECT unique INTERVAL_OF_VALIDITY_BEGIN, INTERVAL_OF_VALIDITY_END from V_TAG_IOV_CONDDATASET\n";
595  sql_query += "WHERE TAG_NAME='" + fTag + "'\n";
596  sql_query += "ORDER by INTERVAL_OF_VALIDITY_BEGIN\n";
597  try {
598  if (mVerbose) std::cout << "executing query: \n" << sql_query << std::endl;
599  mStatement->setPrefetchRowCount (100);
600  mStatement->setSQL (sql_query);
601  oracle::occi::ResultSet* rset = mStatement->executeQuery ();
602  while (rset->next ()) {
603 // char buffer [128];
604 // oracle::occi::Bytes iovb = rset->getNumber (1).toBytes();
605 // unsigned ix = 0;
606 // std::cout << "total bytes: " << iovb.length() << std::endl;
607 // for (; ix < iovb.length(); ix++) {
608 // sprintf (buffer, "byte# %d: %x", ix, iovb.byteAt (ix));
609 // std::cout << buffer << std::endl;
610 // }
611  IOVTime beginIov = (unsigned long) rset->getNumber (1);
612 // sprintf (buffer, "%x", beginIov);
613 // std::cout << "value: " << buffer << std::endl;
614  IOVTime endIov = rset->getInt (2);
615  if (!endIov) endIov = std::numeric_limits <IOVTime>::max (); // end of ages
616  result.push_back (std::make_pair (beginIov, endIov));
617  }
618  }
619  catch (oracle::occi::SQLException& sqlExcp) {
620  std::cerr << "HcalDbOnline::getIOVs exception-> " << sqlExcp.getErrorCode () << ": " << sqlExcp.what () << std::endl;
621  }
622  return result;
623 }
624 
int i
Definition: DBlmapReader.cc:9
oracle::occi::Environment * mEnvironment
Definition: HcalDbOnline.h:57
static const double slope[3]
void setOffset(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:58
bool addCoder(const HcalQIECoder &fCoder)
Definition: HcalQIEData.h:44
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
const bool exists(DetId fId) const
std::vector< IntervalOV > getIOVs(const std::string &fTag)
tuple result
Definition: query.py:137
HcalSubdetector
Definition: HcalAssistant.h:31
int j
Definition: DBlmapReader.cc:9
unsigned long long IOVTime
Definition: HcalDbOnline.h:36
void setMinCharges(const float fValue[32])
bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId)
HcalDbOnline(const std::string &fDb, bool fVerbose=false)
Definition: HcalDbOnline.cc:26
oracle::occi::Statement * mStatement
Definition: HcalDbOnline.h:59
string host
Definition: query.py:114
std::vector< std::string > metadataAllTags()
Definition: DetId.h:18
void setHTR(int crate, int slot, int tb)
bool getObject(HcalPedestals *fObject, HcalPedestalWidths *fWidths, const std::string &fTag, IOVTime fTime)
oracle::occi::Connection * mConnect
Definition: HcalDbOnline.h:58
void sort()
Definition: HcalQIEData.h:46
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
mVerbose(fConfig.getUntrackedParameter< bool >("verbose", false))
tuple cout
Definition: gather_cfg.py:121
bool addCoder(const HcalCalibrationQIECoder &fCoder)
bool addValues(const Item &myItem)
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