DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ers::Issue Class Referenceabstract

Base class for any user define issue. More...

#include <Issue.hpp>

Inheritance diagram for ers::Issue:
[legend]
Collaboration diagram for ers::Issue:
[legend]

Public Member Functions

 Issue (const Context &context, const std::string &message=std::string())
 Issue (const Context &context, const std::exception &cause)
 Issue (const Context &context, const std::string &message, const std::exception &cause)
 Issue (const Issue &other)
virtual ~Issue () noexcept
virtual Issue * clone () const =0
virtual const char * get_class_name () const =0
 Get key for class (used for serialisation).
virtual inheritance_type get_class_inheritance () const =0
 Get inheritance chain.
virtual void raise () const =0
 throws a copy of this issue preserving the real issue type
void add_qualifier (const std::string &qualif)
 adds a qualifier to the issue
const Issue * cause () const
 return the cause Issue of this Issue
const Context & context () const
 Context of the issue.
const std::string & message () const
 General cause of the issue.
const std::vector< std::string > & qualifiers () const
 return array of qualifiers
const string_map & parameters () const
 return array of parameters
ers::Severity severity () const
 severity of the issue
template<class Precision = std::chrono::seconds>
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
template<class Precision>
std::string localtime (const std::string &format="%Y-%b-%d %H:%M:%S") const
 string representation of UTC time of the issue
template<class Precision>
std::string gmtime (const std::string &format="%Y-%b-%d %H:%M:%S") const
std::time_t time_t () const
 seconds since 1 Jan 1970
const system_clock::time_point & ptime () const
 original time point of the issue
const char * what () const noexcept
 General cause of the issue.
ers::Severity set_severity (ers::Severity severityseverity) const
void wrap_message (const std::string &begin, const std::string &end)

Protected Member Functions

 Issue (Severity severityseverity, const system_clock::time_point &time, const ers::Context &context, const std::string &message, const std::vector< std::string > &qualifiers, const std::map< std::string, std::string > &parameters, const ers::Issue *cause=0)
 Gets a value of any type that has an input operator for the standard stream defined.
template<typename T>
void get_value (const std::string &key, T &value) const
void get_value (const std::string &key, const char *&value) const
void get_value (const std::string &key, std::string &value) const
 Sets a value of any type that has an output operator for the standard stream defined.
template<typename T>
void set_value (const std::string &key, T value)
void set_message (const std::string &message)
void prepend_message (const std::string &message)

Static Protected Member Functions

static auto _get_inheritance ()

Private Member Functions

Issue & operator= (const Issue &other)=delete

Private Attributes

std::unique_ptr< const Issue > m_cause
 Issue that caused the current issue.
std::unique_ptr< Context > m_context
 Context of the current issue.
std::string m_message
 Issue's explanation text.
std::vector< std::string > m_qualifiers
 List of associated qualifiers.
Severity m_severity
 Issue's severity.
system_clock::time_point m_time
 Time when issue was thrown.
string_map m_values
 List of user defined attributes.

Friends

class IssueFactory

Detailed Description

Base class for any user define issue.

This is a base class for any user define issue. The class stores all attributes declared in a user define descendant class in a hashmap as sting key/value pairs. The object defines a number of methods for providing access to this map. For an example of how to define a custom subclass of the Issue have a look at the SampleIssues.h file.

See also
ers::IssueFactory
SampleIssues.h

Definition at line 75 of file Issue.hpp.

Constructor & Destructor Documentation

◆ Issue() [1/5]

Issue::Issue ( const Context & context,
const std::string & message = std::string() )

This constructor create a new issue with the given message.

Parameters
contextthe context of the Issue, e.g where in the code the issue appeared
messagethe user message associated with this issue

Definition at line 80 of file Issue.cpp.

