DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ers::StreamManager Class Reference

This class manages and provides access to ERS streams. More...

#include <StreamManager.hpp>

Collaboration diagram for ers::StreamManager:
[legend]

Public Member Functions

 ~StreamManager ()
void debug (const Issue &issue, int level)
 sends an Issue to the debug stream
void error (const Issue &issue)
 sends an issue to the error stream
void fatal (const Issue &issue)
 sends an issue to the fatal stream
void information (const Issue &issue)
 sends an issue to the information stream
void log (const Issue &issue)
 sends an issue to the log stream
void warning (const Issue &issue)
 sends an issue to the warning stream
void add_receiver (const std::string &stream, const std::string &filter, ers::IssueReceiver *receiver)
void add_receiver (const std::string &stream, const std::initializer_list< std::string > &params, ers::IssueReceiver *receiver)
void remove_receiver (ers::IssueReceiver *receiver)
void add_output_stream (ers::severity severityseverity, ers::OutputStream *new_stream)
void report_issue (ers::severity type, const Issue &issue)

Static Public Member Functions

static StreamManagerinstance ()
 return the singleton

Private Member Functions

 StreamManager ()
OutputStreamsetup_stream (ers::severity severityseverity)
OutputStreamsetup_stream (const std::vector< std::string > &streams)

Private Attributes

PluginManager m_plugin_manager
std::mutex m_mutex
std::list< std::shared_ptr< InputStream > > m_in_streams
std::shared_ptr< OutputStreamm_init_streams [ers::Fatal+1]
 array of pointers to streams per severity
std::shared_ptr< OutputStreamm_out_streams [ers::Fatal+1]
 array of pointers to streams per severity

Friends

class StreamInitializer
class ers::LocalStream
class ers::ErrorHandler
template<class>
class SingletonCreator

Detailed Description

This class manages and provides access to ERS streams.

The StreamManager class is responsible for creating and handling all the ERS streams used by an application. It implements the singleton pattern and handles a table of the different stream attached to each severity. When issues occur they are dispatched to an appropriate stream by the singleton instance of this class. Users should not use this class directly. In order to report issues users should use global functions declared in the ers namespace.

Author
Serguei Kolos
See also
ers::debug
ers::error
ers::fatal
ers::infomation
ers::log
ers::warning

Definition at line 69 of file StreamManager.hpp.

Constructor & Destructor Documentation

◆ ~StreamManager()

ers::StreamManager::~StreamManager ( )

Destructor - basic cleanup

Definition at line 185 of file StreamManager.cpp.

186{ ; }

◆ StreamManager()

ers::StreamManager::StreamManager ( )
private

Private constructor - can not be called by user code, use the instance() method instead

See also
instance()

Definition at line 174 of file StreamManager.cpp.

175{
176 for( short ss = ers::Debug; ss <= ers::Fatal; ++ss )
177 {
178 m_init_streams[ss] = std::make_shared<StreamInitializer>( *this );
180 }
181}
std::shared_ptr< OutputStream > m_init_streams[ers::Fatal+1]
array of pointers to streams per severity
std::shared_ptr< OutputStream > m_out_streams[ers::Fatal+1]
array of pointers to streams per severity
@ Debug
Definition Severity.hpp:37
@ Fatal
Definition Severity.hpp:37

Member Function Documentation

◆ add_output_stream()

void ers::StreamManager::add_output_stream ( ers::severity severity,
ers::OutputStream * new_stream )

Definition at line 189 of file StreamManager.cpp.

190{
191 std::shared_ptr<OutputStream> head = m_out_streams[severity];
192 if ( head && !head->isNull() )
193 {
194 OutputStream * parent = head.get();
195 for ( OutputStream * stream = parent; !stream->isNull(); parent = stream,
196 stream = &parent->chained() )
197 ;
198
199 parent->chained( new_stream );
200 }
201 else
202 {
203 m_out_streams[severity] = std::shared_ptr<OutputStream>( new_stream );
204 }
205}
severity
Definition Severity.hpp:37

◆ add_receiver() [1/2]

