40 std::string no_prefix( std::string_view value, std::string_view prefix ) {
41 if ( value.starts_with( prefix ) ) value.remove_prefix(
prefix.size() );
42 return std::string{ value };
51 inline size_t add_prefix( MAP& _map,
const std::string& prefix ) {
53 if (
prefix.empty() ) {
return 0; }
55 auto it = std::find_if_not( _map.begin(), _map.end(), [&](
typename MAP::ValueType::const_reference i ) {
56 return i.first.starts_with( prefix );
58 if ( it == _map.end() )
return 0;
60 std::string value = std::move( it->second );
62 _map[
key] = std::move( value );
63 return 1 + add_prefix( _map, prefix );
71 inline size_t get_dir(
const std::string&
object,
SET& _set ) {
72 std::string::size_type ifind =
object.rfind(
'/' );
74 if ( std::string::npos == ifind ) {
return 0; }
75 if ( 0 == ifind ) {
return 0; }
76 const std::string
top = std::string(
object, 0, ifind );
78 return 1 + get_dir( top, _set );
85 template <
class MAP,
class SET>
86 inline size_t get_dirs(
const MAP& _map,
SET& _set ) {
87 size_t size = _set.size();
88 for (
const auto& item : _map ) { get_dir( item.first, _set ); }
89 return _set.size() -
size;
94 ClassH cl = TClass::GetClass( type.c_str() );
95 if ( !cl ) {
warning() <<
"Failed to access dictionary class for " <<
name <<
" of type:" << type <<
endmsg; }
100 Leaf leaf( alg.type(), alg.name() );
107 leaf =
Leaf( alg.type(), alg.name() );
122 error() <<
"Failed to setup old \"Nodes\"" <<
endmsg;
128 error() <<
"Failed to setup old \"Algorithms\"" <<
endmsg;
136 std::set<std::string> dirs;
140 auto _e = dirs.find(
"/Event" );
141 if ( dirs.end() != _e ) { dirs.erase( _e ); }
143 for (
const auto& dir : dirs ) {
152 for (
const auto& alg :
m_algMap ) {
181 <<
"(Alg/Node/Total)." <<
endmsg;
183 info() <<
m_total.outputUserTime(
"Algorithm timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] ",
186 info() <<
m_timer_nodes.outputUserTime(
"Nodes timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] ",
189 info() <<
m_timer_algs.outputUserTime(
"Algs timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] ",
192 info() <<
m_timer_all.outputUserTime(
"All timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] ",
215 warning() <<
"ToolSvc already finalized: cannot release tools. Check options." <<
endmsg;
254 error() <<
"Failed to retrieve the IAlgManager interface." <<
endmsg;
260 error() <<
"Failed to retrieve Incident service." <<
endmsg;
296 std::string nam, typ, tag;
301 for (
auto attrib : Parser( node ) ) {
304 tag = std::move( attrib.value );
307 nam = std::move( attrib.value );
312 warning() <<
"The obsolete property 'Nodes' redefines the action for '" + tag +
"' to be '" + nam +
"'" <<
endmsg;
322 std::string typ, tag;
326 for (
auto attrib : Parser( alg ) ) {
329 tag = std::move( attrib.value );
332 typ = std::move( attrib.value );
338 warning() <<
"The obsolete property 'Algorithms' redefines the action for '" + tag +
"' to be '" + item.
type() +
339 "/" + item.
name() +
"'"
350 l.algorithm =
m_algMgr->algorithm( l.name,
false );
355 error() <<
"Failed to create algorithm " << l.type <<
"('" << l.name <<
"')" <<
endmsg;
356 l.algorithm =
nullptr;
361 sc = l.algorithm->sysInitialize();
363 error() <<
"Failed to initialize algorithm " << l.type <<
"('" << l.name <<
"')" <<
endmsg;
364 l.algorithm =
nullptr;
369 sc = l.algorithm->sysStart();
371 error() <<
"Failed to 'run' algorithm " << l.type <<
"('" << l.name <<
"')" <<
endmsg;
372 l.algorithm =
nullptr;
386 ToolGetter( std::string _path ) : path(
std::move( _path ) ) {}
388 inline std::string operator()( IDODNodeMapper* t )
const {
return t->nodeTypeForPath( path ); }
390 inline Gaudi::Utils::TypeNameString operator()( IDODAlgMapper* t )
const {
return t->algorithmForPath( path ); }
395 inline bool isGood(
const std::string& r ) {
return !r.empty(); }
402 const ToolGetter getter;
403 const std::vector<IDODNodeMapper*>& nodes;
404 const std::vector<IDODAlgMapper*>& algs;
406 template <
class R,
class C>
407 R find(
const C& l )
const {
408 for (
auto& i : l ) {
409 auto result = getter( i );
410 if ( isGood( result ) )
return result;
417 Finder( std::string _path,
const std::vector<IDODNodeMapper*>& _nodes,
const std::vector<IDODAlgMapper*>& _algs )
418 : getter(
std::move( _path ) ), nodes( _nodes ), algs( _algs ) {}
420 inline std::string node()
const {
return find<std::string>( nodes ); }
422 inline Gaudi::Utils::TypeNameString
alg()
const {
return find<Gaudi::Utils::TypeNameString>( algs ); }
434 if ( !inc ) {
return; }
441 verbose() <<
"Incident: [" << incident.
type() <<
"] "
442 <<
" = " << incident.
source() <<
" Location:" << inc->tag() <<
endmsg;
447 auto icl =
m_nodes.find( tag );
454 auto ialg =
m_algs.find( tag );
455 if ( ialg !=
m_algs.end() ) {
466 std::string node = finder.node();
467 if ( isGood( node ) ) {
477 if ( isGood( alg ) ) {
495 std::unique_ptr<DataObject> object;
497 if ( n.dataObject ) {
501 if ( !n.clazz ) { n.clazz = TClass::GetClass( n.name.c_str() ); }
503 error() <<
"Failed to get dictionary for class '" << n.name <<
"' for location:" << tag <<
endmsg;
507 object.reset(
reinterpret_cast<DataObject*
>( n.clazz->New() ) );
510 error() <<
"Failed to create an object of type:" << n.clazz->GetName() <<
" for location:" << tag <<
endmsg;
517 error() <<
"Failed to register an object of type:" << n.name <<
" at location:" << tag <<
endmsg;
529 if ( !l.algorithm ) {
532 error() <<
"Failed to configure handler for: " << l.name <<
"[" << l.type <<
"] " << tag <<
endmsg;
547 error() <<
"Failed to execute the algorithm:" << l.algorithm->name() <<
" for location:" << tag <<
endmsg;
557 typedef std::pair<std::string, std::string> Pair;
558 std::map<std::string, Pair> _m;
559 for (
auto& alg :
m_algs ) {
560 auto check = _m.find( alg.first );
561 if ( _m.end() != check ) {
562 warning() <<
" The data item is activated for '" << check->first <<
"' as '" << check->second.first <<
"'"
565 const Leaf& l = alg.second;
566 std::string nam = ( l.name == l.type ? l.type : ( l.type +
"/" + l.name ) );
568 if ( !mode && 0 == l.num ) {
continue; }
572 val = ( !l.algorithm ) ?
"F" :
"T";
574 val = std::to_string( l.num );
577 _m[no_prefix( alg.first,
m_prefix )] = { nam, val };
580 for (
const auto& node :
m_nodes ) {
581 auto check = _m.find( node.first );
582 if ( _m.end() != check ) {
583 warning() <<
" The data item is already activated for '" << check->first <<
"' as '" << check->second.first <<
"'"
586 const Node& n = node.second;
587 std::string nam =
"'" + n.name +
"'";
591 if ( !mode && 0 == n.num ) {
continue; }
594 val = ( 0 == n.clazz ) ?
"F" :
"T";
596 val = std::to_string( n.num );
599 _m[no_prefix( node.first,
m_prefix )] = { nam, val };
602 if ( _m.empty() ) {
return; }
608 for (
const auto& i : _m ) {
609 n1 = std::max( n1, i.first.size() );
610 n2 = std::max( n2, i.second.first.size() );
611 n3 = std::max( n3, i.second.second.size() );
613 n1 = std::min( n1,
size_t{ 60 } );
614 n2 = std::min( n2,
size_t{ 60 } );
619 msg <<
"Data-On-Demand Actions enabled for:";
621 msg <<
"Data-On-Demand Actions has been used for:";
624 const auto header = std::format(
" | {3:<{0}.{0}s} | {4:<{1}.{1}s} | {5:>{2}.{2}s} |", n1, n2, n3,
"Address",
625 "Creator", ( mode ?
"S" :
"#" ) );
626 const auto line = std::format(
" {0:-^{1}}",
"", header.size() - 1 );
627 msg <<
'\n' << line <<
'\n' << header <<
'\n' << line;
630 for (
const auto& item : _m ) {
631 msg << std::format(
"\n | {3:<{0}.{0}s} | {4:<{1}.{1}s} | {5:>{2}.{2}s} |", n1, n2, n3, item.first,
632 item.second.first, item.second.second );
void toupper(std::string &s)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_COMPONENT(type)
implementation of various functions for streaming.
A small utility class for chronometry of user codes.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & msgStream() const
Return an uninitialized MsgStream.
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel() const
Data service incident class.
A DataObject is the base class of any identifiable object on any data store.
The DataOnDemandSvc listens to incidents typically triggered by the data service of the configurable ...
Gaudi::Property< std::string > m_trapType
ChronoEntity m_timer_nodes
StatusCode reinitialize() override
Inherited Service overrides: Service reinitialization.
Gaudi::Property< std::vector< std::string > > m_algMapTools
void dump(const MSG::Level level, const bool mode=true) const
dump the content of DataOnDemand service
Gaudi::Property< std::string > m_prefix
Gaudi::Property< Setup > m_algMapping
ChronoEntity m_timer_algs
StatusCode setup()
Setup routine (called by (re-) initialize.
std::vector< IDODNodeMapper * > m_nodeMappers
Gaudi::Property< std::vector< std::string > > m_nodeMapTools
NodeMap m_nodes
Map of "empty" objects to be placed as intermediate nodes.
Gaudi::Property< Setup > m_nodeMapping
Gaudi::Property< Map > m_algMap
Gaudi::Property< bool > m_partialPath
SmartIF< IIncidentSvc > m_incSvc
Incident service.
Gaudi::Property< bool > m_init
unsigned long long m_statAlg
Gaudi::Property< bool > m_dump
StatusCode execHandler(const std::string &tag, Leaf &leaf)
Execute leaf handler (algorithm)
Gaudi::Property< std::string > m_dataSvcName
SmartIF< IDataProviderSvc > m_dataSvc
Data provider reference.
StatusCode setupAlgHandlers()
Initialize leaf handlers.
SmartIF< IToolSvc > m_toolSvc
Data provider reference.
unsigned long long m_stat
StatusCode setupNodeHandlers()
Initialize node handlers.
unsigned long long m_statNode
void i_setNodeHandler(const std::string &name, const std::string &type)
Internal method to initialize a node handler.
StatusCode finalize() override
Inherited Service overrides: Service finalization.
StatusCode update()
update the handlers
SmartIF< IAlgManager > m_algMgr
Algorithm manager.
StatusCode i_setAlgHandler(const std::string &name, const Gaudi::Utils::TypeNameString &alg)
Internal method to initialize an algorithm handler.
void handle(const Incident &incident) override
IIncidentListener interfaces overrides: incident handling.
Gaudi::Property< Map > m_nodeMap
Gaudi::Property< bool > m_allowInitFailure
std::vector< IDODAlgMapper * > m_algMappers
StatusCode configureHandler(Leaf &leaf)
Configure handler for leaf.
AlgMap m_algs
Map of algorithms to handle incidents.
StatusCode initialize() override
Inherited Service overrides: Service initialization.
Helper class for efficient "key" access for strings.
Parse attribute strings allowing iteration over the various attributes.
Helper object, useful for measurement of CPU-performance of highly-recursive structures,...
Helper class to parse a string of format "type/name".
const std::string & type() const
const std::string & name() const
Define general base for Gaudi exception.
Interface of tools used by the DataOnDemandSvc to choose the algorithm to be run to produce the data ...
Interface of tools used by the DataOnDemandSvc to choose the type of node to be created at a path.
Base class for all Incidents (computing events).
const std::string & type() const
Access to the incident type.
const std::string & source() const
Access to the source of the incident.
Gaudi::StateMachine::State FSMState() const override
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
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
Small smart pointer class with automatic reference counting for IInterface.
This class is used for returning status codes from appropriate routines.
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
GAUDI_API const EventContext & currentContext()
constexpr auto size(const T &, Args &&...) noexcept
Helper class of the DataOnDemandSvc.
Helper class of the DataOnDemandSvc.