84 , m_time(system_clock::now())
85{
86 add_qualifier(m_context->package_name());
87 add_default_qualifiers(*this);
88}
virtual Context * clone() const =0
const Context & context() const
Context of the issue.
Definition Issue.hpp:102
Severity m_severity
Issue's severity.
Definition Issue.hpp:176
std::unique_ptr< Context > m_context
Context of the current issue.
Definition Issue.hpp:173
system_clock::time_point m_time
Time when issue was thrown.
Definition Issue.hpp:177
const std::string & message() const
General cause of the issue.
Definition Issue.hpp:104
std::string m_message
Issue's explanation text.
Definition Issue.hpp:174
void add_qualifier(const std::string &qualif)
adds a qualifier to the issue
Definition Issue.cpp:177
@ Error
Definition Severity.hpp:42

◆ Issue() [2/5]

Issue::Issue ( const Context & context,
const std::exception & cause )

This constructor takes another exceptions as its cause.

Parameters
contextthe context of the Issue, e.g where in the code the issue appeared
causethe other exception that has caused this one

Definition at line 94 of file Issue.cpp.

97 , m_time(system_clock::now())
98{
99 const Issue* issue = dynamic_cast<const Issue*>(&cause);
100 m_cause.reset(issue ? issue->clone() : new StdIssue(ERS_HERE, cause.what()));
101 add_qualifier(m_context->package_name());
102 add_default_qualifiers(*this);
103}
#define ERS_HERE
virtual Issue * clone() const =0
std::unique_ptr< const Issue > m_cause
Issue that caused the current issue.
Definition Issue.hpp:172
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:100

◆ Issue() [3/5]

Issue::Issue ( const Context & context,
const std::string & message,
const std::exception & cause )

This constructor takes another exceptions as its cause.

Parameters
contextthe context of the Issue, e.g where in the code did the issue appear
messagethe user message associated with this issue
causeexception that caused the current issue

Definition at line 110 of file Issue.cpp.

114 , m_time(system_clock::now())
115{
116 const Issue* issue = dynamic_cast<const Issue*>(&cause);
117 m_cause.reset(issue ? issue->clone() : new StdIssue(ERS_HERE, cause.what()));
118 add_qualifier(m_context->package_name());
119 add_default_qualifiers(*this);
120}

◆ Issue() [4/5]

Issue::Issue ( const Issue & other)

Definition at line 63 of file Issue.cpp.

64 : std::exception(other)
65 , m_cause(other.m_cause.get() ? other.m_cause->clone() : 0)
66 , m_context(other.m_context->clone())
67 , m_message(other.m_message)
69 , m_severity(other.m_severity)
70 , m_time(other.m_time)
71 , m_values(other.m_values)
72{
73 ;
74}
string_map m_values
List of user defined attributes.
Definition Issue.hpp:178
std::vector< std::string > m_qualifiers
List of associated qualifiers.
Definition Issue.hpp:175

◆ ~Issue()

ers::Issue::~Issue ( )
virtualnoexcept

Definition at line 140 of file Issue.cpp.

141{
142 ;
143}

◆ Issue() [5/5]

Issue::Issue ( Severity severity,
const system_clock::time_point & time,
const ers::Context & context,
const std::string & message,
const std::vector< std::string > & qualifiers,
const std::map< std::string, std::string > & parameters,
const ers::Issue * cause = 0 )
protected

Gets a value of any type that has an input operator for the standard stream defined.

Definition at line 122 of file Issue.cpp.

129 : m_cause(cause)
134 , m_time(time)
136{
137 ;
138}
ers::Severity severity() const
severity of the issue
Definition Issue.hpp:110
const std::vector< std::string > & qualifiers() const
return array of qualifiers
Definition Issue.hpp:106
const string_map & parameters() const
return array of parameters
Definition Issue.hpp:108
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:213

Member Function Documentation

◆ _get_inheritance()

auto ers::Issue::_get_inheritance ( )
inlinestaticprotected

Definition at line 162 of file Issue.hpp.

