BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
ers::StreamFactory Class Reference

Factory for Stream objects and repository of default streams. More...

#include <StreamFactory.h>

Public Types

typedef Stream *(* create_stream_callback) (const std::string &, const std::string &)
typedef std::map< std::string, create_stream_callbackstream_factory_collection
typedef Stream *(* create_stream_callback) (const std::string &, const std::string &)
typedef std::map< std::string, create_stream_callbackstream_factory_collection
typedef Stream *(* create_stream_callback) (const std::string &, const std::string &)
typedef std::map< std::string, create_stream_callbackstream_factory_collection

Public Member Functions

 ~StreamFactory ()
Streamcreate_stream (const std::string &key) const
 create a stream from a key
Streamget_stream (severity_t s)
 get stream for severity_t
void set (severity_t severity, Stream *s)
 Sets the stream for a given severity_t.
void set (severity_t severity, const char *key)
 Setup a stream for a given severity_t based on a key.
Streamfatal ()
 Fatal stream.
Streamerror ()
 Error stream.
Streamwarning ()
 Warning stream.
Streamdebug (severity_t s)
 Debug stream for level.
bool register_factory (const std::string &name, create_stream_callback callback)
 register a factory method
void write_to (std::ostream &stream) const
 write content of factory to stream
 ~StreamFactory ()
Streamcreate_stream (const std::string &key) const
 create a stream from a key
Streamget_stream (severity_t s)
 get stream for severity_t
void set (severity_t severity, Stream *s)
 Sets the stream for a given severity_t.
void set (severity_t severity, const char *key)
 Setup a stream for a given severity_t based on a key.
Streamfatal ()
 Fatal stream.
Streamerror ()
 Error stream.
Streamwarning ()
 Warning stream.
Streamdebug (severity_t s)
 Debug stream for level.
bool register_factory (const std::string &name, create_stream_callback callback)
 register a factory method
void write_to (std::ostream &stream) const
 write content of factory to stream
 ~StreamFactory ()
Streamcreate_stream (const std::string &key) const
 create a stream from a key
Streamget_stream (severity_t s)
 get stream for severity_t
void set (severity_t severity, Stream *s)
 Sets the stream for a given severity_t.
void set (severity_t severity, const char *key)
 Setup a stream for a given severity_t based on a key.
Streamfatal ()
 Fatal stream.
Streamerror ()
 Error stream.
Streamwarning ()
 Warning stream.
Streamdebug (severity_t s)
 Debug stream for level.
bool register_factory (const std::string &name, create_stream_callback callback)
 register a factory method
void write_to (std::ostream &stream) const
 write content of factory to stream

Static Public Member Functions

static StreamFactoryinstance ()
 return the singleton
static void print_registered ()
static void fatal (Issue *i)
 sends an issue to the fatal stream
static void error (Issue *i)
 sends an issue to the error stream
static void warning (Issue *i)
 sends an issue to the warning stream
static void warning (const Context &c, const std::string &message)
 sends a warning message
static void debug (Issue *i, severity_t)
 sends an Issue to the debug stream
static void debug (const Context &c, const std::string &message, severity_t s)
 sends a debug message
static void dispatch (Issue *i, bool throw_error=false)
 Sends an issue to the appropriate stream according to its severity_t.
static void dispatch (Issue &i, bool throw_error=false)
static void set_stream (severity_t, const std::string &key)
static StreamFactoryinstance ()
 return the singleton
static void print_registered ()
static void fatal (Issue *i)
 sends an issue to the fatal stream
static void error (Issue *i)
 sends an issue to the error stream
static void warning (Issue *i)
 sends an issue to the warning stream
static void warning (const Context &c, const std::string &message)
 sends a warning message
static void debug (Issue *i, severity_t)
 sends an Issue to the debug stream
static void debug (const Context &c, const std::string &message, severity_t s)
 sends a debug message
static void dispatch (Issue *i, bool throw_error=false)
 Sends an issue to the appropriate stream according to its severity_t.
static void dispatch (Issue &i, bool throw_error=false)
static void set_stream (severity_t, const std::string &key)
static StreamFactoryinstance ()
 return the singleton
static void print_registered ()
static void fatal (Issue *i)
 sends an issue to the fatal stream
static void error (Issue *i)
 sends an issue to the error stream
static void warning (Issue *i)
 sends an issue to the warning stream
