ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
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),
26  //nop
27 }

◆ ~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 74 of file IOVDbConn.cxx.

74  {
75  setInactive();
76 }

◆ decUsage()

void IOVDbConn::decUsage ( )
inline

Definition at line 74 of file IOVDbConn.h.

74 { --m_nfolder; }

◆ dropAndReconnect()

bool IOVDbConn::dropAndReconnect ( )

Definition at line 79 of file IOVDbConn.cxx.

79  {
80  bool success{};
81  try {
82  setInactive();
83  success = open();
84  } catch (std::exception& e) {
85  m_log << MSG::WARNING << "Exception from disconnect/reconnect: " <<e.what() << endmsg;
86  // try once more to connect
87  try {
88  success = open();
89  } catch (std::exception& e) {
90  m_log << MSG::ERROR << "Cannot reconnect to database:" << e.what()<< endmsg;
91  }
92  }
93  return success;
94 }

◆ 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 <<
43  endmsg;
44  ++m_nconn;
45  cool::IDatabaseSvc& dbSvc=cool::DatabaseSvcFactory::databaseService();
46  try {
47  m_coolDb=dbSvc.openDatabase(m_connstr,m_readonly);
48  m_active=true;
49  } catch (std::exception& e) {
50  // create a new COOL conditions DB
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  }
63  }
64  return m_coolDb;
65 }

◆ getCoraCoolDb()

CoraCoolDatabasePtr IOVDbConn::getCoraCoolDb ( )

Definition at line 96 of file IOVDbConn.cxx.

96  {
97  // only open if not already activated
98  if (not m_coracoolDb.get()) {
99  // open new connection
100  m_log << MSG::INFO << "Opening CoraCool connection for " << m_connstr << endmsg;
101  coral::ConnectionService connSvc;
103  m_coracoolDb->connect();
104  }
105  return m_coracoolDb;
106 }

◆ 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 68 of file IOVDbConn.cxx.

68  {
69  m_coolDb = getCoolDb();
70  return valid();
71 }

◆ setInactive()

void IOVDbConn::setInactive ( )

Definition at line 108 of file IOVDbConn.cxx.

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

◆ setReadOnly()

void IOVDbConn::setReadOnly ( const bool  readOnly)

Definition at line 130 of file IOVDbConn.cxx.

130  {
131  // reset readonly state, assuming different from current one
132  // close current connection if required
133  setInactive();
134  m_readonly=readOnly;
135 }

◆ summary()

void IOVDbConn::summary ( const float  fread)

Definition at line 137 of file IOVDbConn.cxx.

137  {
138  // print summary of usage
139  m_log << MSG::INFO << "Connection " << m_connstr << " : nConnect: " <<
140  m_nconn << " nFolders: " << m_nfolder << " ReadTime: (( " << std::fixed <<
141  std::setw(8) << std::setprecision(2) << fread << " ))s" << endmsg;
142 }

◆ 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:
IOVDbConn::m_log
MsgStream & m_log
Definition: IOVDbConn.h:49
CaloNoise_fillDB.dbname
dbname
Definition: CaloNoise_fillDB.py:43
CoraCoolDatabase
Definition: CoraCoolDatabase.h:24
IOVDbConn::m_coracoolDb
CoraCoolDatabasePtr m_coracoolDb
Definition: IOVDbConn.h:57
IOVDbConn::open
bool open()
Definition: IOVDbConn.cxx:68
IOVDbConn::m_nconn
unsigned int m_nconn
Definition: IOVDbConn.h:53
IOVDbConn::valid
bool valid() const
Definition: IOVDbConn.h:60
IOVDbConn::m_readonly
bool m_readonly
Definition: IOVDbConn.h:51
IOVDbConn::m_nfolder
unsigned int m_nfolder
Definition: IOVDbConn.h:54
IOVDbConn::m_coolDb
cool::IDatabasePtr m_coolDb
Definition: IOVDbConn.h:56
IOVDbConn::getCoolDb
cool::IDatabasePtr getCoolDb()
Definition: IOVDbConn.cxx:31
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
calibdata.exception
exception
Definition: calibdata.py:496
IOVDbConn::m_abort
bool m_abort
Definition: IOVDbConn.h:52
CaloNoise_fillDB.dbSvc
dbSvc
Definition: CaloNoise_fillDB.py:108
IOVDbConn::setInactive
void setInactive()
Definition: IOVDbConn.cxx:108
CoraCoolDatabasePtr
boost::shared_ptr< CoraCoolDatabase > CoraCoolDatabasePtr
Definition: CoraCoolTypes.h:12
CaloCellTimeCorrFiller.folderName
string folderName
Definition: CaloCellTimeCorrFiller.py:20
IOVDbConn::m_active
bool m_active
Definition: IOVDbConn.h:50
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
IOVDbConn::m_connstr
const std::string m_connstr
Definition: IOVDbConn.h:55
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7