00001 #ifndef Impala_Core_Feature_VirtualFeatureTableIOBufferWriter_h
00002 #define Impala_Core_Feature_VirtualFeatureTableIOBufferWriter_h
00003
00004 #include <ctime>
00005 #include "Core/Feature/VirtualFeatureTable.h"
00006 #include "Core/Matrix/VirtualMatrixIOBufferWriter.h"
00007 #include "Core/Array/WriteRaw.h"
00008 #include "Core/Array/SetVal.h"
00009 #include "Core/Column/Write.h"
00010
00011 namespace Impala
00012 {
00013 namespace Core
00014 {
00015 namespace Feature
00016 {
00017
00018
00019 class VirtualFeatureTableIOBufferWriter : public VirtualFeatureTable
00020 {
00021 public:
00022
00023 VirtualFeatureTableIOBufferWriter(int nrVectors, int vectorLength,
00024 Util::IOBuffer* buffer, bool ownBuffer,
00025 bool write32)
00026 {
00027 Init(nrVectors, vectorLength, buffer, ownBuffer, write32);
00028 }
00029
00030 virtual
00031 ~VirtualFeatureTableIOBufferWriter()
00032 {
00033 delete mMatrix;
00034 mMatrix = 0;
00035 if (mOwnBuffer)
00036 {
00037 delete mIOBuffer;
00038 mIOBuffer = 0;
00039 }
00040 }
00041
00042 virtual int
00043 Size() const
00044 {
00045 return mSize;
00046 }
00047
00048 virtual void
00049 GetQuids(Table::QuidTable* quids)
00050 {
00051 ILOG_ERROR("[GetQuids] Not implemented");
00052 }
00053
00054 virtual int
00055 GetVectorLength() const
00056 {
00057 return mVectorLength;
00058 }
00059
00060 void
00061 AddQuids(Table::QuidTable* quids)
00062 {
00063 mIOBuffer->SetPosition(mQuidsOffset);
00064 Column::Write(quids->GetColumn1(), quids->Size(), mIOBuffer, true);
00065 }
00066
00067 Matrix::VirtualMatrix*
00068 GetMatrix()
00069 {
00070 return mMatrix;
00071 }
00072
00073 void
00074 SetCompleted()
00075 {
00076 const char* str = "impalatableversion: 2";
00077 mIOBuffer->SetPosition(0);
00078 mIOBuffer->Write(str, strlen(str));
00079 }
00080
00081 private:
00082
00083 virtual int
00084 GetVectorImpl(int rowNr, Real64* buffer, int bufferSize)
00085 {
00086 ILOG_ERROR("[GetVectorImpl] Not implemented");
00087 return 0;
00088 }
00089
00090 void
00091 Init(int nrVectors, int vectorLength, Util::IOBuffer* buffer,
00092 bool ownBuffer, bool write32)
00093 {
00094 mSize = nrVectors;
00095 mVectorLength = vectorLength;
00096 mIOBuffer = buffer;
00097 mOwnBuffer = ownBuffer;
00098 mOutputElemSize = (write32) ? 4 : 8;
00099
00100 mBaseOffset = buffer->GetPosition();
00101 mQuidsOffset = mBaseOffset + 1024 + 128;
00102
00103
00104 const int TABLEHEADERSIZE = 1024;
00105 std::ostringstream oss;
00106 oss << "incompletexxxxxxxx: 2, columns: 2, size: " << nrVectors << "\n";
00107 oss << "column1: object\ncolumn2: kerneldata\ninfo: no info\n";
00108 std::time_t rawtime;
00109 std::time ( &rawtime );
00110 oss << "computedon: " << std::ctime (&rawtime);
00111 oss << "computedby: Impala " << IMPALA_VERSION_STR
00112 << " (svnversion " << SVN_VERSION_STR << ") compiled "
00113 << __DATE__ << " " << __TIME__ << "\n";
00114 while(oss.tellp() < TABLEHEADERSIZE)
00115 oss << ' ';
00116 oss.seekp(TABLEHEADERSIZE - 1, std::ios::beg);
00117 oss << '\n';
00118
00119
00120 mIOBuffer->Write(oss.str().c_str(), TABLEHEADERSIZE);
00121
00122
00123 Int64 footer[16];
00124 footer[0] = 0x6F66616C61706D69LL;
00125 footer[1] = 0x000000017265746FLL;
00126 footer[2] = 2;
00127 footer[3] = nrVectors;
00128 footer[4] = mQuidsOffset;
00129 footer[5] = footer[4] + 200 + nrVectors * sizeof(Int64);
00130 footer[6] = footer[5] + nrVectors * vectorLength * mOutputElemSize;
00131 for (int i=7 ; i<14 ; i++)
00132 footer[i] = footer[6];
00133 footer[14] = 0;
00134 footer[15] = 0;
00135 mIOBuffer->Write(footer, sizeof(Int64) * 16);
00136
00137
00138 Array::Array2dScalarUInt64 quids(nrVectors, 1, 0, 0);
00139 Array::SetVal(&quids, 0);
00140 Array::WriteRaw(&quids, mIOBuffer, 1);
00141
00142 if (mIOBuffer->GetPosition() != footer[5])
00143 ILOG_ERROR("Should be the same!");
00144
00145 mMatrix = new Matrix::VirtualMatrixIOBufferWriter
00146 (mSize, mVectorLength, mIOBuffer, false, write32, true);
00147 }
00148
00149 Util::IOBuffer* mIOBuffer;
00150 bool mOwnBuffer;
00151 int mOutputElemSize;
00152 Int64 mBaseOffset;
00153 Int64 mQuidsOffset;
00154 Int64 mSize;
00155 Int64 mVectorLength;
00156 Matrix::VirtualMatrix* mMatrix;
00157
00158 ILOG_VAR_DEC;
00159 };
00160
00161 ILOG_VAR_INIT(VirtualFeatureTableIOBufferWriter, Impala.Core.Feature);
00162
00163 }
00164 }
00165 }
00166
00167 #endif