]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONLogger.cxx
Updating analysis task
[u/mrichter/AliRoot.git] / MUON / AliMUONLogger.cxx
CommitLineData
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
b80faac0 39using std::cout;
40using std::endl;
71a2d3aa 41/// \cond CLASSIMP
48beade4 42ClassImp(AliMUONLogger)
71a2d3aa 43/// \endcond
48beade4 44
45//_____________________________________________________________________________
46AliMUONLogger::AliMUONLogger(Int_t maxNumberOfEntries)
47: TObject(),
48 fMaxNumberOfEntries(maxNumberOfEntries),
49 fLog(new AliMUONStringIntMap)
50{
51 /// ctor. After maxNumberOfEntries, the log is printed and reset
52}
53
54//_____________________________________________________________________________
55AliMUONLogger::~AliMUONLogger()
56{
57 /// dtor
58 delete fLog;
59}
60
61//_____________________________________________________________________________
62Int_t
63AliMUONLogger::Log(const char* message)
64{
65 /// Log a message
64c2397e 66
67 if ( fMaxNumberOfEntries >0 && fLog->GetNofItems() >= fMaxNumberOfEntries )
48beade4 68 {
64c2397e 69 AliWarning(Form("Reached max number of entries (%d over %d). Printing and resetting.",
70 fLog->GetNofItems(),fMaxNumberOfEntries));
48beade4 71 Print();
72 fLog->Clear();
73 }
74
75 Int_t i = fLog->Get(message);
76
77 fLog->Set(message,i+1);
78
79 return i+1;
80}
81
cdf15cc5 82//_____________________________________________________________________________
83void
84AliMUONLogger::Clear(Option_t* /*option*/)
85{
86 /// reset logger spool
87
88 fLog->Clear();
89}
90
48beade4 91//_____________________________________________________________________________
92void
93AliMUONLogger::Print(Option_t* opt) const
94{
95 /// Print the entire log
96 if ( fLog->GetNofItems() )
97 {
98 fLog->Print(opt);
99 }
100 else
101 {
102 cout << "No message" << endl;
103 }
104}
38b84fe8 105
106//_____________________________________________________________________________
107void
108AliMUONLogger::Print(TString& key, ofstream& out) const
109{
110 /// print out into a given streamer with a key word in front of the message
111 fLog->Print(key, out);
112
113
114}
115
116//_____________________________________________________________________________
117void
118AliMUONLogger::ResetItr()
119{
120 /// call reset iterator method
121 fLog->ResetItr();
122
123}
124
125//_____________________________________________________________________________
126Bool_t
127AliMUONLogger::Next(TString& msg, Int_t& occurance)
128{
129 /// call next iterator method
130 return fLog->Next(msg, occurance);
131
132}
133
64c2397e 134//_____________________________________________________________________________
135Int_t
136AliMUONLogger::NumberOfEntries() const
137{
138 /// Get the number of logs we have so far
139 return fLog->GetNofItems();
140}
48beade4 141