DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
StreamFactory.cpp
Go to the documentation of this file.
1/*
2 * DUNE DAQ modification notice:
3 * This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
4 * Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
5 * Renamed since fork: yes (from src/StreamFactory.cxx to src/StreamFactory.cpp).
6 *
7 * Original copyright:
8 * Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
9 * Licensed under the Apache License, Version 2.0.
10 */
11
12/*
13 * StreamFactory.cxx
14 * ERS
15 *
16 * Created by Serguei Kolos on 21.01.05.
17 * Modified by Serguei Kolos on 21.11.05.
18 * Copyright 2005 CERN. All rights reserved.
19 *
20 */
21
22#include <iostream>
23
24#include <ers/Issue.hpp>
25#include <ers/OutputStream.hpp>
26#include <ers/StreamFactory.hpp>
27#include <ers/Severity.hpp>
28#include <ers/ers.hpp>
29#include <ers/internal/Util.hpp>
34
39ers::StreamFactory &
40ers::StreamFactory::instance()
41{
44 static ers::StreamFactory * instance = ers::SingletonCreator<ers::StreamFactory>::create();
45
46 return *instance;
47} // instance
48
58ers::StreamFactory::create_out_stream( const std::string & format ) const
59{
60 std::string key = format;
61 std::string param;
62 std::string::size_type start = format.find( '(' );
63 if ( start != std::string::npos )
64 {
65 key = format.substr( 0, start );
66 std::string::size_type end = format.find( ')', start );
67 if ( end != std::string::npos )
68 param = format.substr( start + 1, end - start - 1 );
69 }
70
71 OutFunctionMap::const_iterator it = m_out_factories.find( key );
72
73 if( it != m_out_factories.end() )
74 {
75 try
76 {
77 return it->second( param );
78 }
79 catch( ers::Issue & issue )
80 {
81 ERS_INTERNAL_ERROR( issue )
82 }
83 }
84 else
85 {
86 ERS_INTERNAL_ERROR( "Creator for the \"" << key << "\" stream is not found" )
87 }
88
89 return 0;
90}
91
101ers::StreamFactory::create_in_stream( const std::string & stream,
102 const std::string & param ) const
103{
104 return create_in_stream( stream, { param } );
105}
106
116ers::StreamFactory::create_in_stream(
117 const std::string & stream,
118 const std::initializer_list<std::string> & params ) const
119{
120 InFunctionMap::const_iterator it = m_in_factories.find( stream );
121
122 if( it != m_in_factories.end() )
123 {
124 try
125 {
126 return it->second( params );
127 }
128 catch( ers::Issue & issue )
129 {
130 throw ers::InvalidFormat( ERS_HERE, stream, issue );
131 }
132 }
133
134 throw ers::InvalidFormat( ERS_HERE, stream );
135}
136
147void
148ers::StreamFactory::register_in_stream( const std::string & name, InputStreamCreator callback )
149{
150 m_in_factories[name] = callback;
151}
152
163void
164ers::StreamFactory::register_out_stream( const std::string & name, OutputStreamCreator callback )
165{
166 m_out_factories[name] = callback;
167}
168
169std::ostream &
170ers::operator<<( std::ostream & out, const ers::StreamFactory & sf )
171{
172 StreamFactory::OutFunctionMap::const_iterator oit = sf.m_out_factories.begin();
173 for( ; oit != sf.m_out_factories.end(); ++oit )
174 {
175 out << oit->first << "\t\"" << oit->second << "\"" << std::endl;
176 }
177
178 StreamFactory::InFunctionMap::const_iterator iit = sf.m_in_factories.begin();
179 for( ; iit != sf.m_in_factories.end(); ++iit )
180 {
181 out << iit->first << "\t\"" << iit->second << "\"" << std::endl;
182 }
183 return out;
184}
#define ERS_HERE
ERS Issue input stream interface.
Base class for any user define issue.
Definition Issue.hpp:80
ERS abstract output stream interface.
#define ERS_INTERNAL_ERROR(message)
Definition macro.hpp:63
FELIX Initialization std::string initerror FELIX queue timed out
std::ostream & operator<<(std::ostream &, const ers::Configuration &)