Belle II Software development
GlobalParamSet< DBObjType > Class Template Reference

Template class for generic access to DB objects. More...

#include <GlobalParam.h>

Inheritance diagram for GlobalParamSet< DBObjType >:
GlobalParamSetAccess

Public Member Functions

 GlobalParamSet ()
 Constructor. Sets callback for DB object changes.
 
 ~GlobalParamSet ()
 Destructor.
 
virtual unsigned short getGlobalUniqueID () const override final
 The DB object unique id in global calibration.
 
virtual double getGlobalParam (unsigned short element, unsigned short param) override final
 Get global parameter of the DB object by its element and parameter number Note this is not const, it might need to construct the object.
 
virtual void setGlobalParam (double value, unsigned short element, unsigned short param) override final
 Set global parameter of the DB object by its element and parameter number.
 
virtual std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams () override final
 List global parameters in this DB object.
 
virtual std::string getDefaultName () const override final
 Get the DB object default name used by datastore.
 
virtual TObject * getDBObj () override final
 Get the raw pointer to the stored object WARNING: Use with caution if you really need to access the internal object.
 
 GlobalParamSet (const GlobalParamSet< DBObjType > &other)
 Copy constructor.
 
GlobalParamSet< DBObjType > & operator= (const GlobalParamSet< DBObjType > &other)
 Assignment operator.
 
virtual TObject * releaseObject () override final
 Release the DB object from the internal unique pointer to be managed elsewhere (e.g.
 
virtual GlobalParamSetAccessclone () override final
 Clone the object, making a copy of the internal object.
 
virtual void loadFromDBObjPtr () override final
 Load content of the object using DBObjPtr<DBObjType> which will try to load object valid for current EventMetaData Also resets if the object has been changed.
 
virtual void loadFromDB (EventMetaData event) override final
 Load content of the object valid at given event from DB Also resets if the object has been changed.
 
virtual void construct () override final
 Construct the internal object using default constructor.
 
virtual bool isConstructed () const override final
 Is the internal object already constructed? we construct the object on first access to the stored values.
 
virtual void callbackDB () override final
 Function to call when object has been changed in DB since last loaded TODO Hide and find the class which calls this to make it friend.
 
unsigned short getGlobalUniqueID () const
 The DB object unique id in global calibration.
 
double getGlobalParam (unsigned short element, unsigned short param)
 Get global parameter of the DB object by its element and parameter number Note this is not const, it might need to construct the object.
 
void setGlobalParam (double value, unsigned short element, unsigned short param)
 Set global parameter of the DB object by its element and parameter number.
 
std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams ()
 List global parameters in this DB object.
 
unsigned short getGlobalUniqueID () const
 The DB object unique id in global calibration.
 
double getGlobalParam (unsigned short element, unsigned short param)
 Get global parameter of the DB object by its element and parameter number Note this is not const, it might need to construct the object.
 
void setGlobalParam (double value, unsigned short element, unsigned short param)
 Set global parameter of the DB object by its element and parameter number.
 
std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams ()
 List global parameters in this DB object.
 
virtual void updateGlobalParam (double correction, unsigned short element, unsigned short param)
 Sum value of global element param with a correction.
 
virtual bool hasBeenChangedInDB (bool resetChangedState=true) final
 Has the object been updated in DB since GlobalParamSet<...> has been constructed? Since last call to this function with resetChangedState=true.
 
template<class DBObjType >
bool is () const
 Is this set of given type?
 
bool empty ()
 Is this set empty or otherwise 'invalid' to identify null sets, end of hierarchy.
 
 operator bool ()
 Tentative operator to quickly check the set Returns true when the set is not empty() and the DB object is constructed and can be accessed.
 

Protected Attributes

bool m_hasBeenChangedInDB {false}
 Flag for object changed in DB.
 

Private Member Functions

void ensureConstructed ()
 Function to construct the object if not already done.
 

Private Attributes

std::unique_ptr< DBObjType > m_object {}
 The internal DB object.
 

Detailed Description

template<class DBObjType>
class Belle2::alignment::GlobalParamSet< DBObjType >

Template class for generic access to DB objects.

Use to access any global calibration DB object, e.g.

GlobalParamSet<BeamSpot> params; params.setGlobalParam(0.0012, 0, 1);

will set X-postion of BeamSpot vertex to 0.0012

Definition at line 186 of file GlobalParam.h.

Constructor & Destructor Documentation

◆ GlobalParamSet() [1/2]

GlobalParamSet ( )
inline

Constructor. Sets callback for DB object changes.

Definition at line 190 of file GlobalParam.h.

191 {
192 //TODO: re-enable
193 //DBObjPtr<DBObjType> dbObject;
194 //dbObject.addCallback(this, &GlobalParamSet<DBObjType>::callbackDB);
195 // if (autoConstruct)
196 // construct();
197 }

◆ ~GlobalParamSet()

~GlobalParamSet ( )
inline

Destructor.

Definition at line 199 of file GlobalParam.h.

199{m_object.reset();}
std::unique_ptr< DBObjType > m_object
The internal DB object.
Definition: GlobalParam.h:299

◆ GlobalParamSet() [2/2]

GlobalParamSet ( const GlobalParamSet< DBObjType > &  other)
inline

Copy constructor.

Definition at line 224 of file GlobalParam.h.

225 {
226 m_hasBeenChangedInDB = other.m_hasBeenChangedInDB;
227 // Make new unique ptr to a copy of the other internal object
228 if (other.m_object)
229 m_object.reset(new DBObjType(*(static_cast<DBObjType*>(other.m_object.get()))));
230 }
bool m_hasBeenChangedInDB
Flag for object changed in DB.
Definition: GlobalParam.h:174

Member Function Documentation

◆ callbackDB()

virtual void callbackDB ( )
inlinefinaloverridevirtual

Function to call when object has been changed in DB since last loaded TODO Hide and find the class which calls this to make it friend.

Reimplemented from GlobalParamSetAccess.

Definition at line 294 of file GlobalParam.h.

virtual void callbackDB()
Function to call when object has been changed in DB since last loaded.
Definition: GlobalParam.h:139

◆ clone()

virtual GlobalParamSetAccess * clone ( )
inlinefinaloverridevirtual

Clone the object, making a copy of the internal object.

Implements GlobalParamSetAccess.

Definition at line 254 of file GlobalParam.h.

255 {
256 return new GlobalParamSet<DBObjType>(*this);
257 }

◆ construct()

virtual void construct ( )
inlinefinaloverridevirtual

Construct the internal object using default constructor.

Implements GlobalParamSetAccess.

Definition at line 287 of file GlobalParam.h.

287{m_object.reset(new DBObjType());}

◆ empty()

bool empty ( )
inlineinherited

Is this set empty or otherwise 'invalid' to identify null sets, end of hierarchy.

Definition at line 148 of file GlobalParam.h.

149 {
150 // We consider this to be the definition of empty
151 if (is<EmptyGlobalParamSet>())
152 return true;
153 // This is by convention (also used in hierarchy)
154 if (getGlobalUniqueID() == 0)
155 return true;
156 // This actually constructs the object using Default constructor if not
157 // previously loaded from DB (or using construct)
158 // TODO this is still not fully impelemnted by DB objects
159 if (listGlobalParams().empty())
160 return true;
161 return false;
162 }
bool empty()
Is this set empty or otherwise 'invalid' to identify null sets, end of hierarchy.
Definition: GlobalParam.h:148
virtual std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams()=0
implement: generate list of all global parameters in the DBObject
virtual unsigned short getGlobalUniqueID() const =0
implement: Get the global unique id of DBObject

◆ ensureConstructed()

void ensureConstructed ( )
inlineprivate

Function to construct the object if not already done.

Definition at line 301 of file GlobalParam.h.

301{if (!m_object) construct();}
virtual void construct() override final
Construct the internal object using default constructor.
Definition: GlobalParam.h:287

◆ getDBObj()

virtual TObject * getDBObj ( )
inlinefinaloverridevirtual

Get the raw pointer to the stored object WARNING: Use with caution if you really need to access the internal object.

Implements GlobalParamSetAccess.

Definition at line 215 of file GlobalParam.h.

216 {
217 if (!m_object)
218 return nullptr;
219
220 return m_object.get();
221 }

◆ getDefaultName()

virtual std::string getDefaultName ( ) const
inlinefinaloverridevirtual

Get the DB object default name used by datastore.

Implements GlobalParamSetAccess.

Definition at line 211 of file GlobalParam.h.

211{return DataStore::objectName<DBObjType>("");}

◆ getGlobalParam() [1/3]

double getGlobalParam ( unsigned short  element,
unsigned short  param 
)
virtual

Get global parameter of the DB object by its element and parameter number Note this is not const, it might need to construct the object.

Implements GlobalParamSetAccess.

◆ getGlobalParam() [2/3]

double getGlobalParam ( unsigned short  element,
unsigned short  param 
)
virtual

Get global parameter of the DB object by its element and parameter number Note this is not const, it might need to construct the object.

Implements GlobalParamSetAccess.

Definition at line 36 of file GlobalParam.cc.

37 {
38 this->ensureConstructed();
39 if (element != 0 or param > 3) {
40 B2ERROR("Invalid global BeamSpot parameter id");
41 return 0;
42 }
43
44 if (auto bp = dynamic_cast<BeamSpot*>(this->getDBObj()))
45 return bp->getIPPosition()[param - 1];
46
47 B2ERROR("Could not get value for BeamSpot");
48 return 0.;
49 }
virtual TObject * getDBObj() override final
Get the raw pointer to the stored object WARNING: Use with caution if you really need to access the i...
Definition: GlobalParam.h:215
void ensureConstructed()
Function to construct the object if not already done.
Definition: GlobalParam.h:301

◆ getGlobalParam() [3/3]

virtual double getGlobalParam ( unsigned short  element,
unsigned short  param 
)
inlinefinaloverridevirtual

Get global parameter of the DB object by its element and parameter number Note this is not const, it might need to construct the object.

Implements GlobalParamSetAccess.

Definition at line 205 of file GlobalParam.h.

205{ensureConstructed(); return m_object->getGlobalParam(element, param);}

◆ getGlobalUniqueID() [1/3]

unsigned short getGlobalUniqueID ( ) const
virtual

The DB object unique id in global calibration.

Implements GlobalParamSetAccess.

◆ getGlobalUniqueID() [2/3]

unsigned short getGlobalUniqueID ( ) const
virtual

The DB object unique id in global calibration.

Implements GlobalParamSetAccess.

Definition at line 32 of file GlobalParam.cc.

32{ return 1; }

◆ getGlobalUniqueID() [3/3]

virtual unsigned short getGlobalUniqueID ( ) const
inlinefinaloverridevirtual

The DB object unique id in global calibration.

Implements GlobalParamSetAccess.

Definition at line 202 of file GlobalParam.h.

202{return DBObjType::getGlobalUniqueID();}

◆ hasBeenChangedInDB()

virtual bool hasBeenChangedInDB ( bool  resetChangedState = true)
inlinefinalvirtualinherited

Has the object been updated in DB since GlobalParamSet<...> has been constructed? Since last call to this function with resetChangedState=true.

Definition at line 137 of file GlobalParam.h.

137{auto tmp = m_hasBeenChangedInDB; if (resetChangedState) m_hasBeenChangedInDB = false; return tmp;}

◆ is()

bool is ( ) const
inlineinherited

Is this set of given type?

Returns
true if stored set is of given type

Definition at line 144 of file GlobalParam.h.

144{return DBObjType::getGlobalUniqueID() == getGlobalUniqueID();}

◆ isConstructed()

virtual bool isConstructed ( ) const
inlinefinaloverridevirtual

Is the internal object already constructed? we construct the object on first access to the stored values.

Implements GlobalParamSetAccess.

Definition at line 290 of file GlobalParam.h.

290{return !!m_object;}

◆ listGlobalParams() [1/3]

std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams ( )
virtual

List global parameters in this DB object.

Implements GlobalParamSetAccess.

◆ listGlobalParams() [2/3]

std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams ( )
virtual

List global parameters in this DB object.

Implements GlobalParamSetAccess.

Definition at line 70 of file GlobalParam.cc.

71 {
72 return {{0, 1}, {0, 2}, {0, 3}};
73 }

◆ listGlobalParams() [3/3]

virtual std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams ( )
inlinefinaloverridevirtual

List global parameters in this DB object.

Implements GlobalParamSetAccess.

Definition at line 209 of file GlobalParam.h.

209{ensureConstructed(); return m_object->listGlobalParams();}

◆ loadFromDB()

virtual void loadFromDB ( EventMetaData  event)
inlinefinaloverridevirtual

Load content of the object valid at given event from DB Also resets if the object has been changed.

Implements GlobalParamSetAccess.

Definition at line 273 of file GlobalParam.h.

274 {
275 auto info = Database::Instance().getData(event, getDefaultName());
276 DBObjType* ptr = dynamic_cast<DBObjType*>(info.first);
277 if (!ptr) {
278 B2ERROR("Could not fetch object " << getDefaultName() << " from DB.");
279 return;
280 }
281 // don't make a copy, you own the object.
282 m_object.reset(ptr);
283 hasBeenChangedInDB(); // will set m_hasBeenChangedInDB to false, ignore return value;
284 }
virtual bool hasBeenChangedInDB(bool resetChangedState=true) final
Has the object been updated in DB since GlobalParamSet<...> has been constructed? Since last call to ...
Definition: GlobalParam.h:137
virtual std::string getDefaultName() const override final
Get the DB object default name used by datastore.
Definition: GlobalParam.h:211
std::pair< TObject *, IntervalOfValidity > getData(const EventMetaData &event, const std::string &name)
Request an object from the database.
Definition: Database.cc:72
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42

◆ loadFromDBObjPtr()

virtual void loadFromDBObjPtr ( )
inlinefinaloverridevirtual

Load content of the object using DBObjPtr<DBObjType> which will try to load object valid for current EventMetaData Also resets if the object has been changed.

Implements GlobalParamSetAccess.

Definition at line 262 of file GlobalParam.h.

263 {
264 DBObjPtr<DBObjType> dbObject;
265 if (dbObject) {
266 m_object.reset(new DBObjType(*dbObject));
267 hasBeenChangedInDB(); // will set m_hasBeenChangedInDB to false, ignore return value;
268 }
269 }

◆ operator bool()

operator bool ( )
inlineinherited

Tentative operator to quickly check the set Returns true when the set is not empty() and the DB object is constructed and can be accessed.

Definition at line 167 of file GlobalParam.h.

168 {
169 return not empty() and isConstructed();
170 }
virtual bool isConstructed() const =0
Has the internal DBObject been already constructed The object is constructed at latest on first acces...

◆ operator=()

GlobalParamSet< DBObjType > & operator= ( const GlobalParamSet< DBObjType > &  other)
inline

Assignment operator.

Definition at line 233 of file GlobalParam.h.

234 {
235 // check for self-assignment
236 if (&other == this)
237 return *this;
238 m_hasBeenChangedInDB = other.m_hasBeenChangedInDB;
239 // Make new unique ptr to a copy of the other internal object
240 if (other.m_object)
241 m_object.reset(new DBObjType(*(static_cast<DBObjType*>(other.m_object.get()))));
242 return *this;
243 }

◆ releaseObject()

virtual TObject * releaseObject ( )
inlinefinaloverridevirtual

Release the DB object from the internal unique pointer to be managed elsewhere (e.g.

stored to the DB and deleted by it)

Implements GlobalParamSetAccess.

Definition at line 247 of file GlobalParam.h.

248 {
249 //ensureConstructed();
250 return m_object.release();
251 }

◆ setGlobalParam() [1/3]

void setGlobalParam ( double  value,
unsigned short  element,
unsigned short  param 
)
virtual

Set global parameter of the DB object by its element and parameter number.

Implements GlobalParamSetAccess.

◆ setGlobalParam() [2/3]

void setGlobalParam ( double  value,
unsigned short  element,
unsigned short  param 
)
virtual

Set global parameter of the DB object by its element and parameter number.

Implements GlobalParamSetAccess.

Definition at line 52 of file GlobalParam.cc.

53 {
54 this->ensureConstructed();
55 if (element != 0 or param > 3) {
56 B2ERROR("Invalid global BeamSpot id");
57 return;
58 }
59 if (auto bp = dynamic_cast<BeamSpot*>(this->getDBObj())) {
60 B2Vector3D vertex = bp->getIPPosition();
61 vertex[param - 1] = value;
62 bp->setIP(vertex, bp->getIPPositionCovMatrix());
63 } else {
64 B2ERROR("Could not set value for BeamSpot");
65 }
66
67 }
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:516

◆ setGlobalParam() [3/3]

virtual void setGlobalParam ( double  value,
unsigned short  element,
unsigned short  param 
)
inlinefinaloverridevirtual

Set global parameter of the DB object by its element and parameter number.

Implements GlobalParamSetAccess.

Definition at line 207 of file GlobalParam.h.

207{ensureConstructed(); m_object->setGlobalParam(value, element, param);}

◆ updateGlobalParam()

virtual void updateGlobalParam ( double  correction,
unsigned short  element,
unsigned short  param 
)
inlinevirtualinherited

Sum value of global element param with a correction.

Definition at line 112 of file GlobalParam.h.

112{setGlobalParam(getGlobalParam(element, param) + correction, element, param);}
virtual void setGlobalParam(double, unsigned short, unsigned short)=0
implemtn: set a global param value by element and param number
virtual double getGlobalParam(unsigned short, unsigned short)=0
implement: get a global parameter value based on the element number in the DBObject and its parameter...

Member Data Documentation

◆ m_hasBeenChangedInDB

bool m_hasBeenChangedInDB {false}
protectedinherited

Flag for object changed in DB.

Definition at line 174 of file GlobalParam.h.

◆ m_object

std::unique_ptr<DBObjType> m_object {}
private

The internal DB object.

Definition at line 299 of file GlobalParam.h.


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