Line data Source code
1 : /**
2 : *
3 : * @file SummaryTextDataStore.hpp
4 : *
5 : * Header for an implementation of the DataStore interface which
6 : * writes out simple text files; intended for unit testing /
7 : * proof-of-concept purposes
8 : *
9 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
10 : * Licensing/copyright details are in the COPYING file that you should have
11 : * received with this code.
12 : */
13 :
14 : #ifndef DFMODULES_PLUGINS_SUMMARYTEXTDATASTORE_HPP_
15 : #define DFMODULES_PLUGINS_SUMMARYTEXTDATASTORE_HPP_
16 :
17 : #include "dfmodules/FileDataStoreImpl.hpp"
18 :
19 : #include "dfmodules/DataStoreConfTestDeriv.hpp"
20 : #include "dfmodules/SummaryTextDataWriter.hpp"
21 :
22 : #include <limits>
23 : #include <memory>
24 : #include <string>
25 :
26 : namespace dunedaq::dfmodules {
27 :
28 : class SummaryTextDataStore : public FileDataStoreImpl<dfmodules::SummaryTextDataWriter>
29 : {
30 :
31 : public:
32 9 : explicit SummaryTextDataStore(std::string const& name,
33 : std::shared_ptr<appfwk::ConfigurationManager> mcfg,
34 : std::string const& writer_name)
35 9 : : FileDataStoreImpl(name, mcfg, writer_name)
36 8 : , m_sds_config{ mcfg ? mcfg->get_dal<DataStoreConfTestDeriv>(name) : nullptr }
37 17 : , m_derivval{ m_sds_config ? m_sds_config->get_derivval() : std::numeric_limits<int>::max() }
38 : {
39 8 : }
40 :
41 : void open_new_file(const std::string& unique_filename) override;
42 :
43 : // This getter function and its underlying member serve no purpose
44 : // other than to demonstrate how you can add parameters specific
45 : // to your implementation of DataStore
46 :
47 1 : int get_derivval() const { return m_derivval; }
48 :
49 : private:
50 : const DataStoreConfTestDeriv* m_sds_config;
51 : const int m_derivval;
52 : };
53 :
54 : inline void
55 27 : SummaryTextDataStore::open_new_file(const std::string& unique_filename)
56 : {
57 :
58 27 : auto& file_handle{ get_file_handle() };
59 27 : try {
60 27 : file_handle.reset(new dfmodules::SummaryTextDataWriter(unique_filename));
61 0 : } catch (std::exception const& excpt) {
62 0 : throw FileOperationProblem(ERS_HERE, get_name(), unique_filename, excpt);
63 0 : } catch (...) { // NOLINT(runtime/exceptions)
64 : // NOLINT here because we *ARE* re-throwing the exception!
65 0 : throw FileOperationProblem(ERS_HERE, get_name(), unique_filename);
66 0 : }
67 :
68 27 : TLOG_DEBUG(TLVL_BASIC) << get_name() << "Created stub file (" << unique_filename << ").";
69 27 : }
70 : } // namespace dunedaq::dfmodules
71 :
72 : #endif // DFMODULES_PLUGINS_SUMMARYTEXTDATASTORE_HPP_
|