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

Class for importing array of objects to the database. More...

#include <DBImportArray.h>

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

Public Types

typedef ObjArrayIterator< TClonesArray, T > iterator
 STL-like iterator over the T objects (not T* ).
 
typedef ObjArrayIterator< const TClonesArray, const T > const_iterator
 STL-like const_iterator over the T objects (not T* ).
 

Public Member Functions

 DBImportArray (const std::string &name="")
 Constructor.
 
 ~DBImportArray ()
 Destructor.
 
int getEntries () const
 Returns number of objects in the array.
 
T * appendNew ()
 Construct a new T object at the end of the array.
 
template<class ... Args>
T * appendNew (Args &&... params)
 Construct a new T object at the end of the array.
 
T * operator[] (int i) const
 Access to the stored objects.
 
iterator begin ()
 Returns iterator to first entry.
 
iterator end ()
 Returns iterator to last entry +1.
 
const_iterator begin () const
 Returns const_iterator to first entry.
 
const_iterator end () const
 Returns const_iterator to last entry +1.
 
void addEventDependency (unsigned int eventNumber) override
 add event dependency
 
void addTimeStampDependency (unsigned long long int timeStamp) override
 add time stamp dependency
 
void addSubrunDependency (int subrun) override
 add subrun dependency
 
void clear () override
 Clear the content, e.g.
 
const std::string & getName () const
 Returns the name under which the object will be stored in the database.
 
bool import (const IntervalOfValidity &iov)
 Import the object to database.
 

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

T * nextFreeAdress ()
 Returns address of the next free position of the array.
 
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::DBImportArray< T >

Class for importing array of objects to the database.

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

Definition at line 25 of file DBImportArray.h.

Member Typedef Documentation

◆ const_iterator

typedef ObjArrayIterator<const TClonesArray, const T> const_iterator

STL-like const_iterator over the T objects (not T* ).

Definition at line 31 of file DBImportArray.h.

◆ iterator

typedef ObjArrayIterator<TClonesArray, T> iterator

STL-like iterator over the T objects (not T* ).

Definition at line 29 of file DBImportArray.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

◆ DBImportArray()

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

Constructor.

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

Definition at line 37 of file DBImportArray.h.

37 :
38 DBImportBase(DBStore::arrayName<T>(name))
39 {
40 m_object = new TClonesArray(T::Class());
41 }
DBImportBase(const std::string &name)
Constructor.
Definition: DBImportBase.h:30
TObject * m_object
pointer to allocated object or array
Definition: DBImportBase.h:100

◆ ~DBImportArray()

~DBImportArray ( )
inline

Destructor.

Definition at line 46 of file DBImportArray.h.

47 {
48 delete m_object;
49 }

Member Function Documentation

◆ addEventDependency()

void addEventDependency ( unsigned int  eventNumber)
inlineoverridevirtual

add event dependency

Parameters
eventNumberevent number

Reimplemented from DBImportBase.

Definition at line 125 of file DBImportArray.h.

126 {
127 addIntraRunDependency(eventNumber, c_Event);
128 m_object = new TClonesArray(T::Class());
129 }
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()

void addSubrunDependency ( int  subrun)
inlineoverridevirtual

add subrun dependency

Parameters
subrunsubrun number

Reimplemented from DBImportBase.

Definition at line 145 of file DBImportArray.h.

146 {
147 addIntraRunDependency(subrun, c_Subrun);
148 m_object = new TClonesArray(T::Class());
149 }

◆ addTimeStampDependency()

void addTimeStampDependency ( unsigned long long int  timeStamp)
inlineoverridevirtual

add time stamp dependency

Parameters
timeStamptime stamp

Reimplemented from DBImportBase.

Definition at line 135 of file DBImportArray.h.

136 {
137 addIntraRunDependency(timeStamp, c_TimeStamp);
138 m_object = new TClonesArray(T::Class());
139 }

