CARMA C++
ArchiveFileHandler.h
Go to the documentation of this file.
1 // $Id: ArchiveFileHandler.h,v 1.2 2011/11/01 23:04:24 eml Exp $
2 
3 #ifndef SZA_UTIL_ARCHIVEFILEHANDLER_H
4 #define SZA_UTIL_ARCHIVEFILEHANDLER_H
5 
17 
18 #include "carma/szaarrayutils/archive.h"
19 #include "carma/szaarrayutils/arraymap.h"
20 #include "carma/szaarrayutils/monitor_stream.h"
21 #include "carma/szaarrayutils/netbuf.h"
22 #include "carma/szaarrayutils/netobj.h"
23 
24 #include <iostream>
25 
26 namespace sza {
27  namespace util {
28 
29  class ArchiveFileHandler : public FileHandler {
30  public:
31 
35  ArchiveFileHandler();
36 
40  ArchiveFileHandler(const ArchiveFileHandler& objToBeCopied);
41 
45  ArchiveFileHandler(ArchiveFileHandler& objToBeCopied);
46 
50  void operator=(const ArchiveFileHandler& objToBeAssigned);
51 
55  void operator=(ArchiveFileHandler& objToBeAssigned);
56 
60  friend std::ostream& operator<<(std::ostream& os, ArchiveFileHandler& obj);
61 
65  virtual ~ArchiveFileHandler();
66 
67  // Open the file for reading. If memMap = true, the file will
68  // be memory-mapped
69 
70  void openForRead(bool memMap=false);
71 
72  ArrayMap* getArrayMap() {
73  return arrayMap_;
74  }
75 
76  private:
77 
78  ArrayMap* arrayMap_; // The register map of the archive file
79  sza::array::NetReadStr* nrs_; // The file input stream
80  int nrsSize_; // The size of the input stream buffer
81  int lastArrayMapSize_; // The last size read
82 
83  unsigned nFramesInFile_;
84 
85  // The number of header bytes in each msg in the file
86 
87  unsigned nBytesInMsgHeader_;
88 
89  // The total number of bytes in the head of the file (before the
90  // register frames begin)
91 
92  unsigned nBytesInFileHeader_;
93 
94  // The total number of bytes in each frame in the file. Note
95  // that this is larger than the number of bytes in the array map
96  // by nBytesInMsgHeader_
97 
98  unsigned nBytesInFrameMsg_;
99 
100  // The offset in bytes of the register array.frame.utc from the
101  // head of the array map
102 
103  unsigned offsetInBytesOfFrameUtcInArrayMap_;
104 
105  // Initialize the net read stream
106 
107  void initializeNetReadStr();
108 
109  // Get the next message from the file
110 
111  sza::array::MsReadState readNextMsg();
112 
113  // Read the arraymap from the file
114 
115  void readArrayMap();
116 
117  // Get the maximum buffer size from the file
118 
119  bool readSize();
120 
121  public:
122 
123  void readTimestamps();
124 
125  void advanceToFrame(unsigned iFrame, off_t offset=0);
126 
127  // Return the MJD of the specified frame
128 
129  double getMjd(unsigned iFrame);
130 
131  // Binary searches for the first frame in the file before/after the
132  // specified date
133 
134  unsigned findFirstFrameBefore(std::string date);
135  unsigned findFirstFrameAfter(std::string date);
136 
137  // Return the total number of frames in this file
138 
139  unsigned nFrame();
140 
141  }; // End class ArchiveFileHandler
142 
143  } // End namespace util
144 } // End namespace sza
145 
146 
147 
148 #endif // End #ifndef SZA_UTIL_ARCHIVEFILEHANDLER_H
Tagged: Thu Jan 29 22:24:18 NZDT 2009.