static void warning (const Context &c, const std::string &message)
 sends a warning message
static void debug (Issue *i, severity_t)
 sends an Issue to the debug stream
static void debug (const Context &c, const std::string &message, severity_t s)
 sends a debug message
static void dispatch (Issue *i, bool throw_error=false)
 Sends an issue to the appropriate stream according to its severity_t.
static void dispatch (Issue &i, bool throw_error=false)
static void set_stream (severity_t, const std::string &key)

Protected Member Functions

 StreamFactory ()
 StreamFactory (const StreamFactory &other)
Streamcreate_stream (severity_t s)
 create a stream for severity_t
 StreamFactory ()
 StreamFactory (const StreamFactory &other)
Streamcreate_stream (severity_t s)
 create a stream for severity_t
 StreamFactory ()
 StreamFactory (const StreamFactory &other)
Streamcreate_stream (severity_t s)
 create a stream for severity_t

Static Protected Member Functions

static const char * key_for_severity (severity_t s)
 finds key for severity_t
static Streamget_default_stream (severity_t s)
 builds default stream for severity_t
static const char * key_for_severity (severity_t s)
 finds key for severity_t
static Streamget_default_stream (severity_t s)
 builds default stream for severity_t
static const char * key_for_severity (severity_t s)
 finds key for severity_t
static Streamget_default_stream (severity_t s)
 builds default stream for severity_t

Protected Attributes

Streamm_streams [severity_max]
 array of pointers to streams per severity_t
stream_factory_collection m_factories
 collection of factories to build streams

Static Protected Attributes

static StreamFactorys_instance = 0
 singleton instance
static const char * DEFAULT_STREAMS []
 keys for default streams

Detailed Description

Factory for Stream objects and repository of default streams.

The StreamFactory class is responsible for creating and handling all the ers stream used by the system. It implements the singleton pattern and the factory pattern. There should normally only be one instance of this class per process at any time, each instance handles a table of the different stream attached to each severity. When issues occurs, they can be dispatched using this instance. In general, the following method should be used to dispatch issues

  • dispatch if the severity_t of the issue is set correctly.
  • fatal, error, warning, debug for setting the severity_t and dispatch.

The default stream are set up in the following way:

  1. The system checks if an environnement variable with the same name as severity_t is defined. If this is the case, the value of this variable is parsed as a key for building the stream. Key are basically URLs, either they start with the file protocol, or a keyword that identifies a different type of protocol followed by a colon. Certain protocols accepts more information after the colon, for instance for file streams, the rest of the URL is used to specify the file path, and deduce the file format from the file extension.
    Examples
    • file:/tmp/out.xml represents a stream that writes issues into file /tmp/out.xml in the XML format.
    • cerr:tab represents a stream that writes in tabulated format on the standard output.
  2. If the stream cannot be determined out of the environement variable, a default stream is built. The actual type of this default stream is determined by the content of the key in DEFAULT_STREAMS. The content is a key with the format described above.y
  3. The user can provide another stream for any severity_t simply by calling method set, either by specifying the stream directly, or by providing a key.

Different packages offer different stream implementations. To use a specific stream type, the relevant library needs to be linked in. If the key for a type of stream that is not available is used, the system will revert to the default stream.

Supported Keys - ERS package

The ERS package supports by default the following keys:

  • null: issues are discarded
  • default: issues are displayed on standard error stream
  • fifo: writes into a FIFO stream, to be actually used the issues need to be read by another entity
  • filter: filter stream, the Issues are filtered and if the filter accept them, passed on to another stream (specified by another key in the stream description).

Supported Keys - System package:

The System package supports the following keys:

  • file: writes into a file
  • cerr: writes into the standard error stream.
    The file: and cerr: protocol support the following data encodings:
    • xml - issues are serialized as XML data
    • tab - issues are serialized as tabulated data
    • txt - issues are serialized as single line of text
  • syslog: issues are sent to syslog

Supported Keys - ers-ipc package:

The ersipc package supports the following keys:

  • mrs: writes issues into the MRS system (q.v.) the rest of the uri in this case designates the IPC partition to use for instance mrs://data

In order to add new stream implementations, one needs to register a factory function of type create_stream_callback. This method takes two parameters, a protocol parameter, and an uri parameter, that basically contains everything except the protocol part of the key. If the implementation can offer a stream that corresponds to the key it should return a heap allocated stream, if not it should return a null pointer. This method should be registered using the register_factory method on the default instance.

Macros
This file also defines a set of macros that send messages to the relevant streams in the factory. Those macros are intendred for logging out debug messages. They can compiled out by the way of the DEBUG_LEVEL macro. This macro should be defined with an integer level. A debugging macro is disabled if its number is higher than the value of DEBUG_LEVEL. For instance if DEBUG_LEVEL=2 then ERS_DEBUG_3 is compiled out. ERS_DEBUG_0 is never compiled out. If no debug level is specified, level 3 (maximum) is assumed. If the macro ERS_FAST_DEBUG is defined then ERS_DEBUG_0 macro directly maps to a fprintf statement on stderr.

Author
Matthias Wiesmann
Version
1.2
See also
ers::Stream
ers::FIFOStream
ers::FilterStream
System::STLStream
System::MessageStream
System::SyslogStream
System::TabStream
System::XercesStream

Definition at line 139 of file Event/ers/include/ers/StreamFactory.h.

Member Typedef Documentation

◆ create_stream_callback [1/3]

typedef Stream *(* ers::StreamFactory::create_stream_callback) (const std::string &, const std::string &)

Definition at line 142 of file Event/ers/include/ers/StreamFactory.h.

◆ create_stream_callback [2/3]

typedef Stream *(* ers::StreamFactory::create_stream_callback) (const std::string &, const std::string &)

◆ create_stream_callback [3/3]

typedef Stream *(* ers::StreamFactory::create_stream_callback) (const std::string &, const std::string &)

◆ stream_factory_collection [1/3]

◆ stream_factory_collection [2/3]

◆ stream_factory_collection [3/3]

Constructor & Destructor Documentation

◆ StreamFactory() [1/6]

ers::StreamFactory::StreamFactory ( )
protected

Constructor - should never be called by user code, use the instance() method instead

See also
instance()

Definition at line 43 of file StreamFactory.cxx.

43 {
44 for ( int i = static_cast<int>( severity_none ); i < static_cast<int>( severity_max ); i++ )
45 {
46 severity_t s = static_cast<severity_t>( i );
47 m_streams[s] = 0;
48 } // for*/
49} // StreamFactory
XmlRpcServer s
Stream * m_streams[severity_max]
array of pointers to streams per severity_t
enum ers::_severity_t severity_t

Referenced by instance(), print_registered(), and StreamFactory().

◆ StreamFactory() [2/6]

ers::StreamFactory::StreamFactory ( const StreamFactory & other)
protected

Copy constructor - disabled, use the instance() method instead

See also
instance()
Exceptions
ers::NotImplementedin all cases

Definition at line 56 of file StreamFactory.cxx.

56 {
57 (void)other; // shut up the compiler
59} // StreamFactory
#define ERS_NOT_IMPLEMENTED()

◆ ~StreamFactory() [1/3]

ers::StreamFactory::~StreamFactory ( )

Destructor - basic cleanup

Note
in practice this method should never be called, the singleton should never be deallocated

Definition at line 66 of file StreamFactory.cxx.

66 {
67 for ( int i = static_cast<int>( severity_none ); i < static_cast<int>( severity_max ); i++ )
68 {
69 severity_t s = static_cast<severity_t>( i );
70 if ( m_streams[s] )
71 {
72 delete ( m_streams[s] );
73 m_streams[s] = 0;
74 } // if stream
75 } // for*/
76} // ~StreamFactory

◆ StreamFactory() [3/6]

ers::StreamFactory::StreamFactory ( )
protected

◆ StreamFactory() [4/6]

ers::StreamFactory::StreamFactory ( const StreamFactory & other)
protected

◆ ~StreamFactory() [2/3]

ers::StreamFactory::~StreamFactory ( )

◆ StreamFactory() [5/6]

ers::StreamFactory::StreamFactory ( )
protected

◆ StreamFactory() [6/6]

ers::StreamFactory::StreamFactory ( const StreamFactory & other)
protected

◆ ~StreamFactory() [3/3]

ers::StreamFactory::~StreamFactory ( )

Member Function Documentation

◆ create_stream() [1/6]

ers::Stream * ers::StreamFactory::create_stream ( const std::string & key) const

create a stream from a key

Builds a stream from a textual key The key should have the format protocol:path.extension In certain cases, the path will be empty. For instance to write in XML format to the error stream, the key is: cerr:.xml

