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