PLearn 0.1
SourceVMatrix.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // SourceVMatrix.cc
00004 //
00005 // Copyright (C) 2003 Pascal Vincent
00006 //
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 //
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 //
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 //
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 //
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 //
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 /* *******************************************************
00036  * $Id: SourceVMatrix.cc 8709 2008-03-20 16:39:48Z nouiz $
00037  ******************************************************* */
00038 
00039 // Authors: Pascal Vincent
00040 
00044 #include "SourceVMatrix.h"
00045 #include <plearn/io/fileutils.h>        
00046 #include <plearn/base/stringutils.h>
00047 
00048 namespace PLearn {
00049 using namespace std;
00050 
00051 
00052 SourceVMatrix::SourceVMatrix(bool call_build_)
00053     : inherited(call_build_),
00054       deep_copy_source(true)
00055 {
00056     if( call_build_ )
00057         build_();
00058 }
00059 
00060 SourceVMatrix::SourceVMatrix(VMat the_source, bool call_build_)
00061     : inherited(call_build_),
00062       source(the_source),
00063       deep_copy_source(true)
00064 {
00065     if( call_build_ )
00066         build_();
00067 }
00068 
00069 SourceVMatrix::SourceVMatrix(VMat the_source, int the_length, int the_width,
00070                              bool call_build_)
00071     : inherited(the_length, the_width, call_build_),
00072       source(the_source),
00073       deep_copy_source(true)
00074 {
00075     if( call_build_ )
00076         build_();
00077 }
00078 
00079 PLEARN_IMPLEMENT_OBJECT(SourceVMatrix,
00080                         "Super-class for VMatrices that point to another one (the source vmatrix)",
00081                         ""
00082     );
00083 
00084 void SourceVMatrix::setMetaDataDir(const PPath& the_metadatadir)
00085 {
00086     inherited::setMetaDataDir(the_metadatadir);
00087 
00088     if (!source)
00089         return;
00090 
00091     if(!source->hasMetaDataDir())
00092         source->setMetaDataDir(the_metadatadir/"Source");
00093 
00094     // Set mapping and info files from source if not set
00095     if(isdir(source->getSFIFDirectory()) && hasFieldInfos())
00096     {
00097         for(int j=0; j<width_; j++)
00098         {
00099             string fnam = fieldName(j);
00100             if(!isfile(getSFIFFilename(fnam,".smap")) && isfile(source->getSFIFFilename(fnam,".smap")))
00101                 setSFIFFilename(fnam, ".smap", source->getSFIFFilename(fnam,".smap"));
00102 
00103             if(!isfile(getSFIFFilename(fnam,".notes")) && isfile(source->getSFIFFilename(fnam,".notes")))
00104                 setSFIFFilename(fnam, ".notes", source->getSFIFFilename(fnam,".notes"));
00105 
00106             if(!isfile(getSFIFFilename(fnam,".binning")) && isfile(source->getSFIFFilename(fnam,".binning")))
00107                 setSFIFFilename(fnam, ".binning", source->getSFIFFilename(fnam,".binning"));
00108         }
00109     }
00110 }
00111 
00112 void SourceVMatrix::declareOptions(OptionList& ol)
00113 {
00114     declareOption(ol, "source", &SourceVMatrix::source, OptionBase::buildoption,
00115                   "The source VMatrix");
00116 
00117     declareOption(ol, "deep_copy_source", &SourceVMatrix::deep_copy_source,
00118                   OptionBase::buildoption,
00119                   "If True, we make a deep copy of the source.");
00120     /*
00121       declareOption(ol, "dependencies", &SourceVMatrix::dependencies, OptionBase::buildoption,
00122       "a list of paths to files that this VMat depends on. \n"
00123       "This vmat's mtime will initially be set to the latest of \n"
00124       "the last modification times of its dependencies. \n"
00125       "The mtime of its source will also be taken into account \n"
00126       "generally later, when setMetaInfoFromSource gets called \n");
00127     */
00128 
00129     // Now call the parent class' declareOptions
00130     inherited::declareOptions(ol);
00131 }
00132 
00133 void SourceVMatrix::build_()
00134 {
00135     /*
00136       for(int k=0; k<dependencies.size(); k++)
00137       updateMtime(dependencies[k]);
00138     */
00139 }
00140 
00142 // setMetaInfoFromSource //
00144 void SourceVMatrix::setMetaInfoFromSource()
00145 {
00146     setMetaInfoFrom(source);
00147 }
00148 
00149 // ### Nothing to add here, simply calls build_
00150 void SourceVMatrix::build()
00151 {
00152     inherited::build();
00153     build_();
00154 }
00155 
00156 void SourceVMatrix::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00157 {
00158     inherited::makeDeepCopyFromShallowCopy(copies);
00159     deepCopyField(sourcerow, copies);
00160     if(deep_copy_source)
00161         deepCopyField(source, copies);
00162 }
00163 
00165 // getNewRow //
00167 void SourceVMatrix::getNewRow(int i, const Vec& v) const {
00168     PLERROR("In SourceVMatrix::getNewRow - getNewRow not implemented for this subclass of SourceVMatrix");
00169 }
00170 
00171 PP<Dictionary> SourceVMatrix::getDictionary(int col) const
00172 {
00173     return source->getDictionary(col);
00174 }
00175 
00176 void SourceVMatrix::getValues(int row, int col, Vec& values) const
00177 {
00178     source->getValues(row,col,values);
00179 }
00180 
00181 void SourceVMatrix::getValues(const Vec& input, int col, Vec& values) const
00182 {
00183     source->getValues(input,col,values);
00184 }
00185 
00186 } // end of namespace PLearn
00187 
00188 
00189 /*
00190   Local Variables:
00191   mode:c++
00192   c-basic-offset:4
00193   c-file-style:"stroustrup"
00194   c-file-offsets:((innamespace . 0)(inline-open . 0))
00195   indent-tabs-mode:nil
00196   fill-column:79
00197   End:
00198 */
00199 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines