CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SiStripCoralIface Class Reference

An interface class to the PVSS cond DB. More...

#include <SiStripCoralIface.h>

Public Member Functions

void doNameQuery (std::vector< std::string > &vec_dpname, std::vector< uint32_t > &vec_dpid)
 
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 doSettingsQuery (const coral::TimeStamp &startTime, const coral::TimeStamp &endTime, std::vector< coral::TimeStamp > &, std::vector< float > &, std::vector< std::string > &, std::vector< uint32_t > &)
 
 SiStripCoralIface (std::string connectionString, std::string authenticationPath, const bool debug)
 
 ~SiStripCoralIface ()
 

Private Member Functions

void initialize ()
 

Private Attributes

bool debug_
 
std::string m_authPath
 
std::string m_connectionString
 
std::map< std::string, unsigned int > m_id_map
 
cond::persistency::Session m_session
 
std::unique_ptr< cond::persistency::TransactionScopem_transaction
 

Detailed Description

An interface class to the PVSS cond DB.

Author
J.Chen, J.Cole

Definition at line 17 of file SiStripCoralIface.h.

Constructor & Destructor Documentation

◆ SiStripCoralIface()

SiStripCoralIface::SiStripCoralIface ( std::string  connectionString,
std::string  authenticationPath,
const bool  debug 
)

constructor

Definition at line 23 of file SiStripCoralIface.cc.

References gather_cfg::cout, and initialize().

25  std::cout << "Building coral interface" << std::endl;
26  initialize();
27 }
std::string m_connectionString
std::string m_authPath
#define debug
Definition: HDRShower.cc:19
cond::persistency::Session m_session

◆ ~SiStripCoralIface()

SiStripCoralIface::~SiStripCoralIface ( )

destructor

Definition at line 30 of file SiStripCoralIface.cc.

References LogTrace.

