19 #define DATASVC_DATASVC_CPP
22 #include "GaudiKernel/IConverter.h"
23 #include "GaudiKernel/IOpaqueAddress.h"
24 #include "GaudiKernel/IConversionSvc.h"
26 #include "GaudiKernel/xtoa.h"
27 #include "GaudiKernel/DataObject.h"
28 #include "GaudiKernel/GaudiException.h"
30 #include "GaudiKernel/RegistryEntry.h"
31 #include "GaudiKernel/DataSvc.h"
32 #include "GaudiKernel/DataIncident.h"
33 #include "GaudiKernel/IIncidentSvc.h"
42 #include "boost/utility/string_ref.hpp"
48 inline std::string itemToPath(
int item) {
49 return std::string{
'/'} + std::to_string(item);
52 inline boost::string_ref::size_type find( boost::string_ref
s,
char c,
size_t o ) {
53 if (!s.empty()) s.remove_prefix(o);
55 return r==boost::string_ref::npos ? r : ( r + o ) ;
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()
85 parent->
remove(node_entry);
88 return INVALID_PARENT;
90 return INVALID_OBJECT;
107 return INVALID_PARENT;
109 return INVALID_OBJECT;
140 if ( !entry )
return INVALID_OBJECT;
204 if ( pDataLoader ) pDataLoader->
addRef();
216 if ( !pObject )
return INVALID_OBJECT;
224 if ( !node_entry )
return INVALID_OBJECT;
225 refpParent = node_entry->
parent();
231 std::vector<IRegistry*>& leaves) {
232 if ( !pObject )
return INVALID_OBJECT;
240 std::vector<IRegistry*>& leaves) {
243 if ( !node_entry )
return INVALID_OBJECT;
244 leaves = node_entry->
leaves();
251 if ( fullPath.empty() )
return INVALID_OBJ_PATH;
258 const std::string& objectPath,
266 const std::string& objPath,
269 if ( objPath.empty() )
return INVALID_OBJ_PATH;
275 std::string::size_type sep = objPath.find(
SEPARATOR,1);
276 if ( sep == std::string::npos ) {
277 return INVALID_PARENT;
279 if ( objPath.compare(0,sep,
m_rootName) == 0 ) {
287 if ( !par_entry )
return INVALID_PARENT;
289 std::string::size_type sep = objPath.rfind(
SEPARATOR);
290 if ( sep > 0 && sep != std::string::npos ) {
291 auto p_path = objPath.substr( 0, sep);
292 auto o_path = objPath.substr( sep );
302 p_entry = par_entry->
findLeaf(p_path);
304 if ( !p_entry )
return INVALID_PARENT;
308 return status.
isSuccess() ? status : DOUBL_OBJ_PATH;
313 if ( fullPath.empty() )
return INVALID_OBJ_PATH;
320 const std::string& objPath) {
327 const std::string& objPath) {
329 if ( objPath.empty() )
return INVALID_OBJ_PATH;
335 std::string::size_type sep = objPath.find(
SEPARATOR,1);
336 if ( sep != std::string::npos &&
340 return INVALID_PARENT;
349 std::string::size_type sep = objPath.rfind(
SEPARATOR);
350 if ( sep > 0 && sep != std::string::npos ) {
357 return INVALID_PARENT;
369 const std::string& objPath,
398 const std::string& objPath,
403 if ( !objPath.empty() ) {
405 std::string::size_type sep = objPath.find(
SEPARATOR,1);
406 if ( sep != std::string::npos ) {
407 return registerObject(objPath.substr( 0, sep), objPath.substr( sep ), pObject);
414 return INVALID_OBJ_PATH;
419 std::string::size_type sep = objPath.find(
SEPARATOR,1);
420 if ( sep != std::string::npos ) {
421 auto p_path = objPath.substr( 0, sep );
422 auto o_path = objPath.substr( sep );
432 par_entry = node_entry->
findLeaf(p_path);
434 else if ( 0 != par_entry && par_entry->
object() == 0 ) {
442 par_entry = node_entry->
findLeaf(p_path);
445 node_entry = par_entry;
456 status = node_entry->
add( objPath, pObject );
462 error() <<
"registerObject: trying to register null DataObject" <<
endmsg;
473 status = DOUBL_OBJ_PATH;
479 return INVALID_PARENT;
488 if ( !pEntry )
return INVALID_ROOT;
490 if ( !pEntry->
isEmpty() )
return DIR_NOT_EMPTY;
493 if ( !pParent )
return INVALID_PARENT;
495 if ( pObject ) pObject->
addRef();
502 const std::string& objPath) {
518 if ( !entry )
return INVALID_OBJECT;
520 if ( !parent )
return INVALID_PARENT;
521 if ( !entry->
isEmpty() )
return DIR_NOT_EMPTY;
523 if ( parent ) parent->
remove(entry);
529 const std::string& objectPath) {
543 return DIR_NOT_EMPTY;
545 return INVALID_OBJECT;
550 return INVALID_PARENT;
570 if ( pReg && path.empty() ) {
578 p.append(path.data(),path.size());
586 p.append(path.data(),path.size());
614 else return NO_DATA_LOADER;
618 else return INVALID_OBJ_ADDR;
637 return INVALID_OBJ_ADDR;
640 status = pLoader->
createObj(pAddress, pObject);
659 catch(
const std::exception& x) {
687 const std::string&
path,
693 boost::string_ref
path,
698 static const auto empty = boost::string_ref{};
706 }
else if ( path.front() !=
SEPARATOR ) {
708 }
else if ( sep != boost::string_ref::npos ) {
712 if ( !status.isSuccess() )
return status;
715 path = path.substr(sep);
717 return INVALID_OBJ_PATH;
723 if ( sep != boost::string_ref::npos ) {
724 if (!parentObj->
object()) {
726 if ( !status.
isSuccess() )
return status;
728 auto p_path = path.substr(0,sep);
734 root_entry = parentObj->
findLeaf(p_path);
741 if ( !status.
isSuccess() )
return status;
743 if ( root_entry->
isSoft() ) {
749 }
else if ( path.empty() ) {
752 if (!parentObj->
object()) {
754 if ( !status.
isSuccess() )
return status;
761 pEntry = (path.empty() ? parentObj : parentObj->
findLeaf(path) );
766 if ( !pEntry )
return INVALID_OBJ_PATH;
783 const std::string&
path,
789 pObject = result->
object();
803 const std::string& objectPath,
822 const std::string&
path,
837 const std::string&
path,
843 if ( !path.empty() ) {
844 pReg = root_entry->
find(path);
847 return INVALID_OBJ_PATH;
851 return (!pObject) ? OBJ_NOT_LOADED : IDataProviderSvc_NO_ERROR;
861 return (0 == pObject) ? OBJ_NOT_LOADED : IDataProviderSvc_NO_ERROR;
873 const std::string& objectPath,
878 status =
findObject (parent, objectPath, pObject);
886 return findObject(parentPath, itemToPath(item), pObject);
893 return findObject(parentObj, itemToPath(item), pObject);
898 const std::string&
path,
917 return INVALID_OBJ_ADDR;
930 return INVALID_OBJECT;
934 return INVALID_OBJECT;
938 return INVALID_OBJ_ADDR;
942 return NO_DATA_LOADER;
952 status = pLoader->
updateObj(pAddress, toUpdate);
963 catch(
const std::exception& x) {
965 pRegistry->
name() +
": " +
980 const std::string& updatePath) {
991 const std::string& updatePath) {
1002 const std::string& objPath,
DataObject* to) {
1010 return INVALID_OBJECT;
1013 std::string::size_type sep = objPath.rfind(
SEPARATOR);
1014 if ( sep > 0 && sep != std::string::npos ) {
1025 IDataProviderSvc_NO_ERROR : DOUBL_OBJ_PATH;
1031 return INVALID_PARENT;
1033 return INVALID_ROOT;
1039 if ( !fullPath.empty() ) {
1044 return linkObject( fullPath.substr( 0, sep), fullPath.substr(sep), to);
1046 return INVALID_OBJ_PATH;
1051 const std::string& objPath,
1063 const std::string& objPath,
1071 return INVALID_PARENT;
1076 const std::string& objPath) {
1081 std::string::size_type sep = objPath.rfind(
SEPARATOR);
1082 if ( sep > 0 && sep != std::string::npos ) {
1094 return INVALID_OBJ_PATH;
1099 return INVALID_PARENT;
1101 return INVALID_ROOT;
1106 if ( !fullPath.empty() ) {
1111 return unlinkObject(fullPath.substr(0,sep), fullPath.substr(sep));
1113 return INVALID_OBJ_PATH;
1118 const std::string& objPath) {
1129 const std::string& objPath) {
1134 return INVALID_ROOT;
1172 if ( pObject && depth++ < load_depth ) {
1175 for (
const auto&
i : *dir) {
1178 if ( status.
isSuccess() && depth < load_depth ) {
1192 int load_depth =
i.depth();
1193 if ( sc.
isSuccess() && load_depth > 1 ) {
1209 error() <<
"Failed to access incident service." <<
endmsg;
1227 error() <<
"Unable to reinitialize base class" <<
endmsg;
1233 error() <<
"Failed to access incident service." <<
endmsg;
1278 m_rootName(
"/Event"), m_root(nullptr)