Diana Software
Classes | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
QGlobalDataManager Class Reference

Object to manage I/O (DB, file, or memory) of diana global quantities. More...

Classes

struct  CachedObject
 store source of cached objects More...
 

Public Member Functions

 QGlobalDataManager ()
 constructor More...
 
 ~QGlobalDataManager ()
 dtor More...
 
void Clear ()
 clear cache More...
 
template<class Q >
QError Get (const std::string &owner, GlobalHandle< Q > *gh, const std::string &inSource, bool printError=true) const
 Get an object using a global handle. More...
 
template<class Q >
QError Get (GlobalHandle< Q > *gh, const std::string &inSource, bool printError=true) const
 Get an object owned by the caller module using a global handle. More...
 
template<class Q >
const Q & Get (const std::string &owner, const std::string &name, const std::string &inSource) const
 Get a QObject of type Q. More...
 
template<class Q >
const Q & Get (const std::string &name, const std::string &inSource) const
 Get a QObject of type Q owned by the caller module. More...
 
template<class Q >
QError Set (GlobalHandle< Q > *gh, const std::string &outSource, bool printError=true) const
 Set a QObject using a GlobalHandle. More...
 
template<class Q >
QError Set (const std::string &name, const Q &obj, const std::string &outSource) const
 Set a QObject of type Q. More...
 
std::vector< QGlobalLabelGetWriteLabels () const
 get labels More...
 
const QObjectGetByLabel (const QGlobalLabel &) const
 get object by label (not-recommended). Works only on cached object's More...
 
void SetOwner (const std::string &owner)
 set the module that is accessing this object More...
 
void SetInputVersion (std::string versionTag)
 set the version tag of the object to be read (default = this release) More...
 
void EnableCache (const bool enable)
 enable / disable caching of objects More...
 
void Dump (std::ostream &o) const
 Dump cached objects to stream. More...
 
bool GetCacheEnable () const
 

Static Public Member Functions

static QGlobalDataManagerGetInstance (const std::string &owner="")
 singleton interface provided for use in non diana executables. Do not use it within diana or root macros. More...
 

Private Attributes

std::string fOwner
 the module that is accessing this object More...
 
std::map< QGlobalLabel, CachedObjectfDataMap
 cached QObject 's More...
 
std::map< QGlobalLabel, std::string > fDefaultMap
 default owners More...
 
bool fCacheEnabled
 cache enabled More...
 
std::string fOutputVersion
 Version tag of this release, used to write onto the DB. Parameter not accessible to the user. More...
 
std::string fInputVersion
 Version tag of the objects to be read, used to read from the DB. Parameter not accessible to the user in diana, but accesible outside diana. More...
 

Static Private Attributes

static int fInstances = 0
 number of instances More...
 
static QGlobalDataManagerfUniqueInstance = 0
 singleton instance More...
 

Friends

class QBaseModule
 

Detailed Description

Object to manage I/O (DB, file, or memory) of diana global quantities.

Author
Marco Vignati

QGlobalDataManager is the I/O class for global QObject s. Any QObject can be saved or retrived using this class. It is interfaced with the DB and files via Get/Set interfaces, using the GlobalHandle class to wrap the QObject s and store their ancillary information. Like in the QEvent, each object has a type, a name and an owner. When this class is invoked in diana via QBaseModule::GlobalData(), the owner of the QObject s that will be saved is automatically set as the name of the caller module. To retrive a QObject owned by someone else, the owner must be specified, as in the QEvent.
A global QObject is identified int the QGlobalDataManager cache by its label. The label is composed by the owner and the name, plus the ancillary information that have been provided. Only the needed ancillary information must be filled. The QGlobalDataManager can be used both in ROOT macros and in external compiled code.

The QGlobalDataManager by default caches QObject s, to speed up the I/O in Diana and to avoid the declaration of the input source every time the QObject is read. A QObject can also be saved in the cache without saving it in a file or a DB. This feature can be used to share global data between modules.

Warning: The I/O source is not recorded in the cache. So if a QObject of same type and same GlobalHandle ancillary information of an already read QObject is read specifying a different input source, the returned QObject will be the cached one and the one from the second source will be ignored (an error will be printed). When using the QGlobalDataManager outside diana users can disable the cache (via EnableCache(false)) and get the same QObject from different sources.

Examples
GlobalDataManagerExample.C, and ScanEvents.C.

Definition at line 48 of file QGlobalDataManager.hh.

Constructor & Destructor Documentation

◆ QGlobalDataManager()

QGlobalDataManager::QGlobalDataManager ( )

constructor

Definition at line 25 of file QGlobalDataManager.cc.

References fCacheEnabled, fInputVersion, fInstances, fOutputVersion, fOwner, and QSWInfo::GetDianaCleanVersionTag().

