]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Making AliLog true instanton (Jimmy)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 16 Feb 2010 08:49:05 +0000 (08:49 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 16 Feb 2010 08:49:05 +0000 (08:49 +0000)
EVE/alieve_main/alieve_main.cxx
HLT/rec/AliHLTDynamicAliLog.cxx
HMPID/AliHMPIDReconHTA.cxx
ITS/ITSSPDFOda.cxx
ITS/ITSSPDPHYSda.cxx
ITS/ITSSPDSCANda.cxx
STEER/AliLog.cxx
STEER/AliLog.h

index 6b3f633aa1d7c2e811f844f9f88d4add21a8574d..41d9809aa20b9d08687bd432e83e9bec6ab6311c 100644 (file)
@@ -64,8 +64,8 @@ int main(int argc, char **argv)
   }
   gROOT->SetMacroPath(macPath);
 
-  // How to hadle AliLog properly?
-  AliLog *log = new AliLog;
+  // get a logger instance
+  AliLog *log = AliLog::GetRootLogger();
   TRint  *app = new TRint("App", &argc, argv);
 
 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,25,4) || defined XXX_LATEST_ROOT
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
 
   app->Terminate(0);
 
-  delete log;
+  //  delete log;
 
   return 0;
 }
index 18150101e3d4c3d2b60074c919cbacb25a487767..5ae47775ac45ed34d1cb43486530843fcd47d6bd 100644 (file)
@@ -134,7 +134,7 @@ extern "C" int InitAliDynamicMessageCallback()
   // older versions of AliLog does not support the notification callback and
   // stringstreams, but they support the logging macros in general
 #ifndef NO_ALILOG_NOTIFICATION
-  AliLog* log=new AliLog;
+  AliLog* log = AliLog::GetRootLogger();
   log->SetLogNotification(LogNotification);
   log->SetStreamOutput(&AliHLTLogging::fgLogstr);
   log->SetPrintScope(true);
