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 Issueclone () 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 Issuecause () const
 return the cause Issue of this Issue
const Contextcontext () 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_mapparameters () 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

Issueoperator= (const Issue &other)=delete

Private Attributes

std::unique_ptr< const Issuem_cause
 Issue that caused the current issue.
std::unique_ptr< Contextm_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 79 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.

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}
const Context & context() const
Context of the issue.
Definition Issue.hpp:111
Severity m_severity
Issue's severity.
Definition Issue.hpp:188
std::unique_ptr< Context > m_context
Context of the current issue.
Definition Issue.hpp:185
system_clock::time_point m_time
Time when issue was thrown.
Definition Issue.hpp:189
const std::string & message() const
General cause of the issue.
Definition Issue.hpp:114
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
@ Error
Definition Severity.hpp:37

◆ 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 95 of file Issue.cpp.

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}
#define ERS_HERE
virtual Issue * clone() const =0
std::unique_ptr< const Issue > m_cause
Issue that caused the current issue.
Definition Issue.hpp:184
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

◆ 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 112 of file Issue.cpp.

115 : m_context( context.clone() ),
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}

◆ Issue() [4/5]

Issue::Issue ( const Issue & other)

Definition at line 64 of file Issue.cpp.

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{ ; }
string_map m_values
List of user defined attributes.
Definition Issue.hpp:190
std::vector< std::string > m_qualifiers
List of associated qualifiers.
Definition Issue.hpp:187

◆ ~Issue()

ers::Issue::~Issue ( )
virtualnoexcept

Definition at line 142 of file Issue.cpp.

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 126 of file Issue.cpp.

133 : m_cause( cause ),
134 m_context( context.clone() ),
138 m_time( time ),
140{ ; }
ers::Severity severity() const
severity of the issue
Definition Issue.hpp:123
const std::vector< std::string > & qualifiers() const
return array of qualifiers
Definition Issue.hpp:117
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

Member Function Documentation

◆ _get_inheritance()

auto ers::Issue::_get_inheritance ( )
inlinestaticprotected

Definition at line 175 of file Issue.hpp.

175 {
176 inheritance_type chain;
177 chain.push_back( "ers::Issue" ) ;
178 return chain;
179 }
std::list< std::string > inheritance_type
Definition Issue.hpp:55

◆ 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 183 of file Issue.cpp.

184{
185 if ( std::find( m_qualifiers.begin(), m_qualifiers.end(), qualifier ) == m_qualifiers.end() ) {
186 m_qualifiers.push_back( qualifier );
187 }
188}

◆ cause()

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

return the cause Issue of this Issue

<

Definition at line 108 of file Issue.hpp.

109 { 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 111 of file Issue.hpp.

112 { 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 {
157 value = it->second.c_str();
158 }
159 else
160 {
161 throw ers::NoValue( ERS_HERE, key );
162 }
163}

◆ 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 166 of file Issue.cpp.

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}

◆ 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 136 of file Issue.hpp.

136 :%M:%S") const
137 { return time<Precision>(format, true); }

◆ 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 131 of file Issue.hpp.

◆ message()

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

General cause of the issue.

<

Definition at line 114 of file Issue.hpp.

115 { 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 120 of file Issue.hpp.

121 { 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 202 of file Issue.cpp.

203{
204 m_message = msg + m_message;
205}

◆ ptime()

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

original time point of the issue

<

Definition at line 141 of file Issue.hpp.

142 { return m_time; }

◆ qualifiers()

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

return array of qualifiers

<

Definition at line 117 of file Issue.hpp.

118 { 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 170 of file Issue.hpp.

171 { m_message = message; }

◆ set_severity()

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

Definition at line 191 of file Issue.cpp.

192{
193 ers::Severity old_severity = m_severity;
195 return old_severity;
196}

◆ 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 123 of file Issue.hpp.

124 { 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 229 of file Issue.hpp.

230{
231 static const int width(::log10(Precision::period::den));
232
233 std::time_t t = time_t();
234 std::tm tm = isUTC ? *gmtime_r(&t, &tm) : *localtime_r(&t, &tm);
235
236 char buff[128];
237 std::strftime(buff, 128 - 16, format.c_str(), &tm);
238
239 auto c = std::chrono::duration_cast<Precision>(
240 m_time.time_since_epoch()).count();
241 double frac = c - (double)t*Precision::period::den;
242 sprintf(buff + strlen(buff), ",%0*.0f", width, frac);
243
244 return buff;
245}
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 144 of file Issue.hpp.

145 { 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 212 of file Issue.cpp.

213{
214 m_message = begin + m_message + end;
215}

◆ IssueFactory

friend class IssueFactory
friend

Definition at line 81 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 184 of file Issue.hpp.

◆ m_context

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

Context of the current issue.

Definition at line 185 of file Issue.hpp.

◆ m_message

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

Issue's explanation text.

Definition at line 186 of file Issue.hpp.

◆ m_qualifiers

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

List of associated qualifiers.

Definition at line 187 of file Issue.hpp.

◆ m_severity

Severity ers::Issue::m_severity
mutableprivate

Issue's severity.

Definition at line 188 of file Issue.hpp.

◆ m_time

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

Time when issue was thrown.

Definition at line 189 of file Issue.hpp.

◆ m_values

string_map ers::Issue::m_values
private

List of user defined attributes.

Definition at line 190 of file Issue.hpp.


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