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 StreamManager & instance ()
 return the singleton

Private Member Functions

 StreamManager ()
OutputStream * setup_stream (ers::severity severityseverity)
OutputStream * setup_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< 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

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

176{
177 ;
178}

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

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

Member Function Documentation

◆ add_output_stream()

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

Definition at line 181 of file StreamManager.cpp.

182{
183 std::shared_ptr<OutputStream> head = m_out_streams[severity];
184 if (head && !head->isNull()) {
185 OutputStream* parent = head.get();
186 for (OutputStream* stream = parent; !stream->isNull(); parent = stream, stream = &parent->chained())
187 ;
188
189 parent->chained(new_stream);
190 } else {
191 m_out_streams[severity] = std::shared_ptr<OutputStream>(new_stream);
192 }
193}
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 206 of file StreamManager.cpp.

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

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

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

312{
313 if (Configuration::instance().debug_level() >= level) {
314 ers::severity old_severity = issue.set_severity(ers::Severity(ers::Debug, level));
315 m_out_streams[ers::Debug]->write(issue);
316 issue.set_severity(old_severity);
317 }
318}
static Configuration & instance()
return the singleton
int debug_level()
Definition ers.hpp:80

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

302{
303 report_issue(ers::Error, issue);
304} // error
void report_issue(ers::severity type, const Issue &issue)
@ Error
Definition Severity.hpp:42

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

325{
326 report_issue(ers::Fatal, issue);
327}

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

343{
345}
@ Information
Definition Severity.hpp:40

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

154{
157 static ers::StreamManager* instance = ers::SingletonCreator<ers::StreamManager>::create();
158
159 return *instance;
160} // 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 351 of file StreamManager.cpp.

352{
353 report_issue(ers::Log, issue);
354}
@ Log
Definition Severity.hpp:39

◆ remove_receiver()

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

Definition at line 218 of file StreamManager.cpp.

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

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

291{
292 ers::severity old_severity = issue.set_severity(type);
293 m_out_streams[type]->write(issue);
294 issue.set_severity(old_severity);
295} // error

◆ setup_stream() [1/2]

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

Definition at line 258 of file StreamManager.cpp.

259{
260 size_t cnt = 0;
261 ers::OutputStream* main = 0;
262 for (; cnt < streams.size(); ++cnt) {
263 main = ers::StreamFactory::instance().create_out_stream(streams[cnt]);
264 if (main)
265 break;
266 }
267
268 if (!main) {
269 return 0;
270 }
271
272 ers::OutputStream* head = main;
273 for (++cnt; cnt < streams.size(); ++cnt) {
274 ers::OutputStream* chained = ers::StreamFactory::instance().create_out_stream(streams[cnt]);
275
276 if (chained) {
277 head->chained(chained);
278 head = chained;
279 }
280 }
281
282 return main;
283}
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 230 of file StreamManager.cpp.

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

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

334{
336}
@ Warning
Definition Severity.hpp:41

◆ 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 75 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 114 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 115 of file StreamManager.hpp.

◆ m_mutex

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

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

◆ m_plugin_manager

PluginManager ers::StreamManager::m_plugin_manager
private

Definition at line 112 of file StreamManager.hpp.


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