forked from JeffersonLab/SBS-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugDef.h
192 lines (161 loc) · 6.08 KB
/
DebugDef.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//////////////////////////////////////////////////////////////////////////
//
// DebugDef.h
//
// debug handling routines for root-based classes.
//
// This file defines a number of predefined debug handling routines:
// assert, DEBUG_<LEVEL> and DEBUG_LINE_<LEVEL>
// Where <LEVEL> could be WARNING, INFO or MASSINFO
//
//////////////////////////////////////////////////////////////////////////
//
// Author: Jin Huang <mailto:[email protected]> Feb 2008
// Modify History:
// Feb 2008 DEBUG_LEVEL_RELATED_PERFORMACE_CHECKER
//
//////////////////////////////////////////////////////////////////////////
/*
REQUIREMENTS
1.In the head file of a root-based class, insert the following lines BELOW
any other header files:
//------------------------------------------------------//
//
// Debug Definitions
// place this section below any other head files
//
//------------------------------------------------------//
#ifdef DEBUG_LEVEL
# undef DEBUG_LEVEL
#endif
// DEBUG_LEVEL;
// =0 or not define: no debug, full speed
// >=1 enable debug extra warning (suggested setting)
// >=2 above + enable debug assert
// >=3 above + enable debug extra info
// >=4 above + massive info (in a for or while)
#define DEBUG_LEVEL 1
#include "DebugDef.h"
//------------------------------------------------------//
Where DEBUG_LEVEL will control which debug handling routines to be
execused as discussed in next section
2.in the .cxx file the the same class, include the header file of that class
BELOW any other header files
3.(Optional, Hall A Analyzer Only, Suggested)
add to the constructor of the class the following line:
DEBUG_LEVEL_RELATED_PERFORMACE_CHECKER;
4.(Optional, Hall A Analyzer Only)
add to the constructor of the class the following line:
DEBUG_HALL_A_ANALYZER_DEBUGER_INIT;
USAGE
Once above requirement is satisified, following routines should be working:
1.assert(exp)
only effect when DEBUG_LEVEL>=2, other wise do nothing
check whether exp is ture. If not, stop the code and print exp on screen
2.DEBUG_WARNING(location,...)
only effect when DEBUG_LEVEL>=1, other wise do nothing
DEBUG_WARNING works just like Warning(); function of TObject.
See its description on
http://root.cern.ch/root/html/TObject.html#TObject:Warning
3.DEBUG_INFO(location,...)
only effect when DEBUG_LEVEL>=3, other wise do nothing
DEBUG_INFO works just like Info(); function of TObject.
See its description on
http://root.cern.ch/root/html/TObject.html#TObject:Info
4.DEBUG_MASSINFO(location,...)
only effect when DEBUG_LEVEL>=4, other wise do nothing
suggested usage is for step by step TRACE or info in a LOOP
DEBUG_MASSINFO works just like Info(); function of TObject.
See its description on
http://root.cern.ch/root/html/TObject.html#TObject:Info
5.DEBUG_LINE_LEVEL(level,exp) and DEBUG_LINE_<LEVEL>(exp)
only execute exp when DEBUG_LEVEL>=level. Similarly, you can demonstrate
the levle by its name using DEBUG_LINE_<LEVEL>(exp)
Where <LEVEL> could be WARNING, INFO or MASSINFO
6.Of course if you have more than one line to be controled by DEBUG_LEVEL
#if DEBUG_LEVEL>= <some level>
...
#endif
7.DEBUG_LEVEL_OVERRIDE
You can overide all DEBUG_LEVEL settings in any class using
thisheader file by change the value DEBUG_LEVEL_OVERRIDE to a
desiderated DEBUG_LEVEL value. Only a non-negative value is
effective.
You can also define a DEBUG_LEVEL_OVERRIDE in MakeFile.
GUIDELINE FOR DEBUG_LEVEL
DEBUG_LEVEL;
<1 or not define: no debug, full speed
>=1 enable debug extra warning (suggested setting for most release code)
>=2 above + enable debug assert
>=3 above + enable debug extra info
>=4 above + massive info (step by step tracing or in info within a loop)
*/
//
#if !defined(DEBUG_LEVEL_OVERRIDE)
//------------------------------------------
// change DEBUG_LEVEL_OVERRIDE value here
//
// You can overide all DEBUG_LEVEL settings in any class using
// thisheader file by change the value DEBUG_LEVEL_OVERRIDE to a
// desiderated DEBUG_LEVEL value. Only a non-negative value is
// effective.
// You can also define a DEBUG_LEVEL_OVERRIDE in MakeFile.
#define DEBUG_LEVEL_OVERRIDE -1
//------------------------------------------
#endif
#if DEBUG_LEVEL_OVERRIDE>=0
# undef DEBUG_LEVEL
# define DEBUG_LEVEL DEBUG_LEVEL_OVERRIDE
#endif
#undef DEBUG_WARNING
#undef DEBUG_LINE_WARNING
#if DEBUG_LEVEL>=1//start show warning
# define DEBUG_WARNING(location,...) Warning(location,__VA_ARGS__);
# define DEBUG_LINE_WARNING(exp) exp;
#else
# define DEBUG_WARNING(location,...) ((void)0)
# define DEBUG_LINE_WARNING(exp) ((void)0)
#endif
#undef NDEBUG
#if DEBUG_LEVEL<2
# define NDEBUG
#endif
#include <cassert>
#undef DEBUG_INFO
#undef DEBUG_LINE_INFO
#if DEBUG_LEVEL>=3//start show info
# define DEBUG_INFO(location,...) Info(location,__VA_ARGS__);
# define DEBUG_LINE_INFO(exp) exp;
#else
# define DEBUG_INFO(location,...) ((void)0)
# define DEBUG_LINE_INFO(exp) ((void)0)
#endif
#undef DEBUG_MASSINFO
#undef DEBUG_LINE_MASSINFO
#if DEBUG_LEVEL>=4//start show massive info.
//Suitable for step by step trace or info in a loop
# define DEBUG_MASSINFO(location,...) Info(location,__VA_ARGS__);
# define DEBUG_LINE_MASSINFO(exp) exp;
#else
# define DEBUG_MASSINFO(location,...) ((void)0)
# define DEBUG_LINE_MASSINFO(exp) ((void)0)
#endif
#undef DEBUG_LINE_LEVEL
#define DEBUG_LINE_LEVEL(level,exp) if (DEBUG_LEVEL>=level) {exp;}
#define DEBUG_HALL_A_ANALYZER_DEBUGER_INIT \
if (DEBUG_LEVEL>=4)\
SetDebug(2);\
else if (DEBUG_LEVEL>=3)\
SetDebug(1);\
else\
SetDebug(0);
#undef DEBUG_LEVEL_RELATED_PERFORMACE_CHECKER
#if DEBUG_LEVEL>2
# define DEBUG_LEVEL_RELATED_PERFORMACE_CHECKER \
Warning(Here("Constructor"),\
"\tThis class is compliled with DEBUG_LEVEL=%d."\
"\n\tChange DEBUG_LEVEL to <=1 to gain full speed.",\
DEBUG_LEVEL);
#else
# define DEBUG_LEVEL_RELATED_PERFORMACE_CHECKER ((void)0)
#endif