11#include <framework/logging/Logger.h>
12#include <framework/database/Database.h>
13#include <framework/database/DBObjPtr.h>
14#include <mdst/dbobjects/BeamSpot.h>
28 class GlobalParamVector;
29 class GlobalDerivativesHierarchy;
60 virtual void readFromResult(std::vector<std::tuple<unsigned short, unsigned short, unsigned short, double>>&,
143 template<
class DBObjType>
151 if (is<EmptyGlobalParamSet>())
185 template<
class DBObjType>
202 virtual unsigned short getGlobalUniqueID() const override final {
return DBObjType::getGlobalUniqueID();}
211 virtual std::string
getDefaultName() const override final {
return DataStore::objectName<DBObjType>(
"");}
229 m_object.reset(
new DBObjType(*(
static_cast<DBObjType*
>(other.
m_object.get()))));
241 m_object.reset(
new DBObjType(*(
static_cast<DBObjType*
>(other.
m_object.get()))));
266 m_object.reset(
new DBObjType(*dbObject));
276 DBObjType* ptr =
dynamic_cast<DBObjType*
>(info.first);
278 B2ERROR(
"Could not fetch object " <<
getDefaultName() <<
" from DB.");
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));
370 template <
class DBObjType>
371 void addDBObj(std::shared_ptr<IGlobalParamInterface> interface = {})
375 m_vector.insert(std::make_pair(DBObjType::getGlobalUniqueID(),
389 bool changed =
false;
392 if (!subset.empty() and subset.find(uID_DBObj.first) != subset.end())
394 if (uID_DBObj.second->hasBeenChangedInDB(resetChangedState)) {
410 void updateGlobalParam(
double difference,
unsigned short uniqueID,
unsigned short element,
unsigned short param);
417 void setGlobalParam(
double value,
unsigned short uniqueID,
unsigned short element,
unsigned short param);
423 double getGlobalParam(
unsigned short uniqueID,
unsigned short element,
unsigned short param);
426 std::vector<std::tuple<unsigned short, unsigned short, unsigned short>>
listGlobalParams();
433 std::vector<TObject*>
releaseObjects(
bool onlyConstructed =
true);
442 void postReadFromResult(std::vector<std::tuple<unsigned short, unsigned short, unsigned short, double>>& result);
448 template<
class DBObjType>
454 return static_cast<DBObjType*
>(
m_vector[DBObjType::getGlobalUniqueID()]->getDBObj());
461 template<
class DBObjType>
485 std::set<unsigned short> result;
487 result.insert(id_obj.first);
492 std::map<unsigned short, std::unique_ptr<GlobalParamSetAccess>>
m_vector {};
Class for accessing objects in the database.
Object representing no parameters.
std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams()
list stored global parameters - empty list, no parameters
double getGlobalParam(unsigned short, unsigned short)
Get global parameter - return zero.
static unsigned short getGlobalUniqueID()
Get global unique id = 0 (empty/none)
void setGlobalParam(double, unsigned short, unsigned short)
Set global parameter - do nothing.
Class for alignment/calibration parameter hierarchy & constraints.
Base accessor class to store different DBObjects e.g.
GlobalParamSetAccess()
Constructor.
virtual void loadFromDBObjPtr()=0
Load using DBObjPtr<DBObjType> which uses current EventMetaData to load valid constants.
virtual GlobalParamSetAccess * clone()=0
Clone the object, making a copy of the internal object - has to be implemented in derived template cl...
virtual void loadFromDB(EventMetaData emd)=0
Load the content (by copying obj retrieved from DB) for a given exp/run/event.
bool empty()
Is this set empty or otherwise 'invalid' to identify null sets, end of hierarchy.
virtual TObject * releaseObject()=0
Release the object from internal unique_ptr to be managed elsewhere Useful to pass it to be stored in...
virtual void callbackDB()
Function to call when object has been changed in DB since last loaded.
virtual std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams()=0
implement: generate list of all global parameters in the DBObject
virtual std::string getDefaultName() const =0
Get the default DBObject name used by datastore.
virtual void updateGlobalParam(double correction, unsigned short element, unsigned short param)
Sum value of global element param with a correction.
bool m_hasBeenChangedInDB
Flag for object changed in DB.
virtual unsigned short getGlobalUniqueID() const =0
implement: Get the global unique id of DBObject
virtual ~GlobalParamSetAccess()
Virtual destructor (base class, but with no members)
virtual void setGlobalParam(double, unsigned short, unsigned short)=0
implemtn: set a global param value by element and param number
virtual TObject * getDBObj()=0
Get a raw pointer to the internal DB object (can be nullptr if not yet constructed) Use with caution ...
virtual bool hasBeenChangedInDB(bool resetChangedState=true) final
Has the object been updated in DB since GlobalParamSet<...> has been constructed? Since last call to ...
virtual void construct()=0
Construct the internal DBObject.
bool is() const
Is this set of given type?
virtual bool isConstructed() const =0
Has the internal DBObject been already constructed The object is constructed at latest on first acces...
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...
Template class for generic access to DB objects.
virtual void loadFromDBObjPtr() override final
Load content of the object using DBObjPtr<DBObjType> which will try to load object valid for current ...
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 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,...
std::unique_ptr< DBObjType > m_object
The internal DB object.
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...
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...
void ensureConstructed()
Function to construct the object if not already done.
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.
GlobalParamSet()
Constructor. Sets callback for DB object changes.
virtual std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams() override final
List global parameters in this DB object.
~GlobalParamSet()
Destructor.
virtual void construct() override final
Construct the internal object using default constructor.
virtual unsigned short getGlobalUniqueID() const override final
The DB object unique id in global calibration.
virtual std::string getDefaultName() const override final
Get the DB object default name used by datastore.
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....
GlobalParamSet(const GlobalParamSet< DBObjType > &other)
Copy constructor.
virtual bool isConstructed() const override final
Is the internal object already constructed? we construct the object on first access to the stored val...
virtual GlobalParamSetAccess * clone() override final
Clone the object, making a copy of the internal object.
The central user class to manipulate any global constant in any DB object Used to retrieve global par...
DBObjType * getDBObj()
Get the raw pointer toa stored object WARNING: Use with caution, returns nullptr if object not regist...
std::set< unsigned short > getComponentsIDs() const
Get set of unique ids of all db objects considered.
std::vector< std::string > m_components
Vector of names of DB objects to consider in the vector - if not here and non-empy,...
std::vector< std::tuple< unsigned short, unsigned short, unsigned short > > listGlobalParams()
Create vector of all global parameters maintained by GlobalParamVector.
GlobalParamSet< EmptyGlobalParamSet > c_emptyGlobalParamSet
An empty set to which reference is returned if DB object not found Also used e.g.
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.
bool hasBeenChangedInDB(const std::set< unsigned short > &subset={})
Const version which does not change the state.
std::map< unsigned short, std::unique_ptr< GlobalParamSetAccess > > m_vector
The vector (well, actually a map) of DB objects.
~GlobalParamVector()
Destructor.
std::vector< std::shared_ptr< IGlobalParamInterface > > m_subDetectorInterfacesVector
Vector of interfaces to run at specific points in the workflow.
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.
void construct()
Construct all DB objects using default constructors (should be filled with zeros)
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...
void addDBObj(std::shared_ptr< IGlobalParamInterface > interface={})
Add a DB object to the vector, optionally with interface.
void addSubDetectorInterface(std::shared_ptr< IGlobalParamInterface > interface={})
Add a generic interface (cannot be disabled by 'components' in constructor)
void postHierarchyChanged(GlobalDerivativesHierarchy &hierarchy)
Function calling interfaces to build alignment hierarchy after constants changed in DB.
void loadFromDB()
Load content of all objects in vector with values valid at current EventMetaData Uses DBObjPtr<DBObjT...
GlobalParamVector & operator+=(GlobalParamVector &rhs)
TODO: operator += to sum two global vectors.
void updateGlobalParam(double difference, unsigned short uniqueID, unsigned short element, unsigned short param)
Add 'difference' to param value.
bool hasBeenChangedInDB(const std::set< unsigned short > &subset, bool resetChangedState=true)
Has any DB object in vector changed from last call to this function.
const std::vector< std::shared_ptr< IGlobalParamInterface > > & getSubDetectorInterfaces() const
Get the vector of added interfaces to subdetectors.
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)
std::set< unsigned short > m_componentsIDs
Vector of UniqueIDs of DB objects to consider in the vector.
Some tentative base class to allow to add functionality to the default behavior, like manipulate cons...
virtual void setupAlignmentHierarchy(GlobalDerivativesHierarchy &)
Super-tentavive: not yet used.
virtual ~IGlobalParamInterface()
Destructor.
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...
Very tentative interface for VXD.
static bool s_enablePXD
Enable PXD in hierarchy?
static bool s_enableSVD
Enable SVD in hierarchy?
virtual void setupAlignmentHierarchy(GlobalDerivativesHierarchy &hierarchy) override final
Very tentaive function: not yet used.
E_VXDHierarchyType
Type of VXD hierarchy.
static E_VXDHierarchyType s_hierarchyType
What type of hierarchy to use for VXD?
std::pair< TObject *, IntervalOfValidity > getData(const EventMetaData &event, const std::string &name)
Request an object from the database.
static Database & Instance()
Instance of a singleton Database.
Abstract base class for different kinds of events.