Belle II Software development
DBImportBase Class Reference

Base class for importing objects to the database. More...

#include <DBImportBase.h>

Inheritance diagram for DBImportBase:
DBImportArray< T > DBImportObjPtr< T >

Public Member Functions

 DBImportBase (const std::string &name)
 Constructor.
 
virtual ~DBImportBase ()
 Destructor.
 
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

 DBImportBase (const DBImportBase &)
 Hidden copy constructor.
 
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

Base class for importing objects to the database.

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

Definition at line 23 of file DBImportBase.h.

Member Enumeration Documentation

◆ EIntraRunDependency

enum EIntraRunDependency
protected

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

◆ DBImportBase() [1/2]

DBImportBase ( const std::string &  name)
inlineexplicit

Constructor.

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

Definition at line 30 of file DBImportBase.h.

30: m_name(name) {}
std::string m_name
object or array name in database
Definition: DBImportBase.h:99

◆ ~DBImportBase()

~DBImportBase ( )
virtual

Destructor.

Definition at line 76 of file DBImportBase.cc.

77{
78 for (auto& object : m_objects) delete object;
79}
std::vector< TObject * > m_objects
container for intra run dependency objects
Definition: DBImportBase.h:138

◆ DBImportBase() [2/2]

DBImportBase ( const DBImportBase )
private

Hidden copy constructor.

To prevent making copies, since the class contains pointer to allocated memory.

Member Function Documentation

◆ addEventDependency()

virtual void addEventDependency ( unsigned int  eventNumber)
inlinevirtual

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 
)
protected

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
EIntraRunDependency m_dependency
dependency type
Definition: DBImportBase.h:137
TObject * m_object
pointer to allocated object or array
Definition: DBImportBase.h:100

◆ addSubrunDependency()

virtual void addSubrunDependency ( int  subrun)
inlinevirtual

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)
inlinevirtual

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 ( )
virtual

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}

◆ getName()

const std::string & getName ( ) const
inline

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;}

◆ import() [1/2]

bool import ( const IntervalOfValidity iov)

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)
inlineprivate

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

◆ storeData()

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

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
private

dependency type

Definition at line 137 of file DBImportBase.h.

◆ m_name

std::string m_name
protected

object or array name in database

Definition at line 99 of file DBImportBase.h.

◆ m_object

TObject* m_object = 0
protected

pointer to allocated object or array

Definition at line 100 of file DBImportBase.h.

◆ m_objects

std::vector<TObject*> m_objects
private

container for intra run dependency objects

Definition at line 138 of file DBImportBase.h.

◆ m_tags

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

container for intra run dep.

tags

Definition at line 139 of file DBImportBase.h.


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