EMAN2
Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Attributes | List of all members
EMAN::DM4IO Class Reference

Gatan DM$ was introduced with the GMS 2.0 release. More...

#include <dm4io.h>

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

Public Member Functions

 DM4IO (const string &fname, IOMode rw_mode=READ_ONLY)
 
 ~DM4IO ()
 
int get_nimg ()
 Return the number of images in this image file. More...
 
- Public Member Functions inherited from EMAN::ImageIO
 ImageIO (const string &fname, IOMode rw)
 
virtual ~ImageIO ()
 
virtual int read_header (Dict &dict, int image_index=0, const Region *area=0, bool is_3d=false)=0
 Read the header from an image. More...
 
virtual int write_header (const Dict &dict, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)=0
 Write a header to an image. More...
 
virtual int read_data (float *data, int image_index=0, const Region *area=0, bool is_3d=false)=0
 Read the data from an image. More...
 
virtual int read_data_8bit (unsigned char *data, int image_index=0, const Region *area=0, bool is_3d=false, float minval=0.0f, float maxval=0.0f)
 Read the data from an image as an 8 bit array, regardless of format. More...
 
virtual int write_data (float *data, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)=0
 Write data to an image. More...
 
virtual int read_ctf (Ctf &ctf, int image_index=0)
 Read CTF data from this image. More...
 
virtual void write_ctf (const Ctf &ctf, int image_index=0)
 Write CTF data to this image. More...
 
virtual void flush ()=0
 Flush the IO buffer. More...
 
virtual bool is_complex_mode ()=0
 Is this an complex image or not. More...
 
virtual bool is_image_big_endian ()=0
 Is this image in big endian or not. More...
 
virtual bool is_single_image_format () const
 Is this image format only storing 1 image or not. More...
 
template<class T >
void become_host_endian (T *data, size_t n=1)
 Convert data of this image into host endian format. More...
 
string get_filename () const
 

Static Public Member Functions

static bool is_valid (const void *first_block)
 

Public Attributes

 DEFINE_IMAGEIO_FUNC
 

Private Types

enum  { NUM_ID_INT = 4 }
 

Private Attributes

bool is_big_endian
 
GatanDM4::TagTabletagtable
 

Additional Inherited Members

- Public Types inherited from EMAN::ImageIO
enum  IOMode { READ_ONLY = 1 , READ_WRITE = 2 , WRITE_ONLY = 3 }
 
- Protected Member Functions inherited from EMAN::ImageIO
virtual void init ()=0
 Do some initialization before doing the read/write. More...
 
void check_read_access (int image_index)
 Validate 'image_index' in file reading. More...
 
void check_read_access (int image_index, const float *data)
 Validate 'image_index' and 'data' in file reading. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg=0)
 Validate rw_mode and image_index in file writing. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg, const float *data)
 Validate rw_mode, image_index, and data pointer in file writing. More...
 
