ATLAS Offline Software
Loading...
Searching...
No Matches
IOVDbConn Class Reference

#include <IOVDbConn.h>

Collaboration diagram for IOVDbConn:

Public Member Functions

 IOVDbConn (const std::string &dbname, const bool readOnly, MsgStream &msg)
 ~IOVDbConn ()
bool isActive () const
bool isReadOnly () const
bool aborted () const
unsigned int nFolders () const
const std::string & name () const
void incUsage ()
void decUsage ()
void summary (const float fread)
cool::IDatabasePtr getCoolDb ()
CoraCoolDatabasePtr getCoraCoolDb ()
void setInactive ()
void setReadOnly (const bool readOnly)
bool open ()
void close ()
bool dropAndReconnect ()
bool valid () const
template<typename T = cool::IFolderPtr>
getFolderPtr (const std::string &folderName)
template<>
CoraCoolFolderPtr getFolderPtr (const std::string &folderName)

Private Attributes

MsgStream & m_log
bool m_active
bool m_readonly
bool m_abort
unsigned int m_nconn
unsigned int m_nfolder
const std::string m_connstr
cool::IDatabasePtr m_coolDb
CoraCoolDatabasePtr m_coracoolDb

Detailed Description

Definition at line 18 of file IOVDbConn.h.

Constructor & Destructor Documentation

◆ IOVDbConn()

IOVDbConn::IOVDbConn ( const std::string & dbname,
const bool readOnly,
MsgStream & msg )

Definition at line 17 of file IOVDbConn.cxx.

18 :
19 m_log(msg),
20 m_active(false),
21 m_readonly(readOnly),
22 m_abort(false),
23 m_nconn(0),
24 m_nfolder(0),
25 m_connstr(dbname){
26 //nop
27}
const std::string m_connstr
Definition IOVDbConn.h:55
unsigned int m_nconn
Definition IOVDbConn.h:53
MsgStream & m_log
Definition IOVDbConn.h:49
bool m_abort
Definition IOVDbConn.h:52
bool m_readonly
Definition IOVDbConn.h:51
unsigned int m_nfolder
Definition IOVDbConn.h:54
bool m_active
Definition IOVDbConn.h:50
MsgStream & msg
Definition testRead.cxx:32

◆ ~IOVDbConn()

IOVDbConn::~IOVDbConn ( )
default

Member Function Documentation

◆ aborted()

bool IOVDbConn::aborted ( ) const
inline

Definition at line 66 of file IOVDbConn.h.

66{return m_abort; }

◆ close()

void IOVDbConn::close ( )

Definition at line 80 of file IOVDbConn.cxx.

80 {
82}
void setInactive()

◆ decUsage()

void IOVDbConn::decUsage ( )
inline

Definition at line 74 of file IOVDbConn.h.

74{ --m_nfolder; }

◆ dropAndReconnect()

bool IOVDbConn::dropAndReconnect ( )

Definition at line 85 of file IOVDbConn.cxx.

85 {
86 bool success{};
87 try {
89 success = open();
90 } catch (std::exception& e) {
91 m_log << MSG::WARNING << "Exception from disconnect/reconnect: " <<e.what() << endmsg;
92 // try once more to connect
93 try {
94 success = open();
95 } catch (std::exception& e) {
96 m_log << MSG::ERROR << "Cannot reconnect to database:" << e.what()<< endmsg;
97 }
98 }
99 return success;
100}
#define endmsg
bool open()
Definition IOVDbConn.cxx:74

◆ getCoolDb()

cool::IDatabasePtr IOVDbConn::getCoolDb ( )

Definition at line 31 of file IOVDbConn.cxx.

31 {
32 // only open if not already activated
33 if (not m_coolDb.get()) {
34 // check connection not already aborted
35 if (m_abort) {
36 m_log << MSG::ERROR << "COOL connection for " << m_connstr << " already aborted as invalid" << endmsg;
37 // in this case, return the null connection ptr immediately to avoid
38 // another full attempt to connect
39 return m_coolDb;
40 }
41 // open new connection
42 m_log << MSG::INFO << "Opening COOL connection for " << m_connstr << endmsg;
43 ++m_nconn;
44 cool::IDatabaseSvc& dbSvc = cool::DatabaseSvcFactory::databaseService();
45 try {
46 m_coolDb = dbSvc.openDatabase(m_connstr, m_readonly);
47 m_active = true;
48 } catch (std::exception& e) {
49 // create a new COOL conditions DB
50 if (!m_readonly) {
51 m_log << MSG::INFO << "*** COOL exception caught: " << e.what() << endmsg;
52 m_log << MSG::INFO << "Create a new conditions database: " << m_connstr << endmsg;
53 try {
54 m_coolDb = dbSvc.createDatabase(m_connstr);
55 m_active = true;
56 } catch (std::exception& e) {
57 m_log << MSG::ERROR << "*** COOL exception caught: " << e.what() << endmsg;
58 m_log << MSG::ERROR << "Could not create a new conditions database - abort connection" << endmsg;
59 m_abort = true;
60 m_coolDb.reset();
61 }
62 } else { //read-only-case:
63 m_log << MSG::ERROR << "*** COOL exception caught: " << e.what() << endmsg;
64 m_log << MSG::ERROR << "*** Cannot open database connection [" << m_connstr << "] in " << (m_readonly ? "readonly" : "writing") << " mode - abort connection" << endmsg;
65 m_abort = true;
66 m_coolDb.reset();
67 }
68 }// end catch
69 }
70 return m_coolDb;
71}
cool::IDatabasePtr m_coolDb
Definition IOVDbConn.h:56

◆ getCoraCoolDb()

