Belle II Software  release-08-01-10
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. More...
 
 ~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. More...
 
template<class ... Args>
T * appendNew (Args &&... params)
 Construct a new T object at the end of the array. More...
 
T * operator[] (int i) const
 Access to the stored objects. More...
 
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 More...
 
void addTimeStampDependency (unsigned long long int timeStamp) override
 add time stamp dependency More...
 
void addSubrunDependency (int subrun) override
 add subrun dependency More...
 
void clear () override
 Clear the content, e.g. More...
 
const std::string & getName () const
 Returns the name under which the object will be stored in the database. More...
 
bool import (const IntervalOfValidity &iov)
 Import the object to database. More...
 

Protected Types

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

Protected Member Functions

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

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

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. More...
 

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.

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

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ clear()

void clear ( void  )
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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

Member Data Documentation

◆ 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: