LoDirList.H

00001 /**
00002    \file  Robots/LoBot/misc/LoDirList.H
00003    \brief A thread-safe object for storing the list of directories
00004    containing metrics logs for the Bayesian TTI prediction experiments.
00005 
00006    This file defines a class that implements a simple object for storing
00007    the list of directories containing metrics logs for the Bayesian
00008    time-to-impact experiments and providing thread-safe access to this
00009    directory list.
00010 
00011    The lobay program enumerates the list of subdirectories under the
00012    Bayesian TTI experiments' root data directory and creates multiple
00013    threads to process each of these datasets in parallel. The analyzer
00014    threads need to know the next directory to process. To ensure that
00015    different threads pick different datasets, we use the lobot::DirList
00016    object to keep track of the next one in the list that should be
00017    analyzed.
00018 
00019    Obviously, since multiple threads can access this list and update the
00020    next field, we need to protect simultaneous accesses. The
00021    lobot::DirList object encapsulates all of that functionality,
00022    providing a straightforward interface to the analyzer threads.
00023 */
00024 
00025 // //////////////////////////////////////////////////////////////////// //
00026 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00027 // by the University of Southern California (USC) and the iLab at USC.  //
00028 // See http://iLab.usc.edu for information about this project.          //
00029 // //////////////////////////////////////////////////////////////////// //
00030 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00031 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00032 // in Visual Environments, and Applications'' by Christof Koch and      //
00033 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00034 // pending; application number 09/912,225 filed July 23, 2001; see      //
00035 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00036 // //////////////////////////////////////////////////////////////////// //
00037 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00038 //                                                                      //
00039 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00040 // redistribute it and/or modify it under the terms of the GNU General  //
00041 // Public License as published by the Free Software Foundation; either  //
00042 // version 2 of the License, or (at your option) any later version.     //
00043 //                                                                      //
00044 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00045 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00046 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00047 // PURPOSE.  See the GNU General Public License for more details.       //
00048 //                                                                      //
00049 // You should have received a copy of the GNU General Public License    //
00050 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00051 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00052 // Boston, MA 02111-1307 USA.                                           //
00053 // //////////////////////////////////////////////////////////////////// //
00054 //
00055 // Primary maintainer for this file: mviswana usc edu
00056 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/baylog/LoDirList.H $
00057 // $Id: LoDirList.H 14083 2010-09-30 13:59:37Z mviswana $
00058 //
00059 
00060 #ifndef LOBOT_BAYLOG_DIR_LIST_DOT_H
00061 #define LOBOT_BAYLOG_DIR_LIST_DOT_H
00062 
00063 //------------------------------ HEADERS --------------------------------
00064 
00065 // lobot headers
00066 #include "Robots/LoBot/thread/LoMutex.H"
00067 
00068 // Standard C++ headers
00069 #include <string>
00070 #include <vector>
00071 
00072 //----------------------------- NAMESPACE -------------------------------
00073 
00074 namespace lobot {
00075 
00076 //------------------------- CLASS DEFINITION ----------------------------
00077 
00078 /**
00079    \class lobot::DirList
00080    \brief An object to help keep track of which dataset should be
00081    analyzed next.
00082 
00083    This class implements a thread-safe interface for the
00084    lobot::BaylogAnalyzer threads so they can figure out which Bayesian
00085    TTI prediction experiment's dataset should be loaded and parsed next.
00086    When all the datasets have been processed, further attempts at
00087    retrieving the name of the next one for analysis will result in an
00088    exception. The analyzer threads can use the exception as a signal to
00089    wind up their work.
00090 */
00091 class DirList {
00092    // Prevent copy and assignment
00093    DirList(const DirList&) ;
00094    DirList& operator=(const DirList&) ;
00095 
00096    /// The whole idea behind this class is to keep track of a list of
00097    /// directories each of which contains metrics logs collected as part
00098    /// of the Robolocust Bayesian time-to-impact prediction experiments.
00099    /// These data members take care of the details.
00100    //@{
00101    typedef std::vector<std::string> List ;
00102    typedef List::iterator Iter ;
00103    List m_list ;
00104    mutable Iter m_next ;
00105    //@}
00106 
00107    /// When an analyzer thread is done processing one log, it will
00108    /// request the next one in the queue from this object. Since multiple
00109    /// threads can use this object, we need a mutex to ensure that they
00110    /// don't step on each others' toes.
00111    Mutex m_mutex ;
00112 
00113 public:
00114    /// When this object is created, it should be passed the list of names
00115    /// of directories containing the relevant logs.
00116    ///
00117    /// NOTE: It is important that the analyzer threads not yet be active
00118    /// when this class is instantiated.
00119    DirList(const std::vector<std::string>& dirs) ;
00120 
00121    /// This method returns the number of directories held by this list
00122    /// object.
00123    int size() const {return m_list.size() ;}
00124 
00125    /// This method retrieves the next name on the list. When all the
00126    /// names have been retrieved, it will throw an end-of-list exception
00127    /// to indicate to the analyzer threads that it's time for them to
00128    /// wind up their business.
00129    std::string next() const ;
00130 
00131    /// This is the exception object thrown when we reach the end of the
00132    /// list.
00133    struct eol {} ;
00134 } ;
00135 
00136 //-----------------------------------------------------------------------
00137 
00138 } // end of namespace encapsulating this file's definitions
00139 
00140 #endif
00141 
00142 /* So things look consistent in everyone's emacs... */
00143 /* Local Variables: */
00144 /* indent-tabs-mode: nil */
00145 /* End: */
Generated on Sun May 8 08:41:22 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3