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) {
48 return '/' + std::to_string(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 ( 0 != par_entry && par_entry->
object() == 0 ) {
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;
463 status = DOUBL_OBJ_PATH;
469 return INVALID_PARENT;
478 if ( !pEntry )
return INVALID_ROOT;
479 if ( !pEntry->
isEmpty() )
return DIR_NOT_EMPTY;
481 if ( !pParent )
return INVALID_PARENT;
482 if ( pObject ) pObject->
addRef();
489 const std::string& objPath) {
504 if ( !entry )
return INVALID_OBJECT;
506 if ( !parent )
return INVALID_PARENT;
507 if ( !entry->
isEmpty() )
return DIR_NOT_EMPTY;
509 if ( parent ) parent->
remove(entry);
515 const std::string& objectPath) {
529 return DIR_NOT_EMPTY;
531 return INVALID_OBJECT;
536 return INVALID_PARENT;
556 if ( pReg && path.empty() ) {
564 p.append(path.data(),path.size());
572 p.append(path.data(),path.size());
600 else return NO_DATA_LOADER;
604 else return INVALID_OBJ_ADDR;
623 return INVALID_OBJ_ADDR;
626 status = pLoader->
createObj(pAddress, pObject);
645 catch(
const std::exception& x) {
666 verbose() <<
"Object " << pRegistry->
identifier() <<
" successfully loaded" <<
endmsg;
673 const std::string&
path,
679 boost::string_ref
path,
684 static const auto empty = boost::string_ref{};
692 }
else if ( path.front() !=
SEPARATOR ) {
694 }
else if ( sep != boost::string_ref::npos ) {
698 if ( !status.isSuccess() )
return status;
701 path = path.substr(sep);
703 return INVALID_OBJ_PATH;
709 if ( sep != boost::string_ref::npos ) {
710 if (!parentObj->
object()) {
712 if ( !status.
isSuccess() )
return status;
714 auto p_path = path.substr(0,sep);
720 root_entry = parentObj->
findLeaf(p_path);
727 if ( !status.
isSuccess() )
return status;
729 if ( root_entry->
isSoft() ) {
735 }
else if ( path.empty() ) {
738 if (!parentObj->
object()) {
740 if ( !status.
isSuccess() )
return status;
747 pEntry = (path.empty() ? parentObj : parentObj->
findLeaf(path) );
752 if ( !pEntry )
return INVALID_OBJ_PATH;
769 const std::string&
path,
787 const std::string& objectPath,
804 const std::string&
path,
819 const std::string&
path,
825 if ( !path.empty() ) pReg = root_entry->
find(path);
826 if ( !pReg )
return INVALID_OBJ_PATH;
829 return (!pObject) ? OBJ_NOT_LOADED : IDataProviderSvc_NO_ERROR;
839 return !pObject ? OBJ_NOT_LOADED : IDataProviderSvc_NO_ERROR;
851 const std::string& objectPath,
862 return findObject(parentPath, itemToPath(item), pObject);
869 return findObject(parentObj, itemToPath(item), pObject);
874 const std::string&
path,
891 return INVALID_OBJ_ADDR;
904 return INVALID_OBJECT;
908 return INVALID_OBJECT;
912 return INVALID_OBJ_ADDR;
916 return NO_DATA_LOADER;
926 status = pLoader->
updateObj(pAddress, toUpdate);
937 catch(
const std::exception& x) {
939 pRegistry->
name() +
": " +
954 const std::string& updatePath) {
963 const std::string& updatePath) {
980 return INVALID_OBJECT;
983 std::string::size_type sep = objPath.rfind(
SEPARATOR);
984 if ( sep > 0 && sep != std::string::npos ) {
995 IDataProviderSvc_NO_ERROR : DOUBL_OBJ_PATH;
1001 return INVALID_PARENT;
1003 return INVALID_ROOT;
1009 if ( !fullPath.empty() ) {
1014 return linkObject( fullPath.substr( 0, sep), fullPath.substr(sep), to);
1016 return INVALID_OBJ_PATH;
1021 const std::string& objPath,
1031 const std::string& objPath,
1039 return INVALID_PARENT;
1044 const std::string& objPath) {
1049 std::string::size_type sep = objPath.rfind(
SEPARATOR);
1050 if ( sep > 0 && sep != std::string::npos ) {
1059 if ( status.
isSuccess() )
return status;
1060 return INVALID_OBJ_PATH;
1065 return INVALID_PARENT;
1067 return INVALID_ROOT;
1072 if ( fullPath.empty() )
return INVALID_OBJ_PATH;
1077 return unlinkObject(fullPath.substr(0,sep), fullPath.substr(sep));
1082 const std::string& objPath) {
1091 const std::string& objPath) {
1092 if ( !
checkRoot() )
return INVALID_ROOT;
1132 if ( pObject && depth++ < load_depth ) {
1135 for (
const auto&
i : *dir) {
1138 if ( status.
isSuccess() && depth < load_depth ) {
1152 int load_depth =
i.depth();
1153 if ( sc.
isSuccess() && load_depth > 1 ) {
1167 error() <<
"Failed to access incident service." <<
endmsg;
1182 error() <<
"Unable to reinitialize base class" <<
endmsg;
1188 error() <<
"Failed to access incident service." <<
endmsg;
StatusCode unregisterObject(const std::string &fullPath) override
Unregister object from the data store.
StatusCode initialize() override
bool m_enableAccessHdlr
Flag to enable interrupts on data access requests.
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...
virtual StatusCode removePreLoadItem(const DataStoreItem &item)
Remove an item from the preload 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.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
auto begin(reverse_wrapper< T > &w)
bool isSuccess() const
Test for a status code of SUCCESS.
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.
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 StatusCode resetPreLoad()
Clear the preload list.
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{})
virtual long remove(const std::string &name)
Remove an entry from the store.
const Store & leaves() const
Access the leaves of the object.
virtual StatusCode preLoad()
load all preload items of the list
StatusCode registerObject(const std::string &fullPath, DataObject *pObject) override
Register object with the data store.
virtual StatusCode registerAddress(const std::string &fullPath, IOpaqueAddress *pAddress)
IDataManagerSvc: Register object address with the data store.
void setAddress(IOpaqueAddress *pAddress) override
Set/Update Opaque address.
Description of the DataStoreItem class.
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.
StatusCode setDataLoader(IConversionSvc *svc) override
IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the service.
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.
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.
unsigned int CLID
Class ID definition.
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 StatusCode unregisterAddress(const std::string &fullPath)
IDataManagerSvc: Unregister object address from the data store.
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.
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.
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.
virtual StatusCode addPreLoadItem(const DataStoreItem &item)
Add an item to the preload list.
void makeHard(DataObject *pObject)
Initialize link as hard link.