ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
APR
StorageSvc
StorageSvc
DbAccessObj.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 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
template
<
class
KEY,
class
TYPE>
class
DbAccessObj
{
48
public
:
50
typedef
DbAccessObj< KEY , TYPE >
Base
;
51
typedef
std::map< KEY, TYPE* >
Keys
;
52
typedef
typename
Keys::iterator
iterator
;
53
typedef
typename
Keys::const_iterator
const_iterator
;
54
private
:
56
mutable
std::atomic<int>
m_refCount
;
58
Io::IoFlag
m_mode
;
60
std::string
m_name
;
62
DbType
m_type
;
64
Keys
m_keys
;
66
IOODatabase
*
m_pool
;
67
68
public
:
70
DbAccessObj
(
const
std::string& n, Io::IoFlag m,
const
DbType
& t,
IOODatabase
* s=0)
71
:
m_refCount
(0),
m_mode
(m),
m_name
(n),
m_type
(t),
m_pool
(s)
72
{
if
(
m_pool
)
m_pool
->addRef(); }
73
74
virtual
~DbAccessObj
() {
releasePtr
(
m_pool
); }
76
const
std::string&
name
()
const
{
return
m_name
; }
78
void
setName
(
const
std::string& n){
m_name
= n; }
80
Io::IoFlag
mode
()
const
{
return
m_mode
; }
82
void
setMode
(Io::IoFlag m) {
m_mode
= m; }
83
// Inline functions
84
const
DbType
&
type
()
const
{
return
m_type
; }
86
const
IOODatabase
*
db
()
const
{
return
m_pool
; }
87
IOODatabase
*
db
() {
return
m_pool
; }
89
int
refCount
()
const
{
return
m_refCount
; }
91
int
addRef
()
const
{
92
#ifdef DEBUG_REFCOUNTS
93
std::cout <<
typeid
(*this).name()
94
<<
" "
95
<<
m_name
96
<<
" Refcount:"
97
<<
m_refCount
+1
98
<< std::endl;
99
#endif
100
return
++
m_refCount
;
101
}
102
103
int
release
()
const
{
104
int
count
= --
m_refCount
;
105
#ifdef DEBUG_REFCOUNTS
106
std::cout <<
typeid
(*this).name()
107
<<
" "
108
<<
m_name
109
<<
" Refcount:"
110
<<
count
111
<< std::endl;
112
#endif
113
if
(
count
== 0 ) {
114
delete
this
;
115
}
116
return
count
;
117
}
118
119
size_t
size
()
const
{
120
return
m_keys
.size();
121
}
122
123
void
clearEntries
() {
124
for
(
const
auto
& k :
m_keys
) k.second->release();
125
m_keys
.clear();
126
}
127
128
const
TYPE
*
find
(
const
KEY& key)
const
{
129
const_iterator
i =
m_keys
.find(key);
130
return
(
m_keys
.end() == i) ? 0 : (*i).second;
131
}
132
133
TYPE
*
find
(
const
KEY& key) {
134
iterator
i =
m_keys
.find(key);
135
return
(
m_keys
.end() == i) ? 0 : (*i).second;
136
}
137
138
StatusCode
add
(
const
KEY& key,
TYPE
* val) {
139
iterator
i =
m_keys
.find(key);
140
if
(
m_keys
.end() == i ) {
141
m_keys
.insert(std::make_pair(key, val));
142
val->addRef();
143
return
StatusCode::SUCCESS;
144
}
145
return
StatusCode::FAILURE;
146
}
147
148
StatusCode
remove
(
const
TYPE
* val) {
149
for
(
iterator
j =
m_keys
.begin(); j !=
m_keys
.end(); ++j ) {
150
if
( (*j).second == val ) {
151
TYPE
* p = (*j).second;
152
m_keys
.erase(j);
153
p->release();
154
return
StatusCode::SUCCESS;
155
}
156
}
157
return
StatusCode::FAILURE;
158
}
159
iterator
begin
() {
return
m_keys
.begin(); }
160
const_iterator
begin
()
const
{
return
m_keys
.begin(); }
161
iterator
end
() {
return
m_keys
.end(); }
162
const_iterator
end
()
const
{
return
m_keys
.end(); }
163
};
164
}
// End namespace pool
165
#endif
// POOL_DBACCESSOBJ_H
pool.h
DbType.h
IOODatabase.h
TYPE
#define TYPE(CODE, TYP, IOTYP)
pool::DbAccessObj::end
const_iterator end() const
Definition
DbAccessObj.h:162
pool::DbAccessObj< std::string, DbContainerObj >::m_name
std::string m_name
Definition
DbAccessObj.h:60
pool::DbAccessObj< std::string, DbContainerObj >::Keys
std::map< std::string, DbContainerObj * > Keys
Definition
DbAccessObj.h:51
pool::DbAccessObj::begin
const_iterator begin() const
Definition
DbAccessObj.h:160
pool::DbAccessObj< std::string, DbContainerObj >::m_pool
IOODatabase * m_pool
Definition
DbAccessObj.h:66
pool::DbAccessObj< std::string, DbContainerObj >::m_refCount
std::atomic< int > m_refCount
Definition
DbAccessObj.h:56
pool::DbAccessObj< std::string, DbContainerObj >::const_iterator
Keys::const_iterator const_iterator
Definition
DbAccessObj.h:53
pool::DbAccessObj< std::string, DbContainerObj >::Base
DbAccessObj< std::string, DbContainerObj > Base
Definition
DbAccessObj.h:50
pool::DbAccessObj::addRef
int addRef() const
Add reference count.
Definition
DbAccessObj.h:91
pool::DbAccessObj< std::string, DbContainerObj >::iterator
Keys::iterator iterator
Definition
DbAccessObj.h:52
pool::DbAccessObj::mode
Io::IoFlag mode() const
Access mode.
Definition
DbAccessObj.h:80
pool::DbAccessObj::name
const std::string & name() const
Access the instance name.
Definition
DbAccessObj.h:76
pool::DbAccessObj< std::string, DbContainerObj >::m_type
DbType m_type
Definition
DbAccessObj.h:62
pool::DbAccessObj::~DbAccessObj
virtual ~DbAccessObj()
Standard destructor.
Definition
DbAccessObj.h:74
pool::DbAccessObj::remove
StatusCode remove(const TYPE *val)
Remove entry from container.
Definition
DbAccessObj.h:148
pool::DbAccessObj::end
iterator end()
Definition
DbAccessObj.h:161
pool::DbAccessObj::add
StatusCode add(const KEY &key, TYPE *val)
Add entry to container.
Definition
DbAccessObj.h:138
pool::DbAccessObj::find
const TYPE * find(const KEY &key) const
Find object by key (CONST).
Definition
DbAccessObj.h:128
pool::DbAccessObj::refCount
int refCount() const
Access reference counter.
Definition
DbAccessObj.h:89
pool::DbAccessObj::setMode
void setMode(Io::IoFlag m)
Set Access mode.
Definition
DbAccessObj.h:82
pool::DbAccessObj::clearEntries
void clearEntries()
Object cleanup: remove all entries.
Definition
DbAccessObj.h:123
pool::DbAccessObj::type
const DbType & type() const
Definition
DbAccessObj.h:84
pool::DbAccessObj::setName
void setName(const std::string &n)
Access the instance name.
Definition
DbAccessObj.h:78
pool::DbAccessObj::DbAccessObj
DbAccessObj(const std::string &n, Io::IoFlag m, const DbType &t, IOODatabase *s=0)
Constructor with initializing arguments.
Definition
DbAccessObj.h:70
pool::DbAccessObj::begin
iterator begin()
Definition
DbAccessObj.h:159
pool::DbAccessObj::db
const IOODatabase * db() const
Allow access to the Database implementation.
Definition
DbAccessObj.h:86
pool::DbAccessObj::release
int release() const
Remove reference count.
Definition
DbAccessObj.h:103
pool::DbAccessObj< std::string, DbContainerObj >::m_keys
Keys m_keys
Definition
DbAccessObj.h:64
pool::DbAccessObj< std::string, DbContainerObj >::m_mode
Io::IoFlag m_mode
Definition
DbAccessObj.h:58
pool::DbAccessObj::find
TYPE * find(const KEY &key)
Find object by key.
Definition
DbAccessObj.h:133
pool::DbAccessObj::db
IOODatabase * db()
Definition
DbAccessObj.h:87
pool::DbAccessObj::size
size_t size() const
Object size.
Definition
DbAccessObj.h:119
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:69
Generated on
for ATLAS Offline Software by
1.17.0