index 073e889de5f6956ac8908d512d807b78e4c9fa1f..b3378cb69656eab0ab55f26e7436d3f42248c03d 100644 (file)
@@ -527,7 +527,11 @@ void AliHMPIDReconHTA::FunMinPhot(Int_t &/* */,Double_t* /* */,Double_t &f,Doubl
       
     meanCkov1/=nClAcc;
     Double_t rms2 = (meanCkov3 - meanCkov*meanCkov*nClAcc)/nClAcc;
-    AliLog::Instance();
+    
+    // get a logger instance
+    // what for??
+    AliLog::GetRootLogger();
+
     if(nClAcc!=nClAccStep1) pRecHTA->SetFitStatus(kTRUE); else pRecHTA->SetFitStatus(kFALSE);
     
     pRecHTA->SetCkovFit(meanCkov1);
index ecd03e821d95b3886b8f118285cd0b9e722f60f7..48c60d34c1932eb6b974a6215fc803667b44ae68 100644 (file)
@@ -85,11 +85,9 @@ int main(int argc, char **argv) {
                                        "TStreamerInfo()");
   
   // turn off annoying warning messages
-  new AliLog;
-  AliLog::Instance()->SetGlobalDebugLevel(-20);
-  
-  
-  
+  // NB: Should not be handled here 
+  AliLog logger = AliLog::GetRootLogger();
+  logger->SetGlobalDebugLevel(-20);
   
 // ********* STEP 0: Get configuration files from db (if there are any) , then read parameters*********  
   
index 5ebf3a4c7ed776c32a731a1cd3366a2c97b1e99d..a9792cc7bf7060ca2f82a340afbd5f3d10be59f6 100644 (file)
@@ -97,9 +97,9 @@ int main(int argc, char **argv) {
                                        "TStreamerInfo()");
 
   // turn off annoying warning messages
-  new AliLog;
-  AliLog::Instance()->SetGlobalDebugLevel(-20);
-
+  // NB: Should not be handled here
+  AliLog logger = AliLog::GetRootLogger();
+  logger->SetGlobalDebugLevel(-20);
 
   // ********* STEP 0: Get configuration files from db (if there are any) , then read parameters*********
   UInt_t nrTuningParams = 0;
index 9e67ed98354458027256b9c0289817234e8660b1..85132e74e6c0d6c7f9d9972d8c558a204c9fe364 100644 (file)
@@ -85,8 +85,9 @@ int main(int argc, char **argv) {
                                        "TStreamerInfo()");
 
   // turn off annoying warning messages
-  new AliLog;
-  AliLog::Instance()->SetGlobalDebugLevel(-20);
+  // NB: Should not be handled here
+  AliLog logger = AliLog::GetRootLogger();
+  logger->SetGlobalDebugLevel(-20);
 
   // calib scan types
   enum calib_types{MINTH,MEANTH,DAC,UNIMA,NOISE,DELAY};
index 025852d202a91a4874cb4d36506385c8fdc7fb44..5258eb8d0428302ad60842e9408dc455978b0a18 100644 (file)
 
 ClassImp(AliLog)
 
-
+// implementation of a singleton here
 AliLog* AliLog::fgInstance = NULL;
 
 Bool_t AliLog::fgDebugEnabled = kTRUE;
 
+/**
+ * get root logger singleton instance
+ */
+AliLog *AliLog::GetRootLogger()
+{
+       if (fgInstance == NULL)
+       {
+               // creating singleton
+               fgInstance =  new AliLog;
+       }
+
+       return fgInstance;
+}
 
-//_____________________________________________________________________________
+/**
+ * delete the root logger singleton instance
+ */
+void AliLog::DeleteRootLogger()
+{
+       if (fgInstance != NULL)
+       {
+               delete fgInstance;
+               fgInstance = NULL;
+       }
+}
+
+/**
+ * default private constructor
+ */
 AliLog::AliLog() :
   TObject(),
   fGlobalLogLevel(kInfo),
@@ -69,7 +96,8 @@ AliLog::AliLog() :
 {
 // default constructor: set default values
 
-  for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+  for (Int_t iType = kFatal; iType < kMaxType; iType++)
+  {
     fOutputTypes[iType] = 0;
     fFileNames[iType] = "";
     fOutputFiles[iType] = NULL;
@@ -82,6 +110,7 @@ AliLog::AliLog() :
     fPrintLocation[iType] = (iType == kDebug);  
   }
 
+  // TO BE REVIEWED
   // replace the previous instance by this one
   if (fgInstance) delete fgInstance;
   fgInstance = this;
@@ -92,31 +121,41 @@ AliLog::AliLog() :
   ReadEnvSettings();
 }
 
-//_____________________________________________________________________________
+/**
+ * private destructor
+ */
 AliLog::~AliLog()
 {
 // destructor: clean up and reset instance pointer
 
   if (fRepetitions > 0) PrintRepetitions();
 
-  for (Int_t i = 0; i < fModuleDebugLevels.GetEntriesFast(); i++) {
+  for (Int_t i = 0; i < fModuleDebugLevels.GetEntriesFast(); i++)
+  {
     if (fModuleDebugLevels[i]) fModuleDebugLevels[i]->Delete();
   }
+
   fClassDebugLevels.Delete();
-  for (Int_t i = 0; i < fClassDebugLevels.GetEntriesFast(); i++) {
+
+  for (Int_t i = 0; i < fClassDebugLevels.GetEntriesFast(); i++)
+  {
     if (fClassDebugLevels[i]) fClassDebugLevels[i]->Delete();
   }
+
   fClassDebugLevels.Delete();
 
-  for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+  for (Int_t iType = kFatal; iType < kMaxType; iType++)
+  {
     CloseFile(iType);
   }
+
   fflush(stderr);
   fflush(stdout);
 
   fgInstance = NULL;
 }
 
+// NOT IMPLEMENTED!?
 //_____________________________________________________________________________
 AliLog::AliLog(const AliLog& log) :
   TObject(log),
@@ -138,6 +177,7 @@ AliLog::AliLog(const AliLog& log) :
   Fatal("AliLog", "copy constructor not implemented");
 }
 
+// NOT IMPLEMENTED!?
 //_____________________________________________________________________________
 AliLog& AliLog::operator = (const AliLog& /*log*/)
 {
@@ -148,48 +188,63 @@ AliLog& AliLog::operator = (const AliLog& /*log*/)
 }
 
 
+/**
+ * gSystem see TSystem.h
+ * gEnv see TEnv.h
+ *
+ * LOG_NO_DEBUG: fgDebugEnabled <- false
+ * AliRoot.AliLog.EnableDebug
+ * AliRoot.AliLog.GlobalLogLevel
+ */
 //_____________________________________________________________________________
 void AliLog::ReadEnvSettings()
 {
 // load settings from the root configuration file (.rootrc)
 // and from environment variables
 
-  static const char* typeNames[kMaxType] = 
-    {"kFatal", "kError", "kWarning", "kInfo", "kDebug"};
+  static const char* typeNames[kMaxType] = {"kFatal", "kError", "kWarning", "kInfo", "kDebug"};
 
   // debug en- or disabling
-  if (gSystem->Getenv("LOG_NO_DEBUG")) {
+  if (gSystem->Getenv("LOG_NO_DEBUG"))
+  {
     fgDebugEnabled = kFALSE;
-  } else if (gEnv->Defined("AliRoot.AliLog.EnableDebug")) {
-    fgDebugEnabled = gEnv->GetValue("AliRoot.AliLog.EnableDebug", 
-                                    fgDebugEnabled);
+  }
+  else if (gEnv->Defined("AliRoot.AliLog.EnableDebug"))
+  {
+    fgDebugEnabled = gEnv->GetValue("AliRoot.AliLog.EnableDebug", fgDebugEnabled);
     AliInfo(Form("debug %sabled", ((fgDebugEnabled) ? "en" : "dis")));
   }
 
   // global log level
-  if (gEnv->Defined("AliRoot.AliLog.GlobalLogLevel")) {
+  if (gEnv->Defined("AliRoot.AliLog.GlobalLogLevel"))
+  {
     const char* type = gEnv->GetValue("AliRoot.AliLog.GlobalLogLevel", "");
-    for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+
+    for (Int_t iType = kFatal; iType < kMaxType; iType++)
+    {
       if (strcmp(type, typeNames[iType]) == 0) fGlobalLogLevel = iType;
     }
+
     AliDebug(3, Form("global log level set to %d", fGlobalLogLevel));
   }
 
   // global debug level
-  if (gEnv->Defined("AliRoot.AliLog.GlobalDebugLevel")) {
-    Int_t level = gEnv->GetValue("AliRoot.AliLog.GlobalDebugLevel",
-                                 Int_t(fGlobalLogLevel - kDebugOffset));
+  if (gEnv->Defined("AliRoot.AliLog.GlobalDebugLevel"))
+  {
+    Int_t level = gEnv->GetValue("AliRoot.AliLog.GlobalDebugLevel", Int_t(fGlobalLogLevel - kDebugOffset));
     if (level < -kDebugOffset) level = kDebugOffset;
     fGlobalLogLevel = kDebugOffset + level;
-    AliDebug(3, Form("global debug level set to %d",
-                    fGlobalLogLevel - kDebugOffset));
+    AliDebug(3, Form("global debug level set to %d", fGlobalLogLevel - kDebugOffset));
   }
 
   // module debug level
-  if (gEnv->Defined("AliRoot.AliLog.ModuleDebugLevel")) {
+  if (gEnv->Defined("AliRoot.AliLog.ModuleDebugLevel"))
+  {
     TString levels = gEnv->GetValue("AliRoot.AliLog.ModuleDebugLevel", "");
     char* p = const_cast<char*>(levels.Data());
-    while (const char* module = strtok(p, " ")) {
+
+    while (const char* module = strtok(p, " "))
+    {
       p = NULL;
       char* pos = const_cast<char*>(index(module, ':'));
       if (!pos) continue;
@@ -201,102 +256,120 @@ void AliLog::ReadEnvSettings()
   }
 
   // class debug level
-  if (gEnv->Defined("AliRoot.AliLog.ClassDebugLevel")) {
+  if (gEnv->Defined("AliRoot.AliLog.ClassDebugLevel"))
+  {
     TString levels = gEnv->GetValue("AliRoot.AliLog.ClassDebugLevel", "");
     char* p = const_cast<char*>(levels.Data());
-    while (const char* className = strtok(p, " ")) {
+
+    while (const char* className = strtok(p, " "))
+    {
       p = NULL;
       char* pos = const_cast<char*>(index(className, ':'));
       if (!pos) continue;
       *(pos++) = '\0';
       Int_t level = atoi(pos);
       SetClassDebugLevel(className, level);
-      AliDebug(3, Form("debug level for class %s set to %d", 
-                       className, level));
+      AliDebug(3, Form("debug level for class %s set to %d", className, level));
     }
   }
 
   // general output stream
-  if (gEnv->Defined("AliRoot.AliLog.Output")) {
+  if (gEnv->Defined("AliRoot.AliLog.Output"))
+  {
     TString stream = gEnv->GetValue("AliRoot.AliLog.Output", "Standard");
-    if (stream.CompareTo("standard", TString::kIgnoreCase) == 0) {
+
+    if (stream.CompareTo("standard", TString::kIgnoreCase) == 0)
+    {
       SetStandardOutput();
       AliDebug(3, "output stream set to standard output for all types");
-    } else if (stream.CompareTo("error", TString::kIgnoreCase) == 0) {
+    }
+    else if (stream.CompareTo("error", TString::kIgnoreCase) == 0)
+    {
       SetErrorOutput();
       AliDebug(3, "output stream set to error output for all types");
-    } else if (!stream.IsNull()) {
+    }
+    else if (!stream.IsNull())
+    {
       SetFileOutput(stream);
-      AliDebug(3, Form("output stream set to file %s for all types", 
-                       stream.Data()));
+      AliDebug(3, Form("output stream set to file %s for all types", stream.Data()));
     }
   }
 
   // individual output streams
-  for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+  for (Int_t iType = kFatal; iType < kMaxType; iType++)
+  {
     TString name("AliRoot.AliLog.Output.");
     name += &typeNames[iType][1];
-    if (gEnv->Defined(name)) {
+
+    if (gEnv->Defined(name))
+    {
       TString stream = gEnv->GetValue(name, "Standard");
-      if (stream.CompareTo("standard", TString::kIgnoreCase) == 0) {
+
+      if (stream.CompareTo("standard", TString::kIgnoreCase) == 0)
+      {
         SetStandardOutput(EType_t(iType));
-        AliDebug(3, Form("output stream set to standard output for type %s",
-                         typeNames[iType]));
-      } else if (stream.CompareTo("error", TString::kIgnoreCase) == 0) {
+        AliDebug(3, Form("output stream set to standard output for type %s", typeNames[iType]));
+      }
+      else if (stream.CompareTo("error", TString::kIgnoreCase) == 0)
+      {
         SetErrorOutput(EType_t(iType));
-        AliDebug(3, Form("output stream set to error output for type %s",
-                         typeNames[iType]));
-      } else if (!stream.IsNull()) {
+        AliDebug(3, Form("output stream set to error output for type %s", typeNames[iType]));
+      }
+      else if (!stream.IsNull())
+      {
         SetFileOutput(EType_t(iType), stream);
-        AliDebug(3, Form("output stream set to file %s for type %s", 
-                         stream.Data(), typeNames[iType]));
+        AliDebug(3, Form("output stream set to file %s for type %s", stream.Data(), typeNames[iType]));
       }
     }
   }
 
   // handling of root error messages
-  if (gEnv->Defined("AliRoot.AliLog.HandleRootMessages")) {
+  if (gEnv->Defined("AliRoot.AliLog.HandleRootMessages"))
+  {
     Bool_t on = gEnv->GetValue("AliRoot.AliLog.HandleRootMessages", kTRUE);
     SetHandleRootMessages(on);
-    AliDebug(3, Form("handling of root messages %sabled",
-                     ((on) ? "en" : "dis")));
+    AliDebug(3, Form("handling of root messages %sabled", ((on) ? "en" : "dis")));
   }
 
   // printout settings
-  static const char* settingNames[4] = 
-    {"Type", "Module", "Scope", "Location"};
-  Bool_t* settings[] = 
-    {fPrintType, fPrintModule, fPrintScope, fPrintLocation};
-  for (Int_t iSetting = 0; iSetting < 4; iSetting++) {
+  static const char* settingNames[4] = {"Type", "Module", "Scope", "Location"};
+  Bool_t* settings[] = {fPrintType, fPrintModule, fPrintScope, fPrintLocation};
+
+  for (Int_t iSetting = 0; iSetting < 4; iSetting++)
+  {
     TString name("AliRoot.AliLog.Print");
     name += settingNames[iSetting];
-    if (gEnv->Defined(name)) {
+
+    if (gEnv->Defined(name))
+    {
       Bool_t on = gEnv->GetValue(name, settings[iSetting][0]);
-      for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+
+      for (Int_t iType = kFatal; iType < kMaxType; iType++)
+      {
         settings[iSetting][iType] = on;
       }
-      AliDebug(3, Form("printing of %s %sabled for all types",
-                       settingNames[iSetting], ((on) ? "en" : "dis")));
+      AliDebug(3, Form("printing of %s %sabled for all types", settingNames[iSetting], ((on) ? "en" : "dis")));
     }
 
-    for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+    for (Int_t iType = kFatal; iType < kMaxType; iType++)
+    {
       TString nameType = name + "." + &typeNames[iType][1];
-      if (gEnv->Defined(nameType)) {
+
+      if (gEnv->Defined(nameType))
+      {
         Bool_t on = gEnv->GetValue(nameType, settings[iSetting][iType]);
         settings[iSetting][iType] = on;
-        AliDebug(3, Form("printing of %s %sabled for type %s",
-                         settingNames[iSetting], ((on) ? "en" : "dis"),
-                         typeNames[iType]));
+        AliDebug(3, Form("printing of %s %sabled for type %s", settingNames[iSetting], ((on) ? "en" : "dis"), typeNames[iType]));
       }
     }
   }
 
   // repetition of messages
-  if (gEnv->Defined("AliRoot.AliLog.PrintRepetitions")) {
+  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")));
+    AliDebug(3, Form("printing of message repetitions %sabled", ((on) ? "en" : "dis")));
   }
 }
 
@@ -307,7 +380,8 @@ void AliLog::RootErrorHandler(Int_t level, Bool_t abort,
 {
 // new error handler for messages from root
 
-  switch (level) {
+  switch (level)
+  {
   case ::kFatal    : level = kFatal; break;
   case ::kSysError :
     DefaultErrorHandler(level, abort, location, message);
@@ -324,6 +398,7 @@ void AliLog::RootErrorHandler(Int_t level, Bool_t abort,
 }
 
 
+// DEPRECATED: USE A CONFIGURATION FILE INSTEAD
 //_____________________________________________________________________________
 void AliLog::EnableDebug(Bool_t enabled)
 {
@@ -337,6 +412,7 @@ void AliLog::SetGlobalLogLevel(EType_t type)
 {
 // set the global debug level
 
+  // TO BE DELETED
   if (!fgInstance) new AliLog; 
   fgInstance->fGlobalLogLevel = type;
 }
index 14d689d9dfe49044e5459cec567c80d59c4fffd9..d9056d0e2b0be273cfc20d341cae293a90930dc0 100644 (file)
@@ -5,25 +5,45 @@
 
 /* $Id$ */
 
-///
-/// class for logging debug, info and error messages
-///
-
 #include <TObject.h>
 #include <TObjArray.h>
 #include <TString.h>
 
+// deprecation macro
+#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+#define ALIROOT_DEPRECATED(func) func  __attribute__ ((deprecated))
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
+#define ALIROOT_DEPRECATED(func) __declspec(deprecated) func
+# else
+#define ALIROOT_DEPRECATED(func) func
+#endif
 
-class AliLog: public TObject {
+/**
+ * class for logging debug, info and error messages
+ */
+class AliLog: public TObject
+{
  public:
-  AliLog();
-  virtual ~AliLog();
-  static AliLog* Instance() {return fgInstance;}
 
+               // Log4j log levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL
   enum EType_t {kFatal = 0, kError, kWarning, kInfo, kDebug, kMaxType};
   typedef void (*AliLogNotification)(EType_t type, const char* message );
 
+               // NB: singleton constructor & destructor should not be public!
+               // ALIROOT_DEPRECATED(AliLog());
+               // ALIROOT_DEPRECATED(virtual ~AliLog());
+
+               // NB: singleton deprecated static instance method
+               // ALIROOT_DEPRECATED(static AliLog* Instance() {return fgInstance;};)
+
+               // get root logger singleton instance
+               static AliLog *GetRootLogger();
 
+               // delete root logger singleton instance
+               static void DeleteRootLogger();
+
+               // NB: the following functions should not be static
+               // NB: deprecated: logging configuration should be made through to a configuration file
   static void  EnableDebug(Bool_t enabled);
   static void  SetGlobalLogLevel(EType_t type);
   static Int_t GetGlobalLogLevel();
@@ -86,6 +106,12 @@ class AliLog: public TObject {
                          const char* function, const char* file, Int_t line);
 
  private:
+
+               // constructor is made private for implementing a singleton
+               AliLog();
+               virtual ~AliLog();
+
+               // NOT IMPLEMENTED?
   AliLog(const AliLog& log);
   AliLog& operator = (const AliLog& log);
 
@@ -118,7 +144,6 @@ class AliLog: public TObject {
   enum {kDebugOffset = kDebug-1};
 
   static AliLog* fgInstance;                 //! pointer to current instance
-
   static Bool_t  fgDebugEnabled;             // flag for debug en-/disabling
 
   UInt_t         fGlobalLogLevel;            // global logging level
@@ -151,14 +176,14 @@ class AliLog: public TObject {
 };
 
 
-// module name
+// module name macro
 #ifdef _MODULE_
 #define MODULENAME() _MODULE_
 #else
 #define MODULENAME() "NoModule"
 #endif
 
-// function name
+// function name macro
 #if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__)
 #define FUNCTIONNAME() __FUNCTION__
 // #elif defined(__HP_aCC) || defined(__alpha) || defined(__DECCXX)
@@ -194,7 +219,7 @@ class AliLog: public TObject {
 // inspired by log4cxx code (see log4cxx/Logger.h)
 // implements GCC branch prediction for increasing logging performance
 #if !defined(ALIROOT_UNLIKELY)
-#if __GNUC__ >= 3
+#if defined(__GNUC__) && (__GNUC__ >= 3)
 /**
 Provides optimization hint to the compiler
 to optimize for the expression being false.
@@ -296,7 +321,6 @@ Logs a message to a specified logger with the DEBUG level.
 #define AliInfoClassStream() AliLog::Stream(AliLog::kInfo, 0, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__)
 #define AliInfoGeneralStream(scope) AliLog::Stream(AliLog::kInfo, 0, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__)
 
-
 // warning messages
 #ifdef LOG_NO_WARNING
 #define AliWarning(message)