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;
258 Leaf leaf(alg.type(), alg.name());
266 leaf =
Leaf(alg.type(), alg.name());
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();
572 Gaudi::Utils::TypeNameString
item(typ);
578 <<
"The obsolete property 'Algorithms' redefines the action for '"
579 + tag +
"' to be '" +item.type() +
"/"+item.name()+
"'"
582 m_algMap[tag] = 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) {}
649 inline Gaudi::Utils::TypeNameString operator() (
IDODAlgMapper *t)
const {
656 inline bool isGood(
const std::string& r) {
return !r.empty();}
657 inline bool isGood(
const Gaudi::Utils::TypeNameString& r) {
return !r.name().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);
687 inline Gaudi::Utils::TypeNameString alg()
const {
688 return find<Gaudi::Utils::TypeNameString>(algs);
707 if ( 0 == inc ) { return ; }
714 <<
"Incident: [" << incident.
type () <<
"] "
715 <<
" = " << incident.
source ()
716 <<
" Location:" << inc->tag() <<
endmsg;
720 Gaudi::StringKey tag ( inc->tag() ) ;
741 verbose() <<
"Try to find mapping with mapping tools" <<
endmsg;
744 std::string node = finder.node();
755 Gaudi::Utils::TypeNameString alg = finder.alg();
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 ;