astrotypes  0.0
Header.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
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 PSS_ASTROTYPES_SIGPROC_HEADER_H
25 #define PSS_ASTROTYPES_SIGPROC_HEADER_H
26 
27 #include "HeaderField.h"
29 #include "detail/HeaderBase.h"
36 
37 namespace pss {
38 namespace astrotypes {
39 namespace sigproc {
40 
73 class Header : public HeaderBase<Header>
74 {
75  private:
76  typedef HeaderBase<Header> BaseT;
77  typedef Header SelfType;
78 
79  template<typename T>
80  class OStreamAdapter {
81  public:
82  OStreamAdapter(Header const& h, T const& data);
83  std::ostream& operator<<(std::ostream& os) const;
84  private:
85  Header const& _h;
86  T const& _d;
87  };
88 
89  friend class HeaderFieldBase;
90 
91  template<typename T>
92  friend class HeaderFieldDataType;
93 
94  public:
97 
98  enum class DataType {
99  Undefined = 0,
100  FilterBank = 1, // stored as a series of spectra
101  TimeSeries // stored as a series of channels
102  };
103 
104  public:
105  Header();
106  Header(Header const&);
107  virtual ~Header() {};
108 
109  Header& operator=(Header const&);
110 
115 
119  void telescope_id(unsigned id);
120 
125 
130  void machine_id(unsigned id);
131 
135  void data_type(DataType type);
136 
140  DataType data_type() const;
141 
146 
151  void raw_data_file(std::string const& name);
152 
157 
161  void source_name(std::string const& name);
162 
166  utils::Optional<unsigned> const& barycentric() const;
167  void barycentric(bool barycentric);
168 
173  void pulsarcentric(bool pulsarcentric);
174 
179  void az_start(boost::units::quantity<units::Degree, double> const&);
180 
185  void za_start(boost::units::quantity<units::Degree, double> const&);
186 
191 
195  void tstart(units::ModifiedJulianDate const&);
196 
200  boost::units::quantity<units::Seconds, double> sample_interval() const;
201 
205  void sample_interval(boost::units::quantity<units::Seconds, double>);
206 
212 
218  void fch1(boost::units::quantity<units::MegaHertz, double> const&);
219 
225 
231  void foff(boost::units::quantity<units::MegaHertz, double> const&);
232 
238  std::vector<boost::units::quantity<units::MegaHertz, double>> const& frequency_channels() const;
239 
244  void frequency_channels(std::vector<boost::units::quantity<units::MegaHertz, double>> const& frequency_channels);
245 
250 
254  void number_of_channels(std::size_t);
256 
260  unsigned number_of_bits() const;
261 
265  void number_of_bits(unsigned);
266 
274 
279  void number_of_samples(unsigned);
280 
285  unsigned number_of_ifs() const;
286 
290  void number_of_ifs(unsigned);
291 
297 
303 
308 
313  void period(boost::units::quantity<units::Seconds, double>);
314 
320 
326 
330  template<typename T, typename Alloc>
331  SelfType& operator>>(astrotypes::FrequencyTime<T, Alloc> const&) const;
332 
336  template<typename T, typename Alloc>
337  SelfType& operator>>(astrotypes::TimeFrequency<T, Alloc> const&) const;
338 
342  template<typename T, typename Alloc>
343  SelfType& operator<<(astrotypes::FrequencyTime<T, Alloc> const&) const;
344 
348  template<typename T, typename Alloc>
349  OStreamAdapter<astrotypes::TimeFrequency<T, Alloc>> operator<<(astrotypes::TimeFrequency<T, Alloc> const&);
350 
354  void info(std::ostream& stream) const;
355 
356  protected:
357  void updated_data_type();
358 
359  private:
360  // standard header data fields
361  HeaderField<unsigned> _telescope_id;
362  HeaderField<unsigned> _machine_id;
364  HeaderField<std::string> _raw_data_file;
365  HeaderField<std::string> _source_name;
366  HeaderField<unsigned> _barycentric;
367  HeaderField<unsigned> _pulsarcentric;
370  HeaderField<double> _src_raj; // right ascension (J2000) of source (hhmmss.s)
371  HeaderField<double> _src_dej; // declination (J2000) of source (ddmmss.s)
372  HeaderField<boost::units::quantity<units::Seconds, double>> _tsamp; // sample time (in seconds)
374  HeaderField<unsigned> _n_bits;
375  HeaderField<unsigned> _nsamples;
378  HeaderField<std::vector<boost::units::quantity<units::MegaHertz, double>>> _freq_channels; // each bin assigned its own value
379  HeaderField<unsigned> _n_chans;
380  HeaderField<unsigned> _nifs; // number of seperate IF channels
381  HeaderField<units::DispersionMeasure<double>> _refdm; // parsecs_per_cm_cubed
382  HeaderField<boost::units::quantity<units::Seconds, double>> _period; // folding period seconds
383 
384  // these fielde are not standard but added here to allow parsing
385  HeaderField<unsigned> _ibeam; // the beam index
386  HeaderField<unsigned> _nbeams; // the total number of beams in the observation
387 };
388 
389 template<typename Stream>
390 Header::InfoSentry<Stream> operator<<(Stream& os, Header::Info const&);
391 
392 } // namespace sigproc
393 } // namespace astrotypes
394 } // namespace pss
395 #include "detail/Header.cpp"
396 
397 #endif // PSS_ASTROTYPES_SIGPROC_HEADER_H
class to provide a virtual lookup table for read/write the varoious types of SigProcVariables ...
Definition: HeaderField.h:44
boost::units::quantity< units::Seconds, double > sample_interval() const
return the sample_interval (if defined)
Definition: Header.cpp:271
unsigned number_of_ifs() const
return the number of IF streams (e.g. polarisations) in each channel
Definition: Header.cpp:374
unsigned number_of_bits() const
return the number of bits
Definition: Header.cpp:348
utils::Optional< unsigned > const & number_of_samples() const
return the number of time samples (optional)
Definition: Header.cpp:359
utils::Optional< unsigned > nbeams() const
return the number of beams used in an abservation
Definition: Header.cpp:385
utils::Optional< boost::units::quantity< units::Seconds, double > > const & period() const
return the folding period (if defined)
Definition: Header.cpp:322
utils::Optional< std::string > const & source_name() const
return the value of the source name (if any)
Definition: Header.cpp:211
Store SigProc header information.
Definition: Header.h:73
utils::Optional< std::string > const & raw_data_file() const
return the value of the raw data filename (if any)
Definition: Header.cpp:167
utils::Optional< unsigned > const & barycentric() const
the value of the barycentric field (if any)
Definition: Header.cpp:221
DataType data_type() const
set the data type
Definition: Header.cpp:200
Specilist class for the sigproc data type variable.
boost::units::quantity< DispersionMeasureUnit, T > DispersionMeasure
utils::Optional< boost::units::quantity< units::Degree, double > > az_start() const
getters/setters for the telscope azimuth at start of scan (in degrees)
Definition: Header.cpp:241
Store SigProc header information.
Definition: HeaderBase.h:69
std::vector< boost::units::quantity< units::MegaHertz, double > > const & frequency_channels() const
return a list of frequency channels (if set)
Definition: Header.cpp:302
utils::Optional< unsigned > telescope_id() const
return the telescope_id identifier (if any)
Definition: Header.cpp:147
DimensionSize< units::Frequency > number_of_channels() const
return the number of frequency channels
Definition: Header.cpp:332
SelfType & operator<<(astrotypes::FrequencyTime< T, Alloc > const &) const
read header data from the provided object
SelfType & operator>>(astrotypes::FrequencyTime< T, Alloc > const &) const
write header data to the provided object, resizing appropriately
utils::Optional< boost::units::quantity< units::MegaHertz, double > > const & fch1() const
get the frequency of the first channel
Definition: Header.cpp:282
A template class representing values associated with a time and frequecny such as Stokes values or vo...
A template class representing values associated with a time and frequecny such as Stokes values or vo...
Header & operator=(Header const &)
Definition: Header.cpp:118
utils::Optional< unsigned > machine_id() const
return the machine_id identifier (if any)
Definition: Header.cpp:157
utils::Optional< unsigned > ibeam() const
return the beam index number
Definition: Header.cpp:380
utils::Optional< boost::units::quantity< units::MegaHertz, double > > const & foff() const
get the band width of a channel (assumes homogenous badwidth for each channel)
Definition: Header.cpp:292
utils::Optional< units::ModifiedJulianDate > const & tstart() const
return the date of the start of the data block
Definition: Header.cpp:261
utils::Optional< boost::units::quantity< units::Degree, double > > za_start() const
getters/setters for the telscope zenith at start of scan (in degrees)
Definition: Header.cpp:251
utils::Optional< units::DispersionMeasure< double > > const & ref_dm() const
return the reference Dispersion Measure
Definition: Header.cpp:312
Header::InfoSentry< Stream > operator<<(Stream &os, Header::Info const &adapter)
Definition: Header.cpp:397
void info(std::ostream &stream) const
human readable summary of the header written to the stream
Definition: Header.cpp:391
ModifiedJulianClock::time_point ModifiedJulianDate
Definition: Time.h:46
utils::Optional< unsigned > const & pulsarcentric() const
the value of the pulsarcentric field (if any)
Definition: Header.cpp:231