3 #include "RelationalAccess/ISessionProxy.h"
4 #include "RelationalAccess/ISchema.h"
5 #include "RelationalAccess/ITable.h"
6 #include "RelationalAccess/TableDescription.h"
7 #include "RelationalAccess/ITablePrivilegeManager.h"
8 #include "RelationalAccess/ICursor.h"
9 #include "RelationalAccess/IQuery.h"
10 #include "RelationalAccess/ITableDataEditor.h"
11 #include "CoralBase/Exception.h"
12 #include "CoralBase/AttributeList.h"
13 #include "CoralBase/AttributeSpecification.h"
14 #include "CoralBase/Attribute.h"
23 std::cout <<
"Building coral interface" << std::endl;
31 LogTrace(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] Destructor called.";
42 LogTrace(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] Database connection opened";
45 edm::LogError(
"SiStripCoralIface") <<
"Database connection failed";
52 std::vector<float> &vec_actualValue, std::vector<std::string> &vec_dpname)
57 LogTrace(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] table to be accessed: " <<
queryType;
59 if (queryType ==
"STATUSCHANGE") {
60 query->addToOutputList(
"FWCAENCHANNEL.CHANGE_DATE",
"CHANGE_DATE");
61 query->addToOutputList(
"FWCAENCHANNEL.ACTUAL_STATUS",
"ACTUAL_STATUS");
62 query->addToOutputList(
"DP_NAME2ID.DPNAME",
"DPNAME");
63 query->addToOrderList(
"FWCAENCHANNEL.CHANGE_DATE");
64 query->addToTableList(
"FWCAENCHANNEL");
65 query->addToTableList(
"DP_NAME2ID");
66 condition =
"FWCAENCHANNEL.DPID = DP_NAME2ID.id AND FWCAENCHANNEL.CHANGE_DATE<=:tmax AND FWCAENCHANNEL.ACTUAL_STATUS IS NOT NULL AND FWCAENCHANNEL.CHANGE_DATE >=:tmin AND (DP_NAME2ID.dpname like '%easyBoard%')";
67 }
else if (queryType ==
"LASTVALUE") {
68 query->addToOutputList(
"DCSLASTVALUE_VOLTAGE.CHANGE_DATE",
"CHANGE_DATE");
69 query->addToOutputList(
"DCSLASTVALUE_VOLTAGE.ACTUAL_VMON",
"ACTUAL_VMON");
70 query->addToOutputList(
"DP_NAME2ID.DPNAME",
"DPNAME");
71 query->addToOrderList(
"DCSLASTVALUE_VOLTAGE.CHANGE_DATE");
72 query->addToTableList(
"DCSLASTVALUE_VOLTAGE");
73 query->addToTableList(
"DP_NAME2ID");
74 condition =
"DCSLASTVALUE_VOLTAGE.DPID = DP_NAME2ID.id AND DCSLASTVALUE_VOLTAGE.CHANGE_DATE<=:tmax AND DCSLASTVALUE_VOLTAGE.CHANGE_DATE>=:tmin AND DCSLASTVALUE_VOLTAGE.ACTUAL_VMON IS NOT NULL AND (DP_NAME2ID.dpname like '%easyBoard%')";
77 coral::AttributeList conditionData;
78 conditionData.extend<coral::TimeStamp>(
"tmax" );
79 conditionData.extend<coral::TimeStamp>(
"tmin" );
80 query->setCondition( condition, conditionData );
81 conditionData[0].data<coral::TimeStamp>() = endTime;
82 conditionData[1].data<coral::TimeStamp>() = startTime;
84 query->setMemoryCacheSize( 100 );
86 if (
debug_)
std::cout<<
"[SiStripCoralIface::"<<__func__<<
"] Dumping all query results:"<<std::endl;
87 coral::ICursor& cursor =
query->execute();
89 while( cursor.next() ){
90 const coral::AttributeList& row = cursor.currentRow();
96 if (queryType ==
"STATUSCHANGE") {
97 coral::TimeStamp ts = row[
"CHANGE_DATE"].data<coral::TimeStamp>();
98 vec_changedate.push_back(ts);
99 float as = (float)row[
"ACTUAL_STATUS"].data<float>();
100 vec_actualValue.push_back(as);
102 vec_dpname.push_back(id_name);
103 }
else if (queryType ==
"LASTVALUE") {
104 coral::TimeStamp ts = row[
"CHANGE_DATE"].data<coral::TimeStamp>();
105 vec_changedate.push_back(ts);
106 float av = (float)row[
"ACTUAL_VMON"].data<float>();
107 vec_actualValue.push_back(av);
109 vec_dpname.push_back(id_name);
113 if (
debug_)
std::cout<<
"[SiStripCoralIface::"<<__func__<<
"] Finished dumping query results, "<< numberRow<<
" rows were retrieved from PVSS Cond DB (both Pixel and Strip CAEN supplies)"<<std::endl;
114 LogTrace(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] " << numberRow <<
" rows retrieved from PVSS Cond DB";
119 std::vector<float> &vec_settings, std::vector<std::string> &vec_dpname, std::vector<uint32_t> &vec_dpid)
122 query->addToOutputList(
"FWCAENCHANNEL.CHANGE_DATE",
"CHANGE_DATE");
123 query->addToOutputList(
"FWCAENCHANNEL.SETTINGS_V0",
"VSET");
124 query->addToOutputList(
"FWCAENCHANNEL.DPID",
"DPID");
125 query->addToOutputList(
"DP_NAME2ID.DPNAME",
"DPNAME");
126 query->addToOrderList(
"FWCAENCHANNEL.CHANGE_DATE");
127 query->addToTableList(
"FWCAENCHANNEL");
128 query->addToTableList(
"DP_NAME2ID");
129 std::string condition =
"FWCAENCHANNEL.DPID = DP_NAME2ID.id AND FWCAENCHANNEL.CHANGE_DATE<=:tmax AND FWCAENCHANNEL.SETTINGS_V0 IS NOT NULL AND FWCAENCHANNEL.CHANGE_DATE >=:tmin AND (DP_NAME2ID.dpname like '%easyBoard%')";
131 coral::AttributeList conditionData;
132 conditionData.extend<coral::TimeStamp>(
"tmax" );
133 conditionData.extend<coral::TimeStamp>(
"tmin" );
134 query->setCondition( condition, conditionData );
135 conditionData[0].data<coral::TimeStamp>() = endTime;
136 conditionData[1].data<coral::TimeStamp>() = startTime;
138 query->setMemoryCacheSize( 100 );
139 coral::ICursor& cursor =
query->execute();
141 while( cursor.next() ){
142 const coral::AttributeList& row = cursor.currentRow();
145 coral::TimeStamp ts = row[
"CHANGE_DATE"].data<coral::TimeStamp>();
146 vec_changedate.push_back(ts);
147 float vs = (float)row[
"VSET"].data<float>();
148 vec_settings.push_back(vs);
149 uint32_t
id = (uint32_t)row[
"DPID"].data<float>();
150 vec_dpid.push_back(
id);
152 vec_dpname.push_back(id_name);
155 LogTrace(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] " << numberRow <<
" rows retrieved from PVSS Cond DB";
161 query->addToOutputList(
"DP_NAME2ID.DPNAME",
"DPNAME");
162 query->addToOutputList(
"DP_NAME2ID.ID",
"DPID");
163 query->addToTableList(
"DP_NAME2ID");
165 std::string condition =
"DP_NAME2ID.dpname like '%easyBoard%' ";
166 query->setCondition( condition, coral::AttributeList() );
168 query->setMemoryCacheSize( 100 );
169 coral::ICursor& cursor =
query->execute();
171 while( cursor.next() ){
172 const coral::AttributeList& row = cursor.currentRow();
174 uint32_t
id = (uint32_t)row[
"DPID"].data<float>();
175 vec_dpid.push_back(
id);
177 vec_dpname.push_back(id_name);
180 LogTrace(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] " << numberRow <<
" rows retrieved from PVSS Cond DB";
std::string m_connectionString
void doSettingsQuery(const coral::TimeStamp &startTime, const coral::TimeStamp &endTime, std::vector< coral::TimeStamp > &, std::vector< float > &, std::vector< std::string > &, std::vector< uint32_t > &)
void open(const std::string &connectionString, bool readOnly=false)
DbConnectionConfiguration & configuration()
cond::DbConnection m_connection
coral::ISchema & schema(const std::string &schemaName)
SiStripCoralIface(std::string connectionString, std::string authenticationPath, const bool debug)
cond::DbSession m_session
void doQuery(std::string queryType, const coral::TimeStamp &startTime, const coral::TimeStamp &endTime, std::vector< coral::TimeStamp > &, std::vector< float > &, std::vector< std::string > &)
void doNameQuery(std::vector< std::string > &vec_dpname, std::vector< uint32_t > &vec_dpid)
std::auto_ptr< cond::DbScopedTransaction > m_transaction
DbSession createSession() const
void setAuthenticationPath(const std::string &p)