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 76 of file GlobalParam.cc.

76: m_components(components) {}
std::vector< std::string > m_components
Vector of names of DB objects to consider in the vector - if not here and non-empy,...
Definition: GlobalParam.h:496

◆ ~GlobalParamVector()

~GlobalParamVector ( )
inline

Destructor.

Definition at line 339 of file GlobalParam.h.

339{}

Member Function Documentation

◆ addDBObj()

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 }
std::map< unsigned short, std::unique_ptr< GlobalParamSetAccess > > m_vector
The vector (well, actually a map) of DB objects.
Definition: GlobalParam.h:492
void addSubDetectorInterface(std::shared_ptr< IGlobalParamInterface > interface={})
Add a generic interface (cannot be disabled by 'components' in constructor)
Definition: GlobalParam.h:357

◆ 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) {
361 interface) == m_subDetectorInterfacesVector.end())
362 m_subDetectorInterfacesVector.push_back(interface);
363 }
364 }
std::vector< std::shared_ptr< IGlobalParamInterface > > m_subDetectorInterfacesVector
Vector of interfaces to run at specific points in the workflow.
Definition: GlobalParam.h:494

◆ construct()

void construct ( )

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

Definition at line 147 of file GlobalParam.cc.

148 {
149 for (auto& uID_DBObj : m_vector) {
150 if (not uID_DBObj.second->isConstructed()) uID_DBObj.second->construct();
151 }
152 }

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

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 96 of file GlobalParam.cc.

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

◆ getGlobalParamSet()

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())
466
467 return static_cast<GlobalParamSet<DBObjType>&>(*m_vector[DBObjType::getGlobalUniqueID()]);
468 }
GlobalParamSet< EmptyGlobalParamSet > c_emptyGlobalParamSet
An empty set to which reference is returned if DB object not found Also used e.g.
Definition: GlobalParam.h:331

◆ 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 {
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);}
bool hasBeenChangedInDB(const std::set< unsigned short > &subset, bool resetChangedState=true)
Has any DB object in vector changed from last call to this function.
Definition: GlobalParam.h:387

◆ 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 107 of file GlobalParam.cc.

108 {
109 std::vector<std::tuple<unsigned short, unsigned short, unsigned short>> params;
110 for (auto& uID_DBObj : m_vector) {
111 for (auto element_param : uID_DBObj.second->listGlobalParams()) {
112 params.push_back({uID_DBObj.first, element_param.first, element_param.second});
113 }
114 }
115 return params;
116 }

◆ 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 128 of file GlobalParam.cc.

129 {
130 for (auto& uID_DBObj : m_vector) {
131 uID_DBObj.second->loadFromDBObjPtr();
132 }
133 }

◆ 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 134 of file GlobalParam.cc.

135 {
136 for (auto& uID_DBObj : m_vector) {
137 uID_DBObj.second->loadFromDB(event);
138 }
139 }

◆ 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 }
std::vector< std::tuple< unsigned short, unsigned short, unsigned short > > listGlobalParams()
Create vector of all global parameters maintained by GlobalParamVector.
Definition: GlobalParam.cc:107
void updateGlobalParam(double difference, unsigned short uniqueID, unsigned short element, unsigned short param)
Add 'difference' to param value.
Definition: GlobalParam.cc:78

◆ postHierarchyChanged()

void postHierarchyChanged ( GlobalDerivativesHierarchy hierarchy)

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

Definition at line 140 of file GlobalParam.cc.

141 {
142 for (auto interface : m_subDetectorInterfacesVector) {
143 interface->setupAlignmentHierarchy(hierarchy);
144 }
145
146 }

◆ 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 153 of file GlobalParam.cc.

155 {
156 for (auto interface : m_subDetectorInterfacesVector) {
157 interface->readFromResult(results, *this);
158 }
159 }

◆ 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 117 of file GlobalParam.cc.

118 {
119 std::vector<TObject*> result;
120 for (auto& uID_DBObj : m_vector) {
121 if (onlyConstructed and not uID_DBObj.second->isConstructed())
122 continue;
123
124 result.push_back({uID_DBObj.second->releaseObject()});
125 }
126 return result;
127 }

◆ 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 85 of file GlobalParam.cc.

87 {
88 auto dbObj = m_vector.find(uniqueID);
89 if (dbObj != m_vector.end()) {
90 dbObj->second->setGlobalParam(value, element, param);
91 } else {
92 B2WARNING("Did not found DB object with unique id " << uniqueID << " in global vector. Cannot set value for element " << element <<
93 " and parameter " << param);
94 }
95 }

◆ 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 78 of file GlobalParam.cc.

80 {
81 // TODO: niw can be replaced by other fcn updateGlobalParam of GlobalParamSetAccess
82 auto prev = getGlobalParam(uniqueID, element, param);
83 setGlobalParam(prev + difference, uniqueID, element, param);
84 }
void setGlobalParam(double value, unsigned short uniqueID, unsigned short element, unsigned short param)
Set param value.
Definition: GlobalParam.cc:85
double getGlobalParam(unsigned short uniqueID, unsigned short element, unsigned short param)
Get parameter value.
Definition: GlobalParam.cc:96

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.

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

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

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

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


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