1 #ifndef _Q_GLOBALDATAMANAGER_HH_
2 #define _Q_GLOBALDATAMANAGER_HH_
78 template<
class Q>
QError Get(
const std::string& owner,
GlobalHandle<Q> * gh,
const std::string& inSource,
bool printError=
true)
const;
104 template<
class Q>
const Q&
Get(
const std::string& owner,
const std::string& name,
const std::string& inSource)
const
107 Get(owner, &gd, inSource);
118 template<
class Q>
const Q&
Get(
const std::string& name,
const std::string& inSource)
const
149 template<
class Q>
QError Set(
const std::string& name,
const Q& obj,
const std::string& outSource)
const
153 return Set(&gd,outSource);
172 void Dump(std::ostream& o)
const;
189 mutable std::map<QGlobalLabel, CachedObject>
fDataMap;
217 return Get(bgh->
GetOwner(),bgh,inSource, printError);
226 std::map<QGlobalLabel,std::string>::const_iterator idef =
fDefaultMap.find(label);
238 std::map<QGlobalLabel, CachedObject>::const_iterator iter =
fDataMap.find(label);
243 bool cacheError =
true;
244 cacheError = cacheError && inSource !=
"" && inSource != iter->second.source && iter->second.object;
245 cacheError = cacheError && bgh->
GetVersion() != iter->second.version;
247 std::stringstream msg;
248 msg<<
"Cannot get object "<<std::string(label)<<
" from \""<<inSource
250 <<
"\") since it is in cache with another source: \""<<iter->second.source
251 <<
"\"(Version=\""<<iter->second.version
252 <<
"\"). If outside diana, you may consider to disable the cache [see QGlobalDataManager::EnableCache()]";
255 err.SetDescription(msg.str());
258 *addr =
dynamic_cast<Q*
>(iter->second.object);
263 err.SetDescription(
"Object not found");
265 if(inSource ==
"DB") {
267 }
else if(!inSource.empty()) {
271 if(*addr) (*addr)->InValidate();
285 fDataMap[label].object = (*addr)->Duplicate();
286 (*addr)->FullyFill(
fDataMap[label].
object);
287 (*addr) = (Q*)
fDataMap[label].
object;
295 std::stringstream msg;
296 msg<<
"Setting default owner \""<<bgh->
GetOwner()<<
"\" ";
313 err.SetDescription(
"QGlobalDataManager::Set(): Unable to Set object, since no owner has been specified (if you are using this class outside diana, set the object owner with QGlobalDataManager::SetOwner())");
325 std::map<QGlobalLabel, CachedObject>::const_iterator iter =
fDataMap.find(label);
331 std::map<QGlobalLabel, CachedObject>::iterator iter2 =
fDataMap.find(label);
334 if(!iter2->second.object) iter2->second.object = (*addr)->Duplicate();
335 if((*addr) != (iter2->second.object))
336 (*addr)->FullyFill(iter2->second.object);
338 if(iter2->second.object) iter2->second.object->Reset();
343 if(outSource ==
"DB") {
345 }
else if(!outSource.empty()){
357 std::stringstream msg;
358 msg<<
"Setting default owner \""<<bgh->
GetOwner()<<
"\" ";
#define Q_BEGIN_NAMESPACE
template class to handle diana global QObject with QGlobalDataManager
virtual QError FillFromFile(const std::string &fname)
fill QObject from file fname
bool IsValid() const
check QObject validity
virtual QError StoreOnDB() const
store object on DB
virtual QError StoreOnFile(const std::string &fname) const
store object on file fname
const QGlobalLabel & GetLabel() const
Get label.
Q ** GetAddress()
get object address
void SetOwner(const std::string &owner)
set object owner
std::string GetVersion() const
Get version tag of the object, if any.
const std::string & GetOwner() const
Get object owner.
QError fGlobalDataManagerError
I/O error from the QGlobalDataManager.
const std::string & GetDefaultOwner() const
Get default owner (may be set by inheriting classes)
void Set(const Q &obj)
set the QObject
virtual QError FillFromDB()
fill object from DB
const Q & Get() const
get the QObject
void SetVersion(const std::string &tag)
set version tag of the object to be read (used by QGlobalDataManager)
error class with error type and description
Object to manage I/O (DB, file, or memory) of diana global quantities.
std::vector< QGlobalLabel > GetWriteLabels() const
get labels
static QGlobalDataManager & GetInstance(const std::string &owner="")
singleton interface provided for use in non diana executables. Do not use it within diana or root mac...
std::string fOutputVersion
Version tag of this release, used to write onto the DB. Parameter not accessible to the user.
bool fCacheEnabled
cache enabled
bool GetCacheEnable() const
~QGlobalDataManager()
dtor
std::string fOwner
the module that is accessing this object
QError Set(const std::string &name, const Q &obj, const std::string &outSource) const
Set a QObject of type Q.
static QGlobalDataManager * fUniqueInstance
singleton instance
std::string fInputVersion
Version tag of the objects to be read, used to read from the DB. Parameter not accessible to the user...
void SetOwner(const std::string &owner)
set the module that is accessing this object
void EnableCache(const bool enable)
enable / disable caching of objects
std::map< QGlobalLabel, CachedObject > fDataMap
cached QObject 's
void SetInputVersion(std::string versionTag)
set the version tag of the object to be read (default = this release)
QError Set(GlobalHandle< Q > *gh, const std::string &outSource, bool printError=true) const
Set a QObject using a GlobalHandle.
QError Get(const std::string &owner, GlobalHandle< Q > *gh, const std::string &inSource, bool printError=true) const
Get an object using a global handle.
const Q & Get(const std::string &owner, const std::string &name, const std::string &inSource) const
Get a QObject of type Q.
void Dump(std::ostream &o) const
Dump cached objects to stream.
QGlobalDataManager()
constructor
std::map< QGlobalLabel, std::string > fDefaultMap
default owners
const QObject * GetByLabel(const QGlobalLabel &) const
get object by label (not-recommended). Works only on cached object's
static int fInstances
number of instances
const Q & Get(const std::string &name, const std::string &inSource) const
Get a QObject of type Q owned by the caller module.
Label for global QObject's.
std::string fOwner
Object owner.
std::string GetStringLabel() const
convert label to string
static void Debug(const std::string &sender, const std::string &msg)
static void Error(const std::string &sender, const std::string &msg)
base class for objects handled by QEvent and QGlobalDataManager.
store source of cached objects