Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:44

0001 #include "CondTools/DQM/interface/DQMSummaryReader.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "RelationalAccess/ISession.h"
0004 //#include "RelationalAccess/ISessionProxy.h"
0005 //#include "RelationalAccess/ITypeConverter.h"
0006 #include "RelationalAccess/ITransaction.h"
0007 #include "RelationalAccess/ISchema.h"
0008 #include "RelationalAccess/ITable.h"
0009 #include "RelationalAccess/ITableDataEditor.h"
0010 #include "RelationalAccess/TableDescription.h"
0011 #include "RelationalAccess/IQuery.h"
0012 #include "RelationalAccess/ICursor.h"
0013 #include "CoralBase/AttributeList.h"
0014 #include "CoralBase/Attribute.h"
0015 #include "CoralBase/AttributeSpecification.h"
0016 #include <iostream>
0017 #include <stdexcept>
0018 #include <vector>
0019 #include <cmath>
0020 
0021 DQMSummaryReader::DQMSummaryReader(const std::string& connectionString,
0022                                    const std::string& user,
0023                                    const std::string& pass)
0024     : TestBase(), /*ReadBase(),*/
0025       m_connectionString(connectionString),
0026       m_user(user),
0027       m_pass(pass) {
0028   m_tableToRead = "";
0029 }
0030 
0031 DQMSummaryReader::~DQMSummaryReader() {}
0032 
0033 void DQMSummaryReader::run() {}
0034 
0035 DQMSummary DQMSummaryReader::readData(const std::string& table,
0036                                       /*const std::string & column,*/ const long long r_number) {
0037   m_tableToRead = table;  // to be  CMS_DQM_SUMMARY.summarycontent
0038   //m_columnToRead = column;  // to be run, lumisec
0039   DQMSummary dqmSummary;
0040   dqmSummary.m_run = r_number;
0041   std::cout << "Entering readData" << std::endl;
0042   coral::ISession* session = this->connect(m_connectionString, m_user, m_pass);
0043   //coral::ISessionProxy* session = this->connect(m_connectionString,
0044   //                                              m_user, m_pass);
0045   try {
0046     //session->typeConverter().setCppTypeForSqlType(coral::AttributeSpecification::typeNameForId(typeid(std::string)), "VARCHAR2(20)");
0047     //session->typeConverter().setCppTypeForSqlType(coral::AttributeSpecification::typeNameForId(typeid(std::string)), "VARCHAR2(40)");
0048     session->transaction().start();
0049     std::cout << "Starting session on the connection " << m_connectionString << std::endl;
0050     coral::ISchema& schema = session->nominalSchema();
0051     std::cout << "--- accessing schema for user " << m_user << std::endl;
0052     std::cout << "------ trying to handle table " << m_tableToRead << std::endl;
0053     //defining count query
0054     coral::IQuery* query = schema.tableHandle(m_tableToRead).newQuery();
0055     query->addToOutputList("count(*)", "count");
0056     //condition for the WHERE clause in the count query
0057     std::string condition = "run=:n_run";
0058     coral::AttributeList conditionData;
0059     conditionData.extend<long long>("n_run");
0060     //conditionData[0].setValue<long long>(r_number);
0061     conditionData[0].data<long long>() = r_number;
0062     query->setCondition(condition, conditionData);
0063     //performing count query
0064     coral::ICursor& cursor = query->execute();
0065     DQMSummary::DQMSummary::RunItem runItem;
0066     DQMSummary::DQMSummary::RunItem::LumiItem lumiItem;
0067     double nRows = 0;
0068     if (cursor.next()) {
0069       //cursor.currentRow().toOutputStream(std::cout) << std::endl;
0070       const coral::AttributeList& row = cursor.currentRow();
0071       nRows = row["count"].data<double>();
0072       /*const coral::Attribute& count = cursor.currentRow()["count"];
0073     if(count.specification().type() == typeid(double))
0074       nRows = count.data<double>();
0075       else
0076       nRows = count.data<float>();*/
0077       std::cout << "Rows for count query " << nRows << std::endl;
0078       if (nRows != 0) {
0079         std::cout << "Starting to build DQMSummary" << std::endl;
0080         //defining first query
0081         coral::IQuery* queryI = schema.tableHandle(m_tableToRead).newQuery();
0082         queryI->setDistinct();
0083         queryI->addToOutputList("lumisec");
0084         //condition for the WHERE clause in the first query
0085         std::string conditionI = "run=:n_run";
0086         coral::AttributeList conditionDataI;
0087         conditionDataI.extend<long long>("n_run");
0088         //conditionDataI[0].setValue<long long>(r_number);
0089         conditionDataI[0].data<long long>() = r_number;
0090         queryI->setCondition(conditionI, conditionDataI);
0091         //performing query
0092         coral::ICursor& cursorI = queryI->execute();
0093         //a little printout, then filling DQMSummary
0094         int nRowsI = 0;
0095         while (cursorI.next()) {
0096           //cursorI.currentRow().toOutputStream(std::cout) << std::endl;
0097           ++nRowsI;
0098           const coral::AttributeList& rowI = cursorI.currentRow();
0099           runItem.m_lumisec = rowI["lumisec"].data<long long>();
0100           //defining second query
0101           coral::IQuery* queryII = schema.tableHandle(m_tableToRead).newQuery();
0102           queryII->addToOutputList("subsystem");
0103           queryII->addToOutputList("reportcontent");
0104           //queryII->addToOutputList("type"); // when implemented in OMDS
0105           queryII->addToOutputList("status");
0106           std::string conditionII = "run= :n_run AND lumisec= :n_lumisec";
0107           coral::AttributeList conditionDataII;
0108           conditionDataII.extend<long long>("n_run");
0109           //conditionDataII[0].setValue<long long>(r_number);
0110           conditionDataII[0].data<long long>() = r_number;
0111           conditionDataII.extend<long long>("n_lumisec");
0112           //conditionDataII[1].setValue<long long>(rowI["lumisec"].data<long long>());
0113           conditionDataII[1].data<long long>() = rowI["lumisec"].data<long long>();
0114           queryII->setCondition(conditionII, conditionDataII);
0115           //performing query
0116           coral::ICursor& cursorII = queryII->execute();
0117           //a little printout, then filling DQMSummary
0118           int nRowsII = 0;
0119           while (cursorII.next()) {
0120             //cursorII.currentRow().toOutputStream(std::cout) << std::endl;
0121             ++nRowsII;
0122             const coral::AttributeList& rowII = cursorII.currentRow();
0123             lumiItem.m_subsystem = rowII["subsystem"].data<std::string>();
0124             lumiItem.m_reportcontent = rowII["reportcontent"].data<std::string>();
0125             //lumiItem.m_type = rowII["type"].data<std::string>(); // when implemented in OMDS
0126             lumiItem.m_type = "reportSummary";
0127             lumiItem.m_status = rowII["status"].data<double>();
0128             runItem.m_lumisummary.push_back(lumiItem);
0129             std::cout << "DQMSummary::DQMSummary::RunItem::LumiItem filled" << std::endl;
0130           }
0131           std::cout << "Returned rows for lumisection query " << nRowsII << std::endl;
0132           dqmSummary.m_summary.push_back(runItem);
0133           std::cout << "DQMSummary::DQMSummary::RunItem filled" << std::endl;
0134           delete queryII;
0135         }
0136         std::cout << "Returned rows for run number query " << nRowsI << std::endl;
0137         delete queryI;
0138       } else {
0139         runItem.m_lumisec = 0;
0140         lumiItem.m_subsystem = " ";
0141         lumiItem.m_reportcontent = " ";
0142         lumiItem.m_type = " ";
0143         lumiItem.m_status = -2;
0144         std::cout << "[lumisec (long long) : " << runItem.m_lumisec
0145                   << "], [subsystem (string) : " << lumiItem.m_subsystem
0146                   << "], [reportcontent (string) : " << lumiItem.m_reportcontent
0147                   << "], [type (string) : " << lumiItem.m_type << "], [status (double) : " << lumiItem.m_status << "]"
0148                   << std::endl;
0149         runItem.m_lumisummary.push_back(lumiItem);
0150         dqmSummary.m_summary.push_back(runItem);
0151         std::cout << "No information in DQMSummary for run " << r_number << std::endl;
0152       }
0153     } else
0154       throw cms::Exception("UnconsistentData") << "What is wrong with you?" << std::endl;
0155     std::cout << "DQMSummary built" << std::endl;
0156     delete query;
0157     session->transaction().commit();
0158   } catch (const std::exception& e) {
0159     std::cout << "Exception: " << e.what() << std::endl;
0160   }
0161   delete session;
0162   return dqmSummary;
0163 }