Commit b0ad6b40 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

First working version of hardware saving with Pilatus

parent 181c9dea
Subproject commit f62bc46bb4dbca5be759cc3901277e3521ca5bee Subproject commit a3434f09aaf3d1a623fe1e563b3100f7172bc4a4
...@@ -89,6 +89,8 @@ namespace lima { ...@@ -89,6 +89,8 @@ namespace lima {
void getDataFromHwFrameInfo(Data&,const HwFrameInfoType&, void getDataFromHwFrameInfo(Data&,const HwFrameInfoType&,
int readBlockLen=1); int readBlockLen=1);
static void transformHwFrameInfoToData(Data&,const HwFrameInfoType&,
int readBlockLen=1);
private: private:
class _DataDestroyCallback; class _DataDestroyCallback;
friend class _DataDestroyCallback; friend class _DataDestroyCallback;
......
...@@ -92,7 +92,6 @@ namespace lima { ...@@ -92,7 +92,6 @@ namespace lima {
FileFormat fileFormat; ///< the saving format (EDF,CBF...) FileFormat fileFormat; ///< the saving format (EDF,CBF...)
SavingMode savingMode; ///< saving mode (automatic,manual...) SavingMode savingMode; ///< saving mode (automatic,manual...)
OverwritePolicy overwritePolicy; ///< how you the saving react it find existing filename OverwritePolicy overwritePolicy; ///< how you the saving react it find existing filename
ManagedMode managedMode; ///< two option either harware (manage by SDK,hardware) or software (Lima core)
std::string indexFormat; ///< ie: %.4d if you want 4 digits std::string indexFormat; ///< ie: %.4d if you want 4 digits
long framesPerFile; ///< the number of images save in one files long framesPerFile; ///< the number of images save in one files
long nbframes; long nbframes;
...@@ -193,7 +192,7 @@ namespace lima { ...@@ -193,7 +192,7 @@ namespace lima {
class Stream; class Stream;
class LIMACORE_API SaveContainer class LIMACORE_API SaveContainer
{ {
DEB_CLASS_NAMESPC(DebModControl,"Saving Container","Control"); DEB_CLASS_NAMESPC(DebModControl,"Saving Container","Control");
public: public:
SaveContainer(Stream& stream); SaveContainer(Stream& stream);
...@@ -221,7 +220,7 @@ namespace lima { ...@@ -221,7 +220,7 @@ namespace lima {
protected: protected:
virtual bool _open(const std::string &filename, virtual bool _open(const std::string &filename,
std::ios_base::openmode flags) = 0; std::ios_base::openmode flags) = 0;
virtual void _close() = 0; virtual void _close() = 0;
virtual void _writeFile(Data &data, virtual void _writeFile(Data &data,
CtSaving::HeaderMap &aHeader, CtSaving::HeaderMap &aHeader,
...@@ -345,133 +344,137 @@ namespace lima { ...@@ -345,133 +344,137 @@ namespace lima {
bool m_has_hwsaving; bool m_has_hwsaving;
HwSavingCtrlObj* m_hwsaving; HwSavingCtrlObj* m_hwsaving;
_NewFrameSaveCBK* m_new_frame_save_cbk; _NewFrameSaveCBK* m_new_frame_save_cbk;
ManagedMode m_managed_mode; ///< two option either harware (manage by SDK,hardware) or software (Lima core)
Stream& getStream(int stream_idx) std::string m_specific_hardware_format;
{ bool stream_ok = (stream_idx >= 0) && (stream_idx < m_nb_stream);
return stream_ok ? *m_stream[stream_idx] : getStreamExc(stream_idx); } Stream& getStream(int stream_idx)
{ bool stream_ok = (stream_idx >= 0) && (stream_idx < m_nb_stream);
const Stream& getStream(int stream_idx) const return stream_ok ? *m_stream[stream_idx] : getStreamExc(stream_idx); }
{ bool stream_ok = (stream_idx >= 0) && (stream_idx < m_nb_stream);
return stream_ok ? *m_stream[stream_idx] : getStreamExc(stream_idx); } const Stream& getStream(int stream_idx) const
{ bool stream_ok = (stream_idx >= 0) && (stream_idx < m_nb_stream);
Stream& getStreamExc(int stream_idx) const; return stream_ok ? *m_stream[stream_idx] : getStreamExc(stream_idx); }
SavingMode getAcqSavingMode() const Stream& getStreamExc(int stream_idx) const;
{ return getStream(0).getParameters(Acq).savingMode; }
SavingMode getAcqSavingMode() const
ManagedMode getManagedMode() const { return getStream(0).getParameters(Acq).savingMode; }
{ return getStream(0).getParameters(Acq).managedMode; }
ManagedMode getManagedMode() const
// --- from control { return m_managed_mode; }
void getSaveCounters(int& first_to_save, int& last_to_save)
{ AutoMutex lock(m_cond.mutex()); // --- from control
first_to_save = last_to_save = -1; void getSaveCounters(int& first_to_save, int& last_to_save)
FrameMap::const_iterator it, end = m_frame_datas.end(); { AutoMutex lock(m_cond.mutex());
for (it = m_frame_datas.begin(); it != end; ++it) { first_to_save = last_to_save = -1;
if (it->first > last_to_save) FrameMap::const_iterator it, end = m_frame_datas.end();
last_to_save = it->first; for (it = m_frame_datas.begin(); it != end; ++it) {
if ((first_to_save == -1) || (it->first < first_to_save)) if (it->first > last_to_save)
first_to_save = it->first; last_to_save = it->first;
if ((first_to_save == -1) || (it->first < first_to_save))
first_to_save = it->first;
}
} }
}
// --- internal call // --- internal call
void _prepare(); void _prepare();
void _getCommonHeader(HeaderMap&); void _getCommonHeader(HeaderMap&);
void _takeHeader(FrameHeaderMap::iterator&, HeaderMap& header, void _takeHeader(FrameHeaderMap::iterator&, HeaderMap& header,
bool keep_in_map); bool keep_in_map);
void _getTaskList(TaskType type, long frame_nr, const HeaderMap& header, void _getTaskList(TaskType type, long frame_nr, const HeaderMap& header,
TaskList& task_list); TaskList& task_list);
void _postTaskList(Data&, const TaskList&); void _postTaskList(Data&, const TaskList&);
void _compressionFinished(Data&, Stream&); void _compressionFinished(Data&, Stream&);
void _saveFinished(Data&, Stream&); void _saveFinished(Data&, Stream&);
void _setSavingError(CtControl::ErrorCode); void _setSavingError(CtControl::ErrorCode);
void _updateParameters(); void _updateParameters();
void _synchronousSaving(Data&,HeaderMap&); void _synchronousSaving(Data&,HeaderMap&);
bool _controlIsFault(); bool _controlIsFault();
bool _newFrameWrite(int); bool _newFrameWrite(int);
bool _checkHwFileFormat(const std::string&) const;
void _ReadImage(Data&,int framenb);
}; };
inline std::ostream& operator<<(std::ostream &os,const CtSaving::Parameters &params) inline std::ostream& operator<<(std::ostream &os,const CtSaving::Parameters &params)
{ {
const char *aFileFormatHumanPt; const char *aFileFormatHumanPt;
switch(params.fileFormat) switch(params.fileFormat)
{ {
case CtSaving::EDF: case CtSaving::EDF:
aFileFormatHumanPt = "EDF";break; aFileFormatHumanPt = "EDF";break;
case CtSaving::CBFFormat: case CtSaving::CBFFormat:
aFileFormatHumanPt = "CBF";break; aFileFormatHumanPt = "CBF";break;
case CtSaving::NXS: case CtSaving::NXS:
aFileFormatHumanPt = "NXS";break; aFileFormatHumanPt = "NXS";break;
case CtSaving::FITS: case CtSaving::FITS:
aFileFormatHumanPt = "FITS";break; aFileFormatHumanPt = "FITS";break;
case CtSaving::EDFGZ: case CtSaving::EDFGZ:
aFileFormatHumanPt = "EDF gzip";break; aFileFormatHumanPt = "EDF gzip";break;
default: default:
aFileFormatHumanPt = "RAW";break; aFileFormatHumanPt = "RAW";break;
} }
const char *aSavingModeHumanPt; const char *aSavingModeHumanPt;
switch(params.savingMode) switch(params.savingMode)
{ {
case CtSaving::AutoFrame: case CtSaving::AutoFrame:
aSavingModeHumanPt = "Auto frame";break; aSavingModeHumanPt = "Auto frame";break;
case CtSaving::AutoHeader: case CtSaving::AutoHeader:
aSavingModeHumanPt = "Auto header";break; aSavingModeHumanPt = "Auto header";break;
default: // Manual default: // Manual
aSavingModeHumanPt = "Manual";break; aSavingModeHumanPt = "Manual";break;
} }
const char *anOverwritePolicyHumanPt; const char *anOverwritePolicyHumanPt;
switch(params.overwritePolicy) switch(params.overwritePolicy)
{ {
case CtSaving::Overwrite: case CtSaving::Overwrite:
anOverwritePolicyHumanPt = "Overwrite";break; anOverwritePolicyHumanPt = "Overwrite";break;
case CtSaving::Append: case CtSaving::Append:
anOverwritePolicyHumanPt = "Append";break; anOverwritePolicyHumanPt = "Append";break;
default: // Abort default: // Abort
anOverwritePolicyHumanPt = "Abort";break; anOverwritePolicyHumanPt = "Abort";break;
} }
os << "<" os << "<"
<< "directory=" << params.directory << ", " << "directory=" << params.directory << ", "
<< "prefix=" << params.prefix << ", " << "prefix=" << params.prefix << ", "
<< "suffix=" << params.suffix << ", " << "suffix=" << params.suffix << ", "
<< "nextNumber=" << params.nextNumber << ", " << "nextNumber=" << params.nextNumber << ", "
<< "fileFormat=" << params.fileFormat << "," << aFileFormatHumanPt << ", " << "fileFormat=" << params.fileFormat << "," << aFileFormatHumanPt << ", "
<< "savingMode=" << params.savingMode << "," << aSavingModeHumanPt << ", " << "savingMode=" << params.savingMode << "," << aSavingModeHumanPt << ", "
<< "overwritePolicy=" << params.overwritePolicy << "," << anOverwritePolicyHumanPt << ", " << "overwritePolicy=" << params.overwritePolicy << "," << anOverwritePolicyHumanPt << ", "
<< "framesPerFile=" << params.framesPerFile << ", " << "framesPerFile=" << params.framesPerFile << ", "
<< "nbframes=" << params.nbframes << "nbframes=" << params.nbframes
<< ">"; << ">";
return os; return os;
} }
inline bool operator ==(const CtSaving::Parameters& a, inline bool operator ==(const CtSaving::Parameters& a,
const CtSaving::Parameters& b) const CtSaving::Parameters& b)
{ {
return ((a.directory == b.directory) && return ((a.directory == b.directory) &&
(a.prefix == b.prefix) && (a.prefix == b.prefix) &&
(a.suffix == b.suffix) && (a.suffix == b.suffix) &&
(a.imageType == b.imageType) && (a.imageType == b.imageType) &&
(a.nextNumber == b.nextNumber) && (a.nextNumber == b.nextNumber) &&
(a.fileFormat == b.fileFormat) && (a.fileFormat == b.fileFormat) &&
(a.savingMode == b.savingMode) && (a.savingMode == b.savingMode) &&
(a.overwritePolicy == b.overwritePolicy) && (a.overwritePolicy == b.overwritePolicy) &&
(a.indexFormat == b.indexFormat) && (a.indexFormat == b.indexFormat) &&
(a.framesPerFile == b.framesPerFile) && (a.framesPerFile == b.framesPerFile) &&
(a.nbframes == b.nbframes)); (a.nbframes == b.nbframes));
} }
inline std::ostream& operator<<(std::ostream &os,const CtSaving::HeaderMap &header) inline std::ostream& operator<<(std::ostream &os,const CtSaving::HeaderMap &header)
{ {
os << "< "; os << "< ";
for(CtSaving::HeaderMap::const_iterator i = header.begin(); for(CtSaving::HeaderMap::const_iterator i = header.begin();
i != header.end();++i) i != header.end();++i)
os << "(" << i->first << "," << i->second << ") "; os << "(" << i->first << "," << i->second << ") ";
os << ">"; os << ">";
return os; return os;
} }
inline std::ostream& operator<<(std::ostream &os,const CtSaving::HeaderValue &value) inline std::ostream& operator<<(std::ostream &os,const CtSaving::HeaderValue &value)
{ {
os << "< (" << value.first << "," << value.second << ") >"; os << "< (" << value.first << "," << value.second << ") >";
......
...@@ -197,6 +197,8 @@ using namespace lima; ...@@ -197,6 +197,8 @@ using namespace lima;
void getFramePerFile(unsigned long& frames_per_file /Out/, void getFramePerFile(unsigned long& frames_per_file /Out/,
int stream_idx=0) const; int stream_idx=0) const;
void setManagedMode(ManagedMode mode);
void getManagedMode(ManagedMode &mode /Out/) const;
// --- common headers // --- common headers
void resetCommonHeader(); void resetCommonHeader();
......
...@@ -256,9 +256,9 @@ void CtBuffer::setup(CtControl *ct) ...@@ -256,9 +256,9 @@ void CtBuffer::setup(CtControl *ct)
m_hw_buffer_cb->releaseAll(); m_hw_buffer_cb->releaseAll();
} }
void CtBuffer::getDataFromHwFrameInfo(Data &fdata, void CtBuffer::transformHwFrameInfoToData(Data &fdata,
const HwFrameInfoType& frame_info, const HwFrameInfoType& frame_info,
int readBlockLen) int readBlockLen)
{ {
DEB_STATIC_FUNCT(); DEB_STATIC_FUNCT();
DEB_PARAM() << DEB_VAR2(frame_info, readBlockLen); DEB_PARAM() << DEB_VAR2(frame_info, readBlockLen);
...@@ -302,12 +302,20 @@ void CtBuffer::getDataFromHwFrameInfo(Data &fdata, ...@@ -302,12 +302,20 @@ void CtBuffer::getDataFromHwFrameInfo(Data &fdata,
fdata.setBuffer(fbuf); fdata.setBuffer(fbuf);
fbuf->unref(); fbuf->unref();
}
void CtBuffer::getDataFromHwFrameInfo(Data &fdata,
const HwFrameInfoType& frame_info,
int readBlockLen)
{
DEB_MEMBER_FUNCT();
transformHwFrameInfoToData(fdata,frame_info,readBlockLen);
// Manage Buffer callback // Manage Buffer callback
if(m_hw_buffer_cb) if(m_hw_buffer_cb)
{ {
m_hw_buffer_cb->map(frame_info.frame_ptr); m_hw_buffer_cb->map(frame_info.frame_ptr);
fbuf->callback = m_data_destroy_callback; fdata.buffer->callback = m_data_destroy_callback;
} }
DEB_RETURN() << DEB_VAR1(fdata); DEB_RETURN() << DEB_VAR1(fdata);
} }
......
...@@ -244,6 +244,11 @@ void CtControl::prepareAcq() ...@@ -244,6 +244,11 @@ void CtControl::prepareAcq()
DEB_TRACE() << "Prepare Accumulation if needed"; DEB_TRACE() << "Prepare Accumulation if needed";
m_ct_accumulation->prepare(); m_ct_accumulation->prepare();
DEB_TRACE() << "Prepare Saving if needed";
m_ct_saving->_prepare();
m_autosave= m_ct_saving->hasAutoSaveMode();
m_ready= true;
DEB_TRACE() << "Prepare Hardware for Acquisition"; DEB_TRACE() << "Prepare Hardware for Acquisition";
m_hw->prepareAcq(); m_hw->prepareAcq();
...@@ -283,10 +288,6 @@ void CtControl::prepareAcq() ...@@ -283,10 +288,6 @@ void CtControl::prepareAcq()
else else
m_op_ext->setEndSinkTaskCallback(NULL); m_op_ext->setEndSinkTaskCallback(NULL);
m_ct_saving->_prepare();
m_autosave= m_ct_saving->hasAutoSaveMode();
m_ready= true;
#ifdef WITH_SPS_IMAGE #ifdef WITH_SPS_IMAGE
m_display_active_flag = m_ct_sps_image->isActive(); m_display_active_flag = m_ct_sps_image->isActive();
if(m_display_active_flag) if(m_display_active_flag)
...@@ -302,6 +303,19 @@ void CtControl::prepareAcq() ...@@ -302,6 +303,19 @@ void CtControl::prepareAcq()
m_images_buffer.clear(); m_images_buffer.clear();
m_ct_video->_prepareAcq(); m_ct_video->_prepareAcq();
m_ct_event->_prepareAcq(); m_ct_event->_prepareAcq();
//Check that no software operation is done if Hardware saving is activated
CtSaving::ManagedMode savingManagedMode;
m_ct_saving->getManagedMode(savingManagedMode);
if(savingManagedMode == CtSaving::Hardware &&
(m_op_int_active ||
m_op_ext_link_task_active ||
m_op_ext_sink_task_active ||
#ifdef WITH_SPS_IMAGE
m_display_active_flag ||
#endif
m_ct_video->isActive()))
THROW_CTL_ERROR(Error) << "Can't have any software operation if Hardware saving is active";
} }
void CtControl::startAcq() void CtControl::startAcq()
...@@ -472,7 +486,18 @@ void CtControl::ReadImage(Data &aReturnData,long frameNumber, ...@@ -472,7 +486,18 @@ void CtControl::ReadImage(Data &aReturnData,long frameNumber,
else else
{ {
aLock.unlock(); aLock.unlock();
ReadBaseImage(aReturnData,frameNumber,readBlockLen); // todo change when external op activated CtSaving::ManagedMode savingManagedMode;
m_ct_saving->getManagedMode(savingManagedMode);
if(savingManagedMode == CtSaving::Hardware)
{
if (readBlockLen != 1)
THROW_CTL_ERROR(NotSupported) << "Cannot read more than one frame "
<< "at a time with Hardware Saving";
m_ct_saving->_ReadImage(aReturnData,frameNumber);
}
else
ReadBaseImage(aReturnData,frameNumber,readBlockLen);
} }
DEB_RETURN() << DEB_VAR1(aReturnData); DEB_RETURN() << DEB_VAR1(aReturnData);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "CtSaving.h" #include "CtSaving.h"
#include "CtSaving_Edf.h" #include "CtSaving_Edf.h"
#include "CtAcquisition.h" #include "CtAcquisition.h"
#include "CtBuffer.h"
#ifdef WITH_NXS_SAVING #ifdef WITH_NXS_SAVING
#include "CtSaving_Nxs.h" #include "CtSaving_Nxs.h"
...@@ -141,7 +142,7 @@ private: ...@@ -141,7 +142,7 @@ private:
*/ */
CtSaving::Parameters::Parameters() CtSaving::Parameters::Parameters()
: nextNumber(0), fileFormat(RAW), savingMode(Manual), : nextNumber(0), fileFormat(RAW), savingMode(Manual),
overwritePolicy(Abort),managedMode(Software), overwritePolicy(Abort),
indexFormat("%04d"),framesPerFile(1) indexFormat("%04d"),framesPerFile(1)
{ {
} }
...@@ -383,7 +384,7 @@ public: ...@@ -383,7 +384,7 @@ public:
m_saving(ct_saving) m_saving(ct_saving)
{ {
} }
bool newFrameWrite(int frame_id) bool newFrameWritten(int frame_id)
{ {
return m_saving._newFrameWrite(frame_id); return m_saving._newFrameWrite(frame_id);
} }
...@@ -398,7 +399,8 @@ CtSaving::CtSaving(CtControl &aCtrl) : ...@@ -398,7 +399,8 @@ CtSaving::CtSaving(CtControl &aCtrl) :
m_ready_flag(true), m_ready_flag(true),
m_need_compression(false), m_need_compression(false),
m_nb_save_cbk(0), m_nb_save_cbk(0),
m_end_cbk(NULL) m_end_cbk(NULL),
m_managed_mode(Software)
{ {
DEB_CONSTRUCTOR(); DEB_CONSTRUCTOR();
...@@ -610,6 +612,70 @@ void CtSaving::getFormat(FileFormat& format, int stream_idx) const ...@@ -610,6 +612,70 @@ void CtSaving::getFormat(FileFormat& format, int stream_idx) const
DEB_RETURN() << DEB_VAR1(format); DEB_RETURN() << DEB_VAR1(format);
} }
/** @brief return a list of hardware possible saving format
*/
void CtSaving::getHardwareFormatList(std::list<std::string> &format_list) const
{
DEB_MEMBER_FUNCT();
if(!m_has_hwsaving)
THROW_CTL_ERROR(NotSupported) << "No hardware saving for this camera";
m_hwsaving->getPossibleSaveFormat(format_list);
}
void CtSaving::setHardwareFormat(const std::string &format)
{
DEB_MEMBER_FUNCT();
if(!m_has_hwsaving)
THROW_CTL_ERROR(NotSupported) << "No hardware saving for this camera";
bool found = _checkHwFileFormat(format);
if(!found)
{
THROW_CTL_ERROR(NotSupported) <<
"Hardware does not support" << DEB_VAR1(format);
}
m_specific_hardware_format = format;
}
bool CtSaving::_checkHwFileFormat(const std::string &format) const
{
std::list<std::string> format_list;
m_hwsaving->getPossibleSaveFormat(format_list);
bool found = false;
for(std::list<std::string>::const_iterator i = format_list.begin();
!found && i != format_list.end();++i)
found = *i == format;
return found;
}
void CtSaving::_ReadImage(Data &image,int frameNumber)
{
DEB_MEMBER_FUNCT();
if(m_hwsaving->getCapabilities() & HwSavingCtrlObj::MANUAL_READ)
{
HwFrameInfoType frame;
m_hwsaving->readFrame(frame,frameNumber);
CtBuffer::transformHwFrameInfoToData(image,frame);
}
else
THROW_CTL_ERROR(NotSupported) << "Image read is not supported for this hardware";
}
void CtSaving::getHardwareFormat(std::string &format) const
{
DEB_MEMBER_FUNCT();
if(!m_has_hwsaving)
THROW_CTL_ERROR(NotSupported) << "No hardware saving for this camera";
format = m_specific_hardware_format;
}
/** @brief set the saving mode for a saving stream /** @brief set the saving mode for a saving stream
*/ */
void CtSaving::setSavingMode(SavingMode mode) void CtSaving::setSavingMode(SavingMode mode)
...@@ -709,13 +775,21 @@ void CtSaving::setManagedMode(CtSaving::ManagedMode mode) ...@@ -709,13 +775,21 @@ void CtSaving::setManagedMode(CtSaving::ManagedMode mode)
THROW_CTL_ERROR(InvalidValue) << DEB_VAR1(mode) << "Not supported"; THROW_CTL_ERROR(InvalidValue) << DEB_VAR1(mode) << "Not supported";
AutoMutex aLock(m_cond.mutex()); AutoMutex aLock(m_cond.mutex());
for (int s = 0; s < m_nb_stream; ++s) if(mode == Hardware)
{ {
Stream& stream = getStream(s); if(!m_has_hwsaving)
Parameters pars = stream.getParameters(Auto); THROW_CTL_ERROR(NotSupported) << "Hardware saving is not supported";
pars.managedMode = mode;
stream.setParameters(pars); int hw_cap = m_hwsaving->getCapabilities();
if(hw_cap & HwSavingCtrlObj::COMMON_HEADER)
m_hwsaving->setCommonHeader(m_common_header);
else if(!m_common_header.empty())
{
THROW_CTL_ERROR(Error) << "Hardware saving do not manage common header"
<< ", clear it first";
}
} }
m_managed_mode = mode;
} </