Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::file_store Class Reference

#include <reconstructor.h>

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


Constructor & Destructor Documentation

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

Definition at line 4300 of file reconstructor.cpp.

References m_ctf, m_npad, m_prev, and m_write.

04301     : m_bin_file(filename + ".bin"),
04302       m_txt_file(filename + ".txt")
04303 {
04304     m_ctf = ctf;
04305     m_prev = -1;
04306     m_npad = npad;
04307     m_write = write;
04308 }

file_store::~file_store  )  [virtual]
 

Definition at line 4310 of file reconstructor.cpp.

04311 {
04312 }


Member Function Documentation

void file_store::add_image EMData data,
const Transform tf
 

Definition at line 4314 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_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().

04315 {
04316 
04317     EMData* padfft = padfft_slice( emdata, tf, m_npad );
04318 
04319     float* data = padfft->get_data();
04320 
04321     if( m_write && m_bin_ohandle == NULL )
04322     {
04323         m_bin_ohandle = shared_ptr< ofstream >( new ofstream(m_bin_file.c_str(), std::ios::out | std::ios::binary) );
04324         m_txt_ohandle = shared_ptr< ofstream >( new ofstream(m_txt_file.c_str() ) );
04325         if( m_ctf )
04326                  *m_txt_ohandle << "Cs pixel voltage ctf_applied amp_contrast defocus ";
04327 
04328         *m_txt_ohandle << "phi theta psi" << std::endl;
04329     }
04330 
04331     m_x_out = padfft->get_xsize();
04332     m_y_out = padfft->get_ysize();
04333     m_z_out = padfft->get_zsize();
04334     m_totsize = m_x_out*m_y_out*m_z_out;
04335 
04336     if( m_ctf )
04337     {
04338         Ctf* ctf = padfft->get_attr( "ctf" );
04339         Dict ctf_params = ctf->to_dict();
04340 
04341         m_ctf_applied = padfft->get_attr( "ctf_applied" );
04342 
04343         m_Cs = ctf_params["cs"];
04344         m_pixel = ctf_params["apix"];
04345         m_voltage = ctf_params["voltage"];
04346         m_amp_contrast = ctf_params["ampcont"];
04347         m_defocuses.push_back( ctf_params["defocus"] );
04348         if(ctf) {delete ctf; ctf=0;}
04349     }
04350 
04351     Dict params = tf.get_rotation( "spider" );
04352     float phi = params.get( "phi" );
04353     float tht = params.get( "theta" );
04354     float psi = params.get( "psi" );
04355 
04356 
04357     m_phis.push_back( phi );
04358     m_thetas.push_back( tht );
04359     m_psis.push_back( psi );
04360 
04361     if( m_write )
04362     {
04363         m_bin_ohandle->write( (char*)data, sizeof(float)*m_totsize );
04364 
04365         if( m_ctf )
04366         {
04367             *m_txt_ohandle << m_Cs << " ";
04368             *m_txt_ohandle << m_pixel << " ";
04369             *m_txt_ohandle << m_voltage << " ";
04370             *m_txt_ohandle << m_ctf_applied << " ";
04371             *m_txt_ohandle << m_amp_contrast << " ";
04372             *m_txt_ohandle << m_defocuses.back() << " ";
04373         }
04374         *m_txt_ohandle << m_phis.back() << " ";
04375         *m_txt_ohandle << m_thetas.back() << " ";
04376         *m_txt_ohandle << m_psis.back() << " ";
04377         *m_txt_ohandle << m_x_out << " ";
04378         *m_txt_ohandle << m_y_out << " ";
04379         *m_txt_ohandle << m_z_out << " ";
04380         *m_txt_ohandle << m_totsize << std::endl;
04381     }
04382 
04383     checked_delete(padfft);
04384 
04385 }

void file_store::get_image int  id,
EMData padfft
 

Definition at line 4387 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_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().

