Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tango-ds
DeviceClasses
Acquisition
2D
AGIPD
Commits
a87999c2
Commit
a87999c2
authored
Feb 15, 2016
by
Yuelong Yu
Browse files
add files
parent
4b66b251
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
agipd/NXFileWriter.h
0 → 100644
View file @
a87999c2
#ifndef __NXFILEWRITER_H__
#define __NXFILEWRITER_H__
#include
"NXWrapper.h"
namespace
NXFileNS
{
using
namespace
NexusNS
;
/**
* @brief class Nexus file writer
* write data in Nexus file
*/
class
NXFileWriter
{
public:
NXFileWriter
()
{
m_objNXWrapper
=
new
NXWrapper
();
}
~
NXFileWriter
()
{
delete
m_objNXWrapper
;
m_objNXWrapper
=
NULL
;
}
/**
* @brief create nexus file
* @param file name
* @param overwrite or not. true: overwrite the old file
* @return 0:OK; Otherwise error occurred
*/
int
CreateFile
()
{
string
strFullFileName
=
m_strFileName
;
//file split enabled
if
(
m_bSplitting
)
{
strFullFileName
=
m_strFileName
+
string
(
"_%3d"
)
+
string
(
"."
)
+
m_strFilePostfix
;
return
m_objNXWrapper
->
CreateFile
(
strFullFileName
,
m_bOverwrite
,
m_bSplitting
,
m_nLimitSize
);
}
else
{
strFullFileName
=
m_strFileName
+
string
(
"."
)
+
m_strFilePostfix
;
return
m_objNXWrapper
->
CreateFile
(
strFullFileName
,
m_bOverwrite
);
}
}
/**
* @brief create group
* @param group path,the place where the group is created
* @param group name
* @param NX class type
* @return 0: OK;
* 1: error occurred in HDF5 or PNI lib;
*/
int
CreateGroup
(
const
string
strGroupPath
,
const
string
strGroupName
,
const
string
strNXClassType
)
{
return
m_objNXWrapper
->
CreateGroup
(
strGroupPath
,
strGroupName
,
strNXClassType
);
}
/**
* @brief create field
* @param field path,the place where the field is created
* @param field name
* @return 0: OK;
* 1: error occurred in HDF5 or PNI lib;
*/
template
<
typename
T
>
int
CreateField
(
const
string
strGroupPath
,
const
string
strFieldName
)
{
return
m_objNXWrapper
->
CreateField
<
T
>
(
strGroupPath
,
strFieldName
);
}
template
<
typename
T
>
int
CreateField
(
const
string
strGroupPath
,
const
string
strFieldName
,
int
nSize
)
{
return
m_objNXWrapper
->
CreateField
<
T
>
(
strGroupPath
,
strFieldName
,
nSize
);
}
template
<
typename
T
>
int
Create2DField
(
const
string
strGroupPath
,
const
string
strFieldName
)
{
int
nCompressor
=
0
;
if
(
m_bCompression
)
nCompressor
=
1
;
return
m_objNXWrapper
->
Create2DField
<
T
>
(
strGroupPath
,
strFieldName
,
m_nCacheSize
,
m_nX
,
m_nY
,
nCompressor
);
}
/**
* Config File paramaters.
* @param : file path/name
* @param : overwrite old file
* @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
,
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
;
if
(
m_bCompression
)
return
m_objNXWrapper
->
CreateCompressor
(
m_bCompressorShuffle
,
m_ushCompressionRate
);
return
0
;
}
/**
* @brief close file
* @return 0: OK;
* 1: failed;
*/
int
CloseFile
()
{
return
m_objNXWrapper
->
CloseFile
();
}
/**
* @brief write data
* @param data field path
* @param data
* @param frame number field path
* @param frame number
* @param error code field path
* @param error code of the frame
* @return error code.
* 0: OK;
*/
template
<
typename
T
>
int
WriteData
(
string
strDataFieldPath
,
vector
<
T
>
vData
,
string
strFrameFieldPath
,
long
lFrameNo
,
string
strErrCodeFieldPath
,
short
shErrCode
)
{
return
m_objNXWrapper
->
Write2DData
<
T
>
(
strDataFieldPath
,
vData
,
m_nX
,
m_nY
,
strFrameFieldPath
,
lFrameNo
,
strErrCodeFieldPath
,
shErrCode
);
}
/**
* @brief write data
* @param data
* @param frame number field path
* @param error code field path
* @param frame number
* @param error code of the path
* @return error code.
* 0: OK;
*/
int
WriteCompressedData
(
string
strDataFieldPath
,
vector
<
unsigned
char
>
vuchData
,
string
strFrameFieldPath
,
long
lFrameNo
,
string
strErrCodeFieldPath
,
short
shErrCode
)
{
return
m_objNXWrapper
->
Write2DCompressedData
(
strDataFieldPath
,
vuchData
,
m_nX
,
m_nY
,
strFrameFieldPath
,
lFrameNo
,
strErrCodeFieldPath
,
shErrCode
);
}
/**
* Dump all tango attributes into Nexus file.
* @param : Field name
* @param : data, in order to support different data type. This method is overloaded.
* @param : unit, only if the data are int or double, it has unit
* @return : 0: OK;otherwise error occurred
*/
template
<
typename
T
>
int
DumpAllAttributesFromTango
(
string
strGroupName
,
string
strFieldName
,
T
tData
,
string
strUnit
=
string
(
""
))
{
int
nRet
=
this
->
CreateField
<
T
>
(
strGroupName
,
strFieldName
);
if
(
nRet
!=
0
)
return
nRet
;
string
strFullPath
=
GetPath
(
strGroupName
,
strFieldName
);
nRet
=
m_objNXWrapper
->
Write0DData
<
T
>
(
tData
,
strFullPath
,
strUnit
);
if
(
nRet
!=
0
)
return
nRet
;
return
0
;
}
int
DumpAllAttributesFromTango
(
string
strGroupName
,
string
strFieldName
,
string
strData
)
{
int
nRet
=
this
->
CreateField
<
string
>
(
strGroupName
,
strFieldName
);
if
(
nRet
!=
0
)
return
nRet
;
string
strFullPath
=
GetPath
(
strGroupName
,
strFieldName
);
nRet
=
m_objNXWrapper
->
Write0DData
<
string
>
(
strData
,
strFullPath
);
if
(
nRet
!=
0
)
return
nRet
;
return
0
;
}
template
<
typename
T
>
int
DumpAllAttributesFromTango
(
string
strGroupName
,
string
strFieldName
,
std
::
vector
<
T
>
vnData
)
{
int
nRet
=
this
->
Create2DField
<
T
>
(
strGroupName
,
strFieldName
);
if
(
nRet
!=
0
)
return
nRet
;
string
strFullPath
=
GetPath
(
strGroupName
,
strFieldName
);
nRet
=
m_objNXWrapper
->
Write2DData
<
T
>
(
strFullPath
,
vnData
,
m_nX
,
m_nY
);
if
(
nRet
!=
0
)
return
nRet
;
return
0
;
}
int
DumpAllAttributesFromTango
(
string
strGroupName
,
string
strFieldName
,
std
::
vector
<
float
>
vfData
,
int
nSize
,
string
strUnit
=
string
(
""
))
{
int
nRet
=
this
->
CreateField
<
float
>
(
strGroupName
,
strFieldName
,
nSize
);
if
(
nRet
!=
0
)
return
nRet
;
string
strFullPath
=
GetPath
(
strGroupName
,
strFieldName
);
nRet
=
m_objNXWrapper
->
Write1DData
<
float
>
(
vfData
,
strFullPath
,
strUnit
);
if
(
nRet
!=
0
)
return
nRet
;
return
0
;
}
private:
string
GetPath
(
string
strGroupName
,
string
strFieldName
)
{
string
strFullPath
=
strGroupName
;
char
chTemp
=
strGroupName
[(
strGroupName
.
length
()
-
1
)];
if
(
chTemp
!=
'/'
)
strFullPath
=
strFullPath
+
string
(
"/"
)
+
strFieldName
;
else
strFullPath
=
strFullPath
+
strFieldName
;
return
strFullPath
;
}
private:
int
m_nCacheSize
;
int
m_nDataDepth
;
int
m_nDataType
;
int
m_nX
;
int
m_nY
;
int
m_nSize
;
int
m_nLimitSize
;
//compression related parameters
unsigned
short
m_ushCompressionRate
;
bool
m_bBuildInCompressor
;
bool
m_bCompression
;
bool
m_bCompressorShuffle
;
bool
m_bSplitting
;
bool
m_bOverwrite
;
string
m_strFilePostfix
;
string
m_strFileName
;
NXWrapper
*
m_objNXWrapper
;
};
}
#endif
/* NXFILESAVING_H_ */
agipd/NXWrapper.h
0 → 100644
View file @
a87999c2
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment