1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /// \class AliMUONStopwatchGroup
20 /// A class to group timers by name
21 /// Typically used to time out some methods, e.g.
23 /// AliMUONStopwatchGroup timers;
25 /// void Class::Method()
27 /// timers.Start("Class","Method");
37 /// \author Laurent Aphecetche, Subatech
39 #include "AliMUONStopwatchGroup.h"
43 #include <TObjString.h>
44 #include <TStopwatch.h>
45 #include <Riostream.h>
48 ClassImp(AliMUONStopwatchGroup)
51 //_____________________________________________________________________________
52 AliMUONStopwatchGroup::AliMUONStopwatchGroup() : TObject(), fTimers(new TMap)
55 fTimers->SetOwner(kTRUE);
58 //_____________________________________________________________________________
59 AliMUONStopwatchGroup::AliMUONStopwatchGroup(const AliMUONStopwatchGroup& other) : TObject(), fTimers(new TMap)
65 //_____________________________________________________________________________
66 AliMUONStopwatchGroup&
67 AliMUONStopwatchGroup::operator=(const AliMUONStopwatchGroup& other)
75 //_____________________________________________________________________________
76 AliMUONStopwatchGroup::~AliMUONStopwatchGroup()
83 //_____________________________________________________________________________
84 void AliMUONStopwatchGroup::Continue(const char* detector, const char* method)
86 /// Resume a previously stop timer
87 TStopwatch* t = Stopwatch(detector,method);
94 AliError(Form("No timer for %s/%s",detector,method));
98 //_____________________________________________________________________________
100 AliMUONStopwatchGroup::CopyTo(AliMUONStopwatchGroup& other) const
102 /// Copy this to other
104 TObjString* detector;
106 while ( ( detector = static_cast<TObjString*>(next()) ) )
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);
114 while ( ( method = static_cast<TObjString*>(next2()) ) )
116 TStopwatch* timer = static_cast<TStopwatch*>(m->GetValue(method->String().Data()));
117 otherm->Add(new TObjString(method->String()),new TStopwatch(*timer));
122 //_____________________________________________________________________________
123 Double_t AliMUONStopwatchGroup::CpuTime(const char* detector, const char* method) const
125 /// Return cpu time for a given timer
126 TStopwatch* t = Stopwatch(detector,method);
137 //_____________________________________________________________________________
139 AliMUONStopwatchGroup::Map(const char* detector) const
141 /// Return the map for a given "detector"
142 return static_cast<TMap*>(fTimers->GetValue(detector));
145 //_____________________________________________________________________________
146 void AliMUONStopwatchGroup::Print(Option_t* /*opt*/) const
148 /// Print all the timers we hold
150 TObjString* detector;
152 while ( ( detector = static_cast<TObjString*>(next()) ) )
154 cout << detector->String() << endl;
155 TMap* m = static_cast<TMap*>(fTimers->GetValue(detector->String().Data()));
158 while ( ( method = static_cast<TObjString*>(next2()) ) )
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;
168 //_____________________________________________________________________________
170 AliMUONStopwatchGroup::RealTime(const char* detector, const char* method) const
172 /// Return real time of a given time
173 TStopwatch* t = Stopwatch(detector,method);
176 return t->RealTime();
184 //_____________________________________________________________________________
186 AliMUONStopwatchGroup::Reset()
190 TObjString* detector;
192 while ( ( detector = static_cast<TObjString*>(next()) ) )
194 TMap* m = static_cast<TMap*>(fTimers->GetValue(detector->String().Data()));
198 fTimers->DeleteAll();
201 //_____________________________________________________________________________
203 AliMUONStopwatchGroup::Start(const char* detector, const char* method)
205 /// Start a given time
206 TStopwatch* t = Stopwatch(detector,method);
209 TMap* m = Map(detector);
214 fTimers->Add(new TObjString(detector),m);
219 m->Add(new TObjString(method),t);
224 //_____________________________________________________________________________
226 AliMUONStopwatchGroup::Stop(const char* detector, const char* method)
228 /// Stop a given timer
229 TStopwatch* t = Stopwatch(detector,method);
232 AliError(Form("No timer for %s/%s",detector,method));
240 //_____________________________________________________________________________
242 AliMUONStopwatchGroup::Stopwatch(const char* detector, const char* method) const
244 /// Return the internal TStopwatch for a given timer
245 TMap* m = Map(detector);
248 return static_cast<TStopwatch*>(m->GetValue(method));