]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTLogging.h
Added files for the reference version based on an old version of Anders'
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTLogging.h
1 // @(#) $Id: 
2
3 #ifndef ALIHLTLOGGING_H
4 #define ALIHLTLOGGING_H
5 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6  * See cxx source for full Copyright notice                               */
7
8 /* AliHLTLogging
9    the HLT logging methods
10  */
11
12
13 #include "AliHLTDataTypes.h"
14 #include <TObject.h>
15 #include <stdio.h>
16
17 #define LOG_BUFFER_SIZE 100 // global logging buffer
18 //#define LOG_PREFIX ""       // logging prefix, for later extensions
19
20
21 /* the logging macros can be used inside methods of classes which inherit from 
22  * AliHLTLogging
23  */
24 // HLTMessage is not filtered
25 #define HLTMessage( ... )   LoggingVarargs(kHLTLogNone,      NULL , NULL ,  __VA_ARGS__ )
26
27 // the following macros are filtered by the Global and Local Log Filter
28 #define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, this->Class_Name() , __func__ ,  __VA_ARGS__ )
29 #define HLTDebug( ... )     LoggingVarargs(kHLTLogDebug,     this->Class_Name() , __func__ ,  __VA_ARGS__ )
30 #define HLTInfo( ... )      LoggingVarargs(kHLTLogInfo,      this->Class_Name() , __func__ ,  __VA_ARGS__ )
31 #define HLTWarning( ... )   LoggingVarargs(kHLTLogWarning,   this->Class_Name() , __func__ ,  __VA_ARGS__ )
32 #define HLTError( ... )     LoggingVarargs(kHLTLogError,     this->Class_Name() , __func__ ,  __VA_ARGS__ )
33 #define HLTFatal( ... )     LoggingVarargs(kHLTLogFatal,     this->Class_Name() , __func__ ,  __VA_ARGS__ )
34
35 // helper macro to set the keyword
36 #define HLTLogKeyword(a)    AliHLTKeyword __hltlog_tmpkey__LINE__(this, a)
37
38 #define HLT_DEFAULT_LOG_KEYWORD "no key"
39
40 class AliHLTLogging {
41 public:
42   AliHLTLogging();
43   virtual ~AliHLTLogging();
44
45   // logging filter for all objects
46   //
47   static AliHLTComponent_LogSeverity SetGlobalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;}
48
49   // logging filter for individual object
50   //
51   AliHLTComponent_LogSeverity SetLocalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;}
52
53   // set the default key word
54   // the keyword is intended to simplify the use of logging macros
55   // 
56   void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
57
58   // set a temporary keyword
59   // returns the old key value
60   const char* SetKeyword(const char* keyword) 
61     { 
62       const char* currentKeyword=fpCurrentKeyword;
63       fpCurrentKeyword=keyword;
64       return currentKeyword; 
65     }
66
67   // get the current keyword
68   //
69   const char* GetKeyword()
70     {
71       if (fpCurrentKeyword) return fpCurrentKeyword;
72       else if (fpDefaultKeyword) return fpDefaultKeyword;
73       return HLT_DEFAULT_LOG_KEYWORD;
74     }
75   
76   static int Init(AliHLTfctLogging pFun) { fLoggingFunc=pFun; return 0;}
77
78   // genaral logging function
79   //
80   int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
81
82   // logging function with two origin parameters, used by the log macros
83   //
84   int LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func,  ... );
85
86   // apply filter, return 1 if message should pass
87   //
88   int CheckFilter(AliHLTComponent_LogSeverity severity);
89
90   static int Message(void * param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message);
91
92   static const char* BuildLogString(const char *format, va_list ap);
93
94   virtual void* GetParameter() {return NULL;}
95 protected:
96
97 private:
98   static  AliHLTComponent_LogSeverity fGlobalLogFilter;
99   AliHLTComponent_LogSeverity fLocalLogFilter;
100   static char fLogBuffer[LOG_BUFFER_SIZE];
101   static char fOriginBuffer[LOG_BUFFER_SIZE];
102   static AliHLTfctLogging fLoggingFunc;
103   const char* fpDefaultKeyword;
104   const char* fpCurrentKeyword;
105
106   ClassDef(AliHLTLogging, 0)
107 };
108
109 /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
110  * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
111  * the object is destroyed automatically when the current scope is left and so the keyword is set
112  * to the original value
113  */
114 class AliHLTKeyword {
115  public:
116   AliHLTKeyword()
117     {
118       fpParent=NULL;
119       fpOriginal=NULL;
120     }
121
122   AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
123     {
124       fpOriginal=NULL;
125       if (parent) {
126         fpParent=parent;
127         fpOriginal=fpParent->SetKeyword(keyword);
128       }
129     }
130
131   ~AliHLTKeyword()
132     {
133       if (fpParent) {
134         fpParent->SetKeyword(fpOriginal);
135       }
136     }
137
138  private:
139   AliHLTLogging* fpParent;
140   const char* fpOriginal;
141 };
142 #endif
143