ifw-daq  2.1.0-pre1
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::unique_ptr<KeywordRuleProcessor> processor)
15  : m_processor(std::move(processor)) {
16 }
17 
18 Source::Source(std::string name) noexcept : m_name(std::move(name)) {
19 }
20 
21 FitsFile::FitsFile(std::filesystem::path path, fits::OpenMode mode)
22  : m_path(std::move(path)), m_fits(nullptr, fits::DefaultClose) {
23  auto entry = std::filesystem::directory_entry(m_path);
24  if (!entry.exists()) {
25  throw SourceNotFoundError(m_path.c_str());
26  }
27  if (mode == fits::OpenMode::ReadWrite && !entry.is_regular_file()) {
28  throw std::invalid_argument(
29  fmt::format("source path must be a regular file: '{}'", m_path.c_str()));
30  }
31  m_fits = fits::Open(m_path.c_str(), mode);
32 }
33 FitsFile::FitsFile(std::filesystem::path path, fits::UniqueFitsFile file)
34  : m_path(std::move(path)), m_fits(std::move(file)) {
35 }
36 
37 } // namespace base
38 
40  : std::invalid_argument(fmt::format("source path not found: '{}' ", path).c_str()) {
41 }
42 
43 TargetSource::TargetSource(std::string name,
44  std::filesystem::path path,
45  std::unique_ptr<KeywordRuleProcessor> keyword_rules)
46  : base::Source(std::move(name))
47  , base::FitsFile(std::move(path), fits::OpenMode::ReadWrite)
48  , base::KeywordRules(std::move(keyword_rules)) {
49 }
50 
51 TargetSource::TargetSource(std::string name,
52  std::filesystem::path path,
53  std::unique_ptr<KeywordRuleProcessor> keyword_rules,
55  : base::Source(std::move(name))
56  , base::FitsFile(std::move(path), std::move(file))
57  , base::KeywordRules(std::move(keyword_rules)) {
58 }
59 
61  std::filesystem::path path,
62  std::string origin,
63  std::unique_ptr<KeywordRuleProcessor> keyword_rules)
64  : base::Source(std::move(name))
65  , base::FitsFile(std::move(path), fits::OpenMode::ReadOnly)
66  , base::KeywordRules(std::move(keyword_rules))
67  , m_origin(std::move(origin)) {
68 }
69 
71  fits::KeywordVector keywords,
72  std::unique_ptr<KeywordRuleProcessor> keyword_rules) noexcept
73  : base::Source(std::move(name))
74  , base::KeywordRules(std::move(keyword_rules))
75  , m_keywords(std::move(keywords)) {
76 }
77 
78 } // namespace daq::dpm::merge
daq::dpm::merge::base::Source::Source
Source(std::string name) noexcept
Definition: sources.cpp:18
daq::dpm::merge::base::KeywordRules
Represents the keyword rules from the Data Product Specification.
Definition: sources.hpp:86
daq::Source
Simple class that holds the source and associated state.
Definition: source.hpp:29
daq::dpm::merge::SourceNotFoundError
Source file not found.
Definition: sources.hpp:102
daq::fits::Open
UniqueFitsFile Open(char const *filename, OpenMode mode)
Open file.
Definition: cfitsio.cpp:168
daq::fits::UniqueFitsFile
std::unique_ptr< fitsfile, void(*)(fitsfile *) noexcept > UniqueFitsFile
Defines unique ownership type to cfitsio fitsfile.
Definition: cfitsio.hpp:32
daq::dpm::merge::base::Source
Base source.
Definition: sources.hpp:25
daq::fits::OpenMode::ReadOnly
@ ReadOnly
daq::fits::OpenMode
OpenMode
Definition: cfitsio.hpp:25
daq::dpm::merge::base::FitsFile::FitsFile
FitsFile(std::filesystem::path path, fits::OpenMode mode)
Open existing fits file.
Definition: sources.cpp:21
daq::dpm::merge::SourceNotFoundError::SourceNotFoundError
SourceNotFoundError(char const *path)
Definition: sources.cpp:39
daq::dpm::merge
Definition: entrypoint.cpp:26
daq::dpm::merge::TargetSource::TargetSource
TargetSource(std::string name, std::filesystem::path path, std::unique_ptr< KeywordRuleProcessor > keyword_rules)
Definition: sources.cpp:43
daq::fits::KeywordVector
std::vector< KeywordVariant > KeywordVector
Vector of keywords.
Definition: keyword.hpp:414
daq::fits::DefaultClose
void DefaultClose(fitsfile *ptr) noexcept
Default close function that is used by UniqueFitsFile as a deleter.
Definition: cfitsio.cpp:100
daq::dpm::merge::FitsFileSource::FitsFileSource
FitsFileSource(std::string name, std::filesystem::path path, std::string origin, std::unique_ptr< KeywordRuleProcessor > keyword_rules)
Definition: sources.cpp:60
daq::dpm::merge::base::KeywordRules::KeywordRules
KeywordRules(std::unique_ptr< KeywordRuleProcessor > keyword_rules)
Definition: sources.cpp:14
daq::dpm::merge::FitsKeywordsSource::FitsKeywordsSource
FitsKeywordsSource(std::string name, fits::KeywordVector keywords, std::unique_ptr< KeywordRuleProcessor > keyword_rules) noexcept
Definition: sources.cpp:70
sources.hpp