framefast/framefast.hh

00001 /*----------------------------------------------------------------------*/
00002 /*                                                                      */
00003 /* Module Name: framefast                                               */
00004 /*                                                                      */
00005 /* Module Description: Frame reader using TOC for fast access           */
00006 /*                                                                      */
00007 /* Revision History:                                                    */
00008 /* Rel   Date     Programmer    Comments                                */
00009 /* 0.1   26Sep00  D. Sigg       First release                           */
00010 /*                                                                      */
00011 /* Documentation References:                                            */
00012 /*      Man Pages: framefast.html                                       */
00013 /*      References: none                                                */
00014 /*                                                                      */
00015 /* Author Information:                                                  */
00016 /* Name          Telephone       Fax             e-mail                 */
00017 /* Daniel Sigg   (509) 372-8132  (509) 372-8137  sigg_d@ligo.mit.edu    */
00018 /*                                                                      */
00019 /*                                                                      */
00020 /*                      -------------------                             */
00021 /*                                                                      */
00022 /*                             LIGO                                     */
00023 /*                                                                      */
00024 /*        THE LASER INTERFEROMETER GRAVITATIONAL WAVE OBSERVATORY.      */
00025 /*                                                                      */
00026 /*                     (C) The LIGO Project, 1999.                      */
00027 /*                                                                      */
00028 /*                                                                      */
00029 /* Caltech                              MIT                             */
00030 /* LIGO Project MS 51-33                LIGO Project NW-17 161          */
00031 /* Pasadena CA 91125                    Cambridge MA 01239              */
00032 /*                                                                      */
00033 /* LIGO Hanford Observatory             LIGO Livingston Observatory     */
00034 /* P.O. Box 1970 S9-02                  19100 LIGO Lane Rd.             */
00035 /* Richland WA 99352                    Livingston, LA 70754            */
00036 /*                                                                      */
00037 /*----------------------------------------------------------------------*/
00038 
00039 #ifndef _LIGO_FRAMEFAST_H
00040 #define _LIGO_FRAMEFAST_H
00041 
00042 
00043 #include <iosfwd>
00044 #include <deque>
00045 #include <vector>
00046 #include "Time.hh"
00047 #include "Interval.hh"
00048 #include "framefast/frametype.hh"
00049 #include "framefast/frameio.hh"
00050 
00051 #if defined(__SUNPRO_CC) && defined(G__DICTIONARY)
00052    namespace framefast {}
00053    using namespace framefast;
00054 #endif
00055 
00056 
00057 
00058 namespace framefast {
00059 
00081    class framereader {
00082    private:
00083       framereader (const framereader&);
00084       framereader& operator= (const framereader&);
00085    
00086    public:
00090       framereader ();
00094       virtual ~framereader();
00095    
00103       bool loadFile (const char* filename, bool map = true);
00111       bool loadFrame (const void* fdata, int len, bool ownit = false);
00118       bool loadFrame (basic_frame_storage* frame) {
00119          frame_storage_ptr ptr (frame); 
00120          return loadFrame (ptr); }
00127       bool loadFrame (frame_storage_ptr& frame) {
00128          fFrame = frame;
00129          return (fFrame.data() != 0); }
00136       bool releaseFrame (frame_storage_ptr& frame);
00137    
00142       void unload ();
00143    
00148       bool isFrame ();
00149    
00155       bool getDict (dict_t& dict);
00156    
00163       bool getFrameHeader (frameheader_t& h, int fnum = 0);
00164    
00172       bool getDetectorInfo (detector_t& det, int fnum = 0, int dnum = 0);
00177       int getDetectorInfoNum();
00178    
00185       bool getHistoryInfo (hist_t& hist, int fnum = 0);
00186    
00193       bool getRawDataInfo (rawdata_t& raw, int fnum = 0);
00194    
00203       bool getData (data_t& dat, int_8u_t pos, datatype_t dtype,
00204                    frvect_t::datacopy cpy = frvect_t::fv_copy);
00205    
00214       bool getData (data_t& dat, const char* channel, int nframe = 0,  
00215                    frvect_t::datacopy cpy = frvect_t::fv_copy);
00216    
00231       int copy (const char* chnname, real_4_t* x, int max);
00232 
00247       int copy (const char* chnname, real_8_t* x, int max);
00248 
00263       int copy (const char* chnname, int_2s_t* x, int max);
00264 
00279       int copy (const char* chnname, int_4s_t* x, int max);
00280    
00286       std::ostream& writeTOC (std::ostream& os);
00287    
00293       std::ostream& writeFileHeader (std::ostream& os);
00294    
00299       int length() const {
00300          return fFrame.size(); }
00305       const char* frame() const {
00306          return fFrame.data(); }
00311       const char* frameend() const {
00312          return frame() + length(); }
00317       const char* fname() const {
00318          return fFrame.name(); }
00325       std::string guessFilename();
00326    
00331       int nframe();
00337       Time starttime (int framenum = 0);
00343       Interval duration (int framenum = 0);
00348       Time nexttime ();
00353       const toc_t* getTOC();
00358       void setScanTOC (bool set = true) {
00359          fForceScanToc = set; }
00360    
00361    protected:
00363       enum toc_status_t {
00365       kTOCUndefined = 0,
00367       kTOCNo,
00369       kTOCYes
00370       };
00372       enum header_status_t {
00374       kFileHeaderUndefined = 0,
00376       kFileHeaderInvalid,
00378       kFileHeaderValid
00379       };
00380    
00382       bool              fDebug;
00384       frame_storage_ptr fFrame;
00386       toc_t*            fTOC;
00388       toc_status_t      fHasTOC;
00390       bool              fForceScanToc;
00392       fileheader_t*     fFileHeader;
00394       header_status_t   fHasFileHeader;
00396       frameheader_t*    fFrameHeader;
00398       bool              fSwap;
00399    
00401       bool newTOC();
00403       bool freeTOC();
00405       bool readTOC();
00407       bool scanTOC();
00408    
00410       bool newFileHeader();
00412       bool freeFileHeader();
00414       bool readFileHeader();
00415    
00417       int lookup (const char* chnname, int_8u_t*& ofs, datatype_t& dtype);
00418    };
00419 
00420 
00427    std::ostream& operator<< (std::ostream& os, const framereader& fr);
00428 
00429 
00436    class framewriter {
00437    private:
00438       framewriter (const framewriter&);
00439       framewriter& operator= (const framewriter&);
00440    
00441    public:
00443       enum framepos {
00445       framebegin = 0,
00447       framebusy,
00449       framebreak,
00451       frameend
00452       };
00453    
00455       class framebuffer_t {
00456       public:
00458          explicit framebuffer_t (int size = 0);
00460          framebuffer_t (const framebuffer_t& buf);
00462          ~framebuffer_t ();
00464          framebuffer_t& operator= (const framebuffer_t& buf);
00466          bool allocate (int size);
00468          void deallocate ();
00469       
00471          const char* data() const {
00472             return fData; }
00474          char* pos() const {
00475             return fData ? fData + fLen : 0; }
00477          int len() const {
00478             return fLen; }
00480          int size() const {
00481             return fSize; }
00483          void expand (int len) {
00484             fLen += len; }
00485       protected:
00487          int            fLen;
00489          int            fSize;
00491          char*          fData;
00493          mutable bool   fOwn;
00494       };
00496       typedef std::deque<framebuffer_t> framebufferlist;
00498       typedef std::vector<detector_t> detector_array_t;
00499    
00500    
00508       explicit framewriter (int nFrameLen = 1, int nFrame = 1,
00509                         int compress = 0, 
00510                         int version = kDefaultFrameVersion);
00514       ~framewriter ();
00515    
00520       framepos status() {
00521          return fFramePos; }
00530       bool setFormat (int nFrameLen = 1, int nFrame = 1, 
00531                      int compress = 0,
00532                      int version = kDefaultFrameVersion);
00537       int frameLength () const {
00538          return fFrameLen; }
00544       bool setTime (const Time& time);
00545    
00551       bool setDetectorInfo (const detector_t& det);
00557       bool addDetectorInfo (const detector_t& det);
00563       const detector_t* getDetectorInfo (int dnum = 0) const {
00564          return ((dnum >= 0) && (dnum < (int)fDetector.size())) ?
00565             &fDetector[0] : 0; }
00570       const toc_t* getTOC () const {
00571          return &fTOC; }
00576       int nframe() const;
00582       Time starttime (int framenum = 0) const;
00588       Interval duration (int framenum = 0) const;
00593       Time nexttime () const;
00594    
00601       bool addData (const adcdata_t& adc, const frvect_t& vect);
00602    
00612       bool next();
00613 
00624       bool next (const Time& nextframe);
00625    
00631       bool write (basic_frameout* out);
00638       bool getBuffers (framebufferlist& bufs) {
00639          bufs = fFrameBuffer; purge(); 
00640          return true; }
00641    
00646       int buffers() const {
00647          return fFrameBuffer.size(); }
00653       const char* framebuffer (int buffer) const {
00654          return ((buffer >= 0) && (buffer < (int)fFrameBuffer.size())) ? 
00655             fFrameBuffer[buffer].data() : 0; }
00661       int bufferlen (int buffer) const {
00662          return ((buffer >= 0) && (buffer < (int)fFrameBuffer.size())) ? 
00663             fFrameBuffer[buffer].len() : 0; }
00668       int total() const {
00669          return fTotal; }
00673       void purge () {
00674          fFrameBuffer.clear(); }
00675    
00680       void setFilename (const char* filename) {
00681          fFilename = filename; }
00686       const char* getFilename () const {
00687          return fFilename.c_str(); }
00693       std::string guessFilename() const;
00698       void setFrameNum (int num) {
00699          fFrameNum = num; }
00704       int getFrameNum () const {
00705          return fFrameNum; }
00710       void setRunNum (int num) {
00711          fRunNum = num; }
00716       int getRunNum () const {
00717          return fRunNum; }
00718    
00719    protected:
00721       bool              fSwap;
00723       int               fVersion;
00725       framepos          fFramePos;
00727       Time              fTime;
00729       Time              fNext;
00731       int               fRunNum;
00733       int               fFrameNum;
00735       int               fFrameLen;
00737       int               fNFrame;
00739       int               fCompress;
00741       int               fN;
00743       int               fTotal;
00745       framebufferlist   fFrameBuffer;
00747       detector_array_t  fDetector;
00749       toc_t             fTOC;
00751       std::string       fFilename;
00752    
00756       ptr_struct        fPtr[9];
00757    
00759       framebuffer_t* currentBuffer();
00761       bool appendBuffer (const char* dat, int len);
00763       bool beginFile();
00765       bool endFile();
00767       bool beginFrame();
00769       bool endFrame();
00770    };
00771 
00772 }
00773 
00774 #endif /* _LIGO_FRAMEFAST_H */

Generated on Sun Mar 8 19:20:46 2009 for dmt by  doxygen 1.5.4