CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CondTools/DQM/src/DQMSummaryReader.cc

Go to the documentation of this file.
00001 #include "CondTools/DQM/interface/DQMSummaryReader.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include "RelationalAccess/ISession.h"
00004 //#include "RelationalAccess/ISessionProxy.h"
00005 //#include "RelationalAccess/ITypeConverter.h"
00006 #include "RelationalAccess/ITransaction.h"
00007 #include "RelationalAccess/ISchema.h"
00008 #include "RelationalAccess/ITable.h"
00009 #include "RelationalAccess/ITableDataEditor.h"
00010 #include "RelationalAccess/TableDescription.h"
00011 #include "RelationalAccess/IQuery.h"
00012 #include "RelationalAccess/ICursor.h"
00013 #include "CoralBase/AttributeList.h"
00014 #include "CoralBase/Attribute.h"
00015 #include "CoralBase/AttributeSpecification.h"
00016 #include <iostream>
00017 #include <stdexcept>
00018 #include <vector>
00019 #include <cmath>
00020 
00021 DQMSummaryReader::DQMSummaryReader(const std::string& connectionString,
00022                                    const std::string& user,
00023                                    const std::string& pass):
00024   TestBase(), /*ReadBase(),*/
00025   m_connectionString( connectionString ),
00026   m_user( user ),
00027   m_pass( pass ) {
00028   m_tableToRead="";
00029 }
00030 
00031 DQMSummaryReader::~DQMSummaryReader() {}
00032 
00033 void DQMSummaryReader::run() {}
00034 
00035 DQMSummary DQMSummaryReader::readData(const std::string & table, /*const std::string & column,*/ const long long r_number) {
00036   m_tableToRead = table; // to be  CMS_DQM_SUMMARY.summarycontent
00037   //m_columnToRead = column;  // to be run, lumisec
00038   DQMSummary dqmSummary;
00039   dqmSummary.m_run = r_number;
00040   std::cout<< "Entering readData" << std::endl;
00041   coral::ISession* session = this->connect(m_connectionString,
00042                                            m_user, m_pass);
00043   //coral::ISessionProxy* session = this->connect(m_connectionString,
00044   //                                              m_user, m_pass);
00045   try{
00046     //session->typeConverter().setCppTypeForSqlType(coral::AttributeSpecification::typeNameForId(typeid(std::string)), "VARCHAR2(20)");
00047     //session->typeConverter().setCppTypeForSqlType(coral::AttributeSpecification::typeNameForId(typeid(std::string)), "VARCHAR2(40)");
00048     session->transaction().start();
00049     std::cout<< "Starting session on the connection " << m_connectionString << std::endl;
00050     coral::ISchema& schema = session->nominalSchema();
00051     std::cout<< "--- accessing schema for user " << m_user << std::endl;
00052     std::cout<< "------ trying to handle table " << m_tableToRead << std::endl;
00053     //defining count query
00054     coral::IQuery* query = schema.tableHandle(m_tableToRead).newQuery();
00055     query->addToOutputList("count(*)", "count");
00056     //condition for the WHERE clause in the count query
00057     std::string condition = "run=:n_run";
00058     coral::AttributeList conditionData;
00059     conditionData.extend<long long>( "n_run" );
00060     //conditionData[0].setValue<long long>(r_number); 
00061     conditionData[0].data<long long>() = r_number;
00062     query->setCondition(condition, conditionData);
00063     //performing count query
00064     coral::ICursor& cursor = query->execute();
00065     DQMSummary::DQMSummary::RunItem runItem;
00066     DQMSummary::DQMSummary::RunItem::LumiItem lumiItem;
00067     double nRows = 0;
00068     if( cursor.next() ) {
00069       //cursor.currentRow().toOutputStream(std::cout) << std::endl;
00070       const coral::AttributeList& row = cursor.currentRow();
00071       nRows = row["count"].data<double>();
00072       /*const coral::Attribute& count = cursor.currentRow()["count"];
00073         if(count.specification().type() == typeid(double))
00074       nRows = count.data<double>();
00075       else
00076       nRows = count.data<float>();*/
00077       std::cout << "Rows for count query " << nRows << std::endl;
00078       if( nRows != 0 ) {
00079         std::cout << "Starting to build DQMSummary" << std::endl;
00080         //defining first query
00081         coral::IQuery* queryI = schema.tableHandle(m_tableToRead).newQuery();
00082         queryI->setDistinct();
00083         queryI->addToOutputList("lumisec");
00084         //condition for the WHERE clause in the first query
00085         std::string conditionI = "run=:n_run";
00086         coral::AttributeList conditionDataI;
00087         conditionDataI.extend<long long>( "n_run" );
00088         //conditionDataI[0].setValue<long long>(r_number); 
00089         conditionDataI[0].data<long long>() = r_number;
00090         queryI->setCondition(conditionI, conditionDataI);
00091         //performing query
00092         coral::ICursor& cursorI = queryI->execute();
00093         //a little printout, then filling DQMSummary
00094         int nRowsI = 0;
00095         while( cursorI.next() ) {
00096           //cursorI.currentRow().toOutputStream(std::cout) << std::endl;
00097           ++nRowsI;
00098           const coral::AttributeList& rowI = cursorI.currentRow();
00099           runItem.m_lumisec = rowI["lumisec"].data<long long>();
00100           //defining second query
00101           coral::IQuery* queryII = schema.tableHandle(m_tableToRead).newQuery();
00102           queryII->addToOutputList("subsystem");
00103           queryII->addToOutputList("reportcontent");
00104           //queryII->addToOutputList("type"); // when implemented in OMDS
00105           queryII->addToOutputList("status");
00106           std::string conditionII = "run= :n_run AND lumisec= :n_lumisec";
00107           coral::AttributeList conditionDataII;
00108           conditionDataII.extend<long long>( "n_run" );
00109           //conditionDataII[0].setValue<long long>(r_number); 
00110           conditionDataII[0].data<long long>() = r_number;
00111           conditionDataII.extend<long long>( "n_lumisec" );
00112           //conditionDataII[1].setValue<long long>(rowI["lumisec"].data<long long>()); 
00113           conditionDataII[1].data<long long>() = rowI["lumisec"].data<long long>();
00114           queryII->setCondition(conditionII, conditionDataII);
00115           //performing query
00116           coral::ICursor& cursorII = queryII->execute();
00117           //a little printout, then filling DQMSummary
00118           int nRowsII = 0;
00119           while( cursorII.next() ) {
00120             //cursorII.currentRow().toOutputStream(std::cout) << std::endl;
00121             ++nRowsII;
00122             const coral::AttributeList& rowII = cursorII.currentRow();
00123             lumiItem.m_subsystem = rowII["subsystem"].data<std::string>();
00124             lumiItem.m_reportcontent = rowII["reportcontent"].data<std::string>();
00125             //lumiItem.m_type = rowII["type"].data<std::string>(); // when implemented in OMDS
00126             lumiItem.m_type = "reportSummary";
00127             lumiItem.m_status = rowII["status"].data<double>();
00128             runItem.m_lumisummary.push_back(lumiItem);
00129             std::cout << "DQMSummary::DQMSummary::RunItem::LumiItem filled" << std::endl;
00130           }
00131           std::cout << "Returned rows for lumisection query " << nRowsII << std::endl;
00132           dqmSummary.m_summary.push_back(runItem);
00133           std::cout << "DQMSummary::DQMSummary::RunItem filled" << std::endl;
00134           delete queryII;
00135         }
00136         std::cout << "Returned rows for run number query " << nRowsI << std::endl;
00137         delete queryI;
00138       }
00139       else {
00140         runItem.m_lumisec = 0;
00141         lumiItem.m_subsystem = " ";
00142         lumiItem.m_reportcontent = " ";
00143         lumiItem.m_type = " ";
00144         lumiItem.m_status = -2;
00145         std::cout << "[lumisec (long long) : " << runItem.m_lumisec
00146                   << "], [subsystem (string) : " << lumiItem.m_subsystem
00147                   << "], [reportcontent (string) : " << lumiItem.m_reportcontent
00148                   << "], [type (string) : " << lumiItem.m_type
00149                   << "], [status (double) : " << lumiItem.m_status
00150                   << "]" << std::endl;
00151         runItem.m_lumisummary.push_back(lumiItem);
00152         dqmSummary.m_summary.push_back(runItem);
00153         std::cout << "No information in DQMSummary for run " 
00154                   << r_number <<std::endl;
00155       }
00156     }
00157     else 
00158       throw cms::Exception("UnconsistentData") << "What is wrong with you?" << std::endl;
00159     std::cout << "DQMSummary built" << std::endl;
00160     delete query;
00161     session->transaction().commit();
00162   } 
00163   catch (const std::exception& e) { 
00164     std::cout << "Exception: "<<e.what()<<std::endl; 
00165   }
00166   delete session;
00167   return dqmSummary;
00168 }