ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MuonCalib::CalibDbConnection Class Reference

#include <CalibDbConnection.h>

Collaboration diagram for MuonCalib::CalibDbConnection:

Public Member Functions

 CalibDbConnection (const std::string &ConnectionString, const std::string &WorkingSchema)
 
virtual ~CalibDbConnection ()
 
bool OpenConnection ()
 
void SetLogin (const std::string &username, const std::string &password)
 
void GetLogin (std::string &username, std::string &password) const
 
const std::string & GetConnectionString () const
 
void SetTargetUser (const std::string &target_user)
 
void OpenTransaction ()
 
void Commit ()
 
void Rollback ()
 
coral::ITableDataEditor & GetTableEditor (const std::string &table_name)
 
coral::IQuery * GetQuery ()
 
void DestroyQuery (coral::IQuery *query)
 

Private Member Functions

coral::IRelationalDomain & domain (const std::string &connectionString)
 

Private Attributes

std::string m_connection_string
 
std::string m_working_schema
 
bool m_comp_loaded
 
std::set< coral::IQuery * > m_queries
 
coral::Context * m_context
 
coral::ISessionProxy * m_session
 
std::string m_username
 
std::string m_password
 
std::string m_target_user
 
bool m_transaction
 

Detailed Description

Definition at line 22 of file CalibDbConnection.h.

Constructor & Destructor Documentation

◆ CalibDbConnection()

MuonCalib::CalibDbConnection::CalibDbConnection ( const std::string &  ConnectionString,
const std::string &  WorkingSchema 
)

Definition at line 38 of file CalibDbConnection.cxx.

38  :
39  m_connection_string(ConnectionString),
40  m_working_schema(WorkingSchema),
41  m_comp_loaded(false),
43  m_session(nullptr),
44  m_transaction(false) {
45  coral::IHandle<coral::IConnectionService> lookSvcH = m_context->query<coral::IConnectionService>();
46  if (!lookSvcH.isValid()) {
47  m_context->loadComponent("CORAL/Services/ConnectionService");
48  lookSvcH = m_context->query<coral::IConnectionService>();
49  }
50  if (!lookSvcH.isValid()) { return; }
51  m_context->loadComponent("CORAL/Services/XMLAuthenticationService");
52  m_context->loadComponent("CORAL/Services/RelationalService");
53  m_comp_loaded = true;
54  m_session = nullptr;
55  }

◆ ~CalibDbConnection()

MuonCalib::CalibDbConnection::~CalibDbConnection ( )
virtual

Definition at line 57 of file CalibDbConnection.cxx.

57  {
58  for (std::set<coral::IQuery*>::iterator it = m_queries.begin(); it != m_queries.end(); ++it) {
59  if (*it) { delete (*it); }
60  }
61  m_queries.clear();
62  }

Member Function Documentation

◆ Commit()

void MuonCalib::CalibDbConnection::Commit ( )

Definition at line 109 of file CalibDbConnection.cxx.

109  {
110  if (m_transaction) {
111  m_session->transaction().commit();
112  m_transaction = false;
113  }
114  }

◆ DestroyQuery()

void MuonCalib::CalibDbConnection::DestroyQuery ( coral::IQuery *  query)

Definition at line 151 of file CalibDbConnection.cxx.

151  {
153  if (it == m_queries.end()) { return; }
154  m_queries.erase(it);
155  delete query;
156  }

◆ domain()

coral::IRelationalDomain & MuonCalib::CalibDbConnection::domain ( const std::string &  connectionString)
private

Definition at line 158 of file CalibDbConnection.cxx.

158  {
159  coral::IHandle<coral::IRelationalService> relationalService = m_context->query<coral::IRelationalService>();
160  if (!relationalService.isValid()) {
161  throw std::runtime_error(
162  Form("File: %s, Line: %d\nCalibDbConnection::domain() - Could not locate the relational service!", __FILE__, __LINE__));
163  }
164 
165  coral::IHandle<coral::IAuthenticationService> authenticationService = m_context->query<coral::IAuthenticationService>();
166  if (!authenticationService.isValid()) {
167  throw std::runtime_error(
168  Form("File: %s, Line: %d\nCalibDbConnection::domain() - Could not locate the authentication service!", __FILE__, __LINE__));
169  }
170  if (m_username == "") {
171  const coral::IAuthenticationCredentials& credentials = authenticationService->credentials(connectionString);
172  m_username = credentials.valueForItem("user");
173  m_password = credentials.valueForItem("password");
174  }
175  if (m_target_user != "" && m_target_user != m_username) { m_username = m_username + "[" + m_target_user + "]"; }
176  return relationalService->domainForConnection(connectionString);
177  }

◆ GetConnectionString()

const std::string& MuonCalib::CalibDbConnection::GetConnectionString ( ) const
inline

Definition at line 38 of file CalibDbConnection.h.

38 { return m_connection_string; }

◆ GetLogin()

void MuonCalib::CalibDbConnection::GetLogin ( std::string &  username,
std::string &  password 
) const
inline

Definition at line 34 of file CalibDbConnection.h.

34  {
35  username = m_username;
37  }

◆ GetQuery()

coral::IQuery * MuonCalib::CalibDbConnection::GetQuery ( )

Definition at line 136 of file CalibDbConnection.cxx.

136  {
137  if (!m_session) {
138  MsgStream log(Athena::getMessageSvc(), "CalibDbConnection");
139  log << MSG::WARNING << "No Session open!" << endmsg;
140  return nullptr;
141  }
142  coral::ISchema& workingSchema = m_session->schema(m_working_schema);
143  coral::IQuery* query = workingSchema.newQuery();
144  m_queries.insert(query);
145  return query;
146  }

◆ GetTableEditor()