CoraCoolDatabasePtr IOVDbConn::getCoraCoolDb ( )

Definition at line 102 of file IOVDbConn.cxx.

102 {
103 // only open if not already activated
104 if (not m_coracoolDb.get()) {
105 // open new connection
106 m_log << MSG::INFO << "Opening CoraCool connection for " << m_connstr << endmsg;
107 coral::ConnectionService connSvc;
108 m_coracoolDb=CoraCoolDatabasePtr(new CoraCoolDatabase(m_connstr,m_coolDb,connSvc,m_readonly));
109 m_coracoolDb->connect();
110 }
111 return m_coracoolDb;
112}
boost::shared_ptr< CoraCoolDatabase > CoraCoolDatabasePtr
CoraCoolDatabasePtr m_coracoolDb
Definition IOVDbConn.h:57

◆ getFolderPtr() [1/2]

template<typename T = cool::IFolderPtr>
T IOVDbConn::getFolderPtr ( const std::string & folderName)
inline

Definition at line 43 of file IOVDbConn.h.

43 {
44 if (not m_coolDb.get()) return nullptr;
45 return m_coolDb->getFolder(folderName);
46 }

◆ getFolderPtr() [2/2]

template<>
CoraCoolFolderPtr IOVDbConn::getFolderPtr ( const std::string & folderName)
inline

Definition at line 78 of file IOVDbConn.h.

78 {
79 if (not m_coracoolDb.get()) return nullptr;
80 return m_coracoolDb->getFolder(folderName);
81}

◆ incUsage()

void IOVDbConn::incUsage ( )
inline

Definition at line 72 of file IOVDbConn.h.

72{ ++m_nfolder; }

◆ isActive()

bool IOVDbConn::isActive ( ) const
inline

Definition at line 62 of file IOVDbConn.h.

62{ return m_active; }

◆ isReadOnly()

bool IOVDbConn::isReadOnly ( ) const
inline

Definition at line 64 of file IOVDbConn.h.

64{return m_readonly; }

◆ name()

const std::string & IOVDbConn::name ( ) const
inline

Definition at line 70 of file IOVDbConn.h.

70{ return m_connstr; }

◆ nFolders()

unsigned int IOVDbConn::nFolders ( ) const
inline

Definition at line 68 of file IOVDbConn.h.

68{return m_nfolder; }

◆ open()

bool IOVDbConn::open ( )

Definition at line 74 of file IOVDbConn.cxx.

74 {
76 return valid();
77}
cool::IDatabasePtr getCoolDb()
Definition IOVDbConn.cxx:31
bool valid() const
Definition IOVDbConn.h:60

◆ setInactive()

void IOVDbConn::setInactive ( )

Definition at line 114 of file IOVDbConn.cxx.

114 {
115 if (m_coolDb.get()) {
116 m_log << MSG::INFO << "Disconnecting from " << m_connstr << endmsg;
117 try {
118 m_coolDb->closeDatabase();
119 } catch (std::exception& e) {
120 m_log << MSG::INFO << "Exception caught when disconnecting: " <<e.what() << endmsg;
121 }
122 m_coolDb.reset();
123 }
124 if (m_coracoolDb.get()) {
125 m_log << MSG::INFO << "Disconnecting CoraCool from " << m_connstr << endmsg;
126 try {
127 m_coracoolDb->disconnect();
128 } catch (std::exception& e) {
129 m_log << MSG::INFO << "Exception caught when disconnecting CoraCool: "<< e.what() << endmsg;
130 }
131 m_coracoolDb.reset();
132 }
133 m_active=false;
134}

◆ setReadOnly()

void IOVDbConn::setReadOnly ( const bool readOnly)

Definition at line 136 of file IOVDbConn.cxx.

136 {
137 // reset readonly state, assuming different from current one
138 // close current connection if required
139 setInactive();
140 m_readonly=readOnly;
141}

◆ summary()

void IOVDbConn::summary ( const float fread)

Definition at line 143 of file IOVDbConn.cxx.

143 {
144 // print summary of usage
145 m_log << MSG::INFO << "Connection " << m_connstr << " : nConnect: " <<
146 m_nconn << " nFolders: " << m_nfolder << " ReadTime: (( " << std::fixed <<
147 std::setw(8) << std::setprecision(2) << fread << " ))s" << endmsg;
148}

◆ valid()

bool IOVDbConn::valid ( ) const
inline

Definition at line 60 of file IOVDbConn.h.

60{ return m_coolDb.get()!=0; }

Member Data Documentation

◆ m_abort

bool IOVDbConn::m_abort
private

Definition at line 52 of file IOVDbConn.h.

◆ m_active

bool IOVDbConn::m_active
private

Definition at line 50 of file IOVDbConn.h.

◆ m_connstr

const std::string IOVDbConn::m_connstr
private

Definition at line 55 of file IOVDbConn.h.

◆ m_coolDb

cool::IDatabasePtr IOVDbConn::m_coolDb
private

Definition at line 56 of file IOVDbConn.h.

◆ m_coracoolDb

CoraCoolDatabasePtr IOVDbConn::m_coracoolDb
private

Definition at line 57 of file IOVDbConn.h.

◆ m_log

MsgStream& IOVDbConn::m_log
private

Definition at line 49 of file IOVDbConn.h.

◆ m_nconn

unsigned int IOVDbConn::m_nconn
private

Definition at line 53 of file IOVDbConn.h.

◆ m_nfolder

unsigned int IOVDbConn::m_nfolder
private

Definition at line 54 of file IOVDbConn.h.

◆ m_readonly

bool IOVDbConn::m_readonly
private

Definition at line 51 of file IOVDbConn.h.


The documentation for this class was generated from the following files: