CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WriteDQMSummaryIntoOMDS.cc
Go to the documentation of this file.
2 
3 #include "RelationalAccess/ISession.h"
4 #include "RelationalAccess/ITransaction.h"
5 #include "RelationalAccess/ISchema.h"
6 #include "RelationalAccess/ITable.h"
7 #include "RelationalAccess/ITableDataEditor.h"
8 #include "RelationalAccess/TableDescription.h"
9 #include "RelationalAccess/IQuery.h"
10 #include "RelationalAccess/ICursor.h"
11 #include "CoralBase/AttributeList.h"
12 #include "CoralBase/Attribute.h"
13 #include "CoralBase/AttributeSpecification.h"
14 //#include "SealBase/TimeInfo.h"
15 #include<fstream>
16 #include<vector>
17 #include <iostream>
18 #include <stdexcept>
19 #include <vector>
20 #include <math.h>
21 
23 
24  const std::string& connectionString,
25  const std::string& user,
26  const std::string& pass):
27  TestBase(),
28  m_connectionString( connectionString ),
29  m_user( user ),
30  m_pass( pass )
31 {
32  m_tableToDrop="";
33  m_viewToDrop="";
34  m_tableToAppend="";
35  m_file="";
36 
37 }
38 
39 
41 {}
42 
43 
44 
45 void
47 {
48 }
49 
52 coral::ISession* session = this->connect( m_connectionString,m_user, m_pass );
53  session->transaction().start( );
54  std::cout << "connected succesfully to omds" <<std::endl;
55  coral::ISchema& schema = session->nominalSchema();
56  schema.dropIfExistsTable(m_tableToDrop);
57 
58 
59 }
60 
62  m_viewToDrop = view;
63  coral::ISession* session = this->connect( m_connectionString,m_user, m_pass );
64  session->transaction().start( );
65  std::cout << "connected succesfully to omds" <<std::endl;
66  coral::ISchema& schema = session->nominalSchema();
67  schema.dropIfExistsView(m_viewToDrop);
68 }
69 
70 
71 std::vector<Item>
73 {
74 
75  m_file = file;
76  std::ifstream indata;
77  indata.open(m_file.c_str(),std::ios::in);
78  if(!indata) {
79  std::cerr <<"Error: no such file!"<< std::endl;
80  exit(1);
81  }
82  Item ItemI_tmp;
83  char line[100];
84  char first_three_char[3];
85  // string of the file relevant
86  std::string spaces="===";
87  std::string Run="Run";
88  // string needed for parsing
89  char subsys[50], comp[50], tmp[3];
90  int l=0;
91  //reading the file and filling the struct
92  while(!indata.eof()) {
93  indata.getline(line,100);
94  l++;
95  for(int k=0; k<3;k++){
96  first_three_char[k]= line[k];
97  }
98  // skipp fist line and when ===
99  if ( l==1 || first_three_char ==spaces) continue;
100  if (first_three_char==Run){
101  // getting run number and subdetector name
102  sscanf( line, "%s%d%s", tmp , &ItemI_tmp.m_run , subsys);
103  ItemI_tmp.m_subsystem = subsys;
104  } else {
105  // getting the string/component between the < .... > and the status
106  sscanf( line, "<%[^>]>%f",comp,&ItemI_tmp.m_status );
107  ItemI_tmp.m_reportcontent=comp;
108  m_itemvec.push_back(ItemI_tmp);
109  }
110  }
111  indata.close();
112  // to avoid inserted last row twice.....
113  m_itemvec.pop_back();
114  return m_itemvec;
115 }
116 
117 
118 
119 void
121  {
122 
123  for (size_t k= 0; k< m_itemvec.size(); k++){
124  Item Itemtemp= m_itemvec[k];
125  // printing to stdout the value to be transferred
126  std::cout<< "read from file, and now transferring these value : " << std::endl;
127  std::cout<< "item run : " << Itemtemp.m_run<<std::endl;
128  std::cout<< "item subsystem : " << Itemtemp.m_subsystem << std::endl;
129  std::cout<< "item reportcontent : " << Itemtemp.m_reportcontent <<std::endl;
130  std::cout<< "item status : " << Itemtemp.m_status<<std::endl;
131 
132  }
133 
134 
135  std::cout<< "starting to write the data in omds : " << std::endl;
136  m_tableToAppend = tableToRead;
137 
138  std::cout << "connecting to omds" <<std::endl;
139  coral::ISession* session = this->connect( m_connectionString,m_user, m_pass );
140  session->transaction().start( );
141  std::cout << "connected succesfully to omds" <<std::endl;
142  coral::ISchema& schema = session->nominalSchema();
143 
144  std::cout << "new table: " << m_tableToAppend <<std::endl;
145  coral::ITable& table = schema.tableHandle(m_tableToAppend);
146  coral::AttributeList rowBuffer;
147  table.dataEditor().rowBuffer( rowBuffer );
148 // appending to the existing table
149  for (size_t k= 0; k< m_itemvec.size(); k++ )
150  {
151  Item Itemtemp= m_itemvec[k];
152 
153  rowBuffer["RUN"].data<long long int>() =Itemtemp.m_run ;
154  rowBuffer["SUBSYSTEM"].data<std::string>() = Itemtemp.m_subsystem;
155  rowBuffer["REPORTCONTENT"].data<std::string>() = Itemtemp.m_reportcontent;
156  rowBuffer["STATUS"].data<double>() = Itemtemp.m_status;
157  table.dataEditor().insertRow( rowBuffer );
158  }
159 
160  session->transaction().commit();
161 delete session;
162 
163 }
164 
165 
166 
void writeData(const std::string &tableToRead)
std::string m_reportcontent
WriteDQMSummaryIntoOMDS(const std::string &connectionString, const std::string &user, const std::string &pass)
std::string m_subsystem
void dropView(const std::string &view)
std::vector< Item > readData(const std::string &file)
int k[5][pyjets_maxn]
#define table(NAME)
Definition: DbCore.h:49
void dropTable(const std::string &table)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple cout
Definition: gather_cfg.py:121
coral::ISession * connect(const std::string &connectionString, const std::string &user, const std::string &password)
Definition: TestBase.cc:24