Commit 76a80181 authored by Yuelong Yu's avatar Yuelong Yu
Browse files

bug fix on file writing

parent eb0412c5
......@@ -72,6 +72,7 @@ namespace FSDataRecvNS
m_receiver_task = (new ReceiverTask(udp_ip,
port,
m_x,m_y,
m_img_size,
m_mempool));
......
......@@ -88,6 +88,13 @@ namespace FSDataRecvNS
m_frames_per_file = frame_numbers_per_file;
}
int32 FileSavingTask::GetFileIndex()
{
LOG_TRACE(__FUNCTION__);
return m_file_index;
}
int32 FileSavingTask::GetSavedImages()
{
LOG_TRACE(__FUNCTION__);
......@@ -121,11 +128,6 @@ namespace FSDataRecvNS
Stop();
continue;
}
else
//open related fields for data written
nx_writer->PreAcq(string("/:NXentry/:NXinstrument/:NXdetector/data"),
string("/:NXentry/:NXinstrument/:NXdetector/sequence_number"),
string("/:NXentry/:NXinstrument/:NXdetector/:NXcollection/error_code"));
}
......@@ -134,9 +136,10 @@ namespace FSDataRecvNS
if(m_saved_images >= m_requested_frames)
{
{
Stop();
CloseFile();
++m_file_index;
continue;
}
......@@ -157,13 +160,13 @@ namespace FSDataRecvNS
++m_saved_images;
lock.unlock();
if(m_file_split && (m_saved_images % m_frames_per_file) == 0)
if(m_file_split &&
(m_saved_images % m_frames_per_file) == 0 && m_saved_images<m_requested_frames)
{
CloseFile();
++m_file_index;
if(!CreateFile())
Stop();
CloseFile();
++m_file_index;
if(!CreateFile())
Stop();
}
}
}
......@@ -191,15 +194,15 @@ namespace FSDataRecvNS
bool FileSavingTask::CreateFile()
{
LOG_TRACE(__FUNCTION__);
string nxs_filename = m_file_name;
if(m_file_split)
{
char chNum[10];
sprintf (chNum, "part%05d",m_file_index);
m_file_name = m_file_name + "_" + chNum;
nxs_filename = m_file_name + "_" + chNum;
}
if(nx_writer->FileConfig(m_file_name,
if(nx_writer->FileConfig(nxs_filename,
true,
1,
m_y,
......@@ -217,9 +220,17 @@ namespace FSDataRecvNS
if(nx_writer->CreateFile() !=0 )
return false;
LOG_INFOS("Create file:" + m_file_name);
if(nx_writer->CreateStructureFromXMLString(m_xml_structure) !=0 )
return false;
cout<<m_xml_structure<<endl;
LOG_INFOS("XML file structure:" + m_xml_structure);
//open related fields for data written
nx_writer->PreAcq(string("/:NXentry/:NXinstrument/:NXdetector/data"),
string("/:NXentry/:NXinstrument/:NXdetector/sequence_number"),
string("/:NXentry/:NXinstrument/:NXdetector/:NXcollection/error_code"));
m_fileopen = true;
return true;
......@@ -233,6 +244,8 @@ namespace FSDataRecvNS
return false;
m_fileopen=false;
LOG_INFOS("Close file:" + m_file_name);
return true;
}
......
......@@ -68,6 +68,12 @@ namespace FSDataRecvNS
*/
void SetFramesPerFile(int32 frame_numbers_per_file);
/**
* @brief get file index
* @return file index
*/
int32 GetFileIndex();
/**
* @brief saving data
*/
......
......@@ -233,7 +233,7 @@ namespace NexusNS
void PreAcq(string strDataFieldPath,string strFrameFieldPath,string strErrField)
{
//cout<<"m_nX:"<<m_nX<<"m_nY:"<<m_nY<<endl;
//cout<<"m_nX:"<<m_nX<<"m_nY:"<<m_nY<<endl;
//m_nIdx = nIndex;
m_objDataSelection = dataspace::Hyperslab({{0,0,0},
......@@ -295,7 +295,7 @@ namespace NexusNS
template<typename T>
int Write2DData(vector<T>& vData,int nFrameNo,short shErr)
{
//cout<<"write 2d data"<<endl;
//cout<<"write 2d data"<<endl;
try
{
......
......@@ -26,14 +26,19 @@ namespace FSDataRecvNS
ReceiverTask::ReceiverTask(string udp_ip,
int16 port,
int32 x,
int32 y,
int32 img_size,
sptr_mem16bit const& mempool)
:m_mempool16bit(mempool),
m_img_size(img_size),
m_received_imgs(0),
m_packets_collected(0),
m_x(x),
m_y(y),
m_packet(),
m_img_data(img_size,0)
m_img_data(img_size,0),
m_reordered_img(img_size,0)
{
LOG_TRACE(__FUNCTION__);
......@@ -69,7 +74,7 @@ namespace FSDataRecvNS
{
LOG_TRACE(__FUNCTION__);
boost::unique_lock<boost::mutex> lock(m_bstSync);
std::copy(m_img_data.begin(),m_img_data.end(),img_data.get());
std::copy(m_reordered_img.begin(),m_reordered_img.end(),img_data.get());
frame_number = m_current_frame_number;
error_code = 0;//not used for live images
lock.unlock();
......@@ -117,7 +122,7 @@ namespace FSDataRecvNS
void ReceiverTask::BuildImage(packet_struct const& packet_data)
{
LOG_TRACE(__FUNCTION__);
memcpy(&m_img_data[m_packets_collected*4096],
packet_data.data,
4096*sizeof(uint16_t));
......@@ -127,10 +132,24 @@ namespace FSDataRecvNS
{
++m_received_imgs;
m_current_frame_number = m_received_imgs;
int16* data = reinterpret_cast<int16*>(&m_img_data[0]);
//covert col-major order to row-major order
int32 col = 0;
int32 row = 0;
for(int32 i=0; i<m_img_size; ++i)
{
m_reordered_img[(col+m_x*row)]=m_img_data[i];
++row;
if(row == m_y)
{
row = 0;
++col;
}
}
int16* data = reinterpret_cast<int16*>(&m_reordered_img[0]);
m_mempool16bit->SetImage(data,m_received_imgs,0);
m_packets_collected = 0;
LOG_INFOS("Get one image : "+to_string(m_received_imgs));
LOG_INFOS("Get image : "+to_string(m_received_imgs));
}
}
......
......@@ -59,6 +59,8 @@ namespace FSDataRecvNS
*/
ReceiverTask(string udp_ip,
int16 port,
int32 x,
int32 y,
int32 img_size,
sptr_mem16bit const& mempool);
......@@ -106,9 +108,9 @@ namespace FSDataRecvNS
int64 m_current_frame_number;
int32 m_img_size,m_received_imgs,m_requested_frames,m_packets_collected;
int32 m_img_size,m_received_imgs,m_requested_frames,m_packets_collected,m_x,m_y;
packet_struct m_packet;
vector<int16> m_img_data;
vector<int16> m_img_data,m_reordered_img;
};
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment