4 #include "RelationalAccess/ISession.h"
5 #include "RelationalAccess/ITransaction.h"
6 #include "RelationalAccess/ISchema.h"
7 #include "RelationalAccess/ITable.h"
8 #include "RelationalAccess/ITableDataEditor.h"
9 #include "RelationalAccess/TableDescription.h"
10 #include "RelationalAccess/IQuery.h"
11 #include "RelationalAccess/ICursor.h"
12 #include "CoralBase/AttributeList.h"
13 #include "CoralBase/Attribute.h"
14 #include "CoralBase/AttributeSpecification.h"
15 #include "CoralBase/TimeStamp.h"
39 m_connectionString( connectionString ),
61 const boost::posix_time::ptime
time0 =
62 boost::posix_time::from_time_t(0);
64 temp_sum.
m_run = r_number;
65 std::cout <<
"entering readData" << std::endl;
69 session->transaction().start();
70 std::cout <<
"starting session " << std::endl;
71 coral::ISchema&
schema = session->schema(
"CMS_RUNINFO");
72 std::cout <<
" accessing schema " << std::endl;
75 long long id_start = 0;
77 coral::IQuery* queryI = schema.tableHandle(
m_tableToRead).newQuery();
79 queryI->addToOutputList(
m_tableToRead +
dot + m_columnToRead_id, m_columnToRead_id);
81 coral::AttributeList conditionData;
82 conditionData.extend<
int>(
"n_run" );
83 conditionData[0].data<
int>() = r_number;
85 queryI->setCondition(condition1, conditionData);
86 coral::ICursor& cursorI = queryI->execute();
87 if( cursorI.next() ) {
89 const coral::AttributeList& row = cursorI.currentRow();
90 id_start = row[m_columnToRead_id].data<
long long>();
102 coral::IQuery* queryII = schema.tableHandle(m_tableToRead_date).newQuery();
104 queryII->addToOutputList(m_tableToRead_date +
dot + m_columnToRead_val, m_columnToRead_val);
106 coral::AttributeList conditionData2;
107 conditionData2.extend<
long long>(
"n_id" );
108 conditionData2[0].data<
long long>() = id_start;
109 std::string condition2 = m_tableToRead_date +
".RUNSESSION_PARAMETER_ID=:n_id";
110 queryII->setCondition(condition2, conditionData2);
111 coral::ICursor& cursorII = queryII->execute();
112 coral::TimeStamp
start;
113 if( cursorII.next() ) {
115 const coral::AttributeList& row = cursorII.currentRow();
116 start = row[m_columnToRead_val].data<coral::TimeStamp>();
128 boost::posix_time::ptime start_ptime = start.time();
129 std::cout <<
"Posix time for run start: "<< start_ptime << std::endl;
130 boost::posix_time::time_duration startTimeFromEpoch = start_ptime -
time0;
131 temp_sum.
m_start_time_str = boost::posix_time::to_iso_extended_string(start_ptime);
143 coral::IQuery* queryIII = schema.tableHandle(m_tableToRead).newQuery();
145 queryIII->addToOutputList(m_tableToRead +
dot + m_columnToRead_id, m_columnToRead_id);
147 std::string condition3 = m_tableToRead +
".RUNNUMBER=:n_run AND " + m_tableToRead +
".NAME='CMS.LVL0:STOP_TIME_T'";
148 queryIII->setCondition(condition3, conditionData);
149 coral::ICursor& cursorIII = queryIII->execute();
150 long long id_stop = 0;
151 if( cursorIII.next() ) {
153 const coral::AttributeList& row = cursorIII.currentRow();
154 id_stop = row[m_columnToRead_id].data<
long long>();
163 coral::IQuery* queryIV = schema.tableHandle(m_tableToRead_date).newQuery();
165 queryIV->addToOutputList(m_tableToRead_date +
dot + m_columnToRead_val, m_columnToRead_val);
167 coral::AttributeList conditionData4;
168 conditionData4.extend<
long long>(
"n_id" );
169 conditionData4[0].data<
long long>() = id_stop;
170 std::string condition4 = m_tableToRead_date +
".RUNSESSION_PARAMETER_ID=:n_id";
171 queryIV->setCondition(condition4, conditionData4);
172 coral::ICursor& cursorIV = queryIV->execute();
173 coral::TimeStamp stop;
174 if( cursorIV.next() ) {
176 const coral::AttributeList& row = cursorIV.currentRow();
177 stop = row[m_columnToRead_val].data<coral::TimeStamp>();
189 boost::posix_time::ptime stop_ptime = stop.time();
190 std::cout <<
"Posix time for run stop: "<< stop_ptime << std::endl;
191 boost::posix_time::time_duration stopTimeFromEpoch = stop_ptime -
time0;
192 temp_sum.
m_stop_time_str = boost::posix_time::to_iso_extended_string(stop_ptime);
203 std::string m_tableToRead_fed =
"RUNSESSION_STRING";
204 coral::IQuery* queryV = schema.newQuery();
205 queryV->addToTableList(m_tableToRead);
206 queryV->addToTableList(m_tableToRead_fed);
207 queryV->addToOutputList(m_tableToRead_fed +
dot + m_columnToRead_val, m_columnToRead_val);
210 std::string condition5 = m_tableToRead +
".RUNNUMBER=:n_run AND " + m_tableToRead +
".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
212 queryV->setCondition(condition5, conditionData);
213 coral::ICursor& cursorV = queryV->execute();
215 if ( cursorV.next() ) {
217 const coral::AttributeList& row = cursorV.currentRow();
227 std::stringstream stream(fed);
230 if ( !(stream >> word) ){
break;}
232 std::stringstream
ss(word);
235 ss >> fedNumber >> val;
238 if( (val & 0001) == 1 && (val != 5) && (val != 7) )
239 temp_sum.
m_fed_in.push_back(fedNumber);
243 std::cout << std::endl;
250 coral::ISchema& schema2 = session->schema(
"CMS_DCS_ENV_PVSS_COND");
254 coral::IQuery* queryVI = schema2.tableHandle(m_tableToRead_cur).newQuery();
255 queryVI->addToOutputList(m_tableToRead_cur +
dot + squoted(m_columnToRead_cur), m_columnToRead_cur);
256 queryVI->addToOutputList(m_tableToRead_cur +
dot + m_columnToRead_date, m_columnToRead_date);
258 coral::AttributeList conditionData6;
259 float last_current = -1;
261 conditionData6.extend<coral::TimeStamp>(
"runstart_time" );
262 conditionData6.extend<coral::TimeStamp>(
"runstop_time" );
263 conditionData6[
"runstart_time"].data<coral::TimeStamp>() = start;
264 conditionData6[
"runstop_time"].data<coral::TimeStamp>() = stop;
265 std::string conditionVI =
" NOT " + m_tableToRead_cur +
dot + squoted(m_columnToRead_cur) +
" IS NULL AND "
266 + m_tableToRead_cur +
dot + m_columnToRead_date +
">:runstart_time AND "
267 + m_tableToRead_cur +
dot + m_columnToRead_date +
"<:runstop_time" ;
268 queryVI->setCondition(conditionVI, conditionData6);
269 queryVI->addToOrderList(m_tableToRead_cur +
dot + m_columnToRead_date +
" DESC");
271 std::cout <<
"run stop null" << std::endl;
272 conditionData6.extend<coral::TimeStamp>(
"runstart_time" );
273 conditionData6[
"runstart_time"].data<coral::TimeStamp>() = start;
274 std::string conditionVI =
" NOT " + m_tableToRead_cur +
dot + squoted(m_columnToRead_cur) +
" IS NULL AND "
275 + m_tableToRead_cur +
dot + m_columnToRead_date +
"<:runstart_time" ;
276 queryVI->setCondition(conditionVI, conditionData6);
277 queryVI->addToOrderList(m_tableToRead_cur +
dot + m_columnToRead_date +
" DESC");
279 queryVI->limitReturnedRows(10000);
280 coral::ICursor& cursorVI = queryVI->execute();
281 coral::TimeStamp lastCurrentDate;
283 std::vector<double> time_curr;
284 if ( !cursorVI.next() ) {
287 coral::AttributeList conditionData6bis;
288 conditionData6bis.extend<coral::TimeStamp>(
"runstop_time" );
289 conditionData6bis[
"runstop_time"].data<coral::TimeStamp>() = stop;
290 std::string conditionVIbis =
" NOT " + m_tableToRead_cur +
dot + squoted(m_columnToRead_cur) +
" IS NULL AND "
291 + m_tableToRead_cur +
dot + m_columnToRead_date +
" <:runstop_time" ;
292 coral::IQuery* queryVIbis = schema2.tableHandle(m_tableToRead_cur).newQuery();
293 queryVIbis->addToOutputList(m_tableToRead_cur +
dot + squoted(m_columnToRead_cur), m_columnToRead_cur);
294 queryVIbis->setCondition(conditionVIbis, conditionData6bis);
295 queryVIbis->addToOrderList(m_tableToRead_cur +
dot + m_columnToRead_date +
" DESC");
296 coral::ICursor& cursorVIbis= queryVIbis->execute();
297 if( cursorVIbis.next() ) {
299 const coral::AttributeList& row = cursorVIbis.currentRow();
300 last_current = row[m_columnToRead_cur].data<
float>();
301 std::cout <<
"previos run(s) current, not changed in this run... " << last_current << std::endl;
309 while( cursorVI.next() ) {
311 const coral::AttributeList& row = cursorVI.currentRow();
312 lastCurrentDate = row[m_columnToRead_date].data<coral::TimeStamp>();
313 temp_sum.
m_current.push_back( row[m_columnToRead_cur].data<float>() );
326 boost::posix_time::ptime lastCurrentDate_ptime = lastCurrentDate.time();
327 std::cout <<
"Posix time for last current time: " << lastCurrentDate_ptime << std::endl;
328 boost::posix_time::time_duration lastCurrentDateTimeFromEpoch = lastCurrentDate_ptime -
time0;
329 last_date = boost::posix_time::to_iso_extended_string(lastCurrentDate_ptime);
330 std::cout <<
"last current time extracted == " << last_date << std::endl;
331 long long last_date_ll = lastCurrentDateTimeFromEpoch.total_microseconds();
332 time_curr.push_back(last_date_ll);
336 size_t csize = temp_sum.
m_current.size();
337 std::cout <<
"size of currents " << csize << std::endl;
338 size_t tsize = time_curr.size();
339 std::cout <<
"size of time " << tsize << std::endl;
341 std::cout<<
"current and time not filled correctly" << std::endl;
348 std::cout <<
"change current during run interval in microseconds " << temp_sum.
m_run_intervall_micros << std::endl;
360 for(
size_t i = 0;
i < csize; ++
i) {
361 std::cout <<
"--> " << temp_sum.
m_current[
i] << std::endl;
362 if( (tsize > 1) && (
i < csize - 1 ) ) {
363 wi = (time_curr[
i] - time_curr[
i+1]) ;
377 std::cout <<
"--> " <<
"start cur " << temp_sum.
m_start_current << std::endl;
379 std::cout<<
"--> " <<
"stop cur " << temp_sum.
m_stop_current << std::endl;
385 std::cout<<
"--> " <<
"avg cur " << temp_sum.
m_avg_current << std::endl;
387 std::cout<<
"--> " <<
"max cur " << temp_sum.
m_max_current << std::endl;
389 std::cout<<
"--> " <<
"min cur " << temp_sum.
m_min_current << std::endl;
400 std::cout <<
"temp_sum.m_avg_current " << temp_sum.
m_avg_current << std::endl;
401 std::cout <<
"temp_sum.m_min_current " << temp_sum.
m_min_current << std::endl;
402 std::cout <<
"temp_sum.m_max_current " << temp_sum.
m_max_current << std::endl;
403 std::cout <<
"temp_sum.m_stop_current " << temp_sum.
m_stop_current << std::endl;
404 std::cout <<
"temp_sum.m_start_current " << temp_sum.
m_start_current << std::endl;
406 session->transaction().commit();
409 std::cout <<
"Exception: " << e.what() << std::endl;
tuple start
Check for commandline option errors.
const boost::posix_time::ptime time0
RunInfoRead(const std::string &connectionString, const std::string &user, const std::string &pass)
std::string m_tableToRead
std::vector< int > m_fed_in
std::string m_start_time_str
std::vector< float > m_current
RunInfo readData(const std::string &table, const std::string &column, const int r_number)
float m_run_intervall_micros
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
std::string m_columnToRead
std::string m_stop_time_str
std::string m_connectionString
std::vector< float > m_times_of_currents
long long m_start_time_ll
coral::ISession * connect(const std::string &connectionString, const std::string &user, const std::string &password)