04388 {
04389 
04390     if( m_phis.size() == 0 ) {
04391         ifstream m_txt_ifs( m_txt_file.c_str() );
04392 
04393         if( !m_txt_ifs )
04394         {
04395             std::cerr << "Error: file " << m_txt_file << " does not exist" << std::endl;
04396         }
04397 
04398         string line;
04399         std::getline( m_txt_ifs, line );
04400 
04401         float first, defocus, phi, theta, psi;
04402 
04403 
04404 
04405         while( m_txt_ifs >> first ) {
04406 
04407             if( m_ctf )
04408             {
04409                 m_Cs = first;
04410                 m_txt_ifs >> m_pixel >> m_voltage;
04411                 m_txt_ifs >> m_ctf_applied >> m_amp_contrast;
04412                 m_txt_ifs >> defocus >> phi >> theta >> psi;
04413                 m_defocuses.push_back( defocus );
04414             }
04415             else
04416             {
04417                 phi = first;
04418                 m_txt_ifs >> theta >> psi;
04419             }
04420 
04421             m_txt_ifs >> m_x_out >> m_y_out >> m_z_out >> m_totsize;
04422             m_phis.push_back( phi );
04423             m_thetas.push_back( theta );
04424             m_psis.push_back( psi );
04425         }
04426     }
04427 
04428     Assert( m_ihandle != NULL );
04429 
04430     std::istream::off_type offset = id*sizeof(float)*m_totsize;
04431     Assert( offset >= 0 );
04432 
04433     if( offset > 0 )
04434     {
04435         m_ihandle->seekg(offset, std::ios::beg);
04436     }
04437 
04438     if( m_ihandle->bad() )
04439     {
04440         std::cout << "bad while fetching id, offset: " << id << " " << offset << std::endl;
04441         throw std::logic_error( "bad happen" );
04442     }
04443 
04444     if( m_ihandle->fail() )
04445     {
04446         std::cout << "fail while fetching id, offset, curoff: " << id << " " << offset << std::endl;
04447         throw std::logic_error( "fail happen" );
04448     }
04449 
04450     if( m_ihandle->eof() )
04451     {
04452         std::cout << "eof while fetching id, offset: " << id << " " << offset << std::endl;
04453         throw std::logic_error( "eof happen" );
04454     }
04455 
04456     if( padfft->get_xsize() != m_x_out ||
04457         padfft->get_ysize() != m_y_out ||
04458         padfft->get_zsize() != m_z_out )
04459     {
04460         padfft->set_size(m_x_out, m_y_out, m_z_out);
04461     }
04462 
04463     char* data = (char*)(padfft->get_data());
04464     m_ihandle->read( data, sizeof(float)*m_totsize );
04465     padfft->update();
04466 
04467     if( m_ctf )
04468     {
04469         padfft->set_attr( "Cs", m_Cs );
04470         padfft->set_attr( "Pixel_size", m_pixel );
04471         padfft->set_attr( "voltage", m_voltage );
04472         padfft->set_attr( "ctf_applied", m_ctf_applied );
04473         padfft->set_attr( "amp_contrast", m_amp_contrast );
04474         padfft->set_attr( "defocus", m_defocuses[id] );
04475     }
04476 
04477     padfft->set_attr( "padffted", 1 );
04478     padfft->set_attr( "phi", m_phis[id] );
04479     padfft->set_attr( "theta", m_thetas[id] );
04480     padfft->set_attr( "psi", m_psis[id] );
04481 
04482 }

void file_store::restart  ) 
 

Definition at line 4484 of file reconstructor.cpp.

References m_bin_file, and m_ihandle.

04485 {
04486     if( m_ihandle == NULL )
04487     {
04488         m_ihandle = shared_ptr< ifstream >( new ifstream(m_bin_file.c_str(), std::ios::in | std::ios::binary) );
04489     }
04490 
04491     if( m_ihandle->bad() || m_ihandle->fail() || m_ihandle->eof() )
04492     {
04493         m_ihandle->open( m_bin_file.c_str(), std::ios::binary );
04494     }
04495 
04496     m_ihandle->seekg( 0, std::ios::beg );
04497 }


Member Data Documentation

float EMAN::file_store::m_amp_contrast [private]
 

Definition at line 1348 of file reconstructor.h.

Referenced by add_image(), and get_image().

string EMAN::file_store::m_bin_file [private]
 

Definition at line 1334 of file reconstructor.h.

Referenced by add_image(), and restart().

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

Definition at line 1332 of file reconstructor.h.

Referenced by add_image().

float EMAN::file_store::m_Cs [private]
 

Definition at line 1344 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_ctf [private]
 

Definition at line 1336 of file reconstructor.h.

Referenced by file_store().

float EMAN::file_store::m_ctf_applied [private]
 

Definition at line 1347 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1349 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1331 of file reconstructor.h.

Referenced by get_image(), and restart().

int EMAN::file_store::m_npad [private]
 

Definition at line 1337 of file reconstructor.h.

Referenced by add_image(), and file_store().

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

Definition at line 1350 of file reconstructor.h.

Referenced by add_image(), and get_image().

float EMAN::file_store::m_pixel [private]
 

Definition at line 1345 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_prev [private]
 

Definition at line 1338 of file reconstructor.h.

Referenced by file_store().

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

Definition at line 1352 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1351 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1343 of file reconstructor.h.

Referenced by add_image(), and get_image().

string EMAN::file_store::m_txt_file [private]
 

Definition at line 1335 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 1333 of file reconstructor.h.

Referenced by add_image().

float EMAN::file_store::m_voltage [private]
 

Definition at line 1346 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_write [private]
 

Definition at line 1342 of file reconstructor.h.

Referenced by add_image(), and file_store().

int EMAN::file_store::m_x_out [private]
 

Definition at line 1339 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_y_out [private]
 

Definition at line 1340 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_z_out [private]
 

Definition at line 1341 of file reconstructor.h.

Referenced by add_image(), and get_image().


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:51:44 2011 for EMAN2 by  doxygen 1.3.9.1