Belle II Software light-2406-ragdoll
DBImportObjPtr< T > Class Template Reference

Class for importing a single object to the database. More...

#include <DBImportObjPtr.h>

Inheritance diagram for DBImportObjPtr< T >:
Collaboration diagram for DBImportObjPtr< T >:

Public Member Functions

 DBImportObjPtr (const std::string &name="")
 Constructor: the object itself is not allocated here, but in construct(...) function.
 
 ~DBImportObjPtr ()
 Destructor.
 
template<class ... Args>
void construct (Args &&... params)
 Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
 
T * operator-> () const
 Imitate pointer functionality.
 
const std::string & getName () const
 Returns the name under which the object will be stored in the database.
 
virtual void addEventDependency (unsigned int eventNumber)
 add event dependency
 
virtual void addTimeStampDependency (unsigned long long int timeStamp)
 add time stamp dependency
 
virtual void addSubrunDependency (int subrun)
 add subrun dependency
 
bool import (const IntervalOfValidity &iov)
 Import the object to database.
 
virtual void clear ()
 Clear the content, e.g.
 

Protected Types

enum  EIntraRunDependency {
  c_None = 0 ,
  c_Event = 1 ,
  c_TimeStamp = 2 ,
  c_Subrun = 3
}
 Intra run dependency types (used only internaly) More...
 

Protected Member Functions

void addIntraRunDependency (unsigned long long int tag, EIntraRunDependency type)
 add intra run dependency
 

Protected Attributes

std::string m_name
 object or array name in database
 
TObject * m_object = 0
 pointer to allocated object or array
 

Private Member Functions

template<class IntraRun >
bool import (const IntervalOfValidity &iov)
 Import intra run dependent object to database.
 
bool storeData (TObject *intraRun, const IntervalOfValidity &iov)
 Store intra run dependent objects.
 

Private Attributes

EIntraRunDependency m_dependency = c_None
 dependency type
 
std::vector< TObject * > m_objects
 container for intra run dependency objects
 
std::vector< unsigned long long int > m_tags
 container for intra run dep.
 

Detailed Description

template<class T>
class Belle2::DBImportObjPtr< T >

Class for importing a single object to the database.

Note that the object is NOT parked at DBStore, but allocated internally.

Definition at line 23 of file DBImportObjPtr.h.

Member Enumeration Documentation

◆ EIntraRunDependency

enum EIntraRunDependency
protectedinherited

Intra run dependency types (used only internaly)

Definition at line 86 of file DBImportBase.h.

86 { c_None = 0,
87 c_Event = 1,
88 c_TimeStamp = 2,
89 c_Subrun = 3
90 };

Constructor & Destructor Documentation

◆ DBImportObjPtr()

DBImportObjPtr ( const std::string &  name = "")
inlineexplicit

Constructor: the object itself is not allocated here, but in construct(...) function.

Parameters
nameName under which the object will be stored in the database

Definition at line 31 of file DBImportObjPtr.h.

31 :
32 DBImportBase(DBStore::objectName<T>(name))
33 {}
DBImportBase(const std::string &name)
Constructor.
Definition: DBImportBase.h:30

◆ ~DBImportObjPtr()

~DBImportObjPtr ( )
inline

Destructor.

Definition at line 38 of file DBImportObjPtr.h.

39 {
40 if (m_object) delete m_object;
41 }
TObject * m_object
pointer to allocated object or array
Definition: DBImportBase.h:100

Member Function Documentation

◆ addEventDependency()

virtual void addEventDependency ( unsigned int  eventNumber)
inlinevirtualinherited

add event dependency

Parameters
eventNumberevent number

Reimplemented in DBImportArray< T >.

Definition at line 47 of file DBImportBase.h.

48 {
49 addIntraRunDependency(eventNumber, c_Event);
50 }
void addIntraRunDependency(unsigned long long int tag, EIntraRunDependency type)
add intra run dependency
Definition: DBImportBase.cc:17

◆ addIntraRunDependency()

void addIntraRunDependency ( unsigned long long int  tag,
EIntraRunDependency  type 
)
protectedinherited

add intra run dependency

Parameters
tagaccording to type: event number or time stamp or subrun number
typeintra run dependency type

Definition at line 17 of file DBImportBase.cc.

19{
20
21 if (!m_object) return;
22
23 if (m_dependency == c_None) m_dependency = dependency;
24 if (dependency == m_dependency) {
25 m_objects.push_back(m_object);
26 m_tags.push_back(tag);
27 m_object = nullptr;
28 } else {
29 B2FATAL("DBImportBase::addIntraRunDependency: " <<
30 "intra run dependency cannot be of mixed types");
31 }
32
33}
std::vector< unsigned long long int > m_tags
container for intra run dep.
Definition: DBImportBase.h:139
std::vector< TObject * > m_objects
container for intra run dependency objects
Definition: DBImportBase.h:138
EIntraRunDependency m_dependency
dependency type
Definition: DBImportBase.h:137

◆ addSubrunDependency()