Parameters
keythe textual key
Note
the stream is allocated on the stack, it is the caller's responsibility to delete it.

Definition at line 144 of file StreamFactory.cxx.

144 {
145 std::string protocol;
146 std::string uri;
147
148 std::string::size_type colon = key.find( ':' );
149 if ( colon == std::string::npos ) { protocol = key; }
150 else
151 {
152 protocol = key.substr( 0, colon );
153 std::string::size_type uri_start = colon + 1;
154 if ( uri_start < key.size() ) { uri = key.substr( uri_start ); } // if
155 } // colon present
156 for ( stream_factory_collection::const_iterator pos = m_factories.begin();
157 pos != m_factories.end(); ++pos )
158 {
159 create_stream_callback callback = pos->second;
160 Stream* s = callback( protocol, uri );
161 if ( s != 0 ) return s;
162 } // for
163 fprintf( stderr, "Warning, could not find stream for key protocol=\"%s\" uri=\"%s\" (%s)\n",
164 protocol.c_str(), uri.c_str(), key.c_str() );
165 return new DefaultStream();
166} // create_stream
*************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
Stream *(* create_stream_callback)(const std::string &, const std::string &)
stream_factory_collection m_factories
collection of factories to build streams

◆ create_stream() [2/6]

Stream * ers::StreamFactory::create_stream ( const std::string & key) const

create a stream from a key

◆ create_stream() [3/6]

Stream * ers::StreamFactory::create_stream ( const std::string & key) const

create a stream from a key

◆ create_stream() [4/6]

ers::Stream * ers::StreamFactory::create_stream ( severity_t s)
protected

create a stream for severity_t

Builds a stream for a given severity. The actual key for the severity_t is found using key_for_severity, then the appropriate stream is constructred using create_stream

See also
key_for_severity()
create_stream()
Parameters
sthe severity_t of the requested stream
Returns
the newly created stream
Note
the stream is allocated on the stack, it is the caller's responsibility to delete it.

Definition at line 178 of file StreamFactory.cxx.

178 {
179 const char* key = key_for_severity( s );
180 return create_stream( key );
181} // get_stream
static const char * key_for_severity(severity_t s)
finds key for severity_t
Stream * create_stream(severity_t s)
create a stream for severity_t

Referenced by create_stream(), ers::FilterStream::factory(), get_stream(), and set().

◆ create_stream() [5/6]

Stream * ers::StreamFactory::create_stream ( severity_t s)
protected

create a stream for severity_t

◆ create_stream() [6/6]

Stream * ers::StreamFactory::create_stream ( severity_t s)
protected

create a stream for severity_t

◆ debug() [1/9]

void ers::StreamFactory::debug ( const Context & c,
const std::string & message,
severity_t s )
static

sends a debug message

Sends a message to the debug stream

Parameters
cthe Context of the message
messagethe text of the message
sthe severity_t of the associated stream. Accepted values:
  • ers_debug_0
  • ers_debug_1
  • ers_debug_2
  • ers_debug_3

Definition at line 235 of file StreamFactory.cxx.

235 {
236 LogIssue log_issue( c, s, message );
237 debug( &log_issue, s );
238} // debug
static void debug(Issue *i, severity_t)
sends an Issue to the debug stream

◆ debug() [2/9]

void ers::StreamFactory::debug ( const Context & c,
const std::string & message,
severity_t s )
static

sends a debug message

◆ debug() [3/9]

void ers::StreamFactory::debug ( const Context & c,
const std::string & message,
severity_t s )
static

sends a debug message

◆ debug() [4/9]

void ers::StreamFactory::debug ( Issue * issue_ptr,
severity_t s )
static

sends an Issue to the debug stream

Sends an issue to the debug stream

Parameters
issue_ptrthe Issue to send
sthe severity_t of the associated stream. Accepted values:
  • ers_debug_0
  • ers_debug_1
  • ers_debug_2
  • ers_debug_3

Definition at line 220 of file StreamFactory.cxx.

220 {
221 ERS_PRE_CHECK_PTR( issue_ptr );
222 ERS_PRECONDITION( s < ers::information, "severity_t is not debug : %s (%d) %d",
224 issue_ptr->severity( s );
225 dispatch( issue_ptr, false );
226} // debug
#define ERS_PRECONDITION(expr,...)
static const char * to_string(severity_t s)
severity_t to string
Definition Core.cxx:25
static void dispatch(Issue *i, bool throw_error=false)
Sends an issue to the appropriate stream according to its severity_t.

Referenced by debug().

◆ debug() [5/9]

void ers::StreamFactory::debug ( Issue * i,
severity_t  )
static

sends an Issue to the debug stream

◆ debug() [6/9]

void ers::StreamFactory::debug ( Issue * i,
severity_t  )
static

sends an Issue to the debug stream

◆ debug() [7/9]

ers::Stream * ers::StreamFactory::debug ( severity_t s)

Debug stream for level.

Finds the debug stream

Parameters
sthe severity_t of the associated stream. Accepted values:
  • ers_debug_0
  • ers_debug_1
  • ers_debug_2
  • ers_debug_3
Returns
debug stream

Definition at line 341 of file StreamFactory.cxx.

341 {
343 "severity_t is not debug : %s (%d)", ers::Core::to_string( s ), s );
344 return get_stream( s );
345} // debug
Stream * get_stream(severity_t s)
get stream for severity_t

◆ debug() [8/9]

Stream * ers::StreamFactory::debug ( severity_t s)

Debug stream for level.

◆ debug() [9/9]

Stream * ers::StreamFactory::debug ( severity_t s)

Debug stream for level.

◆ dispatch() [1/6]

void ers::StreamFactory::dispatch ( Issue & i,
bool throw_error = false )
static

Definition at line 266 of file StreamFactory.cxx.

266 {
267 dispatch( &issue_ref, throw_error );
268} // dispatch

◆ dispatch() [2/6]

void ers::StreamFactory::dispatch ( Issue & i,
bool throw_error = false )
static

◆ dispatch() [3/6]

void ers::StreamFactory::dispatch ( Issue & i,
bool throw_error = false )
static

◆ dispatch() [4/6]

void ers::StreamFactory::dispatch ( Issue * issue_ptr,
bool throw_error = false )
static

Sends an issue to the appropriate stream according to its severity_t.

Dispatches an issue to the appropriate stream. The stream is decided based upon the severity_t specified in the Issue. If throw_error is true errors and fatal errors are not sent to a stream, but thrown in the context of the caller.

Parameters
issue_ptrthe Issue to dispatch
throw_errorshould errors and fatals are thrown

Definition at line 257 of file StreamFactory.cxx.

257 {
258 ERS_PRE_CHECK_PTR( issue_ptr );
259 if ( throw_error && issue_ptr->is_error() ) { throw *issue_ptr; }
260 const severity_t s = issue_ptr->severity();
261 Stream* stream_ptr = instance()->get_stream( s );
262 ERS_CHECK_PTR( stream_ptr );
263 stream_ptr->send( issue_ptr );
264} // dispatch
static StreamFactory * instance()
return the singleton

Referenced by debug(), dispatch(), error(), fatal(), main(), and warning().

◆ dispatch() [5/6]

void ers::StreamFactory::dispatch ( Issue * i,
bool throw_error = false )
static

Sends an issue to the appropriate stream according to its severity_t.

◆ dispatch() [6/6]

void ers::StreamFactory::dispatch ( Issue * i,
bool throw_error = false )
static

Sends an issue to the appropriate stream according to its severity_t.

◆ error() [1/6]

ers::Stream * ers::StreamFactory::error ( )

Error stream.

Returns
the current error stream

Definition at line 327 of file StreamFactory.cxx.

327{ return get_stream( ers::error ); } // error

◆ error() [2/6]

Stream * ers::StreamFactory::error ( )

Error stream.

◆ error() [3/6]

Stream * ers::StreamFactory::error ( )

Error stream.

◆ error() [4/6]

void ers::StreamFactory::error ( Issue * issue_ptr)
static

sends an issue to the error stream

Sends an Issue to the error stream

Parameters
issue_ptr

Definition at line 197 of file StreamFactory.cxx.

197 {
198 ERS_PRE_CHECK_PTR( issue_ptr );
199 issue_ptr->severity( ers::error );
200 dispatch( issue_ptr, false );
201} // error

◆ error() [5/6]

void ers::StreamFactory::error ( Issue * i)
static

sends an issue to the error stream

◆ error() [6/6]

void ers::StreamFactory::error ( Issue * i)
static

sends an issue to the error stream

◆ fatal() [1/6]

