EMAN2
Public Member Functions | Private Attributes | List of all members
EMAN::file_store Class Reference

#include <reconstructor.h>

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

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 1778 of file reconstructor.h.

Constructor & Destructor Documentation

◆ file_store()

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

Definition at line 6533 of file reconstructor.cpp.

6534 : m_bin_file(filename + ".bin"),
6535 m_txt_file(filename + ".txt")
6536{
6537 m_ctf = ctf;
6538 m_prev = -1;
6539 m_npad = npad;
6540 m_write = write;
6541}

References m_ctf, m_npad, m_prev, and m_write.

◆ ~file_store()

file_store::~file_store ( )
virtual

Definition at line 6543 of file reconstructor.cpp.

6544{
6545}

Member Function Documentation

◆ add_image()

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

Definition at line 6547 of file reconstructor.cpp.

6548{
6549
6550 EMData* padfft = padfft_slice( emdata, tf, m_npad );
6551
6552 float* data = padfft->get_data();
6553
6554 if( m_write && m_bin_ohandle == NULL )
6555 {
6556 m_bin_ohandle = shared_ptr< ofstream >( new ofstream(m_bin_file.c_str(), std::ios::out | std::ios::binary) );
6557 m_txt_ohandle = shared_ptr< ofstream >( new ofstream(m_txt_file.c_str() ) );
6558 if( m_ctf )
6559 *m_txt_ohandle << "Cs pixel voltage ctf_applied amp_contrast defocus ";
6560
6561 *m_txt_ohandle << "phi theta psi" << std::endl;
6562 }
6563
6564 m_x_out = padfft->get_xsize();
6565 m_y_out = padfft->get_ysize();
6566 m_z_out = padfft->get_zsize();
6568
6569 if( m_ctf )
6570 {
6571 Ctf* ctf = padfft->get_attr( "ctf" );
6572 Dict ctf_params = ctf->to_dict();
6573
6574 m_ctf_applied = padfft->get_attr( "ctf_applied" );
6575
6576 m_Cs = ctf_params["cs"];
6577 m_pixel = ctf_params["apix"];
6578 m_voltage = ctf_params["voltage"];
6579 m_amp_contrast = ctf_params["ampcont"];
6580 m_defocuses.push_back( ctf_params["defocus"] );
6581 if(ctf) {delete ctf; ctf=0;}
6582 }
6583
6584 Dict params = tf.get_rotation( "spider" );
6585 float phi = params.get( "phi" );
6586 float tht = params.get( "theta" );
6587 float psi = params.get( "psi" );
6588
6589
6590 m_phis.push_back( phi );
6591 m_thetas.push_back( tht );
6592 m_psis.push_back( psi );
6593
6594 if( m_write )
6595 {
6596 m_bin_ohandle->write( (char*)data, sizeof(float)*m_totsize );
6597
6598 if( m_ctf )
6599 {
6600 *m_txt_ohandle << m_Cs << " ";
6601 *m_txt_ohandle << m_pixel << " ";
6602 *m_txt_ohandle << m_voltage << " ";
6603 *m_txt_ohandle << m_ctf_applied << " ";
6604 *m_txt_ohandle << m_amp_contrast << " ";
6605 *m_txt_ohandle << m_defocuses.back() << " ";
6606 }
6607 *m_txt_ohandle << m_phis.back() << " ";
6608 *m_txt_ohandle << m_thetas.back() << " ";
6609 *m_txt_ohandle << m_psis.back() << " ";
6610 *m_txt_ohandle << m_x_out << " ";
6611 *m_txt_ohandle << m_y_out << " ";
6612 *m_txt_ohandle << m_z_out << " ";
6613 *m_txt_ohandle << m_totsize << std::endl;
6614 }
6615
6616 checked_delete(padfft);
6617
6618}
Ctf is the base class for all CTF model.
Definition: ctf.h:60
virtual Dict to_dict() const =0
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
EMObject get(const string &key) const
Get the EMObject corresponding to the particular key Probably better to just use operator[].
Definition: emobject.h:527
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
Dict get_rotation(const string &euler_type="eman") const
Get a rotation in any Euler format.
Definition: transform.cpp:829
shared_ptr< std::ofstream > m_bin_ohandle
shared_ptr< std::ofstream > m_txt_ohandle
vector< float > m_defocuses
std::istream::off_type m_totsize
vector< float > m_thetas
vector< float > m_phis
vector< float > m_psis
EMData * padfft_slice(const EMData *const slice, const Transform &t, int npad)
Direct Fourier inversion Reconstructor.
void checked_delete(T *&x)

References checked_delete(), EMAN::Dict::get(), EMAN::Transform::get_rotation(), 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(), and EMAN::Ctf::to_dict().

◆ get_image()

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

Definition at line 6620 of file reconstructor.cpp.

