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

References m_ctf, m_npad, m_prev, and m_write.

03661     : m_bin_file(filename + ".bin"),
03662       m_txt_file(filename + ".txt")
03663 {
03664     m_ctf = ctf;
03665     m_prev = -1;
03666     m_npad = npad;
03667     m_write = write;
03668 }

file_store::~file_store  )  [virtual]
 

Definition at line 3670 of file reconstructor.cpp.

03671 {
03672 }


Member Function Documentation

void file_store::add_image EMData data,
const Transform tf
 

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

03675 {
03676 
03677     EMData* padfft = padfft_slice( emdata, tf, m_npad );
03678 
03679     float* data = padfft->get_data();
03680 
03681     if( m_write && m_bin_ohandle == NULL )
03682     {
03683         m_bin_ohandle = shared_ptr< ofstream >( new ofstream(m_bin_file.c_str(), std::ios::out | std::ios::binary) );
03684         m_txt_ohandle = shared_ptr< ofstream >( new ofstream(m_txt_file.c_str() ) );
03685         if( m_ctf )
03686                  *m_txt_ohandle << "Cs pixel voltage ctf_applied amp_contrast defocus ";
03687 
03688         *m_txt_ohandle << "phi theta psi" << std::endl;
03689     }
03690 
03691     m_x_out = padfft->get_xsize();
03692     m_y_out = padfft->get_ysize();
03693     m_z_out = padfft->get_zsize();
03694     m_totsize = m_x_out*m_y_out*m_z_out;
03695 
03696     if( m_ctf )
03697     {
03698         Ctf* ctf = padfft->get_attr( "ctf" );
03699         Dict ctf_params = ctf->to_dict();
03700 
03701         m_ctf_applied = padfft->get_attr( "ctf_applied" );
03702 
03703         m_Cs = ctf_params["cs"];
03704         m_pixel = ctf_params["apix"];
03705         m_voltage = ctf_params["voltage"];
03706         m_amp_contrast = ctf_params["ampcont"];
03707         m_defocuses.push_back( ctf_params["defocus"] );
03708         if(ctf) {delete ctf; ctf=0;}
03709     }
03710 
03711     Dict params = tf.get_rotation( "spider" );
03712     float phi = params.get( "phi" );
03713     float tht = params.get( "theta" );
03714     float psi = params.get( "psi" );
03715 
03716 
03717     m_phis.push_back( phi );
03718     m_thetas.push_back( tht );
03719     m_psis.push_back( psi );
03720 
03721     if( m_write )
03722     {
03723         m_bin_ohandle->write( (char*)data, sizeof(float)*m_totsize );
03724 
03725         if( m_ctf )
03726         {
03727             *m_txt_ohandle << m_Cs << " ";
03728             *m_txt_ohandle << m_pixel << " ";
03729             *m_txt_ohandle << m_voltage << " ";
03730             *m_txt_ohandle << m_ctf_applied << " ";
03731             *m_txt_ohandle << m_amp_contrast << " ";
03732             *m_txt_ohandle << m_defocuses.back() << " ";
03733         }
03734         *m_txt_ohandle << m_phis.back() << " ";
03735         *m_txt_ohandle << m_thetas.back() << " ";
03736         *m_txt_ohandle << m_psis.back() << " ";
03737         *m_txt_ohandle << m_x_out << " ";
03738         *m_txt_ohandle << m_y_out << " ";
03739         *m_txt_ohandle << m_z_out << " ";
03740         *m_txt_ohandle << m_totsize << std::endl;
03741     }
03742 
03743     checked_delete(padfft);
03744 
03745 }

void file_store::get_image int  id,
EMData padfft
 

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

