Parser Upload.
This commit is contained in:
160
src/DataReader/MetaDataReader.cpp
Normal file
160
src/DataReader/MetaDataReader.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "MetaDataReader.h"
|
||||
#include "Mapper/MapperDataBase.h"
|
||||
#include "ShotList/ShotList.h"
|
||||
#include "Data/Hardwareinfomation.h"
|
||||
#include "Data/ConfigHeader.h"
|
||||
#include "Helper/MatlabHelper.h"
|
||||
#include "Json/json.hpp"
|
||||
|
||||
#include <matio.h>
|
||||
#include <fstream>
|
||||
|
||||
MetaDataReader::MetaDataReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MetaData MetaDataReader::getMetaDataFromKIT(const std::string& aFilePath,std::shared_ptr<ShotList> aShotList)
|
||||
{
|
||||
mat_t* matFile = Mat_Open(aFilePath.c_str(), MAT_ACC_RDONLY);
|
||||
MetaData result;
|
||||
if(matFile == nullptr)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
//DataType
|
||||
matvar_t* dataTypeVar = Mat_VarRead(matFile,"AScanDatatype");
|
||||
if(dataTypeVar!=nullptr)
|
||||
{
|
||||
result.setDataType(MatlabHelper::getMatlabString(dataTypeVar));
|
||||
}
|
||||
//Samplenumber
|
||||
matvar_t* sampleNumberVar = Mat_VarRead(matFile,"NumberSamples");
|
||||
if(sampleNumberVar!=nullptr)
|
||||
{
|
||||
result.setSampleNumber(static_cast<unsigned int>(*reinterpret_cast<double*>(sampleNumberVar->data)));
|
||||
}
|
||||
//Samplerate
|
||||
matvar_t* samplerateVar = Mat_VarRead(matFile,"SampleRate");
|
||||
if(samplerateVar!=nullptr)
|
||||
{
|
||||
result.setSamplerate(static_cast<unsigned int>(*reinterpret_cast<double*>(samplerateVar->data)));
|
||||
}
|
||||
matvar_t* metaDataVar = Mat_VarRead(matFile,"MetaData");
|
||||
if(metaDataVar !=nullptr)
|
||||
{
|
||||
//MeasurementID
|
||||
matvar_t* measurementIDVar = Mat_VarGetStructFieldByName(metaDataVar,"MeasurementID",0);
|
||||
if(measurementIDVar != nullptr)
|
||||
{
|
||||
result.setMeasurementID(MatlabHelper::getMatlabString(measurementIDVar));
|
||||
}
|
||||
//AperturePosition
|
||||
matvar_t* aperturePositionVar = Mat_VarGetStructFieldByName(metaDataVar,"PositionRotation",0);
|
||||
if(aperturePositionVar != nullptr)
|
||||
{
|
||||
unsigned short aperturePositionNum = static_cast<unsigned short>(aperturePositionVar->nbytes / static_cast<unsigned long long>(aperturePositionVar->data_size));
|
||||
result.setAperturePositionNumber(aperturePositionNum);
|
||||
}
|
||||
}
|
||||
//TASIndices
|
||||
std::shared_ptr<unsigned short> mapperArrayPointer = MapperDataBase::getMapperArray();
|
||||
unsigned long long tasIndicesLength = aShotList->getMuxSize() * TOTAL_CHANNEL;
|
||||
std::shared_ptr<uint8_t> tasIndices = std::shared_ptr<uint8_t>(new uint8_t[tasIndicesLength],std::default_delete<uint8_t[]>());
|
||||
for(unsigned int i = 0; i < aShotList->getMuxSize(); ++i)
|
||||
{
|
||||
unsigned int index = 0;
|
||||
for(unsigned int j = 0; j < TOTAL_CHANNEL; ++j)
|
||||
{
|
||||
tasIndices.get()[i * TOTAL_CHANNEL + j] = static_cast<uint8_t>(mapperArrayPointer.get()[index + 2]);
|
||||
index+=9;
|
||||
}
|
||||
}
|
||||
TasIndicesPointer tasIndicesPointer;
|
||||
tasIndicesPointer.setArray(tasIndices,tasIndicesLength);
|
||||
result.setTasIndices(tasIndicesPointer);
|
||||
//receiverIndices
|
||||
unsigned long long receiverIndicesLength = aShotList->getMuxSize() * TOTAL_CHANNEL;
|
||||
std::shared_ptr<uint8_t> receiverIndices = std::shared_ptr<uint8_t>(new uint8_t[receiverIndicesLength],std::default_delete<uint8_t[]>());
|
||||
for(unsigned int i = 0; i < aShotList->getMuxSize(); ++i)
|
||||
{
|
||||
unsigned int index = 0;
|
||||
unsigned short mux = aShotList->getMuxValue(i);
|
||||
for(unsigned int j = 0; j < TOTAL_CHANNEL; ++j)
|
||||
{
|
||||
receiverIndices.get()[i * TOTAL_CHANNEL + j] = static_cast<uint8_t>(mapperArrayPointer.get()[index + 2 + mux]);
|
||||
index+=9;
|
||||
}
|
||||
}
|
||||
ReceiverIndicesPointer receiverIndicesPointer;
|
||||
receiverIndicesPointer.setArray(receiverIndices,receiverIndicesLength);
|
||||
result.setReceiverIndices(receiverIndicesPointer);
|
||||
|
||||
|
||||
Mat_VarFree(dataTypeVar);
|
||||
Mat_VarFree(sampleNumberVar);
|
||||
Mat_VarFree(samplerateVar);
|
||||
Mat_VarFree(metaDataVar);
|
||||
Mat_Close(matFile);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
MetaData MetaDataReader::getMetaDataFromHJ(const std::string& aConfigBinPath, const std::string& aConfigJsonPath, ConfigHeader* aConfigHeader)
|
||||
{
|
||||
MetaData result;
|
||||
nlohmann::json jsonObj;
|
||||
std::ifstream jsonFile(aConfigJsonPath);
|
||||
jsonFile >> jsonObj;
|
||||
if(jsonObj.contains("General Info"))
|
||||
{
|
||||
nlohmann::json generalInfo = jsonObj.at("General Info");
|
||||
if(generalInfo.contains("MeasurementID"))
|
||||
{
|
||||
result.setMeasurementID(generalInfo.at("MeasurementID").get<std::string>());
|
||||
}
|
||||
if(generalInfo.contains("Aperture Position"))
|
||||
{
|
||||
result.setAperturePositionNumber(generalInfo.at("Aperture Position").get<unsigned short>());
|
||||
}
|
||||
}
|
||||
|
||||
if(jsonObj.contains("AMC Board Config"))
|
||||
{
|
||||
nlohmann::json amcBoardConfig = jsonObj.at("AMC Board Config");
|
||||
if(amcBoardConfig.contains("Data Format"))
|
||||
{
|
||||
result.setDataType(amcBoardConfig.at("Data Format").get<std::string>());
|
||||
}
|
||||
if(amcBoardConfig.contains("Sample Rate"))
|
||||
{
|
||||
result.setSamplerate(amcBoardConfig.at("Sample Rate").get<unsigned int>());
|
||||
}
|
||||
if(amcBoardConfig.contains("Shot length"))
|
||||
{
|
||||
result.setSampleNumber(amcBoardConfig.at("Shot length").get<unsigned int>());
|
||||
}
|
||||
}
|
||||
|
||||
std::ifstream stream;
|
||||
stream.open(aConfigBinPath, std::ios_base::binary | std::ios::in);
|
||||
stream.seekg(aConfigHeader->getTasIndicesPosition(),std::ios::beg);
|
||||
unsigned int arrayLength = aConfigHeader->getTasIndicesLength();
|
||||
std::shared_ptr<uint8_t> tasIndicesArray(new uint8_t[arrayLength],std::default_delete<uint8_t[]>());
|
||||
stream.read(reinterpret_cast<char*>(tasIndicesArray.get()),arrayLength);
|
||||
TasIndicesPointer tasIndices;
|
||||
tasIndices.setArray(tasIndicesArray,arrayLength);
|
||||
result.setTasIndices(tasIndices);
|
||||
|
||||
|
||||
stream.seekg(aConfigHeader->getReceiverIndicesPosition(),std::ios::beg);
|
||||
arrayLength = aConfigHeader->getReceiverIndicesLength();
|
||||
std::shared_ptr<uint8_t> receiverIndicesArray(new uint8_t[arrayLength],std::default_delete<uint8_t[]>());
|
||||
stream.read(reinterpret_cast<char*>(receiverIndicesArray.get()),arrayLength);
|
||||
TasIndicesPointer receiverIndices;
|
||||
receiverIndices.setArray(receiverIndicesArray,arrayLength);
|
||||
result.setReceiverIndices(receiverIndices);
|
||||
|
||||
stream.close();
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user