CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDdebug.h
Go to the documentation of this file.
1 #ifndef DDdebug_h
2 #define DDdebug_h
3 
4 // Message logger.
6 
7  // If DDEBUG is defined, the debug macros DCOUT and DCOUT_V are active
8  // Undefined DDEBUG redefines DCOUT and DCOUT_V to not to produce any code.
9 #define DDEBUG
10 
11  #ifdef DDEBUG
12  // Extended debug macros: DDEBUG(a,b) and DDEBUG_V(a,b) for extended verbosity
13  // Both macros are kind of CPU intensive (calls to getenv, loop over a std::string)
14  //
15  // Usage: DEBUGOUT(char, std::ostream )
16  // char (i.e. 'P') defines the module which should produce debug-output
17  // At runtime the environment variables DDEBUG and DDEBUG_V specify which
18  // module should activate its debug-output.
19  //
20  // Example:
21  // file DDCore/src/a.cc: DCOUT('C',"Debuginfo of moule C" << i_ << j_ );
22  // file Parser/src/b.cc: DCOUT('P',"Parser debug");
23  // runtime: setenv DDEBUG P > activates debug-output of a.cc
24  // setenv DDEBUG C > activates debug-output of b.cc
25  // setenv DDEBUG PC > activated debug-output of a.cc and b.cc
26 
27 
28  #include <cstdlib>
29  #include <iostream>
30  #include <string>
31 
32  inline const char* ddDebug() {
33  static const char* c = getenv("DDEBUG");
34  return c;
35 }
36 
37  inline const char* ddDebugV() {
38  static const char* c = getenv("DDEBUG_V");
39  return c;
40 }
41 
42 inline const std::string & ddDebugS() {
43  static const std::string s(ddDebug()? ddDebug(): "");
44  return s;
45 }
46 
47 inline const std::string & ddDebugVS() {
48  static const std::string s(ddDebugV()? ddDebugV(): "");
49  return s;
50 }
51 
52 
53  #define DCOUT(M_v_Y,M_v_S) { for(std::string::size_type M_v_i=0; M_v_i < ddDebugS().size(); ++M_v_i) if(ddDebugS()[M_v_i]==M_v_Y) LogDebug("DDdebug") << ddDebugS()[M_v_i] << " : " << M_v_S << std::endl; }
54  #define DCOUT_V(M_v_Y,M_v_S) { for(std::string::size_type M_v_i=0; M_v_i < ddDebugVS().size(); ++M_v_i) if(ddDebugVS()[M_v_i]==M_v_Y) LogDebug("DDdebug") << ddDebugVS()[M_v_i] << "v: " << M_v_S << std::endl; }
55 
56  // backward compatiblility, don't use anymore!
57  #define DEBUGOUT(s) if (ddDebug()) { LogDebug("DDdebug") << s << std::endl; }
58  #define DEBUGOUT_V(s) if (ddDebugV()) { LogDebug("DDdebug") << s << std::endl; }
59 
60  #else
61 
62  #define DCOUT(M_v_Y, M_v_s)
63  #define DCOUT_V(M_v_Y, M_v_s)
64  #define DEBUGOUT(s)
65  #define DEBUGOUT_V(s)
66 
67  #endif
68 
72 int DDmem();
73 int DDtime();
74 
75 #endif
const char * ddDebugV()
Definition: DDdebug.h:37
const char * ddDebug()
Definition: DDdebug.h:32
int DDtime()
const std::string & ddDebugS()
Definition: DDdebug.h:42
int DDmem()
const std::string & ddDebugVS()
Definition: DDdebug.h:47