BOSS
8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/ers/include/ers/ers.h
Go to the documentation of this file.
1
/*
2
* ers.h
3
* ers
4
*
5
* Created by Matthias Wiesmann on 26.01.05.
6
* Copyright 2005 CERN. All rights reserved.
7
*
8
*/
9
10
/** \file ers.h This file includes all the main headers of the Error Reporting System.
11
* It does not declare anything <em>per se</em>, it does contains the doxygen code to
12
* generate all the general documentation for the package.
13
* \author Matthias Wiesmann
14
* \version 1.1 Removed dependency on System package
15
* \brief ers header and documentation file
16
*/
17
18
#include "ers/Context.h"
19
#include "ers/Core.h"
20
21
#include "ers/Issue.h"
22
#include "ers/IssueFactory.h"
23
#include "ers/Stream.h"
24
#include "ers/StreamFactory.h"
25
26
#include "ers/Assertion.h"
27
#include "ers/InvalidReferenceIssue.h"
28
#include "ers/LogIssue.h"
29
#include "ers/NotImplemented.h"
30
#include "ers/Precondition.h"
31
#include "ers/RangeIssue.h"
32
33
/** \page ERSHowTo How to use the ERS package
34
The goal of the Error Reporting System is to offer tool to simplify and unify error handling
35
and error reporting in TDAQ applications. This package can be used at different levels. At
36
the lowest level, one can simply use the existing checking macros. A more advanced way of
37
using this package is to define specific Issue subclasses. \section Macros Basic macros Basic
38
ERS functionality can be accessed by using simple macros. Those macros are available simply
39
by including the ers/ers.h header file. \subsection AssertionMacros Assertion Macros The ERS
40
package offers a set of macros to do basic checking. Those macros generally behave like the
41
standard C assert macros. They have the following features:<ul> <li>Different types of
42
checks: <ul> <li>Compile time checks (\c ERS_STATIC_ASSERT) those should be used to verity
43
certain assertions at compile-time. For instance if you code rely on certain data structures
44
having certain memory sizes, this can be checked using static assertions. <li>Preconditions
45
(\c ERS_PRECONDITION) those should be used to check condition when entering functions. For
46
instance if you only accept certain values for parameters precondtions should verify that
47
those conditions are resepected. <li>Pointer precondition (\c ERS_PRE_CHECK_PTR) this special
48
type of pre-condition checks that a pointer is valid (not null), you should this macro to
49
check all pointers that a function or method receives as parameters. <li>Pointer checking (\c
50
ERS_CHECK_PTR) this type of checks is used to verify general pointers internally. <li>General
51
assertion (\c ERS_ASSERT) this macro can be used for checks that do not fit into any other
52
category.
53
</ul></li>
54
<li>Macros are compiled out if macro \c N_DEBUG is defined</li>
55
<li>Throws complete ERS issues, they can be caught streamed, modified etc.</li>
56
<li>Preconditions and general assertions support variable number of parameters and \c fprintf
57
like formatting</li> <li>Runtime assertion can detect if they are invariant conditions</li>
58
</ul>
59
All macros throw Issues object as exceptions with a severity_t of \c ers::error.
60
The main difference between the different macros is that the Issue object they generate in
61
case of violated condition contains different information fields. For instance all
62
precondition macros generate issue that specify that the responsiblity for the Issue lies in
63
the caller, not the callee. \see ers::Assertion \see ers::Precondition \see
64
ers::InvalidReferenceIssue
65
66
\subsection LoggingMacros Logging Macros
67
The ERS package offers a set of macros to do logging. Those macros construct an issue and
68
send them to the relevant stream. They all support multiple number of parameters with \c
69
fprintf like patterns. For each debug and warning severity_t level there is an associated
70
macro: \li ERS_DEBUG_0 \li ERS_DEBUG_1 \li ERS_DEBUG_2 \li ERS_DEBUG_3 \li ERS_WARN
71
72
The actual behaviour of the macro can be set up either at compile or runtime.
73
Debug macros with levels larger than 0 can be disabled at compile time simply by defining the
74
DEBUG_LEVEL. For instance, if DEBUG_LEVEL is 1, then ERS_DEBUG_2 and ERS_DEBUG_3 are compiled
75
out. At runtime the stream associated with a given severity can be disabled by associated a
76
null stream with the severity. A filtering stream can also be associated with the severity
77
level. The different types of streams supported by the package and the debug and warning
78
macros are presented in the documentation for class ers::StreamFactory \see
79
ers::StreamFactory
80
81
\section Issues Building Custom Issues
82
For a discussion about building custom issue, see the documentation for the Issue class.
83
An example custom issue is also given in the example directory.
84
\see ers::Issue
85
\see ExampleIssue
86
\see ExampleIssue.h
87
88
\section Selecting Streams
89
The ERS system use the abstraction of streams to handle issues.
90
Conceptualy, a stream is simply an object that can the user can use to send (or receive)
91
Issues. There is one stream associated with each severity level, those streams can be set or
92
retrieved using methods of the ers::StreamFactory class. \see ers::StreamFactory
93
94
\section Exit values
95
The ERS system offers some facilities to give out standard compliant exit values for
96
programs. That is, if a program exists because of an ers Issue, it can call the \c exit_value
97
method on the issue to possibly get an appropriate exit value (as defined in sysexits.h). A
98
typical main program would look like this: \code int main(int argc, char** argv) { try {
99
do_stuff();
100
} catch (ers::Issue &e) {
101
ers::StreamFactory::dispatch(e); // we send the issue to the appropriate stream
102
exit(e.exit_value()); // we get the actual exit value from the issue
103
} // try / catch
104
} // main
105
\endcode
106
\see http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
107
108
\section FAQ FAQ
109
\subsection Assertion-Precondition What is the difference between an assertion and a
110
precondition? An precondition is a condition that needs to be respected when \e entering a
111
function, an assertion is a condition that needs to be respected \e inside a function. A
112
failed precondition indicates that the problem lies outside of the function, a failed
113
assertion indicates that the problem lies inside the function. \see ers::Assertion
114
115
\subsection ERS_HERE What is the macro ERS_HERE?
116
The macro ERS_HERE is used to insert all the context information to a ers issue.
117
When constructing an issue one should always give the macro ERS_HERE as a first parameter.
118
\see ers::Context
119
120
\subsection factory Do I need to implement the registration and factory methods for each of
121
my Issues? The registration and factory mechanism as implemented in the ExampleIssue class is
122
needed for some functionality of ERS. If it is not present, the system will work but certain
123
features will be disabled. In particular the absence of factory method means that ERS cannot
124
dynamically build instance with the precise C++ type. For instance if you instanciate an
125
CustomIssue that does not declare a factory method, if you serialise this issue to a file and
126
then deserialise it, it will not have the type CustomIssue, but instead will have the type
127
DefaultIssue. The same happens if an Issue is caused by another issue, the cause issue is
128
cloned into the second issue, so if there is no factory method, the clone issue will have the
129
generic type.
130
131
*/
8.0.0
BOSS_Source
Event
ers
include
ers
ers.h
Generated by
1.16.1