coral::ITableDataEditor & MuonCalib::CalibDbConnection::GetTableEditor ( const std::string &  table_name)

Definition at line 129 of file CalibDbConnection.cxx.

129  {
130  return m_session->schema(m_working_schema).tableHandle(table_name).dataEditor();
131  }

◆ OpenConnection()

bool MuonCalib::CalibDbConnection::OpenConnection ( )

Definition at line 68 of file CalibDbConnection.cxx.

68  {
69  if (!m_comp_loaded) { return false; }
70  if (m_session) { return true; }
71 
72  try {
73  // Load CORAL connection service
74  coral::IHandle<coral::IConnectionService> lookSvcH = m_context->query<coral::IConnectionService>();
75  m_context->loadComponent("CORAL/Services/ConnectionService");
76  lookSvcH = m_context->query<coral::IConnectionService>();
77 
78  if (!lookSvcH.isValid()) {
79  throw std::runtime_error(
80  Form("File: %s, Line: %d\nCalibDbConnection::OpenConnection() - Could not locate the connection service!", __FILE__,
81  __LINE__));
82  }
83  // connection to CORAL
84  MsgStream log(Athena::getMessageSvc(), "CalibDbConnection");
85  log << MSG::INFO << "CalibDbConnection::OpenConnection: " << m_connection_string << " Schema: " << m_working_schema << endmsg;
86  m_session = lookSvcH->connect(m_connection_string, coral::Update);
87  return true;
88  } catch (coral::SchemaException& e) {
89  MsgStream log(Athena::getMessageSvc(), "CalibDbConnection");
90  log << MSG::WARNING << "Schema exception : " << e.what() << endmsg;
91  m_session = nullptr;
92  return false;
93  }
94  }

◆ OpenTransaction()

void MuonCalib::CalibDbConnection::OpenTransaction ( )

Definition at line 99 of file CalibDbConnection.cxx.

99  {
100  if (!m_transaction) {
101  m_session->transaction().start();
102  m_transaction = true;
103  }
104  }

◆ Rollback()

void MuonCalib::CalibDbConnection::Rollback ( )

Definition at line 119 of file CalibDbConnection.cxx.

119  {
120  if (m_transaction) {
121  m_session->transaction().rollback();
122  m_transaction = false;
123  }
124  }

◆ SetLogin()

void MuonCalib::CalibDbConnection::SetLogin ( const std::string &  username,
const std::string &  password 
)
inline

Definition at line 30 of file CalibDbConnection.h.

30  {
31  m_username = username;
33  }

◆ SetTargetUser()

void MuonCalib::CalibDbConnection::SetTargetUser ( const std::string &  target_user)
inline

Definition at line 40 of file CalibDbConnection.h.

40 { m_target_user = target_user; }

Member Data Documentation

◆ m_comp_loaded

bool MuonCalib::CalibDbConnection::m_comp_loaded
private

Definition at line 55 of file CalibDbConnection.h.

◆ m_connection_string

std::string MuonCalib::CalibDbConnection::m_connection_string
private

Definition at line 54 of file CalibDbConnection.h.

◆ m_context

coral::Context* MuonCalib::CalibDbConnection::m_context
private

Definition at line 59 of file CalibDbConnection.h.

◆ m_password

std::string MuonCalib::CalibDbConnection::m_password
private

Definition at line 65 of file CalibDbConnection.h.

◆ m_queries

std::set<coral::IQuery*> MuonCalib::CalibDbConnection::m_queries
private

Definition at line 57 of file CalibDbConnection.h.

◆ m_session

coral::ISessionProxy* MuonCalib::CalibDbConnection::m_session
private

Definition at line 61 of file CalibDbConnection.h.

◆ m_target_user

std::string MuonCalib::CalibDbConnection::m_target_user
private

Definition at line 67 of file CalibDbConnection.h.

◆ m_transaction

bool MuonCalib::CalibDbConnection::m_transaction
private

Definition at line 69 of file CalibDbConnection.h.

◆ m_username

std::string MuonCalib::CalibDbConnection::m_username
private

Definition at line 63 of file CalibDbConnection.h.

◆ m_working_schema

std::string MuonCalib::CalibDbConnection::m_working_schema
private

Definition at line 54 of file CalibDbConnection.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
MuonCalib::CalibDbConnection::m_working_schema
std::string m_working_schema
Definition: CalibDbConnection.h:54
MuonCalib::CalibDbConnection::m_transaction
bool m_transaction
Definition: CalibDbConnection.h:69
skel.it
it
Definition: skel.GENtoEVGEN.py:396
MuonCalib::CalibDbConnection::m_username
std::string m_username
Definition: CalibDbConnection.h:63
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonCalib::CalibDbConnection::m_password
std::string m_password
Definition: CalibDbConnection.h:65
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
query
Definition: query.py:1
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib::CalibDbConnection::m_context
coral::Context * m_context
Definition: CalibDbConnection.h:59
MuonCalib::CalibDbConnection::m_target_user
std::string m_target_user
Definition: CalibDbConnection.h:67
GetLBsToIgnore.password
password
Definition: GetLBsToIgnore.py:13
query_example.query
query
Definition: query_example.py:15
MuonCalib::CalibDbConnection::m_queries
std::set< coral::IQuery * > m_queries
Definition: CalibDbConnection.h:57
MuonCalib::CalibDbConnection::m_connection_string
std::string m_connection_string
Definition: CalibDbConnection.h:54
MuonCalib::CalibDbConnection::m_session
coral::ISessionProxy * m_session
Definition: CalibDbConnection.h:61
MuonCalib::CalibDbConnection::m_comp_loaded
bool m_comp_loaded
Definition: CalibDbConnection.h:55
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20