35 #include "boost/format.hpp"
36 #include "boost/algorithm/string/predicate.hpp"
48 "The type of handled Incident" ) ;
50 declareProperty (
"DataSvc" , m_dataSvcName ) ;
52 declareProperty (
"UsePreceedingPath" , m_partialPath ) ;
56 "Dump the configuration and stastics" ) ->
62 "Flag to (pre)initialize all algorithms" ) ;
64 (
"AllowPreInitializeFailure" ,
66 "Allow (pre)initialization of algorithms to fail without stopping the application" ) ;
68 declareProperty (
"Algorithms" , m_algMapping ) ->
70 declareProperty (
"Nodes" , m_nodeMapping ) ->
73 declareProperty (
"AlgMap" , m_algMap ) ->
75 declareProperty (
"NodeMap" , m_nodeMap ) ->
78 declareProperty (
"Prefix" , m_prefix ) ;
80 declareProperty(
"NodeMappingTools", m_nodeMapTools,
81 "List of tools of type IDODNodeMapper");
82 declareProperty(
"AlgMappingTools", m_algMapTools,
83 "List of tools of type IDODAlgMapper");
91 verbose() <<
" I am update handler for property " << p <<
endmsg ;
101 <<
"The property 'Nodes' is obsolete, switch to map-like 'NodeMap' "
102 <<
" = { 'data' : 'type' } "
113 <<
"The property 'Algorithms' is obsolete, switch to map-like 'AlgMap' "
114 <<
" = { 'data' : 'algorithm' } "
144 return boost::algorithm::starts_with(value,prefix) ?
155 inline size_t add_prefix ( MAP& _map ,
const std::string& prefix )
158 if ( prefix.
empty() ) {
return 0 ; }
161 [&](
typename MAP::const_reference
i) {
162 return boost::algorithm::starts_with(
i.first,prefix);
164 if ( it == _map.end() )
return 0 ;
169 return 1 + add_prefix ( _map , prefix ) ;
181 std::string::size_type ifind =
object.rfind(
'/') ;
183 if ( std::string::npos == ifind ) {
return 0 ; }
184 if ( 0 == ifind ) {
return 0 ; }
188 return 1 + get_dir ( top , _set ) ;
196 template <
class MAP,
class SET>
197 inline size_t get_dirs (
const MAP& _map,
SET& _set )
199 size_t size = _set.size() ;
200 for (
const auto&
item : _map )
201 { get_dir (
item.first , _set ) ; }
202 return _set.size() - size ;
211 <<
"Failed to access dictionary class for "
212 << name <<
" of type:" << type <<
endmsg;
247 error() <<
"Failed to setup old \"Nodes\"" <<
endmsg ;
254 error() <<
"Failed to setup old \"Algorithms\"" <<
endmsg ;
266 auto _e = dirs.
find(
"/Event") ;
267 if ( dirs.
end() != _e ) { dirs.
erase( _e ) ; }
269 for (
const auto& dir : dirs )
320 <<
"Handled \"" <<
m_trapType <<
"\" incidents: "
327 (
"Algorithm timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " ,
System::milliSec )
331 (
"Nodes timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " ,
System::milliSec )
335 (
"Algs timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " ,
System::milliSec )
339 (
"All timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " ,
System::milliSec )
359 warning() <<
"ToolSvc already finalized: cannot release tools. Check options." <<
endmsg;
381 m_nodeMappers.clear();
383 m_algMappers.clear();
404 error() <<
"Failed to retrieve the IAlgManager interface." <<
endmsg;
410 error() <<
"Failed to retrieve Incident service." <<
endmsg;
418 <<
"Failed to retrieve the data provider interface of "
458 for (
auto attrib: Parser(node)) {
459 switch( ::
toupper(attrib.tag[0]) ) {
472 <<
"The obsolete property 'Nodes' redefines the action for '"
473 + tag +
"' to be '" +nam+
"'"
493 for (
auto attrib: Parser(alg)) {
494 switch( ::
toupper(attrib.tag[0]) ) {
508 <<
"The obsolete property 'Algorithms' redefines the action for '"
509 + tag +
"' to be '" +item.
type() +
"/"+item.
name()+
"'"
531 <<
"Failed to create algorithm "
542 <<
"Failed to initialize algorithm "
554 <<
"Failed to 'run' algorithm "
590 const ToolGetter getter;
594 template <
class R,
class C>
595 R
find(
const C&
l)
const {
597 auto result = getter(
i);
598 if (isGood(result))
return result;
607 : getter(
std::
move(_path)), nodes(_nodes), algs(_algs) {
611 return find<std::string>(nodes);
615 return find<Gaudi::Utils::TypeNameString>(algs);
634 if ( ! inc ) { return ; }
641 <<
"Incident: [" << incident.
type () <<
"] "
642 <<
" = " << incident.
source ()
643 <<
" Location:" << inc->tag() <<
endmsg;
667 verbose() <<
"Try to find mapping with mapping tools" <<
endmsg;
716 <<
"Failed to get dictionary for class '"
718 <<
"' for location:" << tag <<
endmsg;
722 object.reset( reinterpret_cast<DataObject*>(n.
clazz->New()) );
727 <<
"Failed to create an object of type:"
728 << n.
clazz->GetName() <<
" for location:" << tag
737 error() <<
"Failed to register an object of type:"
738 << n.
name <<
" at location:" << tag
762 <<
"Failed to configure handler for: "
774 error() <<
"Failed to execute the algorithm:"
790 const bool mode )
const
792 if ( m_algs.empty() && m_nodes.empty() ) { return ; }
796 for (
auto& alg : m_algs )
801 warning() <<
" The data item is activated for '"
804 const Leaf& l = alg.second ;
807 if ( !mode && 0 == l.
num ) { continue ; }
810 if ( mode ) { val = ( ! l.
algorithm ) ?
"F" :
"T" ; }
813 _m[ no_prefix ( alg.first , m_prefix ) ] = { nam , val } ;
816 for (
const auto& node : m_nodes )
821 warning() <<
" The data item is already activated for '"
824 const Node&
n = node.second ;
829 if ( !mode && 0 == n.
num ) { continue ; }
831 if ( mode ) { val = ( 0 == n.
clazz ) ?
"F" :
"T" ; }
834 _m[ no_prefix ( node.first , m_prefix ) ] = { nam , val } ;
837 if ( _m.
empty() ) { return ; }
843 for (
const auto&
i : _m )
846 n2 =
std::max ( n2 ,
i.second.first.size() ) ;
847 n3 =
std::max ( n3 ,
i.second.second.size() ) ;
849 if ( 10 > n1 ) { n1 = 10 ; }
850 if ( 10 > n2 ) { n2 = 10 ; }
851 if ( 60 < n1 ) { n1 = 60 ; }
852 if ( 60 < n2 ) { n2 = 60 ; }
855 const std::string _f =
" | %%1$-%1%.%1%s | %%2$-%2%.%2%s | %%3$%3%.%3%s |" ;
861 auto&
msg = msgStream(level);
863 if ( mode ) {
msg <<
"Data-On-Demand Actions enabled for:" ; }
864 else {
msg <<
"Data-On-Demand Actions has been used for:" ; }
867 fmt1 %
"Address" %
"Creator" % ( mode ?
"S" :
"#" ) ;
878 for (
const auto&
item : _m )
882 ( fmt %
item.first %
item.second.first %
item.second.second ) ;
void i_setNodeHandler(const std::string &name, const std::string &type)
Internal method to initialize a node handler.
Parse attribute strings allowing iteration over the various attributes.
virtual SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
StatusCode initialize() override
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
const std::string & type() const
Access to the incident type.
The DataOnDemandSvc listens to incidents typically triggered by the data service of the configurable ...
StatusCode finalize() override
virtual StatusCode sysStart()=0
Startup method invoked by the framework.
ChronoEntity m_timer_algs
Gaudi::StateMachine::State FSMState() const override
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
const std::string & source() const
Access to the source of the incident.
std::vector< IDODNodeMapper * > m_nodeMappers
bool isSuccess() const
Test for a status code of SUCCESS.
SmartIF< IIncidentSvc > m_incSvc
Incident service.
void handle(const Incident &incident) override
IIncidentListener interfaces overrides: incident handling.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
virtual StatusCode createAlgorithm(const std::string &algtype, const std::string &algname, IAlgorithm *&alg, bool managed=false, bool checkIfExists=true)=0
Create an instance of a algorithm type that has been declared beforehand and assigns to it a name...
std::vector< std::string > m_algMapTools
std::string m_trapType
Trap name.
std::string m_dataSvcName
Data service name.
Setup m_nodeMapping
Mapping to nodes.
A small utility class for chronometry of user codes.
Map m_algMap
the major configuration property { 'data' : 'algorithm' }
StatusCode initialize() override
Inherited Service overrides: Service initialization.
bool isFailure() const
Test for a status code of FAILURE.
The helper class to represent the efficient "key" for access.
virtual StatusCode sysExecute()=0
System execution. This method invokes the execute() method of a concrete algorithm.
#define DECLARE_COMPONENT(type)
SmartIF< IDataProviderSvc > m_dataSvc
Data provider reference.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
const std::string & name() const override
Retrieve name of the service.
ClassH clazz
the actual class
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Interface of tools used by the DataOnDemandSvc to choose the type of node to be created at a path...
Setup m_algMapping
Mapping to algorithms.
Helper class to parse a string of format "type/name".
StatusCode setup()
Setup routine (called by (re-) initialize.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
bool m_allowInitFailure
flag to allow DataOnDemand initialization to succeed even if the (pre)initialization of the algorithm...
StatusCode execHandler(const std::string &tag, Leaf &leaf)
Execute leaf handler (algorithm)
This class is used for returning status codes from appropriate routines.
void update_dump(Property &)
update handler for 'Dump' property
StatusCode setupNodeHandlers()
Initialize node handlers.
iterator find(const key_type &key)
Helper class of the DataOnDemandSvc.
virtual Gaudi::Utils::TypeNameString algorithmForPath(const std::string &path)=0
For the given path, returns a TypeNameString object identifying the algorithm to be run to produce th...
std::vector< std::string > m_nodeMapTools
NodeMap m_nodes
Map of "empty" objects to be placed as intermediate nodes.
auto end(reverse_wrapper< T > &w)
StatusCode reinitialize() override
void dump(const MSG::Level level, const bool mode=true) const
dump the content of DataOnDemand service
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
bool m_partialPath
Flag to allow for the creation of partial leaves.
std::string outputUserTime() const
print the chrono ;
std::vector< IDODAlgMapper * > m_algMappers
Interface of tools used by the DataOnDemandSvc to choose the algorithm to be run to produce the data ...
Property base class allowing Property* collections to be "homogeneous".
SmartIF< IAlgManager > m_algMgr
Algorithm manager.
SmartIF< IToolSvc > m_toolSvc
Data provider reference.
Helper object, useful for measurement of CPU-performance of highly-recursive structures, e.g.
AlgMap m_algs
Map of algorithms to handle incidents.
bool m_dump
flag to force the printout
bool m_init
flag to warm up the configuration
const std::string & type() const
ChronoEntity m_timer_nodes
Base class for all Incidents (computing events).
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
bool dataObject
trivial object? DataObject?
DataOnDemandSvc(const std::string &name, ISvcLocator *svc)
Standard initializing service constructor.
StatusCode finalize() override
Inherited Service overrides: Service finalization.
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
virtual bool isInitialized() const =0
check if the algorithm is initialized properly
Map m_nodeMap
the major configuration property { 'data' : 'type' }
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
Data service incident class.
const std::string & name() const
implementation of various functions for streaming.
StatusCode setupAlgHandlers()
Initialize leaf handlers.
Helper class of the DataOnDemandSvc.
virtual std::string nodeTypeForPath(const std::string &path)=0
For the given path, returns a the type name of the object to be created at the path.
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
StatusCode i_setAlgHandler(const std::string &name, const Gaudi::Utils::TypeNameString &alg)
Internal method to initialize an algorithm handler.
StatusCode configureHandler(Leaf &leaf)
Configure handler for leaf.
void update_2(Property &p)
void toupper(std::string &s)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void update_3(Property &p)
void update_1(Property &p)
StatusCode reinitialize() override
Inherited Service overrides: Service reinitialization.
StatusCode update()
update the handlers
StatusCode sysInitialize() override
Initialize Service.