11#define DATASVC_DATASVC_CPP
26 std::string
operator+(
char c, std::string_view sr ) {
28 s.append( sr.data(), sr.size() );
32 std::string_view::size_type
find( std::string_view s,
char c,
size_t o ) {
33 if ( !s.empty() ) s.remove_prefix( o );
35 return r == std::string_view::npos ? r : ( r + o );
38 std::string to_string( std::string_view sr ) {
return { sr.data(), sr.size() }; }
46#define CAST_REGENTRY( x, y ) dynamic_cast<x>( y )
50#define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
51#define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
53#define DEBMSG ON_DEBUG debug()
54#define VERMSG ON_VERBOSE verbose()
64 if ( !node_entry )
return Status::INVALID_OBJECT;
66 if ( !parent )
return Status::INVALID_PARENT;
67 parent->
remove( node_entry );
75 if ( !
checkRoot() )
return Status::INVALID_ROOT;
77 if ( !entry )
return Status::INVALID_OBJECT;
79 if ( !parent )
return Status::INVALID_PARENT;
102 return entry ? entry->
traverseTree( pAgent ) : Status::INVALID_OBJECT;
107 if ( !
checkRoot() )
return Status::INVALID_ROOT;
108 return m_root->traverseTree( pAgent );
128 m_root->makeHard( pRootObj );
129 m_root->setDataSvc(
this );
152 m_root->makeHard( pRootAddr );
153 m_root->setDataSvc(
this );
168 if ( !pObject )
return Status::INVALID_OBJECT;
173 if ( !
checkRoot() )
return Status::INVALID_ROOT;
175 if ( !node_entry )
return Status::INVALID_OBJECT;
176 refpParent = node_entry->
parent();
182 if ( !pObject )
return Status::INVALID_OBJECT;
190 if ( !
checkRoot() )
return Status::INVALID_ROOT;
192 if ( !node_entry )
return Status::INVALID_OBJECT;
193 leaves = node_entry->
leaves();
199 if ( fullPath.empty() )
return Status::INVALID_OBJ_PATH;
205 if ( !
checkRoot() )
return Status::INVALID_ROOT;
206 if ( objPath.empty() )
return Status::INVALID_OBJ_PATH;
211 if ( sep == std::string_view::npos || objPath.substr( 0, sep ) !=
m_rootName.
value() ) {
212 return Status::INVALID_PARENT;
218 if ( !par_entry )
return Status::INVALID_PARENT;
221 if ( sep > 0 && sep != std::string_view::npos ) {
222 auto p_path = objPath.substr( 0, sep );
223 auto o_path = objPath.substr( sep );
231 p_entry = par_entry->
findLeaf( p_path );
233 if ( !p_entry )
return Status::INVALID_PARENT;
236 StatusCode status = par_entry->
add( to_string( objPath ), pAddress );
237 return status.
isSuccess() ? status : Status::DOUBL_OBJ_PATH;
242 if ( fullPath.empty() )
return Status::INVALID_OBJ_PATH;
248 if ( !
checkRoot() )
return Status::INVALID_ROOT;
249 if ( objPath.empty() )
return Status::INVALID_OBJ_PATH;
254 if ( sep != std::string_view::npos && objPath.substr( 0, sep ) ==
m_rootName.
value() ) {
257 return Status::INVALID_PARENT;
265 if ( sep > 0 && sep != std::string_view::npos ) {
272 return Status::INVALID_PARENT;
289 if ( !
checkRoot() )
return Status::INVALID_ROOT;
292 if ( !objPath.empty() ) {
295 if ( sep != std::string_view::npos ) {
296 return registerObject( objPath.substr( 0, sep ), objPath.substr( sep ), pObject );
299 return Status::INVALID_OBJ_PATH;
305 if ( sep != std::string_view::npos ) {
306 auto p_path = objPath.substr( 0, sep );
307 auto o_path = objPath.substr( sep );
315 par_entry = node_entry->
findLeaf( p_path );
316 }
else if ( par_entry && !par_entry->
object() ) {
322 par_entry = node_entry->
findLeaf( p_path );
325 node_entry = par_entry;
333 status = node_entry->
add( to_string( objPath ), pObject );
338 error() <<
"registerObject: trying to register null DataObject" <<
endmsg;
346 status = Status::DOUBL_OBJ_PATH;
352 return Status::INVALID_PARENT;
361 if ( !pEntry )
return Status::INVALID_ROOT;
362 if ( !pEntry->
isEmpty() )
return Status::DIR_NOT_EMPTY;
364 if ( !pParent )
return Status::INVALID_PARENT;
366 pParent->
remove( pEntry );
372 if ( !
checkRoot() )
return Status::INVALID_ROOT;
374 if ( !entry )
return Status::INVALID_OBJECT;
376 if ( !parent )
return Status::INVALID_PARENT;
377 if ( !entry->
isEmpty() )
return Status::DIR_NOT_EMPTY;
379 if ( parent ) parent->
remove( entry );
396 return Status::DIR_NOT_EMPTY;
398 return Status::INVALID_OBJECT;
401 return Status::INVALID_PARENT;
403 return Status::INVALID_ROOT;
415 if ( pReg && path.
empty() ) {
426 pLeaf =
m_root->findLeaf( p );
428 std::string p =
m_root->identifier();
433 pLeaf =
m_root->findLeaf( p );
435 if ( pLeaf ) {
return pLeaf->
object(); }
474 return Status::INVALID_OBJ_ADDR;
477 status = pLoader->
createObj( pAddress, pObject );
486 status = pLoader->
fillObjRefs( pAddress, pObject );
517 if ( !
checkRoot() )
return Status::INVALID_ROOT;
519 static constexpr auto empty = std::string_view{};
529 }
else if ( sep != std::string_view::npos ) {
530 if ( !
m_root->object() ) {
533 if ( !status.isSuccess() )
return status;
536 path = path.
substr( sep );
538 return Status::INVALID_OBJ_PATH;
544 if ( sep != std::string_view::npos ) {
545 if ( !parentObj->
object() ) {
547 if ( !status.
isSuccess() )
return status;
549 auto p_path = path.
substr( 0, sep );
555 root_entry = parentObj->
findLeaf( p_path );
562 if ( !status.
isSuccess() )
return status;
567 return Status::INVALID_OBJ_PATH;
568 }
else if ( path.
empty() ) {
571 if ( !parentObj->
object() ) {
573 if ( !status.
isSuccess() )
return status;
576 pEntry = parentObj->
findLeaf( path );
580 pEntry = ( path.
empty() ? parentObj : parentObj->
findLeaf( path ) );
585 if ( !pEntry )
return Status::INVALID_OBJ_PATH;
615 if ( !path.
empty() ) pReg = root_entry->
find( path );
616 if ( !pReg )
return Status::INVALID_OBJ_PATH;
619 return ( !pObject ) ? Status::OBJ_NOT_LOADED : Status::IDataProviderSvc_NO_ERROR;
625 if ( !
checkRoot() )
return Status::INVALID_ROOT;
627 pObject =
m_root->object();
628 return !pObject ? Status::OBJ_NOT_LOADED : Status::IDataProviderSvc_NO_ERROR;
636 return Status::INVALID_OBJ_ADDR;
649 return Status::INVALID_OBJECT;
653 return Status::INVALID_OBJECT;
657 return Status::INVALID_OBJ_ADDR;
661 return Status::NO_DATA_LOADER;
668 status = pLoader->
updateObj( pAddress, toUpdate );
673 throw GaudiException(
"std::exception in updateObject() " + pRegistry->
name() +
": " +
684 if ( !
checkRoot() )
return Status::INVALID_ROOT;
690 if ( !to_entry )
return Status::INVALID_OBJECT;
692 if ( sep > 0 && sep != std::string_view::npos ) {
698 StatusCode status = from_entry->
add( to_string( objPath ), to,
true );
699 return status.
isSuccess() ? Status::IDataProviderSvc_NO_ERROR : Status::DOUBL_OBJ_PATH;
702 return Status::INVALID_PARENT;
707 if ( fullPath.empty() )
return Status::INVALID_OBJ_PATH;
710 return linkObject( fullPath.substr( 0, sep ), fullPath.substr( sep ), to );
715 if ( !
checkRoot() )
return Status::INVALID_ROOT;
720 if ( sep > 0 && sep != std::string_view::npos ) {
727 return Status::INVALID_OBJ_PATH;
730 return Status::INVALID_PARENT;
735 if ( fullPath.empty() )
return Status::INVALID_OBJ_PATH;
738 return unlinkObject( fullPath.substr( 0, sep ), fullPath.substr( sep ) );
743 if ( !
checkRoot() )
return Status::INVALID_ROOT;
770 if ( pObject && depth++ < load_depth ) {
773 for (
const auto& i : *dir ) {
788 int load_depth = i.depth();
814 error() <<
"Unable to reinitialize base class" <<
endmsg;
820 error() <<
"Failed to access incident service." <<
endmsg;
unsigned int CLID
Class ID definition.
DataSvcHelpers::RegistryEntry RegEntry
#define CAST_REGENTRY(x, y)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
constexpr _OI move(_II __first, _II __last, _OI __result)
constexpr _ForwardIterator remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__value)
constexpr _InputIterator find(_InputIterator __first, _InputIterator __last, const _Tp &__val)
constexpr basic_string< _CharT, _Traits, _Alloc > operator+(_CharT __lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
constexpr auto begin(_Container &__cont) -> decltype(__cont.begin())
constexpr auto end(_Container &__cont) -> decltype(__cont.end())
const _CharT * data() const noexcept
basic_string substr(size_type __pos=0, size_type __n=npos) const
size_type size() const noexcept
basic_string & append(_InputIterator __first, _InputIterator __last)
bool empty() const noexcept
virtual const char * what() const noexcept
constexpr void push_back(const value_type &__x)
constexpr iterator erase(const_iterator __first, const_iterator __last)
constexpr void reset(pointer __p=pointer()) noexcept
constexpr pointer get() const noexcept
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Data service incident class.
A DataObject is the base class of any identifiable object on any data store.
virtual unsigned long addRef()
Add reference to object.
void setRegistry(IRegistry *pRegistry)
Set pointer to Registry.
const std::string & name() const
Retreive DataObject name. It is the name when registered in the store.
IRegistry * registry() const
Get pointer to Registry.
DataObject()
Standard Constructor.
virtual unsigned long release()
release reference to object
Description of the DataStoreItem class.
Definition of an entry in the transient data store.
void setObject(DataObject *obj)
Set/Update object address.
StatusCode traverseTree(IDataStoreAgent *pAgent, int level=0)
traverse data tree
void setAddress(IOpaqueAddress *pAddress) override
Set/Update Opaque address.
IRegistry * parent() const
Pointer to parent directory entry.
const Store & leaves() const
Access the leaves of the object.
bool isSoft() const
Is the link soft or hard.
const std::string & identifier() const override
Full identifier (or key).
RegistryEntry * findLeaf(std::string_view path) const
Find identified leaf in this registry node.
IRegistry * find(const IRegistry *obj) const
Try to find an object identified by its pointer.
RegistryEntry * parentEntry()
Pointer to parent registry entry.
DataObject * object() const override
Retrive object behind the link.
bool isEmpty() const
Simple check if the Container is empty.
IOpaqueAddress * address() const override
Retrieve opaque storage address.
StatusCode remove(std::string_view name)
Remove an entry from the store.
StatusCode add(std::string name, DataObject *pObject, bool is_soft=false)
Add entry to data store.
StatusCode reinitialize() override
Service initialization.
StatusCode retrieveEntry(DataSvcHelpers::RegistryEntry *pNode, std::string_view path, DataSvcHelpers::RegistryEntry *&pEntry)
Retrieve registry entry from store.
StatusCode traverseSubTree(std::string_view sub_tree_path, IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects below the sub tree identified by its full pat...
StatusCode setRoot(std::string root_name, DataObject *pRootObj) override
Initialize data store for new event by giving new event path and root object.
virtual DataObject * createDefaultObject() const
Create default objects in case forced creation of leaves is requested.
StatusCode finalize() override
Service initialization.
Gaudi::Property< std::string > m_rootName
StatusCode findObject(std::string_view fullPath, DataObject *&pObject) override
Find object identified by its full path in the data store.
StatusCode resetPreLoad() override
Clear the preload list.
virtual StatusCode preLoad(int depth, int load_depth, DataObject *pObject)
Execute one level of preloading and recursively load until the final level is reached.
StatusCode clearSubTree(std::string_view sub_tree_path) override
IDataManagerSvc: Remove all data objects below the sub tree identified by its full path name.
virtual StatusCode i_setRoot(std::string root_name, DataObject *pRootObj)
Initialize data store for new event by giving new event path and root object.
virtual IConversionSvc * getDataLoader(IRegistry *pReg)
Retrieve customizable data loader according to registry entry to be retrieved.
SmartIF< IConversionSvc > m_dataLoader
Pointer to data loader service.
StatusCode setDataLoader(IConversionSvc *svc, IDataProviderSvc *dpsvc=nullptr) override
IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the service and optionally a data pro...
StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves) override
IDataManagerSvc: Explore the object store: retrieve all leaves attached to the object.
StatusCode initialize() override
Service initialization.
StatusCode unregisterAddress(std::string_view fullPath) override
IDataManagerSvc: Unregister object address from the data store.
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to incident service.
StatusCode unregisterObject(std::string_view fullPath) override
Unregister object from the data store.
StatusCode registerObject(std::string_view parentPath, std::string_view objPath, DataObject *pObject) override
Register object with the data store.
StatusCode addPreLoadItem(const DataStoreItem &item) override
Add an item to the preload list.
DataObject * handleDataFault(IRegistry *pReg, std::string_view path="")
Invoke data fault handling if enabled.
DataObject * i_handleDataFault(IRegistry *pReg, std::string_view path=std::string_view{})
Gaudi::Property< std::vector< std::string > > m_inhibitPathes
Gaudi::Property< bool > m_enableAccessHdlr
Gaudi::Property< CLID > m_rootCLID
Gaudi::Property< std::string > m_accessName
StatusCode preLoad() override
load all preload items of the list
StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject) override
Retrieve object from data store.
const std::string & rootName() const override
IDataManagerSvc: Accessor for root event name.
StatusCode registerAddress(std::string_view fullPath, IOpaqueAddress *pAddress) override
IDataManagerSvc: Register object address with the data store.
StatusCode traverseTree(IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects in the data store.
bool checkRoot()
Check if root path is valid.
CLID rootCLID() const override
IDataManagerSvc: Accessor for root event CLID.
StatusCode objectParent(const DataObject *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
StatusCode removePreLoadItem(const DataStoreItem &item) override
Remove an item from the preload list.
Gaudi::Property< bool > m_forceLeaves
Gaudi::Property< bool > m_enableFaultHdlr
StatusCode clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
StatusCode i_retrieveEntry(DataSvcHelpers::RegistryEntry *parentObj, std::string_view path, DataSvcHelpers::RegistryEntry *&pEntry)
Gaudi::Property< std::string > m_faultName
virtual StatusCode loadObject(IRegistry *pNode)
Invoke Persistency service to create transient object from its persistent representation.
std::vector< DataStoreItem > m_preLoads
Items to be pre-loaded.
StatusCode unlinkObject(IRegistry *from, std::string_view objPath) override
Remove a link to another object.
StatusCode linkObject(IRegistry *from, std::string_view objPath, DataObject *to) override
Add a link to another object.
std::unique_ptr< DataSvcHelpers::RegistryEntry > m_root
Pointer to root entry.
const ValueType & value() const
Define general base for Gaudi exception.
GaudiException(std::string Message, std::string Tag, StatusCode Code)
Constructor (1).
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Resolve the references of the created transient object.
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
virtual StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *refpObject)=0
Update the transient object from the other representation.
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)=0
Create the transient representation of an object.
virtual StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)=0
Update the references of an updated transient object.
Data provider interface definition.
Generic data agent interface.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
Opaque address interface definition.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
virtual const name_type & name() const =0
Name of the directory (or key).
virtual const id_type & identifier() const =0
Full identifier (or key).
virtual DataObject * object() const =0
Retrieve object behind the link.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
StatusCode finalize() override
const std::string & name() const override
Retrieve name of the service.
StatusCode reinitialize() override
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
StatusCode initialize() override
TYPE * get() const
Get interface pointer.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
This class is used for returning status codes from appropriate routines.
StatusCode()=default
Default constructor.
void ignore() const
Allow discarding a StatusCode without warning.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.