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 severity, 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 severity)
 
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 58 of file StreamManager.hpp.

Constructor & Destructor Documentation

◆ ~StreamManager()

ers::StreamManager::~StreamManager ( )

Destructor - basic cleanup

Definition at line 174 of file StreamManager.cpp.

175{ ; }

◆ 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 163 of file StreamManager.cpp.

164{
165 for( short ss = ers::Debug; ss <= ers::Fatal; ++ss )
166 {
167 m_init_streams[ss] = std::make_shared<StreamInitializer>( *this );
169 }
170}
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:26
@ Fatal
Definition Severity.hpp:26

Member Function Documentation

◆ add_output_stream()

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

Definition at line 178 of file StreamManager.cpp.

179{
180 std::shared_ptr<OutputStream> head = m_out_streams[severity];
181 if ( head && !head->isNull() )
182 {
183 OutputStream * parent = head.get();
184 for ( OutputStream * stream = parent; !stream->isNull(); parent = stream,
185 stream = &parent->chained() )
186 ;
187
188 parent->chained( new_stream );
189 }
190 else
191 {
192 m_out_streams[severity] = std::shared_ptr<OutputStream>( new_stream );
193 }
194}
severity
Definition Severity.hpp:26

◆ 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 209 of file StreamManager.cpp.

212{
213 InputStream * in = ers::StreamFactory::instance().create_in_stream( stream, params );
214 in->set_receiver( receiver );
215
216 std::scoped_lock lock( m_mutex );
217 m_in_streams.push_back( std::shared_ptr<InputStream>( in ) );
218}
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 197 of file StreamManager.cpp.

200{
201 InputStream * in = ers::StreamFactory::instance().create_in_stream( stream, filter );
202 in->set_receiver( receiver );
203
204 std::scoped_lock lock( m_mutex );
205 m_in_streams.push_back( std::shared_ptr<InputStream>( in ) );
206}

◆ 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 326 of file StreamManager.cpp.

327{
328 if ( Configuration::instance().debug_level() >= level )
329 {
330 ers::severity old_severity = issue.set_severity( ers::Severity( ers::Debug, level ) );
331 m_out_streams[ers::Debug]->write( issue );
332 issue.set_severity( old_severity );
333 }
334}
static Configuration & instance()
return the singleton
int debug_level()
Definition ers.hpp:66

◆ 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 316 of file StreamManager.cpp.

317{
318 report_issue( ers::Error, issue );
319} // error
void report_issue(ers::severity type, const Issue &issue)
@ Error
Definition Severity.hpp:26

◆ 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 340 of file StreamManager.cpp.

341{
342 report_issue( ers::Fatal, issue );
343}

◆ 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 358 of file StreamManager.cpp.

359{
361}
@ Information
Definition Severity.hpp:26

◆ 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 151 of file StreamManager.cpp.

152{
156
157 return *instance;
158} // instance
This class manages and provides access to ERS streams.
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 367 of file StreamManager.cpp.

368{
369 report_issue( ers::Log, issue );
370}
@ Log
Definition Severity.hpp:26

◆ remove_receiver()

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

Definition at line 221 of file StreamManager.cpp.

222{
223 std::scoped_lock lock( m_mutex );
224 for( std::list<std::shared_ptr<InputStream> >::iterator it = m_in_streams.begin();
225 it != m_in_streams.end(); )
226 {
227 if ( (*it) -> m_receiver == receiver )
228 m_in_streams.erase( it++ );
229 else
230 ++it;
231 }
232}

◆ 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 305 of file StreamManager.cpp.

306{
307 ers::severity old_severity = issue.set_severity( type );
308 m_out_streams[type]->write( issue );
309 issue.set_severity( old_severity );
310} // error

◆ setup_stream() [1/2]

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

Definition at line 269 of file StreamManager.cpp.

270{
271 size_t cnt = 0;
273 for ( ; cnt < streams.size(); ++cnt )
274 {
275 main = ers::StreamFactory::instance().create_out_stream( streams[cnt] );
276 if ( main )
277 break;
278 }
279
280 if ( !main )
281 {
282 return 0;
283 }
284
285 ers::OutputStream * head = main;
286 for ( ++cnt; cnt < streams.size(); ++cnt )
287 {
288 ers::OutputStream * chained = ers::StreamFactory::instance().create_out_stream( streams[cnt] );
289
290 if ( chained )
291 {
292 head->chained( chained );
293 head = chained;
294 }
295 }
296
297 return main;
298}
ERS abstract output stream interface.
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 235 of file StreamManager.cpp.

236{
237 std::string config = get_stream_description( severity );
238 std::vector<std::string> streams;
239 try
240 {
241 parse_stream_definition( config, streams );
242 }
243 catch ( ers::BadConfiguration & ex )
244 {
245 ERS_INTERNAL_ERROR( "Configuration for the \"" << severity << "\" stream is invalid. "
246 "Default configuration will be used." );
247 }
248
249 ers::OutputStream * main = setup_stream( streams );
250
251 if ( !main )
252 {
253 std::vector<std::string> default_streams;
254 try
255 {
256 parse_stream_definition( DefaultOutputStreams[severity], default_streams );
257 main = setup_stream( default_streams );
258 }
259 catch ( ers::BadConfiguration & ex )
260 {
261 ERS_INTERNAL_ERROR( "Can not configure the \"" << severity
262 << "\" stream because of the following issue {" << ex << "}" );
263 }
264 }
265 return ( main ? main : new ers::NullStream() );
266}
OutputStream * setup_stream(ers::severity severity)
#define ERS_INTERNAL_ERROR(message)
Definition macro.hpp:52
Null stream.

◆ 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 349 of file StreamManager.cpp.

350{
351 report_issue( ers::Warning, issue );
352}
@ Warning
Definition Severity.hpp:26

Friends And Related Symbol Documentation

◆ ers::ErrorHandler

friend class ers::ErrorHandler
friend

Definition at line 62 of file StreamManager.hpp.

◆ ers::LocalStream

friend class ers::LocalStream
friend

Definition at line 61 of file StreamManager.hpp.

◆ SingletonCreator

template<class >
friend class SingletonCreator
friend

Definition at line 63 of file StreamManager.hpp.

◆ StreamInitializer

friend class StreamInitializer
friend

Definition at line 60 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 105 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 106 of file StreamManager.hpp.

◆ m_mutex

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

Definition at line 104 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 107 of file StreamManager.hpp.

◆ m_plugin_manager

PluginManager ers::StreamManager::m_plugin_manager
private

Definition at line 103 of file StreamManager.hpp.


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