| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

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

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