Line data Source code
1 : /**
2 : * @file fileOpMonFacility.hpp
3 : *
4 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #ifndef OPMONLIB_PLUGIN_FILEOPMONFACILITY_HPP_
10 : #define OPMONLIB_PLUGIN_FILEOPMONFACILITY_HPP_
11 :
12 :
13 : #include <opmonlib/JSonOpMonFacility.hpp>
14 :
15 : #include <fstream>
16 : #include <mutex>
17 : #include <condition_variable>
18 :
19 : namespace dunedaq {
20 :
21 4 : ERS_DECLARE_ISSUE(opmonlib,
22 : BadFile,
23 : "Can not open file: " << filename,
24 : ((std::string)filename) )
25 :
26 2 : ERS_DECLARE_ISSUE(opmonlib,
27 : WritingFailed,
28 : "Failed to write. Message: " << message,
29 : ((std::string)message)
30 : )
31 :
32 2 : ERS_DECLARE_ISSUE(opmonlib,
33 : FacilityStopRequested,
34 : "Facility about to be destroyed and cannot write messages anymore.",
35 : ERS_EMPTY
36 : )
37 :
38 2 : ERS_DECLARE_ISSUE(opmonlib,
39 : FileClosedBeforeWritingComplete,
40 : "Facility was destroyed after " << milliseconds << " ms with " << counter << " entries yet to be written",
41 : ((uint16_t)milliseconds)((uint16_t)counter)
42 : )
43 :
44 :
45 : } // namespace dunedaq
46 :
47 : namespace dunedaq::opmonlib {
48 :
49 : class fileOpMonFacility
50 : : public JSonOpMonFacility {
51 :
52 : public:
53 : explicit fileOpMonFacility(std::string uri, OptionalOrigin);
54 : ~fileOpMonFacility();
55 :
56 : void publish(opmon::OpMonEntry && e) const override;
57 :
58 : private:
59 : void write(opmon::OpMonEntry && e) const noexcept;
60 :
61 : mutable std::ofstream m_ofs;
62 : mutable std::mutex m_mutex;
63 : mutable std::condition_variable m_writing_variable;
64 : mutable std::atomic<uint16_t> m_writing_counter{0};
65 : mutable std::atomic<bool> m_stop_request{false};
66 :
67 : };
68 :
69 : } // namespace dunedaq::opmonlib
70 :
71 :
72 : #endif // OPMONLIB_PLUGIN_FILEOPMONFACILITY_HPP_
|