]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/src/Utils.hpp
e476f4fa47c29fe373eaefb81443d6549e403e96
[u/mrichter/AliRoot.git] / HLT / MUON / src / Utils.hpp
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Author: Artur Szostak
4 // Email:  artur@alice.phy.uct.ac.za | artursz@iafrica.com
5 //
6 ////////////////////////////////////////////////////////////////////////////////
7
8 #ifndef dHLT_UTILITIES_HPP
9 #define dHLT_UTILITIES_HPP
10
11 /* Since c++ is missing a finally "keyword" we define one. Its usage is identical
12    to a try..finally statement in Java etc.. however, since it is officialy a macro
13    one must use the ( ) brackets instead of { }
14  */
15
16 // if the compiler supports __finally use it otherwise make our own
17 #if defined(__BORLANDC__)
18
19 #       define finally(str) __finally{str}
20
21 #else
22
23 #       define finally(code) \
24                 catch(...) \
25                 { \
26                         code \
27                         throw; \
28                 }; \
29                 code
30
31 #endif // __BORLANDC__
32
33
34 /* Define logical operators that are easier to read.
35    and = &&
36    or = ||
37    not = !
38  */
39 #ifndef __GNUC__
40
41 #       define and &&
42 #       define or ||
43 #       define not !
44
45 #endif // GCC
46
47
48 #ifdef DEBUG
49
50 #       ifdef __ROOT__
51 #               include <TError.h>
52 #       else
53 #               include <cassert>
54                 // Define assert with a capital first letter to maintain coding style. 
55 #               define Assert(statement) assert(statement);
56 #       endif // __ROOT__
57
58         // Any code that should be compiled in only when the DEBUG macro is specified
59         // can be enclosed with this DebugCode macro.
60 #       define DebugCode(code) code
61
62 #else // DEBUG
63
64 #       ifdef __ROOT__
65 #               include <TError.h>
66 #       else
67 #               define Assert(statement)
68 #       endif // __ROOT__
69
70 #       define DebugCode(code)
71
72 #endif // DEBUG
73
74
75 #ifdef DEBUG
76 namespace dHLT
77 {
78         extern int DebugLevel;
79 };
80 #endif // DEBUG
81
82
83 /* Here we define the DebugMsg(level, message) macro for easy embedding of debug information
84    into a program. The output is only generated in programs compiled with the DEBUG macro
85    defined. Here is a usage example:
86    
87        // statements...
88        DebugMsg(2, "some debug information.");
89        // statements...
90        
91    One can also use C++ ostream operators << like so:
92    
93        // statements...
94        int x, y;
95        DebugMsg(2, "x = " << x << " and y = " << y );
96        // statements...
97  */
98 #ifdef USE_ALILOG
99
100 #       include "AliLog.h"
101
102         // We are defining this DebugMsg_PREECODE macro to use in DebugMsg in such a way
103         // so that the code is removed when the LOG_NO_DEBUG macro is specified but 
104         // compiled otherwise.
105 #       include <sstream>
106 #       ifndef LOG_NO_DEBUG
107 #               define __DebugMsg_PREECODE__(message) std::ostringstream os; os << message;
108 #       else // LOG_NO_DEBUG
109 #               define __DebugMsg_PREECODE__(message) 
110 #       endif // LOG_NO_DEBUG
111
112 #       define DebugMsg(level, message) \
113                 { \
114                         __DebugMsg_PREECODE__(message) \
115                         AliDebug(level, os.str()); \
116                 }
117
118 #else // USE_ALILOG
119
120 #       include <iostream>
121 #       define DebugMsg(level, message) \
122                 DebugCode( if (dHLT::DebugLevel > level) std::cout << message << std::endl; )
123
124 #endif // USE_ALILOG
125
126
127 #endif // dHLT_BASIC_TYPES_HPP