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" 22 : m_connectionString(connectionString), m_authPath(authenticationPath), m_session(), debug_(debug) {
23 std::cout <<
"Building coral interface" << std::endl;
29 LogTrace(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] Destructor called.";
42 LogTrace(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] Database connection opened";
44 edm::LogError(
"SiStripCoralIface") <<
"Database connection failed";
51 const coral::TimeStamp& startTime,
52 const coral::TimeStamp& endTime,
53 std::vector<coral::TimeStamp>& vec_changedate,
54 std::vector<float>& vec_actualValue,
55 std::vector<std::string>& vec_dpname) {
56 std::unique_ptr<coral::IQuery>
query(
60 LogTrace(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] table to be accessed: " << queryType;
62 if (queryType ==
"STATUSCHANGE") {
63 query->addToOutputList(
"FWCAENCHANNEL.CHANGE_DATE",
"CHANGE_DATE");
64 query->addToOutputList(
"FWCAENCHANNEL.ACTUAL_STATUS",
"ACTUAL_STATUS");
65 query->addToOutputList(
"DP_NAME2ID.DPNAME",
"DPNAME");
66 query->addToOrderList(
"FWCAENCHANNEL.CHANGE_DATE");
67 query->addToTableList(
"FWCAENCHANNEL");
68 query->addToTableList(
"DP_NAME2ID");
70 "FWCAENCHANNEL.DPID = DP_NAME2ID.ID AND FWCAENCHANNEL.CHANGE_DATE<=:tmax AND FWCAENCHANNEL.ACTUAL_STATUS IS " 71 "NOT NULL AND FWCAENCHANNEL.CHANGE_DATE >=:tmin AND (DP_NAME2ID.DPNAME like '%easyBoard%')";
72 }
else if (queryType ==
"LASTVALUE") {
73 query->addToOutputList(
"DCSLASTVALUE_VOLTAGE.CHANGE_DATE",
"CHANGE_DATE");
74 query->addToOutputList(
"DCSLASTVALUE_VOLTAGE.ACTUAL_VMON",
"ACTUAL_VMON");
75 query->addToOutputList(
"DP_NAME2ID.DPNAME",
"DPNAME");
76 query->addToOrderList(
"DCSLASTVALUE_VOLTAGE.CHANGE_DATE");
77 query->addToTableList(
"DCSLASTVALUE_VOLTAGE");
78 query->addToTableList(
"DP_NAME2ID");
80 "DCSLASTVALUE_VOLTAGE.DPID = DP_NAME2ID.ID AND DCSLASTVALUE_VOLTAGE.CHANGE_DATE<=:tmax AND " 81 "DCSLASTVALUE_VOLTAGE.CHANGE_DATE>=:tmin AND DCSLASTVALUE_VOLTAGE.ACTUAL_VMON IS NOT NULL AND " 82 "(DP_NAME2ID.DPNAME like '%easyBoard%')";
85 coral::AttributeList conditionData;
86 conditionData.extend<coral::TimeStamp>(
"tmax");
87 conditionData.extend<coral::TimeStamp>(
"tmin");
88 query->setCondition(condition, conditionData);
89 conditionData[0].data<coral::TimeStamp>() = endTime;
90 conditionData[1].data<coral::TimeStamp>() = startTime;
92 query->setMemoryCacheSize(100);
93 std::cout <<
"Executing query" << std::endl;
95 std::cout <<
"[SiStripCoralIface::" << __func__ <<
"] Dumping all query results:" << std::endl;
96 coral::ICursor& cursor =
query->execute();
98 while (cursor.next()) {
99 const coral::AttributeList& row = cursor.currentRow();
104 row.toOutputStream(
std::cout) << std::endl;
106 if (queryType ==
"STATUSCHANGE") {
107 coral::TimeStamp ts = row[
"CHANGE_DATE"].data<coral::TimeStamp>();
108 vec_changedate.push_back(ts);
109 float as = (
float)row[
"ACTUAL_STATUS"].data<float>();
110 vec_actualValue.push_back(as);
112 vec_dpname.push_back(id_name);
113 }
else if (queryType ==
"LASTVALUE") {
114 coral::TimeStamp ts = row[
"CHANGE_DATE"].data<coral::TimeStamp>();
115 vec_changedate.push_back(ts);
116 float av = (
float)row[
"ACTUAL_VMON"].data<float>();
117 vec_actualValue.push_back(av);
119 vec_dpname.push_back(id_name);
124 std::cout <<
"[SiStripCoralIface::" << __func__ <<
"] Finished dumping query results, " << numberRow
125 <<
" rows were retrieved from PVSS Cond DB (both Pixel and Strip CAEN supplies)" << std::endl;
126 edm::LogInfo(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] " << numberRow
127 <<
" rows retrieved from PVSS Cond DB";
132 const coral::TimeStamp& endTime,
133 std::vector<coral::TimeStamp>& vec_changedate,
134 std::vector<float>& vec_settings,
135 std::vector<std::string>& vec_dpname,
136 std::vector<uint32_t>& vec_dpid) {
137 std::unique_ptr<coral::IQuery>
query(
139 query->addToOutputList(
"FWCAENCHANNEL.CHANGE_DATE",
"CHANGE_DATE");
140 query->addToOutputList(
"FWCAENCHANNEL.SETTINGS_V0",
"VSET");
141 query->addToOutputList(
"FWCAENCHANNEL.DPID",
"DPID");
142 query->addToOutputList(
"DP_NAME2ID.DPNAME",
"DPNAME");
143 query->addToOrderList(
"FWCAENCHANNEL.CHANGE_DATE");
144 query->addToTableList(
"FWCAENCHANNEL");
145 query->addToTableList(
"DP_NAME2ID");
147 "FWCAENCHANNEL.DPID = DP_NAME2ID.ID AND FWCAENCHANNEL.CHANGE_DATE<=:tmax AND FWCAENCHANNEL.SETTINGS_V0 IS NOT " 148 "NULL AND FWCAENCHANNEL.CHANGE_DATE >=:tmin AND (DP_NAME2ID.DPNAME like '%easyBoard%')";
150 coral::AttributeList conditionData;
151 conditionData.extend<coral::TimeStamp>(
"tmax");
152 conditionData.extend<coral::TimeStamp>(
"tmin");
153 query->setCondition(condition, conditionData);
154 conditionData[0].data<coral::TimeStamp>() = endTime;
155 conditionData[1].data<coral::TimeStamp>() = startTime;
157 query->setMemoryCacheSize(100);
158 coral::ICursor& cursor =
query->execute();
160 while (cursor.next()) {
161 const coral::AttributeList& row = cursor.currentRow();
163 row.toOutputStream(
std::cout) << std::endl;
165 coral::TimeStamp ts = row[
"CHANGE_DATE"].data<coral::TimeStamp>();
166 vec_changedate.push_back(ts);
167 float vs = (
float)row[
"VSET"].data<float>();
168 vec_settings.push_back(vs);
169 uint32_t
id = (uint32_t)row[
"DPID"].data<float>();
170 vec_dpid.push_back(
id);
172 vec_dpname.push_back(id_name);
175 edm::LogInfo(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] " << numberRow
176 <<
" rows retrieved from PVSS Cond DB";
180 std::unique_ptr<coral::IQuery>
query(
182 query->addToOutputList(
"DP_NAME2ID.DPNAME",
"DPNAME");
183 query->addToOutputList(
"DP_NAME2ID.ID",
"DPID");
184 query->addToTableList(
"DP_NAME2ID");
186 std::string condition =
"DP_NAME2ID.DPNAME like '%easyBoard%' ";
187 query->setCondition(condition, coral::AttributeList());
189 query->setMemoryCacheSize(100);
190 coral::ICursor& cursor =
query->execute();
192 while (cursor.next()) {
193 const coral::AttributeList& row = cursor.currentRow();
195 uint32_t
id = (uint32_t)row[
"DPID"].data<float>();
196 vec_dpid.push_back(
id);
198 vec_dpname.push_back(id_name);
201 edm::LogInfo(
"SiStripCoralIface") <<
"[SiStripCoralIface::" << __func__ <<
"] " << numberRow
202 <<
" 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 > &)
Transaction & transaction()
SiStripCoralIface(std::string connectionString, std::string authenticationPath, const bool debug)
def query(query_str, verbose=False)
Session createSession(const std::string &connectionString, bool writeCapable=false)
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)
cond::persistency::Session m_session
coral::ISessionProxy & coralSession()
std::unique_ptr< cond::persistency::TransactionScope > m_transaction
void setAuthenticationPath(const std::string &p)