163 {
164 inheritance_type chain;
165 chain.push_back("ers::Issue");
166 return chain;
167 }
std::list< std::string > inheritance_type
Definition Issue.hpp:54

◆ add_qualifier()

void Issue::add_qualifier ( const std::string & qualifier)

adds a qualifier to the issue

Add a new qualifier to the qualifiers list of this issue

Parameters
qualifierthe qualifier to add

Definition at line 177 of file Issue.cpp.

178{
179 if (std::find(m_qualifiers.begin(), m_qualifiers.end(), qualifier) == m_qualifiers.end()) {
180 m_qualifiers.push_back(qualifier);
181 }
182}

◆ cause()

const Issue * ers::Issue::cause ( ) const
inline

return the cause Issue of this Issue

<

Definition at line 100 of file Issue.hpp.

100{ return m_cause.get(); }

◆ clone()

virtual Issue * ers::Issue::clone ( ) const
pure virtual

◆ context()

const Context & ers::Issue::context ( ) const
inline

Context of the issue.

<

Definition at line 102 of file Issue.hpp.

102{ return *(m_context.get()); }

◆ get_class_inheritance()

virtual inheritance_type ers::Issue::get_class_inheritance ( ) const
pure virtual

Get inheritance chain.

Implemented in ers::AnyIssue.

◆ get_class_name()

virtual const char * ers::Issue::get_class_name ( ) const
pure virtual

Get key for class (used for serialisation).

Implemented in dunedaq::logging::Logging::InternalMessage, and ers::AnyIssue.

◆ get_value() [1/3]

void ers::Issue::get_value ( const std::string & key,
const char *& value ) const
protected

Definition at line 152 of file Issue.cpp.

153{
154 string_map::const_iterator it = m_values.find(key);
155 if (it != m_values.end()) {
156 value = it->second.c_str();
157 } else {
158 throw ers::NoValue(ERS_HERE, key);
159 }
160}

◆ get_value() [2/3]

void ers::Issue::get_value ( const std::string & key,
std::string & value ) const
protected

Sets a value of any type that has an output operator for the standard stream defined.

Definition at line 163 of file Issue.cpp.

164{
165 string_map::const_iterator it = m_values.find(key);
166 if (it != m_values.end()) {
167 value = it->second;
168 } else {
169 throw ers::NoValue(ERS_HERE, key);
170 }
171}

◆ get_value() [3/3]

template<typename T>
void ers::Issue::get_value ( const std::string & key,
T & value ) const
protected

◆ gmtime()

template<class Precision>
std::string ers::Issue::gmtime ( const std::string & format = "%Y-%b-%d %H:%M:%S") const
inline

Definition at line 124 of file Issue.hpp.

124 :%M:%S") const
125 {
126 return time<Precision>(format, true);
127 }

◆ localtime()

template<class Precision>
std::string ers::Issue::localtime ( const std::string & format = "%Y-%b-%d %H:%M:%S") const
inline

string representation of UTC time of the issue

Definition at line 117 of file Issue.hpp.

◆ message()

const std::string & ers::Issue::message ( ) const
inline

General cause of the issue.

<

Definition at line 104 of file Issue.hpp.

104{ return m_message; }

◆ operator=()

Issue & ers::Issue::operator= ( const Issue & other)
privatedelete

◆ parameters()

const string_map & ers::Issue::parameters ( ) const
inline

return array of parameters

<

Definition at line 108 of file Issue.hpp.

108{ return m_values; }

◆ prepend_message()

void Issue::prepend_message ( const std::string & msg)
protected

Adds the given text to the beginning of the issue's message

Parameters
msgtext to be prepended

Definition at line 196 of file Issue.cpp.

197{
198 m_message = msg + m_message;
199}

◆ ptime()

const system_clock::time_point & ers::Issue::ptime ( ) const
inline

original time point of the issue

<

Definition at line 131 of file Issue.hpp.

131{ return m_time; }

◆ qualifiers()

const std::vector< std::string > & ers::Issue::qualifiers ( ) const
inline

return array of qualifiers

<

Definition at line 106 of file Issue.hpp.

106{ return m_qualifiers; }

◆ raise()

virtual void ers::Issue::raise ( ) const
pure virtual

throws a copy of this issue preserving the real issue type

Implemented in dunedaq::logging::Logging::InternalMessage, and ers::AnyIssue.

◆ set_message()

void ers::Issue::set_message ( const std::string & message)
inlineprotected

Definition at line 158 of file Issue.hpp.

158{ m_message = message; }

◆ set_severity()

ers::Severity Issue::set_severity ( ers::Severity severity) const

Definition at line 185 of file Issue.cpp.

186{
187 ers::Severity old_severity = m_severity;
189 return old_severity;
190}

◆ set_value()

template<typename T>
void ers::Issue::set_value ( const std::string & key,
T value )
protected

◆ severity()

ers::Severity ers::Issue::severity ( ) const
inline

severity of the issue

<

Definition at line 110 of file Issue.hpp.

110{ return m_severity; }

◆ time()

template<class Precision>
std::string ers::Issue::time ( const std::string & format = "%Y-%b-%d %H:%M:%S",
bool isUTC = false ) const

string representation of local time of the issue

Definition at line 213 of file Issue.hpp.

214{
215 static const int width(::log10(Precision::period::den));
216
217 std::time_t t = time_t();
218 std::tm tm = isUTC ? *gmtime_r(&t, &tm) : *localtime_r(&t, &tm);
219
220 char buff[128];
221 std::strftime(buff, 128 - 16, format.c_str(), &tm);
222
223 auto c = std::chrono::duration_cast<Precision>(m_time.time_since_epoch()).count();
224 double frac = c - (double)t * Precision::period::den;
225 sprintf(buff + strlen(buff), ",%0*.0f", width, frac);
226
227 return buff;
228}
std::time_t time_t() const
seconds since 1 Jan 1970
Definition Issue.cpp:146

◆ time_t()

std::time_t ers::Issue::time_t ( ) const

seconds since 1 Jan 1970

Definition at line 146 of file Issue.cpp.

147{
148 return system_clock::to_time_t(m_time);
149}

◆ what()

const char * ers::Issue::what ( ) const
inlinenoexcept

General cause of the issue.

<

Definition at line 133 of file Issue.hpp.

133{ return m_message.c_str(); }

◆ wrap_message()

void Issue::wrap_message ( const std::string & begin,
const std::string & end )

Adds the given text strings to the beginning and to the end of the issue's message

Parameters
begintext to be prepended
begintext to be appended

Definition at line 206 of file Issue.cpp.

207{
208 m_message = begin + m_message + end;
209}

◆ IssueFactory

friend class IssueFactory
friend

Definition at line 77 of file Issue.hpp.

Member Data Documentation

◆ m_cause

std::unique_ptr<const Issue> ers::Issue::m_cause
private

Issue that caused the current issue.

Definition at line 172 of file Issue.hpp.

◆ m_context

std::unique_ptr<Context> ers::Issue::m_context
private

Context of the current issue.

Definition at line 173 of file Issue.hpp.

◆ m_message

std::string ers::Issue::m_message
private

Issue's explanation text.

Definition at line 174 of file Issue.hpp.

◆ m_qualifiers

std::vector<std::string> ers::Issue::m_qualifiers
private

List of associated qualifiers.

Definition at line 175 of file Issue.hpp.

◆ m_severity

Severity ers::Issue::m_severity
mutableprivate

Issue's severity.

Definition at line 176 of file Issue.hpp.

◆ m_time

system_clock::time_point ers::Issue::m_time
private

Time when issue was thrown.

Definition at line 177 of file Issue.hpp.

◆ m_values

string_map ers::Issue::m_values
private

List of user defined attributes.

Definition at line 178 of file Issue.hpp.


The documentation for this class was generated from the following files: