#include <reconstructor.h>
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 |
Definition at line 1128 of file reconstructor.h.
file_store::file_store | ( | const string & | filename, | |
int | npad, | |||
int | write, | |||
bool | CTF | |||
) |
Definition at line 3539 of file reconstructor.cpp.
References m_ctf, m_npad, m_prev, and m_write.
03540 : m_bin_file(filename + ".bin"), 03541 m_txt_file(filename + ".txt") 03542 { 03543 m_ctf = ctf; 03544 m_prev = -1; 03545 m_npad = npad; 03546 m_write = write; 03547 }
file_store::~file_store | ( | ) | [virtual] |
Definition at line 3553 of file reconstructor.cpp.
References checked_delete(), data, EMAN::Dict::get(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), 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, tf(), and EMAN::Ctf::to_dict().
03554 { 03555 03556 EMData* padfft = padfft_slice( emdata, tf, m_npad ); 03557 03558 float* data = padfft->get_data(); 03559 03560 if( m_write && m_bin_ohandle == NULL ) 03561 { 03562 m_bin_ohandle = shared_ptr< ofstream >( new ofstream(m_bin_file.c_str(), std::ios::out | std::ios::binary) ); 03563 m_txt_ohandle = shared_ptr< ofstream >( new ofstream(m_txt_file.c_str() ) ); 03564 if( m_ctf ) 03565 *m_txt_ohandle << "Cs pixel voltage ctf_applied amp_contrast defocus "; 03566 03567 *m_txt_ohandle << "phi theta psi" << std::endl; 03568 } 03569 03570 m_x_out = padfft->get_xsize(); 03571 m_y_out = padfft->get_ysize(); 03572 m_z_out = padfft->get_zsize(); 03573 m_totsize = m_x_out*m_y_out*m_z_out; 03574 03575 if( m_ctf ) 03576 { 03577 Ctf* ctf = padfft->get_attr( "ctf" ); 03578 Dict ctf_params = ctf->to_dict(); 03579 03580 m_ctf_applied = padfft->get_attr( "ctf_applied" ); 03581 03582 m_Cs = ctf_params["cs"]; 03583 m_pixel = ctf_params["apix"]; 03584 m_voltage = ctf_params["voltage"]; 03585 m_amp_contrast = ctf_params["ampcont"]; 03586 m_defocuses.push_back( ctf_params["defocus"] ); 03587 if(ctf) {delete ctf; ctf=0;} 03588 } 03589 03590 Dict params = tf.get_rotation( "spider" ); 03591 float phi = params.get( "phi" ); 03592 float tht = params.get( "theta" ); 03593 float psi = params.get( "psi" ); 03594 03595 03596 m_phis.push_back( phi ); 03597 m_thetas.push_back( tht ); 03598 m_psis.push_back( psi ); 03599 03600 if( m_write ) 03601 { 03602 m_bin_ohandle->write( (char*)data, sizeof(float)*m_totsize ); 03603 03604 if( m_ctf ) 03605 { 03606 *m_txt_ohandle << m_Cs << " "; 03607 *m_txt_ohandle << m_pixel << " "; 03608 *m_txt_ohandle << m_voltage << " "; 03609 *m_txt_ohandle << m_ctf_applied << " "; 03610 *m_txt_ohandle << m_amp_contrast << " "; 03611 *m_txt_ohandle << m_defocuses.back() << " "; 03612 } 03613 *m_txt_ohandle << m_phis.back() << " "; 03614 *m_txt_ohandle << m_thetas.back() << " "; 03615 *m_txt_ohandle << m_psis.back() << " "; 03616 *m_txt_ohandle << m_x_out << " "; 03617 *m_txt_ohandle << m_y_out << " "; 03618 *m_txt_ohandle << m_z_out << " "; 03619 *m_txt_ohandle << m_totsize << std::endl; 03620 } 03621 03622 checked_delete(padfft); 03623 03624 }
void file_store::get_image | ( | int | id, | |
EMData * | padfft | |||
) |
Definition at line 3626 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().
03627 { 03628 03629 if( m_phis.size() == 0 ) { 03630 ifstream m_txt_ifs( m_txt_file.c_str() ); 03631 03632 if( !m_txt_ifs ) 03633 { 03634 std::cerr << "Error: file " << m_txt_file << " does not exist" << std::endl; 03635 } 03636 03637 string line; 03638 std::getline( m_txt_ifs, line ); 03639 03640 float first, defocus, phi, theta, psi; 03641 03642 03643 03644 while( m_txt_ifs >> first ) { 03645 03646 if( m_ctf ) 03647 { 03648 m_Cs = first; 03649 m_txt_ifs >> m_pixel >> m_voltage; 03650 m_txt_ifs >> m_ctf_applied >> m_amp_contrast; 03651 m_txt_ifs >> defocus >> phi >> theta >> psi; 03652 m_defocuses.push_back( defocus ); 03653 } 03654 else 03655 { 03656 phi = first; 03657 m_txt_ifs >> theta >> psi; 03658 } 03659 03660 m_txt_ifs >> m_x_out >> m_y_out >> m_z_out >> m_totsize; 03661 m_phis.push_back( phi ); 03662 m_thetas.push_back( theta ); 03663 m_psis.push_back( psi ); 03664 } 03665 } 03666 03667 Assert( m_ihandle != NULL ); 03668 03669 std::istream::off_type offset = id*sizeof(float)*m_totsize; 03670 Assert( offset >= 0 ); 03671 03672 if( offset > 0 ) 03673 { 03674 m_ihandle->seekg(offset, std::ios::beg); 03675 } 03676 03677 if( m_ihandle->bad() ) 03678 { 03679 std::cout << "bad while fetching id, offset: " << id << " " << offset << std::endl; 03680 throw std::logic_error( "bad happen" ); 03681 } 03682 03683 if( m_ihandle->fail() ) 03684 { 03685 std::cout << "fail while fetching id, offset, curoff: " << id << " " << offset << std::endl; 03686 throw std::logic_error( "fail happen" ); 03687 } 03688 03689 if( m_ihandle->eof() ) 03690 { 03691 std::cout << "eof while fetching id, offset: " << id << " " << offset << std::endl; 03692 throw std::logic_error( "eof happen" ); 03693 } 03694 03695 if( padfft->get_xsize() != m_x_out || 03696 padfft->get_ysize() != m_y_out || 03697 padfft->get_zsize() != m_z_out ) 03698 { 03699 padfft->set_size(m_x_out, m_y_out, m_z_out); 03700 } 03701 03702 char* data = (char*)(padfft->get_data()); 03703 m_ihandle->read( data, sizeof(float)*m_totsize ); 03704 padfft->update(); 03705 03706 if( m_ctf ) 03707 { 03708 padfft->set_attr( "Cs", m_Cs ); 03709 padfft->set_attr( "Pixel_size", m_pixel ); 03710 padfft->set_attr( "voltage", m_voltage ); 03711 padfft->set_attr( "ctf_applied", m_ctf_applied ); 03712 padfft->set_attr( "amp_contrast", m_amp_contrast ); 03713 padfft->set_attr( "defocus", m_defocuses[id] ); 03714 } 03715 03716 padfft->set_attr( "padffted", 1 ); 03717 padfft->set_attr( "phi", m_phis[id] ); 03718 padfft->set_attr( "theta", m_thetas[id] ); 03719 padfft->set_attr( "psi", m_psis[id] ); 03720 03721 }
void file_store::restart | ( | ) |
Definition at line 3723 of file reconstructor.cpp.
References in, m_bin_file, and m_ihandle.
03724 { 03725 if( m_ihandle == NULL ) 03726 { 03727 m_ihandle = shared_ptr< ifstream >( new ifstream(m_bin_file.c_str(), std::ios::in | std::ios::binary) ); 03728 } 03729 03730 if( m_ihandle->bad() || m_ihandle->fail() || m_ihandle->eof() ) 03731 { 03732 m_ihandle->open( m_bin_file.c_str(), std::ios::binary ); 03733 } 03734 03735 m_ihandle->seekg( 0, std::ios::beg ); 03736 }
float EMAN::file_store::m_amp_contrast [private] |
string EMAN::file_store::m_bin_file [private] |
shared_ptr<std::ofstream> EMAN::file_store::m_bin_ohandle [private] |
float EMAN::file_store::m_Cs [private] |
int EMAN::file_store::m_ctf [private] |
Definition at line 1146 of file reconstructor.h.
Referenced by add_image(), file_store(), and get_image().
float EMAN::file_store::m_ctf_applied [private] |
vector< float > EMAN::file_store::m_defocuses [private] |
shared_ptr<std::ifstream> EMAN::file_store::m_ihandle [private] |
int EMAN::file_store::m_npad [private] |
vector< float > EMAN::file_store::m_phis [private] |
float EMAN::file_store::m_pixel [private] |
int EMAN::file_store::m_prev [private] |
vector< float > EMAN::file_store::m_psis [private] |
vector< float > EMAN::file_store::m_thetas [private] |
std::istream::off_type EMAN::file_store::m_totsize [private] |
string EMAN::file_store::m_txt_file [private] |
shared_ptr<std::ofstream> EMAN::file_store::m_txt_ohandle [private] |
float EMAN::file_store::m_voltage [private] |
int EMAN::file_store::m_write [private] |
int EMAN::file_store::m_x_out [private] |
int EMAN::file_store::m_y_out [private] |
int EMAN::file_store::m_z_out [private] |