]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONStopwatchGroup.cxx
- Reshape the architecture of the Kalman tracking to make it more modular
[u/mrichter/AliRoot.git] / MUON / AliMUONStopwatchGroup.cxx
CommitLineData
dfbc1173 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15
16// $Id$
17
18/// \class AliMUONStopwatchGroup
19///
20/// A class to group timers by name
21/// Typically used to time out some methods, e.g.
22///
23/// AliMUONStopwatchGroup timers;
24///
25/// void Class::Method()
26/// {
27/// timers.Start("Class","Method");
28/// ...
29/// timers.Stop();
30/// }
31///
32/// and later on :
33///
34/// timers.Print();
35///
36///
37/// \author Laurent Aphecetche, Subatech
38
39#include "AliMUONStopwatchGroup.h"
40
41#include "AliLog.h"
42#include <TMap.h>
43#include <TObjString.h>
44#include <TStopwatch.h>
45#include <Riostream.h>
46
47/// \cond CLASSIMP
48ClassImp(AliMUONStopwatchGroup)
49/// \endcond
50
51//_____________________________________________________________________________
52AliMUONStopwatchGroup::AliMUONStopwatchGroup() : TObject(), fTimers(new TMap)
53{
54 /// Ctor
55 fTimers->SetOwner(kTRUE);
56}
57
58//_____________________________________________________________________________
59AliMUONStopwatchGroup::AliMUONStopwatchGroup(const AliMUONStopwatchGroup& other) : TObject(), fTimers(new TMap)
60{
61 /// Copy ctor
62 other.CopyTo(*this);
63}
64
65//_____________________________________________________________________________
66AliMUONStopwatchGroup&
67AliMUONStopwatchGroup::operator=(const AliMUONStopwatchGroup& other)
68{
69 /// Assignment
70 Reset();
71 other.CopyTo(*this);
72 return *this;
73}
74
75//_____________________________________________________________________________
76AliMUONStopwatchGroup::~AliMUONStopwatchGroup()
77{
78 /// Dtor
79 Reset();
80 delete fTimers;
81}
82
83//_____________________________________________________________________________
84void AliMUONStopwatchGroup::Continue(const char* detector, const char* method)
85{
86 /// Resume a previously stop timer
87 TStopwatch* t = Stopwatch(detector,method);
88 if (t)
89 {
90 t->Continue();
91 }
92 else
93 {
94 AliError(Form("No timer for %s/%s",detector,method));
95 }
96}
97
98//_____________________________________________________________________________
99void
100AliMUONStopwatchGroup::CopyTo(AliMUONStopwatchGroup& other) const
101{
102 /// Copy this to other
103 TIter next(fTimers);
104 TObjString* detector;
105
106 while ( ( detector = static_cast<TObjString*>(next()) ) )
107 {
108 TMap* m = static_cast<TMap*>(fTimers->GetValue(detector->String().Data()));
109 TMap* otherm = new TMap;
110 otherm->SetOwner(kTRUE);
111 other.fTimers->Add(new TObjString(detector->String()),otherm);
112 TIter next2(m);
113 TObjString* method;
114 while ( ( method = static_cast<TObjString*>(next2()) ) )
115 {
116 TStopwatch* timer = static_cast<TStopwatch*>(m->GetValue(method->String().Data()));
117 otherm->Add(new TObjString(method->String()),new TStopwatch(*timer));
118 }
119 }
120}
121
122//_____________________________________________________________________________
123Double_t AliMUONStopwatchGroup::CpuTime(const char* detector, const char* method) const
124{
125 /// Return cpu time for a given timer
126 TStopwatch* t = Stopwatch(detector,method);
127 if (t)
128 {
129 return t->CpuTime();
130 }
131 else
132 {
133 return 0;
134 }
135}
136
137//_____________________________________________________________________________
138TMap*
139AliMUONStopwatchGroup::Map(const char* detector) const
140{
141 /// Return the map for a given "detector"
142 return static_cast<TMap*>(fTimers->GetValue(detector));
143}
144
145//_____________________________________________________________________________
146void AliMUONStopwatchGroup::Print(Option_t* /*opt*/) const
147{
148 /// Print all the timers we hold
149 TIter next(fTimers);
150 TObjString* detector;
151
152 while ( ( detector = static_cast<TObjString*>(next()) ) )
153 {
154 cout << detector->String() << endl;
155 TMap* m = static_cast<TMap*>(fTimers->GetValue(detector->String().Data()));
156 TIter next2(m);
157 TObjString* method;
158 while ( ( method = static_cast<TObjString*>(next2()) ) )
159 {
160 TStopwatch* timer = static_cast<TStopwatch*>(m->GetValue(method->String().Data()));
161 cout << Form(" %s R:%.2fs C:%.2fs (%d slices)",
162 method->String().Data(),timer->RealTime(),
163 timer->CpuTime(),timer->Counter()-1) << endl;
164 }
165 }
166}
167
168//_____________________________________________________________________________
169Double_t
170AliMUONStopwatchGroup::RealTime(const char* detector, const char* method) const
171{
172 /// Return real time of a given time
173 TStopwatch* t = Stopwatch(detector,method);
174 if (t)
175 {
176 return t->RealTime();
177 }
178 else
179 {
180 return 0;
181 }
182}
183
184//_____________________________________________________________________________
185void
186AliMUONStopwatchGroup::Reset()
187{
188 /// Reset
189 TIter next(fTimers);
190 TObjString* detector;
191
192 while ( ( detector = static_cast<TObjString*>(next()) ) )
193 {
194 TMap* m = static_cast<TMap*>(fTimers->GetValue(detector->String().Data()));
195 m->DeleteAll();
196 }
197
198 fTimers->DeleteAll();
199}
200
201//_____________________________________________________________________________
202void
203AliMUONStopwatchGroup::Start(const char* detector, const char* method)
204{
205 /// Start a given time
206 TStopwatch* t = Stopwatch(detector,method);
207 if (!t)
208 {
209 TMap* m = Map(detector);
210 if (!m)
211 {
212 m = new TMap;
213 m->SetOwner(kTRUE);
214 fTimers->Add(new TObjString(detector),m);
215 }
216 t = new TStopwatch;
217 t->Start(kTRUE);
218 t->Stop();
219 m->Add(new TObjString(method),t);
220 }
221 t->Start(kFALSE);
222}
223
224//_____________________________________________________________________________
225void
226AliMUONStopwatchGroup::Stop(const char* detector, const char* method)
227{
228 /// Stop a given timer
229 TStopwatch* t = Stopwatch(detector,method);
230 if (!t)
231 {
232 AliError(Form("No timer for %s/%s",detector,method));
233 }
234 else
235 {
236 t->Stop();
237 }
238}
239
240//_____________________________________________________________________________
241TStopwatch*
242AliMUONStopwatchGroup::Stopwatch(const char* detector, const char* method) const
243{
244 /// Return the internal TStopwatch for a given timer
245 TMap* m = Map(detector);
246 if (m)
247 {
248 return static_cast<TStopwatch*>(m->GetValue(method));
249 }
250 else
251 {
252 return 0x0;
253 }
254}
255