ATLAS Offline Software
IOVDbConn.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // IOVDbConn.h
6 // helper class for IOVDbSvc managing DB connections
7 // Richard Hawkings, started 24/11/08
8 #ifndef IOVDbSvc_IOVDbConn_h
9 #define IOVDbSvc_IOVDbConn_h
10 
11 #include "CoolKernel/IDatabase.h"
12 #include "CoolKernel/IFolder.h"
13 #include "CoraCool/CoraCoolTypes.h"
15 
16 class MsgStream;
17 
18 class IOVDbConn {
19  public:
20  IOVDbConn(const std::string& dbname, const bool readOnly, MsgStream & msg);
22 
23  bool isActive() const;
24  bool isReadOnly() const;
25  bool aborted() const;
26  unsigned int nFolders() const;
27  const std::string& name() const;
28 
29  void incUsage();
30  void decUsage();
31  void summary(const float fread);
32  cool::IDatabasePtr getCoolDb();
34  void setInactive();
35  void setReadOnly(const bool readOnly);
36  bool open();
37  void close();
38  bool dropAndReconnect();
39  bool valid() const;
40 
41  template<typename T=cool::IFolderPtr>
42  T
43  getFolderPtr(const std::string &folderName){
44  if (not m_coolDb.get()) return nullptr;
45  return m_coolDb->getFolder(folderName);
46  }
47 
48  private:
49  MsgStream & m_log;
50  bool m_active;
51  bool m_readonly;
52  bool m_abort;
53  unsigned int m_nconn;
54  unsigned int m_nfolder;
55  const std::string m_connstr;
56  cool::IDatabasePtr m_coolDb;
58 };
59 
60 inline bool IOVDbConn::valid() const { return m_coolDb.get()!=0; }
61 
62 inline bool IOVDbConn::isActive() const { return m_active; }
63 
64 inline bool IOVDbConn::isReadOnly() const {return m_readonly; }
65 
66 inline bool IOVDbConn::aborted() const {return m_abort; }
67 
68 inline unsigned int IOVDbConn::nFolders() const {return m_nfolder; }
69 
70 inline const std::string& IOVDbConn::name() const { return m_connstr; }
71 
72 inline void IOVDbConn::incUsage() { ++m_nfolder; }
73 
74 inline void IOVDbConn::decUsage() { --m_nfolder; }
75 
76 template<>
77 inline CoraCoolFolderPtr
78 IOVDbConn::getFolderPtr(const std::string &folderName){
79  if (not m_coracoolDb.get()) return nullptr;
80  return m_coracoolDb->getFolder(folderName);
81 }
82 
83 #endif // IOVDbSvc_IOVDbConn_h
IOVDbConn::incUsage
void incUsage()
Definition: IOVDbConn.h:72
IOVDbConn::m_log
MsgStream & m_log
Definition: IOVDbConn.h:49
CaloNoise_fillDB.dbname
dbname
Definition: CaloNoise_fillDB.py:43
IOVDbConn::aborted
bool aborted() const
Definition: IOVDbConn.h:66
CoraCoolTypes.h
IOVDbConn::m_coracoolDb
CoraCoolDatabasePtr m_coracoolDb
Definition: IOVDbConn.h:57
IOVDbConn::open
bool open()
Definition: IOVDbConn.cxx:68
IOVDbConn::name
const std::string & name() const
Definition: IOVDbConn.h:70
IOVDbConn::m_nconn
unsigned int m_nconn
Definition: IOVDbConn.h:53
IOVDbConn::close
void close()
Definition: IOVDbConn.cxx:74
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::getFolderPtr
T getFolderPtr(const std::string &folderName)
Definition: IOVDbConn.h:43
IOVDbConn::isActive
bool isActive() const
Definition: IOVDbConn.h:62
IOVDbConn::getCoolDb
cool::IDatabasePtr getCoolDb()
Definition: IOVDbConn.cxx:31
IOVDbConn::~IOVDbConn
~IOVDbConn()
IOVDbConn::m_abort
bool m_abort
Definition: IOVDbConn.h:52
IOVDbConn::nFolders
unsigned int nFolders() const
Definition: IOVDbConn.h:68
IOVDbConn::IOVDbConn
IOVDbConn(const std::string &dbname, const bool readOnly, MsgStream &msg)
Definition: IOVDbConn.cxx:17
IOVDbConn::isReadOnly
bool isReadOnly() const
Definition: IOVDbConn.h:64
CoraCoolFolderPtr
boost::shared_ptr< CoraCoolFolder > CoraCoolFolderPtr
Definition: CoraCoolTypes.h:15
IOVDbConn::summary
void summary(const float fread)
Definition: IOVDbConn.cxx:137
IOVDbConn::setInactive
void setInactive()
Definition: IOVDbConn.cxx:108
CoraCoolDatabasePtr
boost::shared_ptr< CoraCoolDatabase > CoraCoolDatabasePtr
Definition: CoraCoolTypes.h:12
IOVDbConn
Definition: IOVDbConn.h:18
CaloCellTimeCorrFiller.folderName
string folderName
Definition: CaloCellTimeCorrFiller.py:20
IOVDbConn::m_active
bool m_active
Definition: IOVDbConn.h:50
IOVDbConn::setReadOnly
void setReadOnly(const bool readOnly)
Definition: IOVDbConn.cxx:130
IOVDbConn::decUsage
void decUsage()
Definition: IOVDbConn.h:74
IOVDbConn::m_connstr
const std::string m_connstr
Definition: IOVDbConn.h:55
CoraCoolDatabase.h
IOVDbConn::dropAndReconnect
bool dropAndReconnect()
Definition: IOVDbConn.cxx:79
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
IOVDbConn::getCoraCoolDb
CoraCoolDatabasePtr getCoraCoolDb()
Definition: IOVDbConn.cxx:96
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35