ATLAS Offline Software
Loading...
Searching...
No Matches
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"
15
16class MsgStream;
17
18class 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;
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
60inline bool IOVDbConn::valid() const { return m_coolDb.get()!=0; }
61
62inline bool IOVDbConn::isActive() const { return m_active; }
63
64inline bool IOVDbConn::isReadOnly() const {return m_readonly; }
65
66inline bool IOVDbConn::aborted() const {return m_abort; }
67
68inline unsigned int IOVDbConn::nFolders() const {return m_nfolder; }
69
70inline const std::string& IOVDbConn::name() const { return m_connstr; }
71
72inline void IOVDbConn::incUsage() { ++m_nfolder; }
73
74inline void IOVDbConn::decUsage() { --m_nfolder; }
75
76template<>
78IOVDbConn::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
boost::shared_ptr< CoraCoolDatabase > CoraCoolDatabasePtr
boost::shared_ptr< CoraCoolFolder > CoraCoolFolderPtr
void summary(const float fread)
bool isActive() const
Definition IOVDbConn.h:62
CoraCoolDatabasePtr m_coracoolDb
Definition IOVDbConn.h:57
void decUsage()
Definition IOVDbConn.h:74
CoraCoolDatabasePtr getCoraCoolDb()
void setReadOnly(const bool readOnly)
const std::string & name() const
Definition IOVDbConn.h:70
void close()
Definition IOVDbConn.cxx:80
T getFolderPtr(const std::string &folderName)
Definition IOVDbConn.h:43
const std::string m_connstr
Definition IOVDbConn.h:55
unsigned int m_nconn
Definition IOVDbConn.h:53
bool isReadOnly() const
Definition IOVDbConn.h:64
void setInactive()
MsgStream & m_log
Definition IOVDbConn.h:49
cool::IDatabasePtr getCoolDb()
Definition IOVDbConn.cxx:31
cool::IDatabasePtr m_coolDb
Definition IOVDbConn.h:56
bool m_abort
Definition IOVDbConn.h:52
bool m_readonly
Definition IOVDbConn.h:51
bool dropAndReconnect()
Definition IOVDbConn.cxx:85
bool valid() const
Definition IOVDbConn.h:60
unsigned int nFolders() const
Definition IOVDbConn.h:68
unsigned int m_nfolder
Definition IOVDbConn.h:54
IOVDbConn(const std::string &dbname, const bool readOnly, MsgStream &msg)
Definition IOVDbConn.cxx:17
bool open()
Definition IOVDbConn.cxx:74
bool aborted() const
Definition IOVDbConn.h:66
bool m_active
Definition IOVDbConn.h:50
void incUsage()
Definition IOVDbConn.h:72
MsgStream & msg
Definition testRead.cxx:32