Referenced by GetInstance().

◆ ~QGlobalDataManager()

QGlobalDataManager::~QGlobalDataManager ( )

dtor

Definition at line 40 of file QGlobalDataManager.cc.

References Clear(), and fInstances.

Member Function Documentation

◆ Clear()

void QGlobalDataManager::Clear ( )

clear cache

Definition at line 47 of file QGlobalDataManager.cc.

References fDataMap, and fDefaultMap.

Referenced by QSequence::QSequence(), ~QGlobalDataManager(), and QSequence::~QSequence().

◆ Dump()

void QGlobalDataManager::Dump ( std::ostream &  o) const

◆ EnableCache()

void QGlobalDataManager::EnableCache ( const bool  enable)
inline

enable / disable caching of objects

Examples
ScanEvents.C.

Definition at line 169 of file QGlobalDataManager.hh.

References fCacheEnabled.

Referenced by ScanEvents().

◆ Get() [1/4]

template<class Q >
const Q& QGlobalDataManager::Get ( const std::string &  name,
const std::string &  inSource 
) const
inline

Get a QObject of type Q owned by the caller module.

Parameters
namename of the object
insource"filename" or "" to access cached object's;
const QMyObject& obj = dm.Get<QMyObject>("ObjectName","DB");

Definition at line 118 of file QGlobalDataManager.hh.

References GlobalHandle< Q >::Get(), and Get().

◆ Get() [2/4]

template<class Q >
const Q& QGlobalDataManager::Get ( const std::string &  owner,
const std::string &  name,
const std::string &  inSource 
) const
inline

Get a QObject of type Q.

Parameters
ownername of the module that set the quantity
namename of the object
inSource"filename" or "" to access cached object's;
const QMyObject& obj = dm.Get<QMyObject>("ModuleNameWithoutM","ObjectName","DB");

Definition at line 104 of file QGlobalDataManager.hh.

References GlobalHandle< Q >::Get(), and Get().

◆ Get() [3/4]

template<class Q >
QError QGlobalDataManager::Get ( const std::string &  owner,
GlobalHandle< Q > *  gh,
const std::string &  inSource,
bool  printError = true 
) const

Get an object using a global handle.

Parameters
ownername of the module that set the quantity
ghGlobalHandle class to be filled
inSource"DB" or "filename" or "" to access cached object's
printErrorprint errors on screen and logfile. Error is anyhow stored in the return value;
GlobalHandle<QMyObject> handle("ObjectName");
handle.SetChannel(3); // optional
handle.SetRun(000809); // optional
dm.Get("ModuleNameWithoutM",&handle,"DB");
const QMyObject& obj = handle.Get();
Examples
GlobalDataManagerExample.C, and ScanEvents.C.

Definition at line 220 of file QGlobalDataManager.hh.

References QMessageHandler::Debug(), err, QMessageHandler::Error(), fCacheEnabled, fDataMap, fDefaultMap, GlobalHandle< Q >::fGlobalDataManagerError, GlobalHandle< Q >::FillFromDB(), GlobalHandle< Q >::FillFromFile(), fInputVersion, QGlobalLabel::fOwner, GlobalHandle< Q >::GetAddress(), GlobalHandle< Q >::GetDefaultOwner(), GlobalHandle< Q >::GetLabel(), GlobalHandle< Q >::GetOwner(), QGlobalLabel::GetStringLabel(), GlobalHandle< Q >::GetVersion(), QERR_GLOBAL_GENERIC, QERR_SUCCESS, GlobalHandle< Q >::SetOwner(), and GlobalHandle< Q >::SetVersion().

Referenced by QFileWriter::BuildFileName(), QTriggerOptimumFilter::BuildOptimumFilter(), QFileWriter::Do(), DrawAveragePulse(), FillFromDB(), Get(), QInitFileHandler::GetBool(), QInitFileHandler::GetDouble(), QInitFileHandler::GetInt(), QInitFileHandler::GetQObject(), QInitFileHandler::GetStdVector(), QInitFileHandler::GetString(), main(), Read(), QSequence::Run(), QSequence::SaveConfig(), ScanEvents(), and StoreOnDB().

◆ Get() [4/4]

template<class Q >
QError QGlobalDataManager::Get ( GlobalHandle< Q > *  gh,
const std::string &  inSource,
bool  printError = true 
) const

Get an object owned by the caller module using a global handle.

Parameters
bghGlobalHandle class to be filled
inSource"DB" or "filename" or "" to access cached object's
printErrorprint errors on screen and logfile. Error is anyhow stored in the return value;
GlobalHandle<QMyObject> handle("ObjectName");
handle.SetChannel(3); // optional
handle.SetRun(000809); // optional
dm.Get(&handle,"DB");
const QMyObject& obj = handle.Get();

