CMS 3D CMS Logo

WriteDQMSummeryIntoOMDS.cc

Go to the documentation of this file.
00001 #include "DQM/Integration/interface/WriteDQMSummeryIntoOMDS.h"
00002 
00003 #include "RelationalAccess/ISession.h"
00004 #include "RelationalAccess/ITransaction.h"
00005 #include "RelationalAccess/ISchema.h"
00006 #include "RelationalAccess/ITable.h"
00007 #include "RelationalAccess/ITableDataEditor.h"
00008 #include "RelationalAccess/TableDescription.h"
00009 #include "RelationalAccess/IQuery.h"
00010 #include "RelationalAccess/ICursor.h"
00011 #include "CoralBase/AttributeList.h"
00012 #include "CoralBase/Attribute.h"
00013 #include "CoralBase/AttributeSpecification.h"
00014 #include "SealBase/TimeInfo.h"
00015 #include<fstream>
00016 #include<vector>
00017 #include <iostream>
00018 #include <stdexcept>
00019 #include <vector>
00020 #include <math.h>
00021 
00022 WriteDQMSummeryIntoOMDS::WriteDQMSummeryIntoOMDS(
00023            
00024               const std::string& connectionString,
00025               const std::string& user,
00026               const std::string& pass):
00027   TestBase(),
00028   m_connectionString( connectionString ),
00029   m_user( user ),
00030   m_pass( pass )
00031 {
00032   m_tableToDrop="";  
00033   m_viewToDrop="";  
00034   m_tableToAppend="";
00035   m_file="";
00036 
00037 }
00038 
00039 
00040 WriteDQMSummeryIntoOMDS::~WriteDQMSummeryIntoOMDS()
00041 {}
00042 
00043 
00044 
00045 void
00046 WriteDQMSummeryIntoOMDS::run()
00047 {
00048 }
00049 
00050 void WriteDQMSummeryIntoOMDS::dropTable(const std::string & table){
00051   m_tableToDrop = table;
00052 coral::ISession* session = this->connect( m_connectionString,m_user, m_pass );
00053    session->transaction().start( );
00054     std::cout << "connected succesfully to omds" <<std::endl;
00055    coral::ISchema& schema = session->nominalSchema(); 
00056   schema.dropIfExistsTable(m_tableToDrop);
00057  
00058  
00059 }
00060 
00061 void WriteDQMSummeryIntoOMDS::dropView(const std::string & view){
00062   m_viewToDrop = view;
00063   coral::ISession* session = this->connect( m_connectionString,m_user, m_pass );
00064   session->transaction().start( );
00065   std::cout << "connected succesfully to omds" <<std::endl;
00066   coral::ISchema& schema = session->nominalSchema(); 
00067   schema.dropIfExistsView(m_viewToDrop);
00068 }
00069 
00070 
00071 std::vector<Item>
00072 WriteDQMSummeryIntoOMDS::readData(const std::string & file)
00073 {
00074   
00075   m_file = file;
00076   std::ifstream indata;
00077   indata.open(m_file.c_str(),std::ios::in);
00078   if(!indata) {
00079     std::cerr <<"Error: no such file!"<< std::endl;
00080     exit(1);
00081   }
00082   Item ItemI_tmp;
00083  char line[100];
00084  char first_three_char[3];
00085   // string of the file relevant  
00086  std::string spaces="===";
00087  std::string Run="Run";
00088  // string needed for parsing 
00089  char subsys[50], comp[50], tmp[3];
00090  int i=0, j=0, l=0;
00091    //reading the file and filling the struct
00092   while(!indata.eof()) {
00093     indata.getline(line,100);
00094     l++;
00095     for(int k=0; k<3;k++){
00096       first_three_char[k]= line[k];
00097     }
00098     // skipp fist line and when ===
00099     if ( l==1  || first_three_char ==spaces) continue;
00100     if (first_three_char==Run){
00101       // getting run number and subdetector name 
00102       i=  sscanf( line, "%s%d%s", tmp , &ItemI_tmp.m_run , subsys);
00103       ItemI_tmp.m_subsystem = subsys;
00104     } else {
00105       // getting the string/component between the < .... > and the status
00106       j=  sscanf( line, "<%[^>]>%f",comp,&ItemI_tmp.m_status );
00107       ItemI_tmp.m_reportcontent=comp;
00108          m_itemvec.push_back(ItemI_tmp);
00109        }
00110   }
00111   indata.close();
00112   // to avoid inserted last row twice..... 
00113   m_itemvec.pop_back();
00114   return  m_itemvec;
00115 }
00116  
00117  
00118 
00119 void
00120 WriteDQMSummeryIntoOMDS::writeData(const std::string & tableToRead)
00121   {
00122     
00123  for (size_t k= 0; k< m_itemvec.size(); k++){
00124     Item Itemtemp= m_itemvec[k];
00125     // printing to stdout the value to be transferred 
00126   std::cout<< "read from file, and now transferring  these value   : " << std::endl;
00127   std::cout<< "item run  : " << Itemtemp.m_run<<std::endl;
00128   std::cout<< "item subsystem : " << Itemtemp.m_subsystem << std::endl;
00129   std::cout<< "item reportcontent  : " << Itemtemp.m_reportcontent <<std::endl;
00130   std::cout<< "item status  : " << Itemtemp.m_status<<std::endl;
00131 
00132   }
00133  
00134  
00135   std::cout<< "starting to write the data in omds  : " << std::endl;
00136   m_tableToAppend = tableToRead; 
00137 
00138   std::cout << "connecting to omds" <<std::endl;
00139  coral::ISession* session = this->connect( m_connectionString,m_user, m_pass );
00140  session->transaction().start( );
00141  std::cout << "connected succesfully to omds" <<std::endl;
00142  coral::ISchema& schema = session->nominalSchema(); 
00143  
00144  std::cout << "new table: " <<  m_tableToAppend <<std::endl;
00145  coral::ITable& table = schema.tableHandle(m_tableToAppend); 
00146  coral::AttributeList rowBuffer;
00147  table.dataEditor().rowBuffer( rowBuffer );
00148 // appending to the existing table
00149  for (size_t k= 0; k< m_itemvec.size(); k++ )
00150    {
00151      Item Itemtemp= m_itemvec[k];
00152 
00153      rowBuffer["RUN"].data<long long int>() =Itemtemp.m_run ;
00154      rowBuffer["SUBSYSTEM"].data<std::string>() = Itemtemp.m_subsystem;
00155      rowBuffer["REPORTCONTENT"].data<std::string>() = Itemtemp.m_reportcontent;
00156      rowBuffer["STATUS"].data<double>() =  Itemtemp.m_status;
00157      table.dataEditor().insertRow( rowBuffer ); 
00158    }
00159  
00160  session->transaction().commit();
00161 delete session;
00162  
00163 }
00164 
00165 
00166 

Generated on Tue Jun 9 17:33:09 2009 for CMSSW by  doxygen 1.5.4