Line data Source code
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 :
24 : //-----------------------------------------------------------------------------
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 : ///
36 : /// \author Laurent Aphecetche
37 : //-----------------------------------------------------------------------------
38 :
39 : using std::cout;
40 : using std::endl;
41 : /// \cond CLASSIMP
42 18 : ClassImp(AliMUONLogger)
43 : /// \endcond
44 :
45 : //_____________________________________________________________________________
46 : AliMUONLogger::AliMUONLogger(Int_t maxNumberOfEntries, const char* name)
47 14 : : TObject(),
48 14 : fMaxNumberOfEntries(maxNumberOfEntries),
49 42 : fLog(new AliMUONStringIntMap),
50 14 : fName(name)
51 70 : {
52 : /// ctor. After maxNumberOfEntries, the log is printed and reset
53 28 : }
54 :
55 : //_____________________________________________________________________________
56 : AliMUONLogger::~AliMUONLogger()
57 56 : {
58 : /// dtor
59 20 : delete fLog;
60 28 : }
61 :
62 : //_____________________________________________________________________________
63 : Int_t
64 : AliMUONLogger::Log(const char* message)
65 : {
66 : /// Log a message
67 :
68 61848 : if ( fMaxNumberOfEntries >0 && fLog->GetNofItems() >= fMaxNumberOfEntries )
69 : {
70 0 : AliWarning(Form("Reached max number of entries (%d over %d). Printing and resetting.",
71 : fLog->GetNofItems(),fMaxNumberOfEntries));
72 0 : Print();
73 0 : fLog->Clear();
74 0 : }
75 :
76 41232 : Int_t i = fLog->Get(message);
77 :
78 41232 : fLog->Set(message,i+1);
79 :
80 20616 : return i+1;
81 0 : }
82 :
83 : //_____________________________________________________________________________
84 : void
85 : AliMUONLogger::Clear(Option_t* /*option*/)
86 : {
87 : /// reset logger spool
88 :
89 0 : fLog->Clear();
90 0 : }
91 :
92 : //_____________________________________________________________________________
93 : void
94 : AliMUONLogger::Print(Option_t* opt) const
95 : {
96 : /// Print the entire log
97 6 : if ( fLog->GetNofItems() )
98 : {
99 2 : fLog->Print(opt);
100 2 : }
101 : else
102 : {
103 1 : cout << "No message" << endl;
104 : }
105 3 : }
106 :
107 : //_____________________________________________________________________________
108 : void
109 : AliMUONLogger::Print(TString& key, ofstream& out) const
110 : {
111 : /// print out into a given streamer with a key word in front of the message
112 0 : fLog->Print(key, out);
113 :
114 :
115 0 : }
116 :
117 : //_____________________________________________________________________________
118 : void
119 : AliMUONLogger::ResetItr()
120 : {
121 : /// call reset iterator method
122 0 : fLog->ResetItr();
123 :
124 0 : }
125 :
126 : //_____________________________________________________________________________
127 : Bool_t
128 : AliMUONLogger::Next(TString& msg, Int_t& occurance)
129 : {
130 : /// call next iterator method
131 4 : return fLog->Next(msg, occurance);
132 :
133 : }
134 :
135 : //_____________________________________________________________________________
136 : Int_t
137 : AliMUONLogger::NumberOfEntries() const
138 : {
139 : /// Get the number of logs we have so far
140 0 : return fLog->GetNofItems();
141 : }
142 :
143 : //______________________________________________________________________________
144 : Long64_t AliMUONLogger::Merge(TCollection* list)
145 : {
146 : /// Merge method
147 :
148 : // Merge a list of AliMUONLogger objects with this
149 : // Returns the number of merged objects (including this).
150 : //
151 : // Not the most clever implementation, but it works...
152 : //
153 :
154 0 : if (!list) return 0;
155 :
156 0 : if (list->IsEmpty()) return 1;
157 :
158 0 : TIter next(list);
159 : TObject* currObj;
160 : Int_t count(0);
161 :
162 0 : while ( ( currObj = next() ) )
163 : {
164 0 : AliMUONLogger* logger = dynamic_cast<AliMUONLogger*>(currObj);
165 0 : if (!logger)
166 : {
167 0 : AliFatal(Form("object named \"%s\" is a %s instead of an logger!", currObj->GetName(), currObj->ClassName()));
168 0 : continue;
169 : }
170 0 : logger->ResetItr();
171 0 : TString msg;
172 0 : Int_t occurance;
173 0 : while ( logger->Next(msg,occurance) )
174 : {
175 0 : for ( Int_t i = 0; i < occurance; ++i )
176 : {
177 0 : Log(msg);
178 : }
179 : }
180 0 : ++count;
181 0 : }
182 :
183 0 : return count+1;
184 0 : }
|