Gaudi Framework, version v21r6

Home   Generated: 11 Nov 2009

GaudiCommon.icpp

Go to the documentation of this file.
00001 // $Id: GaudiCommon.icpp,v 1.22 2008/10/10 15:18:56 marcocle Exp $
00002 
00003 // ============================================================================
00004 // CVS tag $Name:  $ version $Revision: 1.22 $
00005 // ============================================================================
00006 // ============================================================================
00007 // include files
00008 // ============================================================================
00009 // STL & STD
00010 // ============================================================================
00011 #include <algorithm>
00012 #include <cstdlib>
00013 // ============================================================================
00014 /* @file GaudiCommon.cpp
00015  *
00016  *  Implementation file for class : GaudiCommon
00017  *
00018  *  @author Chris Jones   Christopher.Rob.Jones@cern.ch
00019  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
00020  *  @author Rob Lambert Rob.Lambert@cern.ch
00021  *  @date   2009-08-04
00022  */
00023 // GaudiKernel
00024 // ============================================================================
00025 #include "GaudiKernel/IDataProviderSvc.h"
00026 #include "GaudiKernel/IToolSvc.h"
00027 #include "GaudiKernel/IProperty.h"
00028 #include "GaudiKernel/Property.h"
00029 #include "GaudiKernel/ISvcLocator.h"
00030 #include "GaudiKernel/MsgStream.h"
00031 #include "GaudiKernel/ObjectVector.h"
00032 #include "GaudiKernel/SmartDataPtr.h"
00033 #include "GaudiKernel/SmartRef.h"
00034 #include "GaudiKernel/Stat.h"
00035 #include "GaudiKernel/System.h"
00036 #include "GaudiKernel/IJobOptionsSvc.h"
00037 #include "GaudiKernel/StatEntity.h"
00038 #include "GaudiKernel/Algorithm.h"
00039 #include "GaudiKernel/AlgTool.h"
00040 // ============================================================================
00041 // GaudiAlg
00042 // ============================================================================
00043 #include "GaudiAlg/Print.h"
00044 #include "GaudiAlg/GaudiCommon.h"
00045 #include "GaudiAlg/GaudiAlgorithm.h"
00046 #include "GaudiAlg/GaudiTool.h"
00047 // ============================================================================
00048 // GaudiUtils
00049 // ============================================================================
00050 #include "GaudiUtils/RegEx.h"
00051 // ============================================================================
00052 // Boost
00053 // ============================================================================
00054 #include "boost/format.hpp"
00055 #include "boost/lexical_cast.hpp"
00056 // ============================================================================
00057 // Disable warning on windows
00058 #ifdef _WIN32
00059 #pragma warning ( disable:4661 ) // incomplete explicit templates
00060 #endif
00061 // ============================================================================
00062 
00063 //=============================================================================
00064 // Destructor
00065 //=============================================================================
00066 template < class PBASE >
00067 GaudiCommon<PBASE>::~GaudiCommon() { resetMsgStream(); }
00068 //==========================================================================
00069 
00070 // ============================================================================
00071 // constructor initialisation
00072 // ============================================================================
00073 template <class PBASE>
00074 void
00075 GaudiCommon<PBASE>::initGaudiCommonConstructor( const IInterface * parent )
00076 {
00077   // initialise data members
00078   m_msgLevel    = MSG::NIL;
00079   m_msgStream   = 0;
00080   m_updMgrSvc   = 0;
00081   m_fastContainersSvc   = 0;
00082   m_typePrint   = true;
00083   m_propsPrint  = false;
00084   m_statPrint   = true;
00085   m_errorsPrint = true;
00086   m_context     = "" ;
00087   m_rootInTES   = "" ;
00088   m_globalTimeOffset = 0.0 ;
00089   //data members for the CounterSummarySvc
00090   m_counterSummarySvc=NULL;
00091   m_counterList=std::vector<std::string>(1,".*");
00092   m_statEntityList=std::vector<std::string>(0);
00093 
00094   // printout of counters:
00095 
00096   // the header row for counters printout
00097   m_header  = " |    Counter                                      |     #     |    sum     | mean/eff^* | rms/err^*  |     min     |     max     |" ;
00098   // format for regular statistical printout rows
00099   m_format1 = " | %|-48.48s|%|50t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |" ;
00100   // format for "efficiency" statistical printout rows
00101   m_format2 = " |*%|-48.48s|%|50t||%|10d| |%|11.5g| |(%|#9.6g| +- %|-#9.6g|)%%|   -------   |   -------   |" ;
00102   // flag to use the special "efficiency" format
00103   m_useEffFormat = true ; 
00104 
00105   // job options
00106   // print error counters at finalization ?
00107   this->declareProperty 
00108     ( "ErrorsPrint"     , m_errorsPrint     , 
00109       "Print the statistics of errors/warnings/exceptions") 
00110     -> declareUpdateHandler
00111     ( &GaudiCommon<PBASE>::printErrorHandler, this  ) ;
00112   // print properties at initialization?
00113   this->declareProperty 
00114     ( "PropertiesPrint" , m_propsPrint  ,
00115       "Print the properties of the component ") 
00116     -> declareUpdateHandler
00117     ( &GaudiCommon<PBASE>::printPropsHandler, this  ) ;
00118   // print statistical counters at finalization ?
00119   this->declareProperty 
00120     ( "StatPrint"       , m_statPrint   , 
00121       "Print the table of counters"  ) 
00122     -> declareUpdateHandler
00123     ( &GaudiCommon<PBASE>::printStatHandler, this  ) ;    
00124   // insert  the actual C++ type of the algorithm or tool in the messages?
00125   this->declareProperty 
00126     ( "TypePrint"       , m_typePrint   , 
00127       "Add the actal C++ component type into the messages" ) ;
00128   // context
00129   this->declareProperty ( "Context"         , m_context     ) ;
00130   // root in TES
00131   this->declareProperty ( "RootInTES"       , m_rootInTES   ) ;
00132   // root on TES ( temporary )
00133   this->declareProperty ( "RootOnTES"       , m_rootOnTES   ) ;
00134   // global time offset
00135   this->declareProperty ( "GlobalTimeOffset", m_globalTimeOffset ) ;
00136 
00137 
00138   // the header row for counters printout
00139   this->declareProperty
00140     ( "StatTableHeader"        , m_header                          ,
00141       "The header row for the output Stat-table"                   ) ;
00142   // format for regular statistical printout rows
00143   this->declareProperty
00144     ( "RegularRowFormat"       , m_format1                         ,
00145       "The format for the regular row in the output Stat-table"    ) ;
00146   // format for "efficiency" statistical printout rows
00147   this->declareProperty
00148     ( "EfficiencyRowFormat"    , m_format2                         ,
00149       "The format for the regular row in the output Stat-table"    ) ;
00150   // flag to use the special "efficiency" format
00151   this->declareProperty
00152     ( "UseEfficiencyRowFormat" , m_useEffFormat                    ,
00153       "Use the special format for printout of efficiency counters" ) ;
00154         
00155 
00156   //declare the list of simple counters to write.
00157   this->declareProperty(
00158         "CounterList",
00159         m_counterList=std::vector<std::string>(1,".*"),
00160         "RegEx list, of simple integer counters for CounterSummary.");
00161   //declare the list of stat entities to write.
00162   this->declareProperty(
00163         "StatEntityList",
00164         m_statEntityList=std::vector<std::string>(0),
00165         "RegEx list, of StatEntity counters for CounterSummary.");
00166   
00167   // add handler for message level changes
00168   this->outputLevelProperty().declareUpdateHandler( &GaudiCommon<PBASE>::msgLevelHandler, this );
00169 
00170   // setup context from parent if available
00171   if ( parent )
00172   {
00173     if      ( const GaudiAlgorithm* gAlg = dynamic_cast<const GaudiAlgorithm*>(parent) )
00174     {
00175       m_context = gAlg->context();
00176       m_rootInTES = gAlg->rootInTES();
00177       m_globalTimeOffset = gAlg->globalTimeOffset();
00178     }
00179     else if ( const GaudiTool*     gTool = dynamic_cast<const GaudiTool*>     (parent) )
00180     {
00181       m_context = gTool->context();
00182       m_rootInTES = gTool->rootInTES();
00183       m_globalTimeOffset = gTool->globalTimeOffset();
00184     }
00185   }
00186 
00187   // Get the job option service
00188   IJobOptionsSvc* jos = svc<IJobOptionsSvc>( "JobOptionsSvc" );
00189 
00190   // Get the "Context" option if in the file...
00191   const std::vector<const Property*>* myList = jos->getProperties( this->name() );
00192   if ( 0 != myList )
00193   {
00194     // Iterate over the list to set the options
00195     for ( std::vector<const Property*>::const_iterator iter = myList->begin();
00196           iter != myList->end();
00197           ++iter )
00198     {
00199       const StringProperty* sp = dynamic_cast<const StringProperty*>(*iter);
00200       if ( 0 != sp )
00201       {
00202         if ( "Context" == (*iter)->name() )
00203         {
00204           m_context = sp->value();
00205         } else if ( "RootInTES" == (*iter)->name() ) {
00206           m_rootInTES = sp->value();
00207         } else if ( "GlobalTimeOffset" == (*iter)->name() ) {
00208           m_globalTimeOffset = atof( sp->value().c_str() );
00209         }
00210       }
00211     }
00212   }
00213 
00214   // release tool
00215   release( jos ).ignore();
00216 
00217 }
00218 //=============================================================================
00219 
00220 //=============================================================================
00221 // Initialise the common functionality
00222 //=============================================================================
00223 template < class PBASE >
00224 StatusCode GaudiCommon<PBASE>::initialize()
00225 {
00226 
00227   // initialize base class
00228   const StatusCode sc = PBASE::initialize();
00229   if ( sc.isFailure() )
00230   { return Error ( "Failed to initialise base class PBASE", sc ) ; }
00231 
00232 
00233   // some debug printout
00234   if ( msgLevel(MSG::DEBUG) )
00235   {
00236     debug() << "Initialize base class GaudiCommon<" << System::typeinfoName(typeid(PBASE)) << ">" << endmsg;
00237     if ( !context().empty() )
00238       debug() << "Created with context = '" << context() << "'" << endmsg;
00239   }
00240 
00241   // some temporary checks to see if people are using RootOnTES and warn if so
00242   // TO BE REMOVED ASAP ...
00243   if ( m_rootInTES.empty() && !m_rootOnTES.empty() )
00244   {
00245     m_rootInTES = m_rootOnTES;
00246     Warning( "RootOnTES option is OBSOLETE -> Use RootInTES instead. RootInTES has been updated to "
00247              + m_rootInTES, StatusCode::SUCCESS ).ignore();
00248   }
00249   else if ( !m_rootInTES.empty() && !m_rootOnTES.empty() )
00250   {
00251     Warning( "Options RootOnTES AND RootInTES are defined ! Use RootInTES. RootOnTES is ignored",
00252              StatusCode::SUCCESS ).ignore();
00253   }
00254 
00255   // Check rootInTES ends with a /
00256   if ( !m_rootInTES.empty() &&
00257        m_rootInTES.substr(m_rootInTES.size()-1) != "/" ) m_rootInTES += "/";
00258   
00259   //Set up the CounterSummarySvc May need to be changed
00260   this->svcLoc()->service("CounterSummarySvc",m_counterSummarySvc,false).ignore() ;
00261   if (msgLevel(MSG::DEBUG))
00262   {
00263     if (m_counterSummarySvc==NULL )  
00264         debug() <<  "could not locate CounterSummarySvc, no counter summary will be made" << endmsg;
00265     else debug() <<  "found CounterSummarySvc OK" << endmsg;
00266   }
00267 
00268   // properties will be printed if asked for or in "MSG::DEBUG" mode
00269   if      ( propsPrint()         ) { printProps(MSG::ALWAYS); }
00270   else if ( msgLevel(MSG::DEBUG) ) { printProps(MSG::DEBUG);  }
00271 
00272   return sc;
00273 }
00274 //=============================================================================
00275 
00276 //=============================================================================
00277 // Finalize the common functionality
00278 //=============================================================================
00279 template < class PBASE >
00280 StatusCode GaudiCommon<PBASE>::finalize()
00281 {
00282   StatusCode sc = StatusCode::SUCCESS;
00283 
00284   // print the general information about statistical counters
00285   if ( msgLevel(MSG::DEBUG) || (statPrint() && !counters().empty()) )
00286   {
00287     // print general statistical counters
00288     printStat ( statPrint() ? MSG::ALWAYS : MSG::DEBUG ) ;
00289   }
00290   //add all counters to the CounterSummarySvc
00291   if(m_counterSummarySvc && this->svcLoc()->existsService("CounterSummarySvc"))
00292   {
00293     if ( msgLevel(MSG::DEBUG) ) debug() << "adding counters to CounterSummarySvc" << endmsg;
00294     for(Statistics::const_iterator i=this->counters().begin();
00295         i!=this->counters().end();
00296         i++)
00297     {
00298       if(Gaudi::Utils::RegEx::matchOr(i->first,m_statEntityList))
00299         m_counterSummarySvc->addCounter(this->name(),i->first,i->second,
00300                                         Gaudi::CounterSummary::SaveStatEntity);
00301       else if(Gaudi::Utils::RegEx::matchOr(i->first,m_counterList))
00302         m_counterSummarySvc->addCounter(this->name(),i->first,i->second);
00303     }
00304   }
00305   // release all located tools and services
00306   if ( msgLevel(MSG::DEBUG) )
00307   {
00308     debug() << "Tools to release :";
00309     for ( AlgTools::const_iterator i = m_tools.begin();
00310           i != m_tools.end(); ++i )
00311     {
00312       debug() << " " << (*i)->name();
00313     }
00314     debug() << endmsg;
00315   }
00316   while ( !m_tools.empty() ) { sc = sc && releaseTool( m_tools.back() ) ; }
00317 
00318   // release all located services
00319   if ( msgLevel(MSG::DEBUG) )
00320   {
00321     debug() << "Services to release :";
00322     for ( Services::const_iterator i = m_services.begin();
00323           i != m_services.end(); ++i )
00324     {
00325       debug() << " " << (*i).first;
00326     }
00327     debug() << endmsg;
00328   }
00329   while ( !m_services.empty() ) { sc = sc && releaseSvc( m_services.begin()->second ) ; }
00330   
00331   //release the CounterSummarySvc manually
00332   if(m_counterSummarySvc) 
00333   {
00334     m_counterSummarySvc->release();
00335     m_counterSummarySvc=NULL;
00336   }
00337   
00338   // format printout
00339   if ( !m_errors.empty() || !m_warnings.empty() || !m_exceptions.empty() )
00340   {
00341     always() << "Exceptions/Errors/Warnings/Infos Statistics : "
00342              << m_exceptions .size () << "/"
00343              << m_errors     .size () << "/"
00344              << m_warnings   .size () << "/"
00345              << m_infos      .size () << endmsg ;
00346     if ( errorsPrint() ) { printErrors () ; }
00347   }
00348 
00349   // delete the MsgStream
00350   resetMsgStream();
00351 
00352   // clear *ALL* counters explicitly
00353   m_counters   .clear() ;
00354   m_exceptions .clear() ;
00355   m_infos      .clear() ;
00356   m_warnings   .clear() ;
00357   m_errors     .clear() ;
00358   m_counterList.clear() ;
00359   m_statEntityList.clear() ;
00360 
00361   // finalize base class
00362   return sc && PBASE::finalize();
00363 }
00364 //=============================================================================
00365 
00366 //=============================================================================
00367 // Methods related to tools and services
00368 //=============================================================================
00369 
00370 // ============================================================================
00371 // manual forced (and 'safe') release of the active tool or service
00372 // ============================================================================
00373 template < class PBASE >
00374 StatusCode GaudiCommon<PBASE>::release ( const IInterface* interface ) const
00375 {
00376   if ( 0 == interface )
00377   { return Error ( "release(IInterface):: IInterface* points to NULL!" ) ; }
00378   // dispatch between tools and services
00379   const IAlgTool* algTool = dynamic_cast<const IAlgTool*>( interface )  ;
00380   // perform the actual release
00381   return 0 != algTool ? releaseTool( algTool ) : releaseSvc( interface ) ;
00382 }
00383 // ============================================================================
00384 
00385 // ============================================================================
00386 // manual forced (and 'save') release of the tool
00387 // ============================================================================
00388 template < class PBASE >
00389 StatusCode GaudiCommon<PBASE>::releaseTool ( const IAlgTool* algTool ) const
00390 {
00391   if( 0 == algTool   )
00392   { return Error ( "releaseTool(IAlgTool):: IAlgTool* points to NULL!" ) ; }
00393   if( this->toolSvc() == 0 )
00394   { return Error ( "releaseTool(IAlgTool):: IToolSvc* points to NULL!" ) ; }
00395   // find a tool in the list of active tools
00396   AlgTools::reverse_iterator it =
00397     std::find( m_tools.rbegin() , m_tools.rend() , algTool ) ;
00398   if(  m_tools.rend() == it )
00399   { return Warning("releaseTool(IAlgTool):: IAlgTool* is not active"   ) ; }
00400   // get the tool
00401   IAlgTool* t = *it ;
00402   // cache name
00403   const std::string name = t->name();
00404   if ( msgLevel(MSG::DEBUG) )
00405   { debug() << "Releasing tool '" << name << "'" << endmsg; }
00406   // remove the tool from the lists
00407   m_tools.erase( --it.base() ) ;
00408   // release tool
00409   const StatusCode sc = this->toolSvc()->releaseTool( t ) ;
00410   if ( sc.isFailure() )
00411   { return Warning ( "releaseTool(IAlgTool):: error from IToolSvc whilst releasing "+name , sc ) ; }
00412   // return final status code
00413   return sc ;
00414 }
00415 // ============================================================================
00416 
00417 // ============================================================================
00418 // manual forced (and 'safe') release of the service
00419 // ============================================================================
00420 template < class PBASE >
00421 StatusCode GaudiCommon<PBASE>::releaseSvc ( const IInterface* Svc  ) const
00422 {
00423   if( 0 == Svc ) {
00424     return Error ( "releaseSvc(IInterface):: IInterface* points to NULL!" ) ;
00425   }
00426   SmartIF<IService> svc(const_cast<IInterface*>(Svc));
00427   if (svc.isValid()) {
00428     Services::iterator it = m_services.find(svc->name());
00429     if (it == m_services.end()) {
00430       return Warning( "releaseSvc(IInterface):: IInterface* is not active" );
00431     }
00432     if ( msgLevel(MSG::DEBUG) ) {
00433       debug() << "Releasing service '" << it->first << "'" << endmsg;
00434     }
00435     m_services.erase(it);
00436     return StatusCode::SUCCESS;
00437   }
00438   return Warning( "releaseSvc(IInterface):: IInterface* is not a service" );
00439 }
00440 // ============================================================================
00441 
00442 // ============================================================================
00443 // Add the given tool to the list of active tools
00444 // ============================================================================
00445 template < class PBASE >
00446 void GaudiCommon<PBASE>::addToToolList( IAlgTool * tool ) const
00447 {
00448   m_tools.push_back( tool ) ;
00449 }
00450 // ============================================================================
00451 
00452 // ============================================================================
00453 // Add the given service to the list of active services
00454 // ============================================================================
00455 template < class PBASE >
00456 void GaudiCommon<PBASE>::addToServiceList( const SmartIF<IService>& svc ) const
00457 {
00458   if (svc.isValid()) {
00459     m_services[svc->name()] = svc;
00460   }
00461 }
00462 // ============================================================================
00463 
00464 //=============================================================================
00465 // Methods related to messaging
00466 //=============================================================================
00467 
00468 // ============================================================================
00469 // Print the error  message and return status code
00470 // ============================================================================
00471 template < class PBASE >
00472 StatusCode GaudiCommon<PBASE>::Error( const std::string& msg ,
00473                                       const StatusCode   st  ,
00474                                       const size_t       mx  ) const
00475 {
00476   // increase local counter of errors
00477   const size_t num = ++m_errors[msg] ;
00478   // If suppressed, just return
00479   if      ( num  > mx ) { return st ; }
00480   else if ( num == mx ) // issue one-time suppression message
00481   { return Print ( "The   ERROR message is suppressed : '" +
00482                    msg + "'" , st , MSG::ERROR ) ; }
00483   // return message
00484   return Print ( msg , st , MSG::ERROR ) ;
00485 }
00486 // ============================================================================
00487 
00488 // ============================================================================
00489 // Print the warning  message and return status code
00490 // ============================================================================
00491 template < class PBASE >
00492 StatusCode GaudiCommon<PBASE>::Warning
00493 ( const std::string& msg ,
00494   const StatusCode   st  ,
00495   const size_t       mx  ) const
00496 {
00497   // increase local counter of warnings
00498   const size_t num = ++m_warnings[msg] ;
00499   // If suppressed, just return
00500   if      ( num  > mx ) { return st ; }
00501   else if ( num == mx ) // issue one-time suppression message
00502   { return Print ( "The WARNING message is suppressed : '" +
00503                    msg + "'" , st , MSG::WARNING ) ; }
00504   // return message
00505   return Print ( msg , st , MSG::WARNING ) ;
00506 }
00507 // ============================================================================
00508 
00509 // ============================================================================
00510 // Print the info message and return status code
00511 // ============================================================================
00512 template < class PBASE >
00513 StatusCode GaudiCommon<PBASE>::Info
00514 ( const std::string& msg ,
00515   const StatusCode   st  ,
00516   const size_t       mx  ) const
00517 {
00518   // increase local counter of warnings
00519   const size_t num = ++m_infos[msg] ;
00520   // If suppressed, just return
00521   if      ( num  > mx ) { return st ; }
00522   else if ( num == mx ) // issue one-time suppression message
00523   { return Print ( "The INFO message is suppressed : '" +
00524                    msg + "'" , st , MSG::INFO ) ; }
00525   // return message
00526   return Print ( msg , st , MSG::INFO ) ;
00527 }
00528 // ============================================================================
00529 
00530 // ============================================================================
00531 //  Print the message and return status code
00532 // ============================================================================
00533 template < class PBASE >
00534 StatusCode GaudiCommon<PBASE>::Print( const std::string& msg ,
00535                                       const StatusCode   st  ,
00536                                       const MSG::Level   lvl ) const
00537 {
00538   // perform printout ?
00539   if ( !msgLevel( lvl ) ) { return st ; }   // RETURN
00540 
00541   // use the predefined stream
00542   MsgStream& str = msgStream( lvl ) ;
00543   if ( typePrint() ) { str << System::typeinfoName(typeid(*this)) << ":: " ; }
00544   // print the message
00545   str  << msg ;
00546   // test status code
00547   if      ( st.isSuccess() ) { }
00548   else if ( StatusCode::FAILURE != st.getCode() )
00549   { str << " StatusCode=" << st.getCode() ; }
00550   else
00551   { str << " StatusCode=FAILURE" ; }
00552   // perform print operation
00553   str << endmsg ;
00554   // return
00555   return  st;
00556 }
00557 // ============================================================================
00558 
00559 // ============================================================================
00560 // Create and (re)-throw the exception
00561 // ============================================================================
00562 template < class PBASE >
00563 StatusCode GaudiCommon<PBASE>::Exception( const std::string    & msg ,
00564                                           const GaudiException & exc ,
00565                                           const StatusCode       sc  ) const
00566 {
00567   // increase local counter of exceptions
00568   ++m_exceptions[ msg ];
00569   Print ( "Exception (re)throw: " + msg , sc , MSG::FATAL );
00570   throw   GaudiException( this->name() + ":: " + msg , this->name() , sc, exc);
00571   return  sc ;
00572 }
00573 // ============================================================================
00574 
00575 // ============================================================================
00576 // Create and (re)-throw the exception
00577 // ============================================================================
00578 template < class PBASE >
00579 StatusCode GaudiCommon<PBASE>::Exception( const std::string    & msg ,
00580                                           const std::exception & exc ,
00581                                           const StatusCode       sc  ) const
00582 {
00583   // increase local counter of exceptions
00584   ++m_exceptions[ msg ];
00585   Print ( "Exception (re)throw: " + msg , sc , MSG::FATAL  );
00586   throw GaudiException( this->name() + ":: " + msg+"("+exc.what()+")", "", sc );
00587   return  sc ;
00588 }
00589 // ============================================================================
00590 
00591 // ============================================================================
00592 // Create and throw the exception
00593 // ============================================================================
00594 template < class PBASE >
00595 StatusCode GaudiCommon<PBASE>::Exception( const std::string    & msg ,
00596                                           const StatusCode       sc  ) const
00597 {
00598   // increase local counter of exceptions
00599   ++m_exceptions[ msg ];
00600   Print ( "Exception throw: " + msg , sc , MSG::FATAL );
00601   throw GaudiException( this->name() + ":: " + msg , "",  sc );
00602   return  sc ;
00603 }
00604 // ============================================================================
00605 
00606 // ============================================================================
00607 // perform the actual printout of counters
00608 // ============================================================================
00609 template < class PBASE >
00610 long GaudiCommon<PBASE>::printStat( const MSG::Level level ) const
00611 {
00612   // print statistics
00613   if ( counters().empty() ) { return 0 ; }
00614   MsgStream& msg = msgStream ( level ) ;
00615   //
00616   msg << "Number of counters : "  << counters().size() ;
00617   //
00618   if ( !counters().empty() ) { msg << std::endl << m_header ; }
00619   //
00620   for ( Statistics::const_iterator entry = counters().begin() ;
00621         counters().end() != entry ; ++entry )
00622   {
00623     msg << std::endl
00624         << Gaudi::Utils::formatAsTableRow
00625       ( entry -> first  ,
00626         entry -> second ,
00627         m_useEffFormat  ,
00628         m_format1       , m_format2 );
00629   }
00630   //
00631   msg << endmsg ;
00632   //
00633   return counters().size() ;
00634 }
00635 // ============================================================================
00636 
00637 // ============================================================================
00638 // perform the actual printout of error counters
00639 // ============================================================================
00640 template < class PBASE >
00641 long GaudiCommon<PBASE>::printErrors ( const MSG::Level level ) const
00642 {
00643   // format for printout
00644   boost::format ftm ( " %s = %|.8s| %|23t| Message = '%s'" );
00645 
00646   { // print exceptions
00647     for ( Counter::const_iterator excp = m_exceptions.begin() ;
00648           excp  != m_exceptions.end() ; ++excp  )
00649     {
00650       msgStream(level)
00651         << ( ftm % "#EXCEPTIONS" % excp->second % excp->first       )
00652         << endmsg;
00653     }
00654   }
00655   { // print errors
00656     for ( Counter::const_iterator error = m_errors.begin() ;
00657           error != m_errors.end() ; ++error )
00658     {
00659       msgStream(level)
00660         << ( ftm % "#ERRORS    " % error->second % error->first     )
00661         << endmsg;
00662     }
00663   }
00664   { // print warnings
00665     for ( Counter::const_iterator warning = m_warnings.begin() ;
00666           warning != m_warnings.end() ; ++warning )
00667     {
00668       msgStream(level)
00669         << ( ftm % "#WARNINGS  " % warning->second % warning->first )
00670         << endmsg;
00671     }
00672   }
00673   { // print warnings
00674     for ( Counter::const_iterator info = m_infos.begin() ;
00675     info != m_infos.end() ; ++info )
00676     {
00677       msgStream(level)
00678         << ( ftm % "#INFOS     " % info->second % info->first )
00679         << endmsg;
00680     }
00681   }
00682 
00683   // return total number of errors+warnings+exceptions
00684   return
00685     m_exceptions .size () +
00686     m_errors     .size () +
00687     m_warnings   .size () +
00688     m_infos      .size () ;
00689 }
00690 // ============================================================================
00691 
00692 // ============================================================================
00696 // ============================================================================
00697 template < class PBASE >
00698 long GaudiCommon<PBASE>::printProps ( const MSG::Level level ) const
00699 {
00700 
00701   // print ALL properties
00702   MsgStream& msg = msgStream ( level );
00703   typedef std::vector<Property*> Properties;
00704   const Properties& properties = this->getProperties() ;
00705   msg << "List of ALL properties of "
00706       << System::typeinfoName( typeid( *this ) ) << "/" << this->name()
00707       << "  #properties = " << properties.size() << endmsg ;
00708   for ( Properties::const_reverse_iterator property
00709           = properties.rbegin() ;
00710         properties.rend() != property ; ++property )
00711   {
00712     msg << "Property ['Name': Value] = "
00713         << ( **property)
00714         << endmsg ;
00715   }
00716   return properties.size() ;
00717 }
00718 // ============================================================================
00719 
00720 // ============================================================================
00721 // Handle method for changes in the Messaging levels
00722 // ============================================================================
00723 template < class PBASE >
00724 void GaudiCommon<PBASE>::msgLevelHandler ( Property & theProp )
00725 {
00726   // Force a new MsgStream object, to pick up the new settings
00727   resetMsgStream();
00728 
00729   // adjust internal message level
00730   m_msgLevel =
00731     this->outputLevel() <  (int) MSG::NIL        ?  MSG::NIL    :
00732     this->outputLevel() >= (int) MSG::NUM_LEVELS ?  MSG::ALWAYS :
00733     MSG::Level( this->outputLevel() ) ;
00734 
00735   // Keep MessageSvc up to date if needed
00736   if ( this->msgSvc()->outputLevel(this->name()) != this->outputLevel() )
00737   {
00738     this->msgSvc()->setOutputLevel( this->name(), this->outputLevel() );
00739   }
00740 
00741   // printout message
00742   if ( msgLevel(MSG::DEBUG) )
00743   {
00744     debug() << "Property update for "
00745             << theProp.name() << " : new value = " << this->outputLevel() << endmsg;
00746   }
00747 }
00748 // ============================================================================
00749 
00750 // ============================================================================
00751 // Methods for dealing with the TES and TDS
00752 // ============================================================================
00753 
00754 // ============================================================================
00755 // put results into Gaudi Event Transient Store
00756 // ============================================================================
00757 template < class PBASE >
00758 DataObject* GaudiCommon<PBASE>::put ( IDataProviderSvc*  svc     ,
00759                                DataObject*        object  ,
00760                                const std::string& location ,
00761                                const bool useRootInTES ) const
00762 {
00763   // check arguments
00764   Assert ( 0 != svc              , "put():: Invalid 'service'!"       ) ;
00765   Assert ( 0 != object           , "put():: Invalid 'Object'!"        ) ;
00766   Assert ( !location.empty()     , "put():: Invalid 'address' = '' "  ) ;
00767   // final data location
00768   const std::string & fullLocation = fullTESLocation( location, useRootInTES );
00769   // register the object!
00770   const StatusCode status = '/' == fullLocation[0] ?
00771     svc -> registerObject(             fullLocation , object ) :
00772     svc -> registerObject( "/Event/" + fullLocation , object ) ;
00773   // check the result!
00774   if ( status.isFailure() )
00775   { Exception ( "put():: could not register '"            +
00776                 System::typeinfoName( typeid( *object ) ) +
00777                 "' at address '" + fullLocation + "'"  , status ) ; }
00778   if ( msgLevel( MSG::DEBUG ) )
00779   { Print( "The object of type '"                    +
00780            System::typeinfoName( typeid( *object ) ) +
00781            "' is registered in TS at address '"
00782            + fullLocation + "'" , status , MSG::DEBUG ) ; }
00783   return object;
00784 }
00785 // ============================================================================
00786 
00787 // ============================================================================
00788 // Handle method for changes in the 'ErrorsPrint'
00789 // ============================================================================
00790 template < class PBASE >
00791 void GaudiCommon<PBASE>::printErrorHandler ( Property& /* theProp */ )
00792 {
00793   // no action if not yet initialized 
00794   if ( this -> FSMState() < Gaudi::StateMachine::INITIALIZED ) { return ; }
00795   if ( this -> errorsPrint() ) { this -> printErrors () ; }
00796 }
00797 // ============================================================================
00798 // Handle method for changes in the 'PropertiesPrint'
00799 // ============================================================================
00800 template < class PBASE >
00801 void GaudiCommon<PBASE>::printPropsHandler ( Property& /* theProp */ )
00802 {
00803   // no action if not yet initialized 
00804   if ( this -> FSMState() < Gaudi::StateMachine::INITIALIZED ) { return ; }
00805   if ( this -> propsPrint() ) { this -> printProps ( MSG::ALWAYS ) ; }
00806 }
00807 // ============================================================================
00808 // Handle method for changes in the 'StatPrint'
00809 // ============================================================================
00810 template < class PBASE >
00811 void GaudiCommon<PBASE>::printStatHandler ( Property& /* theProp */ )
00812 {
00813   // no action if not yet initialized 
00814   if ( this -> FSMState() < Gaudi::StateMachine::INITIALIZED ) { return ; }
00815   if ( this -> statPrint() ) { this -> printStat ( MSG::ALWAYS ) ; }
00816 }
00817 // ============================================================================
00818 
00819 
00820 // ============================================================================
00821 // The END 
00822 // ============================================================================
00823 
00824 

Generated at Wed Nov 11 16:22:57 2009 for Gaudi Framework, version v21r6 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004