#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 1535 of file reconstructor.h.
file_store::file_store | ( | const string & | filename, | |
int | npad, | |||
int | write, | |||
bool | CTF | |||
) |
Definition at line 4322 of file reconstructor.cpp.
References m_ctf, m_npad, m_prev, and m_write.
04323 : m_bin_file(filename + ".bin"), 04324 m_txt_file(filename + ".txt") 04325 { 04326 m_ctf = ctf; 04327 m_prev = -1; 04328 m_npad = npad; 04329 m_write = write; 04330 }
file_store::~file_store | ( | ) | [virtual] |
Definition at line 4336 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().
04337 { 04338 04339 EMData* padfft = padfft_slice( emdata, tf, m_npad ); 04340 04341 float* data = padfft->get_data(); 04342 04343 if( m_write && m_bin_ohandle == NULL ) 04344 { 04345 m_bin_ohandle = shared_ptr< ofstream >( new ofstream(m_bin_file.c_str(), std::ios::out | std::ios::binary) ); 04346 m_txt_ohandle = shared_ptr< ofstream >( new ofstream(m_txt_file.c_str() ) ); 04347 if( m_ctf ) 04348 *m_txt_ohandle << "Cs pixel voltage ctf_applied amp_contrast defocus "; 04349 04350 *m_txt_ohandle << "phi theta psi" << std::endl; 04351 } 04352 04353 m_x_out = padfft->get_xsize(); 04354 m_y_out = padfft->get_ysize(); 04355 m_z_out = padfft->get_zsize(); 04356 m_totsize = m_x_out*m_y_out*m_z_out; 04357 04358 if( m_ctf ) 04359 { 04360 Ctf* ctf = padfft->get_attr( "ctf" ); 04361 Dict ctf_params = ctf->to_dict(); 04362 04363 m_ctf_applied = padfft->get_attr( "ctf_applied" ); 04364 04365 m_Cs = ctf_params["cs"]; 04366 m_pixel = ctf_params["apix"]; 04367 m_voltage = ctf_params["voltage"]; 04368 m_amp_contrast = ctf_params["ampcont"]; 04369 m_defocuses.push_back( ctf_params["defocus"] ); 04370 if(ctf) {delete ctf; ctf=0;} 04371 } 04372 04373 Dict params = tf.get_rotation( "spider" ); 04374 float phi = params.get( "phi" ); 04375 float tht = params.get( "theta" ); 04376 float psi = params.get( "psi" ); 04377 04378 04379 m_phis.push_back( phi ); 04380 m_thetas.push_back( tht ); 04381 m_psis.push_back( psi ); 04382 04383 if( m_write ) 04384 { 04385 m_bin_ohandle->write( (char*)data, sizeof(float)*m_totsize ); 04386 04387 if( m_ctf ) 04388 { 04389 *m_txt_ohandle << m_Cs << " "; 04390 *m_txt_ohandle << m_pixel << " "; 04391 *m_txt_ohandle << m_voltage << " "; 04392 *m_txt_ohandle << m_ctf_applied << " "; 04393 *m_txt_ohandle << m_amp_contrast << " "; 04394 *m_txt_ohandle << m_defocuses.back() << " "; 04395 } 04396 *m_txt_ohandle << m_phis.back() << " "; 04397 *m_txt_ohandle << m_thetas.back() << " "; 04398 *m_txt_ohandle << m_psis.back() << " "; 04399 *m_txt_ohandle << m_x_out << " "; 04400 *m_txt_ohandle << m_y_out << " "; 04401 *m_txt_ohandle << m_z_out << " "; 04402 *m_txt_ohandle << m_totsize << std::endl; 04403 } 04404 04405 checked_delete(padfft); 04406 04407 }
void file_store::get_image | ( | int | id, | |
EMData * | padfft | |||
) |
Definition at line 4409 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().
04410 { 04411 04412 if( m_phis.size() == 0 ) { 04413 ifstream m_txt_ifs( m_txt_file.c_str() ); 04414 04415 if( !m_txt_ifs ) 04416 { 04417 std::cerr << "Error: file " << m_txt_file << " does not exist" << std::endl; 04418 } 04419 04420 string line; 04421 std::getline( m_txt_ifs, line ); 04422 04423 float first, defocus, phi, theta, psi; 04424 04425 04426 04427 while( m_txt_ifs >> first ) { 04428 04429 if( m_ctf ) 04430 { 04431 m_Cs = first; 04432 m_txt_ifs >> m_pixel >> m_voltage; 04433 m_txt_ifs >> m_ctf_applied >> m_amp_contrast; 04434 m_txt_ifs >> defocus >> phi >> theta >> psi; 04435 m_defocuses.push_back( defocus ); 04436 } 04437 else 04438 { 04439 phi = first; 04440 m_txt_ifs >> theta >> psi; 04441 } 04442 04443 m_txt_ifs >> m_x_out >> m_y_out >> m_z_out >> m_totsize; 04444 m_phis.push_back( phi ); 04445 m_thetas.push_back( theta ); 04446 m_psis.push_back( psi ); 04447 } 04448 } 04449 04450 Assert( m_ihandle != NULL ); 04451 04452 std::istream::off_type offset = id*sizeof(float)*m_totsize; 04453 Assert( offset >= 0 ); 04454 04455 if( offset > 0 ) 04456 { 04457 m_ihandle->seekg(offset, std::ios::beg); 04458 } 04459 04460 if( m_ihandle->bad() ) 04461 { 04462 std::cout << "bad while fetching id, offset: " << id << " " << offset << std::endl; 04463 throw std::logic_error( "bad happen" ); 04464 } 04465 04466 if( m_ihandle->fail() ) 04467 { 04468 std::cout << "fail while fetching id, offset, curoff: " << id << " " << offset << std::endl; 04469 throw std::logic_error( "fail happen" ); 04470 } 04471 04472 if( m_ihandle->eof() ) 04473 { 04474 std::cout << "eof while fetching id, offset: " << id << " " << offset << std::endl; 04475 throw std::logic_error( "eof happen" ); 04476 } 04477 04478 if( padfft->get_xsize() != m_x_out || 04479 padfft->get_ysize() != m_y_out || 04480 padfft->get_zsize() != m_z_out ) 04481 { 04482 padfft->set_size(m_x_out, m_y_out, m_z_out); 04483 } 04484 04485 char* data = (char*)(padfft->get_data()); 04486 m_ihandle->read( data, sizeof(float)*m_totsize ); 04487 padfft->update(); 04488 04489 if( m_ctf ) 04490 { 04491 padfft->set_attr( "Cs", m_Cs ); 04492 padfft->set_attr( "Pixel_size", m_pixel ); 04493 padfft->set_attr( "voltage", m_voltage ); 04494 padfft->set_attr( "ctf_applied", m_ctf_applied ); 04495 padfft->set_attr( "amp_contrast", m_amp_contrast ); 04496 padfft->set_attr( "defocus", m_defocuses[id] ); 04497 } 04498 04499 padfft->set_attr( "padffted", 1 ); 04500 padfft->set_attr( "phi", m_phis[id] ); 04501 padfft->set_attr( "theta", m_thetas[id] ); 04502 padfft->set_attr( "psi", m_psis[id] ); 04503 04504 }
void file_store::restart | ( | ) |
Definition at line 4506 of file reconstructor.cpp.
References in, m_bin_file, and m_ihandle.
04507 { 04508 if( m_ihandle == NULL ) 04509 { 04510 m_ihandle = shared_ptr< ifstream >( new ifstream(m_bin_file.c_str(), std::ios::in | std::ios::binary) ); 04511 } 04512 04513 if( m_ihandle->bad() || m_ihandle->fail() || m_ihandle->eof() ) 04514 { 04515 m_ihandle->open( m_bin_file.c_str(), std::ios::binary ); 04516 } 04517 04518 m_ihandle->seekg( 0, std::ios::beg ); 04519 }
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 1553 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] |