PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions
PLearn::BinaryNumbersVMatrix Class Reference

VMatrix that can take its values from a possibly large file (greater than 2Gig) containing numbers in a user-given binary format, preceded by an arbitrary header whose length is user-given. More...

#include <BinaryNumbersVMatrix.h>

Inheritance diagram for PLearn::BinaryNumbersVMatrix:
Inheritance graph
[legend]
Collaboration diagram for PLearn::BinaryNumbersVMatrix:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 BinaryNumbersVMatrix ()
 Default constructor.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual BinaryNumbersVMatrixdeepCopy (CopiesMap &copies) const
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

Static Public Member Functions

static string _classname_ ()
 RowBufferedVMatrix.
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()

Public Attributes

PPath filename
 ### declare public option fields (such as build options) here
string format
int header_size
bool file_is_bigendian
int row_size

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

virtual void getNewRow (int i, const Vec &v) const
 Fill the vector 'v' with the content of the i-th row.
virtual ~BinaryNumbersVMatrix ()
 destructor releases buffer and file pointer

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares the class options.

Protected Attributes

PRFileDesc * f
void * buffer

Private Types

typedef RowBufferedVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

VMatrix that can take its values from a possibly large file (greater than 2Gig) containing numbers in a user-given binary format, preceded by an arbitrary header whose length is user-given.

Definition at line 55 of file BinaryNumbersVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 57 of file BinaryNumbersVMatrix.h.


Constructor & Destructor Documentation

PLearn::BinaryNumbersVMatrix::BinaryNumbersVMatrix ( )

Default constructor.

Definition at line 56 of file BinaryNumbersVMatrix.cc.

    : format("u1"), header_size(0), file_is_bigendian(false), f(0), buffer(0)
{
}
PLearn::BinaryNumbersVMatrix::~BinaryNumbersVMatrix ( ) [protected, virtual]

destructor releases buffer and file pointer

Definition at line 170 of file BinaryNumbersVMatrix.cc.

References buffer, and f.

{
    if (buffer) delete[] (char*)buffer;
    buffer=0;
    if (f) 
        PR_Close(f);
    f=0;
}

Member Function Documentation

string PLearn::BinaryNumbersVMatrix::_classname_ ( ) [static]

RowBufferedVMatrix.

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

OptionList & PLearn::BinaryNumbersVMatrix::_getOptionList_ ( ) [static]

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

RemoteMethodMap & PLearn::BinaryNumbersVMatrix::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

bool PLearn::BinaryNumbersVMatrix::_isa_ ( const Object o) [static]

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

Object * PLearn::BinaryNumbersVMatrix::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

StaticInitializer BinaryNumbersVMatrix::_static_initializer_ & PLearn::BinaryNumbersVMatrix::_static_initialize_ ( ) [static]

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

void PLearn::BinaryNumbersVMatrix::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::VMatrix.

Definition at line 158 of file BinaryNumbersVMatrix.cc.

References PLearn::VMatrix::build(), and build_().

Here is the call graph for this function:

void PLearn::BinaryNumbersVMatrix::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::VMatrix.

Definition at line 142 of file BinaryNumbersVMatrix.cc.

References buffer, f, filename, format, row_size, PLearn::VMatrix::updateMtime(), and PLearn::VMatrix::width_.

Referenced by build().

