Belle II Software development
GlobalParamVector Class Reference

The central user class to manipulate any global constant in any DB object Used to retrieve global parameters from database and access the for update. More...

#include <GlobalParam.h>

Public Member Functions

 GlobalParamVector (const std::vector< std::string > &components={})
 Constructor.
 
 ~GlobalParamVector ()
 Destructor.
 
void construct ()
 Construct all DB objects using default constructors (should be filled with zeros)
 
GlobalParamVectoroperator+= (GlobalParamVector &rhs)
 TODO: operator += to sum two global vectors.
 
void addSubDetectorInterface (std::shared_ptr< IGlobalParamInterface > interface={})
 Add a generic interface (cannot be disabled by 'components' in constructor)
 
template<class DBObjType>
void addDBObj (std::shared_ptr< IGlobalParamInterface > interface={})
 Add a DB object to the vector, optionally with interface.
 
bool hasBeenChangedInDB (const std::set< unsigned short > &subset, bool resetChangedState=true)
 Has any DB object in vector changed from last call to this function.
 
bool hasBeenChangedInDB (const std::set< unsigned short > &subset={})
 Const version which does not change the state.
 
void updateGlobalParam (double difference, unsigned short uniqueID, unsigned short element, unsigned short param)
 Add 'difference' to param value.
 
void setGlobalParam (double value, unsigned short uniqueID, unsigned short element, unsigned short param)
 Set param value.
 
double getGlobalParam (unsigned short uniqueID, unsigned short element, unsigned short param)
 Get parameter value.
 
std::vector< std::tuple< unsigned short, unsigned short, unsigned short > > listGlobalParams ()
 Create vector of all global parameters maintained by GlobalParamVector.
 
std::vector< TObject * > releaseObjects (bool onlyConstructed=true)
 Get the vector of raw pointers to DB objects Caller takes the ownership of the objects and has to delete them Use for passing the objects to store in DB (not deleted after GlobalParamVector goes out of scope)
 
void loadFromDB ()
 Load content of all objects in vector with values valid at current EventMetaData Uses DBObjPtr<DBObjType> to access current data.
 
void loadFromDB (const EventMetaData &event)
 Load content of all objects in vector with values valid for given exp/run/event.
 
void postReadFromResult (std::vector< std::tuple< unsigned short, unsigned short, unsigned short, double > > &result)
 Function calling interfaces to do post processing after reading millepede result into GlobalParamVector.
 
void postHierarchyChanged (GlobalDerivativesHierarchy &hierarchy)
 Function calling interfaces to build alignment hierarchy after constants changed in DB.
 
