]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliLog.cxx
Problem with boundary crossing on common boundaries between mother and daughter volum...
[u/mrichter/AliRoot.git] / STEER / AliLog.cxx
index 60536e872f9e50431d08e634b9897d0782ddc989..fad662ba8e4314ab5a1be04c7eed9a6f7404c62a 100644 (file)
@@ -53,7 +53,16 @@ AliLog::AliLog() :
   TObject(),
   fGlobalLogLevel(kInfo),
   fModuleDebugLevels(),
-  fClassDebugLevels()
+  fClassDebugLevels(),
+  fPrintRepetitions(kTRUE),
+  fRepetitions(0),
+  fLastType(0),
+  fLastMessage(),
+  fLastModule(),
+  fLastClassName(),
+  fLastFunction(),
+  fLastFile(),
+  fLastLine(0)
 {
 // default constructor: set default values
 
@@ -69,12 +78,12 @@ AliLog::AliLog() :
     fPrintLocation[iType] = (iType == kDebug);  
   }
 
-  SetHandleRootMessages(kTRUE);
-
   // replace the previous instance by this one
   if (fgInstance) delete fgInstance;
   fgInstance = this;
 
+  SetHandleRootMessages(kTRUE);
+
   // read the .rootrc settings
   ReadEnvSettings();
 }
@@ -84,6 +93,8 @@ AliLog::~AliLog()
 {
 // destructor: clean up and reset instance pointer
 
+  if (fRepetitions > 0) PrintRepetitions();
+
   for (Int_t i = 0; i < fModuleDebugLevels.GetEntriesFast(); i++) {
     if (fModuleDebugLevels[i]) fModuleDebugLevels[i]->Delete();
   }
@@ -263,6 +274,14 @@ void AliLog::ReadEnvSettings()
       }
     }
   }
+
+  // repetition of messages
+  if (gEnv->Defined("AliRoot.AliLog.PrintRepetitions")) {
+    Bool_t on = gEnv->GetValue("AliRoot.AliLog.PrintRepetitions", kTRUE);
+    fPrintRepetitions = on;
+    AliDebug(3, Form("printing of message repetitions %sabled",
+                     ((on) ? "en" : "dis")));
+  }
 }
 
 
@@ -555,6 +574,7 @@ void AliLog::SetHandleRootMessages(Bool_t on)
 {
 // enable or disable the handling of messages form root
 
+  if (!fgInstance) new AliLog;
   if (on) {
     SetErrorHandler(RootErrorHandler);
   } else {
@@ -652,7 +672,19 @@ void AliLog::SetPrintLocation(EType type, Bool_t on)
 
 
 //_____________________________________________________________________________
-void AliLog::Write(const char* name, Int_t option)
+void AliLog::SetPrintRepetitions(Bool_t on)
+{
+// switch on or off the printing of the number of repetitions of a message
+// instead of repeating the same message
+
+  if (!fgInstance) new AliLog;
+  if (!on && (fgInstance->fRepetitions > 0)) fgInstance->PrintRepetitions();
+  fgInstance->fPrintRepetitions = on;
+}
+
+
+//_____________________________________________________________________________
+void AliLog::WriteToFile(const char* name, Int_t option)
 {
 // write the log object with the given name and option to the current file
 
@@ -667,10 +699,14 @@ UInt_t AliLog::GetLogLevel(const char* module, const char* className) const
 // get the logging level for the given module and class
 
   if (!fgInstance) new AliLog;
-  TObject* obj = fgInstance->fClassDebugLevels.FindObject(className);
-  if (obj) return obj->GetUniqueID();
-  obj = fgInstance->fModuleDebugLevels.FindObject(module);
-  if (obj) return obj->GetUniqueID();
+  if (className) {
+    TObject* obj = fgInstance->fClassDebugLevels.FindObject(className);
+    if (obj) return obj->GetUniqueID();
+  }
+  if (module) {
+    TObject* obj = fgInstance->fModuleDebugLevels.FindObject(module);
+    if (obj) return obj->GetUniqueID();
+  }
   return fgInstance->fGlobalLogLevel;
 }
 
@@ -690,14 +726,44 @@ void AliLog::PrintMessage(UInt_t type, const char* message,
 {
 // print the given message
 
+  // don't print the message if it is repeated
+  if (fPrintRepetitions &&
+      (fLastType == type) && 
+      (message && (fLastMessage.CompareTo(message) == 0)) &&
+      ((module && (fLastModule.CompareTo(module) == 0)) ||
+       (!module && fLastModule.IsNull())) &&
+      ((className && (fLastClassName.CompareTo(className) == 0)) ||
+       (!className && fLastClassName.IsNull())) &&
+      ((function && (fLastFunction.CompareTo(function) == 0)) ||
+       (!function && fLastFunction.IsNull()))&&
+      ((file && (fLastFile.CompareTo(file) == 0)) ||
+       (!file && fLastFile.IsNull())) &&
+      (fLastLine == line)) {
+    fRepetitions++;
+    return;
+  }
+
+  // print number of repetitions
+  if (fRepetitions > 0) PrintRepetitions();
+
+  // remember this message
+  fRepetitions = 0;
+  fLastType = type;
+  fLastMessage = message;
+  fLastModule = module;
+  fLastClassName = className;
+  fLastFunction = function;
+  fLastFile = file;
+  fLastLine = line;
+
+  // print the message
   FILE* stream = GetOutputStream(type);
   static const char* typeNames[kMaxType] = 
     {"Fatal", "Error", "Warning", "Info", "Debug"};
 
   if (fPrintType[type]) {
-    fprintf(stream, "%s in ", typeNames[type]);
+    fprintf(stream, "%c-", typeNames[type][0]);
   }
-  fprintf(stream, "<");
   if (fPrintModule[type] && module) {
     fprintf(stream, "%s/", module);
   }
@@ -705,9 +771,9 @@ void AliLog::PrintMessage(UInt_t type, const char* message,
     fprintf(stream, "%s::", className);
   }
   if (message) {
-    fprintf(stream, "%s>: %s", function, message);
+    fprintf(stream, "%s: %s", function, message);
   } else {
-    fprintf(stream, "%s>", function);
+    fprintf(stream, "%s", function);
   }
   if (fPrintLocation[type] && file) {
     fprintf(stream, " (%s:%.0d)", file, line);
@@ -719,6 +785,15 @@ void AliLog::PrintMessage(UInt_t type, const char* message,
   }
 }
 
+//_____________________________________________________________________________
+void AliLog::PrintRepetitions()
+{
+// print number of repetitions
+
+  fprintf(GetOutputStream(fLastType), " <message repeated %d time%s>\n", 
+          fRepetitions, (fRepetitions > 1) ? "s" : "");
+}
+
 //_____________________________________________________________________________
 void AliLog::Message(UInt_t level, const char* message, 
                     const char* module, const char* className,
@@ -831,6 +906,7 @@ void AliLog::RestoreStdout(Int_t original)
 
   fflush(stdout);
   dup2(original, fileno(stdout));  
+  close(original);
 }
 
 //_____________________________________________________________________________
@@ -840,6 +916,7 @@ void AliLog::RestoreStderr(Int_t original)
 
   fflush(stderr);
   dup2(original, fileno(stderr));  
+  close(original);
 }