void ers::StreamManager::add_receiver ( const std::string & stream,
const std::initializer_list< std::string > & params,
ers::IssueReceiver * receiver )

Definition at line 220 of file StreamManager.cpp.

223{
224 InputStream * in = ers::StreamFactory::instance().create_in_stream( stream, params );
225 in->set_receiver( receiver );
226
227 std::scoped_lock lock( m_mutex );
228 m_in_streams.push_back( std::shared_ptr<InputStream>( in ) );
229}
std::list< std::shared_ptr< InputStream > > m_in_streams

◆ add_receiver() [2/2]

void ers::StreamManager::add_receiver ( const std::string & stream,
const std::string & filter,
ers::IssueReceiver * receiver )

Definition at line 208 of file StreamManager.cpp.

211{
212 InputStream * in = ers::StreamFactory::instance().create_in_stream( stream, filter );
213 in->set_receiver( receiver );
214
215 std::scoped_lock lock( m_mutex );
216 m_in_streams.push_back( std::shared_ptr<InputStream>( in ) );
217}

◆ debug()

void ers::StreamManager::debug ( const Issue & issue,
int level )

sends an Issue to the debug stream

Sends an issue to the debug stream

Parameters
issuethe Issue to send
levelthe debug level.

Definition at line 337 of file StreamManager.cpp.

338{
339 if ( Configuration::instance().debug_level() >= level )
340 {
341 ers::severity old_severity = issue.set_severity( ers::Severity( ers::Debug, level ) );
342 m_out_streams[ers::Debug]->write( issue );
343 issue.set_severity( old_severity );
344 }
345}
static Configuration & instance()
return the singleton
int debug_level()
Definition ers.hpp:77

◆ error()

void ers::StreamManager::error ( const Issue & issue)

sends an issue to the error stream

Sends an Issue to the error stream

Parameters
issue

Definition at line 327 of file StreamManager.cpp.

328{
329 report_issue( ers::Error, issue );
330} // error
void report_issue(ers::severity type, const Issue &issue)
@ Error
Definition Severity.hpp:37

◆ fatal()

void ers::StreamManager::fatal ( const Issue & issue)

sends an issue to the fatal stream

Sends an Issue to the fatal error stream

Parameters
issue

Definition at line 351 of file StreamManager.cpp.

352{
353 report_issue( ers::Fatal, issue );
354}

◆ information()

void ers::StreamManager::information ( const Issue & issue)

sends an issue to the information stream

Sends an issue to the info stream

Parameters
issuethe Issue to send

Definition at line 369 of file StreamManager.cpp.

370{
372}
@ Information
Definition Severity.hpp:37

◆ instance()

ers::StreamManager & ers::StreamManager::instance ( )
static

return the singleton

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

Returns
a reference to the singleton instance

Singleton instance

Definition at line 162 of file StreamManager.cpp.

163{
166 static ers::StreamManager * instance = ers::SingletonCreator<ers::StreamManager>::create();
167
168 return *instance;
169} // instance
static StreamManager & instance()
return the singleton

◆ log()

void ers::StreamManager::log ( const Issue & issue)

sends an issue to the log stream

Sends an issue to the log stream

Parameters
issuethe Issue to send

Definition at line 378 of file StreamManager.cpp.

379{
380 report_issue( ers::Log, issue );
381}
@ Log
Definition Severity.hpp:37

◆ remove_receiver()

void ers::StreamManager::remove_receiver ( ers::IssueReceiver * receiver)

Definition at line 232 of file StreamManager.cpp.

233{
234 std::scoped_lock lock( m_mutex );
235 for( std::list<std::shared_ptr<InputStream> >::iterator it = m_in_streams.begin();
236 it != m_in_streams.end(); )
237 {
238 if ( (*it) -> m_receiver == receiver )
239 m_in_streams.erase( it++ );
240 else
241 ++it;
242 }
243}

◆ report_issue()

void ers::StreamManager::report_issue ( ers::severity type,
const Issue & issue )

Sends an Issue to an appropriate stream

Parameters
type
issue

Definition at line 316 of file StreamManager.cpp.

317{
318 ers::severity old_severity = issue.set_severity( type );
319 m_out_streams[type]->write( issue );
320 issue.set_severity( old_severity );
321} // error

◆ setup_stream() [1/2]

ers::OutputStream * ers::StreamManager::setup_stream ( const std::vector< std::string > & streams)
private

Definition at line 280 of file StreamManager.cpp.

281{
282 size_t cnt = 0;
283 ers::OutputStream * main = 0;
284 for ( ; cnt < streams.size(); ++cnt )
285 {
286 main = ers::StreamFactory::instance().create_out_stream( streams[cnt] );
287 if ( main )
288 break;
289 }
290
291 if ( !main )
292 {
293 return 0;
294 }
295
296 ers::OutputStream * head = main;
297 for ( ++cnt; cnt < streams.size(); ++cnt )
298 {
299 ers::OutputStream * chained = ers::StreamFactory::instance().create_out_stream( streams[cnt] );
300
301 if ( chained )
302 {
303 head->chained( chained );
304 head = chained;
305 }
306 }
307
308 return main;
309}
OutputStream & chained()
int main(int argc, char *argv[])

◆ setup_stream() [2/2]

ers::OutputStream * ers::StreamManager::setup_stream ( ers::severity severity)
private

Definition at line 246 of file StreamManager.cpp.

247{
248 std::string config = get_stream_description( severity );
249 std::vector<std::string> streams;
250 try
251 {
252 parse_stream_definition( config, streams );
253 }
254 catch ( ers::BadConfiguration & ex )
255 {
256 ERS_INTERNAL_ERROR( "Configuration for the \"" << severity << "\" stream is invalid. "
257 "Default configuration will be used." );
258 }
259
260 ers::OutputStream * main = setup_stream( streams );
261
262 if ( !main )
263 {
264 std::vector<std::string> default_streams;
265 try
266 {
267 parse_stream_definition( DefaultOutputStreams[severity], default_streams );
268 main = setup_stream( default_streams );
269 }
270 catch ( ers::BadConfiguration & ex )
271 {
272 ERS_INTERNAL_ERROR( "Can not configure the \"" << severity
273 << "\" stream because of the following issue {" << ex << "}" );
274 }
275 }
276 return ( main ? main : new ers::NullStream() );
277}
OutputStream * setup_stream(ers::severity severity)
#define ERS_INTERNAL_ERROR(message)
Definition macro.hpp:63

◆ warning()

void ers::StreamManager::warning ( const Issue & issue)

sends an issue to the warning stream

Sends an Issue to the warning stream

Parameters
issuethe issue to send

Definition at line 360 of file StreamManager.cpp.

361{
362 report_issue( ers::Warning, issue );
363}
@ Warning
Definition Severity.hpp:37

◆ ers::ErrorHandler

friend class ers::ErrorHandler
friend

Definition at line 73 of file StreamManager.hpp.

◆ ers::LocalStream

friend class ers::LocalStream
friend

Definition at line 72 of file StreamManager.hpp.

◆ SingletonCreator

template<class>
friend class SingletonCreator
friend

Definition at line 74 of file StreamManager.hpp.

◆ StreamInitializer

friend class StreamInitializer
friend

Definition at line 71 of file StreamManager.hpp.

Member Data Documentation

◆ m_in_streams

std::list<std::shared_ptr<InputStream> > ers::StreamManager::m_in_streams
private

Definition at line 116 of file StreamManager.hpp.

◆ m_init_streams

std::shared_ptr<OutputStream> ers::StreamManager::m_init_streams[ers::Fatal+1]
private

array of pointers to streams per severity

Definition at line 117 of file StreamManager.hpp.

◆ m_mutex

std::mutex ers::StreamManager::m_mutex
private

Definition at line 115 of file StreamManager.hpp.

◆ m_out_streams

std::shared_ptr<OutputStream> ers::StreamManager::m_out_streams[ers::Fatal+1]
private

array of pointers to streams per severity

Definition at line 118 of file StreamManager.hpp.

◆ m_plugin_manager

PluginManager ers::StreamManager::m_plugin_manager
private

Definition at line 114 of file StreamManager.hpp.


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