]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTLogging.cxx
adapting dndeta analysis to new AliCorrection schema
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTLogging.cxx
CommitLineData
3495cce2 1// $Id:
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
3495cce2 8 * for The ALICE Off-line Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
b22e91eb 19/** @file AliHLTLogging.cxx
20 @author Matthias Richter, Timm Steinbeck
21 @date
22 @brief Implementation of HLT logging primitives.
23*/
3495cce2 24
0c0c9d99 25#if __GNUC__>= 3
3495cce2 26using namespace std;
27#endif
28
85869391 29#include "AliHLTStdIncludes.h"
3495cce2 30#include "AliHLTLogging.h"
3495cce2 31
5f1685a0 32// global logging buffer
33#define LOG_BUFFER_SIZE 100
34char gAliHLTLoggingBuffer[LOG_BUFFER_SIZE]="";
35char gAliHLTLoggingOriginBuffer[LOG_BUFFER_SIZE]="";
36
b22e91eb 37/** ROOT macro for the implementation of ROOT specific class methods */
3495cce2 38ClassImp(AliHLTLogging)
39
3495cce2 40AliHLTLogging::AliHLTLogging()
85869391 41 :
42 fpDefaultKeyword(NULL),
43 fpCurrentKeyword(NULL),
44 //fLocalLogFilter(kHLTLogDefault),
45 fLocalLogFilter(kHLTLogAll)
3495cce2 46{
85869391 47}
48
49AliHLTLogging::AliHLTLogging(const AliHLTLogging&)
50 :
51 fpDefaultKeyword(NULL),
52 fpCurrentKeyword(NULL),
53 fLocalLogFilter(kHLTLogAll)
54{
55 HLTFatal("copy constructor untested");
56}
57
58AliHLTLogging& AliHLTLogging::operator=(const AliHLTLogging&)
59{
60 HLTFatal("assignment operator untested");
61 return *this;
3495cce2 62}
63
b22e91eb 64AliHLTComponent_LogSeverity AliHLTLogging::fGlobalLogFilter=kHLTLogAll;
65AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL;
3495cce2 66
67AliHLTLogging::~AliHLTLogging()
68{
69}
70
bb16cc41 71int AliHLTLogging::Init(AliHLTfctLogging pFun)
72{
73 if (fLoggingFunc!=NULL && fLoggingFunc!=pFun) {
74 (*fLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function");
75 }
76 fLoggingFunc=pFun;
77 return 0;
78}
79
3495cce2 80int AliHLTLogging::Message(void *param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message) {
81 int iResult=0;
82 const char* strSeverity="";
83 switch (severity) {
84 case kHLTLogBenchmark:
85 strSeverity="benchmark";
86 break;
87 case kHLTLogDebug:
88 strSeverity="debug";
89 break;
90 case kHLTLogInfo:
91 strSeverity="info";
92 break;
93 case kHLTLogWarning:
94 strSeverity="warning";
95 break;
96 case kHLTLogError:
97 strSeverity="error";
98 break;
99 case kHLTLogFatal:
100 strSeverity="fatal";
101 break;
102 default:
103 break;
104 }
85465857 105 cout << "HLT Log " << strSeverity << ": " << origin << " " << message;
106 if (strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0)
107 cout << " (" << keyword << ")";
108 cout << endl;
3495cce2 109 return iResult;
110}
111
112const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) {
113 int tgtLen=0;
114 int iBufferSize=LOG_BUFFER_SIZE;
5f1685a0 115 char* tgtBuffer=gAliHLTLoggingBuffer;
3495cce2 116 tgtBuffer[tgtLen]=0;
117
85465857 118#if (defined LOG_PREFIX)
3495cce2 119 tgtLen = snprintf(tgtBuffer, iBufferSize, LOG_PREFIX); // add logging prefix
85465857 120#endif
3495cce2 121 if (tgtLen>=0) {
122 tgtBuffer+=tgtLen; iBufferSize-=tgtLen;
123 tgtLen = vsnprintf(tgtBuffer, iBufferSize, format, ap);
124 if (tgtLen>0) {
125 tgtBuffer+=tgtLen;
126// if (tgtLen<LOG_BUFFER_SIZE-1) {
127// *tgtBuffer++='\n'; // add newline if space in buffer
128// }
129 *tgtBuffer=0; // terminate the buffer
130 }
131 }
5f1685a0 132 return gAliHLTLoggingBuffer;
3495cce2 133}
134
135int AliHLTLogging::Logging(AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* format, ... ) {
85465857 136 int iResult=CheckFilter(severity);
137 if (iResult>0) {
138 va_list args;
139 va_start(args, format);
140 if (fLoggingFunc) {
141 iResult = (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
142 } else {
143 iResult = Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
144 }
3495cce2 145 }
85465857 146 return iResult;
3495cce2 147}
148
85869391 149int AliHLTLogging::LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func, ... ) const
3495cce2 150{
85465857 151 int iResult=CheckFilter(severity);
152 if (iResult>0) {
153 int iMaxSize=LOG_BUFFER_SIZE-1;
154 int iPos=0;
155 const char* separator="";
5f1685a0 156 gAliHLTLoggingOriginBuffer[iPos]=0;
85465857 157 if (origin_class) {
158 if ((int)strlen(origin_class)<iMaxSize-iPos) {
5f1685a0 159 strcpy(&gAliHLTLoggingOriginBuffer[iPos], origin_class);
85465857 160 iPos+=strlen(origin_class);
161 separator="::";
162 }
3495cce2 163 }
85465857 164 if (origin_func) {
165 if ((int)strlen(origin_func)+(int)strlen(separator)<iMaxSize-iPos) {
5f1685a0 166 strcpy(&gAliHLTLoggingOriginBuffer[iPos], separator);
85465857 167 iPos+=strlen(separator);
5f1685a0 168 strcpy(&gAliHLTLoggingOriginBuffer[iPos], origin_func);
85465857 169 iPos+=strlen(origin_func);
170 }
3495cce2 171 }
85465857 172 va_list args;
173 va_start(args, origin_func);
174 const char* format = va_arg(args, const char*);
175
176 const char* message=format;
177 char* qualifier=NULL;
178 if ((qualifier=strchr(format, '%'))!=NULL) {
179 message=AliHLTLogging::BuildLogString(format, args);
180 }
181 if (fLoggingFunc) {
5f1685a0 182 iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, gAliHLTLoggingOriginBuffer, GetKeyword(), message);
85465857 183 } else {
5f1685a0 184 iResult=Message(NULL/*fParam*/, severity, gAliHLTLoggingOriginBuffer, GetKeyword(), message);
85465857 185 }
186 va_end(args);
3495cce2 187 }
3495cce2 188 return iResult;
189}
190
85869391 191int AliHLTLogging::CheckFilter(AliHLTComponent_LogSeverity severity) const
3495cce2 192{
85465857 193 int iResult=severity==kHLTLogNone || (severity&fGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0;
3495cce2 194 return iResult;
195}