CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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_
 
cond::DbConnection m_connection
 
std::string m_connectionString
 
std::map< std::string,
unsigned int > 
m_id_map
 
cond::DbSession m_session
 
std::auto_ptr
< cond::DbScopedTransaction
m_transaction
 

Detailed Description

An interface class to the PVSS cond DB.

Author
J.Chen, J.Cole

Definition at line 20 of file SiStripCoralIface.h.

Constructor & Destructor Documentation

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

constructor

Definition at line 21 of file SiStripCoralIface.cc.

References cond::DbConnection::configuration(), cond::DbConnection::configure(), gather_cfg::cout, initialize(), m_connection, and cond::DbConnectionConfiguration::setAuthenticationPath().

21  : m_connectionString(connectionString), m_session(), debug_(debug)
22 {
23  std::cout << "Building coral interface" << std::endl;
24  m_connection.configuration().setAuthenticationPath(authenticationPath);
26  initialize();
27 }
std::string m_connectionString
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:83
cond::DbConnection m_connection
cond::DbSession m_session
#define debug
Definition: HDRShower.cc:19
void setAuthenticationPath(const std::string &p)
tuple cout
Definition: gather_cfg.py:121
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

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

Definition at line 158 of file SiStripCoralIface.cc.

References LogTrace, m_session, o2o::query, cond::DbSession::schema(), and AlCaHLTBitMon_QueryRunRegistry::string.

159 {
160  std::auto_ptr<coral::IQuery> query( m_session.schema(std::string("CMS_TRK_DCS_PVSS_COND")).newQuery());
161  query->addToOutputList("DP_NAME2ID.DPNAME","DPNAME");
162  query->addToOutputList("DP_NAME2ID.ID","DPID");
163  query->addToTableList("DP_NAME2ID");
164 
165  std::string condition = "DP_NAME2ID.dpname like '%easyBoard%' ";
166  query->setCondition( condition, coral::AttributeList() );
167 
168  query->setMemoryCacheSize( 100 );
169  coral::ICursor& cursor = query->execute();
170  int numberRow=0;
171  while( cursor.next() ){
172  const coral::AttributeList& row = cursor.currentRow();
173  numberRow++;
174  uint32_t id = (uint32_t)row["DPID"].data<float>();
175  vec_dpid.push_back(id);
176  std::string id_name = (std::string)row["DPNAME"].data<std::string>();
177  vec_dpname.push_back(id_name);
178  }
179  cursor.close();
180  LogTrace("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] " << numberRow << " rows retrieved from PVSS Cond DB";
181 }
coral::ISchema & schema(const std::string &schemaName)
Definition: DbSession.cc:242
cond::DbSession m_session
#define LogTrace(id)
tuple query
Definition: o2o.py:269
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 51 of file SiStripCoralIface.cc.

References gather_cfg::cout, debug_, LogTrace, m_session, o2o::query, builder_last_value_cfg::queryType, cond::DbSession::schema(), and AlCaHLTBitMon_QueryRunRegistry::string.

53 {
54  std::auto_ptr<coral::IQuery> query( m_session.schema(std::string("CMS_TRK_DCS_PVSS_COND")).newQuery());
55  std::string condition;
56 
57  LogTrace("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] table to be accessed: " << queryType;
58 
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%')";
75  }
76 
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;
83 
84  query->setMemoryCacheSize( 100 );
85  std::cout<<"Executing query"<<std::endl;
86  if (debug_) std::cout<<"[SiStripCoralIface::"<<__func__<<"] Dumping all query results:"<<std::endl;
87  coral::ICursor& cursor = query->execute();
88  int numberRow=0;
89  while( cursor.next() ){
90  const coral::AttributeList& row = cursor.currentRow();
91  //DEBUG
92  //Output the query results directly to cout,
93  //Can be subsequently parsed by Python validation code
94  if( debug_ ) row.toOutputStream( std::cout ) << std::endl;
95  numberRow++;
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);
101  std::string id_name = (std::string)row["DPNAME"].data<std::string>();
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);
108  std::string id_name = (std::string)row["DPNAME"].data<std::string>();
109  vec_dpname.push_back(id_name);
110  }
111  }
112  cursor.close();
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";
115 }
coral::ISchema & schema(const std::string &schemaName)
Definition: DbSession.cc:242
cond::DbSession m_session
#define LogTrace(id)
tuple query
Definition: o2o.py:269
tuple cout
Definition: gather_cfg.py:121
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 118 of file SiStripCoralIface.cc.

References gather_cfg::cout, debug_, LogTrace, m_session, o2o::query, cond::DbSession::schema(), and AlCaHLTBitMon_QueryRunRegistry::string.

120 {
121  std::auto_ptr<coral::IQuery> query( m_session.schema(std::string("CMS_TRK_DCS_PVSS_COND")).newQuery());
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%')";
130 
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;
137 
138  query->setMemoryCacheSize( 100 );
139  coral::ICursor& cursor = query->execute();
140  int numberRow=0;
141  while( cursor.next() ){
142  const coral::AttributeList& row = cursor.currentRow();
143  if( debug_ ) row.toOutputStream( std::cout ) << std::endl;
144  numberRow++;
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);
151  std::string id_name = (std::string)row["DPNAME"].data<std::string>();
152  vec_dpname.push_back(id_name);
153  }
154  cursor.close();
155  LogTrace("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] " << numberRow << " rows retrieved from PVSS Cond DB";
156 }
coral::ISchema & schema(const std::string &schemaName)
Definition: DbSession.cc:242
cond::DbSession m_session
#define LogTrace(id)
tuple query
Definition: o2o.py:269
tuple cout
Definition: gather_cfg.py:121
void SiStripCoralIface::initialize ( )
private

Set up the connection to the database

Definition at line 36 of file SiStripCoralIface.cc.

References cond::DbConnection::createSession(), cmsRelvalreport::exit, LogTrace, m_connection, m_connectionString, m_session, m_transaction, and cond::DbSession::open().

Referenced by SiStripCoralIface().

36  {
39  try {
41  m_transaction->start(true);
42  LogTrace("SiStripCoralIface") << "[SiStripCoralIface::" << __func__ << "] Database connection opened";
43  }
44  catch (...) {
45  edm::LogError("SiStripCoralIface") << "Database connection failed";
46  exit(1);
47  }
48 }
std::string m_connectionString
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:159
cond::DbConnection m_connection
cond::DbSession m_session
#define LogTrace(id)
std::auto_ptr< cond::DbScopedTransaction > m_transaction
DbSession createSession() const
Definition: DbConnection.cc:66

Member Data Documentation

bool SiStripCoralIface::debug_
private

Definition at line 47 of file SiStripCoralIface.h.

Referenced by doQuery(), and doSettingsQuery().

cond::DbConnection SiStripCoralIface::m_connection
private

Definition at line 41 of file SiStripCoralIface.h.

Referenced by initialize(), and SiStripCoralIface().

std::string SiStripCoralIface::m_connectionString
private

Definition at line 38 of file SiStripCoralIface.h.

Referenced by initialize().

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

Definition at line 39 of file SiStripCoralIface.h.

cond::DbSession SiStripCoralIface::m_session
private

Definition at line 42 of file SiStripCoralIface.h.

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

std::auto_ptr<cond::DbScopedTransaction> SiStripCoralIface::m_transaction
private

Definition at line 45 of file SiStripCoralIface.h.

Referenced by initialize().