Commit 9427e046 by d_a_heitbrink Committed by David Heitbrink

fixed some formating, added some predefs

parent 5e0a94a9
......@@ -6,14 +6,21 @@ project(DaqIOLib CXX)
set(CMAKE_C_FLAGS "-Wall -g")
set (SOURCES
DaqFileIO.cxx
DaqFileIO.cxx
DaqPlayer.cpp
)
set (HEADERS
DaqBuffer.h
DaqChannelInfo.h
DaqIo.h
DaqIoLib.h
DaqIoLibDefines.h
DaqBuffer.h
DaqChannelInfo.h
DaqIo.h
DaqIoLib.h
DaqIoLibDefines.h
DaqPlayer.h
)
set (TEST_DAQ
daqTest.cpp
daqTest.h
)
......@@ -25,11 +32,15 @@ source_group("Header Files" FILES ${HEADERS})
################################################################################
set(ROOT_NAMESPACE DaqIOLib)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
endif()
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/./"
"${CMAKE_CURRENT_SOURCE_DIR}/./"
"${CMAKE_CURRENT_SOURCE_DIR}/../nads-boost;"
)
......@@ -39,12 +50,24 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
)
add_executable(testDaq ${TEST_DAQ})
target_link_libraries(testDaq PUBLIC
${PROJECT_NAME}
misc
)
set_target_properties(testDaq PROPERTIES
CXX_STANDARD 17
CXX_EXCEPTIONS on
)
################################################################################
# Output directory
################################################################################
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}//lib/"
OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}//lib/"
OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}//lib/"
)
......@@ -41,7 +41,7 @@ public:
int GetItemCount() const; ///< C
int GetType() const; ///< D
int GetId() const; ///< E
const std::string& GetName() const; ///< H
const std::string& GetName() const; ///< H
int GetCapRate() const; ///< G
bool IsVarLen() const; ///< H
......
......@@ -491,7 +491,7 @@ CDaqLowLevelIo::ResyncFrame(
// Since we've lost allignment, we can't keep reading, we have to
// keep looking for a frame header one byte at a time
else {
fseek(m_pFile, 1 - 3 * sizeof(int), SEEK_CUR);
fseek(m_pFile, long(1 - 3 * sizeof(int)), SEEK_CUR);
bytesSkipped++;
}
}
......@@ -925,6 +925,10 @@ CDaqLowLevelIo::CheckIntegrity(
if ( rcode == eDAQ_READ_EOF ) {
int tot = m_LastFrame - m_FirstFrame;
(*m_UserProgrFunc)(m_Filename.c_str(), tot, tot);
auto ptr = _progressHandler.lock();
if (ptr) {
ptr->progf(m_Filename.c_str(), tot, tot);
}
break;
}
}
......@@ -948,6 +952,10 @@ CDaqLowLevelIo::CheckIntegrity(
m_Skips.push_back(skip);
sprintf(buf, "Data error before %d, resync'ed successfuly", ftell(m_pFile));
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
}
// Now read information about data in this record and skip over data portion
......@@ -964,6 +972,10 @@ CDaqLowLevelIo::CheckIntegrity(
m_LastFrame = curFrame;
done = true;
(*m_UserErrorFunc)(m_Filename.c_str(), "reached EOF with no end-marker");
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), "reached EOF with no end-marker");
}
break;
}
else if ( m_EofStatus == eDAQ_EOF_PARTIAL_MARK && curFrame == m_LastFrame ) {
......@@ -987,6 +999,10 @@ CDaqLowLevelIo::CheckIntegrity(
if ( rcode == eRESYNC_CHANNEL || rcode == eRESYNC_FRAME ) {
sprintf(buf, "Invalid channel %d @ ofs %d, resync'ed ok", chId, errOfs);
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
break;
}
else {
......@@ -1007,6 +1023,10 @@ CDaqLowLevelIo::CheckIntegrity(
chId, ftell(m_pFile));
m_LastError = buf;
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
return false;
}
skip = ch.GetItemSize() * actCount;
......@@ -1030,6 +1050,10 @@ CDaqLowLevelIo::CheckIntegrity(
if ( numRead == 1 && okChan ) {
sprintf(buf, "Found extra channel %d in frame %d", chId, curFrame);
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
ch--;
fseek(m_pFile, -4, SEEK_CUR);
continue;
......@@ -1066,6 +1090,10 @@ CDaqLowLevelIo::CheckIntegrity(
sprintf(buf, "Highest number frame (%d) wasn't last one in file,"
"which was %d", largestFrame, m_LastFrame);
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
m_LastFrame = largestFrame;
}
while ( frm < m_LastFrame ) {
......@@ -1213,8 +1241,13 @@ CDaqLowLevelIo::LowLevelDataRead(
numFrames++;
// print info every 30 seconds of collection (30*240=720)
if ( (numFrames % 720) == 0 )
(*m_UserProgrFunc)(m_Filename.c_str(), numFrames, m_LastFrame - m_FirstFrame);
if ((numFrames % 720) == 0) {
(*m_UserProgrFunc)(m_Filename.c_str(), numFrames, m_LastFrame - m_FirstFrame);
auto ptr = _progressHandler.lock();
if (ptr) {
ptr->progf(m_Filename.c_str(), numFrames, m_LastFrame - m_FirstFrame);
}
}
}
else if ( recHead[0] == -2 ) { // This is an end marker
curFrame = recHead[1];
......@@ -1232,7 +1265,10 @@ CDaqLowLevelIo::LowLevelDataRead(
sprintf(buf, "Unexpected header code %d at file offset %d",
recHead[0], ftell(m_pFile));
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
int skip;
int ofs = ftell(m_pFile);
if ( ResyncFrame(curFrame, skip) == false ) {
......@@ -1277,6 +1313,10 @@ CDaqLowLevelIo::LowLevelDataRead(
chId, ftell(m_pFile));
m_LastError = buf;
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
return false;
}
size = ch.GetItemSize() * actCount;
......@@ -1770,7 +1810,7 @@ CDaqLowLevelIo::GetFullData(
const void* pSrc = latestData[idx].GetDataPtr();
if (pSrc) {
if ( diffChan && (option & eEXPAND_DIFFERENTIAL) ) {
if ( diffChan && !(option & eEXPAND_DIFFERENTIAL) ) {
userDataStorage[idx].Append(pSrc, size, chInf.GetItemCount());
if ( pFrmList) (*pFrmList)[idx].push_back(curFrame);
}
......@@ -1874,6 +1914,10 @@ CDaqLowLevelIo::ReadDataForOneFrame(
chId, ftell(m_pFile));
m_LastError = buf;
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
return eDAQ_READ_ERROR;
}
size = ch.GetItemSize() * actCount;
......@@ -1954,6 +1998,10 @@ CDaqLowLevelIo::ReadChannelDataForOneFrame(
chId, ftell(m_pFile));
m_LastError = buf;
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
return eDAQ_READ_ERROR;
}
size = ch.GetItemSize() * actCount;
......@@ -2066,6 +2114,12 @@ CDaqLowLevelIo::ReadFrameHeader(
if ( (curFrame % 720) == 0 ) {
(*m_UserProgrFunc)(m_Filename.c_str(), curFrame - m_FirstFrame,
m_LastFrame - m_FirstFrame);
auto ptr = _progressHandler.lock();
if (ptr) {
ptr->progf(m_Filename.c_str(),
curFrame - m_FirstFrame,
m_LastFrame - m_FirstFrame);
}
}
return eDAQ_READ_OK;
}
......@@ -2084,6 +2138,10 @@ CDaqLowLevelIo::ReadFrameHeader(
sprintf(buf, "Expected header code (-1) but found %d at fileofs %d",
recHead[0], ftell(m_pFile));
(*m_UserErrorFunc)(m_Filename.c_str(), buf);
auto ref = _errorHandler.lock();
if (ref) {
ref->DaqError(m_Filename.c_str(), buf);
}
int ofs = ftell(m_pFile);
if ( ResyncFrame(curFrame, skip) == false ) {
......
......@@ -25,19 +25,78 @@ public:
CDaqLowLevelIo();
~CDaqLowLevelIo();
class ErrorHandler {
public:
ErrorHandler() = default;
virtual void DaqError(const char *, const char *) = 0;
};
typedef std::shared_ptr<ErrorHandler> TErrorHandlerRef;
typedef std::weak_ptr<ErrorHandler> TErrorHandlerWRef;
class ProgressHandler {
public:
ProgressHandler() = default;
virtual void progf(const char *, int, int) = 0;
};
typedef std::shared_ptr<ProgressHandler> TProgressHandlerRef;
typedef std::weak_ptr<ProgressHandler> TProgressHandlerWRef;
template <class T> class DaqProgCB {
public:
static TErrorHandlerRef Register(T* ref,CDaqLowLevelIo* daq) {
auto ref = std::make_shared< DaqProgCB<T> >(ref);
daq->SetProgressHandler(ref);
return ref;
}
virtual void progf(const char *name, int pram1, int param2) override {
_ref->DaqReadProgress(name,pram1,param2);
}
private:
DaqProgCB(T* ref) :ProgressHandler(),_ref(ref) {}
TErrorHandlerRef _ref;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \class DaqErrorCB
///
/// \brief A daq error cb.
///
/// \author D A Heitbrink
/// \date 9/25/2020
///
/// \tparam T Generic type parameter.
////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T> class DaqErrorCB {
public:
static TErrorHandlerRef Register(T* ref,CDaqLowLevelIo* daq) {
auto ref = std::make_shared< DaqErrorCB<T> >(ref);
daq->SetErrorHandler(ref);
return ref;
}
virtual void DaqError(const char *file, const char *error) {
ref->DaqError(file, error);
}
private:
DaqErrorCB(T* ref) :ErrorHandler(),_ref(ref) {}
TErrorHandlerRef _ref;
};
bool LowLevelDataRead(const TIntVec* , TDataVec& , std::vector<TIntVec>* pFrameList=0);
bool LowLevelDataCopy(const TIntVec* chans, TFileVec& dest,
TConvertOptions options = eBINARY_FORMAT + eINCLUDE_FRAME);
bool GetFullData(const TIntVec* chans, TDataVec& data, TConvertOptions option = eNO_OPTION,
int firstFrame = -1, int lastFrame = -1, std::vector<TIntVec>* pFrameList = 0, int maxDiffLook = -1);
bool Open(const std::string &); ///< Open the file
void GetChannels(TChanInfoVec& channels) const; ///< Return info about channels
bool GetChannelInfo(int chId, CDaqChannelInfo &info) const;
int GetFirstFrame() const;
int GetLastFrame() const;
int GetFrames() const;
int GetFrequency() const;
bool Open(const std::string &); ///< Open the file
void GetChannels(TChanInfoVec& channels) const; ///< Return info about channels
bool GetChannelInfo(int chId, CDaqChannelInfo &info) const;
int GetFirstFrame() const;
int GetLastFrame() const;
int GetFrames() const;
int GetFrequency() const;
const std::string& GetDate() const;
const std::string& GetVersion() const;
const std::string& GetTitle() const;
......@@ -45,8 +104,8 @@ public:
const std::string& GetRun() const;
const std::string& GetRunInst() const;
const std::string& GetFileName() const;
size_t GetNumChannels() const;
bool TocFileExists() const;
size_t GetNumChannels() const;
bool TocFileExists() const;
bool CheckIntegrity(bool buildToc = false, bool forceFileCreate = false);
bool QueryIntegrityValues(TIntVec& drops, TIntVec& dropedFrm, TIntVec& skips,
......@@ -61,8 +120,8 @@ public:
int GetDroppedFrames() const;
void SetCallbacks( void errf(const char *, const char *), void progf(const char *, int, int));
void SetErrorHandler(TErrorHandlerRef error) { _errorHandler = error; };
void SetProgressHandler(TProgressHandlerWRef handler) { _progressHandler = handler; };
private:
enum TReadErrorCode {
eDAQ_READ_OK,
......@@ -92,14 +151,14 @@ private:
TReadErrorCode ReadChannelDataForOneFrame(int, int, CDaqBuffer&, void*, bool&);
std::string m_Filename;
std::string m_Version; ///< file version
std::string m_Version; ///< file version
FILE* m_pFile;
std::string m_Title; ///< Simulation title, as stored in DAQ file
std::string m_Date; ///< Date of collection, as stored in DAQ file
std::string m_Subj; ///< As stored in DAQ file
std::string m_Run; ///< As stored in DAQ file
std::string m_RunInst; ///< As stored in DAQ file
std::string m_Title; ///< Simulation title, as stored in DAQ file
std::string m_Date; ///< Date of collection, as stored in DAQ file
std::string m_Subj; ///< As stored in DAQ file
std::string m_Run; ///< As stored in DAQ file
std::string m_RunInst; ///< As stored in DAQ file
int m_NumEntries; ///< As stored in DAQ file
int m_Frequency; ///< As stored in DAQ file
......@@ -110,13 +169,16 @@ private:
bool m_HaveToc; ///< Indicates if we have TOC in memory
TChanInfoVec m_Channels; ///< Channel information
long m_DataOffset; ///< where data starts in the file
std::map<int, int> m_Toc; ///< given a sim frame, gives the offset in the file
std::vector<int> m_DroppedFrames;
std::map<int, int> m_Toc; ///< given a sim frame, gives the offset in the file
std::vector<int> m_DroppedFrames;
int m_FirstFrame;
int m_LastFrame;
mutable std::string m_LastError;
mutable std::string m_LastError;
TDaqEofStatus m_EofStatus;
TErrorHandlerWRef _errorHandler;
TProgressHandlerWRef _progressHandler;
// These are for data integrity
TIntVec m_FrameDrops; ///< sequences of skipped frames
TIntVec m_Skips; ///< groups of bytes skipped
......
#include <string>
#include <vector>
#include <map>
#include <memory>
#include "DaqPlayer.h"
using namespace std;
DaqPlayer::DaqPlayer(int stride):_stride(stride),_firstFrame(-1),_lastFrame(-1) {
}
bool DaqPlayer::OpenDaqFile(const std::string& fileName,TStrVec items) {
if (_pDaqIo) {
_pDaqIo.reset();
}
_cellList = items;
string temp;
_pDaqIo = std::make_unique<CDaqLowLevelIo>();
struct stat daqTocInfo;
//_pDaqIo->SetCallbacks(NULL, &DaqProgressCallBack);
temp = fileName;
temp += ".toc";
//see if we have a .toc file, if not create one
if (0 != stat(temp.c_str(), &daqTocInfo)) {
if (!_pDaqIo->Open(fileName)) {
string message = "Unable to load DAQ file - ";
message += _pDaqIo->GetLastError();
_pDaqIo.reset();
return false;
}
if (!_pDaqIo->CheckIntegrity(true, true)) {
_pDaqIo.reset();
return false;
}
}
else if (!_pDaqIo->Open(fileName) || !_pDaqIo->TocFileExists()) {
string message = "Unable to load DAQ file - ";
message += _pDaqIo->GetLastError();
return false;
}
_pDaqIo->GetChannels(_allDaqChannels);
_DaqFrameRate = _pDaqIo->GetFrequency();
if (_DaqFrameRate < 60)
_DaqFrameRate = 60;
size_t cnt = 0;
for (TChanInfoVec::iterator i = _allDaqChannels.begin(); i != _allDaqChannels.end(); i++,cnt++) {
_varNameList.push_back(i->GetName());
_nameToChannel[i->GetName()] = cnt;
for (auto & val : _cellList) {
if (i->GetName() == val) {
_getDaqChannels.push_back(i->GetId());
_daqNameToIndex[val] = (int)_getDaqChannels.size() - 1;
}
}
}
CDaqBuffer empty;
_daqBuffers.resize(_getDaqChannels.size(), empty);
TConvertOptions opt = eNO_OPTION;
opt = opt + eFILL_MISSING;
_firstFrame =_pDaqIo->GetFirstFrame();
_lastFrame = _pDaqIo->GetFrames() / (_DaqFrameRate / 60) + _firstFrame;
//lets see if we have any droped frames
_pDaqIo->QueryIntegrityValues(
_stats.drops, _stats.dropedFrm, _stats.skips, _stats.eofStat);
}
bool DaqPlayer::GotoFrame(int frameNum) {
//DAH this is +3, we are counting by 4's and we are not guarented to have data every 4th frame, although this is true 95% of the time
if (!_pDaqIo->GetFullData(&_getDaqChannels, _daqBuffers, eFILL_MISSING, frameNum, frameNum + _stride - 1)) {
return false;
}
return true;
}
bool DaqPlayer::AddCell(const std::string& str) {
auto itr = _nameToChannel.find(str);
if (itr == _nameToChannel.end()) {
return false;
}
//see if we have it already
if (_daqNameToIndex.find(str) == _daqNameToIndex.end())
return true;
int id = _allDaqChannels[(itr->second)].GetId();
_getDaqChannels.push_back(id);
_daqNameToIndex[str] = _getDaqChannels.size()-1;
return true;
}
\ No newline at end of file
#pragma once
#include <DaqIoLib.h>
class DaqPlayer
{
typedef unsigned char TDaqByte;
typedef std::vector<int> TIntVec;
typedef std::vector<std::string> TStrVec;
typedef std::vector<CDaqBuffer> TDataVec;
typedef std::vector<CDaqChannelInfo> TChanInfoVec;
typedef std::unique_ptr<CDaqLowLevelIo> TDaqFile;
typedef struct TStats{
TIntVec drops;
TIntVec dropedFrm;
TIntVec skips;
TDaqEofStatus eofStat;
};
DaqPlayer(int stride = 4);
bool OpenDaqFile(const std::string &file,TStrVec items);
bool GotoFrame(int frameNum);
const TStats& GetStats() {return _stats;}
virtual void DaqReadProgress(const char *name, int pram1, int param2) {};
virtual void DaqError(const char *, const char *) {};
std::string GetLastError() { return m_lastError; };
bool AddCell(const std::string&);
template <class T> std::vector<T> GetData(const std::string& name){
std::vector<T> ret;
auto idx = _daqNameToIndex.find(name);
if (idx == _daqNameToIndex.end())
return ret;
auto index = idx->second;
auto type = _allDaqChannels[index].GetType();
int typeSize = sizeof(T);
if (index >= _daqBuffers.size())
return ret;
auto valValueVec = _daqBuffers.at(index);
auto cnt = valValueVec.GetCount();
ret.reserve(cnt);
for (size_t i = 0; i < cnt; i++) {
if (type == "i") {
ret.push_back((T)valValueVec.GetInt(i));
}
else if (type == "s"){
ret.push_back((T)valValueVec.GetShort(i));
}
else if (type == "c") {
ret.push_back((T)valValueVec.GetChar(i));
}
else if (type == "f") {
ret.push_back((T)valValueVec.GetFloat(i));
}
else if (type == "d") {
ret.push_back((T)valValueVec.GetDouble(i));
}
}
return ret;
}
private:
TDaqFile _pDaqIo;
TChanInfoVec _allDaqChannels;
struct TDifferntialDataFrame {
TDifferntialDataFrame() :frame(-1) {};
TDifferntialDataFrame(const TDifferntialDataFrame& in):frame(in.frame), data(in.data) {};
TDifferntialDataFrame(TDifferntialDataFrame&& in) :frame(in.frame), data(std::move(in.data)) {};
int frame;
CDaqBuffer data;
};
TIntVec _getDaqChannels;
CDaqLowLevelIo::TProgressHandlerRef _prog;
CDaqLowLevelIo::TErrorHandlerRef _error;
int _stride;
TStrVec _cellList;
std::map<std::string,int> _daqNameToIndex;
std::vector<CDaqBuffer> _daqBuffers;
std::map<std::string, size_t> _nameToChannel;
TStrVec _varNameList;
int _DaqFrameRate;
int _firstFrame;
int _lastFrame;
TStats _stats;
TDaqFile file;
std::string m_lastError;
};
#include <string>
#include <vector>
#include <map>
#include <memory>
#include "DaqPlayer.h"
using namespace std;
DaqPlayer::DaqPlayer(int stride):_stride(stride),_firstFrame(-1),_lastFrame(-1) {
}
bool DaqPlayer::OpenDaqFile(const std::string& fileName,TStrVec items) {
if (_pDaqIo) {
_pDaqIo.reset();
}
_cellList = items;
string temp;
_pDaqIo = std::make_unique<CDaqLowLevelIo>();
struct stat daqTocInfo;
//_pDaqIo->SetCallbacks(NULL, &DaqProgressCallBack);
temp = fileName;
temp += ".toc";
//see if we have a .toc file, if not create one
if (0 != stat(temp.c_str(), &daqTocInfo)) {
if (!_pDaqIo->Open(fileName)) {
string message = "Unable to load DAQ file - ";
message += _pDaqIo->GetLastError();
_pDaqIo.reset();
return false;
}
if (!_pDaqIo->CheckIntegrity(true, true)) {
_pDaqIo.reset();
return false;
}
}
else if (!_pDaqIo->Open(fileName) || !_pDaqIo->TocFileExists()) {
string message = "Unable to load DAQ file - ";
message += _pDaqIo->GetLastError();
return false;
}
_pDaqIo->GetChannels(_allDaqChannels);
_DaqFrameRate = _pDaqIo->GetFrequency();
if (_DaqFrameRate < 60)
_DaqFrameRate = 60;
size_t cnt = 0;
for (TChanInfoVec::iterator i = _allDaqChannels.begin(); i != _allDaqChannels.end(); i++,cnt++) {
_varNameList.push_back(i->GetName());
_nameToChannel[i->GetName()] = cnt;
for (auto & val : _cellList) {
if (i->GetName() == val) {
_getDaqChannels.push_back(i->GetId());
_daqNameToIndex[val] = (int)_getDaqChannels.size() - 1;
}
}
}
CDaqBuffer empty;
_daqBuffers.resize(_getDaqChannels.size(), empty);
TConvertOptions opt = eNO_OPTION;
opt = opt + eFILL_MISSING;
_firstFrame =_pDaqIo->GetFirstFrame();
_lastFrame = _pDaqIo->GetFrames() / (_DaqFrameRate / 60) + _firstFrame;
//lets see if we have any droped frames
_pDaqIo->QueryIntegrityValues(
_stats.drops, _stats.dropedFrm, _stats.skips, _stats.eofStat);
}
bool DaqPlayer::GotoFrame(int frameNum) {
//DAH this is +3, we are counting by 4's and we are not guarented to have data every 4th frame, although this is true 95% of the time
if (!_pDaqIo->GetFullData(&_getDaqChannels, _daqBuffers, eFILL_MISSING, frameNum, frameNum + _stride - 1)) {
return false;
}
return true;
}
bool DaqPlayer::AddCell(const std::string& str) {
auto itr = _nameToChannel.find(str);
if (itr == _nameToChannel.end()) {
return false;
}
//see if we have it already
if (_daqNameToIndex.find(str) == _daqNameToIndex.end())
return true;
int id = _allDaqChannels[(itr->second)].GetId();
_getDaqChannels.push_back(id);
_daqNameToIndex[str] = _getDaqChannels.size()-1;
return true;
}
\ No newline at end of file
#pragma once
#include <DaqIoLib.h>
class DaqPlayer
{
typedef unsigned char TDaqByte;
typedef std::vector<int> TIntVec;
typedef std::vector<std::string> TStrVec;
typedef std::vector<CDaqBuffer> TDataVec;
typedef std::vector<CDaqChannelInfo> TChanInfoVec;
typedef std::unique_ptr<CDaqLowLevelIo> TDaqFile;
typedef struct TStats{
TIntVec drops;
TIntVec dropedFrm;
TIntVec skips;
TDaqEofStatus eofStat;
};
DaqPlayer(int stride = 4);
bool OpenDaqFile(const std::string &file,TStrVec items);
bool GotoFrame(int frameNum);
const TStats& GetStats() {return _stats;}
virtual void DaqReadProgress(const char *name, int pram1, int param2) {};
virtual void DaqError(const char *, const char *) {};
std::string GetLastError() { return m_lastError; };
bool AddCell(const std::string&);
template <class T> std::vector<T> GetData(const std::string& name){
std::vector<T> ret;
auto idx = _daqNameToIndex.find(name);
if (idx == _daqNameToIndex.end())
return ret;
auto index = idx->second;
auto type = _allDaqChannels[index].GetType();
int typeSize = sizeof(T);
if (index >= _daqBuffers.size())
return ret;
auto valValueVec = _daqBuffers.at(index);
auto cnt = valValueVec.GetCount();
ret.reserve(cnt);
for (size_t i = 0; i < cnt; i++) {
if (type == "i") {
ret.push_back((T)valValueVec.GetInt(i));
}
else if (type == "s"){
ret.push_back((T)valValueVec.GetShort(i));
}
else if (type == "c") {
ret.push_back((T)valValueVec.GetChar(i));
}
else if (type == "f") {
ret.push_back((T)valValueVec.GetFloat(i));
}
else if (type == "d") {
ret.push_back((T)valValueVec.GetDouble(i));
}
}
return ret;
}
private:
TDaqFile _pDaqIo;
TChanInfoVec _allDaqChannels;
struct TDifferntialDataFrame {
TDifferntialDataFrame() :frame(-1) {};
TDifferntialDataFrame(const TDifferntialDataFrame& in):frame(in.frame), data(in.data) {};
TDifferntialDataFrame(TDifferntialDataFrame&& in) :frame(in.frame), data(std::move(in.data)) {};
int frame;
CDaqBuffer data;
};
TIntVec _getDaqChannels;
CDaqLowLevelIo::TProgressHandlerRef _prog;
CDaqLowLevelIo::TErrorHandlerRef _error;
int _stride;
TStrVec _cellList;
std::map<std::string,int> _daqNameToIndex;
std::vector<CDaqBuffer> _daqBuffers;
std::map<std::string, size_t> _nameToChannel;
TStrVec _varNameList;
int _DaqFrameRate;
int _firstFrame;
int _lastFrame;
TStats _stats;
TDaqFile file;
std::string m_lastError;
};
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