File.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2002 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Kernel/Classes/dsp/File.h
10 
11 
12 #ifndef __File_h
13 #define __File_h
14 
15 #include "dsp/Seekable.h"
16 #include "Registry.h"
17 
18 namespace dsp {
19 
21 
33  class File : public Seekable
34  {
35  friend class SerialFiles;
36  friend class Multiplex;
37  friend class HoleyFile;
38  friend class RingBuffer;
39 
40  public:
41 
43 
45  static File* create (const char* filename);
46 
48  static File* create (const std::string& filename)
49  { return create (filename.c_str()); }
50 
52  File (const char* name);
53 
55  virtual ~File ();
56 
58 
60  virtual bool is_valid (const char* filename) const = 0;
61 
63  virtual void open (const char* filename);
64 
66  void open (const std::string& filename)
67  { open (filename.c_str()); }
68 
70  virtual void close ();
71 
73  virtual void reopen ();
74 
76  std::string get_filename () const { return current_filename; }
77  std::string get_current_filename() const { return current_filename; }
78 
80  virtual std::string get_data_filename () const;
81 
83  int get_header_bytes() const{ return header_bytes; }
84 
86  virtual bool contiguous (const File* that) const;
87 
90 
91  protected:
92 
94 
96  virtual void open_file (const char* filename) = 0;
97 
99 
102  virtual int64_t fstat_file_ndat(uint64_t tailer_bytes=0);
103 
105  virtual int64_t pad_bytes(unsigned char* buffer, int64_t bytes);
106 
111 
113  int fd;
114 
116  int header_bytes;
117 
119 
121  std::string current_filename;
122 
124  void * host_buffer = nullptr;
125 
127  uint64_t host_buffer_size = 0;
128 
130 
133  virtual int64_t load_bytes (unsigned char* buffer, uint64_t nbytes);
134 
135  virtual int64_t load_bytes_device (unsigned char* buffer, uint64_t bytes, void * device_handle);
136 
138 
143  virtual int64_t seek_bytes (uint64_t bytes);
144 
146  virtual void set_total_samples ();
147 
149  virtual void open_fd (const std::string& filename);
150 
152  static Register& get_register();
153 
154  private:
155 
157  void init();
158 
159 
160  };
161 
162 }
163 
164 #endif // !defined(__File_h)
165 
166 
Registry::List< File > Register
typedef used to simplify template syntax in File_registry.C
Definition: File.h:99
std::string current_filename
The name of the currently opened file, set by open()
Definition: File.h:131
virtual MJD get_end_time() const
Return the end time of the trailing edge of the last time sample.
Definition: Observation.C:521
int fd
The file descriptor.
Definition: File.h:123
virtual bool contiguous(const File *that) const
Return true this this is contiguous with that.
Definition: File.C:340
virtual bool is_valid(const char *filename) const =0
Return true if filename contains data in the recognized format.
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
virtual void reopen()
Reopen the file.
Definition: File.C:162
virtual Observation * get_info()
Get the information about the data source.
Definition: Input.h:113
static File * create(const char *filename)
Return a pointer to a new instance of the appropriate sub-class.
Definition: File.C:67
static bool verbose
Verbosity flag.
Definition: Observation.h:39
virtual std::string get_data_filename() const
For when the data file is not the current filename.
Definition: File.C:157
virtual int64_t fstat_file_ndat(uint64_t tailer_bytes=0)
Return ndat given the file and header sizes, nchan, npol, and ndim.
Definition: File.C:307
static Register & get_register()
Return the list of registered sub-classes.
Definition: File_registry.C:246
virtual void set_help_header(const std::string &s)
Loads BitSeries data from file.
Definition: File.h:38
virtual void set_total_samples()
Calculates the total number of samples in the file, based on its size.
Definition: File.C:184
virtual void close()
Close the file.
Definition: File.C:145
std::string name
Operation name.
Definition: Operation.h:153
Parent * create(unsigned i) const
virtual void open_file(const char *filename)=0
Open the file specified by filename for reading.
virtual void open(const char *filename)
Open the file.
Definition: File.C:120
Stores information about digital, band-limited, time-varying signals.
Definition: Observation.h:33
uint64_t host_buffer_size
The size of the host_buffer in bytes.
Definition: File.h:137
virtual int64_t seek_bytes(uint64_t bytes)
Set the file pointer to the absolute number of sampled data bytes.
Definition: File.C:283
void * host_buffer
staging buffer for Host to Device transfers
Definition: File.h:134
virtual int64_t pad_bytes(unsigned char *buffer, int64_t bytes)
Over-ride this function to pad data via HoleyFile.
Definition: File.C:334
unsigned size() const
File(const char *name)
Constructor.
Definition: File.C:34
static bool verbose
Global verbosity flag.
Definition: Operation.h:48
virtual void add(Item *)
virtual void set_version(const std::string &s)
virtual int64_t load_bytes(unsigned char *buffer, uint64_t nbytes)
Load nbyte bytes of sampled data from the device into buffer.
Definition: File.C:190
int get_header_bytes() const
Inquire how many bytes are in the header.
Definition: File.h:93
Pure virtual base class of sources that can seek through data.
Definition: Seekable.h:29
std::string get_filename() const
Return the name of the file from which this instance was created.
Definition: File.h:86
const std::string get_message() const
MJD get_start_time() const
Return the start time of the leading edge of the first time sample.
Definition: Observation.h:152
virtual void parse(int argc, char *const *argv)
virtual ~File()
Destructor.
Definition: File.C:45
int header_bytes
The size of the header in bytes.
Definition: File.h:126
virtual void open_fd(const std::string &filename)
Utility opens the file descriptor.
Definition: File.C:176
virtual int64_t load_bytes_device(unsigned char *buffer, uint64_t bytes, void *device_handle)
The file descriptor.
Definition: File.C:221

Generated using doxygen 1.8.17