CMS 3D CMS Logo

RPCFw.cc

Go to the documentation of this file.
00001  /* 
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2008/07/17 16:33:19 $
00005  *  $Revision: 1.3 $
00006  *  \author D. Pagano - Dip. Fis. Nucl. e Teo. & INFN Pavia
00007  */
00008 
00009 #include "RPCFw.h"
00010 #include "TimeConv.h"
00011 #include "RelationalAccess/ISession.h"
00012 #include "RelationalAccess/ITransaction.h"
00013 #include "RelationalAccess/ISchema.h"
00014 #include "RelationalAccess/ITable.h"
00015 #include "RelationalAccess/ITableDataEditor.h"
00016 #include "RelationalAccess/TableDescription.h"
00017 #include "RelationalAccess/IQuery.h"
00018 #include "RelationalAccess/ICursor.h"
00019 #include "CoralBase/AttributeList.h"
00020 #include "CoralBase/Attribute.h"
00021 #include "CoralBase/AttributeSpecification.h"
00022 #include "SealBase/TimeInfo.h"
00023 #include <iostream>
00024 #include <stdexcept>
00025 #include <vector>
00026 #include <math.h>
00027 
00028 RPCFw::RPCFw( const std::string& connectionString,
00029               const std::string& userName,
00030               const std::string& password):
00031   TestBase(),
00032   m_connectionString( connectionString ),
00033   m_userName( userName ),
00034   m_password( password )
00035 {}
00036 
00037 
00038 RPCFw::~RPCFw()
00039 {}
00040 
00041 void
00042 RPCFw::run()
00043 {
00044 }
00045 
00046 
00047 //----------------------------- I M O N ------------------------------------------------------------------------
00048 std::vector<RPCdbData::Item> RPCFw::createIMON(int from)
00049 {
00050   thr = UTtoT(from);
00051   std::cout <<">> Processing since: "<<thr.day()<<"/"<<thr.month()<<"/"<<thr.year()<<" "<<thr.hour()<<":"<<thr.minute()<<"."<<thr.second()<< std::endl;
00052   //coral::TimeStamp thr = coral::TimeStamp(2007,11,2,03,11,00,00);
00053  
00054   coral::ISession* session = this->connect( m_connectionString,
00055                                             m_userName, m_password );
00056   session->transaction().start( true );
00057   coral::ISchema& schema = session->nominalSchema();
00058   int nRows = 0;
00059   std::cout << ">> creating IMON object..." << std::endl;
00060   coral::IQuery* queryI = schema.newQuery();
00061   queryI->addToTableList( "FWCAENCHANNEL" );
00062   queryI->addToOutputList( "FWCAENCHANNEL.DPID", "DPID" );
00063   queryI->addToOutputList( "FWCAENCHANNEL.CHANGE_DATE", "TSTAMP" );
00064   queryI->addToOutputList( "FWCAENCHANNEL.ACTUAL_IMON", "IMON" );
00065   std::string condI = "FWCAENCHANNEL.ACTUAL_IMON is not NULL AND ";
00066 
00067   std::string condition = "FWCAENCHANNEL.ACTUAL_IMON is not NULL AND FWCAENCHANNEL.CHANGE_DATE >:tmax";
00068   coral::AttributeList conditionData;
00069   conditionData.extend<coral::TimeStamp>( "tmax" );
00070   queryI->setCondition( condition, conditionData );
00071   conditionData[0].data<coral::TimeStamp>() = thr;
00072   coral::ICursor& cursorI = queryI->execute();
00073 
00074   RPCdbData::Item Itemp;
00075   std::vector<RPCdbData::Item> imonarray;
00076   while ( cursorI.next() ) {
00077     const coral::AttributeList& row = cursorI.currentRow();
00078     float idoub = row["DPID"].data<float>();
00079     int id = static_cast<int>(idoub);
00080     float val = row["IMON"].data<float>();
00081     coral::TimeStamp ts =  row["TSTAMP"].data<coral::TimeStamp>();
00082     int ndate = (ts.day() * 10000) + (ts.month() * 100) + (ts.year()-2000);
00083     int ntime = (ts.hour() * 10000) + (ts.minute() * 100) + ts.second();
00084 
00085     Itemp.dpid = id;
00086     Itemp.value = val;
00087     Itemp.day = ndate;
00088     Itemp.time = ntime;
00089     imonarray.push_back(Itemp);
00090 
00091     ++nRows;
00092   }
00093   
00094 
00095   std::cout << ">> Imon array --> size: " << imonarray.size() << " >> done." << std::endl;
00096   delete queryI;
00097   session->transaction().commit();
00098   delete session;
00099   return imonarray;
00100 }
00101 
00102 
00103 
00104 //------------------------------------------------------- V M O N ---------------------------------------------------
00105 std::vector<RPCdbData::Item> RPCFw::createVMON(int from)
00106 {
00107   thr = UTtoT(from);
00108   std::cout <<">> Processing since: "<<thr.day()<<"/"<<thr.month()<<"/"<<thr.year()<<" "<<thr.hour()<<":"<<thr.minute()<<"."<<thr.second()<< std::endl;
00109   //coral::TimeStamp thr = this->lastValue();
00110   //coral::TimeStamp thr = coral::TimeStamp(2007,11,2,03,11,00,00);
00111 
00112   coral::ISession* session = this->connect( m_connectionString,
00113                                             m_userName, m_password );
00114   session->transaction().start( true );
00115   coral::ISchema& schema = session->nominalSchema();
00116   int nRows = 0;
00117   std::cout << ">> creating VMON object..." << std::endl;
00118   coral::IQuery* queryV = schema.newQuery();
00119   queryV->addToTableList( "FWCAENCHANNEL" );
00120   queryV->addToOutputList( "FWCAENCHANNEL.DPID", "DPID" );
00121   queryV->addToOutputList( "FWCAENCHANNEL.CHANGE_DATE", "TSTAMP" );
00122   queryV->addToOutputList( "FWCAENCHANNEL.ACTUAL_VMON", "VMON" );
00123   std::string condV = "FWCAENCHANNEL.ACTUAL_VMON is not NULL";
00124   
00125   std::string condition = "FWCAENCHANNEL.ACTUAL_VMON is not NULL AND FWCAENCHANNEL.CHANGE_DATE >:tmax";
00126   coral::AttributeList conditionData;
00127   conditionData.extend<coral::TimeStamp>( "tmax" );
00128   queryV->setCondition( condition, conditionData );
00129   conditionData[0].data<coral::TimeStamp>() = thr;
00130   coral::ICursor& cursorV = queryV->execute();
00131 
00132   RPCdbData::Item Vtemp;
00133   std::vector<RPCdbData::Item> vmonarray;
00134   while ( cursorV.next() ) {
00135     const coral::AttributeList& row = cursorV.currentRow();
00136     float idoub = row["DPID"].data<float>();
00137     int id = static_cast<int>(idoub);
00138     float val = row["VMON"].data<float>();
00139     coral::TimeStamp ts =  row["TSTAMP"].data<coral::TimeStamp>();
00140     int ndate = (ts.day() * 10000) + (ts.month() * 100) + (ts.year()-2000);
00141     int ntime = (ts.hour() * 10000) + (ts.minute() * 100) + ts.second();
00142 
00143     Vtemp.dpid = id;
00144     Vtemp.value = val;
00145     Vtemp.day = ndate;
00146     Vtemp.time = ntime;
00147     vmonarray.push_back(Vtemp);
00148 
00149     ++nRows;
00150   }
00151   std::cout << ">> Vmon array --> size: " << vmonarray.size() << " >> done." << std::endl;
00152   delete queryV;
00153   session->transaction().commit();
00154   delete session;
00155   return vmonarray;
00156 }
00157 
00158 
00159 //------------------------------ S T A T U S ---------------------------------------------------------------------
00160 std::vector<RPCdbData::Item> RPCFw::createSTATUS(int from)
00161 {
00162   thr = UTtoT(from);
00163   std::cout <<">> Processing since: "<<thr.day()<<"/"<<thr.month()<<"/"<<thr.year()<<" "<<thr.hour()<<":"<<thr.minute()<<"."<<thr.second()<< std::endl;
00164   //coral::TimeStamp thr = this->lastValue();
00165   //coral::TimeStamp thr = coral::TimeStamp(2007,11,2,03,11,00,00);
00166 
00167   coral::ISession* session = this->connect( m_connectionString,
00168                                             m_userName, m_password );
00169   session->transaction().start( true );
00170   coral::ISchema& schema = session->nominalSchema();
00171   int nRows = 0;
00172   std::cout << ">> creating STATUS object..." << std::endl;
00173   coral::IQuery* queryS = schema.newQuery();
00174   queryS->addToTableList( "FWCAENCHANNEL" );
00175   queryS->addToOutputList( "FWCAENCHANNEL.DPID", "DPID" );
00176   queryS->addToOutputList( "FWCAENCHANNEL.CHANGE_DATE", "TSTAMP" );
00177   queryS->addToOutputList( "FWCAENCHANNEL.ACTUAL_STATUS", "STATUS" );
00178   std::string condS = "FWCAENCHANNEL.ACTUAL_STATUS is not NULL";
00179 
00180   std::string condition = "FWCAENCHANNEL.ACTUAL_STATUS is not NULL AND FWCAENCHANNEL.CHANGE_DATE >:tmax";
00181   coral::AttributeList conditionData;
00182   conditionData.extend<coral::TimeStamp>( "tmax" );
00183   queryS->setCondition( condition, conditionData );
00184   conditionData[0].data<coral::TimeStamp>() = thr;
00185   coral::ICursor& cursorS = queryS->execute();
00186 
00187   RPCdbData::Item Stemp;
00188   std::vector<RPCdbData::Item> statusarray;
00189   while ( cursorS.next() ) {
00190     const coral::AttributeList& row = cursorS.currentRow();
00191     float idoub = row["DPID"].data<float>();
00192     int id = static_cast<int>(idoub);
00193     float val = row["STATUS"].data<float>();
00194     coral::TimeStamp ts =  row["TSTAMP"].data<coral::TimeStamp>();
00195     int ndate = (ts.day() * 10000) + (ts.month() * 100) + (ts.year()-2000);
00196     int ntime = (ts.hour() * 10000) + (ts.minute() * 100) + ts.second();
00197 
00198     Stemp.dpid = id;
00199     Stemp.value = val;
00200     Stemp.day = ndate;
00201     Stemp.time = ntime;
00202     statusarray.push_back(Stemp);
00203 
00204     ++nRows;
00205   }
00206   std::cout << ">> Staus array --> size: " << statusarray.size() << " >> done." << std::endl << std::endl << std::endl;
00207   
00208   delete queryS;
00209   session->transaction().commit();
00210   delete session;
00211 
00212   return statusarray;
00213 
00214 }

Generated on Tue Jun 9 17:26:56 2009 for CMSSW by  doxygen 1.5.4