/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Utilities/BesTimerSvc/BesTimerSvc-00-00-12/src/BesTimerSvc.cxx

Go to the documentation of this file.
00001 // this is -*- c++ -*-
00002 // $Id: BesTimerSvc.cxx,v 1.4 2011/02/18 04:23:58 maqm Exp $
00003 // $Name: BesTimerSvc-00-00-12 $
00004 #include <algorithm>
00005 #include <string>
00006 #include <vector>
00007 #include "GaudiKernel/Kernel.h"
00008 #include "GaudiKernel/IInterface.h"
00009 #include "GaudiKernel/StatusCode.h"
00010 //#include "GaudiKernel/ISvcFactory.h"
00011 #include "GaudiKernel/SvcFactory.h"
00012 #include "GaudiKernel/MsgStream.h"
00013 #include "BesTimerSvc/BesTimerSvc.h"
00014 
00015 
00016 BesTimerSvc::BesTimerSvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc) {}
00017 
00018 BesTimerSvc::~BesTimerSvc() {
00019   std::vector < BesTimer* >::iterator it =  m_itemList.begin();
00020   for (; it != m_itemList.end(); it++) {
00021     delete (*it);
00022   }  
00023 }
00024 
00025 StatusCode BesTimerSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ) {
00026 
00027   if ( IID_IBesTimerSvc.versionMatch(riid) ) { 
00028     *ppvInterface = static_cast<IBesTimerSvc*> (this); 
00029   } else { 
00030     return Service::queryInterface(riid, ppvInterface) ; 
00031   }
00032   return StatusCode::SUCCESS;
00033 }
00034 StatusCode BesTimerSvc::initialize ( ) {
00035   MsgStream log(messageService(), name());
00036   log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
00037 
00038   StatusCode sc = Service::initialize();
00039   if ( sc.isFailure() ) return sc;
00040   // Set my own properties
00041   setProperties();  
00042   
00043   return StatusCode::SUCCESS;
00044 }
00045 
00046 
00047 StatusCode BesTimerSvc::finalize ( ) {
00048   MsgStream log(messageService(), name());
00049   log << MSG::INFO << name() << ": End of Run Statistics" << endreq;
00050   this->print();
00051   return StatusCode::SUCCESS;
00052 }
00053 
00054 
00055 
00056 BesTimer* BesTimerSvc::addItem(const std::string &itemName) {
00057 
00058   // Create a BesTimer and return a pointer to it
00059   // If an item of that name already exists, flag error
00060   // by returning NULL
00061   
00062   MsgStream log(messageService(), name());
00063   log << MSG::DEBUG << name() << " adding " << itemName  << endreq;
00064   
00065   BesTimer* item = new BesTimer(itemName);
00066   m_itemList.push_back(item);
00067   return item;
00068 }
00069 
00070 void BesTimerSvc::print( ) {
00071   MsgStream log(messageService(), name());
00072 
00073   log << MSG::INFO << "==============================BesTimerSvc::Print===============================" << endreq;
00074   unsigned int maxname=0;
00075   std::vector < BesTimer* >::iterator it =  m_itemList.begin();
00076   for (; it != m_itemList.end(); it++) {
00077     if ((*it)->name().length() > maxname) maxname = static_cast<int>((*it)->name().length());
00078     if (!(*it)->propName().empty()) {
00079       if ((*it)->propName().length() > maxname) maxname = static_cast<int>((*it)->propName().length());
00080     }
00081   }
00082 
00083   it =  m_itemList.begin();
00084   for (; it != m_itemList.end(); it++) {
00085     std::string nam = (*it)->name();
00086     for (unsigned int i = static_cast<int>(nam.length()); i<maxname; i++) nam.insert(i," ");
00087     log << MSG::INFO << nam << "  mean(t) : " << std::setw(12) << (*it)->mean()<< 
00088       " ms      rms : " << std::setw(12) << (*it)->rms() << " ms " << endreq;
00089   }
00090   log << MSG::INFO << "------------------------------------------------------------------------------" << endreq;
00091   it =  m_itemList.begin();
00092   for (; it != m_itemList.end(); it++) {
00093     if (!(*it)->propName().empty()) {
00094       std::string nam = (*it)->name();
00095       for (unsigned int i = static_cast<int>(nam.length()); i<maxname; i++) nam.insert(i," ");
00096       log << MSG::INFO << nam << "  mean(t) : " << std::setw(12) << (*it)->mean()<< 
00097         " ms      rms : " << std::setw(12) << (*it)->rms() << " ms " << endreq;
00098 
00099       nam = (*it)->propName();
00100       for (unsigned int i = static_cast<int>(nam.length()); i<maxname; i++) nam.insert(i," ");
00101       if ((*it)->meanPropVal() == 0) {
00102         log << MSG::INFO << nam << "  mean(N) : " << std::setw(12) << endreq;
00103       } else {
00104         log << MSG::INFO << nam << "  mean(N) : " << std::setw(12) << (*it)->meanPropVal() << 
00105           "   mean(t/N) : " 
00106             << 1000.*(*it)->meanTimePerObject() << " us " << endreq; 
00107       }
00108     }
00109   }
00110 
00111   log << MSG::INFO << "==============================BesTimerSvc::Print===============================" << endreq;
00112   }
00113 
00114 std::vector < BesTimer* >::iterator BesTimerSvc::begin( void ) {
00115   return m_itemList.begin();
00116 }
00117 std::vector < BesTimer* >::iterator BesTimerSvc::end( void ){
00118   return m_itemList.end();
00119 }
00120 

Generated on Tue Nov 29 23:14:42 2016 for BOSS_7.0.2 by  doxygen 1.4.7