BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTimerSvc.cxx
Go to the documentation of this file.
1// this is -*- c++ -*-
2// $Id: BesTimerSvc.cxx,v 1.5 2022/01/12 04:44:15 maqm Exp $
3// $Name: BesTimerSvc-00-01-00 $
4#include <algorithm>
5#include <string>
6#include <vector>
7#include "GaudiKernel/Kernel.h"
8#include "GaudiKernel/IInterface.h"
9#include "GaudiKernel/StatusCode.h"
10//#include "GaudiKernel/ISvcFactory.h"
11#include "GaudiKernel/SvcFactory.h"
12#include "GaudiKernel/MsgStream.h"
14
15DECLARE_COMPONENT(BesTimerSvc)
16
17BesTimerSvc::BesTimerSvc( const std::string& name, ISvcLocator* svcloc ) : base_class(name, svcloc) {}
18
20 std::vector < BesTimer* >::iterator it = m_itemList.begin();
21 for (; it != m_itemList.end(); it++) {
22 delete (*it);
23 }
24}
25
26/*StatusCode BesTimerSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ) {
27
28 if ( IID_IBesTimerSvc.versionMatch(riid) ) {
29 *ppvInterface = static_cast<IBesTimerSvc*> (this);
30 } else {
31 return Service::queryInterface(riid, ppvInterface) ;
32 }
33 return StatusCode::SUCCESS;
34}*/
36 MsgStream log(messageService(), name());
37 log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
38
39 StatusCode sc = Service::initialize();
40 if ( sc.isFailure() ) return sc;
41 // Set my own properties
42 setProperties();
43
44 return StatusCode::SUCCESS;
45}
46
47
48StatusCode BesTimerSvc::finalize ( ) {
49 MsgStream log(messageService(), name());
50 log << MSG::INFO << name() << ": End of Run Statistics" << endreq;
51 this->print();
52 return StatusCode::SUCCESS;
53}
54
55
56
57BesTimer* BesTimerSvc::addItem(const std::string &itemName) {
58
59 // Create a BesTimer and return a pointer to it
60 // If an item of that name already exists, flag error
61 // by returning NULL
62
63 MsgStream log(messageService(), name());
64 log << MSG::DEBUG << name() << " adding " << itemName << endreq;
65
66 BesTimer* item = new BesTimer(itemName);
67 m_itemList.push_back(item);
68 return item;
69}
70
72 MsgStream log(messageService(), name());
73
74 log << MSG::INFO << "==============================BesTimerSvc::Print===============================" << endreq;
75 unsigned int maxname=0;
76 std::vector < BesTimer* >::iterator it = m_itemList.begin();
77 for (; it != m_itemList.end(); it++) {
78 if ((*it)->name().length() > maxname) maxname = static_cast<int>((*it)->name().length());
79 if (!(*it)->propName().empty()) {
80 if ((*it)->propName().length() > maxname) maxname = static_cast<int>((*it)->propName().length());
81 }
82 }
83
84 it = m_itemList.begin();
85 for (; it != m_itemList.end(); it++) {
86 std::string nam = (*it)->name();
87 for (unsigned int i = static_cast<int>(nam.length()); i<maxname; i++) nam.insert(i," ");
88 log << MSG::INFO << nam << " mean(t) : " << std::setw(12) << (*it)->mean()<<
89 " ms rms : " << std::setw(12) << (*it)->rms() << " ms " << endreq;
90 }
91 log << MSG::INFO << "------------------------------------------------------------------------------" << endreq;
92 it = m_itemList.begin();
93 for (; it != m_itemList.end(); it++) {
94 if (!(*it)->propName().empty()) {
95 std::string nam = (*it)->name();
96 for (unsigned int i = static_cast<int>(nam.length()); i<maxname; i++) nam.insert(i," ");
97 log << MSG::INFO << nam << " mean(t) : " << std::setw(12) << (*it)->mean()<<
98 " ms rms : " << std::setw(12) << (*it)->rms() << " ms " << endreq;
99
100 nam = (*it)->propName();
101 for (unsigned int i = static_cast<int>(nam.length()); i<maxname; i++) nam.insert(i," ");
102 if ((*it)->meanPropVal() == 0) {
103 log << MSG::INFO << nam << " mean(N) : " << std::setw(12) << endreq;
104 } else {
105 log << MSG::INFO << nam << " mean(N) : " << std::setw(12) << (*it)->meanPropVal() <<
106 " mean(t/N) : "
107 << 1000.*(*it)->meanTimePerObject() << " us " << endreq;
108 }
109 }
110 }
111
112 log << MSG::INFO << "==============================BesTimerSvc::Print===============================" << endreq;
113 }
114
115std::vector < BesTimer* >::iterator BesTimerSvc::begin( void ) {
116 return m_itemList.begin();
117}
118std::vector < BesTimer* >::iterator BesTimerSvc::end( void ){
119 return m_itemList.end();
120}
121
virtual std::vector< BesTimer * >::iterator begin(void)
virtual BesTimer * addItem(const std::string &name)
Definition: BesTimerSvc.cxx:57
virtual StatusCode initialize()
Definition: BesTimerSvc.cxx:35
virtual void print()
Definition: BesTimerSvc.cxx:71
virtual StatusCode finalize()
Definition: BesTimerSvc.cxx:48
virtual std::vector< BesTimer * >::iterator end(void)