30  {
31  LogTrace("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] Destructor called.";
32  // m_connection.close();
33 }
#define LogTrace(id)

Member Function Documentation

◆ doNameQuery()

void SiStripCoralIface::doNameQuery ( std::vector< std::string > &  vec_dpname,
std::vector< uint32_t > &  vec_dpid 
)

Definition at line 181 of file SiStripCoralIface.cc.

References cond::persistency::Session::coralSession(), m_session, contentValuesFiles::query, and AlCaHLTBitMon_QueryRunRegistry::string.

181  {
182  std::unique_ptr<coral::IQuery> query(
183  m_session.coralSession().schema(std::string("CMS_TRK_DCS_PVSS_COND")).newQuery());
184  query->addToOutputList("DP_NAME2ID.DPNAME", "DPNAME");
185  query->addToOutputList("DP_NAME2ID.ID", "DPID");
186  query->addToTableList("DP_NAME2ID");
187 
188  std::string condition = "DP_NAME2ID.DPNAME like '%easyBoard%' ";
189  query->setCondition(condition, coral::AttributeList());
190 
191  query->setMemoryCacheSize(100);
192  coral::ICursor& cursor = query->execute();
193  int numberRow = 0;
194  while (cursor.next()) {
195  const coral::AttributeList& row = cursor.currentRow();
196  numberRow++;
197  uint32_t id = (uint32_t)row["DPID"].data<float>();
198  vec_dpid.push_back(id);
199  std::string id_name = (std::string)row["DPNAME"].data<std::string>();
200  vec_dpname.push_back(id_name);
201  }
202  cursor.close();
203  edm::LogInfo("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] " << numberRow
204  << " rows retrieved from PVSS Cond DB";
205 }
Definition: query.py:1
Log< level::Info, false > LogInfo
cond::persistency::Session m_session
coral::ISessionProxy & coralSession()
Definition: Session.cc:218

◆ doQuery()

void SiStripCoralIface::doQuery ( std::string  queryType,
const coral::TimeStamp &  startTime,
const coral::TimeStamp &  endTime,
std::vector< coral::TimeStamp > &  vec_changedate,
std::vector< float > &  vec_actualValue,
std::vector< std::string > &  vec_dpname 
)

Method to retrieve information from status change table or lastValue table. queryType defines which table is to be accessed.

Definition at line 52 of file SiStripCoralIface.cc.

References cond::persistency::Session::coralSession(), gather_cfg::cout, debug_, endTime, dqmMemoryStats::float, LogTrace, m_session, contentValuesFiles::query, startTime, and AlCaHLTBitMon_QueryRunRegistry::string.

57  {
58  std::unique_ptr<coral::IQuery> query(
59  m_session.coralSession().schema(std::string("CMS_TRK_DCS_PVSS_COND")).newQuery());
60  std::string condition;
61 
62  LogTrace("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] table to be accessed: " << queryType;
63 
64  if (queryType == "STATUSCHANGE") {
65  query->addToOutputList("FWCAENCHANNEL.CHANGE_DATE", "CHANGE_DATE");
66  query->addToOutputList("FWCAENCHANNEL.ACTUAL_STATUS", "ACTUAL_STATUS");
67  query->addToOutputList("DP_NAME2ID.DPNAME", "DPNAME");
68  query->addToOrderList("FWCAENCHANNEL.CHANGE_DATE");
69  query->addToTableList("FWCAENCHANNEL");
70  query->addToTableList("DP_NAME2ID");
71  condition =
72  "FWCAENCHANNEL.DPID = DP_NAME2ID.ID AND FWCAENCHANNEL.CHANGE_DATE<=:tmax AND FWCAENCHANNEL.ACTUAL_STATUS IS "
73  "NOT NULL AND FWCAENCHANNEL.CHANGE_DATE >=:tmin AND (DP_NAME2ID.DPNAME like '%easyBoard%')";
74  } else if (queryType == "LASTVALUE") {
75  query->addToOutputList("DCSLASTVALUE_VOLTAGE.CHANGE_DATE", "CHANGE_DATE");
76  query->addToOutputList("DCSLASTVALUE_VOLTAGE.ACTUAL_VMON", "ACTUAL_VMON");
77  query->addToOutputList("DP_NAME2ID.DPNAME", "DPNAME");
78  query->addToOrderList("DCSLASTVALUE_VOLTAGE.CHANGE_DATE");
79  query->addToTableList("DCSLASTVALUE_VOLTAGE");
80  query->addToTableList("DP_NAME2ID");
81  condition =
82  "DCSLASTVALUE_VOLTAGE.DPID = DP_NAME2ID.ID AND DCSLASTVALUE_VOLTAGE.CHANGE_DATE<=:tmax AND "
83  "DCSLASTVALUE_VOLTAGE.CHANGE_DATE>=:tmin AND DCSLASTVALUE_VOLTAGE.ACTUAL_VMON IS NOT NULL AND "
84  "(DP_NAME2ID.DPNAME like '%easyBoard%')";
85  }
86 
87  coral::AttributeList conditionData;
88  conditionData.extend<coral::TimeStamp>("tmax");
89  conditionData.extend<coral::TimeStamp>("tmin");
90  query->setCondition(condition, conditionData);
91  conditionData[0].data<coral::TimeStamp>() = endTime;
92  conditionData[1].data<coral::TimeStamp>() = startTime;
93 
94  query->setMemoryCacheSize(100);
95  std::cout << "Executing query" << std::endl;
96  if (debug_)
97  std::cout << "[SiStripCoralIface::" << __func__ << "] Dumping all query results:" << std::endl;
98  coral::ICursor& cursor = query->execute();
99  int numberRow = 0;
100  while (cursor.next()) {
101  const coral::AttributeList& row = cursor.currentRow();
102  //DEBUG
103  //Output the query results directly to cout,
104  //Can be subsequently parsed by Python validation code
105  if (debug_)
106  row.toOutputStream(std::cout) << std::endl;
107  numberRow++;
108  if (queryType == "STATUSCHANGE") {
109  coral::TimeStamp ts = row["CHANGE_DATE"].data<coral::TimeStamp>();
110  vec_changedate.push_back(ts);
111  float as = (float)row["ACTUAL_STATUS"].data<float>();
112  vec_actualValue.push_back(as);
113  std::string id_name = (std::string)row["DPNAME"].data<std::string>();
114  vec_dpname.push_back(id_name);
115  } else if (queryType == "LASTVALUE") {
116  coral::TimeStamp ts = row["CHANGE_DATE"].data<coral::TimeStamp>();
117  vec_changedate.push_back(ts);
118  float av = (float)row["ACTUAL_VMON"].data<float>();
119  vec_actualValue.push_back(av);
120  std::string id_name = (std::string)row["DPNAME"].data<std::string>();
121  vec_dpname.push_back(id_name);
122  }
123  }
124  cursor.close();
125  if (debug_)
126  std::cout << "[SiStripCoralIface::" << __func__ << "] Finished dumping query results, " << numberRow
127  << " rows were retrieved from PVSS Cond DB (both Pixel and Strip CAEN supplies)" << std::endl;
128  edm::LogInfo("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] " << numberRow
129  << " rows retrieved from PVSS Cond DB";
130 }
#define LogTrace(id)
Definition: query.py:1
string startTime
Log< level::Info, false > LogInfo
cond::persistency::Session m_session
coral::ISessionProxy & coralSession()
Definition: Session.cc:218
string endTime

◆ doSettingsQuery()

void SiStripCoralIface::doSettingsQuery ( const coral::TimeStamp &  startTime,
const coral::TimeStamp &  endTime,
std::vector< coral::TimeStamp > &  vec_changedate,
std::vector< float > &  vec_settings,
std::vector< std::string > &  vec_dpname,
std::vector< uint32_t > &  vec_dpid 
)

Method to access the settings for each channel stored in the status change table

Definition at line 133 of file SiStripCoralIface.cc.

References cond::persistency::Session::coralSession(), gather_cfg::cout, debug_, endTime, dqmMemoryStats::float, m_session, contentValuesFiles::query, startTime, and AlCaHLTBitMon_QueryRunRegistry::string.

138  {
139  std::unique_ptr<coral::IQuery> query(
140  m_session.coralSession().schema(std::string("CMS_TRK_DCS_PVSS_COND")).newQuery());
141  query->addToOutputList("FWCAENCHANNEL.CHANGE_DATE", "CHANGE_DATE");
142  query->addToOutputList("FWCAENCHANNEL.SETTINGS_V0", "VSET");
143  query->addToOutputList("FWCAENCHANNEL.DPID", "DPID");
144  query->addToOutputList("DP_NAME2ID.DPNAME", "DPNAME");
145  query->addToOrderList("FWCAENCHANNEL.CHANGE_DATE");
146  query->addToTableList("FWCAENCHANNEL");
147  query->addToTableList("DP_NAME2ID");
148  std::string condition =
149  "FWCAENCHANNEL.DPID = DP_NAME2ID.ID AND FWCAENCHANNEL.CHANGE_DATE<=:tmax AND FWCAENCHANNEL.SETTINGS_V0 IS NOT "
150  "NULL AND FWCAENCHANNEL.CHANGE_DATE >=:tmin AND (DP_NAME2ID.DPNAME like '%easyBoard%')";
151 
152  coral::AttributeList conditionData;
153  conditionData.extend<coral::TimeStamp>("tmax");
154  conditionData.extend<coral::TimeStamp>("tmin");
155  query->setCondition(condition, conditionData);
156  conditionData[0].data<coral::TimeStamp>() = endTime;
157  conditionData[1].data<coral::TimeStamp>() = startTime;
158 
159  query->setMemoryCacheSize(100);
160  coral::ICursor& cursor = query->execute();
161  int numberRow = 0;
162  while (cursor.next()) {
163  const coral::AttributeList& row = cursor.currentRow();
164  if (debug_)
165  row.toOutputStream(std::cout) << std::endl;
166  numberRow++;
167  coral::TimeStamp ts = row["CHANGE_DATE"].data<coral::TimeStamp>();
168  vec_changedate.push_back(ts);
169  float vs = (float)row["VSET"].data<float>();
170  vec_settings.push_back(vs);
171  uint32_t id = (uint32_t)row["DPID"].data<float>();
172  vec_dpid.push_back(id);
173  std::string id_name = (std::string)row["DPNAME"].data<std::string>();
174  vec_dpname.push_back(id_name);
175  }
176  cursor.close();
177  edm::LogInfo("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] " << numberRow
178  << " rows retrieved from PVSS Cond DB";
179 }
Definition: query.py:1
string startTime
Log< level::Info, false > LogInfo
cond::persistency::Session m_session
coral::ISessionProxy & coralSession()
Definition: Session.cc:218
string endTime

◆ initialize()

void SiStripCoralIface::initialize ( )
private

Set up the connection to the database

Definition at line 36 of file SiStripCoralIface.cc.

References cond::persistency::ConnectionPool::configure(), cond::persistency::ConnectionPool::createSession(), beamvalidation::exit(), LogTrace, m_authPath, m_connectionString, m_session, m_transaction, cond::persistency::ConnectionPool::setAuthenticationPath(), and cond::persistency::Session::transaction().

Referenced by SiStripCoralIface().

36  {
39  connection.configure();
41  try {
42  m_transaction = std::make_unique<cond::persistency::TransactionScope>(m_session.transaction());
43  m_transaction->start(true);
44  LogTrace("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] Database connection opened";
45  } catch (...) {
46  edm::LogError("SiStripCoralIface") << "Database connection failed";
47  exit(1);
48  }
49 }
std::string m_connectionString
std::string m_authPath
Log< level::Error, false > LogError
Transaction & transaction()
Definition: Session.cc:52
#define LogTrace(id)
Session createSession(const std::string &connectionString, bool writeCapable=false)
cond::persistency::Session m_session
std::unique_ptr< cond::persistency::TransactionScope > m_transaction
void setAuthenticationPath(const std::string &p)
def exit(msg="")

Member Data Documentation

◆ debug_

bool SiStripCoralIface::debug_
private

Definition at line 53 of file SiStripCoralIface.h.

Referenced by doQuery(), and doSettingsQuery().

◆ m_authPath

std::string SiStripCoralIface::m_authPath
private

Definition at line 46 of file SiStripCoralIface.h.

Referenced by initialize().

◆ m_connectionString

std::string SiStripCoralIface::m_connectionString
private

Definition at line 45 of file SiStripCoralIface.h.

Referenced by initialize().

◆ m_id_map

std::map<std::string, unsigned int> SiStripCoralIface::m_id_map
private

Definition at line 47 of file SiStripCoralIface.h.

◆ m_session

cond::persistency::Session SiStripCoralIface::m_session
private

Definition at line 48 of file SiStripCoralIface.h.

Referenced by doNameQuery(), doQuery(), doSettingsQuery(), and initialize().

◆ m_transaction

std::unique_ptr<cond::persistency::TransactionScope> SiStripCoralIface::m_transaction
private

Definition at line 49 of file SiStripCoralIface.h.

Referenced by initialize().