File indexing completed on 2024-04-06 12:03:19
0001 #include "CondTools/RunInfo/interface/L1TriggerScalerRead.h"
0002
0003 #include "RelationalAccess/ISession.h"
0004 #include "RelationalAccess/ITransaction.h"
0005 #include "RelationalAccess/ISchema.h"
0006 #include "RelationalAccess/ITable.h"
0007 #include "RelationalAccess/ITableDataEditor.h"
0008 #include "RelationalAccess/TableDescription.h"
0009 #include "RelationalAccess/IQuery.h"
0010 #include "RelationalAccess/ICursor.h"
0011 #include "CoralBase/AttributeList.h"
0012 #include "CoralBase/Attribute.h"
0013 #include "CoralBase/AttributeSpecification.h"
0014
0015
0016 #include "CondCore/CondDB/interface/Time.h"
0017
0018 #include "CoralBase/TimeStamp.h"
0019
0020 #include "boost/date_time/posix_time/posix_time.hpp"
0021 #include "boost/date_time.hpp"
0022
0023 #include <iostream>
0024 #include <stdexcept>
0025 #include <vector>
0026 #include <cmath>
0027
0028 L1TriggerScalerRead::L1TriggerScalerRead(
0029
0030 const std::string& connectionString, const std::string& user, const std::string& pass)
0031 : TestBase(),
0032
0033 m_connectionString(connectionString),
0034 m_user(user),
0035 m_pass(pass) {
0036 m_tableToDrop = "";
0037
0038
0039 }
0040
0041 L1TriggerScalerRead::~L1TriggerScalerRead() {}
0042
0043 void L1TriggerScalerRead::run() {}
0044
0045 void L1TriggerScalerRead::dropTable(const std::string& table) {
0046 m_tableToDrop = table;
0047 coral::ISession* session = this->connect(m_connectionString, m_user, m_pass);
0048 session->transaction().start();
0049 std::cout << "connected succesfully to omds" << std::endl;
0050 coral::ISchema& schema = session->nominalSchema();
0051 schema.dropIfExistsTable(m_tableToDrop);
0052 }
0053
0054 std::vector<L1TriggerScaler::Lumi> L1TriggerScalerRead::readData(const int r_number) {
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 std::cout << "entering readData" << std::endl;
0087 coral::ISession* session = this->connect(m_connectionString, m_user, m_pass);
0088 session->transaction().start();
0089 std::cout << "starting session " << std::endl;
0090 coral::ISchema& schema = session->nominalSchema();
0091 std::cout << " accessing schema " << std::endl;
0092
0093
0094 coral::IQuery* query0 = schema.tableHandle("RUNSESSION_PARAMETER").newQuery();
0095 std::cout << "table handling " << std::endl;
0096 query0->addToOutputList("RUNSESSION_PARAMETER.STRING_VALUE", "STRING_VALUE");
0097
0098 std::string condition0 =
0099 "RUNSESSION_PARAMETER.RUNNUMBER=:n_run AND RUNSESSION_PARAMETER.NAME='CMS.TRG:GTLumiSegInfo_format'";
0100 coral::AttributeList conditionData0;
0101 conditionData0.extend<int>("n_run");
0102 query0->setCondition(condition0, conditionData0);
0103 conditionData0[0].data<int>() = r_number;
0104 coral::ICursor& cursor0 = query0->execute();
0105
0106 std::vector<L1TriggerScaler::Lumi> l1triggerscaler_array;
0107
0108 std::string string_format;
0109 while (cursor0.next() != 0) {
0110 const coral::AttributeList& row = cursor0.currentRow();
0111 std::cout << " entering the query == " << std::endl;
0112 string_format = row["STRING_VALUE"].data<std::string>();
0113
0114 std::cout << " string value extracted == " << string_format << std::endl;
0115 }
0116
0117
0118 coral::IQuery* queryI = schema.tableHandle("RUNSESSION_PARAMETER").newQuery();
0119
0120
0121 std::cout << "table handling " << std::endl;
0122
0123
0124 queryI->addToOutputList("RUNSESSION_PARAMETER.ID", "ID");
0125
0126 queryI->addToOutputList("RUNSESSION_PARAMETER.TIME", "TIME");
0127
0128
0129 std::string condition =
0130 "RUNSESSION_PARAMETER.RUNNUMBER=:n_run AND RUNSESSION_PARAMETER.NAME LIKE 'CMS.TRG:GTLumiSegInfo%' ORDER BY "
0131 "TIME ";
0132
0133 coral::AttributeList conditionData;
0134 conditionData.extend<int>("n_run");
0135 queryI->setCondition(condition, conditionData);
0136 conditionData[0].data<int>() = r_number;
0137 coral::ICursor& cursorI = queryI->execute();
0138
0139 std::vector<std::pair<int, long long> >
0140 v_vid;
0141
0142 if (cursorI.next() == 0) {
0143 std::cout << " run " << r_number << " not full " << std::endl;
0144 }
0145 while (cursorI.next() != 0) {
0146
0147 L1TriggerScaler::Lumi Itemp;
0148
0149 Itemp.m_runnumber = r_number;
0150
0151 Itemp.m_date = "0";
0152 Itemp.m_string_format = string_format;
0153 const coral::AttributeList& row = cursorI.currentRow();
0154 std::cout << " entering the query == " << std::endl;
0155
0156
0157
0158 Itemp.m_lumi_id = row["ID"].data<long long>();
0159 std::cout << " id value extracted == " << Itemp.m_lumi_id
0160 << std::endl;
0161
0162
0163 coral::TimeStamp st = row["TIME"].data<coral::TimeStamp>();
0164 int year = st.year();
0165 int month = st.month();
0166 int day = st.day();
0167 int hour = st.hour();
0168
0169 int minute = st.minute();
0170 int second = st.second();
0171 long nanosecond = st.nanosecond();
0172 std::cout << " start time time extracted == "
0173 << "-->year " << year << "-- month " << month << "-- day " << day << "-- hour " << hour << "-- minute "
0174 << minute << "-- second " << second << std::endl;
0175 boost::gregorian::date dt(year, month, day);
0176 boost::posix_time::time_duration td(hour, minute, second, nanosecond / 1000);
0177 boost::posix_time::ptime pt(dt, td);
0178 Itemp.m_start_time = boost::posix_time::to_iso_extended_string(pt);
0179 std::cout << " time extracted == " << Itemp.m_start_time << std::endl;
0180
0181 coral::IQuery* queryII = schema.newQuery();
0182 queryII->addToOutputList("RUNSESSION_VECTOR.VALUE_ID", "VALUE_ID");
0183 queryII->addToOutputList("RUNSESSION_VECTOR.VALUE_INDEX", "VALUE_INDEX");
0184
0185 queryII->addToTableList("RUNSESSION_VECTOR");
0186 std::string condition2 = "RUNSESSION_VECTOR.PARENT_ID=:n_vid";
0187 coral::AttributeList conditionData2;
0188 conditionData2.extend<long>("n_vid");
0189 queryII->setCondition(condition2, conditionData2);
0190 conditionData2[0].data<long>() = Itemp.m_lumi_id + 1;
0191 coral::ICursor& cursorII = queryII->execute();
0192 while (cursorII.next() != 0) {
0193 const coral::AttributeList& row = cursorII.currentRow();
0194 std::cout << " entering the queryII == " << std::endl;
0195 long long vid_val = row["VALUE_ID"].data<long long>();
0196 int vid_id = (int)row["VALUE_INDEX"].data<long long>();
0197 v_vid.push_back(std::make_pair(vid_id, vid_val));
0198 std::cout << " value_id index extracted == " << v_vid.back().first << std::endl;
0199 std::cout << " value_id value extracted == " << v_vid.back().second << std::endl;
0200
0201
0202 coral::AttributeList conditionData3;
0203 conditionData3.extend<int>("n_vid_val");
0204 conditionData3[0].data<int>() = vid_val;
0205 switch (vid_id) {
0206 case 0: {
0207 std::cout << " caso 0" << std::endl;
0208 coral::IQuery* queryIII = schema.newQuery();
0209 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
0210 queryIII->addToTableList("RUNSESSION_INTEGER");
0211 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
0212 queryIII->setCondition(condition3, conditionData3);
0213 coral::ICursor& cursorIII = queryIII->execute();
0214
0215 while (cursorIII.next() != 0) {
0216 const coral::AttributeList& row = cursorIII.currentRow();
0217
0218 Itemp.m_rn = row["VALUE"].data<long long>();
0219 std::cout << " run extracted == " << Itemp.m_rn << std::endl;
0220 }
0221 delete queryIII;
0222 } break;
0223 case 1: {
0224 std::cout << " caso 1" << std::endl;
0225 coral::IQuery* queryIII = schema.newQuery();
0226 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
0227 queryIII->addToTableList("RUNSESSION_INTEGER");
0228 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
0229 queryIII->setCondition(condition3, conditionData3);
0230 coral::ICursor& cursorIII = queryIII->execute();
0231 while (cursorIII.next() != 0) {
0232 const coral::AttributeList& row = cursorIII.currentRow();
0233 std::cout << " entering the queryIII " << std::endl;
0234 Itemp.m_lumisegment = row["VALUE"].data<long long>();
0235 std::cout << " lumisegment extracted == " << Itemp.m_lumisegment << std::endl;
0236 }
0237 delete queryIII;
0238 } break;
0239 case 2: {
0240 std::cout << " caso 2" << std::endl;
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257 } break;
0258 case 3: {
0259 std::cout << " caso 3" << std::endl;
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276 } break;
0277 case 4: {
0278 std::cout << " caso 4" << std::endl;
0279 coral::IQuery* queryIII = schema.newQuery();
0280 queryIII->addToOutputList("RUNSESSION_DATE.VALUE", "VALUE");
0281 queryIII->addToTableList("RUNSESSION_DATE");
0282 std::string condition3 = "RUNSESSION_DATE.PARENT_ID=:n_vid_val";
0283 queryIII->setCondition(condition3, conditionData3);
0284 coral::ICursor& cursorIII = queryIII->execute();
0285 if (cursorIII.next() != 0) {
0286 const coral::AttributeList& row = cursorIII.currentRow();
0287 std::cout << " entering the queryIII " << std::endl;
0288 coral::TimeStamp ts = row["VALUE"].data<coral::TimeStamp>();
0289 int year = ts.year();
0290 int month = ts.month();
0291 int day = ts.day();
0292 int hour = ts.hour();
0293
0294 int minute = ts.minute();
0295 int second = ts.second();
0296 long nanosecond = ts.nanosecond();
0297 std::cout << " start time time extracted == "
0298 << "-->year " << year << "-- month " << month << "-- day " << day << "-- hour " << hour
0299 << "-- minute " << minute << "-- second " << second << std::endl;
0300 boost::gregorian::date dt(year, month, day);
0301 boost::posix_time::time_duration td(hour, minute, second, nanosecond / 1000);
0302 boost::posix_time::ptime pt(dt, td);
0303 Itemp.m_date = boost::posix_time::to_iso_extended_string(pt);
0304 std::cout << " date extracted == " << Itemp.m_date << std::endl;
0305 } else {
0306 std::cout << "date extracted == " << Itemp.m_date << std::endl;
0307 }
0308 delete queryIII;
0309 } break;
0310 case 5: {
0311 std::cout << " caso 5" << std::endl;
0312 coral::IQuery* queryIII = schema.newQuery();
0313 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
0314 queryIII->addToTableList("RUNSESSION_INTEGER");
0315 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
0316 queryIII->setCondition(condition3, conditionData3);
0317 coral::ICursor& cursorIII = queryIII->execute();
0318 while (cursorIII.next() != 0) {
0319 const coral::AttributeList& row = cursorIII.currentRow();
0320 std::cout << " entering the queryIII " << std::endl;
0321 int v = (int)row["VALUE"].data<long long>();
0322 Itemp.m_GTAlgoCounts.push_back(v);
0323 }
0324
0325 delete queryIII;
0326
0327 }
0328
0329 break;
0330 case 6: {
0331 std::cout << " caso 6" << std::endl;
0332 coral::IQuery* queryIII = schema.newQuery();
0333 queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE", "VALUE");
0334 queryIII->addToTableList("RUNSESSION_FLOAT");
0335 std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
0336 queryIII->setCondition(condition3, conditionData3);
0337 coral::ICursor& cursorIII = queryIII->execute();
0338 while (cursorIII.next() != 0) {
0339 const coral::AttributeList& row = cursorIII.currentRow();
0340 std::cout << " entering the queryIII " << std::endl;
0341 float v = (float)row["VALUE"].data<double>();
0342 Itemp.m_GTAlgoRates.push_back(v);
0343 }
0344
0345 delete queryIII;
0346
0347 }
0348
0349 break;
0350
0351 case 7: {
0352 std::cout << " caso 7" << std::endl;
0353 coral::IQuery* queryIII = schema.newQuery();
0354 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
0355 queryIII->addToTableList("RUNSESSION_INTEGER");
0356 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
0357 queryIII->setCondition(condition3, conditionData3);
0358 coral::ICursor& cursorIII = queryIII->execute();
0359 while (cursorIII.next() != 0) {
0360 const coral::AttributeList& row = cursorIII.currentRow();
0361 std::cout << " entering the queryIII " << std::endl;
0362 int v = (int)row["VALUE"].data<long long>();
0363 Itemp.m_GTAlgoPrescaling.push_back(v);
0364 }
0365
0366 delete queryIII;
0367
0368 }
0369
0370 break;
0371 case 8: {
0372 std::cout << " caso 8" << std::endl;
0373 coral::IQuery* queryIII = schema.newQuery();
0374 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
0375 queryIII->addToTableList("RUNSESSION_INTEGER");
0376 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
0377 queryIII->setCondition(condition3, conditionData3);
0378 coral::ICursor& cursorIII = queryIII->execute();
0379 while (cursorIII.next() != 0) {
0380 const coral::AttributeList& row = cursorIII.currentRow();
0381 std::cout << " entering the queryIII " << std::endl;
0382 int v = (int)row["VALUE"].data<long long>();
0383 Itemp.m_GTTechCounts.push_back(v);
0384 }
0385
0386 delete queryIII;
0387
0388 }
0389
0390 break;
0391 case 9: {
0392 std::cout << " caso 9" << std::endl;
0393 coral::IQuery* queryIII = schema.newQuery();
0394 queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE", "VALUE");
0395 queryIII->addToTableList("RUNSESSION_FLOAT");
0396 std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
0397 queryIII->setCondition(condition3, conditionData3);
0398 coral::ICursor& cursorIII = queryIII->execute();
0399 while (cursorIII.next() != 0) {
0400 const coral::AttributeList& row = cursorIII.currentRow();
0401 std::cout << " entering the queryIII " << std::endl;
0402 float v = (float)row["VALUE"].data<double>();
0403 Itemp.m_GTTechRates.push_back(v);
0404 }
0405
0406 delete queryIII;
0407
0408 }
0409
0410 break;
0411 case 10: {
0412 std::cout << " caso 10" << std::endl;
0413 coral::IQuery* queryIII = schema.newQuery();
0414 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
0415 queryIII->addToTableList("RUNSESSION_INTEGER");
0416 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
0417 queryIII->setCondition(condition3, conditionData3);
0418 coral::ICursor& cursorIII = queryIII->execute();
0419 while (cursorIII.next() != 0) {
0420 const coral::AttributeList& row = cursorIII.currentRow();
0421 std::cout << " entering the queryIII " << std::endl;
0422 int v = (int)row["VALUE"].data<long long>();
0423 Itemp.m_GTTechPrescaling.push_back(v);
0424 }
0425
0426 delete queryIII;
0427
0428 }
0429
0430 break;
0431 case 11: {
0432 std::cout << " caso 11" << std::endl;
0433 coral::IQuery* queryIII = schema.newQuery();
0434 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
0435 queryIII->addToTableList("RUNSESSION_INTEGER");
0436 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
0437 queryIII->setCondition(condition3, conditionData3);
0438 coral::ICursor& cursorIII = queryIII->execute();
0439 while (cursorIII.next() != 0) {
0440 const coral::AttributeList& row = cursorIII.currentRow();
0441 std::cout << " entering the queryIII " << std::endl;
0442 int v = (int)row["VALUE"].data<long long>();
0443 Itemp.m_GTPartition0TriggerCounts.push_back(v);
0444 }
0445
0446 delete queryIII;
0447
0448 }
0449
0450 break;
0451 case 12: {
0452 std::cout << " caso 12" << std::endl;
0453 coral::IQuery* queryIII = schema.newQuery();
0454 queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE", "VALUE");
0455 queryIII->addToTableList("RUNSESSION_FLOAT");
0456 std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
0457 queryIII->setCondition(condition3, conditionData3);
0458 coral::ICursor& cursorIII = queryIII->execute();
0459 while (cursorIII.next() != 0) {
0460 const coral::AttributeList& row = cursorIII.currentRow();
0461 std::cout << " entering the queryIII " << std::endl;
0462 float v = (float)row["VALUE"].data<double>();
0463 Itemp.m_GTPartition0TriggerRates.push_back(v);
0464 }
0465
0466 delete queryIII;
0467
0468 }
0469
0470 break;
0471 case 13: {
0472 std::cout << " caso 13" << std::endl;
0473 coral::IQuery* queryIII = schema.newQuery();
0474 queryIII->addToOutputList("RUNSESSION_INTEGER.VALUE", "VALUE");
0475 queryIII->addToTableList("RUNSESSION_INTEGER");
0476 std::string condition3 = "RUNSESSION_INTEGER.PARENT_ID=:n_vid_val";
0477 queryIII->setCondition(condition3, conditionData3);
0478 coral::ICursor& cursorIII = queryIII->execute();
0479 while (cursorIII.next() != 0) {
0480 const coral::AttributeList& row = cursorIII.currentRow();
0481 std::cout << " entering the queryIII " << std::endl;
0482 int v = (int)row["VALUE"].data<long long>();
0483 Itemp.m_GTPartition0DeadTime.push_back(v);
0484 }
0485
0486 delete queryIII;
0487
0488 }
0489
0490 break;
0491 case 14: {
0492 std::cout << " caso 14" << std::endl;
0493 coral::IQuery* queryIII = schema.newQuery();
0494 queryIII->addToOutputList("RUNSESSION_FLOAT.VALUE", "VALUE");
0495 queryIII->addToTableList("RUNSESSION_FLOAT");
0496 std::string condition3 = "RUNSESSION_FLOAT.PARENT_ID=:n_vid_val";
0497 queryIII->setCondition(condition3, conditionData3);
0498 coral::ICursor& cursorIII = queryIII->execute();
0499 while (cursorIII.next() != 0) {
0500 const coral::AttributeList& row = cursorIII.currentRow();
0501 std::cout << " entering the queryIII " << std::endl;
0502 float v = (float)row["VALUE"].data<double>();
0503 Itemp.m_GTPartition0DeadTimeRatio.push_back(v);
0504 }
0505
0506 delete queryIII;
0507
0508 }
0509
0510 break;
0511
0512 default:
0513 std::cout << "index out of range" << std::endl;
0514 break;
0515 }
0516
0517
0518 }
0519 delete queryII;
0520
0521 l1triggerscaler_array.push_back(Itemp);
0522 }
0523
0524 delete queryI;
0525
0526 session->transaction().commit();
0527 delete session;
0528
0529
0530
0531 return l1triggerscaler_array;
0532 }