My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
ArchiveFileHandler.h
Go to the documentation of this file.
1 // $Id: ArchiveFileHandler.h,v 1.1.1.1 2009/07/06 23:57:24 eml Exp $
2 
3 #ifndef GCP_UTIL_ARCHIVEFILEHANDLER_H
4 #define GCP_UTIL_ARCHIVEFILEHANDLER_H
5 
16 #include "gcp/util/common/FileHandler.h"
17 
18 #include "gcp/control/code/unix/libunix_src/common/archive.h"
19 #include "gcp/control/code/unix/libunix_src/common/arraymap.h"
20 #include "gcp/control/code/unix/libmonitor_src/monitor_stream.h"
21 #include "gcp/control/code/unix/libunix_src/common/netbuf.h"
22 #include "gcp/control/code/unix/libunix_src/common/netobj.h"
23 
24 #include <iostream>
25 
26 namespace gcp {
27  namespace util {
28 
30  public:
31 
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  gcp::control::NetReadStr* nrs_; // The file input stream
80  int nrsSize_; // The size of the input stream buffer
81  unsigned nFramesInFile_;
82 
83  // The number of header bytes in each msg in the file
84 
85  unsigned nBytesInMsgHeader_;
86 
87  // The total number of bytes in the head of the file (before the
88  // register frames begin)
89 
90  unsigned nBytesInFileHeader_;
91 
92  // The total number of bytes in each frame in the file. Note
93  // that this is larger than the number of bytes in the array map
94  // by nBytesInMsgHeader_
95 
96  unsigned nBytesInFrameMsg_;
97 
98  // The offset in bytes of the register array.frame.utc from the
99  // head of the array map
100 
101  unsigned offsetInBytesOfFrameUtcInArrayMap_;
102 
103  // Initialize the net read stream
104 
105  void initializeNetReadStr();
106 
107  // Get the next message from the file
108 
109  gcp::control::MsReadState readNextMsg();
110 
111  // Read the arraymap from the file
112 
113  void readArrayMap();
114 
115  // Get the maximum buffer size from the file
116 
117  void readSize();
118 
119  public:
120 
121  void readTimestamps();
122 
123  void advanceToFrame(unsigned iFrame, off_t offset=0);
124 
125  // Return the MJD of the specified frame
126 
127  double getMjd(unsigned iFrame);
128 
129  // Binary searches for the first frame in the file before/after the
130  // specified date
131 
132  unsigned findFirstFrameBefore(std::string date);
133  unsigned findFirstFrameAfter(std::string date);
134 
135  // Return the total number of frames in this file
136 
137  unsigned nFrame();
138 
139  }; // End class ArchiveFileHandler
140 
141  } // End namespace util
142 } // End namespace gcp
143 
144 
145 
146 #endif // End #ifndef GCP_UTIL_ARCHIVEFILEHANDLER_H
Definition: ArchiveFileHandler.h:29
unsigned findFirstFrameAfter(std::string date)
Definition: ArchiveFileHandler.cc:351
virtual ~ArchiveFileHandler()
Definition: ArchiveFileHandler.cc:72
ArchiveFileHandler()
Definition: ArchiveFileHandler.cc:18
void advanceToFrame(unsigned iFrame, off_t offset=0)
Definition: ArchiveFileHandler.cc:270
unsigned findFirstFrameBefore(std::string date)
Definition: ArchiveFileHandler.cc:309
void openForRead(bool memMap=false)
Definition: ArchiveFileHandler.cc:88
Definition: FileHandler.h:23
void operator=(const ArchiveFileHandler &objToBeAssigned)
Definition: ArchiveFileHandler.cc:47
Definition: netbuf.h:129
friend std::ostream & operator<<(std::ostream &os, ArchiveFileHandler &obj)
Definition: arraymap.h:177
double getMjd(unsigned iFrame)
Definition: ArchiveFileHandler.cc:295