Commit 5cb2e304 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron

Merge branch '118-h5-saving-frames_per_file-not-adjusted-to-the-nb-of-frames' into 'master'

Resolve "h5 saving:  frames_per_file not adjusted to the nb of frames"

Closes #118 and #119

See merge request !164
parents 4bee2829 b84ee692
Pipeline #29216 passed with stages
in 30 minutes and 32 seconds
......@@ -407,7 +407,7 @@ public:
void setParameters(const Parameters& pars);
void updateParameters();
void prepare(CtControl& ct);
void prepare();
void close();
void createSaveContainer();
void checkWriteAccess();
......@@ -483,10 +483,7 @@ public:
m_save_cnt->getEnableLogStat(enable);
}
void clear()
{
m_save_cnt->clear();
}
void clear();
bool isReady(long frame_id) const
{
......@@ -496,10 +493,9 @@ public:
{
m_save_cnt->setReady(frame_id);
}
void prepareWrittingFrame(long frame_nr)
{
m_save_cnt->prepareWrittingFrame(frame_nr);
}
void prepareWrittingFrame(long frame_nr);
void createStatistic(Data& data)
{
m_save_cnt->createStatistic(data);
......@@ -519,17 +515,24 @@ public:
class _SaveTask;
class _CompressionCBK;
CtSaving& m_saving;
void _prepare();
enum ContainerStatus {
Init, Prepare, Open,
};
CtSaving& m_saving;
int m_idx;
SaveContainer* m_save_cnt;
_SaveCBK* m_saving_cbk;
ContainerStatus m_cnt_status;
SaveContainer* m_save_cnt;
_SaveCBK* m_saving_cbk;
Parameters m_pars;
Parameters m_reference_pars;
Parameters m_acquisition_pars;
bool m_pars_dirty_flag;
bool m_active;
_CompressionCBK* m_compression_cbk;
_CompressionCBK* m_compression_cbk;
};
friend class Stream;
......@@ -611,8 +614,8 @@ private:
}
// --- internal call
void _prepare(CtControl&);
void _stop(CtControl&);
void _prepare();
void _stop();
void _close();
void _getCommonHeader(HeaderMap&);
void _createStatistic(Data&);
......@@ -624,7 +627,6 @@ private:
void _compressionFinished(Data&, Stream&);
void _saveFinished(Data&, Stream&);
void _setSavingError(CtControl::ErrorCode);
void _updateParameters();
void _synchronousSaving(Data&, HeaderMap&);
bool _controlIsFault();
bool _newFrameWrite(int);
......
......@@ -504,7 +504,7 @@ void CtControl::prepareAcq()
m_ct_accumulation->prepare();
DEB_TRACE() << "Prepare Saving if needed";
m_ct_saving->_prepare(*this);
m_ct_saving->_prepare();
m_autosave= m_ct_saving->hasAutoSaveMode();
DEB_TRACE() << "Prepare Hardware for Acquisition";
......@@ -654,7 +654,7 @@ void CtControl::_stopAcq(bool faulty_acq)
}
_calcAcqStatus();
m_ct_saving->_stop(*this);
m_ct_saving->_stop();
}
/** @brief stop an acquisition and purge all pending tasks.
......
......@@ -279,23 +279,48 @@ void CtSaving::Stream::setActive(bool active)
m_active = active;
}
void CtSaving::Stream::prepare(CtControl& ct)
void CtSaving::Stream::prepare()
{
DEB_MEMBER_FUNCT();
if (hasAutoSaveMode())
{
if (m_cnt_status == Open)
m_save_cnt->close();
updateParameters();
checkWriteAccess();
}
m_save_cnt->prepare(ct);
m_cnt_status = Init;
updateParameters();
if (hasAutoSaveMode())
_prepare();
}
void CtSaving::Stream::_prepare()
{
DEB_MEMBER_FUNCT();
checkWriteAccess();
m_save_cnt->prepare(m_saving.m_ctrl);
m_cnt_status = Prepare;
}
void CtSaving::Stream::close()
{
m_save_cnt->close();
m_cnt_status = Init;
}
void CtSaving::Stream::clear()
{
m_save_cnt->clear();
m_cnt_status = Init;
}
void CtSaving::Stream::prepareWrittingFrame(long frame_nr)
{
if (m_cnt_status == Init)
_prepare();
m_save_cnt->prepareWrittingFrame(frame_nr);
}
void CtSaving::Stream::updateParameters()
{
DEB_MEMBER_FUNCT();
......@@ -447,6 +472,8 @@ void CtSaving::Stream::createSaveContainer()
if (nb_writing_thread != -1)
m_save_cnt->setMaxConcurrentWritingTask(nb_writing_thread);
m_save_cnt->setEnableLogStat(enable_log_stat);
m_cnt_status = Init;
}
void CtSaving::Stream::writeFile(Data& data, HeaderMap& header)
......@@ -454,6 +481,7 @@ void CtSaving::Stream::writeFile(Data& data, HeaderMap& header)
DEB_MEMBER_FUNCT();
m_save_cnt->writeFile(data, header);
m_cnt_status = Open;
}
......@@ -1707,76 +1735,69 @@ void CtSaving::writeFrame(int aFrameNumber, int aNbFrames, bool synchronous)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(aFrameNumber);
AutoMutex lock(m_cond.mutex());
_updateParameters();
ManagedMode managed_mode;
{
AutoMutex lock(m_cond.mutex());
if (!m_saving_error_handler)
m_saving_error_handler = new _SavingErrorHandler(*this, *m_ctrl.event());
if (getAcqSavingMode() != Manual)
THROW_CTL_ERROR(Error) << "Manual saving is only permitted when "
"saving mode == Manual";
SavingMode saving_mode = getAcqSavingMode();
ManagedMode managed_mode = getManagedMode();
// wait until the saving is no more used
_waitWritingThreads();
_waitWritingThreads();
if (!m_saving_error_handler)
m_saving_error_handler = new _SavingErrorHandler(*this, *m_ctrl.event());
for (int s = 0; s < m_nb_stream; ++s)
{
managed_mode = getManagedMode();
}
if (managed_mode == Hardware) {
int hw_cap = m_hwsaving->getCapabilities();
if (hw_cap & HwSavingCtrlObj::MANUAL_WRITE)
m_hwsaving->writeFrame(aFrameNumber, aNbFrames);
else
THROW_CTL_ERROR(NotSupported) << "Manual write is not available";
return;
}
Data anImage2Save;
m_ctrl.ReadImage(anImage2Save, aFrameNumber, aNbFrames);
if (aFrameNumber < 0) {
aFrameNumber = anImage2Save.frameNumber;
DEB_TRACE() << DEB_VAR1(aFrameNumber);
}
for (int s = 0; s < m_nb_stream; ++s) {
Stream& stream = getStream(s);
if (stream.isActive())
stream.prepareWrittingFrame(aFrameNumber);
}
lock.unlock();
if (saving_mode != Manual)
THROW_CTL_ERROR(Error) << "Manual saving is only permitted when "
"saving mode == Manual";
if (managed_mode == Software)
// Saving
HeaderMap header;
{
Data anImage2Save;
m_ctrl.ReadImage(anImage2Save, aFrameNumber, aNbFrames);
// Saving
HeaderMap header;
AutoMutex lock(m_cond.mutex());
FrameHeaderMap::iterator aHeaderIter;
aHeaderIter = m_frame_headers.find(anImage2Save.frameNumber);
_takeHeader(aHeaderIter, header, false);
if (synchronous)
_synchronousSaving(anImage2Save, header);
else
{
TaskMgr* aSavingManualMgrPt = new TaskMgr();
aSavingManualMgrPt->setEventCallback(m_saving_error_handler);
Data copyImage = anImage2Save.copy();
aSavingManualMgrPt->setInputData(copyImage);
SinkTaskBase* aTaskPt = new CtSaving::_ManualBackgroundSaveTask(*this,
header);
aSavingManualMgrPt->addSinkTask(0, aTaskPt);
aTaskPt->unref();
PoolThreadMgr::get().addProcess(aSavingManualMgrPt);
}
}
if (synchronous)
_synchronousSaving(anImage2Save, header);
else
{
int hw_cap = m_hwsaving->getCapabilities();
if (hw_cap & HwSavingCtrlObj::MANUAL_WRITE)
m_hwsaving->writeFrame(aFrameNumber, aNbFrames);
else
THROW_CTL_ERROR(NotSupported) << "Manual write is not available";
}
}
TaskMgr* aSavingManualMgrPt = new TaskMgr();
aSavingManualMgrPt->setEventCallback(m_saving_error_handler);
Data copyImage = anImage2Save.copy();
aSavingManualMgrPt->setInputData(copyImage);
SinkTaskBase* aTaskPt = new CtSaving::_ManualBackgroundSaveTask(*this,
header);
aSavingManualMgrPt->addSinkTask(0, aTaskPt);
aTaskPt->unref();
void CtSaving::_updateParameters()
{
// wait until the saving is no more used
_waitWritingThreads();
for (int s = 0; s < m_nb_stream; ++s) {
Stream& stream = getStream(s);
if (stream.isActive())
stream.updateParameters();
PoolThreadMgr::get().addProcess(aSavingManualMgrPt);
}
}
......@@ -1797,7 +1818,10 @@ void CtSaving::_synchronousSaving(Data& anImage2Save, HeaderMap& header)
stream.writeFile(anImage2Save, header);
}
_newFrameWrite(anImage2Save.frameNumber);
}
void CtSaving::_postTaskList(Data& aData,
const TaskList& task_list, int priority)
{
......@@ -1930,7 +1954,7 @@ void CtSaving::_setSavingError(CtControl::ErrorCode anErrorCode)
this methode will resetLastFrameNb if mode is AutoSave
and validate the parameter for this new acquisition
*/
void CtSaving::_prepare(CtControl& ct)
void CtSaving::_prepare()
{
DEB_MEMBER_FUNCT();
......@@ -1950,9 +1974,8 @@ void CtSaving::_prepare(CtControl& ct)
for (int s = 0; s < m_nb_stream; ++s) {
Stream& stream = getStream(s);
if (stream.isActive()) {
aLock.unlock();
stream.prepare(ct);
aLock.lock();
AutoMutexUnlock u(aLock);
stream.prepare();
if (stream.needCompression())
m_need_compression = true;
}
......@@ -2007,11 +2030,11 @@ void CtSaving::_prepare(CtControl& ct)
}
// CtSaving::_stop is only called from CtControl::stopAcq()
void CtSaving::_stop(CtControl& ct)
void CtSaving::_stop()
{
// Get the last image acquired counter
CtControl::ImageStatus img_status;
ct.getImageStatus(img_status);
m_ctrl.getImageStatus(img_status);
for (int s = 0; s < m_nb_stream; ++s)
{
......
This diff is collapsed.
......@@ -33,7 +33,7 @@
#define BSHUF_H5FILTER 32008
#define BSHUF_H5_COMPRESS_LZ4 2
extern "C" {
int bshuf_register_h5filter(void);
int bshuf_register_h5filter(void);
}
#endif
......@@ -68,30 +68,30 @@ private:
int findLastEntry(const _File&);
struct Parameters{
string det_name;
string instrument_name;
string det_model;
string det_type;
string lima_version;
double pixel_size[2];
Size max_image_size;
ImageType curr_image_type;
AcqMode acq_mode;
double acq_expo_time;
double acq_latency_time;
int acq_nbframes;
TrigMode acq_trigger_mode;
CtAcquisition::AccTimeMode acc_time_mode;
double acc_max_expotime;
double acc_expotime;
double acc_livetime;
double acc_deadtime;
int concat_nbframes;
Bin image_bin;
Roi image_roi;
Flip image_flip;
RotationMode image_rotation;
FrameDim image_dim;
string det_name;
string instrument_name;
string det_model;
string det_type;
string lima_version;
double pixel_size[2];
Size max_image_size;
ImageType curr_image_type;
AcqMode acq_mode;
double acq_expo_time;
double acq_latency_time;
int acq_nbframes;
TrigMode acq_trigger_mode;
CtAcquisition::AccTimeMode acc_time_mode;
double acc_max_expotime;
double acc_expotime;
double acc_livetime;
double acc_deadtime;
int concat_nbframes;
Bin image_bin;
Roi image_roi;
Flip image_flip;
RotationMode image_rotation;
FrameDim image_dim;
};
CtSaving::FileFormat m_format;
......@@ -100,8 +100,11 @@ private:
CtAcquisition *m_ct_acq;
HwInterface *m_hw_int;
bool m_is_multiset;
int m_nbframes;
int m_compression_level;
int m_frames_per_file;
int m_acq_nbframes;
int m_max_nb_files;
int m_file_cnt;
};
}
......
Markdown is supported
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