ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
sources.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_dpm_merge
4  * @copyright ESO - European Southern Observatory
5  */
6 #include "sources.hpp"
7 
8 #include <fmt/format.h>
9 
10 namespace daq::dpm::merge {
11 
12 namespace base {
13 
14 KeywordRules::KeywordRules(std::optional<KeywordRuleProcessor::DefaultRule> const& initial,
15  std::unique_ptr<KeywordRuleProcessor> keyword_rules)
16  : m_initial(initial), m_processor(std::move(keyword_rules)) {
17 }
18 
19 Source::Source(std::string name) noexcept : m_name(std::move(name)) {
20 }
21 
22 FitsFile::FitsFile(std::filesystem::path path, fits::OpenMode mode)
23  : m_path(std::move(path)), m_fits(nullptr, fits::DefaultClose) {
24  auto entry = std::filesystem::directory_entry(m_path);
25  if (!entry.exists()) {
26  throw SourceNotFoundError(m_path.c_str());
27  }
28  if (mode == fits::OpenMode::ReadWrite && !entry.is_regular_file()) {
29  throw std::invalid_argument(
30  fmt::format("source path must be a regular file: '{}'", m_path.c_str()));
31  }
32  m_fits = fits::Open(m_path.c_str(), mode);
33 }
34 FitsFile::FitsFile(std::filesystem::path path, fits::UniqueFitsFile file)
35  : m_path(std::move(path)), m_fits(std::move(file)) {
36 }
37 
38 } // namespace base
39 
41  : std::invalid_argument(fmt::format("source path not found: '{}' ", path).c_str()) {
42 }
43 
44 TargetSource::TargetSource(std::string name,
45  std::filesystem::path path,
46  std::optional<KeywordRuleProcessor::DefaultRule> const& initial,
47  std::unique_ptr<KeywordRuleProcessor> keyword_rules)
48  : base::Source(std::move(name))
49  , base::FitsFile(std::move(path), fits::OpenMode::ReadWrite)
50  , base::KeywordRules(initial, std::move(keyword_rules)) {
51 }
52 
53 TargetSource::TargetSource(std::string name,
54  std::filesystem::path path,
55  std::optional<KeywordRuleProcessor::DefaultRule> const& initial,
56  std::unique_ptr<KeywordRuleProcessor> keyword_rules,
58  : base::Source(std::move(name))
59  , base::FitsFile(std::move(path), std::move(file))
60  , base::KeywordRules(initial, std::move(keyword_rules)) {
61 }
62 
64  std::filesystem::path path,
65  std::string location,
66  std::optional<KeywordRuleProcessor::DefaultRule> const& initial,
67  std::unique_ptr<KeywordRuleProcessor> keyword_rules)
68  : base::Source(std::move(name))
69  , base::FitsFile(std::move(path), fits::OpenMode::ReadOnly)
70  , base::KeywordRules(initial, std::move(keyword_rules))
71  , m_location(std::move(location)) {
72 }
73 
75  std::string name,
76  fits::KeywordVector keywords,
77  std::optional<KeywordRuleProcessor::DefaultRule> const& initial,
78  std::unique_ptr<KeywordRuleProcessor> keyword_rules) noexcept
79  : base::Source(std::move(name))
80  , base::KeywordRules(initial, std::move(keyword_rules))
81  , m_keywords(std::move(keywords)) {
82 }
83 
84 } // namespace daq::dpm::merge
FitsFileSource(std::string name, std::filesystem::path path, std::string location, std::optional< KeywordRuleProcessor::DefaultRule > const &initial_keywords, std::unique_ptr< KeywordRuleProcessor > keyword_rules)
Definition: sources.cpp:63
FitsKeywordsSource(std::string name, fits::KeywordVector keywords, std::optional< KeywordRuleProcessor::DefaultRule > const &initial_keywords, std::unique_ptr< KeywordRuleProcessor > keyword_rules) noexcept
Definition: sources.cpp:74
TargetSource(std::string name, std::filesystem::path path, std::optional< KeywordRuleProcessor::DefaultRule > const &initial_keywords, std::unique_ptr< KeywordRuleProcessor > keyword_rules)
Definition: sources.cpp:44
FitsFile(std::filesystem::path path, fits::OpenMode mode)
Open existing fits file.
Definition: sources.cpp:22
KeywordRules(std::optional< KeywordRuleProcessor::DefaultRule > const &initial, std::unique_ptr< KeywordRuleProcessor > keyword_rules)
Definition: sources.cpp:14
Source(std::string name) noexcept
Definition: sources.cpp:19
UniqueFitsFile Open(char const *filename, OpenMode mode)
Open file.
Definition: cfitsio.cpp:168
std::unique_ptr< fitsfile, void(*)(fitsfile *) noexcept > UniqueFitsFile
Defines unique ownership type to cfitsio fitsfile.
Definition: cfitsio.hpp:33
void DefaultClose(fitsfile *ptr) noexcept
Default close function that is used by UniqueFitsFile as a deleter.
Definition: cfitsio.cpp:100
std::vector< KeywordVariant > KeywordVector
Vector of keywords.
Definition: keyword.hpp:414
std::vector< KeywordRuleTypes > KeywordRules
Simple class that holds the source and associated state.
Definition: source.hpp:29
Source file not found.
Definition: sources.hpp:108
SourceNotFoundError(char const *path)
Definition: sources.cpp:40