CMS 3D CMS Logo

L1TriggerScalerRead.cc
Go to the documentation of this file.
2 
3 #include "RelationalAccess/ISession.h"
4 #include "RelationalAccess/ITransaction.h"
5 #include "RelationalAccess/ISchema.h"
6 #include "RelationalAccess/ITable.h"
7 #include "RelationalAccess/ITableDataEditor.h"
8 #include "RelationalAccess/TableDescription.h"
9 #include "RelationalAccess/IQuery.h"
10 #include "RelationalAccess/ICursor.h"
11 #include "CoralBase/AttributeList.h"
12 #include "CoralBase/Attribute.h"
13 #include "CoralBase/AttributeSpecification.h"
14 //#include "SealBase/TimeInfo.h"
15 
17 
18 #include "CoralBase/TimeStamp.h"
19 
20 #include "boost/date_time/posix_time/posix_time.hpp"
21 #include "boost/date_time.hpp"
22 
23 #include <iostream>
24 #include <stdexcept>
25 #include <vector>
26 #include <cmath>
27 
29 
30  const std::string& connectionString, const std::string& user, const std::string& pass)
31  : TestBase(),
32 
33  m_connectionString(connectionString),
34  m_user(user),
35  m_pass(pass) {
36  m_tableToDrop = "";
37  // m_tableToRead="";
38  //m_columnToRead="";
39 }
40 
42 
44 
47  coral::ISession* session = this->connect(m_connectionString, m_user, m_pass);
48  session->transaction().start();
49  std::cout << "connected succesfully to omds" << std::endl;
50  coral::ISchema& schema = session->nominalSchema();
51  schema.dropIfExistsTable(m_tableToDrop);
52 }
53 
54 std::vector<L1TriggerScaler::Lumi> L1TriggerScalerRead::readData(const int r_number) {
55  // m_tableToRead = table; // to be cms_runinfo.runsession_parameter
56  // m_columnToRead= column; // to be string_value;
57 
58  /* query to execute
59 select * from runsession_parameter where string_value like '%[%' and name like 'CMS.TR%' order by time;
60 
61 % gets you the parameters of l1 trg
62 select * from runsession_parameter where string_value like '%[%' and name like 'CMS.TR%' and runnumber=51384 order by time;
63 
64 %what is the type?
65 select * from runsession_parameter_meta where name like 'CMS.TRG:GTLumiSegInfo';
66 
67 %what is the table for that type?
68 select * from runsession_type_meta where type like 'rcms.fm.fw.parameter.type.VectorT';
69 
70 % give me the data... value_id is the parent_id for the element
71 select * from runsession_vector where runsession_parameter_id = 3392114;
72 
73 % where is the table for that element type?
74 select * from runsession_type_meta where type like 'rcms.fm.fw.parameter.type.IntegerT';
75 
76 % what is the value of the element (of the vector)
77 select * from runsession_integer where parent_id = 3392118;
78 
79 */
80 
81  /* let's begin with a query to obtain the number of lumi section and the corresponding string value:
82 select string_value from runsession_parameter where string_value like '%[51384]' and name='CMS.TRG:GTLumiSegInfo' and runnumber=51384 order by time;
83 
84 */
85 
86  std::cout << "entering readData" << std::endl;
87  coral::ISession* session = this->connect(m_connectionString, m_user, m_pass);
88  session->transaction().start();
89  std::cout << "starting session " << std::endl;
90  coral::ISchema& schema = session->nominalSchema();
91  std::cout << " accessing schema " << std::endl;
92 
93  // queryI to access the string_format_value
94  coral::IQuery* query0 = schema.tableHandle("RUNSESSION_PARAMETER").newQuery();
95  std::cout << "table handling " << std::endl;
96  query0->addToOutputList("RUNSESSION_PARAMETER.STRING_VALUE", "STRING_VALUE");
97 
98  std::string condition0 =
99  "RUNSESSION_PARAMETER.RUNNUMBER=:n_run AND RUNSESSION_PARAMETER.NAME='CMS.TRG:GTLumiSegInfo_format'";
100  coral::AttributeList conditionData0;
101  conditionData0.extend<int>("n_run");
102  query0->setCondition(condition0, conditionData0);
103  conditionData0[0].data<int>() = r_number;
104  coral::ICursor& cursor0 = query0->execute();
105 
106  std::vector<L1TriggerScaler::Lumi> l1triggerscaler_array;
107 
108  std::string string_format;
109  while (cursor0.next() != 0) {
110  const coral::AttributeList& row = cursor0.currentRow();
111  std::cout << " entering the query == " << std::endl;
112  string_format = row["STRING_VALUE"].data<std::string>();
113 
114  std::cout << " string value extracted == " << string_format << std::endl;
115  }
116 
117  // queryI to access the id_value
118  coral::IQuery* queryI = schema.tableHandle("RUNSESSION_PARAMETER").newQuery();
119 
120  // queryI->addToTableList( m_tableToRead );
121  std::cout << "table handling " << std::endl;
122  // implemating the query here.......
123  // queryI->addToOutputList("RUNSESSION_PARAMETER.STRING_VALUE" , "STRING_VALUE");
124  queryI->addToOutputList("RUNSESSION_PARAMETER.ID", "ID");
125  // to add the starting time of the lumisection
126  queryI->addToOutputList("RUNSESSION_PARAMETER.TIME", "TIME");
127 
128  // condition
129  std::string condition =
130  "RUNSESSION_PARAMETER.RUNNUMBER=:n_run AND RUNSESSION_PARAMETER.NAME LIKE 'CMS.TRG:GTLumiSegInfo%' ORDER BY "
131  "TIME "; //AND RUNSESSION_PARAMETER.STRING_VALUE LIKE '%[%' ORDER BY TIME";
132  // controllare...................
133  coral::AttributeList conditionData;
134  conditionData.extend<int>("n_run");
135  queryI->setCondition(condition, conditionData);
136  conditionData[0].data<int>() = r_number;
137  coral::ICursor& cursorI = queryI->execute();
138 
139  std::vector<std::pair<int, long long> >
140  v_vid; // parent_id for value_id corresponding to each memeber of the lumi object, paired with his corresponding index to diceded the type
141 
142  if (cursorI.next() == 0) {
143  std::cout << " run " << r_number << " not full " << std::endl;
144  }
145  while (cursorI.next() != 0) {
146  // 1 cicle for each lumi
147  L1TriggerScaler::Lumi Itemp;
148  // if cursor is null setting null values
149  Itemp.m_runnumber = r_number;
150  // initializing the date string ...
151  Itemp.m_date = "0";
152  Itemp.m_string_format = string_format;
153  const coral::AttributeList& row = cursorI.currentRow();
154  std::cout << " entering the query == " << std::endl;
155  // Itemp.m_string_value= row["STRING_VALUE"].data<std::string>();
156 
157  // std::cout<< " string value extracted == " << Itemp.m_string_value << std::endl;
158  Itemp.m_lumi_id = row["ID"].data<long long>();
159  std::cout << " id value extracted == " << Itemp.m_lumi_id
160  << std::endl; // now we have the id and we can search and fill the lumi odject
161  // retrieving all the value_id one for each member of the lumi scaler
162 
163  coral::TimeStamp st = row["TIME"].data<coral::TimeStamp>();
164  int year = st.year();
165  int month = st.month();
166  int day = st.day();
167  int hour = st.hour();
168 
169  int minute = st.minute();
170  int second = st.second();
171  long nanosecond = st.nanosecond();
172  std::cout << " start time time extracted == "
173  << "-->year " << year << "-- month " << month << "-- day " << day << "-- hour " << hour << "-- minute "
174  << minute << "-- second " << second << std::endl;
175  boost::gregorian::date dt(year, month, day);
176  boost::posix_time::time_duration td(hour, minute, second, nanosecond / 1000);
177  boost::posix_time::ptime pt(dt, td);
178  Itemp.m_start_time = boost::posix_time::to_iso_extended_string(pt);
179  std::cout << " time extracted == " << Itemp.m_start_time << std::endl;
180 
181  coral::IQuery* queryII = schema.newQuery();
182  queryII->addToOutputList("RUNSESSION_VECTOR.VALUE_ID", "VALUE_ID");
183  queryII->addToOutputList("RUNSESSION_VECTOR.VALUE_INDEX", "VALUE_INDEX");
184 
185  queryII->addToTableList("RUNSESSION_VECTOR");
186  std::string condition2 = "RUNSESSION_VECTOR.PARENT_ID=:n_vid";
187  coral::AttributeList conditionData2;
188  conditionData2.extend<long>("n_vid");
189  queryII->setCondition(condition2, conditionData2);
190  conditionData2[0].data<long>() = Itemp.m_lumi_id + 1;
191  coral::ICursor& cursorII = queryII->execute();
192  while (cursorII.next() != 0) {
193  const coral::AttributeList& row = cursorII.currentRow();
194  std::cout << " entering the queryII == " << std::endl;
195  long long vid_val = row["VALUE_ID"].data<long long>();
196  int vid_id = (int)row["VALUE_INDEX"].data<long long>();
197  v_vid.push_back(std::make_pair(vid_id, vid_val));
198  std::cout << " value_id index extracted == " << v_vid.back().first << std::endl;
199  std::cout << " value_id value extracted == " << v_vid.back().second << std::endl;
200  // depending from the index, fill the object....
201 
202  coral::AttributeList conditionData3;
203  conditionData3.extend<int>("n_vid_val");
204  conditionData3[0].data<int>() = vid_val;
205  switch (vid_id) {
206  case 0: {
207  std::cout << " caso 0" << std::endl;
208  coral::IQuery* queryIII = schema.newQuery();
209  queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
210  queryIII->addToTableList("RUNSESSION_INTEGER");
211  std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
212  queryIII->setCondition(condition3, conditionData3);
213  coral::ICursor& cursorIII = queryIII->execute();
214 
215  while (cursorIII.next() != 0) {
216  const coral::AttributeList& row = cursorIII.currentRow();
217  // std::cout<< " entering the queryIII " << std::endl;
218  Itemp.m_rn = row["VALUE"].data<long long>();
219  std::cout << " run extracted == " << Itemp.m_rn << std::endl;
220  }
221  delete queryIII;
222  } break;
223  case 1: {
224  std::cout << " caso 1" << std::endl;
225  coral::IQuery* queryIII = schema.newQuery();
226  queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
227  queryIII->addToTableList("RUNSESSION_INTEGER");
228  std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
229  queryIII->setCondition(condition3, conditionData3);
230  coral::ICursor& cursorIII = queryIII->execute();
231  while (cursorIII.next() != 0) {
232  const coral::AttributeList& row = cursorIII.currentRow();
233  std::cout << " entering the queryIII " << std::endl;
234  Itemp.m_lumisegment = row["VALUE"].data<long long>();
235  std::cout << " lumisegment extracted == " << Itemp.m_lumisegment << std::endl;
236  }
237  delete queryIII;
238  } break;
239  case 2: {
240  std::cout << " caso 2" << std::endl;
241  /*
242  coral::IQuery* queryIII = schema.newQuery();
243  queryIII->addToOutputList("RUNSESSION_STRING.VALUE" , "VALUE");
244  queryIII->addToTableList("RUNSESSION_STRING");
245  std::string condition3 = "RUNSESSION_STRING.PARENT_ID=:n_vid_val";
246  queryIII->setCondition( condition3, conditionData3 );
247  coral::ICursor& cursorIII = queryIII->execute();
248  while ( cursorIII.next()!=0 ) {
249  const coral::AttributeList& row = cursorIII.currentRow();
250  std::cout<< " entering the queryIII " << std::endl;
251  Itemp.m_version = row["VALUE"].data<std::string>();
252  std::cout<< "version extracted == " << Itemp.m_version << std::endl;
253 
254  }
255  delete queryIII;
256  */
257  } break;
258  case 3: {
259  std::cout << " caso 3" << std::endl;
260  /*
261  coral::IQuery* queryIII = schema.newQuery();
262  queryIII->addToOutputList("RUNSESSION_STRING.VALUE" , "VALUE");
263  queryIII->addToTableList("RUNSESSION_STRING");
264  std::string condition3 = "RUNSESSION_STRING.PARENT_ID=:n_vid_val";
265  queryIII->setCondition( condition3, conditionData3 );
266  coral::ICursor& cursorIII = queryIII->execute();
267  while ( cursorIII.next()!=0 ) {
268  const coral::AttributeList& row = cursorIII.currentRow();
269  std::cout<< " entering the queryIII " << std::endl;
270  Itemp.m_context = row["VALUE"].data<std::string>();
271  std::cout<< " context extracted == " << Itemp.m_context << std::endl;
272 
273  }
274  delete queryIII;
275  */
276  } break;
277  case 4: {
278  std::cout << " caso 4" << std::endl;
279  coral::IQuery* queryIII = schema.newQuery();
280  queryIII->addToOutputList("RUNSESSION_DATE.VALUE", "VALUE");
281  queryIII->addToTableList("RUNSESSION_DATE");
282  std::string condition3 = "RUNSESSION_DATE.PARENT_ID=:n_vid_val";
283  queryIII->setCondition(condition3, conditionData3);
284  coral::ICursor& cursorIII = queryIII->execute();
285  if (cursorIII.next() != 0) {
286  const coral::AttributeList& row = cursorIII.currentRow();
287  std::cout << " entering the queryIII " << std::endl;
288  coral::TimeStamp ts = row["VALUE"].data<coral::TimeStamp>();
289  int year = ts.year();
290  int month = ts.month();
291  int day = ts.day();
292  int hour = ts.hour();
293 
294  int minute = ts.minute();
295  int second = ts.second();
296  long nanosecond = ts.nanosecond();
297  std::cout << " start time time extracted == "
298  << "-->year " << year << "-- month " << month << "-- day " << day << "-- hour " << hour
299  << "-- minute " << minute << "-- second " << second << std::endl;
300  boost::gregorian::date dt(year, month, day);
301  boost::posix_time::time_duration td(hour, minute, second, nanosecond / 1000);
302  boost::posix_time::ptime pt(dt, td);
303  Itemp.m_date = boost::posix_time::to_iso_extended_string(pt);
304  std::cout << " date extracted == " << Itemp.m_date << std::endl;
305  } else {
306  std::cout << "date extracted == " << Itemp.m_date << std::endl;
307  }
308  delete queryIII;
309  } break;
310  case 5: {
311  std::cout << " caso 5" << std::endl;
312  coral::IQuery* queryIII = schema.newQuery();
313  queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
314  queryIII->addToTableList("RUNSESSION_INTEGER");
315  std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
316  queryIII->setCondition(condition3, conditionData3);
317  coral::ICursor& cursorIII = queryIII->execute();
318  while (cursorIII.next() != 0) {
319  const coral::AttributeList& row = cursorIII.currentRow();
320  std::cout << " entering the queryIII " << std::endl;
321  int v = (int)row["VALUE"].data<long long>();
322  Itemp.m_GTAlgoCounts.push_back(v);
323  }
324 
325  delete queryIII;
326 
327  }
328 
329  break;
330  case 6: {
331  std::cout << " caso 6" << std::endl;
332  coral::IQuery* queryIII = schema.newQuery();
333  queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE", "VALUE");
334  queryIII->addToTableList("RUNSESSION_FLOAT");
335  std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
336  queryIII->setCondition(condition3, conditionData3);
337  coral::ICursor& cursorIII = queryIII->execute();
338  while (cursorIII.next() != 0) {
339  const coral::AttributeList& row = cursorIII.currentRow();
340  std::cout << " entering the queryIII " << std::endl;
341  float v = (float)row["VALUE"].data<double>();
342  Itemp.m_GTAlgoRates.push_back(v);
343  }
344 
345  delete queryIII;
346 
347  }
348 
349  break;
350 
351  case 7: {
352  std::cout << " caso 7" << std::endl;
353  coral::IQuery* queryIII = schema.newQuery();
354  queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
355  queryIII->addToTableList("RUNSESSION_INTEGER");
356  std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
357  queryIII->setCondition(condition3, conditionData3);
358  coral::ICursor& cursorIII = queryIII->execute();
359  while (cursorIII.next() != 0) {
360  const coral::AttributeList& row = cursorIII.currentRow();
361  std::cout << " entering the queryIII " << std::endl;
362  int v = (int)row["VALUE"].data<long long>();
363  Itemp.m_GTAlgoPrescaling.push_back(v);
364  }
365 
366  delete queryIII;
367 
368  }
369 
370  break;
371  case 8: {
372  std::cout << " caso 8" << std::endl;
373  coral::IQuery* queryIII = schema.newQuery();
374  queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
375  queryIII->addToTableList("RUNSESSION_INTEGER");
376  std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
377  queryIII->setCondition(condition3, conditionData3);
378  coral::ICursor& cursorIII = queryIII->execute();
379  while (cursorIII.next() != 0) {
380  const coral::AttributeList& row = cursorIII.currentRow();
381  std::cout << " entering the queryIII " << std::endl;
382  int v = (int)row["VALUE"].data<long long>();
383  Itemp.m_GTTechCounts.push_back(v);
384  }
385 
386  delete queryIII;
387 
388  }
389 
390  break;
391  case 9: {
392  std::cout << " caso 9" << std::endl;
393  coral::IQuery* queryIII = schema.newQuery();
394  queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE", "VALUE");
395  queryIII->addToTableList("RUNSESSION_FLOAT");
396  std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
397  queryIII->setCondition(condition3, conditionData3);
398  coral::ICursor& cursorIII = queryIII->execute();
399  while (cursorIII.next() != 0) {
400  const coral::AttributeList& row = cursorIII.currentRow();
401  std::cout << " entering the queryIII " << std::endl;
402  float v = (float)row["VALUE"].data<double>();
403  Itemp.m_GTTechRates.push_back(v);
404  }
405 
406  delete queryIII;
407 
408  }
409 
410  break;
411  case 10: {
412  std::cout << " caso 10" << std::endl;
413  coral::IQuery* queryIII = schema.newQuery();
414  queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
415  queryIII->addToTableList("RUNSESSION_INTEGER");
416  std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
417  queryIII->setCondition(condition3, conditionData3);
418  coral::ICursor& cursorIII = queryIII->execute();
419  while (cursorIII.next() != 0) {
420  const coral::AttributeList& row = cursorIII.currentRow();
421  std::cout << " entering the queryIII " << std::endl;
422  int v = (int)row["VALUE"].data<long long>();
423  Itemp.m_GTTechPrescaling.push_back(v);
424  }
425 
426  delete queryIII;
427 
428  }
429 
430  break;
431  case 11: {
432  std::cout << " caso 11" << std::endl;
433  coral::IQuery* queryIII = schema.newQuery();
434  queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
435  queryIII->addToTableList("RUNSESSION_INTEGER");
436  std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
437  queryIII->setCondition(condition3, conditionData3);
438  coral::ICursor& cursorIII = queryIII->execute();
439  while (cursorIII.next() != 0) {
440  const coral::AttributeList& row = cursorIII.currentRow();
441  std::cout << " entering the queryIII " << std::endl;
442  int v = (int)row["VALUE"].data<long long>();
443  Itemp.m_GTPartition0TriggerCounts.push_back(v);
444  }
445 
446  delete queryIII;
447 
448  }
449 
450  break;
451  case 12: {
452  std::cout << " caso 12" << std::endl;
453  coral::IQuery* queryIII = schema.newQuery();
454  queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE", "VALUE");
455  queryIII->addToTableList("RUNSESSION_FLOAT");
456  std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
457  queryIII->setCondition(condition3, conditionData3);
458  coral::ICursor& cursorIII = queryIII->execute();
459  while (cursorIII.next() != 0) {
460  const coral::AttributeList& row = cursorIII.currentRow();
461  std::cout << " entering the queryIII " << std::endl;
462  float v = (float)row["VALUE"].data<double>();
463  Itemp.m_GTPartition0TriggerRates.push_back(v);
464  }
465 
466  delete queryIII;
467 
468  }
469 
470  break;
471  case 13: {
472  std::cout << " caso 13" << std::endl;
473  coral::IQuery* queryIII = schema.newQuery();
474  queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
475  queryIII->addToTableList("RUNSESSION_INTEGER");
476  std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
477  queryIII->setCondition(condition3, conditionData3);
478  coral::ICursor& cursorIII = queryIII->execute();
479  while (cursorIII.next() != 0) {
480  const coral::AttributeList& row = cursorIII.currentRow();
481  std::cout << " entering the queryIII " << std::endl;
482  int v = (int)row["VALUE"].data<long long>();
483  Itemp.m_GTPartition0DeadTime.push_back(v);
484  }
485 
486  delete queryIII;
487 
488  }
489 
490  break;
491  case 14: {
492  std::cout << " caso 14" << std::endl;
493  coral::IQuery* queryIII = schema.newQuery();
494  queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE", "VALUE");
495  queryIII->addToTableList("RUNSESSION_FLOAT");
496  std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
497  queryIII->setCondition(condition3, conditionData3);
498  coral::ICursor& cursorIII = queryIII->execute();
499  while (cursorIII.next() != 0) {
500  const coral::AttributeList& row = cursorIII.currentRow();
501  std::cout << " entering the queryIII " << std::endl;
502  float v = (float)row["VALUE"].data<double>();
503  Itemp.m_GTPartition0DeadTimeRatio.push_back(v);
504  }
505 
506  delete queryIII;
507 
508  }
509 
510  break;
511 
512  default:
513  std::cout << "index out of range" << std::endl;
514  break;
515  }
516 
517  // l1triggerscaler_array.push_back(Itemp);
518  }
519  delete queryII;
520 
521  l1triggerscaler_array.push_back(Itemp);
522  }
523 
524  delete queryI;
525 
526  session->transaction().commit();
527  delete session;
528 
529  // std::cout<<"filling the lumi array to pass to the object" << std::endl;
530 
531  return l1triggerscaler_array;
532 }
float dt
Definition: AMPTWrapper.h:136
std::vector< float > m_GTAlgoRates
L1TriggerScalerRead(const std::string &connectionString, const std::string &user, const std::string &pass)
std::vector< int > m_GTTechCounts
std::vector< float > m_GTTechRates
std::vector< int > m_GTAlgoCounts
std::vector< int > m_GTTechPrescaling
U second(std::pair< T, U > const &p)
std::vector< float > m_GTPartition0DeadTimeRatio
std::vector< L1TriggerScaler::Lumi > readData(const int r_number)
std::vector< int > m_GTPartition0DeadTime
std::string m_connectionString
void dropTable(const std::string &table)
std::string m_string_format
std::vector< int > m_GTPartition0TriggerCounts
std::vector< float > m_GTPartition0TriggerRates
std::vector< int > m_GTAlgoPrescaling
def day(string)
Definition: getRunInfo.py:11
coral::ISession * connect(const std::string &connectionString, const std::string &user, const std::string &password)
Definition: TestBase.cc:23