template<class DBObjType>
DBObjType * getDBObj ()
 Get the raw pointer toa stored object WARNING: Use with caution, returns nullptr if object not registered (e.g.
 
template<class DBObjType>
GlobalParamSetAccessgetGlobalParamSet ()
 Get reference to the underlying DB object container You should check the container.
 
const std::map< unsigned short, std::unique_ptr< GlobalParamSetAccess > > & getGlobalParamSets () const
 Get map of all contained parameter sets, key = unique id of the set (DB object)
 
const std::vector< std::shared_ptr< IGlobalParamInterface > > & getSubDetectorInterfaces () const
 Get the vector of added interfaces to subdetectors.
 
std::set< unsigned short > getComponentsIDs () const
 Get set of unique ids of all db objects considered.
 

Public Attributes

GlobalParamSet< EmptyGlobalParamSetc_emptyGlobalParamSet {}
 An empty set to which reference is returned if DB object not found Also used e.g.
 

Private Attributes

std::map< unsigned short, std::unique_ptr< GlobalParamSetAccess > > m_vector {}
 The vector (well, actually a map) of DB objects.
 
std::vector< std::shared_ptr< IGlobalParamInterface > > m_subDetectorInterfacesVector {}
 Vector of interfaces to run at specific points in the workflow.
 
std::vector< std::string > m_components {}
 Vector of names of DB objects to consider in the vector - if not here and non-empy, ignored by addDBObj()
 
std::set< unsigned short > m_componentsIDs {}
 Vector of UniqueIDs of DB objects to consider in the vector.
 

Detailed Description

The central user class to manipulate any global constant in any DB object Used to retrieve global parameters from database and access the for update.

Finally all objects can be released for storing in the DB. NOTE the objects are not constructed (an thus quite some memory is saved) until you access them. But the monitoring of changes in DB starts since addDBObj<...>() TODO correct constness to not construct on listGlobalParams()

Definition at line 327 of file GlobalParam.h.

Constructor & Destructor Documentation

◆ GlobalParamVector()

GlobalParamVector ( const std::vector< std::string > & components = {})
explicit

Constructor.

Parameters
componentsvector of string with DB objects default names in the global vector If empty, any component is included by default.

Definition at line 84 of file GlobalParam.cc.

84: m_components(components) {}

◆ ~GlobalParamVector()

~GlobalParamVector ( )
inline

Destructor.

Definition at line 339 of file GlobalParam.h.

339{}

Member Function Documentation

◆ addDBObj()

template<class DBObjType>
void addDBObj ( std::shared_ptr< IGlobalParamInterface > interface = {})
inline

Add a DB object to the vector, optionally with interface.

Parameters
interfaceshared pointer to an interface added only if this DB object is listed in 'components' or 'components' not specified Does nothing if DB object type already added

Definition at line 371 of file GlobalParam.h.

371 {})
372 {
373 if (m_components.empty()
374 or std::find(m_components.begin(), m_components.end(), DataStore::objectName<DBObjType>("")) != m_components.end()) {
375 m_vector.insert(std::make_pair(DBObjType::getGlobalUniqueID(),
376 std::unique_ptr<GlobalParamSet<DBObjType>>(new GlobalParamSet<DBObjType>)
377 ));
378 // NOTE: Components disabled this way also disable added interfaces (e.g. if geometry would be needed to load)
379 // NOTE: add generic interfaces only once by addSubDetectorInterface(...)
380 addSubDetectorInterface(interface);
381 }
382 }

◆ addSubDetectorInterface()

void addSubDetectorInterface ( std::shared_ptr< IGlobalParamInterface > interface = {})
inline

Add a generic interface (cannot be disabled by 'components' in constructor)

Definition at line 357 of file GlobalParam.h.

357 {})
358 {
359 if (interface) {
360 if (std::find(m_subDetectorInterfacesVector.begin(), m_subDetectorInterfacesVector.end(),
361 interface) == m_subDetectorInterfacesVector.end())
362 m_subDetectorInterfacesVector.push_back(interface);
363 }
364 }

◆ construct()

void construct ( )

Construct all DB objects using default constructors (should be filled with zeros)

Definition at line 155 of file GlobalParam.cc.

156 {
157 for (auto& uID_DBObj : m_vector) {
158 if (not uID_DBObj.second->isConstructed()) uID_DBObj.second->construct();
159 }
160 }

◆ getComponentsIDs()

std::set< unsigned short > getComponentsIDs ( ) const
inline

Get set of unique ids of all db objects considered.

Definition at line 483 of file GlobalParam.h.

484 {
485 std::set<unsigned short> result;
486 for (auto& id_obj : m_vector)
487 result.insert(id_obj.first);
488 return result;
489 }

◆ getDBObj()

template<class DBObjType>
DBObjType * getDBObj ( )
inline

Get the raw pointer toa stored object WARNING: Use with caution, returns nullptr if object not registered (e.g.

disabled via 'components')

Definition at line 449 of file GlobalParam.h.

450 {
451 if (m_vector.find(DBObjType::getGlobalUniqueID()) == m_vector.end())
452 return nullptr;
453
454 return static_cast<DBObjType*>(m_vector[DBObjType::getGlobalUniqueID()]->getDBObj());
455 }

◆ getGlobalParam()

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

Get parameter value.

Parameters
uniqueIDuinique id of the DB object
elementid of the element with params inside DB object
paramid of the parameter of the element

Definition at line 104 of file GlobalParam.cc.

105 {
106 auto dbObj = m_vector.find(uniqueID);
107 if (dbObj != m_vector.end()) {
108 return dbObj->second->getGlobalParam(element, param);
109 } else {
110 B2WARNING("Did not found DB object with unique id " << uniqueID << " in global vector. Cannot get value for element " << element <<
111 " and parameter " << param << ". Returning 0.");
112 return 0.;
113 }
114 }

◆ getGlobalParamSet()

template<class DBObjType>
GlobalParamSetAccess & getGlobalParamSet ( )
inline