Definition at line 214 of file QGlobalDataManager.hh.

References fOwner, Get(), GlobalHandle< Q >::GetOwner(), and GlobalHandle< Q >::SetOwner().

◆ GetByLabel()

const QObject * QGlobalDataManager::GetByLabel ( const QGlobalLabel label) const

get object by label (not-recommended). Works only on cached object's

Definition at line 125 of file QGlobalDataManager.cc.

References fDataMap.

◆ GetCacheEnable()

bool QGlobalDataManager::GetCacheEnable ( ) const
inline

Definition at line 174 of file QGlobalDataManager.hh.

References fCacheEnabled.

◆ GetInstance()

QGlobalDataManager & QGlobalDataManager::GetInstance ( const std::string &  owner = "")
static

singleton interface provided for use in non diana executables. Do not use it within diana or root macros.

Parameters
ownerowner of the objects that will be seved. Must be specified at the first call of this function.

Definition at line 13 of file QGlobalDataManager.cc.

References DianaThrow, fUniqueInstance, QGlobalDataManager(), and SetOwner().

◆ GetWriteLabels()

std::vector< QGlobalLabel > QGlobalDataManager::GetWriteLabels ( ) const

get labels

Definition at line 114 of file QGlobalDataManager.cc.

References fDataMap.

◆ Set() [1/2]

template<class Q >
QError QGlobalDataManager::Set ( const std::string &  name,
const Q &  obj,
const std::string &  outSource 
) const
inline

Set a QObject of type Q.

Parameters
namename of the QObject
objthe QObject to be saved
outsource"filename" or "" to set an object in memory;
QMyObject obj;
dm.Set("ObjectName",obj,"filename");

Definition at line 149 of file QGlobalDataManager.hh.

References GlobalHandle< Q >::Set(), and Set().

◆ Set() [2/2]

template<class Q >
QError QGlobalDataManager::Set ( GlobalHandle< Q > *  gh,
const std::string &  outSource,
bool  printError = true 
) const

◆ SetInputVersion()

void QGlobalDataManager::SetInputVersion ( std::string  versionTag)
inline

set the version tag of the object to be read (default = this release)

Definition at line 166 of file QGlobalDataManager.hh.

References fInputVersion.

Referenced by QSequence::Run().

◆ SetOwner()

void QGlobalDataManager::SetOwner ( const std::string &  owner)
inline

Friends And Related Function Documentation

◆ QBaseModule

friend class QBaseModule
friend

Definition at line 209 of file QGlobalDataManager.hh.

Member Data Documentation

◆ fCacheEnabled

bool QGlobalDataManager::fCacheEnabled
private

cache enabled

Definition at line 195 of file QGlobalDataManager.hh.

Referenced by EnableCache(), Get(), GetCacheEnable(), QGlobalDataManager(), and Set().

◆ fDataMap

std::map<QGlobalLabel, CachedObject> QGlobalDataManager::fDataMap
mutableprivate

cached QObject 's

Definition at line 189 of file QGlobalDataManager.hh.

Referenced by Clear(), Dump(), Get(), GetByLabel(), GetWriteLabels(), and Set().

◆ fDefaultMap

std::map<QGlobalLabel, std::string> QGlobalDataManager::fDefaultMap
mutableprivate

default owners

Definition at line 192 of file QGlobalDataManager.hh.

Referenced by Clear(), Get(), and Set().

◆ fInputVersion

std::string QGlobalDataManager::fInputVersion
private

Version tag of the objects to be read, used to read from the DB. Parameter not accessible to the user in diana, but accesible outside diana.

Definition at line 205 of file QGlobalDataManager.hh.

Referenced by Get(), QGlobalDataManager(), and SetInputVersion().

◆ fInstances

Q_BEGIN_NAMESPACE int QGlobalDataManager::fInstances = 0
staticprivate

number of instances

Definition at line 198 of file QGlobalDataManager.hh.

Referenced by QGlobalDataManager(), and ~QGlobalDataManager().

◆ fOutputVersion

std::string QGlobalDataManager::fOutputVersion
private

Version tag of this release, used to write onto the DB. Parameter not accessible to the user.

Definition at line 201 of file QGlobalDataManager.hh.

Referenced by QGlobalDataManager(), and Set().

◆ fOwner

std::string QGlobalDataManager::fOwner
private

the module that is accessing this object

Definition at line 185 of file QGlobalDataManager.hh.

Referenced by Dump(), Get(), QGlobalDataManager(), Set(), and SetOwner().

◆ fUniqueInstance

QGlobalDataManager * QGlobalDataManager::fUniqueInstance = 0
staticprivate

singleton instance

Definition at line 208 of file QGlobalDataManager.hh.

Referenced by GetInstance().


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