DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Issue.cpp
Go to the documentation of this file.
1/*
2 * DUNE DAQ modification notice:
3 * This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
4 * Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
5 * Renamed since fork: yes (from src/Issue.cxx to src/Issue.cpp).
6 *
7 * Original copyright:
8 * Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
9 * Licensed under the Apache License, Version 2.0.
10 */
11
12/*
13 * Issue.cxx
14 * ers
15 *
16 * Created by Matthias Wiesmann on 26.11.04.
17 * Modified by Serguei Kolos on 02.08.05.
18 * Copyright 2004 CERN. All rights reserved.
19 *
20 */
21
22#include <csignal>
23#include <iomanip>
24#include <sstream>
25#include <algorithm>
26#include <ctime>
27#include <time.h>
28
29#include <ers/Issue.hpp>
30#include <ers/IssueFactory.hpp>
31#include <ers/OutputStream.hpp>
33#include <ers/ers.hpp>
34#include <ers/internal/Util.hpp>
35
36using namespace ers;
37
39
40namespace
41{
42 int get_default_qualifiers( std::vector<std::string> & qualifiers )
43 {
44 static const char * environment = ::getenv( "DUNEDAQ_ERS_QUALIFIERS" );
45 if ( environment )
46 {
47 ers::tokenize( environment, ",", qualifiers );
48 }
49 return 1;
50 }
51
52 void add_default_qualifiers( Issue & issue )
53 {
54 static std::vector<std::string> qualifiers;
55 // static int _unused_ = get_default_qualifiers( qualifiers );
56 get_default_qualifiers( qualifiers );
57 for ( std::vector<std::string>::const_iterator it = qualifiers.begin(); it != qualifiers.end(); ++it )
58 {
59 issue.add_qualifier( *it );
60 }
61 }
62}
63
64Issue::Issue( const Issue & other )
65 : std::exception( other ),
66 m_cause( other.m_cause.get() ? other.m_cause->clone() : 0 ),
67 m_context( other.m_context->clone() ),
68 m_message( other.m_message ),
70 m_severity( other.m_severity ),
71 m_time( other.m_time ),
72 m_values( other.m_values )
73{ ; }
74
75
81 const std::string & message )
82 : m_context( context.clone() ),
85 m_time( system_clock::now() )
86{
87 add_qualifier( m_context->package_name() );
88 add_default_qualifiers( *this );
89}
90
96 const std::exception & cause )
97 : m_context( context.clone() ),
99 m_time( system_clock::now() )
100{
101 const Issue * issue = dynamic_cast<const Issue *>( &cause );
102 m_cause.reset( issue ? issue->clone() : new StdIssue( ERS_HERE, cause.what() ) );
103 add_qualifier( m_context->package_name() );
104 add_default_qualifiers( *this );
105}
106
113 const std::string & message,
114 const std::exception & cause )
115 : m_context( context.clone() ),
117 m_severity( ers::Error ),
118 m_time( system_clock::now() )
119{
120 const Issue * issue = dynamic_cast<const Issue *>( &cause );
121 m_cause.reset( issue ? issue->clone() : new StdIssue( ERS_HERE, cause.what() ) );
122 add_qualifier( m_context->package_name() );
123 add_default_qualifiers( *this );
124}
125
127 const system_clock::time_point & time,
128 const ers::Context & context,
129 const std::string & message,
130 const std::vector<std::string> & qualifiers,
131 const std::map<std::string, std::string> & parameters,
132 const ers::Issue * cause )
133 : m_cause( cause ),
138 m_time( time ),
140{ ; }
141
143{ ; }
144
145std::time_t
147{
148 return system_clock::to_time_t(m_time);
149}
150
151void
152ers::Issue::get_value( const std::string & key, const char * & value ) const
153{
154 string_map::const_iterator it = m_values.find(key);
155 if ( it != m_values.end() )
156 {
157 value = it->second.c_str();
158 }
159 else
160 {
161 throw ers::NoValue( ERS_HERE, key );
162 }
163}
164
165void
166ers::Issue::get_value( const std::string & key, std::string & value ) const
167{
168 string_map::const_iterator it = m_values.find(key);
169 if ( it != m_values.end() )
170 {
171 value = it->second;
172 }
173 else
174 {
175 throw ers::NoValue( ERS_HERE, key );
176 }
177}
178
182void
183Issue::add_qualifier( const std::string & qualifier )
184{
185 if ( std::find( m_qualifiers.begin(), m_qualifiers.end(), qualifier ) == m_qualifiers.end() ) {
186 m_qualifiers.push_back( qualifier );
187 }
188}
189
192{
193 ers::Severity old_severity = m_severity;
195 return old_severity;
196}
197
201void
202Issue::prepend_message( const std::string & msg )
203{
204 m_message = msg + m_message;
205}
206
211void
212Issue::wrap_message( const std::string & begin, const std::string & end )
213{
214 m_message = begin + m_message + end;
215}
216
217namespace ers {
218
223 std::ostream & operator<<( std::ostream & out, const ers::Issue & issue )
224 {
226 }
227}
228
229
230
231
#define ERS_EMPTY
#define ERS_HERE
An abstract interface to access an Issue context.
Definition Context.hpp:41
Base class for any user define issue.
Definition Issue.hpp:80
const Context & context() const
Context of the issue.
Definition Issue.hpp:111
ers::Severity severity() const
severity of the issue
Definition Issue.hpp:123
Severity m_severity
Issue's severity.
Definition Issue.hpp:188
void wrap_message(const std::string &begin, const std::string &end)
Definition Issue.cpp:212
std::unique_ptr< Context > m_context
Context of the current issue.
Definition Issue.hpp:185
virtual ~Issue() noexcept
Definition Issue.cpp:142
void prepend_message(const std::string &message)
Definition Issue.cpp:202
system_clock::time_point m_time
Time when issue was thrown.
Definition Issue.hpp:189
void get_value(const std::string &key, T &value) const
const std::vector< std::string > & qualifiers() const
return array of qualifiers
Definition Issue.hpp:117
const std::string & message() const
General cause of the issue.
Definition Issue.hpp:114
const string_map & parameters() const
return array of parameters
Definition Issue.hpp:120
std::string time(const std::string &format="%Y-%b-%d %H:%M:%S", bool isUTC=false) const
string representation of local time of the issue
Definition Issue.hpp:229
virtual Issue * clone() const =0
std::unique_ptr< const Issue > m_cause
Issue that caused the current issue.
Definition Issue.hpp:184
string_map m_values
List of user defined attributes.
Definition Issue.hpp:190
std::string m_message
Issue's explanation text.
Definition Issue.hpp:186
void add_qualifier(const std::string &qualif)
adds a qualifier to the issue
Definition Issue.cpp:183
ers::Severity set_severity(ers::Severity severity) const
Definition Issue.cpp:191
std::time_t time_t() const
seconds since 1 Jan 1970
Definition Issue.cpp:146
std::vector< std::string > m_qualifiers
List of associated qualifiers.
Definition Issue.hpp:187
Issue(const Context &context, const std::string &message=std::string())
Definition Issue.cpp:80
const Issue * cause() const
return the cause Issue of this Issue
Definition Issue.hpp:108
caught dunedaq::conffwk::Exception exception
static int64_t now()
#define ERS_DECLARE_ISSUE( namespace_name, class_name, message_, attributes)
Definition macro.hpp:65
int verbosity_level()
Definition ers.hpp:119
void tokenize(const std::string &text, const std::string &separators, std::vector< std::string > &tokens)
Definition Util.cpp:18
std::ostream & operator<<(std::ostream &, const ers::Configuration &)
@ Error
Definition Severity.hpp:37
static std::ostream & print(std::ostream &out, const Issue &issue, int verbosity)