Get reference to the underlying DB object container You should check the container.

Returns
GlobalParamSet<DBObjType> or GlobalParamSet<EmptyGlobalParamSet> if DBObjType not in global vector (e.g. because disabled via 'components')

Definition at line 462 of file GlobalParam.h.

463 {
464 if (m_vector.find(DBObjType::getGlobalUniqueID()) == m_vector.end())
465 return c_emptyGlobalParamSet;
466
467 return static_cast<GlobalParamSet<DBObjType>&>(*m_vector[DBObjType::getGlobalUniqueID()]);
468 }

◆ getGlobalParamSets()

const std::map< unsigned short, std::unique_ptr< GlobalParamSetAccess > > & getGlobalParamSets ( ) const
inline

Get map of all contained parameter sets, key = unique id of the set (DB object)

Definition at line 471 of file GlobalParam.h.

472 {
473 return m_vector;
474 }

◆ getSubDetectorInterfaces()

const std::vector< std::shared_ptr< IGlobalParamInterface > > & getSubDetectorInterfaces ( ) const
inline

Get the vector of added interfaces to subdetectors.

Definition at line 477 of file GlobalParam.h.

478 {
479 return m_subDetectorInterfacesVector;
480 }

◆ hasBeenChangedInDB() [1/2]

bool hasBeenChangedInDB ( const std::set< unsigned short > & subset,
bool resetChangedState = true )
inline

Has any DB object in vector changed from last call to this function.

Parameters
subsetset of unique ids of objects we are interested
resetChangedStateshould this call result in hasBeenChangedInDB=true?

Definition at line 387 of file GlobalParam.h.

388 {
389 bool changed = false;
390
391 for (auto& uID_DBObj : m_vector) {
392 if (!subset.empty() and subset.find(uID_DBObj.first) != subset.end())
393 continue;
394 if (uID_DBObj.second->hasBeenChangedInDB(resetChangedState)) {
395 changed = true;
396 break;
397 }
398 }
399
400 return changed;
401 }
std::bitset< max - min+1 > subset(std::bitset< nbits > set)
extract a subset of bitstring, like substring.
Definition Cosim.h:120

◆ hasBeenChangedInDB() [2/2]

bool hasBeenChangedInDB ( const std::set< unsigned short > & subset = {})
inline

Const version which does not change the state.

Definition at line 403 of file GlobalParam.h.

403{}) {return hasBeenChangedInDB(subset, false);}

◆ listGlobalParams()

std::vector< std::tuple< short unsigned int, short unsigned int, short unsigned int > > listGlobalParams ( )

Create vector of all global parameters maintained by GlobalParamVector.

Definition at line 115 of file GlobalParam.cc.

116 {
117 std::vector<std::tuple<unsigned short, unsigned short, unsigned short>> params;
118 for (auto& uID_DBObj : m_vector) {
119 for (auto element_param : uID_DBObj.second->listGlobalParams()) {
120 params.push_back({uID_DBObj.first, element_param.first, element_param.second});
121 }
122 }
123 return params;
124 }

◆ loadFromDB() [1/2]

void loadFromDB ( )

Load content of all objects in vector with values valid at current EventMetaData Uses DBObjPtr<DBObjType> to access current data.

Definition at line 136 of file GlobalParam.cc.

137 {
138 for (auto& uID_DBObj : m_vector) {
139 uID_DBObj.second->loadFromDBObjPtr();
140 }
141 }

◆ loadFromDB() [2/2]

void loadFromDB ( const EventMetaData & event)

Load content of all objects in vector with values valid for given exp/run/event.

Definition at line 142 of file GlobalParam.cc.

143 {
144 for (auto& uID_DBObj : m_vector) {
145 uID_DBObj.second->loadFromDB(event);
146 }
147 }

◆ operator+=()

GlobalParamVector & operator+= ( GlobalParamVector & rhs)
inline

TODO: operator += to sum two global vectors.

Definition at line 345 of file GlobalParam.h.

346 {
347 // this += rhs
348 // TODO: needs full implementation of listing in DBObjects
349 for (auto uid_element_param : listGlobalParams()) {
350 double delta = rhs.getGlobalParam(std::get<0>(uid_element_param), std::get<1>(uid_element_param), std::get<2>(uid_element_param));
351 updateGlobalParam(delta, std::get<0>(uid_element_param), std::get<1>(uid_element_param), std::get<2>(uid_element_param));
352 }
353 return *this;
354 }

