Commit 4cfdef4b authored by Yuelong Yu's avatar Yuelong Yu
Browse files

finished file saving task

parent eefab47c
......@@ -50,15 +50,9 @@ else()
message(FATAL_ERROR "Unsupported compiler")
endif()
if(NOT AHA_LIB_FOUND)
# add common flags
add_definitions("-Wall -std=c++11 -fPIC -pthread -D_REENTRANT")
message(STATUS "HW compression is disabled")
else(NOT AHA_LIB_FOUND)
# add common flags
add_definitions("-Wall -std=c++11 -fPIC -pthread -D_REENTRANT -DENABLEHWCOMPRESSION")
message(STATUS "HW compression is enabled")
endif(NOT AHA_LIB_FOUND)
# add common flags
add_definitions("-Wall -std=c++11 -fPIC -pthread -D_REENTRANT")
# define build type, by default is release
if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
......@@ -84,9 +78,10 @@ set(SHARED_LINKER_FLAGS
boost_date_time
pnicore
pniio
h5cpp)
h5cpp
hdf5_serial)
set(PKG_LIBS "-lboost_system -lboost_thread -lpthread -lz")
#set(PKG_LIBS "-lboost_system -lboost_thread -lpthread -lz")
#src
#add_subdirectory("include")
......
......@@ -61,7 +61,7 @@ namespace FSDataRecvNS
m_img_size,
m_mempool));
m_filesaving_task = (new FileSavingTask(m_img_size,
m_filesaving_task = (new FileSavingTask(m_x,m_y,
m_mempool));
......@@ -159,18 +159,9 @@ namespace FSDataRecvNS
if(m_save_file)
{
m_filesaving_task->SetFileParameter(m_file_name,
true,
1,
m_x,
m_y,
m_pixel_depth,
1,
m_compression_enabled,
m_shuffle_enabled,
m_compression_ratio,
m_file_split,
m_frames_per_file);
m_filesaving_task->SetFileName(m_file_name);
m_filesaving_task->SetFramesPerFile(m_frames_per_file);
m_filesaving_task->Start();
}
}
......@@ -194,7 +185,7 @@ namespace FSDataRecvNS
DataReceiver::DataReceiver()
:m_x(1000),m_y(1000),m_img_size(m_x*m_y),
m_frame_number(0),m_requested_frames(0),m_max_frame_numbers(0),m_frames_per_file(20000),
m_frame_number(0),m_requested_frames(0),m_max_frame_numbers(0),m_frames_per_file(100),
m_buffer_length(10),
m_pixel_depth(2),m_error_code(0),
m_start_acq(false),m_stop_acq(false),m_save_file(false),
......
......@@ -30,15 +30,19 @@ namespace FSDataRecvNS
FileSavingTask::FileSavingTask(
int32 img_size,
int32 x, int32 y,
sptr_mem16bit const& mempool)
:m_mempool16bit(mempool),
m_img_size(img_size),
m_requested_frames(0),
m_saved_images(0),
m_x(x),
m_y(y),
m_frames_per_file(0),
m_file_index(0),
m_start(false),
m_img_data(img_size,0)
m_file_name("test"),
m_xml_structure(""),
m_file_split(false),
m_img_data(m_x*m_y,0)
{
LOG_TRACE(__FUNCTION__);
......@@ -57,107 +61,138 @@ namespace FSDataRecvNS
void FileSavingTask::SetRequestFrames(int32 requested_frames)
{
LOG_TRACE(__FUNCTION__);
m_requested_frames = requested_frames;
m_frames_per_file = m_requested_frames;
}
void FileSavingTask::SetFileStructureWithXML(string xml_structure)
{
LOG_TRACE(__FUNCTION__);
m_xml_structure = xml_structure;
}
void FileSavingTask::SetFileParameter(string file_name,
bool over_write,
int32 data_type,
int32 x,
int32 y,
int32 pixel_depth,
int32 cache_size,
bool compression_enabled,
bool shuffle_enabled,
int16 compression_ratio,
bool split_enabled,
int32 frame_numbers_per_file)
void FileSavingTask::SetFileName(string file_name)
{
LOG_TRACE(__FUNCTION__);
m_file_name = file_name;
m_over_write = over_write;
m_data_type = data_type;
m_x = x;
m_y = y;
m_pixel_depth = pixel_depth;
m_cache_size = cache_size;
m_compression_enabled = compression_enabled;
m_shuffle_enabled = shuffle_enabled;
m_compression_ratio = compression_ratio;
m_split_enabled = split_enabled;
}
void FileSavingTask::SetFramesPerFile(int32 frame_numbers_per_file)
{
LOG_TRACE(__FUNCTION__);
m_frames_per_file = frame_numbers_per_file;
}
int32 FileSavingTask::GetSavedImages()
{
LOG_TRACE(__FUNCTION__);
// return m_saved_images;
return m_saved_images;
}
void FileSavingTask::DoTaskAction()
{
LOG_TRACE(__FUNCTION__);
// int current_frame_number = 0;
// short error_code;
while(1)
{
usleep(100);
boost::unique_lock<boost::mutex> lock(m_bstSync);
if(!m_fStart)
{
m_bstCond.wait(lock);
UpdateParameters();
if(!CreateFile())
{
Stop();
continue;
}
}
if(m_fExit)
break;
lock.unlock();
if(m_saved_images >= m_requested_frames)
{
Stop();
continue;
}
if(m_mempool16bit->GetStoredImageNumbers() == 0)
continue;
int16* img;
int32 frame_no;
int16 error_code;
int32 data_length;
if(m_mempool16bit->GetImage(img,frame_no,error_code,data_length))
{
vector<int16> img_data(img,img+m_x*m_y);
WriteData(img_data,frame_no,error_code);
lock.lock();
++m_saved_images;
lock.unlock();
if(m_file_split && (m_saved_images % m_frames_per_file) == 0)
{
CloseFile();
++m_file_index;
if(!CreateFile())
Stop();
}
}
}
}
void FileSavingTask::UpdateParameters()
{
LOG_TRACE(__FUNCTION__);
// m_saved_images = 0;
// m_file_index = 0;
// if(m_frames_per_file < m_requested_frames)
// m_file_split = true;
// else
// m_file_split = false;
m_saved_images = 0;
m_file_index = 0;
m_file_split = (m_frames_per_file < m_requested_frames);
}
bool FileSavingTask::WriteData(vector<int16>& vData,int32 nFrameNo,int16 shErrCode)
bool FileSavingTask::WriteData(vector<int16>& data,int32 frame_no,int16 err_code)
{
LOG_TRACE(__FUNCTION__);
if(!(nx_writer->Write2DData<int16>(data,frame_no,err_code)))
return false;
return true;
}
bool FileSavingTask::CreateFile()
{
LOG_TRACE(__FUNCTION__);
// int nRet = 0;
// string file_name = m_file_name;
// if(m_file_split)
// {
// char suffix[15];
// sprintf (suffix, "_part%05d",m_file_index);
// file_name = file_name +suffix;
// }
if(m_file_split)
{
char chNum[10];
sprintf (chNum, "part%05d",m_file_index);
m_file_name = m_file_name + "_" + chNum;
}
if(!(nx_writer->FileConfig(m_file_name,m_y,m_x)))
return false;
if(!(nx_writer->CreateFile()))
return false;
// nRet = nx_writer->FileConfig(file_name,
// m_over_write,
// m_data_type,
// m_y,
// m_x,
// m_pixel_depth,
// 1,
// false,
// m_compression_enabled,
// m_shuffle_enabled,
// m_compression_ratio,
// m_split_enabled, //not implemented
// m_frames_per_file); // not implemented
// if(nRet !=0 )
// return false;
// nRet = nx_writer->CreateFile();
// if(nRet != 0)
// return false;
if(!(nx_writer->CreateStructureFromXMLString(m_xml_structure)))
return false;
return true;
}
......@@ -166,9 +201,9 @@ namespace FSDataRecvNS
{
LOG_TRACE(__FUNCTION__);
// int nRet = nx_writer->CloseFile();
// if(nRet != 0)
// return false;
if(!(nx_writer->CloseFile()))
return false;
return true;
}
}
......@@ -28,23 +28,14 @@ namespace FSDataRecvNS
class FileSavingTask:public Task
{
public:
FileSavingTask(int32 img_size,sptr_mem16bit const& mempool);
FileSavingTask(int32 x, int32 y, sptr_mem16bit const& mempool);
~FileSavingTask();
void SetRequestFrames(int32 requested_frames);
void SetFileParameter(string file_name,
bool over_write,
int32 data_type,
int32 x,
int32 y,
int32 pixel_depth,
int32 cache_size,
bool compression_enabled,
bool shuffle_enabled,
int16 compression_ratio,
bool split_enabled,
int32 frame_numbers_per_file);
void SetFileStructureWithXML(string xml_structure);
void SetFileName(string file_name);
void SetFramesPerFile(int32 frame_numbers_per_file);
void DoTaskAction();
int32 GetSavedImages();
......@@ -57,14 +48,11 @@ namespace FSDataRecvNS
sptr_mem16bit m_mempool16bit;
int32 m_img_size,m_requested_frames,m_saved_images,
m_data_type,m_x,m_y,m_pixel_depth,m_cache_size,m_frames_per_file,m_file_index;
int32 m_requested_frames,m_saved_images,m_x,m_y,m_frames_per_file,m_file_index;
int16 m_compression_ratio;
bool m_over_write,m_compression_enabled,m_shuffle_enabled,
m_split_enabled,m_start,m_file_split;
string m_file_name,m_xml_structure;
string m_file_name;
bool m_file_split;
vector<int16> m_img_data;
};
......
......@@ -185,48 +185,16 @@ namespace NexusNS
* @param : data type
* @param : x
* @param : y
* @param : depth of data
* @param : cache size
* @param : use build-in compressor or not. true: use build-in compressor
* @param : compression is enabled or not. true: enabled. false: disabled
* @param : compressor shuffle
* @param : compression ratio
* @param : file splitting
* @param : maximum file limit size
* @param : postfix of file. h5 or nxs
* @param : error code
* 0: OK
*/
int FileConfig(string strFileName,
bool bOverwrite,
int nDataType,
int nX,int nY,int nDepth,
int nCacheSize,
bool bBuildInCompressor,
bool bCompressionEnabled,
bool bCompressionShuffleEnabled,
unsigned short usCompressionRate,
bool bSplitEnabled,
int nFileSizeLimit,
int nX,int nY,
string strFilePostfix = string("nxs"))
{
m_strFileName = strFileName;
m_nCacheSize = nCacheSize;
m_nDataDepth = nDepth;
m_nDataType = nDataType;
m_nX = nX;
m_nY = nY;
m_nSize = nX*nY;
m_bSplitting = bSplitEnabled;
m_bOverwrite = bOverwrite;
m_nLimitSize = nFileSizeLimit;
m_strFilePostfix = strFilePostfix;
m_bBuildInCompressor = bBuildInCompressor;
m_bCompression = bCompressionEnabled;
m_bCompressorShuffle = bCompressionShuffleEnabled;
m_ushCompressionRate = usCompressionRate;
m_strFileName = strFileName + "." + strFilePostfix;
return 0;
......@@ -280,6 +248,8 @@ namespace NexusNS
m_nxErrField.close();
m_nxFile.close();
return NO_ERROR;
}
template<typename T>
......@@ -305,6 +275,8 @@ namespace NexusNS
m_nxDataField.extent(0,1);
m_objDataSelection.offset(0,m_nIdx);
m_nxDataField.write(vData,m_objDataSelection);
return NO_ERROR;
}
catch(invalid_object_error& ie)
{
......
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