EMAN2
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
EMAN::LstFastIO Class Reference

A LSX file is a high performance ASCII file that contains a list of image numbers and file names. More...

#include <lstfastio.h>

Inheritance diagram for EMAN::LstFastIO:
Inheritance graph
[legend]
Collaboration diagram for EMAN::LstFastIO:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LstFastIO (const string &filename, IOMode rw_mode=READ_ONLY)
 ~LstFastIO ()
bool is_single_image_format () const
 Is this image format only storing 1 image or not.
int get_nimg ()
 Return the number of images in this image file.

Static Public Member Functions

static bool is_valid (const void *first_block)

Public Attributes

 DEFINE_IMAGEIO_FUNC

Private Member Functions

int calc_ref_image_index (int image_index)

Private Attributes

string filename
IOMode rw_mode
FILE * lst_file
bool is_big_endian
bool initialized
int nimg
unsigned int line_length
unsigned int head_length
ImageIOimageio
string ref_filename
int last_lst_index
int last_ref_index

Static Private Attributes

static const char * MAGIC = "#LSX"

Detailed Description

A LSX file is a high performance ASCII file that contains a list of image numbers and file names.

Each line of a LSX file has the following format: after the #LSX magic number are 2 lines, the second line containing # comment # line-length Denoting the length of each line in the file. If writing additional lines to the file, this length must not be exceeded.

Additional '#' comment lines are NOT permitted within the file

lines have the form: reference_image_index reference-image-filename comments

Definition at line 58 of file lstfastio.h.


Constructor & Destructor Documentation

LstFastIO::LstFastIO ( const string &  filename,
IOMode  rw_mode = READ_ONLY 
) [explicit]
LstFastIO::~LstFastIO ( )

Definition at line 68 of file lstfastio.cpp.

References imageio, lst_file, and ref_filename.

{
        if (lst_file) {
                fclose(lst_file);
                lst_file = 0;
        }
        ref_filename = "";
        if(imageio) {
                delete imageio;
                imageio = 0;
        }
}

Member Function Documentation

int LstFastIO::calc_ref_image_index ( int  image_index) [private]

Definition at line 132 of file lstfastio.cpp.

References FileAccessException, filename, EMAN::EMUtil::get_imageio(), head_length, imageio, EMAN::Util::is_file_exist(), last_lst_index, last_ref_index, line_length, LOGERR, lst_file, ref_filename, and rw_mode.

{
        if (image_index == last_lst_index) {
                return last_ref_index;
        }
        else {
                char buf[MAXPATHLEN];

                fseek(lst_file,head_length+line_length*image_index,SEEK_SET);
                if (!fgets(buf, MAXPATHLEN, lst_file)) {
                        LOGERR("reach EOF in file '%s' before reading %dth image",
                                   filename.c_str(), image_index);
                        return 1;
                }

                int ref_image_index = 0;
                char ref_image_path[MAXPATHLEN];
                char unused[256];
                sscanf(buf, " %d %s %[ .,0-9-]", &ref_image_index, ref_image_path, unused);

                char fullpath[MAXPATHLEN];

                char sep = '/';
#ifdef WIN32
                sep = '\\';
#endif
//              if (ref_image_path[0] == sep) {
                        strcpy(fullpath, ref_image_path);
//              }
//              else {
//                      if (strrchr(filename.c_str(), sep)) {
//                              strcpy(fullpath, filename.c_str());
//                      }
//                      else {
// #ifndef WIN32
//                              getcwd(fullpath, MAXPATHLEN);
// #else
//                              //GetCurrentDirectory(MAXPATHLEN, fullpath);
// #endif
//                      }
// 
//                      char *p_basename = strrchr(fullpath, sep);
//                      if (p_basename) {
//                              //p_basename++;
//                              //*p_basename = '\0';
//                              char ssep[2];
//                              ssep[0] = sep;
//                              ssep[1] = '\0';
//                              strcat(fullpath, ssep);
//                              strcat(fullpath, ref_image_path);
//                      }
//              }

                ref_filename = string(fullpath);
                if (!Util::is_file_exist(ref_filename)) throw FileAccessException(ref_filename);
                imageio = EMUtil::get_imageio(ref_filename, rw_mode);

                last_ref_index = ref_image_index;
        }
//      printf("%d\t%d\t%s\n",image_index,last_ref_index,ref_filename.c_str());

        last_lst_index = image_index;

        return last_ref_index;
}
int LstFastIO::get_nimg ( ) [virtual]

Return the number of images in this image file.

Reimplemented from EMAN::ImageIO.

Definition at line 258 of file lstfastio.cpp.

References EMAN::ImageIO::init(), and nimg.

{
        init();
        return nimg;
}
bool EMAN::LstFastIO::is_single_image_format ( ) const [inline, virtual]

Is this image format only storing 1 image or not.

Some image formats like MRC only store 1 image in a file, so this function returns 'true' for them. Other image formats like IMAGIC/HDF5 may store mutliple images, so this function returns 'false' for them.

Reimplemented from EMAN::ImageIO.

Definition at line 67 of file lstfastio.h.

                {
                        return false;
                }
bool LstFastIO::is_valid ( const void *  first_block) [static]

Definition at line 116 of file lstfastio.cpp.

References EMAN::Util::check_file_by_magic(), ENTERFUNC, EXITFUNC, and MAGIC.

Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type().

{
        ENTERFUNC;
        bool result = false;

        if (!first_block) {
                result = false;
        }
        else {
                result = Util::check_file_by_magic(first_block, MAGIC);
        }

        EXITFUNC;
        return result;
}

Member Data Documentation

Definition at line 64 of file lstfastio.h.

string EMAN::LstFastIO::filename [private]

Definition at line 73 of file lstfastio.h.

Referenced by calc_ref_image_index().

unsigned int EMAN::LstFastIO::head_length [private]

Definition at line 81 of file lstfastio.h.

Referenced by calc_ref_image_index().

Definition at line 83 of file lstfastio.h.

Referenced by calc_ref_image_index(), LstFastIO(), and ~LstFastIO().

Definition at line 78 of file lstfastio.h.

Referenced by LstFastIO().

Definition at line 77 of file lstfastio.h.

Referenced by LstFastIO().

Definition at line 86 of file lstfastio.h.

Referenced by calc_ref_image_index(), and LstFastIO().

Definition at line 87 of file lstfastio.h.

Referenced by calc_ref_image_index(), and LstFastIO().

unsigned int EMAN::LstFastIO::line_length [private]

Definition at line 80 of file lstfastio.h.

Referenced by calc_ref_image_index().

FILE* EMAN::LstFastIO::lst_file [private]

Definition at line 75 of file lstfastio.h.

Referenced by calc_ref_image_index(), and ~LstFastIO().

const char * LstFastIO::MAGIC = "#LSX" [static, private]

Definition at line 90 of file lstfastio.h.

Referenced by is_valid().

int EMAN::LstFastIO::nimg [private]

Definition at line 79 of file lstfastio.h.

Referenced by get_nimg(), and LstFastIO().

Definition at line 84 of file lstfastio.h.

Referenced by calc_ref_image_index(), LstFastIO(), and ~LstFastIO().

Definition at line 74 of file lstfastio.h.

Referenced by calc_ref_image_index().


The documentation for this class was generated from the following files: