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"
24 const std::string&
user,
25 const std::string& pass):
27 m_connectionString( connectionString ),
40 const std::string &column,
const int r_number) {
49 const boost::posix_time::ptime
time0 =
50 boost::posix_time::from_time_t(0);
52 temp_sum.
m_run = r_number;
53 std::cout <<
"entering readData" << std::endl;
57 session->transaction().start();
58 std::cout <<
"starting session " << std::endl;
59 coral::ISchema&
schema = session->schema(
"CMS_RUNINFO");
60 std::cout <<
" accessing schema " << std::endl;
62 std::string m_columnToRead_id =
"ID";
63 long long id_start = 0;
65 coral::IQuery* queryI = schema.tableHandle(
m_tableToRead).newQuery();
67 queryI->addToOutputList(
m_tableToRead +
"." + m_columnToRead_id, m_columnToRead_id);
69 coral::AttributeList conditionData;
70 conditionData.extend<
int>(
"n_run" );
71 conditionData[0].data<
int>() = r_number;
73 queryI->setCondition(condition1, conditionData);
74 coral::ICursor& cursorI = queryI->execute();
75 if( cursorI.next() ) {
77 const coral::AttributeList& row = cursorI.currentRow();
78 id_start = row[m_columnToRead_id].data<
long long>();
87 std::string m_tableToRead_date =
"RUNSESSION_DATE";
88 std::string m_columnToRead_val =
"VALUE";
90 coral::IQuery* queryII = schema.tableHandle(m_tableToRead_date).newQuery();
92 queryII->addToOutputList(m_tableToRead_date +
"." + m_columnToRead_val, m_columnToRead_val);
94 coral::AttributeList conditionData2;
95 conditionData2.extend<
long long>(
"n_id" );
96 conditionData2[0].data<
long long>() = id_start;
97 std::string condition2 = m_tableToRead_date +
".runsession_parameter_id=:n_id";
98 queryII->setCondition(condition2, conditionData2);
99 coral::ICursor& cursorII = queryII->execute();
100 coral::TimeStamp
start;
101 if( cursorII.next() ) {
103 const coral::AttributeList& row = cursorII.currentRow();
104 start = row[m_columnToRead_val].data<coral::TimeStamp>();
116 boost::posix_time::ptime start_ptime = start.time();
117 std::cout <<
"Posix time for run start: "<< start_ptime << std::endl;
118 boost::posix_time::time_duration startTimeFromEpoch = start_ptime -
time0;
119 temp_sum.
m_start_time_str = boost::posix_time::to_iso_extended_string(start_ptime);
131 coral::IQuery* queryIII = schema.tableHandle(m_tableToRead).newQuery();
133 queryIII->addToOutputList(m_tableToRead +
"." + m_columnToRead_id, m_columnToRead_id);
135 std::string condition3 = m_tableToRead +
".runnumber=:n_run AND " + m_tableToRead +
".name='CMS.LVL0:STOP_TIME_T'";
136 queryIII->setCondition(condition3, conditionData);
137 coral::ICursor& cursorIII = queryIII->execute();
138 long long id_stop = 0;
139 if( cursorIII.next() ) {
141 const coral::AttributeList& row = cursorIII.currentRow();
142 id_stop = row[m_columnToRead_id].data<
long long>();
151 coral::IQuery* queryIV = schema.tableHandle(m_tableToRead_date).newQuery();
153 queryIV->addToOutputList(m_tableToRead_date +
"." + m_columnToRead_val, m_columnToRead_val);
155 coral::AttributeList conditionData4;
156 conditionData4.extend<
long long>(
"n_id" );
157 conditionData4[0].data<
long long>() = id_stop;
158 std::string condition4 = m_tableToRead_date +
".runsession_parameter_id=:n_id";
159 queryIV->setCondition(condition4, conditionData4);
160 coral::ICursor& cursorIV = queryIV->execute();
161 coral::TimeStamp stop;
162 if( cursorIV.next() ) {
164 const coral::AttributeList& row = cursorIV.currentRow();
165 stop = row[m_columnToRead_val].data<coral::TimeStamp>();
177 boost::posix_time::ptime stop_ptime = stop.time();
178 std::cout <<
"Posix time for run stop: "<< stop_ptime << std::endl;
179 boost::posix_time::time_duration stopTimeFromEpoch = stop_ptime -
time0;
180 temp_sum.
m_stop_time_str = boost::posix_time::to_iso_extended_string(stop_ptime);
191 std::string m_tableToRead_fed =
"RUNSESSION_STRING";
192 coral::IQuery* queryV = schema.newQuery();
193 queryV->addToTableList(m_tableToRead);
194 queryV->addToTableList(m_tableToRead_fed);
195 queryV->addToOutputList(m_tableToRead_fed +
"." + m_columnToRead_val, m_columnToRead_val);
198 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";
200 queryV->setCondition(condition5, conditionData);
201 coral::ICursor& cursorV = queryV->execute();
203 if ( cursorV.next() ) {
205 const coral::AttributeList& row = cursorV.currentRow();
206 fed = row[m_columnToRead_val].data<std::string>();
215 std::stringstream stream(fed);
218 if ( !(stream >> word) ){
break;}
220 std::stringstream ss(word);
223 ss >> fedNumber >> val;
226 if( (val & 0001) == 1 && (val != 5) && (val != 7) )
227 temp_sum.
m_fed_in.push_back(fedNumber);
231 std::cout << std::endl;
238 coral::ISchema& schema2 = session->schema(
"CMS_DCS_ENV_PVSS_COND");
239 std::string m_tableToRead_cur=
"CMSFWMAGNET";
240 std::string m_columnToRead_cur=
"CURRENT";
241 std::string m_columnToRead_date=
"CHANGE_DATE";
242 coral::IQuery* queryVI = schema2.tableHandle(m_tableToRead_cur).newQuery();
243 queryVI->addToOutputList(m_tableToRead_cur +
"." + m_columnToRead_cur, m_columnToRead_cur);
244 queryVI->addToOutputList(m_tableToRead_cur +
"." + m_columnToRead_date, m_columnToRead_date);
246 coral::AttributeList conditionData6;
247 float last_current = -1;
249 conditionData6.extend<coral::TimeStamp>(
"runstart_time" );
250 conditionData6.extend<coral::TimeStamp>(
"runstop_time" );
251 conditionData6[
"runstart_time"].data<coral::TimeStamp>() = start;
252 conditionData6[
"runstop_time"].data<coral::TimeStamp>() = stop;
253 std::string conditionVI =
" NOT " + m_tableToRead_cur +
"." + m_columnToRead_cur +
" IS NULL AND "
254 + m_tableToRead_cur +
"." + m_columnToRead_date +
">:runstart_time AND "
255 + m_tableToRead_cur +
"." + m_columnToRead_date +
"<:runstop_time" ;
256 queryVI->setCondition(conditionVI, conditionData6);
257 queryVI->addToOrderList(m_tableToRead_cur +
"." + m_columnToRead_date +
" DESC");
259 std::cout <<
"run stop null" << std::endl;
260 conditionData6.extend<coral::TimeStamp>(
"runstart_time" );
261 conditionData6[
"runstart_time"].data<coral::TimeStamp>() = start;
262 std::string conditionVI =
" NOT " + m_tableToRead_cur +
"." + m_columnToRead_cur +
" IS NULL AND "
263 + m_tableToRead_cur +
"." + m_columnToRead_date +
"<:runstart_time" ;
264 queryVI->setCondition(conditionVI, conditionData6);
265 queryVI->addToOrderList(m_tableToRead_cur +
"." + m_columnToRead_date +
" DESC");
267 queryVI->limitReturnedRows(10000);
268 coral::ICursor& cursorVI = queryVI->execute();
269 coral::TimeStamp lastCurrentDate;
270 std::string last_date;
271 std::vector<double> time_curr;
272 if ( !cursorVI.next() ) {
275 coral::AttributeList conditionData6bis;
276 conditionData6bis.extend<coral::TimeStamp>(
"runstop_time" );
277 conditionData6bis[
"runstop_time"].data<coral::TimeStamp>() = stop;
278 std::string conditionVIbis =
" NOT " + m_tableToRead_cur +
"." + m_columnToRead_cur +
" IS NULL AND "
279 + m_tableToRead_cur +
"." + m_columnToRead_date +
" <:runstop_time" ;
280 coral::IQuery* queryVIbis = schema2.tableHandle(m_tableToRead_cur).newQuery();
281 queryVIbis->addToOutputList(m_tableToRead_cur +
"." + m_columnToRead_cur, m_columnToRead_cur);
282 queryVIbis->setCondition(conditionVIbis, conditionData6bis);
283 queryVIbis->addToOrderList(m_tableToRead_cur +
"." + m_columnToRead_date +
" DESC");
284 coral::ICursor& cursorVIbis= queryVIbis->execute();
285 if( cursorVIbis.next() ) {
287 const coral::AttributeList& row = cursorVIbis.currentRow();
288 last_current = row[m_columnToRead_cur].data<
float>();
289 std::cout <<
"previos run(s) current, not changed in this run... " << last_current << std::endl;
297 while( cursorVI.next() ) {
299 const coral::AttributeList& row = cursorVI.currentRow();
300 lastCurrentDate = row[m_columnToRead_date].data<coral::TimeStamp>();
301 temp_sum.
m_current.push_back( row[m_columnToRead_cur].data<float>() );
314 boost::posix_time::ptime lastCurrentDate_ptime = lastCurrentDate.time();
315 std::cout <<
"Posix time for last current time: " << lastCurrentDate_ptime << std::endl;
316 boost::posix_time::time_duration lastCurrentDateTimeFromEpoch = lastCurrentDate_ptime -
time0;
317 last_date = boost::posix_time::to_iso_extended_string(lastCurrentDate_ptime);
318 std::cout <<
"last current time extracted == " << last_date << std::endl;
319 long long last_date_ll = lastCurrentDateTimeFromEpoch.total_microseconds();
320 time_curr.push_back(last_date_ll);
324 size_t csize = temp_sum.
m_current.size();
325 std::cout <<
"size of currents " << csize << std::endl;
326 size_t tsize = time_curr.size();
327 std::cout <<
"size of time " << tsize << std::endl;
329 std::cout<<
"current and time not filled correctly" << std::endl;
336 std::cout <<
"change current during run interval in microseconds " << temp_sum.
m_run_intervall_micros << std::endl;
348 for(
size_t i = 0;
i < csize; ++
i) {
349 std::cout <<
"--> " << temp_sum.
m_current[
i] << std::endl;
350 if( (tsize > 1) && (
i < csize - 1 ) ) {
351 wi = (time_curr[
i] - time_curr[
i+1]) ;
365 std::cout <<
"--> " <<
"start cur " << temp_sum.
m_start_current << std::endl;
367 std::cout<<
"--> " <<
"stop cur " << temp_sum.
m_stop_current << std::endl;
373 std::cout<<
"--> " <<
"avg cur " << temp_sum.
m_avg_current << std::endl;
375 std::cout<<
"--> " <<
"max cur " << temp_sum.
m_max_current << std::endl;
377 std::cout<<
"--> " <<
"min cur " << temp_sum.
m_min_current << std::endl;
388 std::cout <<
"temp_sum.m_avg_current " << temp_sum.
m_avg_current << std::endl;
389 std::cout <<
"temp_sum.m_min_current " << temp_sum.
m_min_current << std::endl;
390 std::cout <<
"temp_sum.m_max_current " << temp_sum.
m_max_current << std::endl;
391 std::cout <<
"temp_sum.m_stop_current " << temp_sum.
m_stop_current << std::endl;
392 std::cout <<
"temp_sum.m_start_current " << temp_sum.
m_start_current << std::endl;
394 session->transaction().commit();
397 std::cout <<
"Exception: " << e.what() << std::endl;
const boost::posix_time::ptime time0
RunInfoRead(const std::string &connectionString, const std::string &user, const std::string &pass)
const T & max(const T &a, const T &b)
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
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)