BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
HumanStream.cxx
Go to the documentation of this file.
1/*
2 * HumanStream.cxx
3 * ers
4 *
5 * Created by Matthias Wiesmann on 01.12.04.
6 * Copyright 2004 CERN. All rights reserved.
7 *
8 */
9
10#include <assert.h>
11#include "ers/ers.h"
12#include "ers/HumanStream.h"
13
14
15const char* const ers::HumanStream::KEY = "human" ;
16
17namespace {
18 ers::Stream *create_stream(const std::string &protocol, const std::string &uri) {
19 (void) uri ;
20 if (protocol==ers::HumanStream::KEY) {
21 return new ers::HumanStream() ;
22 }
23 return 0 ;
24 } //
25 bool registered = ers::StreamFactory::instance()->register_factory(ers::HumanStream::KEY,create_stream) ;
26} // anonymous namespace
27
28
29/** Dumps the content of an issue into a string
30 * This class is used internally by the Issue class to produce then description field.
31 * \param issue_ptr the Issue to serialise
32 * \return string description
33 */
34
35std::string ers::HumanStream::to_string(const Issue *issue_ptr) throw() {
36 try {
37 HumanStream ers_stream ;
38 ers_stream.send(issue_ptr) ;
39 std::string str = ers_stream.to_string();
40 return str ;
41 } catch (std::exception &ex) {
42 std::string msg = "error while building message " + std::string(ex.what()) ;
43 return msg;
44 } //
45} // to_string
46
50
51/** \return the content of the stream as a string
52 */
53
55 return m_out_stream.str();
56} // to_string
57
58/** Clears the content of the stream
59 */
60
62 m_out_stream.str("");
63} // clear
64
65void ers::HumanStream::print_to(std::ostream& stream) const {
66 stream << ers::HumanStream::KEY << ':' ;
67} // print_to
68
69void ers::HumanStream::send(const Issue *issue_ptr) {
70 ERS_PRE_CHECK_PTR(issue_ptr);
71 if (m_out_stream) {
72 try {
73 const string_map_type *table = issue_ptr->get_value_table();
74 const std::string message_str = issue_ptr->get_value(Issue::MESSAGE_KEY) ;
75 const std::string severity_str = issue_ptr->get_value(Issue::SEVERITY_KEY) ;
76 m_out_stream << "issue: " << message_str << "(" << severity_str << ")[" ;
77 bool first = true ;
78 for(string_map_type::const_iterator pos = table->begin();pos!=table->end();++pos) {
79 const std::string &key = pos->first ;
80 const std::string &value = pos->second ;
81 if (first) {
82 first = false ;
83 } else {
84 m_out_stream << ", " ;
85 } // first or not
86 m_out_stream << key << "=\"" << value << '\"';
87 } // for
88 m_out_stream << "]" ;
89 } catch (std::ios_base::failure &ex) {
90 throw ers::Issue(ERS_HERE,ers::error,&ex);
91 } // catch generic I/O errors
92 } // if m_out_stream
93} // send
94
95
96
97
#define ERS_HERE
Definition Context.h:119
#define ERS_PRE_CHECK_PTR(p)
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
Definition Taupair.h:42
Single line, human readable format stream.
Definition HumanStream.h:27
virtual void send(const Issue *ptr)
Sends an issue into the stream.
std::string to_string()
static const char *const KEY
Definition HumanStream.h:32
virtual void print_to(std::ostream &stream) const
static std::string to_string(const Issue *issue)
Root Issue class.
const std::string & get_value(const std::string &key, const std::string &def) const
Reads the property list.
static const char *const MESSAGE_KEY
key for human readable
static const char *const SEVERITY_KEY
key for the severity_t of the issue
const string_map_type * get_value_table() const
extract value table
bool register_factory(const std::string &name, create_stream_callback callback)
register a factory method
static StreamFactory * instance()
return the singleton
Root/Null issue stream.
Definition Stream.h:35
ers header and documentation file
@ error
Definition Core.h:24
std::map< std::string, std::string > string_map_type
Definition Core.h:26