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

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

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

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]
 

Definition at line 56 of file lstfastio.cpp.

References imageio, initialized, is_big_endian, EMAN::ByteOrder::is_host_big_endian(), last_lst_index, last_ref_index, nimg, and ref_filename.

00057 :       filename(file), rw_mode(rw), lst_file(0)
00058 {
00059         is_big_endian = ByteOrder::is_host_big_endian();
00060         initialized = false;
00061         nimg = 0;
00062         imageio = 0;
00063         ref_filename = "";
00064         last_lst_index = -1;
00065         last_ref_index = -1;
00066 }

LstFastIO::~LstFastIO  ) 
 

Definition at line 68 of file lstfastio.cpp.

References imageio, lst_file, and ref_filename.

00069 {
00070         if (lst_file) {
00071                 fclose(lst_file);
00072                 lst_file = 0;
00073         }
00074         ref_filename = "";
00075         if(imageio) {
00076                 delete imageio;
00077                 imageio = 0;
00078         }
00079 }


Member Function Documentation

int LstFastIO::calc_ref_image_index int  image_index  )  [private]
 

Definition at line 132 of file lstfastio.cpp.

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

00133 {
00134         if (image_index == last_lst_index) {
00135                 return last_ref_index;
00136         }
00137         else {
00138                 char buf[MAXPATHLEN];
00139 
00140                 fseek(lst_file,head_length+line_length*image_index,SEEK_SET);
00141                 if (!fgets(buf, MAXPATHLEN, lst_file)) {
00142                         LOGERR("reach EOF in file '%s' before reading %dth image",
00143                                    filename.c_str(), image_index);
00144                         return 1;
00145                 }
00146 
00147                 int ref_image_index = 0;
00148                 char ref_image_path[MAXPATHLEN];
00149                 char unused[256];
00150                 sscanf(buf, " %d %s %[ .,0-9-]", &ref_image_index, ref_image_path, unused);
00151 
00152                 char fullpath[MAXPATHLEN];
00153 
00154                 char sep = '/';
00155 #ifdef WIN32
00156                 sep = '\\';
00157 #endif
00158                 if (ref_image_path[0] == sep) {
00159                         strcpy(fullpath, ref_image_path);
00160                 }
00161                 else {
00162                         if (strrchr(filename.c_str(), sep)) {
00163                                 strcpy(fullpath, filename.c_str());
00164                         }
00165                         else {
00166 #ifndef WIN32
00167                                 getcwd(fullpath, MAXPATHLEN);
00168 #else
00169                                 //GetCurrentDirectory(MAXPATHLEN, fullpath);
00170 #endif
00171                         }
00172 
00173                         char *p_basename = strrchr(fullpath, sep);
00174                         if (p_basename) {
00175                                 //p_basename++;
00176                                 //*p_basename = '\0';
00177                                 char ssep[2];
00178                                 ssep[0] = sep;
00179                                 ssep[1] = '\0';
00180                                 strcat(fullpath, ssep);
00181                                 strcat(fullpath, ref_image_path);
00182                         }
00183                 }
00184 
00185                 ref_filename = string(fullpath);
00186                 imageio = EMUtil::get_imageio(ref_filename, rw_mode);
00187 
00188                 last_ref_index = ref_image_index;
00189         }
00190 //      printf("%d\t%d\t%s\n",image_index,last_ref_index,ref_filename.c_str());
00191 
00192         last_lst_index = image_index;
00193 
00194         return last_ref_index;
00195 }

int LstFastIO::get_nimg  )  [virtual]
 

Return the number of images in this image file.

Reimplemented from EMAN::ImageIO.

Definition at line 255 of file lstfastio.cpp.

References EMAN::ImageIO::init().

00256 {
00257         init();
00258         return nimg;
00259 }

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.

00068                 {
00069                         return false;
00070                 }

bool LstFastIO::is_valid const void *  first_block  )  [static]
 

Definition at line 116 of file lstfastio.cpp.

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

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

00117 {
00118         ENTERFUNC;
00119         bool result = false;
00120 
00121         if (!first_block) {
00122                 result = false;
00123         }
00124         else {
00125                 result = Util::check_file_by_magic(first_block, MAGIC);
00126         }
00127 
00128         EXITFUNC;
00129         return result;
00130 }


Member Data Documentation

EMAN::LstFastIO::DEFINE_IMAGEIO_FUNC
 

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().

ImageIO* EMAN::LstFastIO::imageio [private]
 

Definition at line 83 of file lstfastio.h.

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

bool EMAN::LstFastIO::initialized [private]
 

Definition at line 78 of file lstfastio.h.

Referenced by LstFastIO().

bool EMAN::LstFastIO::is_big_endian [private]
 

Definition at line 77 of file lstfastio.h.

Referenced by LstFastIO().

int EMAN::LstFastIO::last_lst_index [private]
 

Definition at line 86 of file lstfastio.h.

Referenced by calc_ref_image_index(), and LstFastIO().

int EMAN::LstFastIO::last_ref_index [private]
 

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 54 of file lstfastio.cpp.

Referenced by is_valid().

int EMAN::LstFastIO::nimg [private]
 

Definition at line 79 of file lstfastio.h.

Referenced by LstFastIO().

string EMAN::LstFastIO::ref_filename [private]
 

Definition at line 84 of file lstfastio.h.

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

IOMode EMAN::LstFastIO::rw_mode [private]
 

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:
Generated on Tue Jun 11 13:48:09 2013 for EMAN2 by  doxygen 1.3.9.1