AliRoot Core  3dc7879 (3dc7879)
AliMUONLogger.cxx
Go to the documentation of this file.
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 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
38 
39 using std::cout;
40 using std::endl;
42 ClassImp(AliMUONLogger)
44 
45 //_____________________________________________________________________________
46 AliMUONLogger::AliMUONLogger(Int_t maxNumberOfEntries, const char* name)
47 : TObject(),
48  fMaxNumberOfEntries(maxNumberOfEntries),
49  fLog(new AliMUONStringIntMap),
50  fName(name)
51 {
53 }
54 
55 //_____________________________________________________________________________
57 {
59  delete fLog;
60 }
61 
62 //_____________________________________________________________________________
63 Int_t
64 AliMUONLogger::Log(const char* message)
65 {
67 
69  {
70  AliWarning(Form("Reached max number of entries (%d over %d). Printing and resetting.",
72  Print();
73  fLog->Clear();
74  }
75 
76  Int_t i = fLog->Get(message);
77 
78  fLog->Set(message,i+1);
79 
80  return i+1;
81 }
82 
83 //_____________________________________________________________________________
84 void
85 AliMUONLogger::Clear(Option_t* /*option*/)
86 {
88 
89  fLog->Clear();
90 }
91 
92 //_____________________________________________________________________________
93 void
94 AliMUONLogger::Print(Option_t* opt) const
95 {
97  if ( fLog->GetNofItems() )
98  {
99  fLog->Print(opt);
100  }
101  else
102  {
103  cout << "No message" << endl;
104  }
105 }
106 
107 //_____________________________________________________________________________
108 void
109 AliMUONLogger::Print(TString& key, ofstream& out) const
110 {
112  fLog->Print(key, out);
113 
114 
115 }
116 
117 //_____________________________________________________________________________
118 void
120 {
122  fLog->ResetItr();
123 
124 }
125 
126 //_____________________________________________________________________________
127 Bool_t
128 AliMUONLogger::Next(TString& msg, Int_t& occurance)
129 {
131  return fLog->Next(msg, occurance);
132 
133 }
134 
135 //_____________________________________________________________________________
136 Int_t
138 {
140  return fLog->GetNofItems();
141 }
142 
143 //______________________________________________________________________________
144 Long64_t AliMUONLogger::Merge(TCollection* list)
145 {
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  if (!list) return 0;
155 
156  if (list->IsEmpty()) return 1;
157 
158  TIter next(list);
159  TObject* currObj;
160  Int_t count(0);
161 
162  while ( ( currObj = next() ) )
163  {
164  AliMUONLogger* logger = dynamic_cast<AliMUONLogger*>(currObj);
165  if (!logger)
166  {
167  AliFatal(Form("object named \"%s\" is a %s instead of an logger!", currObj->GetName(), currObj->ClassName()));
168  continue;
169  }
170  logger->ResetItr();
171  TString msg;
172  Int_t occurance;
173  while ( logger->Next(msg,occurance) )
174  {
175  for ( Int_t i = 0; i < occurance; ++i )
176  {
177  Log(msg);
178  }
179  }
180  ++count;
181  }
182 
183  return count+1;
184 }
Bool_t Set(const TString &first, Int_t second)
Long64_t Merge(TCollection *list)
Bool_t Next(TString &first, Int_t &second)
void Print(Option_t *opt="") const
Int_t Log(const char *message)
Int_t NumberOfEntries() const
Bool_t Next(TString &msg, Int_t &occurance)
Int_t fMaxNumberOfEntries
! after this number, print and reset
Definition: AliMUONLogger.h:58
#define AliWarning(message)
Definition: AliLog.h:541
Substitutes map <string, int> which ALICE does not allow to use.
A logger that keeps track of the number of times a message appeared.
Definition: AliMUONLogger.h:24
Int_t Get(const TString &first) const
AliMUONStringIntMap * fLog
! map from message to number of times the message was issued
Definition: AliMUONLogger.h:59
virtual void Print(const char *="") const
#define AliFatal(message)
Definition: AliLog.h:640
virtual void Clear(Option_t *="")
void Clear(Option_t *="")
virtual ~AliMUONLogger()