New class to log things that should be collected during the processing, but only...
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 9 Mar 2007 17:16:37 +0000 (17:16 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 9 Mar 2007 17:16:37 +0000 (17:16 +0000)
MUON/AliMUONLogger.cxx [new file with mode: 0644]
MUON/AliMUONLogger.h [new file with mode: 0644]

diff --git a/MUON/AliMUONLogger.cxx b/MUON/AliMUONLogger.cxx
new file mode 100644 (file)
index 0000000..c5caeac
--- /dev/null
@@ -0,0 +1,88 @@
+/**************************************************************************
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+*                                                                        *
+* Author: The ALICE Off-line Project.                                    *
+* Contributors are mentioned in the code where appropriate.              *
+*                                                                        *
+* Permission to use, copy, modify and distribute this software and its   *
+* documentation strictly for non-commercial purposes is hereby granted   *
+* without fee, provided that the above copyright notice appears in all   *
+* copies and that both the copyright notice and this permission notice   *
+* appear in the supporting documentation. The authors make no claims     *
+* about the suitability of this software for any purpose. It is          *
+* provided "as is" without express or implied warranty.                  *
+**************************************************************************/
+
+// $Id$
+
+#include "AliMUONLogger.h"
+
+#include "AliMUONStringIntMap.h"
+#include "AliLog.h"
+#include "Riostream.h"
+
+/// \class AliMUONLogger
+///
+/// A logger that keeps track of the number of times a message appeared.
+///
+/// Typically used to print all messages to screen at once, e.g. in the
+/// dtor of a worker class.
+///
+/// For instance, it is used in AliMUONDigitizerV3, to note which channels
+/// are disabled, and this information is printed in a condensed form
+/// only once when DigitizerV3 is destroyed.
+///
+//author Laurent Aphecetche
+
+ClassImp(AliMUONLogger)
+
+//_____________________________________________________________________________
+AliMUONLogger::AliMUONLogger(Int_t maxNumberOfEntries) 
+: TObject(), 
+  fMaxNumberOfEntries(maxNumberOfEntries),
+  fLog(new AliMUONStringIntMap)
+{
+    /// ctor. After maxNumberOfEntries, the log is printed and reset
+}
+
+//_____________________________________________________________________________
+AliMUONLogger::~AliMUONLogger()
+{
+  /// dtor
+  delete fLog;
+}
+
+//_____________________________________________________________________________
+Int_t 
+AliMUONLogger::Log(const char* message)
+{
+  /// Log a message
+  if ( fLog->GetNofItems() >= fMaxNumberOfEntries ) 
+  {
+    AliWarning("Reached max number of entries. Printing and resetting.");
+    Print();
+    fLog->Clear();
+  }
+  
+  Int_t i = fLog->Get(message);
+  
+  fLog->Set(message,i+1);
+  
+  return i+1;
+}
+
+//_____________________________________________________________________________
+void 
+AliMUONLogger::Print(Option_t* opt) const
+{
+  /// Print the entire log
+  if ( fLog->GetNofItems() )
+  {
+    fLog->Print(opt);
+  }
+  else
+  {
+    cout << "No message" << endl;
+  }
+}
+
diff --git a/MUON/AliMUONLogger.h b/MUON/AliMUONLogger.h
new file mode 100644 (file)
index 0000000..b5ba743
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef ALIMUONLOGGER_H
+#define ALIMUONLOGGER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+* See cxx source for full Copyright notice                               */
+
+// $Id$
+
+/// \ingroup base
+/// \class AliMUONLogger
+/// \brief A logger that keeps track of the number of times a message appeared
+/// 
+/// \author Laurent Aphecetche
+
+#ifndef ROOT_TObject
+#  include "TObject.h"
+#endif
+
+class AliMUONStringIntMap;
+
+class AliMUONLogger : public TObject
+{
+public:
+  AliMUONLogger(Int_t maxNumberOfEntries=-1);
+  virtual ~AliMUONLogger();
+  
+  Int_t Log(const char* message);
+  
+  void Print(Option_t* opt="") const;
+  
+private:
+  
+  AliMUONLogger(const AliMUONLogger& rhs); // not implemented
+  AliMUONLogger& operator=(const AliMUONLogger& rhs); // not implemented
+  
+private:
+  
+  Int_t fMaxNumberOfEntries; //!< after this number, print and reset
+  AliMUONStringIntMap* fLog; //!< map from message to number of times the message was issued
+  
+  ClassDef(AliMUONLogger,1) // 
+};
+
+#endif