]>
Commit | Line | Data |
---|---|---|
48beade4 | 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 | #include "AliMUONLogger.h" | |
19 | ||
20 | #include "AliMUONStringIntMap.h" | |
21 | #include "AliLog.h" | |
22 | #include "Riostream.h" | |
23 | ||
3d1463c8 | 24 | //----------------------------------------------------------------------------- |
48beade4 | 25 | /// \class AliMUONLogger |
26 | /// | |
27 | /// A logger that keeps track of the number of times a message appeared. | |
28 | /// | |
29 | /// Typically used to print all messages to screen at once, e.g. in the | |
30 | /// dtor of a worker class. | |
31 | /// | |
32 | /// For instance, it is used in AliMUONDigitizerV3, to note which channels | |
33 | /// are disabled, and this information is printed in a condensed form | |
34 | /// only once when DigitizerV3 is destroyed. | |
35 | /// | |
78649106 | 36 | /// \author Laurent Aphecetche |
3d1463c8 | 37 | //----------------------------------------------------------------------------- |
48beade4 | 38 | |
71a2d3aa | 39 | /// \cond CLASSIMP |
48beade4 | 40 | ClassImp(AliMUONLogger) |
71a2d3aa | 41 | /// \endcond |
48beade4 | 42 | |
43 | //_____________________________________________________________________________ | |
44 | AliMUONLogger::AliMUONLogger(Int_t maxNumberOfEntries) | |
45 | : TObject(), | |
46 | fMaxNumberOfEntries(maxNumberOfEntries), | |
47 | fLog(new AliMUONStringIntMap) | |
48 | { | |
49 | /// ctor. After maxNumberOfEntries, the log is printed and reset | |
50 | } | |
51 | ||
52 | //_____________________________________________________________________________ | |
53 | AliMUONLogger::~AliMUONLogger() | |
54 | { | |
55 | /// dtor | |
56 | delete fLog; | |
57 | } | |
58 | ||
59 | //_____________________________________________________________________________ | |
60 | Int_t | |
61 | AliMUONLogger::Log(const char* message) | |
62 | { | |
63 | /// Log a message | |
64 | if ( fLog->GetNofItems() >= fMaxNumberOfEntries ) | |
65 | { | |
66 | AliWarning("Reached max number of entries. Printing and resetting."); | |
67 | Print(); | |
68 | fLog->Clear(); | |
69 | } | |
70 | ||
71 | Int_t i = fLog->Get(message); | |
72 | ||
73 | fLog->Set(message,i+1); | |
74 | ||
75 | return i+1; | |
76 | } | |
77 | ||
78 | //_____________________________________________________________________________ | |
79 | void | |
80 | AliMUONLogger::Print(Option_t* opt) const | |
81 | { | |
82 | /// Print the entire log | |
83 | if ( fLog->GetNofItems() ) | |
84 | { | |
85 | fLog->Print(opt); | |
86 | } | |
87 | else | |
88 | { | |
89 | cout << "No message" << endl; | |
90 | } | |
91 | } | |
92 |