#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 1337 of file reconstructor.h.
file_store::file_store | ( | const string & | filename, | |
int | npad, | |||
int | write, | |||
bool | CTF | |||
) |
Definition at line 4392 of file reconstructor.cpp.
References m_ctf, m_npad, m_prev, and m_write.
04393 : m_bin_file(filename + ".bin"), 04394 m_txt_file(filename + ".txt") 04395 { 04396 m_ctf = ctf; 04397 m_prev = -1; 04398 m_npad = npad; 04399 m_write = write; 04400 }
file_store::~file_store | ( | ) | [virtual] |
Definition at line 4406 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().
04407 { 04408 04409 EMData* padfft = padfft_slice( emdata, tf, m_npad ); 04410 04411 float* data = padfft->get_data(); 04412 04413 if( m_write && m_bin_ohandle == NULL ) 04414 { 04415 m_bin_ohandle = shared_ptr< ofstream >( new ofstream(m_bin_file.c_str(), std::ios::out | std::ios::binary) ); 04416 m_txt_ohandle = shared_ptr< ofstream >( new ofstream(m_txt_file.c_str() ) ); 04417 if( m_ctf ) 04418 *m_txt_ohandle << "Cs pixel voltage ctf_applied amp_contrast defocus "; 04419 04420 *m_txt_ohandle << "phi theta psi" << std::endl; 04421 } 04422 04423 m_x_out = padfft->get_xsize(); 04424 m_y_out = padfft->get_ysize(); 04425 m_z_out = padfft->get_zsize(); 04426 m_totsize = m_x_out*m_y_out*m_z_out; 04427 04428 if( m_ctf ) 04429 { 04430 Ctf* ctf = padfft->get_attr( "ctf" ); 04431 Dict ctf_params = ctf->to_dict(); 04432 04433 m_ctf_applied = padfft->get_attr( "ctf_applied" ); 04434 04435 m_Cs = ctf_params["cs"]; 04436 m_pixel = ctf_params["apix"]; 04437 m_voltage = ctf_params["voltage"]; 04438 m_amp_contrast = ctf_params["ampcont"]; 04439 m_defocuses.push_back( ctf_params["defocus"] ); 04440 if(ctf) {delete ctf; ctf=0;} 04441 } 04442 04443 Dict params = tf.get_rotation( "spider" ); 04444 float phi = params.get( "phi" ); 04445 float tht = params.get( "theta" ); 04446 float psi = params.get( "psi" ); 04447 04448 04449 m_phis.push_back( phi ); 04450 m_thetas.push_back( tht ); 04451 m_psis.push_back( psi ); 04452 04453 if( m_write ) 04454 { 04455 m_bin_ohandle->write( (char*)data, sizeof(float)*m_totsize ); 04456 04457 if( m_ctf ) 04458 { 04459 *m_txt_ohandle << m_Cs << " "; 04460 *m_txt_ohandle << m_pixel << " "; 04461 *m_txt_ohandle << m_voltage << " "; 04462 *m_txt_ohandle << m_ctf_applied << " "; 04463 *m_txt_ohandle << m_amp_contrast << " "; 04464 *m_txt_ohandle << m_defocuses.back() << " "; 04465 } 04466 *m_txt_ohandle << m_phis.back() << " "; 04467 *m_txt_ohandle << m_thetas.back() << " "; 04468 *m_txt_ohandle << m_psis.back() << " "; 04469 *m_txt_ohandle << m_x_out << " "; 04470 *m_txt_ohandle << m_y_out << " "; 04471 *m_txt_ohandle << m_z_out << " "; 04472 *m_txt_ohandle << m_totsize << std::endl; 04473 } 04474 04475 checked_delete(padfft); 04476 04477 }
void file_store::get_image | ( | int | id, | |
EMData * | padfft | |||
) |
Definition at line 4479 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().
04480 { 04481 04482 if( m_phis.size() == 0 ) { 04483 ifstream m_txt_ifs( m_txt_file.c_str() ); 04484 04485 if( !m_txt_ifs ) 04486 { 04487 std::cerr << "Error: file " << m_txt_file << " does not exist" << std::endl; 04488 } 04489 04490 string line; 04491 std::getline( m_txt_ifs, line ); 04492 04493 float first, defocus, phi, theta, psi; 04494 04495 04496 04497 while( m_txt_ifs >> first ) { 04498 04499 if( m_ctf ) 04500 { 04501 m_Cs = first; 04502 m_txt_ifs >> m_pixel >> m_voltage; 04503 m_txt_ifs >> m_ctf_applied >> m_amp_contrast; 04504 m_txt_ifs >> defocus >> phi >> theta >> psi; 04505 m_defocuses.push_back( defocus ); 04506 } 04507 else 04508 { 04509 phi = first; 04510 m_txt_ifs >> theta >> psi; 04511 } 04512 04513 m_txt_ifs >> m_x_out >> m_y_out >> m_z_out >> m_totsize; 04514 m_phis.push_back( phi ); 04515 m_thetas.push_back( theta ); 04516 m_psis.push_back( psi ); 04517 } 04518 } 04519 04520 Assert( m_ihandle != NULL ); 04521 04522 std::istream::off_type offset = id*sizeof(float)*m_totsize; 04523 Assert( offset >= 0 ); 04524 04525 if( offset > 0 ) 04526 { 04527 m_ihandle->seekg(offset, std::ios::beg); 04528 } 04529 04530 if( m_ihandle->bad() ) 04531 { 04532 std::cout << "bad while fetching id, offset: " << id << " " << offset << std::endl; 04533 throw std::logic_error( "bad happen" ); 04534 } 04535 04536 if( m_ihandle->fail() ) 04537 { 04538 std::cout << "fail while fetching id, offset, curoff: " << id << " " << offset << std::endl; 04539 throw std::logic_error( "fail happen" ); 04540 } 04541 04542 if( m_ihandle->eof() ) 04543 { 04544 std::cout << "eof while fetching id, offset: " << id << " " << offset << std::endl; 04545 throw std::logic_error( "eof happen" ); 04546 } 04547 04548 if( padfft->get_xsize() != m_x_out || 04549 padfft->get_ysize() != m_y_out || 04550 padfft->get_zsize() != m_z_out ) 04551 { 04552 padfft->set_size(m_x_out, m_y_out, m_z_out); 04553 } 04554 04555 char* data = (char*)(padfft->get_data()); 04556 m_ihandle->read( data, sizeof(float)*m_totsize ); 04557 padfft->update(); 04558 04559 if( m_ctf ) 04560 { 04561 padfft->set_attr( "Cs", m_Cs ); 04562 padfft->set_attr( "Pixel_size", m_pixel ); 04563 padfft->set_attr( "voltage", m_voltage ); 04564 padfft->set_attr( "ctf_applied", m_ctf_applied ); 04565 padfft->set_attr( "amp_contrast", m_amp_contrast ); 04566 padfft->set_attr( "defocus", m_defocuses[id] ); 04567 } 04568 04569 padfft->set_attr( "padffted", 1 ); 04570 padfft->set_attr( "phi", m_phis[id] ); 04571 padfft->set_attr( "theta", m_thetas[id] ); 04572 padfft->set_attr( "psi", m_psis[id] ); 04573 04574 }
void file_store::restart | ( | ) |
Definition at line 4576 of file reconstructor.cpp.
References in, m_bin_file, and m_ihandle.
04577 { 04578 if( m_ihandle == NULL ) 04579 { 04580 m_ihandle = shared_ptr< ifstream >( new ifstream(m_bin_file.c_str(), std::ios::in | std::ios::binary) ); 04581 } 04582 04583 if( m_ihandle->bad() || m_ihandle->fail() || m_ihandle->eof() ) 04584 { 04585 m_ihandle->open( m_bin_file.c_str(), std::ios::binary ); 04586 } 04587 04588 m_ihandle->seekg( 0, std::ios::beg ); 04589 }
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 1355 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] |