6621{
6622
6623 if( m_phis.size() == 0 ) {
6624 ifstream m_txt_ifs( m_txt_file.c_str() );
6625
6626 if( !m_txt_ifs ) std::cerr << "Error: file " << m_txt_file << " does not exist" << std::endl;
6627
6628
6629 string line;
6630 std::getline( m_txt_ifs, line );
6631
6632 float first, defocus, phi, theta, psi;
6633
6634
6635
6636 while( m_txt_ifs >> first ) {
6637
6638 if( m_ctf ) {
6639 m_Cs = first;
6640 m_txt_ifs >> m_pixel >> m_voltage;
6641 m_txt_ifs >> m_ctf_applied >> m_amp_contrast;
6642 m_txt_ifs >> defocus >> phi >> theta >> psi;
6643 m_defocuses.push_back( defocus );
6644 } else {
6645 phi = first;
6646 m_txt_ifs >> theta >> psi;
6647 }
6648
6649 m_txt_ifs >> m_x_out >> m_y_out >> m_z_out >> m_totsize;
6650 m_phis.push_back( phi );
6651 m_thetas.push_back( theta );
6652 m_psis.push_back( psi );
6653 }
6654 }
6655
6656 Assert( m_ihandle != NULL );
6657
6658 std::istream::off_type offset = id*sizeof(float)*m_totsize;
6659 Assert( offset >= 0 );
6660
6661 if( offset > 0 ) m_ihandle->seekg(offset, std::ios::beg);
6662
6663
6664 if( m_ihandle->bad() )
6665 {
6666 std::cout << "bad while fetching id, offset: " << id << " " << offset << std::endl;
6667 throw std::logic_error( "bad happen" );
6668 }
6669
6670 if( m_ihandle->fail() )
6671 {
6672 std::cout << "fail while fetching id, offset, curoff: " << id << " " << offset << std::endl;
6673 throw std::logic_error( "fail happen" );
6674 }
6675
6676 if( m_ihandle->eof() )
6677 {
6678 std::cout << "eof while fetching id, offset: " << id << " " << offset << std::endl;
6679 throw std::logic_error( "eof happen" );
6680 }
6681
6682 if( padfft->get_xsize() != m_x_out ||
6683 padfft->get_ysize() != m_y_out ||
6684 padfft->get_zsize() != m_z_out )
6685 {
6686 padfft->set_size(m_x_out, m_y_out, m_z_out);
6687 }
6688
6689 char* data = (char*)(padfft->get_data());
6690 m_ihandle->read( data, sizeof(float)*m_totsize );
6691 padfft->update();
6692
6693 if( m_ctf ) {
6694 padfft->set_attr( "Cs", m_Cs );
6695 padfft->set_attr( "Pixel_size", m_pixel );
6696 padfft->set_attr( "voltage", m_voltage );
6697 padfft->set_attr( "ctf_applied", m_ctf_applied );
6698 padfft->set_attr( "amp_contrast", m_amp_contrast );
6699 padfft->set_attr( "defocus", m_defocuses[id] );
6700 }
6701
6702 padfft->set_attr( "padffted", 1 );
6703 padfft->set_attr( "phi", m_phis[id] );
6704 padfft->set_attr( "theta", m_thetas[id] );
6705 padfft->set_attr( "psi", m_psis[id] );
6706
6707}
shared_ptr< std::ifstream > m_ihandle
#define Assert(s)
Define Assert() function that is effective only when -DDEBUG is used.
Definition: emassert.h:42

References Assert, 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, and m_z_out.

◆ restart()

void file_store::restart ( )

Definition at line 6709 of file reconstructor.cpp.

6710{
6711 if( m_ihandle == NULL ) m_ihandle = shared_ptr< ifstream >( new ifstream(m_bin_file.c_str(), std::ios::in | std::ios::binary) );
6712
6713
6714 if( m_ihandle->bad() || m_ihandle->fail() || m_ihandle->eof() ) m_ihandle->open( m_bin_file.c_str(), std::ios::binary );
6715
6716 m_ihandle->seekg( 0, std::ios::beg );
6717}

References m_bin_file, and m_ihandle.

Member Data Documentation

◆ m_amp_contrast

float EMAN::file_store::m_amp_contrast
private

Definition at line 1808 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_bin_file

string EMAN::file_store::m_bin_file
private

Definition at line 1794 of file reconstructor.h.

Referenced by add_image(), and restart().

◆ m_bin_ohandle

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

Definition at line 1792 of file reconstructor.h.

Referenced by add_image().

◆ m_Cs

float EMAN::file_store::m_Cs
private

Definition at line 1804 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_ctf

int EMAN::file_store::m_ctf
private

Definition at line 1796 of file reconstructor.h.

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

◆ m_ctf_applied

float EMAN::file_store::m_ctf_applied
private

Definition at line 1807 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_defocuses

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

Definition at line 1809 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_ihandle

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

Definition at line 1791 of file reconstructor.h.

Referenced by get_image(), and restart().

◆ m_npad

int EMAN::file_store::m_npad
private

Definition at line 1797 of file reconstructor.h.

Referenced by add_image(), and file_store().

◆ m_phis

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

Definition at line 1810 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_pixel

float EMAN::file_store::m_pixel
private

Definition at line 1805 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_prev

int EMAN::file_store::m_prev
private

Definition at line 1798 of file reconstructor.h.

Referenced by file_store().

◆ m_psis

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

Definition at line 1812 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_thetas

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

Definition at line 1811 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_totsize

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

Definition at line 1803 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_txt_file

string EMAN::file_store::m_txt_file
private

Definition at line 1795 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_txt_ohandle

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

Definition at line 1793 of file reconstructor.h.

Referenced by add_image().

◆ m_voltage

float EMAN::file_store::m_voltage
private

Definition at line 1806 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_write

int EMAN::file_store::m_write
private

Definition at line 1802 of file reconstructor.h.

Referenced by add_image(), and file_store().

◆ m_x_out

int EMAN::file_store::m_x_out
private

Definition at line 1799 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_y_out

int EMAN::file_store::m_y_out
private

Definition at line 1800 of file reconstructor.h.

Referenced by add_image(), and get_image().

◆ m_z_out

int EMAN::file_store::m_z_out
private

Definition at line 1801 of file reconstructor.h.

Referenced by add_image(), and get_image().


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