Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

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,v 1.11 2004/07/07 17:30:48 tihocan Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Pascal Vincent 00040 00044 #include "SourceVMatrix.h" 00045 00046 namespace PLearn { 00047 using namespace std; 00048 00049 00050 SourceVMatrix::SourceVMatrix() 00051 :inherited() 00052 /* ### Initialise all fields to their default value */ 00053 { 00054 // ... 00055 00056 // ### You may or may not want to call build_() to finish building the object 00057 // build_(); 00058 } 00059 00060 PLEARN_IMPLEMENT_OBJECT(SourceVMatrix, 00061 "Super-class for VMatrices that point to another one (the source vmatrix)", 00062 "" 00063 ); 00064 00065 void SourceVMatrix::setMetaDataDir(const string& the_metadatadir) 00066 { 00067 inherited::setMetaDataDir(the_metadatadir); 00068 if(!source->hasMetaDataDir()) 00069 source->setMetaDataDir(the_metadatadir+slash+"Source"+slash); 00070 00071 // Set mapping and info files from source if not set 00072 if(hasFieldInfos()) 00073 { 00074 for(int j=0; j<width_; j++) 00075 { 00076 string fnam = fieldName(j); 00077 if(!file_exists(getSFIFFilename(fnam,".smap")) && file_exists(source->getSFIFFilename(fnam,".smap"))) 00078 setSFIFFilename(fnam, ".smap", source->getSFIFFilename(fnam,".smap")); 00079 if(!file_exists(getSFIFFilename(fnam,".notes")) && file_exists(source->getSFIFFilename(fnam,".notes"))) 00080 setSFIFFilename(fnam, ".notes", source->getSFIFFilename(fnam,".notes")); 00081 if(!file_exists(getSFIFFilename(fnam,".binning")) && file_exists(source->getSFIFFilename(fnam,".binning"))) 00082 setSFIFFilename(fnam, ".binning", source->getSFIFFilename(fnam,".binning")); 00083 } 00084 } 00085 } 00086 00087 void SourceVMatrix::declareOptions(OptionList& ol) 00088 { 00089 declareOption(ol, "source", &SourceVMatrix::source, OptionBase::buildoption, 00090 "The source VMatrix"); 00091 00092 /* 00093 declareOption(ol, "dependencies", &SourceVMatrix::dependencies, OptionBase::buildoption, 00094 "a list of paths to files that this VMat depends on. \n" 00095 "This vmat's mtime will initially be set to the latest of \n" 00096 "the last modification times of its dependencies. \n" 00097 "The mtime of its source will also be taken into account \n" 00098 "generally later, when setMetaInfoFromSource gets called \n"); 00099 */ 00100 00101 // Now call the parent class' declareOptions 00102 inherited::declareOptions(ol); 00103 } 00104 00105 void SourceVMatrix::build_() 00106 { 00107 /* 00108 time_t mt = getMtime(); 00109 for(int k=0; k<dependencies.size(); k++) 00110 mt = max(mt, mtime(dependencies[k])); 00111 setMtime(mt); 00112 */ 00113 } 00114 00115 void SourceVMatrix::setMetaInfoFromSource() 00116 { 00117 setMtime(max(getMtime(),source->getMtime())); 00118 00119 // copy length and width from source if not set 00120 if(length_<0) 00121 length_ = source->length(); 00122 if(width_<0) 00123 width_ = source->width(); 00124 00125 // copy sizes from source if not set 00126 if(inputsize_<0) 00127 inputsize_ = source->inputsize(); 00128 if(targetsize_<0) 00129 targetsize_ = source->targetsize(); 00130 if(weightsize_<0) 00131 weightsize_ = source->weightsize(); 00132 00133 // copy fieldnames from source if not set and they look good 00134 if(!hasFieldInfos() && (width() == source->width()) && source->hasFieldInfos() ) 00135 setFieldInfos(source->getFieldInfos()); 00136 00137 // Copy String/Real mappings if not set. 00138 if (map_rs.length() == 0) { 00139 map_rs.resize(width_); 00140 for (int j = 0; j < width_; j++) { 00141 if (j < source->width()) { 00142 map_rs[j] = source->getRealToStringMapping(j); 00143 } else { 00144 // Empty map. 00145 map_rs[j] = map<real,string>(); 00146 } 00147 } 00148 } 00149 if (map_sr.length() == 0) { 00150 map_sr.resize(width_); 00151 for (int j = 0; j < width_; j++) { 00152 if (j < source->width()) { 00153 map_sr[j] = source->getStringToRealMapping(j); 00154 } else { 00155 // Empty map. 00156 map_sr[j] = map<string,real>(); 00157 } 00158 } 00159 } 00160 } 00161 00162 // ### Nothing to add here, simply calls build_ 00163 void SourceVMatrix::build() 00164 { 00165 inherited::build(); 00166 build_(); 00167 } 00168 00169 void SourceVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00170 { 00171 inherited::makeDeepCopyFromShallowCopy(copies); 00172 deepCopyField(sourcerow, copies); 00173 deepCopyField(source, copies); 00174 } 00175 00177 // getNewRow // 00179 void SourceVMatrix::getNewRow(int i, const Vec& v) const { 00180 PLERROR("In SourceVMatrix::getNewRow - getNewRow not implemented for this subclass of SourceVMatrix"); 00181 } 00182 00183 } // end of namespace PLearn 00184

Generated on Tue Aug 17 16:06:18 2004 for PLearn by doxygen 1.3.7