19 #define DATASVC_DATASVC_CPP
22 #include "GaudiKernel/IConverter.h"
23 #include "GaudiKernel/IOpaqueAddress.h"
24 #include "GaudiKernel/IConversionSvc.h"
26 #include "GaudiKernel/DataObject.h"
27 #include "GaudiKernel/GaudiException.h"
29 #include "GaudiKernel/RegistryEntry.h"
30 #include "GaudiKernel/DataSvc.h"
31 #include "GaudiKernel/DataIncident.h"
32 #include "GaudiKernel/IIncidentSvc.h"
41 #include "boost/utility/string_ref.hpp"
47 inline std::string itemToPath(
int item) {
51 inline boost::string_ref::size_type find( boost::string_ref
s,
char c,
size_t o ) {
52 if (!s.empty()) s.remove_prefix(o);
54 return r==boost::string_ref::npos ? r : ( r + o ) ;
63 #define CAST_REGENTRY(x,y) dynamic_cast<x>(y)
67 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
68 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
70 #define DEBMSG ON_DEBUG debug()
71 #define VERMSG ON_VERBOSE verbose()
84 parent->
remove(node_entry);
87 return INVALID_PARENT;
89 return INVALID_OBJECT;
106 return INVALID_PARENT;
108 return INVALID_OBJECT;
139 if ( !entry )
return INVALID_OBJECT;
156 return i_setRoot (std::move(root_path), pRootObj);
182 return i_setRoot (std::move(root_path), pRootAddr);
211 if ( !pObject )
return INVALID_OBJECT;
219 if ( !node_entry )
return INVALID_OBJECT;
220 refpParent = node_entry->
parent();
226 std::vector<IRegistry*>& leaves) {
227 if ( !pObject )
return INVALID_OBJECT;
235 std::vector<IRegistry*>& leaves) {
238 if ( !node_entry )
return INVALID_OBJECT;
239 leaves = node_entry->
leaves();
246 if ( fullPath.empty() )
return INVALID_OBJ_PATH;
253 const std::string& objectPath,
261 const std::string& objPath,
264 if ( objPath.empty() )
return INVALID_OBJ_PATH;
270 std::string::size_type sep = objPath.find(
SEPARATOR,1);
271 if ( sep == std::string::npos ) {
272 return INVALID_PARENT;
274 if ( objPath.compare(0,sep,
m_rootName) == 0 ) {
282 if ( !par_entry )
return INVALID_PARENT;
284 std::string::size_type sep = objPath.rfind(
SEPARATOR);
285 if ( sep > 0 && sep != std::string::npos ) {
286 auto p_path = objPath.substr( 0, sep);
287 auto o_path = objPath.substr( sep );
297 p_entry = par_entry->
findLeaf(p_path);
299 if ( !p_entry )
return INVALID_PARENT;
303 return status.
isSuccess() ? status : DOUBL_OBJ_PATH;
308 if ( fullPath.empty() )
return INVALID_OBJ_PATH;
315 const std::string& objPath) {
322 const std::string& objPath) {
324 if ( objPath.empty() )
return INVALID_OBJ_PATH;
330 std::string::size_type sep = objPath.find(
SEPARATOR,1);
331 if ( sep != std::string::npos &&
335 return INVALID_PARENT;
344 std::string::size_type sep = objPath.rfind(
SEPARATOR);
345 if ( sep > 0 && sep != std::string::npos ) {
352 return INVALID_PARENT;
364 const std::string& objPath,
393 const std::string& objPath,
398 if ( !objPath.empty() ) {
401 if ( sep != std::string::npos ) {
402 return registerObject(objPath.substr( 0, sep), objPath.substr( sep ), pObject);
408 return INVALID_OBJ_PATH;
414 if ( sep != std::string::npos ) {
415 auto p_path = objPath.substr( 0, sep );
416 auto o_path = objPath.substr( sep );
424 par_entry = node_entry->
findLeaf(p_path);
426 else if ( par_entry && !par_entry->
object() ) {
432 par_entry = node_entry->
findLeaf(p_path);
435 node_entry = par_entry;
446 status = node_entry->
add( objPath, pObject );
452 error() <<
"registerObject: trying to register null DataObject" <<
endmsg;
461 status = DOUBL_OBJ_PATH;
467 return INVALID_PARENT;
476 if ( !pEntry )
return INVALID_ROOT;
477 if ( !pEntry->
isEmpty() )
return DIR_NOT_EMPTY;
479 if ( !pParent )
return INVALID_PARENT;
480 if ( pObject ) pObject->
addRef();
487 const std::string& objPath) {
502 if ( !entry )
return INVALID_OBJECT;
504 if ( !parent )
return INVALID_PARENT;
505 if ( !entry->
isEmpty() )
return DIR_NOT_EMPTY;
507 if ( parent ) parent->
remove(entry);
513 const std::string& objectPath) {
527 return DIR_NOT_EMPTY;
529 return INVALID_OBJECT;
534 return INVALID_PARENT;
554 if ( pReg && path.empty() ) {
562 p.append(path.data(),path.size());
569 p.append(path.data(),path.size());
618 return INVALID_OBJ_ADDR;
621 status = pLoader->
createObj(pAddress, pObject);
640 catch(
const std::exception& x) {
661 verbose() <<
"Object " << pRegistry->
identifier() <<
" successfully loaded" <<
endmsg;
668 const std::string&
path,
674 boost::string_ref
path,
679 static const auto empty = boost::string_ref{};
687 }
else if ( path.front() !=
SEPARATOR ) {
689 }
else if ( sep != boost::string_ref::npos ) {
693 if ( !status.isSuccess() )
return status;
696 path = path.substr(sep);
698 return INVALID_OBJ_PATH;
704 if ( sep != boost::string_ref::npos ) {
705 if (!parentObj->
object()) {
707 if ( !status.
isSuccess() )
return status;
709 auto p_path = path.substr(0,sep);
715 root_entry = parentObj->
findLeaf(p_path);
722 if ( !status.
isSuccess() )
return status;
724 if ( root_entry->
isSoft() ) {
730 }
else if ( path.empty() ) {
733 if (!parentObj->
object()) {
735 if ( !status.
isSuccess() )
return status;
742 pEntry = (path.empty() ? parentObj : parentObj->
findLeaf(path) );
747 if ( !pEntry )
return INVALID_OBJ_PATH;
764 const std::string&
path,
782 const std::string& objectPath,
799 const std::string&
path,
814 const std::string&
path,
820 if ( !path.empty() ) pReg = root_entry->
find(path);
821 if ( !pReg )
return INVALID_OBJ_PATH;
824 return (!pObject) ? OBJ_NOT_LOADED : IDataProviderSvc_NO_ERROR;
834 return !pObject ? OBJ_NOT_LOADED : IDataProviderSvc_NO_ERROR;
846 const std::string& objectPath,
857 return findObject(parentPath, itemToPath(item), pObject);
864 return findObject(parentObj, itemToPath(item), pObject);
869 const std::string&
path,
886 return INVALID_OBJ_ADDR;
899 return INVALID_OBJECT;
903 return INVALID_OBJECT;
907 return INVALID_OBJ_ADDR;
911 return NO_DATA_LOADER;
921 status = pLoader->
updateObj(pAddress, toUpdate);
932 catch(
const std::exception& x) {
934 pRegistry->
name() +
": " +
949 const std::string& updatePath) {
958 const std::string& updatePath) {
975 return INVALID_OBJECT;
977 std::string::size_type sep = objPath.rfind(
SEPARATOR);
978 if ( sep > 0 && sep != std::string::npos ) {
988 return status.
isSuccess() ? IDataProviderSvc_NO_ERROR : DOUBL_OBJ_PATH;
993 return INVALID_PARENT;
1001 if ( !fullPath.empty() ) {
1006 return linkObject( fullPath.substr( 0, sep), fullPath.substr(sep), to);
1008 return INVALID_OBJ_PATH;
1013 const std::string& objPath,
1023 const std::string& objPath,
1031 return INVALID_PARENT;
1036 const std::string& objPath) {
1041 std::string::size_type sep = objPath.rfind(
SEPARATOR);
1042 if ( sep > 0 && sep != std::string::npos ) {
1051 if ( status.
isSuccess() )
return status;
1052 return INVALID_OBJ_PATH;
1057 return INVALID_PARENT;
1059 return INVALID_ROOT;
1064 if ( fullPath.empty() )
return INVALID_OBJ_PATH;
1069 return unlinkObject(fullPath.substr(0,sep), fullPath.substr(sep));
1074 const std::string& objPath) {
1083 const std::string& objPath) {
1084 if ( !
checkRoot() )
return INVALID_ROOT;
1124 if ( pObject && depth++ < load_depth ) {
1127 for (
const auto&
i : *dir) {
1130 if ( status.
isSuccess() && depth < load_depth ) {
1144 int load_depth =
i.depth();
1145 if ( sc.
isSuccess() && load_depth > 1 ) {
1159 error() <<
"Failed to access incident service." <<
endmsg;
1174 error() <<
"Unable to reinitialize base class" <<
endmsg;
1180 error() <<
"Failed to access incident service." <<
endmsg;
StatusCode unregisterObject(const std::string &fullPath) override
Unregister object from the data store.
StatusCode addPreLoadItem(const DataStoreItem &item) override
Add an item to the preload list.
StatusCode initialize() override
bool m_enableAccessHdlr
Flag to enable interrupts on data access requests.
string to_string(const T &value)
DataSvcHelpers::RegistryEntry * m_root
Pointer to root entry.
RegistryEntry * findLeaf(boost::string_ref path) const
Find identified leaf in this registry node.
~DataSvc() override
Standard Destructor.
Define general base for Gaudi exception.
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.
StatusCode preLoad() override
load all preload items of the list
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)=0
Create the transient representation of an object.
StatusCode finalize() override
bool m_enableFaultHdlr
Flag to enable interrupts on data creation requests.
bool isSuccess() const
Test for a status code of SUCCESS.
auto begin(reverse_wrapper< T > &w)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
StatusCode setRoot(std::string root_name, DataObject *pRootObj) override
Initialize data store for new event by giving new event path and root object.
StatusCode setDataLoader(IConversionSvc *svc, IDataProviderSvc *dpsvc=nullptr) override
IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the service and optionally a data pro...
virtual long add(const std::string &name, DataObject *pObject, bool is_soft=false)
Add entry to data store.
std::string m_rootName
Name of root event.
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to incident service.
virtual long traverseTree(IDataStoreAgent *pAgent, int level=0)
traverse data tree
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
virtual StatusCode loadObject(IRegistry *pNode)
Invoke Persistency service to create transient object from its persistent representation.
LoadItems m_preLoads
Items to be pre-loaded.
std::string m_accessName
Name of the data access incident.
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)
SmartIF< IConversionSvc > m_dataLoader
Pointer to data loader service.
StatusCode traverseTree(IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects in the data store.
DataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
bool checkRoot()
Check if root path is valid.
DataObject * i_handleDataFault(IRegistry *pReg, boost::string_ref path=boost::string_ref{})
StatusCode removePreLoadItem(const DataStoreItem &item) override
Remove an item from the preload list.
virtual long remove(const std::string &name)
Remove an entry from the store.
const Store & leaves() const
Access the leaves of the object.
StatusCode registerObject(const std::string &fullPath, DataObject *pObject) override
Register object with the data store.
Data provider interface definition.
void setAddress(IOpaqueAddress *pAddress) override
Set/Update Opaque address.
Description of the DataStoreItem class.
StatusCode registerAddress(const std::string &fullPath, IOpaqueAddress *pAddress) override
IDataManagerSvc: Register object address with the data store.
std::vector< std::string > m_inhibitPathes
Property for the inhibited leaves.
bool isFailure() const
Test for a status code of FAILURE.
IRegistry * registry() const
Get pointer to Registry.
virtual StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *refpObject)=0
Update the transient object from the other representation.
virtual RegistryEntry * parentEntry()
Pointer to parent registry entry.
TYPE * get() const
Get interface pointer.
virtual bool isSoft() const
Is the link soft or hard.
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 i_retrieveEntry(DataSvcHelpers::RegistryEntry *parentObj, boost::string_ref path, DataSvcHelpers::RegistryEntry *&pEntry)
IOpaqueAddress * address() const override
Retrieve opaque storage address.
auto end(reverse_wrapper< T > &w)
This class is used for returning status codes from appropriate routines.
StatusCode retrieveEntry(DataSvcHelpers::RegistryEntry *pNode, const std::string &path, DataSvcHelpers::RegistryEntry *&pEntry)
Retrieve registry entry from store.
virtual StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Update the references of an updated transient object.
StatusCode findObject(const std::string &fullPath, DataObject *&pObject) override
Find object identified by its full path in the data store.
StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves) override
IDataManagerSvc: Explore the object store: retrieve all leaves attached to the object.
void setDataSvc(IDataProviderSvc *s)
Set the transient data store.
StatusCode unregisterAddress(const std::string &fullPath) override
IDataManagerSvc: Unregister object address from the data store.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
const std::string & identifier() const override
Full identifier (or key)
StatusCode finalize() override
Service initialization.
virtual bool isEmpty() const
Simple check if the Container is empty.
StatusCode reinitialize() override
StatusCode clearSubTree(const std::string &sub_tree_path) override
IDataManagerSvc: Remove all data objects below the sub tree identified by its full path name...
CLID rootCLID() const override
IDataManagerSvc: Accessor for root event CLID.
StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject) override
Retrieve object from data store.
bool m_forceLeaves
Allow forced creation of default leaves on registerObject.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
virtual DataObject * object() const =0
Retrieve object behind the link.
StatusCode linkObject(IRegistry *from, const std::string &objPath, DataObject *to) override
Add a link to another object.
#define CAST_REGENTRY(x, y)
Definition of an entry in the transient data store.
virtual unsigned long release()
release reference to object
std::string m_faultName
Name of the data fault incident.
virtual StatusCode i_setRoot(std::string root_name, DataObject *pRootObj)
Initialize data store for new event by giving new event path and root object.
DataObject * handleDataFault(IRegistry *pReg, const std::string &path="")
Invoke data fault handling if enabled.
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 reinitialize() override
Service initialization.
virtual IRegistry * parent() const
Pointer to parent directory entry.
Generic data agent interface.
Base class used to extend a class implementing other interfaces.
StatusCode initialize() override
Service initialization.
StatusCode unlinkObject(IRegistry *from, const std::string &objPath) override
Remove a link to another object.
CLID m_rootCLID
Integer Property corresponding to CLID of root entry.
StatusCode objectParent(const DataObject *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
virtual const id_type & identifier() const =0
Full identifier (or key)
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Data service incident class.
Opaque address interface definition.
unsigned int CLID
Class ID definition.
virtual IConversionSvc * getDataLoader(IRegistry *pReg)
Retrieve customizable data loader according to registry entry to be retrieved.
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...
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
A DataObject is the base class of any identifiable object on any data store.
StatusCode resetPreLoad() override
Clear the preload list.
virtual DataObject * createDefaultObject() const
Create default objects in case forced creation of leaves is requested.
virtual IRegistry * find(const IRegistry *obj) const
Try to find an object identified by its pointer.
StatusCode clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
DataSvcHelpers::RegistryEntry RegEntry
const std::string & rootName() const override
IDataManagerSvc: Accessor for root event name.
void makeHard(DataObject *pObject)
Initialize link as hard link.