LoMetlogLoader.C

00001 /**
00002    \file  Robots/LoBot/control/LoMetlogLoader.C
00003    \brief This file defines the non-inline member functions of the
00004    lobot::MetlogLoader class.
00005 */
00006 
00007 // //////////////////////////////////////////////////////////////////// //
00008 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00009 // by the University of Southern California (USC) and the iLab at USC.  //
00010 // See http://iLab.usc.edu for information about this project.          //
00011 // //////////////////////////////////////////////////////////////////// //
00012 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00013 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00014 // in Visual Environments, and Applications'' by Christof Koch and      //
00015 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00016 // pending; application number 09/912,225 filed July 23, 2001; see      //
00017 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00018 // //////////////////////////////////////////////////////////////////// //
00019 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00022 // redistribute it and/or modify it under the terms of the GNU General  //
00023 // Public License as published by the Free Software Foundation; either  //
00024 // version 2 of the License, or (at your option) any later version.     //
00025 //                                                                      //
00026 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00027 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00028 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00029 // PURPOSE.  See the GNU General Public License for more details.       //
00030 //                                                                      //
00031 // You should have received a copy of the GNU General Public License    //
00032 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00033 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00034 // Boston, MA 02111-1307 USA.                                           //
00035 // //////////////////////////////////////////////////////////////////// //
00036 //
00037 // Primary maintainer for this file: mviswana usc edu
00038 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/metlog/LoMetlogLoader.C $
00039 // $Id: LoMetlogLoader.C 13930 2010-09-13 23:53:53Z mviswana $
00040 //
00041 
00042 //------------------------------ HEADERS --------------------------------
00043 
00044 // lobot headers
00045 #include "Robots/LoBot/metlog/LoMetlogLoader.H"
00046 #include "Robots/LoBot/metlog/LoDataset.H"
00047 #include "Robots/LoBot/metlog/LoExperiment.H"
00048 #include "Robots/LoBot/metlog/LoMetlogList.H"
00049 
00050 // DEVNOTE: We must supply the definition of YY_EXTRA_TYPE prior to
00051 // including LoMetlogParser.H, which is generated by flex. Otherwise, the
00052 // generated header will define YY_EXTRA_TYPE as void* and the linker
00053 // will fail to find the lomet_parser_set_extra function, which will end
00054 // up being declared in this module as taking a void* rather than a
00055 // lobot::Experiment* as it actually does.
00056 //
00057 // Moreover, we must include the flex-generated LoMetlogParser.H header
00058 // after LoExperiment.H. Otherwise, the lobot::Experiment class will not
00059 // be properly declared or defined and the compiler really detests that.
00060 #define YY_EXTRA_TYPE lobot::Experiment*
00061 #include "Robots/LoBot/metlog/LoMetlogParser.H"
00062 
00063 #include "Robots/LoBot/thread/LoMutex.H"
00064 #include "Robots/LoBot/util/LoString.H"
00065 
00066 // Standard C++ headers
00067 #include <iostream>
00068 #include <string>
00069 
00070 // Standard C headers
00071 #include <stdio.h>
00072 
00073 //----------------------------- NAMESPACE -------------------------------
00074 
00075 namespace lobot {
00076 
00077 //-------------------------- INITIALIZATION -----------------------------
00078 
00079 MetlogLoader* MetlogLoader::create(const MetlogList& L, Dataset* D)
00080 {
00081    return new MetlogLoader(L, D) ;
00082 }
00083 
00084 MetlogLoader::MetlogLoader(const MetlogList& L, Dataset* D)
00085    : m_logs(L), m_dataset(D)
00086 {
00087    static int n ;
00088    static Mutex m ;
00089 
00090    AutoMutex M(m) ;
00091    start(std::string("lomet_metlog_loader_") + to_string(++n)) ;
00092 }
00093 
00094 //-------------------------- METLOG PARSING -----------------------------
00095 
00096 void MetlogLoader::run()
00097 {
00098    yyscan_t parser ;
00099    try
00100    {
00101       lomet_parser_lex_init(&parser) ;
00102       for(;;)
00103       {
00104          std::string name = m_logs.next() ;
00105          FILE* file = fopen(name.c_str(), "r") ;
00106          if (! file) {
00107             std::cerr << Thread::name() << ": "
00108                       << name << ": unable to open\n" ;
00109             continue ;
00110          }
00111 
00112          Experiment* experiment = Experiment::create(name) ;
00113 
00114          lomet_parser_set_extra(experiment, parser) ;
00115          lomet_parser_set_in(file, parser) ;
00116          lomet_parser_lex(parser) ;
00117 
00118          lomet_parser_set_extra(0, parser) ;
00119          lomet_parser_set_in(stdin, parser) ;
00120          fclose(file) ;
00121 
00122          m_dataset->add(experiment) ;
00123       }
00124    }
00125    catch (MetlogList::eol&)
00126    {
00127       lomet_parser_lex_destroy(parser) ;
00128    }
00129 }
00130 
00131 //-----------------------------------------------------------------------
00132 
00133 } // end of namespace encapsulating this file's definitions
00134 
00135 /* So things look consistent in everyone's emacs... */
00136 /* Local Variables: */
00137 /* indent-tabs-mode: nil */
00138 /* End: */
Generated on Sun May 8 08:05:55 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3