20 #define TSDATASVC_DATASVC_CPP
23 #include "GaudiKernel/IConverter.h"
24 #include "GaudiKernel/IOpaqueAddress.h"
25 #include "GaudiKernel/IConversionSvc.h"
27 #include "GaudiKernel/xtoa.h"
28 #include "GaudiKernel/SvcFactory.h"
29 #include "GaudiKernel/DataObject.h"
30 #include "GaudiKernel/GaudiException.h"
32 #include "GaudiKernel/RegistryEntry.h"
33 #include "GaudiKernel/TsDataSvc.h"
34 #include "GaudiKernel/DataIncident.h"
35 #include "GaudiKernel/IIncidentSvc.h"
46 #define STD_LOCK_GUARD_MACRO std::lock_guard<tsDataSvcMutex> lock(m_accessMutex);
52 inline std::string itemToPath(
int item) {
53 std::ostringstream
path;
64 #define CAST_REGENTRY(x,y) dynamic_cast<x>(y)
68 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
69 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
71 #define DEBMSG ON_DEBUG debug()
72 #define VERMSG ON_VERBOSE verbose()
82 if ( 0 != node_entry ) {
85 parent->
remove(node_entry);
88 return INVALID_PARENT;
90 return INVALID_OBJECT;
107 return INVALID_PARENT;
109 return INVALID_OBJECT;
147 return INVALID_OBJECT;
168 return i_setRoot (std::move(root_path), pRootObj);
178 if ( 0 != pRootObj ) {
194 return i_setRoot (std::move(root_path), pRootAddr);
204 if ( 0 != pRootAddr ) {
215 if ( 0 != pDataLoader ) pDataLoader->
addRef();
217 if ( 0 != pDataLoader ) {
231 return INVALID_OBJECT;
240 refpParent = node_entry->
parent();
243 return INVALID_OBJECT;
250 std::vector<IRegistry*>& leaves) {
255 return INVALID_OBJECT;
262 std::vector<IRegistry*>& leaves) {
267 std::copy(node_entry->
leaves().begin(),node_entry->
leaves().end(),back_inserter(leaves));
271 return INVALID_OBJECT;
279 if ( fullPath.length() > 0 ) {
286 return INVALID_OBJ_PATH;
291 const std::string& objectPath,
299 const std::string& objPath,
302 if ( objPath.length() > 0 ) {
303 if ( 0 == parentObj ) {
307 std::string::size_type sep = objPath.find(
SEPARATOR,1);
308 if ( sep != std::string::npos ) {
309 std::string p_path (objPath, 0, sep);
311 std::string o_path (objPath, sep, objPath.length());
315 return INVALID_PARENT;
324 if ( 0 != par_entry ) {
325 std::string::size_type sep = objPath.rfind(
SEPARATOR);
326 if ( sep > 0 && sep != std::string::npos ) {
327 std::string p_path (objPath, 0, sep);
328 std::string o_path (objPath, sep, objPath.length());
340 p_entry = par_entry->
findLeaf(p_path);
342 if ( 0 != p_entry ) {
345 return INVALID_PARENT;
351 return DOUBL_OBJ_PATH;
353 return INVALID_PARENT;
355 return INVALID_OBJ_PATH;
362 if ( fullPath.length() > 0 ) {
369 return INVALID_OBJ_PATH;
374 const std::string& objPath) {
381 const std::string& objPath) {
383 if ( objPath.length() > 0 ) {
384 if ( 0 == pParent ) {
388 std::string::size_type sep = objPath.find(
SEPARATOR,1);
389 if ( sep != std::string::npos ) {
390 std::string p_path (objPath, 0, sep);
392 std::string o_path (objPath, sep, objPath.length());
396 return INVALID_PARENT;
405 if ( 0 != node_entry ) {
407 if ( 0 != leaf_entry ) {
408 std::string::size_type sep = objPath.rfind(
SEPARATOR);
409 if ( sep > 0 && sep != std::string::npos ) {
410 std::string
path = objPath.substr(sep);
419 return INVALID_PARENT;
421 return INVALID_OBJ_PATH;
435 const std::string& objPath,
468 const std::string& objPath,
471 if ( 0 == parentObj ) {
472 if ( objPath.length() > 0 ) {
474 std::string::size_type sep = objPath.find(
SEPARATOR,1);
475 if ( sep != std::string::npos ) {
476 std::string p_path (objPath, 0, sep);
477 std::string o_path (objPath, sep, objPath.length());
485 return INVALID_OBJ_PATH;
488 if ( 0 != node_entry ) {
490 std::string::size_type sep = objPath.find(
SEPARATOR,1);
491 if ( sep != std::string::npos ) {
492 std::string p_path (objPath, 0, sep);
493 std::string o_path (objPath, sep, objPath.length());
503 par_entry = node_entry->
findLeaf(p_path);
505 else if ( 0 != par_entry && par_entry->object() == 0 ) {
513 par_entry = node_entry->
findLeaf(p_path);
516 node_entry = par_entry;
517 if ( 0 != node_entry ) {
527 status = node_entry->
add( objPath, pObject );
533 error() <<
"registerObject: trying to register null DataObject" <<
endmsg;
544 status = DOUBL_OBJ_PATH;
550 return INVALID_PARENT;
564 if ( 0 != pParent ) {
565 if ( 0 != pObject ) {
571 return INVALID_PARENT;
573 return DIR_NOT_EMPTY;
582 const std::string& objPath) {
604 if ( 0 != entry->
object() ) {
612 return INVALID_PARENT;
614 return DIR_NOT_EMPTY;
616 return INVALID_OBJECT;
623 const std::string& objectPath) {
631 if ( 0 != entry->
object() ) {
637 return DIR_NOT_EMPTY;
639 return INVALID_OBJECT;
644 return INVALID_PARENT;
660 if ( pReg && path.length() == 0 ) {
703 if ( 0 == pLoader ) {
705 else return NO_DATA_LOADER;
707 if ( 0 == pRegistry ) {
709 else return INVALID_OBJ_ADDR;
720 const std::string& ident = pRegistry->
identifier();
721 std::vector<std::string>::iterator inhibit =
728 if ( 0 == pAddress ) {
729 return INVALID_OBJ_ADDR;
732 status = pLoader->
createObj(pAddress, pObject);
733 if ( status.isSuccess() ) {
751 catch(
const std::exception& x) {
766 if ( !status.isSuccess() ) {
772 verbose() <<
"Object " << pRegistry->
identifier() <<
" successfully loaded" <<
endmsg;
779 const std::string&
path,
782 std::string::size_type sep = path.find(
SEPARATOR,1);
787 if ( 0 == parentObj ) {
788 if ( path.length() == 0 || path ==
m_rootName ) {
794 else if ( sep != std::string::npos ) {
802 std::string o_path (path, sep, path.length());
805 return INVALID_OBJ_PATH;
807 if ( sep != std::string::npos ) {
808 std::string p_path (path,0,sep);
809 std::string o_path (path,sep,path.length());
810 if (!parentObj->
object()) {
821 root_entry = parentObj->
findLeaf(p_path);
832 if ( root_entry->
isSoft() ) {
839 else if ( path.length() == 0 ) {
843 if (!parentObj->
object()) {
854 pEntry = (0==path.length()) ? parentObj : parentObj->
findLeaf(path);
859 status = INVALID_OBJ_PATH;
861 else if ( 0 == pEntry->
object() ) {
882 const std::string&
path,
889 pObject = result->
object();
903 const std::string& objectPath,
922 const std::string&
path,
937 const std::string&
path,
943 if ( 0 != root_entry ) {
944 if ( path.length() > 0 ) {
945 pReg = root_entry->
find(path);
948 return INVALID_OBJ_PATH;
952 return (0 == pObject) ? OBJ_NOT_LOADED : IDataProviderSvc_NO_ERROR;
961 if ( path.length() == 0 || path ==
m_rootName ) {
963 return (0 == pObject) ? OBJ_NOT_LOADED : IDataProviderSvc_NO_ERROR;
975 const std::string& objectPath,
980 status =
findObject (parent, objectPath, pObject);
988 return findObject(parentPath, itemToPath(item), pObject);
995 return findObject(parentObj, itemToPath(item), pObject);
1000 const std::string&
path,
1018 if ( 0 == pRegistry ) {
1019 return INVALID_OBJ_ADDR;
1022 if ( 0 == toUpdate ) {
1032 if ( 0 == toUpdate ) {
1033 return INVALID_OBJECT;
1036 if ( 0 == pRegistry ) {
1037 return INVALID_OBJECT;
1040 if ( 0 == pAddress ) {
1041 return INVALID_OBJ_ADDR;
1044 if ( 0 == pLoader ) {
1045 return NO_DATA_LOADER;
1048 const std::string& ident = pRegistry->
identifier();
1049 std::vector<std::string>::iterator inhibit =
1056 status = pLoader->
updateObj(pAddress, toUpdate);
1057 if ( status.isSuccess() ) {
1067 catch(
const std::exception& x) {
1069 pRegistry->
name() +
": " +
1084 const std::string& updatePath) {
1095 const std::string& updatePath) {
1106 const std::string& objPath,
DataObject* to) {
1111 if ( 0 != from_entry ) {
1114 if ( 0 == to_entry ) {
1115 return INVALID_OBJECT;
1118 std::string::size_type sep = objPath.rfind(
SEPARATOR);
1119 if ( sep > 0 && sep != std::string::npos ) {
1121 std::string fromPath(objPath, 0, sep);
1124 std::string toPath(objPath, sep, objPath.length());
1132 IDataProviderSvc_NO_ERROR : DOUBL_OBJ_PATH;
1138 return INVALID_PARENT;
1140 return INVALID_ROOT;
1147 if ( fullPath.length() > 0 ) {
1151 std::string::size_type sep = fullPath.rfind(
SEPARATOR);
1152 std::string objPath(fullPath, sep, fullPath.length());
1153 std::string fromPath(fullPath, 0, sep);
1156 return INVALID_OBJ_PATH;
1161 const std::string& objPath,
1167 return linkObject(pO->registry(), objPath, to);
1174 const std::string& objPath,
1179 if ( 0 != from_entry ) {
1183 return INVALID_PARENT;
1188 const std::string& objPath) {
1193 if ( 0 != from_entry ) {
1194 std::string::size_type sep = objPath.rfind(
SEPARATOR);
1195 if ( sep > 0 && sep != std::string::npos ) {
1197 std::string fromPath(objPath, 0, sep);
1200 std::string toPath(objPath, sep, objPath.length());
1209 return INVALID_OBJ_PATH;
1214 return INVALID_PARENT;
1216 return INVALID_ROOT;
1221 if ( fullPath.length() > 0 ) {
1225 std::string::size_type sep = fullPath.rfind(
SEPARATOR);
1226 std::string objPath(fullPath, sep, fullPath.length());
1227 std::string fromPath(fullPath, 0, sep);
1230 return INVALID_OBJ_PATH;
1235 const std::string& objPath) {
1246 const std::string& objPath) {
1251 return INVALID_ROOT;
1270 LoadItems::iterator
i =
1292 if ( 0 != pObject && depth++ < load_depth ) {
1298 if ( status.
isSuccess() && depth < load_depth ) {
1312 int load_depth = (*i).depth();
1313 if ( sc.
isSuccess() && load_depth > 1 ) {
1329 error() <<
"Failed to access incident service." <<
endmsg;
1348 error() <<
"Unable to reinitialize base class" <<
endmsg;
1354 error() <<
"Failed to access incident service." <<
endmsg;
1399 m_rootName(
"/Event"), m_root(0)
StatusCode unregisterAddress(const std::string &fullPath) override
IDataManagerSvc: Unregister object address from the data store.
StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject) override
Retrieve object from data store.
StatusCode initialize() override
RegistryEntry * findLeaf(boost::string_ref path) const
Find identified leaf in this registry node.
Define general base for Gaudi exception.
StatusCode unlinkObject(IRegistry *from, const std::string &objPath) override
Remove a link to another object.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)=0
Create the transient representation of an object.
StatusCode setRoot(std::string root_name, DataObject *pRootObj) override
Initialize data store for new event by giving new event path and root object.
StatusCode finalize() override
StatusCode addPreLoadItem(const DataStoreItem &item) override
Add an item to the preload list.
StatusCode traverseTree(IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects in the data store.
bool isSuccess() const
Test for a status code of SUCCESS.
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
DataSvcHelpers::RegistryEntry * m_root
Pointer to root entry.
virtual long add(const std::string &name, DataObject *pObject, bool is_soft=false)
Add entry to data store.
virtual long traverseTree(IDataStoreAgent *pAgent, int level=0)
traverse data tree
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
std::string m_rootName
Name of root event.
bool m_enableAccessHdlr
Flag to enable interrupts on data access requests.
virtual ~TsDataSvc()
Standard Destructor.
void setRegistry(IRegistry *pRegistry)
Set pointer to Registry.
unsigned long release() override
IInterface implementation: Reference the object.
virtual const name_type & name() const =0
Name of the directory (or key)
StatusCode initialize() override
Service initialization.
StatusCode removePreLoadItem(const DataStoreItem &item) override
Remove an item from the preload list.
virtual IConversionSvc * getDataLoader(IRegistry *pReg)
Retrieve customizable data loader according to registry entry to be retrieved.
virtual long remove(const std::string &name)
Remove an entry from the store.
const Store & leaves() const
Access the leaves of the object.
Data provider interface definition.
void setAddress(IOpaqueAddress *pAddress) override
Set/Update Opaque address.
Description of the DataStoreItem class.
bool m_enableFaultHdlr
Flag to enable interrupts on data creation requests.
IRegistry * registry() const
Get pointer to Registry.
virtual StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *refpObject)=0
Update the transient object from the other representation.
StatusCode resetPreLoad() override
Clear the preload list.
virtual RegistryEntry * parentEntry()
Pointer to parent registry entry.
std::string m_accessName
Name of the data access incident.
virtual bool isSoft() const
Is the link soft or hard.
StatusCode linkObject(IRegistry *from, const std::string &objPath, DataObject *to) override
Add a link to another object.
IIncidentSvc * m_incidentSvc
Pointer to incident service.
virtual unsigned long addRef()
Add reference to object.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
void setObject(DataObject *obj)
Set/Update object address.
StatusCode preLoad() override
load all preload items of the list
IConversionSvc * m_dataLoader
Pointer to data loader service.
CLID rootCLID() const override
IDataManagerSvc: Accessor for root event CLID.
StatusCode traverseSubTree(const std::string &sub_tree_path, IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects below the sub tree identified by its full pat...
bool m_forceLeaves
Allow forced creation of default leaves on registerObject.
virtual Iterator begin() const
Return starting point for container iteration.
This class is used for returning status codes from appropriate routines.
LoadItems m_preLoads
Items to be pre-loaded.
DataSvcHelpers::InhibitMap * m_inhibitMap
Map with object paths to be inhibited from loading.
virtual StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Update the references of an updated transient object.
DataSvcHelpers::RegistryEntry RegEntry
const std::string & rootName() const override
IDataManagerSvc: Accessor for root event name.
void setDataSvc(IDataProviderSvc *s)
Set the transient data store.
StatusCode reinitialize() override
Service initialization.
StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves) override
IDataManagerSvc: Explore the object store: retrieve all leaves attached to the object.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
std::string m_faultName
Name of the data fault incident.
const std::string & identifier() const override
Full identifier (or key)
virtual bool isEmpty() const
Simple check if the Container is empty.
StatusCode reinitialize() override
Store::const_iterator Iterator
Iterator definition.
DataObject * handleDataFault(IRegistry *pReg, const std::string &path="")
Invoke data fault handling if enabled.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
virtual DataObject * object() const =0
Retrieve object behind the link.
Definition of an entry in the transient data store.
virtual unsigned long release()
release reference to object
virtual DataObject * createDefaultObject() const
Create default objects in case forced creation of leaves is requested.
DataObject * object() const override
Retrive object behind the link.
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Resolve the references of the created transient object.
StatusCode registerObject(const std::string &fullPath, DataObject *pObject) override
Register object with the data store.
StatusCode clearSubTree(const std::string &sub_tree_path) override
IDataManagerSvc: Remove all data objects below the sub tree identified by its full path name...
StatusCode setDataLoader(IConversionSvc *svc, IDataProviderSvc *dpsvc=0) override
IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the service and optionally a data pro...
virtual unsigned long release()=0
Release Interface instance.
StatusCode finalize() override
Service initialization.
virtual IRegistry * parent() const
Pointer to parent directory entry.
Generic data agent interface.
StatusCode registerAddress(const std::string &fullPath, IOpaqueAddress *pAddress) override
IDataManagerSvc: Register object address with the data store.
Base class used to extend a class implementing other interfaces.
virtual StatusCode i_setRoot(std::string root_name, DataObject *pRootObj)
Initialize data store for new event by giving new event path and root object.
const std::string & name() const
Retreive DataObject name. It is the name when registered in the store.
bool checkRoot()
Check if root path is valid.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
virtual const id_type & identifier() const =0
Full identifier (or key)
StatusCode clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
Data service incident class.
StatusCode unregisterObject(const std::string &fullPath) override
Unregister object from the data store.
Opaque address interface definition.
unsigned int CLID
Class ID definition.
CLID m_rootCLID
Integer Property corresponding to CLID of root entry.
TsDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
std::vector< std::string > m_inhibitPathes
Property for the inhibited leaves.
A DataObject is the base class of any identifiable object on any data store.
#define STD_LOCK_GUARD_MACRO
#define CAST_REGENTRY(x, y)
virtual StatusCode loadObject(IRegistry *pNode)
Invoke Persistency service to create transient object from its persistent representation.
StatusCode findObject(const std::string &fullPath, DataObject *&pObject) override
Find object identified by its full path in the data store.
StatusCode objectParent(const DataObject *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
virtual IRegistry * find(const IRegistry *obj) const
Try to find an object identified by its pointer.
virtual Iterator end() const
Return end elemtn if the container.
StatusCode retrieveEntry(DataSvcHelpers::RegistryEntry *pNode, const std::string &path, DataSvcHelpers::RegistryEntry *&pEntry)
Retrieve registry entry from store.
void makeHard(DataObject *pObject)
Initialize link as hard link.