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 4291 of file reconstructor.cpp.

References m_ctf, m_npad, m_prev, and m_write.

04292     : m_bin_file(filename + ".bin"),
04293       m_txt_file(filename + ".txt")
04294 {
04295     m_ctf = ctf;
04296     m_prev = -1;
04297     m_npad = npad;
04298     m_write = write;
04299 }

file_store::~file_store  )  [virtual]
 

Definition at line 4301 of file reconstructor.cpp.

04302 {
04303 }


Member Function Documentation

void file_store::add_image EMData data,
const Transform tf
 

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

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

void file_store::get_image int  id,
EMData padfft
 

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

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

void file_store::restart  ) 
 

Definition at line 4475 of file reconstructor.cpp.

References m_bin_file, and m_ihandle.

04476 {
04477     if( m_ihandle == NULL )
04478     {
04479         m_ihandle = shared_ptr< ifstream >( new ifstream(m_bin_file.c_str(), std::ios::in | std::ios::binary) );
04480     }
04481 
04482     if( m_ihandle->bad() || m_ihandle->fail() || m_ihandle->eof() )
04483     {
04484         m_ihandle->open( m_bin_file.c_str(), std::ios::binary );
04485     }
04486 
04487     m_ihandle->seekg( 0, std::ios::beg );
04488 }


Member Data Documentation

float EMAN::file_store::m_amp_contrast [private]
 

Definition at line 1358 of file reconstructor.h.

Referenced by add_image(), and get_image().

string EMAN::file_store::m_bin_file [private]
 

Definition at line 1344 of file reconstructor.h.

Referenced by add_image(), and restart().

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

Definition at line 1342 of file reconstructor.h.

Referenced by add_image().

float EMAN::file_store::m_Cs [private]
 

Definition at line 1354 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_ctf [private]
 

Definition at line 1346 of file reconstructor.h.

Referenced by file_store().

float EMAN::file_store::m_ctf_applied [private]
 

Definition at line 1357 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1359 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1341 of file reconstructor.h.

Referenced by get_image(), and restart().

int EMAN::file_store::m_npad [private]
 

Definition at line 1347 of file reconstructor.h.

Referenced by add_image(), and file_store().

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

Definition at line 1360 of file reconstructor.h.

Referenced by add_image(), and get_image().

float EMAN::file_store::m_pixel [private]
 

Definition at line 1355 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_prev [private]
 

Definition at line 1348 of file reconstructor.h.

Referenced by file_store().

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

Definition at line 1362 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1361 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1353 of file reconstructor.h.

Referenced by add_image(), and get_image().

string EMAN::file_store::m_txt_file [private]
 

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

Referenced by add_image().

float EMAN::file_store::m_voltage [private]
 

Definition at line 1356 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_write [private]
 

Definition at line 1352 of file reconstructor.h.

Referenced by add_image(), and file_store().

int EMAN::file_store::m_x_out [private]
 

Definition at line 1349 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_y_out [private]
 

Definition at line 1350 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_z_out [private]
 

Definition at line 1351 of file reconstructor.h.

Referenced by add_image(), and get_image().


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:48:37 2010 for EMAN2 by  doxygen 1.3.9.1