ers::Stream * ers::StreamFactory::fatal ( )

Fatal stream.

Returns
the current fatal stream

Definition at line 321 of file StreamFactory.cxx.

321{ return get_stream( ers::fatal ); } // fatal

◆ fatal() [2/6]

Stream * ers::StreamFactory::fatal ( )

Fatal stream.

◆ fatal() [3/6]

Stream * ers::StreamFactory::fatal ( )

Fatal stream.

◆ fatal() [4/6]

void ers::StreamFactory::fatal ( Issue * issue_ptr)
static

sends an issue to the fatal stream

Sends an Issue to the fatal error stream

Parameters
issue_ptr

Definition at line 187 of file StreamFactory.cxx.

187 {
188 ERS_PRE_CHECK_PTR( issue_ptr );
189 issue_ptr->severity( ers::fatal );
190 dispatch( issue_ptr, false );
191} // fatal

◆ fatal() [5/6]

void ers::StreamFactory::fatal ( Issue * i)
static

sends an issue to the fatal stream

◆ fatal() [6/6]

void ers::StreamFactory::fatal ( Issue * i)
static

sends an issue to the fatal stream

◆ get_default_stream() [1/3]

ers::Stream * ers::StreamFactory::get_default_stream ( severity_t s)
staticprotected

builds default stream for severity_t

Finds the default stream for a given severity. The stream is searched in the default instance

Parameters
sthe severity_t
Returns
the default stream for the severity_t

Definition at line 104 of file StreamFactory.cxx.

104 {
105 return instance()->get_stream( s );
106} // get_default_stream

◆ get_default_stream() [2/3]

Stream * ers::StreamFactory::get_default_stream ( severity_t s)
staticprotected

builds default stream for severity_t

◆ get_default_stream() [3/3]

Stream * ers::StreamFactory::get_default_stream ( severity_t s)
staticprotected

builds default stream for severity_t

◆ get_stream() [1/3]

ers::Stream * ers::StreamFactory::get_stream ( severity_t s)

get stream for severity_t

Gets stream for severity_t

Parameters
sthe severity_t of the requested stream
Returns
the stream

Definition at line 282 of file StreamFactory.cxx.

282 {
283 if ( m_streams[s] == 0 ) { m_streams[s] = create_stream( s ); } // if
284 return m_streams[s];
285} // get_stream

Referenced by debug(), error(), fatal(), and warning().

◆ get_stream() [2/3]

Stream * ers::StreamFactory::get_stream ( severity_t s)

get stream for severity_t

◆ get_stream() [3/3]

Stream * ers::StreamFactory::get_stream ( severity_t s)

get stream for severity_t

◆ instance() [1/3]

ers::StreamFactory * ers::StreamFactory::instance ( )
static

return the singleton

This method returns the singleton instance. It should be used for every operation on the factory.

Returns
a pointer to the singleton instance

Definition at line 83 of file StreamFactory.cxx.

83 {
84 if ( 0 == s_instance ) { s_instance = new StreamFactory(); } // if
85 return s_instance;
86} // instance
static StreamFactory * s_instance
singleton instance

Referenced by dispatch(), ers::FilterStream::factory(), get_default_stream(), print_registered(), and set_stream().

◆ instance() [2/3]

StreamFactory * ers::StreamFactory::instance ( )
static

return the singleton

◆ instance() [3/3]

StreamFactory * ers::StreamFactory::instance ( )
static

return the singleton

◆ key_for_severity() [1/3]

const char * ers::StreamFactory::key_for_severity ( severity_t s)
staticprotected

finds key for severity_t

Searches for the textual key for a given severity. This key is first searched in the environnement variables, if this fails, the default values are loaded. The environnement variable should have the same name than the severity with the prefix ERS_ in front. The whole name should be in uppercases. For instance for severity_t warning, the environnement variable should be ERS_WARNING.

Parameters
sthe severity_t
Returns
the key describing the stream.

Definition at line 119 of file StreamFactory.cxx.

119 {
120 char key_buffer[64];
121 snprintf( key_buffer, sizeof( key_buffer ), "ERS_%s", ers::Core::to_string( s ) );
122 char* c = &( key_buffer[0] );
123 while ( *c )
124 {
125 *c = toupper( *c );
126 c++;
127 } // while
128 const char* env = ::getenv( key_buffer );
129 if ( env != 0 ) return env;
130 const char* static_key = DEFAULT_STREAMS[s];
131 if ( static_key ) return static_key;
133} // key_for_severity
static const char * DEFAULT_STREAMS[]
keys for default streams

Referenced by create_stream().

◆ key_for_severity() [2/3]

const char * ers::StreamFactory::key_for_severity ( severity_t s)
staticprotected

finds key for severity_t

◆ key_for_severity() [3/3]

const char * ers::StreamFactory::key_for_severity ( severity_t s)
staticprotected

finds key for severity_t

◆ print_registered() [1/3]

void ers::StreamFactory::print_registered ( )
static

Dumps all registered types of streams

Definition at line 90 of file StreamFactory.cxx.

90 {
92 std::cerr << *factory;
93} // print_registered
efhlt::Interface * factory(void)
Definition factory.cxx:15

◆ print_registered() [2/3]

void ers::StreamFactory::print_registered ( )
static

◆ print_registered() [3/3]

void ers::StreamFactory::print_registered ( )
static

◆ register_factory() [1/3]

bool ers::StreamFactory::register_factory ( const std::string & name,
create_stream_callback callback )

register a factory method

Registers a factory function with the stream factory. The callback is function that takes two parameters

  1. a string describing the protocol, for instance file
  2. a string describing a uri, can be a path, a suffix or anything

The function should return a heap allocated stream, or null if it does not understand the protocol.

Parameters
namename of the stream type (human display only).
callbackthe callback function
Returns
true if the registration was sucessfull

Definition at line 359 of file StreamFactory.cxx.

360 {
361 // std::cerr << "registering " << name << std::endl ;
362 m_factories[name] = callback;
363 return true;
364} // register_factory

◆ register_factory() [2/3]

bool ers::StreamFactory::register_factory ( const std::string & name,
create_stream_callback callback )

register a factory method

◆ register_factory() [3/3]

bool ers::StreamFactory::register_factory ( const std::string & name,
create_stream_callback callback )

register a factory method

◆ set() [1/6]

void ers::StreamFactory::set ( severity_t severity,
const char * key )

Setup a stream for a given severity_t based on a key.

Builds a stream using a string key and sets it up for a given severity

Parameters
severity_tseverity_t of the stream Accepted values:
  • ers_debug_0
  • ers_debug_1
  • ers_debug_2
  • ers_debug_3
  • ers_information
  • ers_notification
  • ers_warning
  • ers::error
  • ers_fatal
keythe key used to build the new stream

Definition at line 311 of file StreamFactory.cxx.

311 {
313 Stream* s = create_stream( key );
314 set( severity, s );
315} //
void set(severity_t severity, Stream *s)
Sets the stream for a given severity_t.

◆ set() [2/6]

void ers::StreamFactory::set ( severity_t severity,
const char * key )

Setup a stream for a given severity_t based on a key.

◆ set() [3/6]

void ers::StreamFactory::set ( severity_t severity,
const char * key )

Setup a stream for a given severity_t based on a key.

◆ set() [4/6]

void ers::StreamFactory::set ( severity_t severity,
Stream * s )

Sets the stream for a given severity_t.

Sets the stream for a given severity_t

Parameters
severity_tseverity_t of the stream Accepted values:
  • ers_debug_0
  • ers_debug_1
  • ers_debug_2
  • ers_debug_3
  • ers_information
  • ers_notification
  • ers_warning
  • ers::error
  • ers_fatal
sthe new stream

Definition at line 295 of file StreamFactory.cxx.

295 {
297 ERS_PRECONDITION( severity_none < severity && severity < severity_max,
298 "illegal severity_t %d", (int)severity );
299 if ( m_streams[severity] ) { delete m_streams[severity]; } // if there is a stream defined
300 m_streams[severity] = s;
301} // stream

Referenced by set().

◆ set() [5/6]

void ers::StreamFactory::set ( severity_t severity,
Stream * s )

Sets the stream for a given severity_t.

◆ set() [6/6]

void ers::StreamFactory::set ( severity_t severity,
Stream * s )

Sets the stream for a given severity_t.

◆ set_stream() [1/3]

void ers::StreamFactory::set_stream ( severity_t s,
const std::string & key )
static

Definition at line 270 of file StreamFactory.cxx.

270 {
271 instance()->set( s, key.c_str() );
272} // set

Referenced by main(), and massive_test().

◆ set_stream() [2/3]

void ers::StreamFactory::set_stream ( severity_t ,
const std::string & key )
static

◆ set_stream() [3/3]

void ers::StreamFactory::set_stream ( severity_t ,
const std::string & key )
static

◆ warning() [1/9]

ers::Stream * ers::StreamFactory::warning ( )

Warning stream.

Returns
the current warning stream

Definition at line 333 of file StreamFactory.cxx.

333{ return get_stream( ers::warning ); } // warning

Referenced by main().

◆ warning() [2/9]

Stream * ers::StreamFactory::warning ( )

Warning stream.

◆ warning() [3/9]

Stream * ers::StreamFactory::warning ( )

Warning stream.

◆ warning() [4/9]

void ers::StreamFactory::warning ( const Context & c,
const std::string & message )
static

sends a warning message

Sends a message to the warning stream

Parameters
cthe context of the message
messagethe message to send

Definition at line 245 of file StreamFactory.cxx.

245 {
246 LogIssue log_issue( c, ers::warning, message );
247 warning( &log_issue );
248} // warning
Stream * warning()
Warning stream.

◆ warning() [5/9]

void ers::StreamFactory::warning ( const Context & c,
const std::string & message )
static

sends a warning message

◆ warning() [6/9]

void ers::StreamFactory::warning ( const Context & c,
const std::string & message )
static

sends a warning message

◆ warning() [7/9]

void ers::StreamFactory::warning ( Issue * issue_ptr)
static

sends an issue to the warning stream

Sends an Issue to the warning stream

Parameters
issue_ptrthe issue to send

Definition at line 207 of file StreamFactory.cxx.

207 {
208 ERS_PRE_CHECK_PTR( issue_ptr );
209 issue_ptr->severity( ers::warning );
210 dispatch( issue_ptr, false );
211} // warning

◆ warning() [8/9]

void ers::StreamFactory::warning ( Issue * i)
static

sends an issue to the warning stream

◆ warning() [9/9]

void ers::StreamFactory::warning ( Issue * i)
static

sends an issue to the warning stream

◆ write_to() [1/3]

void ers::StreamFactory::write_to ( std::ostream & stream) const

write content of factory to stream

Writes a description of the factory to a stream. This method gives a list of all registered stream types.

Parameters
streamthe stream to write into

Definition at line 371 of file StreamFactory.cxx.

371 {
372 stream << "Stream factory - registered streams\n";
373 stream << "-----------------------------------\n";
374 int i = 0;
375 for ( stream_factory_collection::const_iterator pos = m_factories.begin();
376 pos != m_factories.end(); ++pos )
377 {
378 std::string name = pos->first;
379 stream << i << ")\t" << name << std::endl;
380 i++;
381 } // for
382 stream << "-----------------------------------\n";
383} // write_to

◆ write_to() [2/3]

void ers::StreamFactory::write_to ( std::ostream & stream) const

write content of factory to stream

◆ write_to() [3/3]

void ers::StreamFactory::write_to ( std::ostream & stream) const

write content of factory to stream

Member Data Documentation

◆ DEFAULT_STREAMS

const char * ers::StreamFactory::DEFAULT_STREAMS
staticprotected
Initial value:
= { "null:",
"default:", "default:", "default:",
"default:",
"default:", "default:",
"default:",
"default:verbose",
"default:verbose",
"null:" }

keys for default streams

This variable contains the default keys for building the default streams. The default is to use the default stream, in verbose mode for errors and fatals.

Definition at line 21 of file Event/ers/include/ers/StreamFactory.h.

Referenced by key_for_severity().

◆ m_factories

stream_factory_collection ers::StreamFactory::m_factories
protected

collection of factories to build streams

Definition at line 157 of file Event/ers/include/ers/StreamFactory.h.

Referenced by create_stream(), register_factory(), StreamFactory(), and write_to().

◆ m_streams

Stream * ers::StreamFactory::m_streams
protected

array of pointers to streams per severity_t

Definition at line 156 of file Event/ers/include/ers/StreamFactory.h.

Referenced by get_stream(), set(), StreamFactory(), StreamFactory(), and ~StreamFactory().

◆ s_instance

StreamFactory * ers::StreamFactory::s_instance = 0
staticprotected

singleton instance

Pointer to the singleton instance

Definition at line 146 of file Event/ers/include/ers/StreamFactory.h.

Referenced by instance().


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