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