Commit 1cf0b91a authored by seb's avatar seb

- first cbf saving feature

- some small lifting for Pilatus
- add cbflib as a third-party project


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@259 45c4679d-1946-429d-baad-37912b19538b
parent 71cece76
......@@ -168,6 +168,7 @@ class PilatusDeviceServerClass(PyTango.DeviceClass):
#----------------------------------------------------------------------------
# Plugins
#----------------------------------------------------------------------------
import lima
from lima.Pilatus import Interface
_PilatusIterface = None
......
......@@ -8,6 +8,12 @@ include ../config.inc
CORE_LDFLAGS = -fPIC -L../third-party/Processlib/build
CORE_LDLIBS = -lprocesslib
ifneq ($(COMPILE_CBF_SAVING),0)
ct-objs += CtSaving_Cbf.o
CORE_LDFLAGS += -L../third-party/CBFLib/lib
CORE_LDLIBS += -lcbf
endif
ifneq ($(COMPILE_CORE),0)
core-objs := ../common/src/Common.o \
......
......@@ -22,7 +22,10 @@ class _ImageReader(threading.Thread) :
self.__continue = True
self.__buffer_ctrl = weakref.ref(buffer_ctrl)
com = buffer_ctrl._com()
self.__dirFd = os.open(com.DEFAULT_PATH,os.O_DIRECTORY)
try:
self.__dirFd = os.open(com.DEFAULT_PATH,os.O_DIRECTORY)
except OSError:
self.__dirFd = None
self.__basePath = com.DEFAULT_PATH
self.__fileBase = com.DEFAULT_FILE_BASE
......@@ -74,6 +77,9 @@ class _ImageReader(threading.Thread) :
def run(self) :
lastDirectoryTime = None
if not self.__dirFd: return #@todo should throw an execption
with self.__cond:
while(self.__continue) :
newDirectoryTime = os.fstat(self.__dirFd).st_mtime
......
......@@ -63,7 +63,10 @@ class DetInfoCtrlObj(lima.HwDetInfoCtrlObj) :
#@lima.Debug.DEB_MEMBER_FUNCT
def getDetectorModel(self):
return self.__name.split(',')[0].split()[-1]
if self.__name :
return self.__name.split(',')[0].split()[-1]
else:
return "Pilatus unknown"
##@brief image size won't change so no callback
......@@ -105,7 +108,10 @@ class DetInfoCtrlObj(lima.HwDetInfoCtrlObj) :
#@lima.Debug.DEB_MEMBER_FUNCT
def _readConfig(self) :
f = file(CAMERA_INFO_FILE)
try:
f = file(CAMERA_INFO_FILE)
except IOError:
return
for line in f:
if line.startswith(CAMERA_NAME_TOKEN) :
self.__name = line.split('=')[-1].strip(' \t\"')
......
......@@ -3,6 +3,8 @@ COMPILE_SIMULATOR=1
COMPILE_ESPIA=0
COMPILE_FRELON=0
COMPILE_MAXIPIX=0
COMPILE_CBF_SAVING=0
export COMPILE_CORE COMPILE_SIMULATOR \
COMPILE_ESPIA COMPILE_FRELON COMPILE_MAXIPIX
COMPILE_ESPIA COMPILE_FRELON COMPILE_MAXIPIX \
COMPILE_CBF_SAVING
......@@ -20,7 +20,6 @@ namespace lima {
friend class CtControl;
public:
CtSaving(CtControl&);
~CtSaving();
......@@ -28,6 +27,7 @@ namespace lima {
{
RAW,
EDF,
CBFFormat,
};
enum SavingMode
......@@ -79,7 +79,7 @@ namespace lima {
void setNextNumber(long number);
void getNextNumber(long& number) const;
void setFormat(const FileFormat &format);
void setFormat(FileFormat format);
void getFormat(FileFormat& format) const;
// --- saving modes
......@@ -128,15 +128,46 @@ namespace lima {
void clear();
class SaveContainer
{
DEB_CLASS_NAMESPC(DebModControl,"Saving Container","Control");
public:
SaveContainer(CtSaving&);
virtual ~SaveContainer();
void open(const CtSaving::Parameters&);
void close();
void writeFile(Data&,CtSaving::HeaderMap &);
void setStatisticSize(int aSize);
void getStatistic(std::list<double>&) const;
void clear();
protected:
virtual bool _open(const std::string &filename,
std::_Ios_Openmode flags) = 0;
virtual void _close() = 0;
virtual void _writeFile(Data &data,
CtSaving::HeaderMap &aHeader,
FileFormat) = 0;
int m_written_frames;
private:
CtSaving &m_saving;
std::list<double> m_statistic_list;
int m_statistic_size;
mutable Cond m_cond;
bool m_file_opened;
};
friend class SaveContainer;
private:
class _SaveTask;
class _SaveContainer;
class _SaveCBK;
friend class _SaveCBK;
friend class _SaveContainer;
CtControl &m_ctrl;
_SaveContainer *m_save_cnt;
SaveContainer *m_save_cnt;
_SaveCBK *m_saving_cbk;
Parameters m_pars;
HeaderMap m_common_header;
......@@ -154,6 +185,8 @@ namespace lima {
void _post_save_task(Data&,_SaveTask*);
void _save_finished(Data&);
void _setSavingError(CtControl::ErrorCode);
inline void _create_save_cnt(FileFormat);
inline void _check_if_multi_frame_per_file_allowed(FileFormat,int) const;
};
inline std::ostream& operator<<(std::ostream &os,const CtSaving::Parameters &params)
{
......
......@@ -92,6 +92,7 @@ using namespace lima;
enum FileFormat {
RAW,
EDF,
CBFFormat,
};
enum SavingMode {
......@@ -143,7 +144,7 @@ using namespace lima;
void setNextNumber(long number);
void getNextNumber(long& number) const;
void setFormat(const FileFormat &format);
void setFormat(FileFormat format);
void getFormat(FileFormat &format /Out/) const;
// --- saving modes
......
This diff is collapsed.
#include <ctype.h>
#include "CtSaving_Cbf.h"
using namespace lima;
static const char *DEFAULT_CATEGORY = "Misc";
static const char LIMA_HEADER_KEY_SEPARATOR = '/';
SaveContainerCbf::SaveContainerCbf(CtSaving &aCtSaving) :
CtSaving::SaveContainer(aCtSaving),
m_fout(NULL)
{
DEB_CONSTRUCTOR();
}
SaveContainerCbf::~SaveContainerCbf()
{
DEB_DESTRUCTOR();
_close();
}
bool SaveContainerCbf::_open(const std::string &filename,
std::_Ios_Openmode stdOpenflags)
{
DEB_MEMBER_FUNCT();
char openFlags[8];
if(stdOpenflags & std::ios_base::app)
openFlags[0] = 'a';
else if(stdOpenflags & std::ios_base::trunc)
openFlags[0] = 'w';
if(stdOpenflags & std::ios_base::binary)
openFlags[1] = 'b',openFlags[2] = '+',openFlags[3] = '\0';
else
openFlags[1] = '+',openFlags[2] = '\0';
m_fout = fopen(filename.c_str(),openFlags);
if(m_fout)
cbf_make_handle(&m_cbf);
return !!m_fout;
}
void SaveContainerCbf::_close()
{
DEB_MEMBER_FUNCT();
if (!m_fout)
{
DEB_TRACE() << "Nothing to do";
return;
}
DEB_TRACE() << "Close current file";
cbf_free_handle(m_cbf);
fclose(m_fout);
m_fout = NULL;
}
void SaveContainerCbf::_writeFile(Data &aData,
CtSaving::HeaderMap &aHeader,
CtSaving::FileFormat)
{
if(_writeCbfHeader(aData,aHeader))
throw LIMA_CTL_EXC(Error,"Something went wrong during CBF header writing");
if(_writeCbfData(aData))
throw LIMA_CTL_EXC(Error,"Something went wrong during CBF data writing");
}
int SaveContainerCbf::_writeCbfHeader(Data &aData,
CtSaving::HeaderMap &aHeader)
{
DEB_MEMBER_FUNCT();
aData.header.lock();
Data::HeaderContainer::Header &aDataHeader = aData.header.header();
aHeader.insert(aDataHeader.begin(),aDataHeader.end());
aData.header.unlock();
std::string previousCategory;
for(CtSaving::HeaderMap::iterator i = aHeader.begin();
i != aHeader.end();++i)
{
size_t found = i->first.find_last_of(LIMA_HEADER_KEY_SEPARATOR);
std::string currentCategory = i->first.substr(0,found);
std::string key = i->first.substr(found);
// no category was find so set it to default
if(key.empty())
{
key = currentCategory;
currentCategory = DEFAULT_CATEGORY;
}
if(previousCategory != currentCategory)
{
previousCategory = currentCategory;
cbf_failnez(cbf_new_category(m_cbf,currentCategory.c_str()));
}
cbf_failnez(cbf_new_column(m_cbf,key.c_str()));
cbf_failnez(cbf_set_value(m_cbf,i->second.c_str()));
}
return 0;
}
int SaveContainerCbf::_writeCbfData(Data &aData)
{
DEB_MEMBER_FUNCT();
char imageBuffer[64];
snprintf(imageBuffer,sizeof(imageBuffer),"image_%d",m_written_frames);
cbf_failnez(cbf_new_category (m_cbf, "array_data"));
cbf_failnez(cbf_new_column (m_cbf, "array_id"));
cbf_failnez(cbf_set_value (m_cbf, imageBuffer));
cbf_failnez(cbf_new_column (m_cbf, "binary_id"));
cbf_failnez(cbf_set_integervalue (m_cbf, m_written_frames));
cbf_failnez(cbf_new_column (m_cbf, "data"));
cbf_failnez(cbf_set_integerarray_wdims(m_cbf,
CBF_BYTE_OFFSET,
m_written_frames,
aData.data(),
aData.depth(),
aData.is_signed(),
aData.size(),
"little_endian",
aData.height,
aData.width,
0,
0));
cbf_failnez(cbf_write_file(m_cbf,m_fout,0,CBF,MSG_DIGEST|MIME_HEADERS,0));
return 0;
}
#ifndef CTSAVING_CBF_H
#define CTSAVING_CBF_H
#include <cbf.h>
#include "CtSaving.h"
namespace lima {
class SaveContainerCbf : public CtSaving::SaveContainer
{
DEB_CLASS_NAMESPC(DebModControl,"Saving CBF Container","Control");
public:
SaveContainerCbf(CtSaving &ct_saving);
virtual ~SaveContainerCbf();
protected:
virtual bool _open(const std::string &filename,
std::_Ios_Openmode flags);
virtual void _close();
virtual void _writeFile(Data &data,
CtSaving::HeaderMap &aHeader,
CtSaving::FileFormat);
private:
inline int _writeCbfHeader(Data&,CtSaving::HeaderMap&);
inline int _writeCbfData(Data&);
FILE* m_fout;
cbf_handle m_cbf;
};
}
#endif // CTSAVING_CBF_H
#include <sys/time.h>
#include "CtSaving_Edf.h"
using namespace lima;
/** @brief saving container
*
* This class manage file saving
*/
SaveContainerEdf::SaveContainerEdf(CtSaving &aCtSaving) :
CtSaving::SaveContainer(aCtSaving)
{
DEB_CONSTRUCTOR();
}
SaveContainerEdf::~SaveContainerEdf()
{
DEB_DESTRUCTOR();
}
bool SaveContainerEdf::_open(const std::string &filename,
std::_Ios_Openmode openFlags)
{
DEB_MEMBER_FUNCT();
m_fout.clear();
m_fout.exceptions(std::ios_base::failbit | std::ios_base::badbit);
m_fout.open(filename.c_str(),openFlags);
return true;
}
void SaveContainerEdf::_close()
{
DEB_MEMBER_FUNCT();
if (!m_fout.is_open()) {
DEB_TRACE() << "Nothing to do";
return;
}
DEB_TRACE() << "Close current file";
m_fout.close();
}
void SaveContainerEdf::_writeFile(Data &aData,
CtSaving::HeaderMap &aHeader,
CtSaving::FileFormat aFormat)
{
if(aFormat == CtSaving::EDF)
_writeEdfHeader(aData,aHeader);
m_fout.write((char*)aData.data(),aData.size());
}
void SaveContainerEdf::_writeEdfHeader(Data &aData,CtSaving::HeaderMap &aHeader)
{
DEB_MEMBER_FUNCT();
time_t ctime_now;
time(&ctime_now);
struct timeval tod_now;
gettimeofday(&tod_now, NULL);
char time_str[64];
ctime_r(&ctime_now, time_str);
time_str[strlen(time_str) - 1] = '\0';
int image_nb = m_written_frames + 1;
char aBuffer[512];
long aStartPosition = m_fout.tellp();
m_fout << "{\n";
snprintf(aBuffer,sizeof(aBuffer),"HeaderID = EH:%06u:000000:000000 ;\n", image_nb);
m_fout << aBuffer;
m_fout << "ByteOrder = LowByteFirst ;\n";
const char *aStringType = NULL;
switch(aData.type)
{
case Data::UINT8: aStringType = "UnsignedByte";break;
case Data::INT8: aStringType = "SignedByte";break;
case Data::UINT16: aStringType = "UnsignedShort";break;
case Data::INT16: aStringType = "SignedShort";break;
case Data::UINT32: aStringType = "UnsignedInteger";break;
case Data::INT32: aStringType = "SignedInteger";break;
case Data::UINT64: aStringType = "Unsigned64";break;
case Data::INT64: aStringType = "Signed64";break;
case Data::FLOAT: aStringType = "FloatValue";break;
case Data::DOUBLE: aStringType = "DoubleValue";break;
default:
break; // @todo ERROR has to be manage
}
m_fout << "DataType = " << aStringType << " ;\n";
m_fout << "Size = " << aData.size() << " ;\n";
m_fout << "Dim_1 = " << aData.width << " ;\n";
m_fout << "Dim_2 = " << aData.height << " ;\n";
m_fout << "acq_frame_nb = " << aData.frameNumber << " ;\n";
m_fout << "time = " << time_str << " ;\n";
snprintf(aBuffer,sizeof(aBuffer),"time_of_day = %ld.%06ld ;\n",tod_now.tv_sec, tod_now.tv_usec);
m_fout << aBuffer;
snprintf(aBuffer,sizeof(aBuffer),"time_of_frame = %.6f ;\n",aData.timestamp);
m_fout << aBuffer;
//@todo m_fout << "valid_pixels = " << aData.validPixels << " ;\n";
aData.header.lock();
Data::HeaderContainer::Header &aDataHeader = aData.header.header();
for(Data::HeaderContainer::Header::iterator i = aDataHeader.begin();i != aDataHeader.end();++i)
m_fout << i->first << " = " << i->second << " ;\n";
aData.header.unlock();
for(CtSaving::HeaderMap::iterator i = aHeader.begin(); i != aHeader.end();++i)
m_fout << i->first << " = " << i->second << " ;\n";
long aEndPosition = m_fout.tellp();
long lenght = aEndPosition - aStartPosition;
long finalHeaderLenght = (lenght + 511) & ~511; // 512 alignment
snprintf(aBuffer,sizeof(aBuffer),"%*s}\n",int(finalHeaderLenght - lenght - 2),"");
m_fout << aBuffer;
}
#ifndef CTSAVING_EDF_H
#define CTSAVING_EDF_H
#include "CtSaving.h"
namespace lima {
class SaveContainerEdf : public CtSaving::SaveContainer
{
DEB_CLASS_NAMESPC(DebModControl,"Saving EDF Container","Control");
public:
SaveContainerEdf(CtSaving &ct_saving);
virtual ~SaveContainerEdf();
protected:
virtual bool _open(const std::string &filename,
std::_Ios_Openmode flags);
virtual void _close();
virtual void _writeFile(Data &data,
CtSaving::HeaderMap &aHeader,
CtSaving::FileFormat);
private:
void _writeEdfHeader(Data&,CtSaving::HeaderMap&);
std::ofstream m_fout;
};
}
#endif // CTSAVING_EDF_H
ct-objs := CtSaving.o CtControl.o CtAcquisition.o CtBuffer.o \
CtImage.o CtSpsImage.o
include ../../config.inc
SRCS = $(ct-objs:.o=.cpp)
ct-objs := CtSaving.o CtControl.o CtAcquisition.o CtBuffer.o \
CtImage.o CtSpsImage.o CtSaving_Edf.o
INCLUDES = -I../include -I../../common/include -I../../hardware/include \
INCLUDES = -I. -I../include -I../../common/include -I../../hardware/include \
-I../software_operation/include \
-I../../third-party/Processlib/core/include \
-I../../third-party/Processlib/tasks/include \
-I../../third-party/Sps/Include
ifndef COMPILE_CBF_SAVING
COMPILE_CBF_SAVING = 0
endif
ifneq ($(COMPILE_CBF_SAVING),0)
ct-objs += CtSaving_Cbf.o
INCLUDES += -I../../third-party/CBFLib/include
CXXFLAGS += -DWITH_CBF_SAVING
endif
SRCS = $(ct-objs:.o=.cpp)
CXXFLAGS += $(INCLUDES) -fPIC -Wall -pthread -g
......@@ -17,7 +29,7 @@ all: Ct.o
Ct.o: $(ct-objs) ../software_operation/src/CtSoftwareOperation.o \
../../third-party/Sps/Src/sps.o
ld -o $@ -r $+
ld $(LIBS) -o $@ -r $+
clean:
rm -f Ct.o $(ct-objs) *.P
......
include ../../config.inc
lima-objs = ../../common/src/Common.o ../../hardware/src/Hw.o ../src/Ct.o
simu-objs = ../../camera/simulator/src/Simu.o
......@@ -15,6 +17,14 @@ CXXFLAGS += $(INC) -g -Wall -pthread
LDFLAGS = -pthread
LDLIBS = -L../../third-party/Processlib/build -lprocesslib
ifndef COMPILE_CBF_SAVING
COMPILE_CBF_SAVING = 0
endif
ifneq ($(COMPILE_CBF_SAVING),0)
LDLIBS += -L../../third-party/CBFLib/lib -lcbf
endif
all: simutest
simutest: $(simutest-objs) $(simutest-ext-objs)
......
......@@ -5,16 +5,16 @@ import shutil
import numpy
modules = [('core', ['common', 'hardware', 'control']),
('simulator', ['camera/simulator']),
('espia', ['camera/common/espia']),
('frelon', ['camera/frelon']),
('maxipix', ['camera/maxipix'])]
('simulator', [os.path.join('camera','simulator')]),
('espia', [os.path.join('camera','common','espia')]),
('frelon', [os.path.join('camera','frelon')]),
('maxipix', [os.path.join('camera','maxipix')])]
espiaModules = ['espia', 'frelon', 'maxipix']
rootDir = '..'
def rootName(fn):
return '%s/%s' % (rootDir, fn)
return os.path.join(rootDir, fn)
def findIncludes(baseDir):
inclDirs = []
......@@ -61,7 +61,7 @@ def main():
os.chdir('%s' % modName)
global rootDir
rootDir = '../' + rootDir
rootDir = os.path.join('..',rootDir)
sipFileNameSrc = "lima%s.sip" % modName
if modName != 'core':
......@@ -74,11 +74,11 @@ def main():
shutil.copyfile(sipFileNameSrc, sipFileName)
initNumpy = 'lima_init_numpy.cpp'
shutil.copyfile('../' + initNumpy, initNumpy)
shutil.copyfile(os.path.join('..',initNumpy), initNumpy)
dirProcesslib = rootName('third-party/Processlib')
sipProcesslib = dirProcesslib + '/sip'
dirProcesslib = rootName(os.path.join('third-party','Processlib'))
sipProcesslib = os.path.join(dirProcesslib,'/sip')
extraIncludes = ['.', '../core', sipProcesslib, numpy.get_include()]
extraIncludes += findIncludes(dirProcesslib)
......@@ -88,7 +88,7 @@ def main():
if (modName in espiaModules) and ('espia' not in excludeMods):
espia_base = '/segfs/bliss/source/driver/linux-2.6/espia'
espia_incl = espia_base + '/src'
espia_incl = os.path.join(espia_base,'src')
extraIncludes += [espia_incl]
extraIncludes += findModuleIncludes(modName)
......
include ../config.inc
PROJECTS = processlib.src sps.src
PROJECTS_CLEAN = processlib.clean sps.clean
ifndef COMPILE_CBF_SAVING
COMPILE_CBF_SAVING = 0
endif
ifneq ($(COMPILE_CBF_SAVING),0)
PROJECTS += cbflib.src
PROJECTS_CLEAN += cbflib.clean
endif
all: src test
src: processlib.src sps.src
src: $(PROJECTS)
processlib.src: Processlib/sip/Makefile Processlib/sip/processlib.so