Gaudi Framework, version v21r7

Home   Generated: 22 Jan 2010

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

Generated at Fri Jan 22 20:27:28 2010 for Gaudi Framework, version v21r7 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004