PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
ObjBase.h
Go to the documentation of this file.
1#ifndef PODIO_OBJBASE_H
2#define PODIO_OBJBASE_H
3
4#include "podio/ObjectID.h"
5#include <atomic>
6#include <iostream>
7
8namespace podio {
9
10class ObjBase {
11public:
12 /// Constructor from ObjectID and initial object-count
13 ObjBase(ObjectID id_, unsigned i) : id(id_), ref_counter(i) {
14 }
15
16 /// checks whether object is "untracked" by a collection
17 /// if yes, increases reference count
18 void acquire() {
19 if (id.index == podio::ObjectID::untracked) {
20 ++ref_counter;
21 }
22 };
23
24 /// checks whether object is "untracked" by a collection
25 /// if yes, decrease reference count and delete itself if count===0
26 int release() {
27 if (id.index != podio::ObjectID::untracked) {
28 return 1;
29 };
30 if (--ref_counter == 0) {
31 delete this;
32 }
33 return 0;
34 };
35
36 /// destructor
37 virtual ~ObjBase() = default;
38
39public:
40 /// ID of the object
42
43private:
44 /// reference counter
45 std::atomic<unsigned> ref_counter;
46};
47
48} // namespace podio
49
50#endif
virtual ~ObjBase()=default
destructor
void acquire()
Definition: ObjBase.h:18
int release()
Definition: ObjBase.h:26
ObjBase(ObjectID id_, unsigned i)
Constructor from ObjectID and initial object-count.
Definition: ObjBase.h:13
podio::ObjectID id
ID of the object.
Definition: ObjBase.h:41
static const int untracked
not part of a collection
Definition: ObjectID.h:15