◆ appendNew() [1/2]

T * appendNew ( )
inline

Construct a new T object at the end of the array.

Appends a new object to the array, and returns a pointer so it can be filled with data. The default constructor is used for the object's creation.

Returns
pointer to the created object

Definition at line 67 of file DBImportArray.h.

67{ return new (nextFreeAdress()) T(); }
T * nextFreeAdress()
Returns address of the next free position of the array.

◆ appendNew() [2/2]

T * appendNew ( Args &&...  params)
inline

Construct a new T object at the end of the array.

This is done by forwarding all arguments to the constructor of the type T. If there is a constructor which takes the given combination of arguments then this call will succeed, otherwise it fails on compilation.

This method imposes no overhead as no temporary has to be constructed and should be the preferred solution for creating new objects.

Returns
pointer to the created object

Definition at line 80 of file DBImportArray.h.

81 {
82 return new (nextFreeAdress()) T(std::forward<Args>(params)...);
83 }

◆ begin() [1/2]

iterator begin ( )
inline

Returns iterator to first entry.

Definition at line 104 of file DBImportArray.h.

104{ return iterator(*static_cast<TClonesArray*>(m_object), 0); }
ObjArrayIterator< TClonesArray, T > iterator
STL-like iterator over the T objects (not T* ).
Definition: DBImportArray.h:29

◆ begin() [2/2]

const_iterator begin ( ) const
inline

Returns const_iterator to first entry.

Definition at line 114 of file DBImportArray.h.

114{ return const_iterator(*static_cast<TClonesArray*>(m_object), 0); }
ObjArrayIterator< const TClonesArray, const T > const_iterator
STL-like const_iterator over the T objects (not T* ).
Definition: DBImportArray.h:31

◆ clear()

void clear ( )
inlineoverridevirtual

Clear the content, e.g.

destroy allocated objects and prepare for the new DB import.

Reimplemented from DBImportBase.

Definition at line 154 of file DBImportArray.h.

155 {
157 m_object = new TClonesArray(T::Class());
158 }
virtual void clear()
Clear the content, e.g.
Definition: DBImportBase.cc:58

◆ end() [1/2]

iterator end ( )
inline

Returns iterator to last entry +1.

Definition at line 109 of file DBImportArray.h.

109{ return iterator(*static_cast<TClonesArray*>(m_object), getEntries()); }
int getEntries() const
Returns number of objects in the array.
Definition: DBImportArray.h:54

◆ end() [2/2]

const_iterator end ( ) const
inline

Returns const_iterator to last entry +1.

Definition at line 119 of file DBImportArray.h.

119{ return const_iterator(*static_cast<TClonesArray*>(m_object), getEntries()); }

◆ getEntries()

int getEntries ( ) const
inline

Returns number of objects in the array.

Definition at line 54 of file DBImportArray.h.

55 {
56 return static_cast<TClonesArray*>(m_object)->GetEntriesFast();
57 }

◆ 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

◆ nextFreeAdress()

T * nextFreeAdress ( )
inlineprivate

Returns address of the next free position of the array.

Returns
pointer to address just past the last array element

Definition at line 167 of file DBImportArray.h.

168 {
169 return static_cast<T*>(static_cast<TClonesArray*>(m_object)->AddrAt(getEntries()));
170 }

◆ operator[]()

T * operator[] ( int  i) const
inline

Access to the stored objects.

Out-of-bounds accesses throw an std::out_of_range exception.

Parameters
iArray index, should be in 0..getEntries()-1
Returns
pointer to the object

Definition at line 91 of file DBImportArray.h.

92 {
93 TObject* obj = static_cast<TClonesArray*>(m_object)->At(i);
94 if (obj == nullptr)
95 throw std::out_of_range("Out-of-range access in DBImportArray::operator[], for "
96 + getName() + ", index "
97 + std::to_string(i));
98 return static_cast<T*>(obj);
99 }
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: