]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONLogger.cxx
Afterburner to generate light nuclei
[u/mrichter/AliRoot.git] / MUON / AliMUONLogger.cxx
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 ClassImp(AliMUONLogger)
43 /// \endcond
44
45 //_____________________________________________________________________________
46 AliMUONLogger::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 //_____________________________________________________________________________
55 AliMUONLogger::~AliMUONLogger()
56 {
57   /// dtor
58   delete fLog;
59 }
60
61 //_____________________________________________________________________________
62 Int_t 
63 AliMUONLogger::Log(const char* message)
64 {
65   /// Log a message
66
67   if ( fMaxNumberOfEntries >0 && fLog->GetNofItems() >= fMaxNumberOfEntries ) 
68   {
69     AliWarning(Form("Reached max number of entries (%d over %d). Printing and resetting.",
70                     fLog->GetNofItems(),fMaxNumberOfEntries));
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
82 //_____________________________________________________________________________
83 void   
84 AliMUONLogger::Clear(Option_t* /*option*/) 
85 {  
86   /// reset logger spool
87
88   fLog->Clear();
89 }
90
91 //_____________________________________________________________________________
92 void 
93 AliMUONLogger::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 }
105   
106 //_____________________________________________________________________________
107 void
108 AliMUONLogger::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 //_____________________________________________________________________________
117 void 
118 AliMUONLogger::ResetItr()
119 {
120   /// call reset iterator method
121   fLog->ResetItr();
122      
123 }
124  
125 //_____________________________________________________________________________
126 Bool_t 
127 AliMUONLogger::Next(TString& msg, Int_t& occurance)
128 {
129   /// call next iterator method
130   return fLog->Next(msg, occurance);
131      
132 }
133     
134 //_____________________________________________________________________________
135 Int_t
136 AliMUONLogger::NumberOfEntries() const
137 {
138   /// Get the number of logs we have so far
139   return fLog->GetNofItems();
140 }
141