]>
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 | |
64c2397e | 64 | |
65 | if ( fMaxNumberOfEntries >0 && fLog->GetNofItems() >= fMaxNumberOfEntries ) | |
48beade4 | 66 | { |
64c2397e | 67 | AliWarning(Form("Reached max number of entries (%d over %d). Printing and resetting.", |
68 | fLog->GetNofItems(),fMaxNumberOfEntries)); | |
48beade4 | 69 | Print(); |
70 | fLog->Clear(); | |
71 | } | |
72 | ||
73 | Int_t i = fLog->Get(message); | |
74 | ||
75 | fLog->Set(message,i+1); | |
76 | ||
77 | return i+1; | |
78 | } | |
79 | ||
cdf15cc5 | 80 | //_____________________________________________________________________________ |
81 | void | |
82 | AliMUONLogger::Clear(Option_t* /*option*/) | |
83 | { | |
84 | /// reset logger spool | |
85 | ||
86 | fLog->Clear(); | |
87 | } | |
88 | ||
48beade4 | 89 | //_____________________________________________________________________________ |
90 | void | |
91 | AliMUONLogger::Print(Option_t* opt) const | |
92 | { | |
93 | /// Print the entire log | |
94 | if ( fLog->GetNofItems() ) | |
95 | { | |
96 | fLog->Print(opt); | |
97 | } | |
98 | else | |
99 | { | |
100 | cout << "No message" << endl; | |
101 | } | |
102 | } | |
38b84fe8 | 103 | |
104 | //_____________________________________________________________________________ | |
105 | void | |
106 | AliMUONLogger::Print(TString& key, ofstream& out) const | |
107 | { | |
108 | /// print out into a given streamer with a key word in front of the message | |
109 | fLog->Print(key, out); | |
110 | ||
111 | ||
112 | } | |
113 | ||
114 | //_____________________________________________________________________________ | |
115 | void | |
116 | AliMUONLogger::ResetItr() | |
117 | { | |
118 | /// call reset iterator method | |
119 | fLog->ResetItr(); | |
120 | ||
121 | } | |
122 | ||
123 | //_____________________________________________________________________________ | |
124 | Bool_t | |
125 | AliMUONLogger::Next(TString& msg, Int_t& occurance) | |
126 | { | |
127 | /// call next iterator method | |
128 | return fLog->Next(msg, occurance); | |
129 | ||
130 | } | |
131 | ||
64c2397e | 132 | //_____________________________________________________________________________ |
133 | Int_t | |
134 | AliMUONLogger::NumberOfEntries() const | |
135 | { | |
136 | /// Get the number of logs we have so far | |
137 | return fLog->GetNofItems(); | |
138 | } | |
48beade4 | 139 |