03748 {
03749 
03750     if( m_phis.size() == 0 ) {
03751         ifstream m_txt_ifs( m_txt_file.c_str() );
03752 
03753         if( !m_txt_ifs )
03754         {
03755             std::cerr << "Error: file " << m_txt_file << " does not exist" << std::endl;
03756         }
03757 
03758         string line;
03759         std::getline( m_txt_ifs, line );
03760 
03761         float first, defocus, phi, theta, psi;
03762 
03763 
03764 
03765         while( m_txt_ifs >> first ) {
03766 
03767             if( m_ctf )
03768             {
03769                 m_Cs = first;
03770                 m_txt_ifs >> m_pixel >> m_voltage;
03771                 m_txt_ifs >> m_ctf_applied >> m_amp_contrast;
03772                 m_txt_ifs >> defocus >> phi >> theta >> psi;
03773                 m_defocuses.push_back( defocus );
03774             }
03775             else
03776             {
03777                 phi = first;
03778                 m_txt_ifs >> theta >> psi;
03779             }
03780 
03781             m_txt_ifs >> m_x_out >> m_y_out >> m_z_out >> m_totsize;
03782             m_phis.push_back( phi );
03783             m_thetas.push_back( theta );
03784             m_psis.push_back( psi );
03785         }
03786     }
03787 
03788     Assert( m_ihandle != NULL );
03789 
03790     std::istream::off_type offset = id*sizeof(float)*m_totsize;
03791     Assert( offset >= 0 );
03792 
03793     if( offset > 0 )
03794     {
03795         m_ihandle->seekg(offset, std::ios::beg);
03796     }
03797 
03798     if( m_ihandle->bad() )
03799     {
03800         std::cout << "bad while fetching id, offset: " << id << " " << offset << std::endl;
03801         throw std::logic_error( "bad happen" );
03802     }
03803 
03804     if( m_ihandle->fail() )
03805     {
03806         std::cout << "fail while fetching id, offset, curoff: " << id << " " << offset << std::endl;
03807         throw std::logic_error( "fail happen" );
03808     }
03809 
03810     if( m_ihandle->eof() )
03811     {
03812         std::cout << "eof while fetching id, offset: " << id << " " << offset << std::endl;
03813         throw std::logic_error( "eof happen" );
03814     }
03815 
03816     if( padfft->get_xsize() != m_x_out ||
03817         padfft->get_ysize() != m_y_out ||
03818         padfft->get_zsize() != m_z_out )
03819     {
03820         padfft->set_size(m_x_out, m_y_out, m_z_out);
03821     }
03822 
03823     char* data = (char*)(padfft->get_data());
03824     m_ihandle->read( data, sizeof(float)*m_totsize );
03825     padfft->update();
03826 
03827     if( m_ctf )
03828     {
03829         padfft->set_attr( "Cs", m_Cs );
03830         padfft->set_attr( "Pixel_size", m_pixel );
03831         padfft->set_attr( "voltage", m_voltage );
03832         padfft->set_attr( "ctf_applied", m_ctf_applied );
03833         padfft->set_attr( "amp_contrast", m_amp_contrast );
03834         padfft->set_attr( "defocus", m_defocuses[id] );
03835     }
03836 
03837     padfft->set_attr( "padffted", 1 );
03838     padfft->set_attr( "phi", m_phis[id] );
03839     padfft->set_attr( "theta", m_thetas[id] );
03840     padfft->set_attr( "psi", m_psis[id] );
03841 
03842 }

void file_store::restart  ) 
 

Definition at line 3844 of file reconstructor.cpp.

References m_bin_file, and m_ihandle.

03845 {
03846     if( m_ihandle == NULL )
03847     {
03848         m_ihandle = shared_ptr< ifstream >( new ifstream(m_bin_file.c_str(), std::ios::in | std::ios::binary) );
03849     }
03850 
03851     if( m_ihandle->bad() || m_ihandle->fail() || m_ihandle->eof() )
03852     {
03853         m_ihandle->open( m_bin_file.c_str(), std::ios::binary );
03854     }
03855 
03856     m_ihandle->seekg( 0, std::ios::beg );
03857 }


Member Data Documentation

float EMAN::file_store::m_amp_contrast [private]
 

Definition at line 1228 of file reconstructor.h.

Referenced by add_image(), and get_image().

string EMAN::file_store::m_bin_file [private]
 

Definition at line 1214 of file reconstructor.h.

Referenced by add_image(), and restart().

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

Definition at line 1212 of file reconstructor.h.

Referenced by add_image().

float EMAN::file_store::m_Cs [private]
 

Definition at line 1224 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_ctf [private]
 

Definition at line 1216 of file reconstructor.h.

Referenced by file_store().

float EMAN::file_store::m_ctf_applied [private]
 

Definition at line 1227 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1229 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1211 of file reconstructor.h.

Referenced by get_image(), and restart().

int EMAN::file_store::m_npad [private]
 

Definition at line 1217 of file reconstructor.h.

Referenced by add_image(), and file_store().

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

Definition at line 1230 of file reconstructor.h.

Referenced by add_image(), and get_image().

float EMAN::file_store::m_pixel [private]
 

Definition at line 1225 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_prev [private]
 

Definition at line 1218 of file reconstructor.h.

Referenced by file_store().

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

Definition at line 1232 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1231 of file reconstructor.h.

Referenced by add_image(), and get_image().

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

Definition at line 1223 of file reconstructor.h.

Referenced by add_image(), and get_image().

string EMAN::file_store::m_txt_file [private]
 

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

Referenced by add_image().

float EMAN::file_store::m_voltage [private]
 

Definition at line 1226 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_write [private]
 

Definition at line 1222 of file reconstructor.h.

Referenced by add_image(), and file_store().

int EMAN::file_store::m_x_out [private]
 

Definition at line 1219 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_y_out [private]
 

Definition at line 1220 of file reconstructor.h.

Referenced by add_image(), and get_image().

int EMAN::file_store::m_z_out [private]
 

Definition at line 1221 of file reconstructor.h.

Referenced by add_image(), and get_image().


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:31 2010 for EMAN2 by  doxygen 1.3.9.1