ATLAS Offline Software
Database/APR/StorageSvc/StorageSvc/pool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //====================================================================
6 //
7 // Package : StorageSvc (The pool framework)
8 //
9 // Description: Management of the object Databases
10 //
11 // @author M.Frank
12 //====================================================================
13 #ifndef POOL_POOL_H
14 #define POOL_POOL_H 1
15 
16 // Framework include files
17 #include "StorageSvc/DbStatus.h"
18 
19 // STL include files
20 #include <string>
21 #include <utility>
22 
23 /* Turn this switch if it is possible to agree on a common
24  * base class for all persistent objects.
25  */
26 //#define POOL_HAVE_BASE
27 
28 #ifdef POOL_HAVE_BASE
29 #define POOL_BASE : public pool::DbObject
30 #define POOL_BASE1(b1) POOL_BASE, b1
31 namespace pool { class DbObject; }
32 #else
33 #define POOL_BASE
34 #define POOL_BASE1(b1) : b1
35 namespace pool { typedef void DbObject; }
36 
37 #endif
38 #define POOL_BASE2(b1,b2) POOL_BASE1(b1), b2
39 #define POOL_BASE3(b1,b2,b3) POOL_BASE2(b1,b2), b3
40 #define POOL_BASE4(b1,b2,b3,b4) POOL_BASE3(b1,b2,b3), b4
41 
42 #define POOL_BEGIN_STATIC_BLOCK(x) namespace { struct __init { __init() {
43 #define POOL_END_STATIC_BLOCK(x) }}; static __init _i;} void* __init_##x () {return &_i;}
44 
45 namespace pool {
46  // Type defintions and forward declarations
47  typedef int DbAccessMode;
48  typedef std::pair< long long, long long > DbLink;
49 }
50 
51 /* namespace poolDb
52  *
53  * Description:
54  * All specific constants for a storage technology
55  *
56  * @author M.Frank
57  * @version 1.0
58  */
59 namespace pool {
60  class DbInstanceCount;
61 
62  static const long long int INVALID = ~0x0LL;
63 
65  enum AccessMode {
66  NONE = 0,
67  NOT_OPEN = 1<<0,
68  READ = 1<<1,
69  UPDATE = 1<<2,
70  CREATE = 1<<3,
71  RECREATE = (1<<4)+(1<<3),
72  WRITE = 1<<3,
73  DESTROY = 1<<5
74  };
75 
76  static const DbStatus Success (DbStatus::Success);
77  static const DbStatus Warning (DbStatus::Warning);
78  static const DbStatus Error (DbStatus::Error);
79  static const DbStatus ConnTimeout (static_cast<unsigned int>(DbStatus::Error)+2);
80 
82  void debugBreak();
83 
85  void debugBreak( const std::string& src,
86  const std::string& msg,
87  bool rethrow=true);
88 
90  void debugBreak( const std::string& src,
91  const std::string& msg,
92  const std::exception& e,
93  bool rethrow=true);
94 
96  bool doTrace();
97 
99  const char* accessMode(pool::DbAccessMode access_mode);
100 
102  template<class T> inline DbStatus deletePtr(T*& p) {
103  if ( 0 != p ) {
104  delete p;
105  p = 0;
106  }
107  return Success;
108  }
110  template<class T> inline DbStatus releasePtr(T*& p) {
111  if ( 0 != p ) {
112  p->release();
113  p = 0;
114  }
115  return Success;
116  }
117 
119  template<class T> inline int decrementPtr(T*& p) {
120  if ( p ) {
121  int cnt = p->release();
122  if ( 0 >= cnt ) {
123  p = 0;
124  }
125  return cnt;
126  }
127  return ~0x0;
128  }
129 
130  class RefCounter {
131  private:
132  int m_count = 1;
133  public:
135  RefCounter( const RefCounter& ) { m_count = 1; }
136  // cppcheck-suppress operatorEqVarError; deliberate
137  RefCounter& operator= (const RefCounter&) { return *this; }
139  int addRef() { return ++m_count; }
141  int subRef() { return --m_count; }
142  };
143 
144 }
145 #endif // POOL_POOL_H
pool::DbAccessMode
int DbAccessMode
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:47
pool::DbObject
void DbObject
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:35
pool::DbStatus
Definition: DbStatus.h:67
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
pool::CREATE
@ CREATE
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:70
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
pool::RefCounter::addRef
int addRef()
Increase the reference count.
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:139
pool::RefCounter::RefCounter
RefCounter(const RefCounter &)
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:135
pool::deletePtr
DbStatus deletePtr(T *&p)
Delete a pointer.
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:102
pool
pool namespace
Definition: libname.h:15
pool::WRITE
@ WRITE
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:72
pool::UPDATE
@ UPDATE
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:69
pool::RefCounter::m_count
int m_count
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:132
pool::decrementPtr
int decrementPtr(T *&p)
Release Reference countable pointer.
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:119
pool::RefCounter::subRef
int subRef()
Decrease the reference count.
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:141
calibdata.exception
exception
Definition: calibdata.py:496
pool::RefCounter
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:130
pool::AccessMode
AccessMode
Definition of access modes.
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:65
pool::RefCounter::operator=
RefCounter & operator=(const RefCounter &)
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:137
pool::NONE
@ NONE
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:66
pool::DESTROY
@ DESTROY
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:73
pool::READ
@ READ
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:68
pool::debugBreak
void debugBreak()
Issue a debug break.
pool::RECREATE
@ RECREATE
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:71
pool::doTrace
bool doTrace()
Check for tracing.
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
pool::DbLink
std::pair< long long, long long > DbLink
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:48
pool::NOT_OPEN
@ NOT_OPEN
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:67
trigbs_pickEvents.cnt
cnt
Definition: trigbs_pickEvents.py:71
pool::accessMode
const char * accessMode(pool::DbAccessMode access_mode)
Translate access mode to string.
pool::RefCounter::RefCounter
RefCounter()
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:134
pool::releasePtr
DbStatus releasePtr(T *&p)
Release a pointer.
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:110
pool::DbStatus::Error
@ Error
Definition: DbStatus.h:76
DbStatus.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
pool::DbStatus::Success
@ Success
Definition: DbStatus.h:73
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
pool::DbStatus::Warning
@ Warning
Definition: DbStatus.h:75