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