37 #pragma warning(disable:2259)
39 #include "boost/format.hpp"
40 #include "boost/lexical_cast.hpp"
52 , m_trapType (
"DataFault")
53 , m_dataSvcName (
"EventDataSvc" )
54 , m_partialPath (
true )
57 , m_allowInitFailure(
false)
65 , m_updateRequired (
true )
66 , m_prefix (
"/Event/" )
76 , m_locked_nodes (
false )
77 , m_locked_algs (
false )
78 , m_locked_all (
false )
85 "The type of handled Incident" ) ;
87 declareProperty (
"DataSvc" , m_dataSvcName ) ;
89 declareProperty (
"UsePreceedingPath" , m_partialPath ) ;
93 "Dump the configuration and stastics" ) ->
99 "Flag to (pre)initialize all algorithms" ) ;
101 (
"AllowPreInitializeFailure" ,
103 "Allow (pre)initialization of algorithms to fail without stopping the application" ) ;
105 declareProperty (
"Algorithms" , m_algMapping ) ->
107 declareProperty (
"Nodes" , m_nodeMapping ) ->
110 declareProperty (
"AlgMap" , m_algMap ) ->
112 declareProperty (
"NodeMap" , m_nodeMap ) ->
115 declareProperty (
"Prefix" , m_prefix ) ;
117 declareProperty(
"NodeMappingTools", m_nodeMapTools,
118 "List of tools of type IDODNodeMapper");
119 declareProperty(
"AlgMappingTools", m_algMapTools,
120 "List of tools of type IDODAlgMapper");
138 <<
"The property 'Nodes' is obsolete, switch to map-like 'NodeMap' "
139 <<
" = { 'data' : 'type' } "
150 <<
"The property 'Algorithms' is obsolete, switch to map-like 'AlgMap' "
151 <<
" = { 'data' : 'algorithm' } "
177 inline std::string no_prefix
178 (
const std::string&
value ,
179 const std::string& prefix )
182 !prefix.empty() && 0 == value.find(prefix) ?
183 std::string( value , prefix.size() ) : value ;
193 inline size_t add_prefix ( MAP& _map ,
const std::string& prefix )
196 if ( prefix.empty() ) {
return 0 ; }
198 for (
typename MAP::iterator it = _map.begin() ; _map.end() != it ; ++it )
200 if ( 0 != it->first.find(prefix) )
202 std::string key = prefix + it->first ;
203 std::string value = it->second ;
205 _map[ key ] =
value ;
206 return 1 + add_prefix ( _map , prefix ) ;
219 inline size_t get_dir (
const std::string&
object ,
SET& _set )
221 std::string::size_type ifind =
object.rfind(
'/') ;
223 if ( std::string::npos == ifind ) {
return 0 ; }
224 if ( 0 == ifind ) {
return 0 ; }
226 const std::string top = std::string(
object , 0 , ifind) ;
228 return 1 + get_dir ( top , _set ) ;
236 template <
class MAP,
class SET>
237 inline size_t get_dirs (
const MAP& _map,
SET& _set )
239 size_t size = _set.size() ;
240 for (
typename MAP::const_iterator
item = _map.begin() ;
241 _map.end() !=
item ; ++
item ) { get_dir (
item->first , _set ) ; }
242 return _set.size() - size ;
248 ClassH cl = TClass::GetClass(type.c_str()) ;
251 <<
"Failed to access dictionary class for "
252 << name <<
" of type:" << type <<
endmsg;
302 typedef std::set<std::string> Set ;
307 Set::iterator _e = dirs.find(
"/Event") ;
308 if ( dirs.end() != _e ) { dirs.erase( _e ) ; }
310 for ( Set::const_iterator dir = dirs.begin() ; dirs.end() != dir ; ++dir )
321 for ( Map::const_iterator ialg =
m_algMap.begin() ;
328 for ( Map::const_iterator inode =
m_nodeMap.begin() ;
369 <<
"Handled \"" <<
m_trapType <<
"\" incidents: "
377 (
"Algorithm timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " ,
System::milliSec )
382 (
"Nodes timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " ,
System::milliSec )
387 (
"Algs timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " ,
System::milliSec )
392 (
"All timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " ,
System::milliSec )
414 warning() <<
"ToolSvc already finalized: cannot release tools. Check options." <<
endmsg;
462 error() <<
"Failed to retrieve the IAlgManager interface." <<
endmsg;
468 error() <<
"Failed to retrieve Incident service." <<
endmsg;
476 <<
"Failed to retrieve the data provider interface of "
490 std::vector<std::string>::iterator
i;
511 Setup::const_iterator j;
512 std::string nam, typ, tag;
518 tok.
analyse(*j,
" ",
"",
"",
"=",
"'",
"'");
519 for ( Tokenizer::Items::iterator
i = tok.
items().begin();
520 i != tok.
items().end();
i++ ) {
521 const std::string& t = (*i).tag();
522 const std::string& v = (*i).value();
537 <<
"The obsolete property 'Nodes' redefines the action for '"
538 + tag +
"' to be '" +nam+
"'"
553 Setup::const_iterator j;
554 std::string typ, tag;
559 tok.
analyse(*j,
" ",
"",
"",
"=",
"'",
"'");
560 for(Tokenizer::Items::iterator
i = tok.
items().begin();
i != tok.
items().end();
i++ ) {
561 const std::string& t = (*i).tag();
562 const std::string& v = (*i).value();
578 <<
"The obsolete property 'Algorithms' redefines the action for '"
579 + tag +
"' to be '" +item.
type() +
"/"+item.
name()+
"'"
602 <<
"Failed to create algorithm "
614 <<
"Failed to initialize algorithm "
627 <<
"Failed to 'run' algorithm "
643 ToolGetter(
const std::string &_path):
path(_path) {}
656 inline bool isGood(
const std::string& r) {
return !r.empty();}
663 const ToolGetter getter;
664 const std::list<IDODNodeMapper*> &nodes;
665 const std::list<IDODAlgMapper*> &algs;
667 template <
class R,
class T>
668 R find(
const std::list<T*> &
l)
const {
669 typename std::list<T*>::const_iterator
i;
670 for(i = l.begin(); i != l.end(); ++
i) {
671 R result = getter(*i);
672 if (isGood(result))
return result;
678 Finder(
const std::string &_path,
679 const std::list<IDODNodeMapper*> &_nodes,
680 const std::list<IDODAlgMapper*> &_algs): getter(_path), nodes(_nodes), algs(_algs) {
683 inline std::string node()
const {
684 return find<std::string>(nodes);
688 return find<Gaudi::Utils::TypeNameString>(algs);
707 if ( 0 == inc ) { return ; }
714 <<
"Incident: [" << incident.
type () <<
"] "
715 <<
" = " << incident.
source ()
716 <<
" Location:" << inc->tag() <<
endmsg;
741 verbose() <<
"Try to find mapping with mapping tools" <<
endmsg;
744 std::string node = finder.node();
791 <<
"Failed to get dictionary for class '"
793 <<
"' for location:" << tag <<
endmsg;
803 <<
"Failed to create an object of type:"
804 << n.
clazz->GetName() <<
" for location:" << tag
814 <<
MSG::ERROR <<
"Failed to register an object of type:"
815 << n.
name <<
" at location:" << tag
840 <<
"Failed to configure handler for: "
853 <<
"Failed to execute the algorithm:"
869 const bool mode )
const
871 if ( m_algs.empty() && m_nodes.empty() ) { return ; }
873 typedef std::pair<std::string,std::string> Pair ;
874 typedef std::map<std::string,Pair> PMap ;
878 m_algs.end() != alg ; ++alg )
880 PMap::const_iterator
check = _m.find(alg->first) ;
881 if ( _m.end() !=
check )
885 <<
" The data item is activated for '"
886 << check->first <<
"' as '" << check->second.first <<
"'" <<
endmsg ;
888 const Leaf& l = alg->second ;
891 if ( !mode && 0 == l.
num ) { continue ; }
894 if ( mode ) { val = ( 0 == l.
algorithm ) ?
"F" :
"T" ; }
895 else { val = boost::lexical_cast<std::string>( l.
num ) ; }
897 _m[ no_prefix ( alg->first , m_prefix ) ] = std::make_pair ( nam , val ) ;
901 m_nodes.end() != node ; ++node )
903 PMap::const_iterator
check = _m.find(node->first) ;
904 if ( _m.end() !=
check )
908 <<
" The data item is already activated for '"
909 << check->first <<
"' as '" << check->second.first <<
"'" <<
endmsg ;
911 const Node&
n = node->second ;
912 std::string nam =
"'" + n.
name +
"'" ;
916 if ( !mode && 0 == n.
num ) { continue ; }
918 if ( mode ) { val = ( 0 == n.
clazz ) ?
"F" :
"T" ; }
919 else { val = boost::lexical_cast<std::string>( n.
num ) ; }
921 _m[ no_prefix ( node->first , m_prefix ) ] = std::make_pair ( nam , val ) ;
924 if ( _m.empty() ) { return ; }
930 for ( PMap::const_iterator it = _m.begin() ; _m.end() != it ; ++it )
932 n1 = std::max ( n1 , it->first.size() ) ;
933 n2 = std::max ( n2 , it->second.first.size() ) ;
934 n3 = std::max ( n3 , it->second.second.size() ) ;
936 if ( 10 > n1 ) { n1 = 10 ; }
937 if ( 10 > n2 ) { n2 = 10 ; }
938 if ( 60 < n1 ) { n1 = 60 ; }
939 if ( 60 < n2 ) { n2 = 60 ; }
942 const std::string _f =
" | %%1$-%1%.%1%s | %%2$-%2%.%2%s | %%3$%3%.%3%s |" ;
946 const std::string _format = _ff.str() ;
950 if ( mode ) { msg <<
"Data-On-Demand Actions enabled for:" ; }
951 else { msg <<
"Data-On-Demand Actions has been used for:" ; }
954 fmt1 %
"Address" %
"Creator" % ( mode ?
"S" :
"#" ) ;
956 const std::string
header = fmt1.str() ;
957 std::string
line = std::string( header.size() ,
'-' ) ;
960 msg << std::endl << line
961 << std::endl << header
962 << std::endl <<
line ;
965 for ( PMap::const_iterator
item = _m.begin() ;
970 ( fmt %
item->first %
item->second.first %
item->second.second ) ;
973 msg << std::endl << line <<
endmsg ;
void i_setNodeHandler(const std::string &name, const std::string &type)
Internal method to initialize a node handler.
Definition of the MsgStream class used to transmit messages.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
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 ...
virtual StatusCode sysStart()=0
Startup method invoked by the framework.
ChronoEntity m_timer_algs
Items & items()
Access token collection.
std::list< IDODNodeMapper * > m_nodeMappers
const std::string & source() const
Access to the source of the incident.
bool isSuccess() const
Test for a status code of SUCCESS.
MsgStream & stream() const
get the message stream
SmartIF< IIncidentSvc > m_incSvc
Incident service.
virtual StatusCode reinitialize()
Inherited Service overrides: Service reinitialization.
int outputLevel() const
get the Service's output level
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
std::vector< std::string > m_algMapTools
std::string m_trapType
Trap name.
void analyse(const std::string &s, const char *delim, const char *tagBegin, const char *tagEnd, const char *eq, const char *valBegin, const char *valEnd)
Analyse tokens from string.
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' }
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)
virtual StatusCode initialize()
Inherited Service overrides: Service initialization.
virtual const std::string & name() const =0
Retrieve the name of the instance.
SmartIF< IDataProviderSvc > m_dataSvc
Data provider reference.
ClassH clazz
the actual class
std::list< IDODAlgMapper * > m_algMappers
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.
virtual void handle(const Incident &incident)
IIncidentListener interfaces overrides: incident handling.
bool m_allowInitFailure
flag to allow DataOnDemand initialization to succeed even if the (pre)initialization of the algorithm...
virtual Gaudi::StateMachine::State FSMState() const =0
Get the current state.
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.
void dump(const MSG::Level level, const bool mode=true) const
dump the content of DataOnDemand service
map_type::const_iterator const_iterator
virtual Gaudi::StateMachine::State FSMState() const
Get the current state.
virtual const std::string & name() const
Retrieve name of the service.
virtual StatusCode sysInitialize()
Initialize 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.
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
std::string outputUserTime() const
print the chrono ;
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".
map_type::iterator iterator
SmartIF< IAlgManager > m_algMgr
Algorithm manager.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
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).
bool dataObject
trivial object? DataObject?
DataOnDemandSvc(const std::string &name, ISvcLocator *svc)
Standard initializing service constructor.
Templated class to add the standard messaging functionalities.
virtual StatusCode finalize()
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.
virtual bool isInitialized() const =0
check if the algorithm is initialized properly
Map m_nodeMap
the major configuration property { 'data' : 'type' }
Data service incident class.
const std::string & name() const
implemenattiono fvarioud 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 ~DataOnDemandSvc()
Standard destructor.
A DataObject is the base class of any identifiable object on any data store.
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 reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
void update_2(Property &p)
void toupper(std::string &s)
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
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 update()
update the handlers
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.