171 lines
6.4 KiB
C++
171 lines
6.4 KiB
C++
#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));
|
|
}
|
|
//DACDelay
|
|
matvar_t* dacDelayVar = Mat_VarGetStructFieldByName(metaDataVar,"DACDelay",0);
|
|
if(dacDelayVar!=nullptr)
|
|
{
|
|
result.setDacDelay(*reinterpret_cast<double*>(dacDelayVar->data));
|
|
}
|
|
matvar_t* filterByPassVar = Mat_VarGetStructFieldByName(metaDataVar,"FilterBypass",0);
|
|
if(filterByPassVar!=nullptr)
|
|
{
|
|
result.setFilterByPass(*reinterpret_cast<double*>(filterByPassVar->data));
|
|
}
|
|
//AperturePosition
|
|
result.setAperturePositionNumber(aShotList->getMotorPositionSize());
|
|
}
|
|
//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(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(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>());
|
|
}
|
|
if(amcBoardConfig.contains("DAC Delay"))
|
|
{
|
|
result.setDacDelay(amcBoardConfig.at("DAC Delay").get<double>());
|
|
}
|
|
if(amcBoardConfig.contains("Filter"))
|
|
{
|
|
result.setFilterByPass(amcBoardConfig.at("Filter").get<double>());
|
|
}
|
|
}
|
|
|
|
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(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(receiverIndicesArray,arrayLength);
|
|
result.setReceiverIndices(receiverIndices);
|
|
|
|
stream.close();
|
|
return result;
|
|
}
|