#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 #include MetaDataReader::MetaDataReader() { } MetaData MetaDataReader::getMetaDataFromKIT(const std::string& aFilePath,std::shared_ptr 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(*reinterpret_cast(sampleNumberVar->data))); } //Samplerate matvar_t* samplerateVar = Mat_VarRead(matFile,"SampleRate"); if(samplerateVar!=nullptr) { result.setSamplerate(static_cast(*reinterpret_cast(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(dacDelayVar->data)); } matvar_t* filterByPassVar = Mat_VarGetStructFieldByName(metaDataVar,"FilterBypass",0); if(filterByPassVar!=nullptr) { result.setFilterByPass(*reinterpret_cast(filterByPassVar->data)); } //AperturePosition result.setAperturePositionNumber(aShotList->getMotorPositionSize()); } //TASIndices std::shared_ptr mapperArrayPointer = MapperDataBase::getMapperArray(); unsigned long long tasIndicesLength = aShotList->getMuxSize() * TOTAL_CHANNEL; std::shared_ptr tasIndices = std::shared_ptr(new uint8_t[tasIndicesLength],std::default_delete()); 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(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 receiverIndices = std::shared_ptr(new uint8_t[receiverIndicesLength],std::default_delete()); 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(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()); } if(generalInfo.contains("Aperture Position")) { result.setAperturePositionNumber(generalInfo.at("Aperture Position").get()); } } 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()); } if(amcBoardConfig.contains("Sample Rate")) { result.setSamplerate(amcBoardConfig.at("Sample Rate").get()); } if(amcBoardConfig.contains("Shot length")) { result.setSampleNumber(amcBoardConfig.at("Shot length").get()); } if(amcBoardConfig.contains("DAC Delay")) { result.setDacDelay(amcBoardConfig.at("DAC Delay").get()); } if(amcBoardConfig.contains("Filter")) { result.setFilterByPass(amcBoardConfig.at("Filter").get()); } } 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 tasIndicesArray(new uint8_t[arrayLength],std::default_delete()); stream.read(reinterpret_cast(tasIndicesArray.get()),arrayLength); TasIndicesPointer tasIndices(tasIndicesArray,arrayLength); result.setTasIndices(tasIndices); stream.seekg(aConfigHeader->getReceiverIndicesPosition(),std::ios::beg); arrayLength = aConfigHeader->getReceiverIndicesLength(); std::shared_ptr receiverIndicesArray(new uint8_t[arrayLength],std::default_delete()); stream.read(reinterpret_cast(receiverIndicesArray.get()),arrayLength); TasIndicesPointer receiverIndices(receiverIndicesArray,arrayLength); result.setReceiverIndices(receiverIndices); stream.close(); return result; }