EMAN2
Public Member Functions | Private Attributes
EMAN::file_store Class Reference

#include <reconstructor.h>

Collaboration diagram for EMAN::file_store:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 file_store (const string &filename, int npad, int write, bool CTF)
virtual ~file_store ()
void add_image (EMData *data, const Transform &tf)
void get_image (int id, EMData *padfft)
void restart ()

Private Attributes

shared_ptr< std::ifstream > m_ihandle
shared_ptr< std::ofstream > m_bin_ohandle
shared_ptr< std::ofstream > m_txt_ohandle
string m_bin_file
string m_txt_file
int m_ctf
int m_npad
int m_prev
int m_x_out
int m_y_out
int m_z_out
int m_write
std::istream::off_type m_totsize
float m_Cs
float m_pixel
float m_voltage
float m_ctf_applied
float m_amp_contrast
vector< float > m_defocuses
vector< float > m_phis
vector< float > m_thetas
vector< float > m_psis

Detailed Description

Definition at line 1630 of file reconstructor.h.


Constructor & Destructor Documentation

file_store::file_store ( const string &  filename,
int  npad,
int  write,
bool  CTF 
)

Definition at line 4635 of file reconstructor.cpp.

References m_ctf, m_npad, m_prev, and m_write.

    : m_bin_file(filename + ".bin"),
      m_txt_file(filename + ".txt")
{
    m_ctf = ctf;
    m_prev = -1;
    m_npad = npad;
    m_write = write;
}
file_store::~file_store ( ) [virtual]

Definition at line 4645 of file reconstructor.cpp.

{
}

Member Function Documentation

void file_store::add_image ( EMData data,
const Transform tf 
)

Definition at line 4649 of file reconstructor.cpp.

References checked_delete(), data, EMAN::Dict::get(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::Transform::get_rotation(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), m_amp_contrast, m_bin_file, m_bin_ohandle, m_Cs, m_ctf, m_ctf_applied, m_defocuses, m_npad, m_phis, m_pixel, m_psis, m_thetas, m_totsize, m_txt_file, m_txt_ohandle, m_voltage, m_write, m_x_out, m_y_out, m_z_out, EMAN::padfft_slice(), phi, and EMAN::Ctf::to_dict().

{

    EMData* padfft = padfft_slice( emdata, tf, m_npad );

    float* data = padfft->get_data();

    if( m_write && m_bin_ohandle == NULL )
    {
        m_bin_ohandle = shared_ptr< ofstream >( new ofstream(m_bin_file.c_str(), std::ios::out | std::ios::binary) );
        m_txt_ohandle = shared_ptr< ofstream >( new ofstream(m_txt_file.c_str() ) );
        if( m_ctf )
                 *m_txt_ohandle << "Cs pixel voltage ctf_applied amp_contrast defocus ";

        *m_txt_ohandle << "phi theta psi" << std::endl;
    }

    m_x_out = padfft->get_xsize();
    m_y_out = padfft->get_ysize();
    m_z_out = padfft->get_zsize();
    m_totsize = m_x_out*m_y_out*m_z_out;

    if( m_ctf )
    {
        Ctf* ctf = padfft->get_attr( "ctf" );
        Dict ctf_params = ctf->to_dict();

        m_ctf_applied = padfft->get_attr( "ctf_applied" );

        m_Cs = ctf_params["cs"];
        m_pixel = ctf_params["apix"];
        m_voltage = ctf_params["voltage"];
        m_amp_contrast = ctf_params["ampcont"];
        m_defocuses.push_back( ctf_params["defocus"] );
        if(ctf) {delete ctf; ctf=0;}
    }

    Dict params = tf.get_rotation( "spider" );
    float phi = params.get( "phi" );
    float tht = params.get( "theta" );
    float psi = params.get( "psi" );


    m_phis.push_back( phi );
    m_thetas.push_back( tht );
    m_psis.push_back( psi );

    if( m_write )
    {
        m_bin_ohandle->write( (char*)data, sizeof(float)*m_totsize );

        if( m_ctf )
        {
            *m_txt_ohandle << m_Cs << " ";
            *m_txt_ohandle << m_pixel << " ";
            *m_txt_ohandle << m_voltage << " ";
            *m_txt_ohandle << m_ctf_applied << " ";
            *m_txt_ohandle << m_amp_contrast << " ";
            *m_txt_ohandle << m_defocuses.back() << " ";
        }
        *m_txt_ohandle << m_phis.back() << " ";
        *m_txt_ohandle << m_thetas.back() << " ";
        *m_txt_ohandle << m_psis.back() << " ";
        *m_txt_ohandle << m_x_out << " ";
        *m_txt_ohandle << m_y_out << " ";
        *m_txt_ohandle << m_z_out << " ";
        *m_txt_ohandle << m_totsize << std::endl;
    }

    checked_delete(padfft);

}
void file_store::get_image ( int  id,
EMData padfft 
)

Definition at line 4722 of file reconstructor.cpp.

References Assert, data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), m_amp_contrast, m_Cs, m_ctf, m_ctf_applied, m_defocuses, m_ihandle, m_phis, m_pixel, m_psis, m_thetas, m_totsize, m_txt_file, m_voltage, m_x_out, m_y_out, m_z_out, phi, EMAN::EMData::set_attr(), EMAN::EMData::set_size(), theta, and EMAN::EMData::update().

{

    if( m_phis.size() == 0 ) {
        ifstream m_txt_ifs( m_txt_file.c_str() );

        if( !m_txt_ifs )
        {
            std::cerr << "Error: file " << m_txt_file << " does not exist" << std::endl;
        }

        string line;
        std::getline( m_txt_ifs, line );

        float first, defocus, phi, theta, psi;



        while( m_txt_ifs >> first ) {

            if( m_ctf )
            {
                m_Cs = first;
                m_txt_ifs >> m_pixel >> m_voltage;
                m_txt_ifs >> m_ctf_applied >> m_amp_contrast;
                m_txt_ifs >> defocus >> phi >> theta >> psi;
                m_defocuses.push_back( defocus );
            }
            else
            {
                phi = first;
                m_txt_ifs >> theta >> psi;
            }

            m_txt_ifs >> m_x_out >> m_y_out >> m_z_out >> m_totsize;
            m_phis.push_back( phi );
            m_thetas.push_back( theta );
            m_psis.push_back( psi );
        }
    }

    Assert( m_ihandle != NULL );

    std::istream::off_type offset = id*sizeof(float)*m_totsize;
    Assert( offset >= 0 );

    if( offset > 0 )
    {
        m_ihandle->seekg(offset, std::ios::beg);
    }

    if( m_ihandle->bad() )
    {
        std::cout << "bad while fetching id, offset: " << id << " " << offset << std::endl;
        throw std::logic_error( "bad happen" );
    }

    if( m_ihandle->fail() )
    {
        std::cout << "fail while fetching id, offset, curoff: " << id << " " << offset << std::endl;
        throw std::logic_error( "fail happen" );
    }

    if( m_ihandle->eof() )
    {
        std::cout << "eof while fetching id, offset: " << id << " " << offset << std::endl;
        throw std::logic_error( "eof happen" );
    }

    if( padfft->get_xsize() != m_x_out ||
        padfft->get_ysize() != m_y_out ||
        padfft->get_zsize() != m_z_out )
    {
        padfft->set_size(m_x_out, m_y_out, m_z_out);
    }

    char* data = (char*)(padfft->get_data());
    m_ihandle->read( data, sizeof(float)*m_totsize );
    padfft->update();

    if( m_ctf )
    {
        padfft->set_attr( "Cs", m_Cs );
        padfft->set_attr( "Pixel_size", m_pixel );
        padfft->set_attr( "voltage", m_voltage );
        padfft->set_attr( "ctf_applied", m_ctf_applied );
        padfft->set_attr( "amp_contrast", m_amp_contrast );
        padfft->set_attr( "defocus", m_defocuses[id] );
    }

    padfft->set_attr( "padffted", 1 );
    padfft->set_attr( "phi", m_phis[id] );
    padfft->set_attr( "theta", m_thetas[id] );
    padfft->set_attr( "psi", m_psis[id] );

}
void file_store::restart ( )

Definition at line 4819 of file reconstructor.cpp.

References in, m_bin_file, and m_ihandle.

{
    if( m_ihandle == NULL )
    {
        m_ihandle = shared_ptr< ifstream >( new ifstream(m_bin_file.c_str(), std::ios::in | std::ios::binary) );
    }

    if( m_ihandle->bad() || m_ihandle->fail() || m_ihandle->eof() )
    {
        m_ihandle->open( m_bin_file.c_str(), std::ios::binary );
    }

    m_ihandle->seekg( 0, std::ios::beg );
}

Member Data Documentation

Definition at line 1660 of file reconstructor.h.

Referenced by add_image(), and get_image().

string EMAN::file_store::m_bin_file [private]

Definition at line 1646 of file reconstructor.h.

Referenced by add_image(), and restart().

shared_ptr<std::ofstream> EMAN::file_store::m_bin_ohandle [private]

Definition at line 1644 of file reconstructor.h.

Referenced by add_image().

float EMAN::file_store::m_Cs [private]

Definition at line 1656 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_ctf [private]

Definition at line 1648 of file reconstructor.h.

Referenced by add_image(), file_store(), and get_image().

Definition at line 1659 of file reconstructor.h.

Referenced by add_image(), and get_image().

vector< float > EMAN::file_store::m_defocuses [private]

Definition at line 1661 of file reconstructor.h.

Referenced by add_image(), and get_image().

shared_ptr<std::ifstream> EMAN::file_store::m_ihandle [private]

Definition at line 1643 of file reconstructor.h.

Referenced by get_image(), and restart().

int EMAN::file_store::m_npad [private]

Definition at line 1649 of file reconstructor.h.

Referenced by add_image(), and file_store().

vector< float > EMAN::file_store::m_phis [private]

Definition at line 1662 of file reconstructor.h.

Referenced by add_image(), and get_image().

float EMAN::file_store::m_pixel [private]

Definition at line 1657 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_prev [private]

Definition at line 1650 of file reconstructor.h.

Referenced by file_store().

vector< float > EMAN::file_store::m_psis [private]

Definition at line 1664 of file reconstructor.h.

Referenced by add_image(), and get_image().

vector< float > EMAN::file_store::m_thetas [private]

Definition at line 1663 of file reconstructor.h.

Referenced by add_image(), and get_image().

std::istream::off_type EMAN::file_store::m_totsize [private]

Definition at line 1655 of file reconstructor.h.

Referenced by add_image(), and get_image().

string EMAN::file_store::m_txt_file [private]

Definition at line 1647 of file reconstructor.h.

Referenced by add_image(), and get_image().

shared_ptr<std::ofstream> EMAN::file_store::m_txt_ohandle [private]

Definition at line 1645 of file reconstructor.h.

Referenced by add_image().

float EMAN::file_store::m_voltage [private]

Definition at line 1658 of file reconstructor.h.

Referenced by add_image(), and get_image().

Definition at line 1654 of file reconstructor.h.

Referenced by add_image(), and file_store().

Definition at line 1651 of file reconstructor.h.

Referenced by add_image(), and get_image().

Definition at line 1652 of file reconstructor.h.

Referenced by add_image(), and get_image().

Definition at line 1653 of file reconstructor.h.

Referenced by add_image(), and get_image().


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