DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FormattedStandardStream.hxx
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 ers/internal/FormattedStandardStream.inc to include/ers/internal/FormattedStandardStream.hxx).
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 * FormattedStandardStream.i
14 * ers
15 *
16 * Created by Serguei Kolos on 02.08.07.
17 * Copyright 2007 CERN. All rights reserved.
18 *
19 */
20
21#include <iomanip>
22#include <iostream>
23#include <fstream>
24
25#define FIELD_SEPARATOR "\n\t"
26#define DELIMITER ','
27
28template <class Device>
30
31template <class Device>
33{
34 (*this)["severity"] = format::Severity;
35 (*this)["time"] = format::Time;
36 (*this)["position"] = format::Position;
37 (*this)["context"] = format::Context;
38 (*this)["pid"] = format::PID;
39 (*this)["tid"] = format::TID;
40 (*this)["user"] = format::User;
41 (*this)["cwd"] = format::CWD;
42 (*this)["function"] = format::Function;
43 (*this)["line"] = format::Line;
44 (*this)["text"] = format::Text;
45 (*this)["stack"] = format::Stack;
46 (*this)["cause"] = format::Cause;
47 (*this)["parameters"] = format::Parameters;
48 (*this)["qualifiers"] = format::Qualifiers;
49}
50
51template <class Device>
52std::string
54{
55 std::string first_token = param.substr( 0, param.find( ',' ) );
56 std::map<std::string,ers::format::Token>::iterator it = s_supported_fields.find( first_token );
57 if ( it != s_supported_fields.end() )
58 return "";
59 else
60 return first_token;
61}
62
63template <class Device>
64std::string
66{
67 std::string first_token = param.substr( 0, param.find( ',' ) );
68 std::map<std::string,ers::format::Token>::iterator it = s_supported_fields.find( first_token );
69 if ( it != s_supported_fields.end() )
70 return param;
71 else
72 return param.substr( first_token.size() < param.size() ? first_token.size() + 1 : param.size() );
73}
74
75template <class Device>
77 : Device( get_file_name( param ) )
78{
79 std::string format = get_format( param );
80
81 size_t offset = 0;
82 size_t index = std::string::npos;
83 do {
84 index = format.find( DELIMITER, offset );
85 std::string token = format.substr( offset, index - offset );
86 std::map<std::string,ers::format::Token>::iterator it = s_supported_fields.find( token );
87 if ( it != s_supported_fields.end() )
88 m_tokens.push_back( it->second );
89
90 offset += token.size() + 1;
91 } while ( index != std::string::npos );
92}
93
94template <class Device>
95void
96ers::FormattedStandardStream<Device>::report( std::ostream & out, const Issue & issue )
97{
98 for ( size_t i = 0; i < m_tokens.size(); i++ )
99 {
100 switch ( m_tokens[i] )
101 {
102 case format::Severity:
103 out << ers::to_string( issue.severity() );
104 break;
105 case format::Time:
106 out << issue.time<std::chrono::microseconds>() << " ";
107 break;
108 case format::Position:
109 out << "[" << issue.context().position( ) << "]";
110 break;
111 case format::Function:
112 out << issue.context().function_name();
113 break;
114 case format::Line:
115 out << issue.context().line_number();
116 break;
117 case format::Text:
118 out << issue.message();
119 break;
121 {
122 out << FIELD_SEPARATOR << "Parameters = ";
123 for ( ers::string_map::const_iterator it = issue.parameters().begin(); it != issue.parameters().end(); ++it )
124 {
125 out << "'" << it->first << "=" << it->second << "' ";
126 }
127 }
128 break;
130 {
131 out << FIELD_SEPARATOR << "Qualifiers = ";
132 for ( std::vector<std::string>::const_iterator it = issue.qualifiers().begin(); it != issue.qualifiers().end(); ++it )
133 {
134 out << "'" << *it << "' ";
135 }
136 }
137 break;
138 case format::Context:
139 out << FIELD_SEPARATOR << "host = " << issue.context().host_name()
140 << FIELD_SEPARATOR << "user = " << issue.context().user_name()
141 << " (" << issue.context().user_id() << ")"
142 << FIELD_SEPARATOR << "process id = " << issue.context().process_id()
143 << FIELD_SEPARATOR << "thread id = " << issue.context().thread_id()
144 << FIELD_SEPARATOR << "process wd = " << issue.context().cwd();
145 break;
146 case format::Host:
147 out << FIELD_SEPARATOR << "host = " << issue.context().host_name();
148 break;
149 case format::User:
150 out << FIELD_SEPARATOR << "user = " << issue.context().user_name()
151 << " (" << issue.context().user_id() << ")";
152 break;
153 case format::PID:
154 out << FIELD_SEPARATOR << "process id = " << issue.context().process_id();
155 break;
156 case format::TID:
157 out << FIELD_SEPARATOR << "thread id = " << issue.context().thread_id();
158 break;
159 case format::CWD:
160 out << FIELD_SEPARATOR << "process wd = " << issue.context().cwd();
161 break;
162 case format::Stack:
163 {
164 std::vector<std::string> stack = issue.context().stack();
165 for( size_t i = 0; i < stack.size(); i++ )
166 {
167 out << FIELD_SEPARATOR << "#" << std::setw(3) << std::left << i << stack[i];
168 }
169 }
170 break;
171 case format::Cause:
172 if ( issue.cause() )
173 {
174 out << FIELD_SEPARATOR << "was caused by: ";
175 report( out, *issue.cause() );
176 }
177 break;
178 default:
179 break;
180 }
181 out << " ";
182 }
183 out << std::endl;
184}
185
186template <class Device>
187void
189{
190 report( device().stream(), issue );
191 chained().write( issue );
192}
#define DELIMITER
#define FIELD_SEPARATOR
virtual int line_number() const =0
virtual const char * user_name() const =0
virtual int user_id() const =0
virtual pid_t thread_id() const =0
virtual const char * host_name() const =0
std::string position(int verbosity=ers::Configuration::instance().verbosity_level()) const
Definition Context.cpp:116
virtual pid_t process_id() const =0
virtual const char * cwd() const =0
std::vector< std::string > stack() const
Definition Context.cpp:95
virtual const char * function_name() const =0
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
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
const Issue * cause() const
return the cause Issue of this Issue
Definition Issue.hpp:108
OutputStream & chained()
double offset
std::string to_string(severity s)
void report(std::ostream &out, const Issue &issue)
std::vector< format::Token > m_tokens
static std::string get_file_name(const std::string &param)
static std::string get_format(const std::string &param)
void write(const Issue &issue) override