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/Severity.hpp>
27#include <ers/StreamFactory.hpp>
28#include <ers/ers.hpp>
32#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 key = format.substr(0, start);
65 std::string::size_type end = format.find(')', start);
66 if (end != std::string::npos)
67 param = format.substr(start + 1, end - start - 1);
68 }
69
70 OutFunctionMap::const_iterator it = m_out_factories.find(key);
71
72 if (it != m_out_factories.end()) {
73 try {
74 return it->second(param);
75 } catch (ers::Issue& issue) {
77 }
78 } else {
79 ERS_INTERNAL_ERROR("Creator for the \"" << key << "\" stream is not found")
80 }
81
82 return 0;
83}
84
94ers::StreamFactory::create_in_stream(const std::string& stream, const std::string& param) const
95{
96 return create_in_stream(stream, { param });
97}
98
108ers::StreamFactory::create_in_stream(const std::string& stream, const std::initializer_list<std::string>& params) const
109{
110 InFunctionMap::const_iterator it = m_in_factories.find(stream);
111
112 if (it != m_in_factories.end()) {
113 try {
114 return it->second(params);
115 } catch (ers::Issue& issue) {
116 throw ers::InvalidFormat(ERS_HERE, stream, issue);
117 }
118 }
119
120 throw ers::InvalidFormat(ERS_HERE, stream);
121}
122
133void
134ers::StreamFactory::register_in_stream(const std::string& name, InputStreamCreator callback)
135{
136 m_in_factories[name] = callback;
137}
138
149void
150ers::StreamFactory::register_out_stream(const std::string& name, OutputStreamCreator callback)
151{
152 m_out_factories[name] = callback;
153}
154
155std::ostream&
156ers::operator<<(std::ostream& out, const ers::StreamFactory& sf)
157{
158 StreamFactory::OutFunctionMap::const_iterator oit = sf.m_out_factories.begin();
159 for (; oit != sf.m_out_factories.end(); ++oit) {
160 out << oit->first << "\t\"" << oit->second << "\"" << std::endl;
161 }
162
163 StreamFactory::InFunctionMap::const_iterator iit = sf.m_in_factories.begin();
164 for (; iit != sf.m_in_factories.end(); ++iit) {
165 out << iit->first << "\t\"" << iit->second << "\"" << std::endl;
166 }
167 return out;
168}
#define ERS_HERE
ERS Issue input stream interface.
Base class for any user define issue.
Definition Issue.hpp:76
ERS abstract output stream interface.
#define ERS_INTERNAL_ERROR(message)
Definition macro.hpp:71
FELIX Initialization std::string initerror FELIX queue timed out
std::ostream & operator<<(std::ostream &, const ers::Configuration &)