| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

# GaudiCommon.icpp

Go to the documentation of this file.

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines