 |
Belle II Software
release-05-01-25
|
13 #include <framework/logging/Logger.h>
14 #include <framework/database/Database.h>
15 #include <framework/database/DBObjPtr.h>
16 #include <mdst/dbobjects/BeamSpot.h>
30 class GlobalParamVector;
31 class GlobalDerivativesHierarchy;
34 class EmptyGlobalParamSet :
public TObject {
44 std::vector<std::pair<unsigned short, unsigned short>>
listGlobalParams() {
return {};}
61 virtual void readFromResult(std::vector<std::tuple<unsigned short, unsigned short, unsigned short, double>>&,
106 virtual double getGlobalParam(
unsigned short,
unsigned short) = 0;
108 virtual void setGlobalParam(
double,
unsigned short,
unsigned short) = 0;
110 virtual std::vector<std::pair<unsigned short, unsigned short>>
listGlobalParams() = 0;
144 template<
class DBObjType>
152 if (is<EmptyGlobalParamSet>())
186 template<
class DBObjType>
203 virtual unsigned short getGlobalUniqueID() const override final {
return DBObjType::getGlobalUniqueID();}
212 virtual std::string
getDefaultName() const override final {
return DataStore::objectName<DBObjType>(
"");}
230 m_object.reset(
new DBObjType(*(
static_cast<DBObjType*
>(other.
m_object.get()))));
234 GlobalParamSet<DBObjType>&
operator=(
const GlobalParamSet<DBObjType>& other)
242 m_object.reset(
new DBObjType(*(
static_cast<DBObjType*
>(other.m_object.get()))));
267 m_object.reset(
new DBObjType(*dbObject));
277 DBObjType* ptr =
dynamic_cast<DBObjType*
>(info.first);
279 B2ERROR(
"Could not fetch object " <<
getDefaultName() <<
" from DB.");
300 std::unique_ptr<DBObjType>
m_object {};
351 double delta = rhs.
getGlobalParam(std::get<0>(uid_element_param), std::get<1>(uid_element_param), std::get<2>(uid_element_param));
352 updateGlobalParam(delta, std::get<0>(uid_element_param), std::get<1>(uid_element_param), std::get<2>(uid_element_param));
371 template <
class DBObjType>
372 void addDBObj(std::shared_ptr<IGlobalParamInterface> interface = {})
376 m_vector.insert(std::make_pair(DBObjType::getGlobalUniqueID(),
388 bool hasBeenChangedInDB(
const std::set<unsigned short>& subset,
bool resetChangedState =
true)
390 bool changed =
false;
393 if (!subset.empty() and subset.find(uID_DBObj.first) != subset.end())
395 if (uID_DBObj.second->hasBeenChangedInDB(resetChangedState)) {
411 void updateGlobalParam(
double difference,
unsigned short uniqueID,
unsigned short element,
unsigned short param);
418 void setGlobalParam(
double value,
unsigned short uniqueID,
unsigned short element,
unsigned short param);
424 double getGlobalParam(
unsigned short uniqueID,
unsigned short element,
unsigned short param);
427 std::vector<std::tuple<unsigned short, unsigned short, unsigned short>>
listGlobalParams();
434 std::vector<TObject*>
releaseObjects(
bool onlyConstructed =
true);
443 void postReadFromResult(std::vector<std::tuple<unsigned short, unsigned short, unsigned short, double>>& result);
449 template<
class DBObjType>
455 return static_cast<DBObjType*
>(
m_vector[DBObjType::getGlobalUniqueID()]->getDBObj());
462 template<
class DBObjType>
472 const std::map<unsigned short, std::unique_ptr<GlobalParamSetAccess>>&
getGlobalParamSets()
const
486 std::set<unsigned short> result;
488 result.insert(id_obj.first);
493 std::map<unsigned short, std::unique_ptr<GlobalParamSetAccess>>
m_vector {};
virtual void callbackDB()
Function to call when object has been changed in DB since last loaded.
std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams()
list stored global parameters - empty list, no parameters
virtual void loadFromDB(EventMetaData emd)=0
Load the content (by copying obj retrieved from DB) for a given exp/run/event.
Very tentative interface for VXD.
virtual ~IGlobalParamInterface()
Destructor.
double getGlobalParam(unsigned short uniqueID, unsigned short element, unsigned short param)
Get parameter value.
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 unsigned short getGlobalUniqueID() const override final
The DB object unique id in global calibration.
std::pair< TObject *, IntervalOfValidity > getData(const EventMetaData &event, const std::string &name)
Request an object from the database.
virtual ~GlobalParamSetAccess()
Virtual destructor (base class, but with no members)
static E_VXDHierarchyType s_hierarchyType
What type of hierarchy to use for VXD?
double getGlobalParam(unsigned short, unsigned short)
Get global parameter - return zero.
virtual GlobalParamSetAccess * clone()=0
Clone the object, making a copy of the internal object - has to be implemented in derived template cl...
virtual void construct()=0
Construct the internal DBObject.
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 del...
GlobalParamSetAccess & getGlobalParamSet()
Get reference to the underlying DB object container You should check the container.
GlobalParamSet< DBObjType > & operator=(const GlobalParamSet< DBObjType > &other)
Assignment operator.
virtual bool hasBeenChangedInDB(bool resetChangedState=true) final
Has the object been updated in DB since GlobalParamSet<...> has been constructed? Since last call to ...
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,...
Class for alignment/calibration parameter hierarchy & constraints.
void setGlobalParam(double, unsigned short, unsigned short)
Set global parameter - do nothing.
DBObjType * getDBObj()
Get the raw pointer toa stored object WARNING: Use with caution, returns nullptr if object not regist...
std::set< unsigned short > m_componentsIDs
Vector of UniqueIDs of DB objects to consider in the vector.
virtual void loadFromDBObjPtr() override final
Load content of the object using DBObjPtr<DBObjType> which will try to load object valid for current ...
std::vector< std::string > m_components
Vector of names of DB objects to consider in the vector - if not here and non-empy,...
bool is() const
Is this set of given type?
Some tentative base class to allow to add functionality to the default behavior, like manipulate cons...
virtual void setupAlignmentHierarchy(GlobalDerivativesHierarchy &hierarchy) override final
Very tentaive function: not yet used.
virtual void setGlobalParam(double, unsigned short, unsigned short)=0
implemtn: set a global param value by element and param number
bool empty()
Is this set empty or otherwise 'invalid' to identify null sets, end of hierarchy.
void construct()
Construct all DB objects using default constructors (should be filled with zeros)
virtual TObject * releaseObject()=0
Release the object from internal unique_ptr to be managed elsewhere Useful to pass it to be stored in...
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 GlobalParamVect...
virtual void readFromResult(std::vector< std::tuple< unsigned short, unsigned short, unsigned short, double >> &, GlobalParamVector &)
Implement this to be called after Millepede finishes and all global parameters are filled in DB objec...
GlobalParamVector & operator+=(GlobalParamVector &rhs)
TODO: operator += to sum two global vectors.
Base accessor class to store different DBObjects e.g.
void updateGlobalParam(double difference, unsigned short uniqueID, unsigned short element, unsigned short param)
Add 'difference' to param value.
Class for accessing objects in the database.
GlobalParamSetAccess()
Constructor.
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...
virtual void callbackDB() override final
Function to call when object has been changed in DB since last loaded TODO Hide and find the class wh...
Template class for generic access to DB objects.
The central user class to manipulate any global constant in any DB object Used to retrieve global par...
virtual unsigned short getGlobalUniqueID() const =0
implement: Get the global unique id of DBObject
virtual TObject * releaseObject() override final
Release the DB object from the internal unique pointer to be managed elsewhere (e....
virtual void construct() override final
Construct the internal object using default constructor.
virtual TObject * getDBObj()=0
Get a raw pointer to the internal DB object (can be nullptr if not yet constructed) Use with caution ...
virtual std::string getDefaultName() const override final
Get the DB object default name used by datastore.
Abstract base class for different kinds of events.
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)
virtual void setupAlignmentHierarchy(GlobalDerivativesHierarchy &)
Super-tentavive: not yet used.
bool hasBeenChangedInDB(const std::set< unsigned short > &subset, bool resetChangedState=true)
Has any DB object in vector changed from last call to this function.
virtual bool isConstructed() const =0
Has the internal DBObject been already constructed The object is constructed at latest on first acces...
std::vector< std::tuple< unsigned short, unsigned short, unsigned short > > listGlobalParams()
Create vector of all global parameters maintained by GlobalParamVector.
void postHierarchyChanged(GlobalDerivativesHierarchy &hierarchy)
Function calling interfaces to build alignment hierarchy after constants changed in DB.
const std::vector< std::shared_ptr< IGlobalParamInterface > > & getSubDetectorInterfaces() const
Get the vector of added interfaces to subdetectors.
static bool s_enablePXD
Enable PXD in hierarchy?
virtual std::string getDefaultName() const =0
Get the default DBObject name used by datastore.
void setGlobalParam(double value, unsigned short uniqueID, unsigned short element, unsigned short param)
Set param value.
virtual void updateGlobalParam(double correction, unsigned short element, unsigned short param)
Sum value of global element param with a correction.
static Database & Instance()
Instance of a singleton Database.
void ensureConstructed()
Function to construct the object if not already done.
void loadFromDB()
Load content of all objects in vector with values valid at current EventMetaData Uses DBObjPtr<DBObjT...
~GlobalParamSet()
Destructor.
static unsigned short getGlobalUniqueID()
Get global unique id = 0 (empty/none)
GlobalParamSet< EmptyGlobalParamSet > c_emptyGlobalParamSet
An empty set to which reference is returned if DB object not found Also used e.g.
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 std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams()=0
implement: generate list of all global parameters in the DBObject
virtual std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams() override final
List global parameters in this DB object.
static bool s_enableSVD
Enable SVD in hierarchy?
GlobalParamVector(const std::vector< std::string > &components={})
Constructor.
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...
std::set< unsigned short > getComponentsIDs() const
Get set of unique ids of all db objects considered.
virtual GlobalParamSetAccess * clone() override final
Clone the object, making a copy of the internal object.
~GlobalParamVector()
Destructor.
E_VXDHierarchyType
Type of VXD hierarchy.
void addSubDetectorInterface(std::shared_ptr< IGlobalParamInterface > interface={})
Add a generic interface (cannot be disabled by 'components' in constructor)
std::vector< std::shared_ptr< IGlobalParamInterface > > m_subDetectorInterfacesVector
Vector of interfaces to run at specific points in the workflow.
virtual bool isConstructed() const override final
Is the internal object already constructed? we construct the object on first access to the stored val...
std::map< unsigned short, std::unique_ptr< GlobalParamSetAccess > > m_vector
The vector (well, actually a map) of DB objects.
void addDBObj(std::shared_ptr< IGlobalParamInterface > interface={})
Add a DB object to the vector, optionally with interface.
std::unique_ptr< DBObjType > m_object
The internal DB object.
bool m_hasBeenChangedInDB
Flag for object changed in DB.
GlobalParamSet()
Constructor. Sets callback for DB object changes.
virtual void loadFromDBObjPtr()=0
Load using DBObjPtr<DBObjType> which uses current EventMetaData to load valid constants.