virtual void addSubrunDependency ( int  subrun)
inlinevirtualinherited

add subrun dependency

Parameters
subrunsubrun number

Reimplemented in DBImportArray< T >.

Definition at line 65 of file DBImportBase.h.

66 {
67 addIntraRunDependency(subrun, c_Subrun);
68 }

◆ addTimeStampDependency()

virtual void addTimeStampDependency ( unsigned long long int  timeStamp)
inlinevirtualinherited

add time stamp dependency

Parameters
timeStamptime stamp

Reimplemented in DBImportArray< T >.

Definition at line 56 of file DBImportBase.h.

57 {
58 addIntraRunDependency(timeStamp, c_TimeStamp);
59 }

◆ clear()

void clear ( )
virtualinherited

Clear the content, e.g.

destroy allocated objects and prepare for the new DB import.

Reimplemented in DBImportArray< T >.

Definition at line 58 of file DBImportBase.cc.

59{
60 if (m_object) {
61 delete m_object;
62 m_object = nullptr;
63 }
64
65 m_dependency = c_None;
66 for (auto& object : m_objects) delete object;
67 m_objects.clear();
68 m_tags.clear();
69}

◆ construct()

void construct ( Args &&...  params)
inline

Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.

Definition at line 47 of file DBImportObjPtr.h.

48 {
49 if (m_object) delete m_object;
50 m_object = new T(std::forward<Args>(params)...);
51 }

◆ getName()

const std::string & getName ( ) const
inlineinherited

Returns the name under which the object will be stored in the database.

Returns
name

Definition at line 41 of file DBImportBase.h.

41{return m_name;}
std::string m_name
object or array name in database
Definition: DBImportBase.h:99

◆ import() [1/2]

bool import ( const IntervalOfValidity iov)
inherited

Import the object to database.

Parameters
iovinterval of validity

Definition at line 36 of file DBImportBase.cc.

37{
38
39 switch (m_dependency) {
40 case c_Event:
41 return import<EventDependency>(iov);
42 case c_TimeStamp:
43 B2ERROR("DBImportBase::import: " <<
44 "intra run dependency of type 'time stamp' not supported yet");
45 return false;
46 case c_Subrun:
47 B2ERROR("DBImportBase::import: " <<
48 "intra run dependency of type 'subrun' not supported yet");
49 return false;
50 default:
51 if (!m_object) return false;
53 }
54
55}
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
Definition: Database.cc:141

◆ import() [2/2]

bool import ( const IntervalOfValidity iov)
inlineprivateinherited

Import intra run dependent object to database.

Parameters
iovinterval of validity

Definition at line 114 of file DBImportBase.h.

115 {
116 if (m_objects.empty()) return false;
117 IntraRun intraRun(m_objects[0], false); // IntraRun must not own the objects
118
119 if (m_object) m_objects.push_back(m_object);
120 for (unsigned i = 1; i < m_objects.size(); i++) {
121 intraRun.add(m_tags[i - 1], m_objects[i]);
122 }
123 if (m_object) m_objects.pop_back(); // restore initial state (mandatory!)
124
125 return storeData(&intraRun, iov);
126 }
bool storeData(TObject *intraRun, const IntervalOfValidity &iov)
Store intra run dependent objects.
Definition: DBImportBase.cc:71

◆ operator->()

T * operator-> ( ) const
inline

Imitate pointer functionality.

Definition at line 56 of file DBImportObjPtr.h.

57 {
58 if (!m_object)
59 throw std::out_of_range("DBImportObjPtr::operator ->, for "
60 + getName() + ", "
61 "object does not exist or is invisible");
62 return static_cast<T*>(m_object);
63 }
const std::string & getName() const
Returns the name under which the object will be stored in the database.
Definition: DBImportBase.h:41

◆ storeData()

bool storeData ( TObject *  intraRun,
const IntervalOfValidity iov 
)
privateinherited

Store intra run dependent objects.

This is an extra function to hide implementation details of Database.h

Parameters
intraRunpointer to the Intra Run implementation which has to inherit from TObject
iovinterval of validity

Definition at line 71 of file DBImportBase.cc.

72{
73 return Database::Instance().storeData(m_name, intraRun, iov);
74}

Member Data Documentation

◆ m_dependency

EIntraRunDependency m_dependency = c_None
privateinherited

dependency type

Definition at line 137 of file DBImportBase.h.

◆ m_name

std::string m_name
protectedinherited

object or array name in database

Definition at line 99 of file DBImportBase.h.

◆ m_object

TObject* m_object = 0
protectedinherited

pointer to allocated object or array

Definition at line 100 of file DBImportBase.h.

◆ m_objects

std::vector<TObject*> m_objects
privateinherited

container for intra run dependency objects

Definition at line 138 of file DBImportBase.h.

◆ m_tags

std::vector<unsigned long long int> m_tags
privateinherited

container for intra run dep.

tags

Definition at line 139 of file DBImportBase.h.


The documentation for this class was generated from the following file: