StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMuTimer.cxx
1 /***************************************************************************
2  *
3  * $Id: StMuTimer.cxx,v 1.3 2003/10/15 17:34:17 laue Exp $
4  *
5  * Author: Thomas Ullrich, April 1999
6  ***************************************************************************
7  *
8  * Description: CPU timer
9  *
10  ***************************************************************************
11  *
12  * $Log: StMuTimer.cxx,v $
13  * Revision 1.3 2003/10/15 17:34:17 laue
14  * StMuDstMaker: Reading fixed. Delete() changed back to Clear()
15  * StMuEmcCollection: Re-implemented the DeleteThis() function,
16  * This hoopefully fixed the memory leak when
17  * writing MuDst again.
18  * StMuTimer: ClassDef/ClassImp
19  *
20  * Revision 1.2 2003/09/09 18:16:53 laue
21  * StMuIOMaker: embedded documentation added
22  * StMuTimer: name of define changed (was same as StTimer)
23  *
24  * Revision 1.1 2002/03/08 17:04:18 laue
25  * initial revision
26  *
27  * Revision 1.1 1999/04/27 19:23:44 ullrich
28  * Initial Revision
29  *
30  **************************************************************************/
31 #include <time.h>
32 #include <stdlib.h>
33 #include "StMuTimer.h"
34 
35 ClassImp(StMuTimer)
36 
37 StMuTimer::StMuTimer() : mStartTime(0), mStopTime(0), mIsStopped(1)
38 {/* noop */}
39 
40 double StMuTimer::resolution() const
41 {
42  return 1./double(CLOCKS_PER_SEC);
43 }
44 
45 double StMuTimer::elapsedTime() const
46 {
47  return (mIsStopped ? mStopTime : absoluteTime()) - mStartTime;
48 }
49 
50 void StMuTimer::reset()
51 {
52  mStartTime = 0;
53  mStopTime = 0;
54  mIsStopped = 1;
55 }
56 
57 void StMuTimer::start()
58 {
59  mStartTime = absoluteTime() - elapsedTime();
60  mIsStopped = 0;
61 }
62 
63 void StMuTimer::stop()
64 {
65  mStopTime = absoluteTime();
66  mIsStopped = 1;
67 }
68 
69 
70 double StMuTimer::absoluteTime()
71 {
72  return (double)clock()/CLOCKS_PER_SEC;
73 }
74