Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SigProcWriter.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef SKA_CHEETAH_SIGPROC_SIGPROCWRITER_H
25 #define SKA_CHEETAH_SIGPROC_SIGPROCWRITER_H
26 
27 #include "pss/astrotypes/sigproc/Header.h"
28 #include "cheetah/sigproc/WriterConfig.h"
29 #include "cheetah/data/TimeFrequency.h"
30 #include "cheetah/data/Spectrum.h"
31 #include <boost/filesystem.hpp>
32 #include <fstream>
33 
34 namespace ska {
35 namespace cheetah {
36 namespace sigproc {
37 
44 template<typename HeaderType=pss::astrotypes::sigproc::Header>
46 {
47  public:
49  SigProcWriter(std::string const& directory);
50  SigProcWriter(boost::filesystem::path const& directory);
51  virtual ~SigProcWriter();
52 
59  template<typename Arch, typename NumericalRep>
60  SigProcWriter& operator<<(data::TimeFrequency<Arch, NumericalRep> const& tf);
61 
62  template<typename DerivedType, typename NumericalRep, typename Alloc>
63  SigProcWriter& operator<<(data::SpectrumBase<DerivedType, NumericalRep, Alloc> const& spectrum_data);
64 
68  void flush();
69 
73  template<typename Arch, typename NumericalRep>
74  static void fill_header(HeaderType& header, data::TimeFrequency<Arch, NumericalRep> const& tf);
75 
79  template<typename T>
80  typename std::enable_if<pss::astrotypes::has_exact_dimensions<T, data::Time, data::Frequency>::value, SigProcWriter&>::type
81  write(HeaderType const&, T const& t);
82 
83 
84  private:
85  void set_dir(boost::filesystem::path const& path);
86  std::string next_file(data::TimeFrequency<Cpu, uint8_t>::TimePointType const&);
87 
88  void file_header(HeaderType const&);
89 
90  template<typename T>
91  typename std::enable_if<pss::astrotypes::has_exact_dimensions<T, data::Time, data::Frequency>::value, SigProcWriter&>::type
92  file_write(HeaderType const&, T const& t, std::size_t spectrum=0);
93 
94  template<typename T>
95  typename std::enable_if<pss::astrotypes::has_exact_dimensions<T, data::Frequency>::value, SigProcWriter&>::type
96  file_write(HeaderType const&, T const& t);
97 
98  private:
99  boost::filesystem::path _dir;
100  HeaderType _header;
101  std::ofstream _file_stream;
102  std::string _extension;
103  std::size_t _sample_count;
104  std::size_t _max_samples_per_file;
105 };
106 
107 } // namespace sigproc
108 } // namespace cheetah
109 } // namespace ska
110 #include "cheetah/sigproc/detail/SigProcWriter.cpp"
111 
112 #endif // SKA_CHEETAH_SIGPROC_SIGPROCWRITER_H
Configuration options for a SigProcWriter.
Definition: WriterConfig.h:41
Some limits and constants for FLDO.
Definition: Brdz.h:35
void flush()
close any existing data files
std::enable_if< pss::astrotypes::has_exact_dimensions< T, data::Time, data::Frequency >::value, SigProcWriter & >::type write(HeaderType const &, T const &t)
write the data out to file using the meta data from the header provided
Writes data types to a sigproc format file.
Definition: SigProcWriter.h:45
static void fill_header(HeaderType &header, data::TimeFrequency< Arch, NumericalRep > const &tf)
fill the sigproc header object with meta data taken from the TimeFrequency object ...