Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #if !defined(ALIZE_FeatureFileReaderSPro4_cpp)
00056 #define ALIZE_FeatureFileReaderSPro4_cpp
00057
00058 #include <new>
00059 #include "FeatureFileReaderSPro4.h"
00060 #include "FileReader.h"
00061 #include "Feature.h"
00062 #include "Exception.h"
00063 #include "LabelServer.h"
00064 #include "Label.h"
00065 #include "Config.h"
00066
00067 using namespace alize;
00068 typedef FeatureFileReaderSPro4 R;
00069
00070
00071 R::FeatureFileReaderSPro4(const FileName& f, const Config& c,
00072 LabelServer* l, BigEndian be, BufferUsage b, unsigned long bufferSize,
00073 HistoricUsage h, unsigned long historicSize)
00074 :FeatureFileReaderSingle(&FileReader::create(f, getPath(f, c),
00075 getExt(f, c), getBigEndian(c, be)), NULL, c, l, b, bufferSize, h, historicSize),
00076 _paramDefined(false) {}
00077
00078 R& R::create(const FileName& f, const Config& c, LabelServer* l,
00079 BigEndian be, BufferUsage b, unsigned long bufferSize,
00080 HistoricUsage h, unsigned long historicSize)
00081 {
00082 R* p = new (std::nothrow)
00083 FeatureFileReaderSPro4(f, c, l, be, b, bufferSize, h, historicSize);
00084 assertMemoryIsAllocated(p, __FILE__, __LINE__);
00085 return *p;
00086 }
00087
00088 void R::readParams()
00089 {
00090 assert(_pReader != NULL);
00091 _pReader->open();
00092
00093 if (!readHeader())
00094 {
00095 _pReader->close();
00096 throw InvalidDataException("Wrong header", __FILE__, __LINE__,
00097 _pReader->getFullFileName());
00098 }
00099 }
00100
00101 unsigned long R::getFeatureCount()
00102 {
00103 if (!_paramDefined)
00104 readParams();
00105 return _featureCount;
00106 }
00107
00108 unsigned long R::getVectSize()
00109 {
00110 if (!_paramDefined)
00111 readParams();
00112 return _vectSize;
00113 }
00114
00115 const FeatureFlags& R::getFeatureFlags()
00116 {
00117 if (!_paramDefined)
00118 readParams();
00119 return _flags;
00120 }
00121
00122 real_t R::getSampleRate()
00123 {
00124 if (!_paramDefined)
00125 readParams();
00126 return _sampleRate;
00127 }
00128
00129 unsigned long R::getHeaderLength()
00130 {
00131 if (!_paramDefined)
00132 readParams();
00133 return _headerLength;
00134 }
00135
00136 String R::getClassName() const { return "FeatureFileReaderSPro4";}
00137
00138 bool R::readHeader()
00139 {
00140 assert(_pReader != NULL);
00141 const int WITHE = 0x01;
00142
00143
00144
00145 const int WITHD = 0x08;
00146 const int WITHA = 0xa0;
00147 const int WITHNODE = 0x10;
00148
00149 if (_pReader->readString(9) == "<header>\n")
00150 while(true)
00151 {
00152 String line = _pReader->readLine();
00153 unsigned long l = line.length();
00154 if (l == 0)
00155 continue;
00156 if (line.getToken(0) == "</header>")
00157 break;
00158 const char* s = line.c_str();
00159 String name, value;
00160 unsigned long i;
00161 for (i=0; i<l&&s[i]!=';'&&s[i]!='='&&(s[i]==' '||s[i]=='\t'); i++)
00162 ;
00163 for (; i<l&&s[i]!=';'&&s[i]!='='&&s[i]!=' '&&s[i]!='\t'; i++)
00164 name += line[i];
00165 for (; i<l&&s[i]!=';'&&s[i]!='='; i++)
00166 ;
00167 for (; i<l&&s[i]!=';'&&(s[i]==' '||s[i]=='\t'); i++)
00168 ;
00169 for (; i<l&&s[i]!=';'&&s[i]!=' '&&s[i]!='\t'; i++)
00170 {
00171 value += line[i];
00172 }
00173 if (name.isEmpty() && value.isEmpty())
00174 return false;
00175
00176 }
00177 else
00178 _pReader->rewind();
00179
00180 _vectSize = _pReader->readInt2();
00181 unsigned long flag = _pReader->readUInt4();
00182 _sampleRate = (real_t)_pReader->readFloat();
00183 _headerLength = _pReader->tell();
00184
00185 _flags.useS = true;
00186
00187
00188 if ((flag & WITHE) != 0)
00189 {
00190 _flags.useE = true;
00191
00192 if ((flag & WITHD) != 0)
00193 {
00194 _flags.useD = true;
00195
00196 if ((flag & WITHNODE) == 0)
00197 {
00198 _flags.useDE = true;
00199
00200 }
00201 if ((flag & WITHA) != 0)
00202 {
00203 _flags.useDD = true;
00204 _flags.useDDE = true;
00205
00206
00207 }
00208 }
00209 else
00210 {
00211 if ((flag & WITHA) != 0)
00212 {
00213 _flags.useD = true;
00214 _flags.useDE = true;
00215
00216
00217 }
00218 }
00219 }
00220 else
00221 {
00222 if ((flag & WITHD) != 0)
00223 {
00224 _flags.useD = true;
00225
00226 if ((flag & WITHA) != 0)
00227 {
00228 _flags.useDD = true;
00229
00230 }
00231 }
00232 else
00233 if ((flag & WITHA) != 0)
00234 {
00235 _flags.useDD = true;
00236
00237 }
00238 }
00239
00240 if (_vectSize == 0)
00241 return false;
00242 _featureCount = (_pReader->getFileLength()-_headerLength)/(_vectSize*sizeof(float));
00243 _paramDefined = true;
00244
00245 return true;
00246 }
00247
00248 R::~FeatureFileReaderSPro4() {}
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 #endif // !defined(ALIZE_FeatureFileReaderSPro4_cpp)
00269