ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
APR
StorageSvc
src
DbAccessObj.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
//====================================================================
6
// DbAccessObj Base class definitions
7
//--------------------------------------------------------------------
8
//
9
// Package : StorageSvc (The POOL project)
10
// @author M.Frank
11
//====================================================================
12
#ifndef POOL_DBACCESSOBJ_H
13
#define POOL_DBACCESSOBJ_H 1
14
15
// Framework include files
16
#include "
StorageSvc/pool.h
"
17
#include "
StorageSvc/DbType.h
"
18
#include "
StorageSvc/IOODatabase.h
"
19
#include "GaudiKernel/StatusCode.h"
20
21
// STL include files
22
#include <map>
23
#include <utility>
24
#include <atomic>
25
26
// #define DEBUG_REFCOUNTS
27
#ifdef DEBUG_REFCOUNTS
28
# include<iostream>
29
#endif
30
31
/*
32
* POOL namespace declaration
33
*/
34
namespace
pool
{
35
47
49
class
DbAccessObjBase
{
50
private
:
52
mutable
std::atomic<int>
m_refCount
;
54
Io::IoFlag
m_mode
;
56
std::string
m_name
;
58
DbType
m_type
;
60
IOODatabase
*
m_pool
;
61
62
public
:
64
DbAccessObjBase
(
const
std::string& n, Io::IoFlag m,
const
DbType
& t,
IOODatabase
* s=0)
65
:
m_refCount
(0),
m_mode
(m),
m_name
(n),
m_type
(t),
m_pool
(s)
66
{
if
(
m_pool
)
m_pool
->addRef(); }
67
68
virtual
~DbAccessObjBase
() {
releasePtr
(
m_pool
); }
70
const
std::string&
name
()
const
{
return
m_name
; }
72
void
setName
(
const
std::string& n){
m_name
= n; }
74
Io::IoFlag
mode
()
const
{
return
m_mode
; }
76
void
setMode
(Io::IoFlag m) {
m_mode
= m; }
77
// Inline functions
78
const
DbType
&
type
()
const
{
return
m_type
; }
80
const
IOODatabase
*
db
()
const
{
return
m_pool
; }
81
IOODatabase
*
db
() {
return
m_pool
; }
83
int
refCount
()
const
{
return
m_refCount
; }
85
int
addRef
()
const
{
86
#ifdef DEBUG_REFCOUNTS
87
std::cout <<
typeid
(*this).name()
88
<<
" "
89
<<
m_name
90
<<
" Refcount:"
91
<<
m_refCount
+1
92
<< std::endl;
93
#endif
94
return
++
m_refCount
;
95
}
96
97
int
release
()
const
{
98
int
count
= --
m_refCount
;
99
#ifdef DEBUG_REFCOUNTS
100
std::cout <<
typeid
(*this).name()
101
<<
" "
102
<<
m_name
103
<<
" Refcount:"
104
<<
count
105
<< std::endl;
106
#endif
107
if
(
count
== 0 ) {
108
delete
this
;
109
}
110
return
count
;
111
}
112
};
113
114
115
template
<
class
KEY,
class
TYPE>
class
DbAccessObj
:
public
DbAccessObjBase
{
116
public
:
118
typedef
DbAccessObj< KEY , TYPE >
Base
;
119
typedef
std::map< KEY, TYPE* >
Keys
;
120
typedef
typename
Keys::iterator
iterator
;
121
typedef
typename
Keys::const_iterator
const_iterator
;
122
123
private
:
125
Keys
m_keys
;
126
127
public
:
129
using
DbAccessObjBase::DbAccessObjBase
;
130
132
size_t
size
()
const
{
133
return
m_keys
.size();
134
}
135
136
void
clearEntries
() {
137
for
(
const
auto
& k :
m_keys
) k.second->release();
138
m_keys
.clear();
139
}
140
141
const
TYPE
*
find
(
const
KEY& key)
const
{
142
const_iterator
i =
m_keys
.find(key);
143
return
(
m_keys
.end() == i) ? 0 : (*i).second;
144
}
145
146
TYPE
*
find
(
const
KEY& key) {
147
iterator
i =
m_keys
.find(key);
148
return
(
m_keys
.end() == i) ? 0 : (*i).second;
149
}
150
151
StatusCode
add
(
const
KEY& key,
TYPE
* val) {
152
iterator
i =
m_keys
.find(key);
153
if
(
m_keys
.end() == i ) {
154
m_keys
.insert(std::make_pair(key, val));
155
val->addRef();
156
return
StatusCode::SUCCESS;
157
}
158
return
StatusCode::FAILURE;
159
}
160
161
StatusCode
remove
(
const
TYPE
* val) {
162
for
(
iterator
j =
m_keys
.begin(); j !=
m_keys
.end(); ++j ) {
163
if
( (*j).second == val ) {
164
TYPE
* p = (*j).second;
165
m_keys
.erase(j);
166
p->release();
167
return
StatusCode::SUCCESS;
168
}
169
}
170
return
StatusCode::FAILURE;
171
}
172
iterator
begin
() {
return
m_keys
.begin(); }
173
const_iterator
begin
()
const
{
return
m_keys
.begin(); }
174
iterator
end
() {
return
m_keys
.end(); }
175
const_iterator
end
()
const
{
return
m_keys
.end(); }
176
};
177
}
// End namespace pool
178
#endif
// POOL_DBACCESSOBJ_H
pool.h
DbType.h
IOODatabase.h
TYPE
#define TYPE(CODE, TYP, IOTYP)
pool::DbAccessObjBase::m_type
DbType m_type
Database type.
Definition
DbAccessObj.h:58
pool::DbAccessObjBase::m_mode
Io::IoFlag m_mode
Access mode.
Definition
DbAccessObj.h:54
pool::DbAccessObjBase::m_pool
IOODatabase * m_pool
Pointer to specific pool implementation.
Definition
DbAccessObj.h:60
pool::DbAccessObjBase::setMode
void setMode(Io::IoFlag m)
Set Access mode.
Definition
DbAccessObj.h:76
pool::DbAccessObjBase::refCount
int refCount() const
Access reference counter.
Definition
DbAccessObj.h:83
pool::DbAccessObjBase::type
const DbType & type() const
Definition
DbAccessObj.h:78
pool::DbAccessObjBase::~DbAccessObjBase
virtual ~DbAccessObjBase()
Standard destructor.
Definition
DbAccessObj.h:68
pool::DbAccessObjBase::db
const IOODatabase * db() const
Allow access to the Database implementation.
Definition
DbAccessObj.h:80
pool::DbAccessObjBase::setName
void setName(const std::string &n)
Access the instance name.
Definition
DbAccessObj.h:72
pool::DbAccessObjBase::release
int release() const
Remove reference count.
Definition
DbAccessObj.h:97
pool::DbAccessObjBase::name
const std::string & name() const
Access the instance name.
Definition
DbAccessObj.h:70
pool::DbAccessObjBase::mode
Io::IoFlag mode() const
Access mode.
Definition
DbAccessObj.h:74
pool::DbAccessObjBase::db
IOODatabase * db()
Definition
DbAccessObj.h:81
pool::DbAccessObjBase::m_name
std::string m_name
Name of the instance.
Definition
DbAccessObj.h:56
pool::DbAccessObjBase::DbAccessObjBase
DbAccessObjBase(const std::string &n, Io::IoFlag m, const DbType &t, IOODatabase *s=0)
Constructor with initializing arguments.
Definition
DbAccessObj.h:64
pool::DbAccessObjBase::m_refCount
std::atomic< int > m_refCount
Reference counter.
Definition
DbAccessObj.h:52
pool::DbAccessObjBase::addRef
int addRef() const
Add reference count.
Definition
DbAccessObj.h:85
pool::DbAccessObj
Description:
Definition
DbAccessObj.h:115
pool::DbAccessObj::end
const_iterator end() const
Definition
DbAccessObj.h:175
pool::DbAccessObj::Keys
std::map< KEY, TYPE * > Keys
Definition
DbAccessObj.h:119
pool::DbAccessObj::begin
const_iterator begin() const
Definition
DbAccessObj.h:173
pool::DbAccessObj::const_iterator
Keys::const_iterator const_iterator
Definition
DbAccessObj.h:121
pool::DbAccessObj::Base
DbAccessObj< KEY, TYPE > Base
Type definitions.
Definition
DbAccessObj.h:118
pool::DbAccessObj::iterator
Keys::iterator iterator
Definition
DbAccessObj.h:120
pool::DbAccessObj::remove
StatusCode remove(const TYPE *val)
Remove entry from container.
Definition
DbAccessObj.h:161
pool::DbAccessObj::end
iterator end()
Definition
DbAccessObj.h:174
pool::DbAccessObj::add
StatusCode add(const KEY &key, TYPE *val)
Add entry to container.
Definition
DbAccessObj.h:151
pool::DbAccessObj::find
const TYPE * find(const KEY &key) const
Find object by key (CONST).
Definition
DbAccessObj.h:141
pool::DbAccessObj::clearEntries
void clearEntries()
Object cleanup: remove all entries.
Definition
DbAccessObj.h:136
pool::DbAccessObj::begin
iterator begin()
Definition
DbAccessObj.h:172
pool::DbAccessObj::DbAccessObjBase
DbAccessObjBase(const std::string &n, Io::IoFlag m, const DbType &t, IOODatabase *s=0)
Constructor from the base class.
Definition
DbAccessObj.h:64
pool::DbAccessObj< std::string, DbContainerObj >::m_keys
Keys m_keys
Definition
DbAccessObj.h:125
pool::DbAccessObj::find
TYPE * find(const KEY &key)
Find object by key.
Definition
DbAccessObj.h:146
pool::DbAccessObj::size
size_t size() const
Object size.
Definition
DbAccessObj.h:132
pool::DbType
Definition
DbType.h:30
pool::IOODatabase
Definition
IOODatabase.h:50
count
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Definition
hcg.cxx:148
pool
Framework include files.
Definition
libname.h:15
pool::releasePtr
void releasePtr(T *&p)
Release a pointer.
Definition
Database/APR/StorageSvc/StorageSvc/pool.h:52
Generated on
for ATLAS Offline Software by
1.17.0