◆ postHierarchyChanged()

void postHierarchyChanged ( GlobalDerivativesHierarchy & hierarchy)

Function calling interfaces to build alignment hierarchy after constants changed in DB.

Definition at line 148 of file GlobalParam.cc.

149 {
150 for (auto interface : m_subDetectorInterfacesVector) {
151 interface->setupAlignmentHierarchy(hierarchy);
152 }
153
154 }

◆ postReadFromResult()

void postReadFromResult ( std::vector< std::tuple< unsigned short, unsigned short, unsigned short, double > > & result)

Function calling interfaces to do post processing after reading millepede result into GlobalParamVector.

Definition at line 161 of file GlobalParam.cc.

163 {
164 for (auto interface : m_subDetectorInterfacesVector) {
165 interface->readFromResult(results, *this);
166 }
167 }

◆ releaseObjects()

std::vector< TObject * > releaseObjects ( bool onlyConstructed = true)

Get the vector of raw pointers to DB objects Caller takes the ownership of the objects and has to delete them Use for passing the objects to store in DB (not deleted after GlobalParamVector goes out of scope)

Parameters
onlyConstructedif true, only returns objects which have been actually constructed Objects are not constructed until accessed or copied from DB (or constructed explicitly)

Definition at line 125 of file GlobalParam.cc.

126 {
127 std::vector<TObject*> result;
128 for (auto& uID_DBObj : m_vector) {
129 if (onlyConstructed and not uID_DBObj.second->isConstructed())
130 continue;
131
132 result.push_back({uID_DBObj.second->releaseObject()});
133 }
134 return result;
135 }

◆ setGlobalParam()

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

Set param value.

Parameters
valuevalue to set
uniqueIDuinique id of the DB object
elementid of the element with params inside DB object
paramid of the parameter of the element

Definition at line 93 of file GlobalParam.cc.

95 {
96 auto dbObj = m_vector.find(uniqueID);
97 if (dbObj != m_vector.end()) {
98 dbObj->second->setGlobalParam(value, element, param);
99 } else {
100 B2WARNING("Did not found DB object with unique id " << uniqueID << " in global vector. Cannot set value for element " << element <<
101 " and parameter " << param);
102 }
103 }

◆ updateGlobalParam()

void updateGlobalParam ( double difference,
unsigned short uniqueID,
unsigned short element,
unsigned short param )

Add 'difference' to param value.

Parameters
differencevalue to add to current value
uniqueIDuinique id of the DB object
elementid of the element with params inside DB object
paramid of the parameter of the element

Definition at line 86 of file GlobalParam.cc.

88 {
89 // TODO: niw can be replaced by other fcn updateGlobalParam of GlobalParamSetAccess
90 auto prev = getGlobalParam(uniqueID, element, param);
91 setGlobalParam(prev + difference, uniqueID, element, param);
92 }

Member Data Documentation

◆ c_emptyGlobalParamSet

GlobalParamSet<EmptyGlobalParamSet> c_emptyGlobalParamSet {}

An empty set to which reference is returned if DB object not found Also used e.g.

to terminate hierarchy

Definition at line 331 of file GlobalParam.h.

331{};

◆ m_components

std::vector<std::string> m_components {}
private

Vector of names of DB objects to consider in the vector - if not here and non-empy, ignored by addDBObj()

Definition at line 496 of file GlobalParam.h.

496{};

◆ m_componentsIDs

std::set<unsigned short> m_componentsIDs {}
private

Vector of UniqueIDs of DB objects to consider in the vector.

Definition at line 498 of file GlobalParam.h.

498{};

◆ m_subDetectorInterfacesVector

std::vector<std::shared_ptr<IGlobalParamInterface> > m_subDetectorInterfacesVector {}
private

Vector of interfaces to run at specific points in the workflow.

Definition at line 494 of file GlobalParam.h.

494{};

◆ m_vector

std::map<unsigned short, std::unique_ptr<GlobalParamSetAccess> > m_vector {}
private

The vector (well, actually a map) of DB objects.

Definition at line 492 of file GlobalParam.h.

492{};

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