void check_region (const Region *area, const FloatSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
void check_region (const Region *area, const IntSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
FILE * sfopen (const string &filename, IOMode mode, bool *is_new=0, bool overwrite=false)
 Run fopen safely. More...
 
- Protected Attributes inherited from EMAN::ImageIO
string filename
 
IOMode rw_mode
 
FILE * file = nullptr
 
bool initialized = false
 

Detailed Description

Gatan DM$ was introduced with the GMS 2.0 release.

Each file starts with a TagGroupWithVersion record which saves the root TagGroup with some additional information.

Gatan DM4 file is a hierarchical binary image format. Everything in the image is a <key, value> pair, where key may be a container-type key which contains more key/value pairs. To read its header information, the whole file has to be parsed. During parsing, we check the keys that we are interested in and get their values.

The real binary data itself is also in this key/value hierarchy.

1 Gatan DM4 file contains 1 2D image.

All data is saved by default with big endian encoding.

Definition at line 249 of file dm4io.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
NUM_ID_INT 

Definition at line 260 of file dm4io.h.

260{ NUM_ID_INT = 4 }; //actually its int+long+int=16 bytes
@ NUM_ID_INT
Definition: dm4io.h:260

Constructor & Destructor Documentation

◆ DM4IO()

DM4IO::DM4IO ( const string &  fname,
IOMode  rw_mode = READ_ONLY 
)
explicit

Definition at line 742 of file dm4io.cpp.

743 : ImageIO(fname, rw)
744{
746 tagtable = new TagTable();
747}
static bool is_host_big_endian()
Definition: byteorder.cpp:40
GatanDM4::TagTable * tagtable
Definition: dm4io.h:263
bool is_big_endian
Definition: dm4io.h:262
ImageIO(const string &fname, IOMode rw)
Definition: imageio.cpp:40

References is_big_endian, EMAN::ByteOrder::is_host_big_endian(), and tagtable.

◆ ~DM4IO()

DM4IO::~DM4IO ( )

Definition at line 749 of file dm4io.cpp.

750{
751 if (file) {
752 fclose(file);
753 file = 0;
754 }
755 if (tagtable) {
756 delete tagtable;
757 tagtable = 0;
758 }
759}
FILE * file
Definition: imageio.h:354

References EMAN::ImageIO::file, and tagtable.

Member Function Documentation

◆ get_nimg()

int DM4IO::get_nimg ( )
virtual

Return the number of images in this image file.

Reimplemented from EMAN::ImageIO.

Definition at line 1037 of file dm4io.cpp.

1038{
1039 init();
1040
1041 TagGroup root_group(file, tagtable, "");
1042 root_group.read_tag_group(true, 0, 1);
1043
1044 return tagtable->get_image_counted();
1045}
int get_image_counted() const
Definition: dm4io.cpp:130
virtual void init()=0
Do some initialization before doing the read/write.

References EMAN::ImageIO::file, EMAN::GatanDM4::TagTable::get_image_counted(), EMAN::ImageIO::init(), EMAN::GatanDM4::TagGroup::read_tag_group(), and tagtable.

◆ is_valid()

bool DM4IO::is_valid ( const void *  first_block)
static

Definition at line 811 of file dm4io.cpp.

812{
813 ENTERFUNC;
814
815 if (!first_block) {
816 return false;
817 }
818
819 const int *data = static_cast < const int *>(first_block);
820
821 int img_ver = data[0];
822 int byte_order = data[3];
824 ByteOrder::swap_bytes(&img_ver);
825 ByteOrder::swap_bytes(&byte_order);
826 }
827
828 if (img_ver != 4) {
829 return false;
830 }
831
832 if (byte_order != 0 && byte_order != 1) {
833 return false;
834 }
835
836 return true;
837}
static void swap_bytes(T *data, size_t n=1)
swap the byte order of data with 'n' T-type elements.
Definition: byteorder.h:131
static bool is_data_big_endian(const T *small_num_addr)
given a pointer to a reasonable small integer number, return whether the number is big endian or not.
Definition: byteorder.h:76
#define ENTERFUNC
Definition: log.h:48

References ENTERFUNC, EMAN::ByteOrder::is_data_big_endian(), EMAN::ByteOrder::is_host_big_endian(), and EMAN::ByteOrder::swap_bytes().

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

Member Data Documentation

◆ DEFINE_IMAGEIO_FUNC

EMAN::DM4IO::DEFINE_IMAGEIO_FUNC

Definition at line 255 of file dm4io.h.

◆ is_big_endian

bool EMAN::DM4IO::is_big_endian
private

Definition at line 262 of file dm4io.h.

Referenced by DM4IO().

◆ tagtable

GatanDM4::TagTable* EMAN::DM4IO::tagtable
private

Definition at line 263 of file dm4io.h.

Referenced by DM4IO(), get_nimg(), and ~DM4IO().


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