{
    if (f)
        PR_Close(f);
    updateMtime(filename);
    f = PR_Open(filename.c_str(), PR_RDONLY, 0666);
    if (width_>0)
    {
        if (buffer) 
            delete[] (char*)buffer;
        row_size = width_*(format[1]-'0');
        buffer = (void*) (new char[row_size]);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::BinaryNumbersVMatrix::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

void PLearn::BinaryNumbersVMatrix::declareOptions ( OptionList ol) [static, protected]

Declares the class options.

Reimplemented from PLearn::VMatrix.

Definition at line 111 of file BinaryNumbersVMatrix.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), file_is_bigendian, filename, format, header_size, PLearn::OptionBase::learntoption, and row_size.

{
    declareOption(ol, "filename", &BinaryNumbersVMatrix::filename,
                   OptionBase::buildoption,
                  "Name of file to be read.");

    declareOption(ol, "format", &BinaryNumbersVMatrix::format,
                   OptionBase::buildoption,
                  "2-character specification of binary format of the numbers in the file:\n"
                  "  u1 = 1-byte unsigned integers\n"
                  "  u2 = 1-byte unsigned integers\n"
                  "  i4 = 4-byte signed integers\n"
                  "  f4 = 4-byte floating point\n"
                  "  f8 = 8-byte floating point\n");

    declareOption(ol, "header_size", &BinaryNumbersVMatrix::header_size,
                   OptionBase::buildoption,
                  "Number of bytes of header at beginning of file.");

    declareOption(ol, "file_is_bigendian", &BinaryNumbersVMatrix::file_is_bigendian,
                   OptionBase::buildoption,
                  "Whether the byte order is 'BIG ENDIAN' or not.");

    declareOption(ol, "row_size", &BinaryNumbersVMatrix::row_size,
                   OptionBase::learntoption,
                  "Number of bytes in each row");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::BinaryNumbersVMatrix::declaringFile ( ) [inline, static]

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 102 of file BinaryNumbersVMatrix.h.

:
    //#####  Protected Options  ###############################################
BinaryNumbersVMatrix * PLearn::BinaryNumbersVMatrix::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

void PLearn::BinaryNumbersVMatrix::getNewRow ( int  i,
const Vec v 
) const [protected, virtual]

Fill the vector 'v' with the content of the i-th row.

'v' is assumed to be the right size.

Implements PLearn::RowBufferedVMatrix.

Definition at line 61 of file BinaryNumbersVMatrix.cc.

References buffer, PLearn::endianswap2(), PLearn::endianswap4(), PLearn::endianswap8(), f, file_is_bigendian, format, header_size, i, PLearn::TVec< T >::length(), PLASSERT_MSG, PLERROR, row_size, and PLearn::VMatrix::width_.

{
    PLASSERT_MSG(v.length()==width_,"BinaryNumbersVMatrix::getNewRow(i,v) with v.length!= vmatrix width");
    PRInt64 offset = i;
    offset *= row_size;
    offset += header_size;
    PR_Seek64(f,offset,PR_SEEK_SET);
    PR_Read(f,buffer,row_size);
    bool swap_endian=false;
#ifdef LITTLEENDIAN
    if(file_is_bigendian)
        swap_endian=true;
#endif
#ifdef BIGENDIAN
    if(!file_is_bigendian)
        swap_endian=true;
#endif
    
    int l=v.length();
    if (format=="u1") 
        for (int i=0;i<l;i++)
            v[i] = (real)((unsigned char*)buffer)[i];
    else if (format=="u2") {
        if (swap_endian)
            endianswap2(buffer,width_);
        for (int i=0;i<l;i++)
            v[i] = (real)((unsigned short*)buffer)[i];
    }
    else if (format=="i4") {
        if (swap_endian)
            endianswap4(buffer,width_);
        for (int i=0;i<l;i++)
            v[i] = (real)((int*)buffer)[i];
    }
    else if (format=="f4") {
        if (swap_endian)
            endianswap4(buffer,width_);
        for (int i=0;i<l;i++)
            v[i] = (real)((float*)buffer)[i];
    }
    else if (format=="f8") {
        if (swap_endian)
            endianswap8(buffer,width_);
        for (int i=0;i<l;i++)
            v[i] = (real)((double*)buffer)[i];
    }
    else
        PLERROR("BinaryNumbersVMatrix: unknown format = %s\n",format.c_str());
}

Here is the call graph for this function:

OptionList & PLearn::BinaryNumbersVMatrix::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

OptionMap & PLearn::BinaryNumbersVMatrix::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

RemoteMethodMap & PLearn::BinaryNumbersVMatrix::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 54 of file BinaryNumbersVMatrix.cc.

void PLearn::BinaryNumbersVMatrix::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 164 of file BinaryNumbersVMatrix.cc.

References PLearn::RowBufferedVMatrix::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 102 of file BinaryNumbersVMatrix.h.

Definition at line 87 of file BinaryNumbersVMatrix.h.

Referenced by build_(), getNewRow(), and ~BinaryNumbersVMatrix().

PRFileDesc* PLearn::BinaryNumbersVMatrix::f [protected]

Definition at line 86 of file BinaryNumbersVMatrix.h.

Referenced by build_(), getNewRow(), and ~BinaryNumbersVMatrix().

Definition at line 76 of file BinaryNumbersVMatrix.h.

Referenced by declareOptions(), and getNewRow().

### declare public option fields (such as build options) here

Definition at line 64 of file BinaryNumbersVMatrix.h.

Referenced by build_(), and declareOptions().

Definition at line 70 of file BinaryNumbersVMatrix.h.

Referenced by build_(), declareOptions(), and getNewRow().

Definition at line 73 of file BinaryNumbersVMatrix.h.

Referenced by declareOptions(), and getNewRow().

Definition at line 81 of file BinaryNumbersVMatrix.h.

Referenced by build_(), declareOptions(), and getNewRow().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines