DiskDataStream.H

Go to the documentation of this file.
00001 /*!@file Devices/DiskDataStream.H Multi-threaded data streamer to disk */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Devices/DiskDataStream.H $
00035 // $Id: DiskDataStream.H 12118 2009-12-04 22:47:43Z sychic $
00036 //
00037 
00038 #ifndef DISKIMAGESTREAM_H_DEFINED
00039 #define DISKIMAGESTREAM_H_DEFINED
00040 
00041 #include "Component/ModelComponent.H"
00042 #include "Component/ModelParam.H"
00043 #include "Transport/FrameOstream.H"
00044 #include "rutz/shared_ptr.h"
00045 
00046 #include <string>
00047 #include <vector>
00048 
00049 class GenericFrame;
00050 class WorkThreadServer;
00051 
00052 //! A multi-threaded data streamer to disk
00053 /*! This class implements a cache to allow asynchronous streaming of
00054   series of data objects to disk. Users push their data objects as
00055   they become available in the main processing thread, and the class'
00056   internal thread will attempt to save them to disk as quickly as
00057   possible. */
00058 class DiskDataStream : public FrameOstream
00059 {
00060 public:
00061   //! Constructor
00062   DiskDataStream(OptionManager& mgr,
00063                  const std::string& descrName = "Disk Data Stream",
00064                  const std::string& tagName = "DiskDataStream");
00065 
00066   //! Destructor
00067   ~DiskDataStream();
00068 
00069   //! Override from FrameOstream; just calls setSavePath()
00070   virtual void setConfigInfo(const std::string& path);
00071 
00072   //! Push a data object for asynchronous saving to disk
00073   /*! This version makes an initial copy of the data, so that it can
00074       be destroyed immediately upon return. */
00075   virtual void writeFrame(const GenericFrame& frame,
00076                           const std::string& shortname,
00077                           const FrameInfo& auxinfo = defaultInfo);
00078 
00079   //! Specify a comma-separated list of output prefixes
00080   /*! The string should contain a comma-separated list of filename
00081       stems for where to save files; e.g., 'dir0/pfx0,dir1/pfx1' will
00082       save even-numbered files with the prefix 'dir0/pfx0' and will
00083       save odd-numbered files with the prefix 'dir1/pfx1'
00084   */
00085   void setSavePath(const std::string& path);
00086 
00087   //! Reset the in and out frame numbers for shortname to 0
00088   virtual void closeStream(const std::string& shortname);
00089 
00090 protected:
00091   //! start our worker thread
00092   virtual void start2();
00093 
00094   //! join our worker thread
00095   virtual void stop1();
00096 
00097 private:
00098   OModelParam<bool>        itsUseMmap;     //!< Whether to use mmap for writing files
00099   OModelParam<uint>        itsNumThreads;  //!< How many worker threads to use
00100   OModelParam<uint>        itsSleepUsecs;  //!< How many usecs to sleep after each write
00101   OModelParam<uint>        itsSavePeriod;  //!< How often to save frames (default = every frame)
00102   OModelParam<std::string> itsSavePath;    //!< Where to save frames
00103 
00104   std::vector<std::string> itsFileStems;   //!< Tokenized version of itsSavePath
00105 
00106   WorkThreadServer*        itsServer;      //!< Our thread server
00107 
00108   struct Impl;
00109   Impl* const rep;
00110 };
00111 
00112 #endif
00113 
00114 // ######################################################################
00115 /* So things look consistent in everyone's emacs... */
00116 /* Local Variables: */
00117 /* indent-tabs-mode: nil */
00118 /* End: */
Generated on Sun May 8 08:40:37 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3