mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-27 07:18:40 +01:00
Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into dev/matterhornserver
This commit is contained in:
@@ -19,16 +19,15 @@ void BinaryDataFile::CloseFile() {
|
||||
fd = nullptr;
|
||||
}
|
||||
|
||||
void BinaryDataFile::CreateFirstBinaryDataFile(const std::string &fNamePrefix,
|
||||
const uint64_t fIndex,
|
||||
const bool ovEnable,
|
||||
const bool sMode,
|
||||
const uint16_t uPortNumber,
|
||||
const uint32_t mFramesPerFile) {
|
||||
void BinaryDataFile::CreateFirstBinaryDataFile(
|
||||
const std::filesystem::path &filePath, const std::string &fNamePrefix,
|
||||
const uint64_t fIndex, const bool ovEnable, const bool sMode,
|
||||
const uint16_t uPortNumber, const uint32_t mFramesPerFile) {
|
||||
|
||||
subFileIndex = 0;
|
||||
numFramesInFile = 0;
|
||||
|
||||
m_filePath = filePath;
|
||||
fileNamePrefix = fNamePrefix;
|
||||
fileIndex = fIndex;
|
||||
overWriteEnable = ovEnable;
|
||||
@@ -42,9 +41,10 @@ void BinaryDataFile::CreateFirstBinaryDataFile(const std::string &fNamePrefix,
|
||||
void BinaryDataFile::CreateFile() {
|
||||
numFramesInFile = 0;
|
||||
|
||||
std::ostringstream os;
|
||||
os << fileNamePrefix << "_f" << subFileIndex << '_' << fileIndex << ".raw";
|
||||
fileName = os.str();
|
||||
std::filesystem::path p =
|
||||
m_filePath / (fileNamePrefix + "_f" + std::to_string(subFileIndex) +
|
||||
'_' + std::to_string(fileIndex) + ".raw");
|
||||
fileName = p.string();
|
||||
|
||||
if (!overWriteEnable) {
|
||||
if (nullptr == (fd = fopen(fileName.c_str(), "wx"))) {
|
||||
|
||||
@@ -14,7 +14,8 @@ class BinaryDataFile : private virtual slsDetectorDefs, public File {
|
||||
|
||||
fileFormat GetFileFormat() const override;
|
||||
void CloseFile() override;
|
||||
void CreateFirstBinaryDataFile(const std::string &fNamePrefix,
|
||||
void CreateFirstBinaryDataFile(const std::filesystem::path &filePath,
|
||||
const std::string &fNamePrefix,
|
||||
const uint64_t fIndex, const bool ovEnable,
|
||||
const bool sMode, const uint16_t uPortNumber,
|
||||
const uint32_t mFramesPerFile) override;
|
||||
@@ -29,6 +30,7 @@ class BinaryDataFile : private virtual slsDetectorDefs, public File {
|
||||
uint32_t index;
|
||||
FILE *fd{nullptr};
|
||||
std::string fileName;
|
||||
std::filesystem::path m_filePath;
|
||||
uint32_t numFramesInFile{0};
|
||||
uint32_t subFileIndex{0};
|
||||
|
||||
|
||||
@@ -148,7 +148,8 @@ void DataProcessor::SetupFileWriter(const bool filewriteEnable,
|
||||
}
|
||||
}
|
||||
|
||||
void DataProcessor::CreateFirstFiles(const std::string &fileNamePrefix,
|
||||
void DataProcessor::CreateFirstFiles(const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable,
|
||||
const bool silentMode,
|
||||
@@ -178,14 +179,14 @@ void DataProcessor::CreateFirstFiles(const std::string &fileNamePrefix,
|
||||
#ifdef HDF5C
|
||||
case HDF5:
|
||||
dataFile->CreateFirstHDF5DataFile(
|
||||
fileNamePrefix, fileIndex, overWriteEnable, silentMode,
|
||||
filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode,
|
||||
udpPortNumber, generalData->framesPerFile, nTotalFrames, nx, ny,
|
||||
generalData->dynamicRange);
|
||||
break;
|
||||
#endif
|
||||
case BINARY:
|
||||
dataFile->CreateFirstBinaryDataFile(
|
||||
fileNamePrefix, fileIndex, overWriteEnable, silentMode,
|
||||
filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode,
|
||||
udpPortNumber, generalData->framesPerFile);
|
||||
break;
|
||||
default:
|
||||
@@ -203,7 +204,7 @@ uint32_t DataProcessor::GetFilesInAcquisition() const {
|
||||
}
|
||||
|
||||
std::string DataProcessor::CreateVirtualFile(
|
||||
const std::string &filePath, const std::string &fileNamePrefix,
|
||||
const std::filesystem::path &filePath, const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode,
|
||||
const int modulePos, const int numModX, const int numModY,
|
||||
std::mutex *hdf5LibMutex, bool gotthard25um) {
|
||||
@@ -247,7 +248,7 @@ void DataProcessor::LinkFileInMaster(const std::string &masterFileName,
|
||||
#endif
|
||||
|
||||
std::string DataProcessor::CreateMasterFile(
|
||||
const std::string &filePath, const std::string &fileNamePrefix,
|
||||
const std::filesystem::path &filePath, const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex, const bool overWriteEnable, bool silentMode,
|
||||
const fileFormat fileFormatType, MasterAttributes *attr,
|
||||
std::mutex *hdf5LibMutex) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "receiver_defs.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
@@ -59,12 +60,13 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
||||
const fileFormat fileFormatType,
|
||||
std::mutex *hdf5LibMutex);
|
||||
|
||||
void CreateFirstFiles(const std::string &fileNamePrefix,
|
||||
void CreateFirstFiles(const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex, const bool overWriteEnable,
|
||||
const bool silentMode, const bool detectorDataStream);
|
||||
#ifdef HDF5C
|
||||
uint32_t GetFilesInAcquisition() const;
|
||||
std::string CreateVirtualFile(const std::string &filePath,
|
||||
std::string CreateVirtualFile(const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable,
|
||||
@@ -76,7 +78,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
||||
const bool silentMode, std::mutex *hdf5LibMutex);
|
||||
#endif
|
||||
|
||||
std::string CreateMasterFile(const std::string &filePath,
|
||||
std::string CreateMasterFile(const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable, bool silentMode,
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "sls/sls_detector_defs.h"
|
||||
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef HDF5C
|
||||
#include "H5Cpp.h"
|
||||
@@ -56,6 +57,7 @@ class File : private virtual slsDetectorDefs {
|
||||
};
|
||||
|
||||
virtual void CreateFirstHDF5DataFile(
|
||||
const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix, const uint64_t fileIndex,
|
||||
const bool overWriteEnable, const bool silentMode,
|
||||
const uint16_t udpPortNumber, const uint32_t maxFramesPerFile,
|
||||
@@ -66,12 +68,11 @@ class File : private virtual slsDetectorDefs {
|
||||
"should be overloaded by a derived class";
|
||||
};
|
||||
#endif
|
||||
virtual void CreateFirstBinaryDataFile(const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable,
|
||||
const bool silentMode,
|
||||
const uint16_t udpPortNumber,
|
||||
const uint32_t maxFramesPerFile) {
|
||||
virtual void CreateFirstBinaryDataFile(
|
||||
const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix, const uint64_t fileIndex,
|
||||
const bool overWriteEnable, const bool silentMode,
|
||||
const uint16_t udpPortNumber, const uint32_t maxFramesPerFile) {
|
||||
LOG(logERROR)
|
||||
<< "This is a generic function CreateFirstBinaryDataFile that "
|
||||
"should be overloaded by a derived class";
|
||||
|
||||
@@ -87,8 +87,9 @@ void HDF5DataFile::CloseFile() {
|
||||
}
|
||||
|
||||
void HDF5DataFile::CreateFirstHDF5DataFile(
|
||||
const std::string &fNamePrefix, const uint64_t fIndex, const bool owEnable,
|
||||
const bool sMode, const uint16_t uPortNumber, const uint32_t mFramesPerFile,
|
||||
const std::filesystem::path &filePath, const std::string &fNamePrefix,
|
||||
const uint64_t fIndex, const bool owEnable, const bool sMode,
|
||||
const uint16_t uPortNumber, const uint32_t mFramesPerFile,
|
||||
const uint64_t nImages, const uint32_t nX, const uint32_t nY,
|
||||
const uint32_t dr) {
|
||||
|
||||
@@ -103,6 +104,7 @@ void HDF5DataFile::CreateFirstHDF5DataFile(
|
||||
nPixelsY = nY;
|
||||
dynamicRange = dr;
|
||||
|
||||
m_filePath = filePath;
|
||||
fileNamePrefix = fNamePrefix;
|
||||
fileIndex = fIndex;
|
||||
overWriteEnable = owEnable;
|
||||
@@ -129,9 +131,10 @@ void HDF5DataFile::CreateFile() {
|
||||
numFramesInFile = 0;
|
||||
numFilesInAcquisition++;
|
||||
|
||||
std::ostringstream os;
|
||||
os << fileNamePrefix << "_f" << subFileIndex << '_' << fileIndex << ".h5";
|
||||
fileName = os.str();
|
||||
std::filesystem::path p =
|
||||
m_filePath / (fileNamePrefix + "_f" + std::to_string(subFileIndex) +
|
||||
'_' + std::to_string(fileIndex) + ".h5");
|
||||
fileName = p.string();
|
||||
|
||||
std::lock_guard<std::mutex> lock(*hdf5Lib);
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "File.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace sls {
|
||||
@@ -23,7 +22,8 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
|
||||
|
||||
void CloseFile() override;
|
||||
|
||||
void CreateFirstHDF5DataFile(const std::string &fNamePrefix,
|
||||
void CreateFirstHDF5DataFile(const std::filesystem::path &filePath,
|
||||
const std::string &fNamePrefix,
|
||||
const uint64_t fIndex, const bool owEnable,
|
||||
const bool sMode, const uint16_t uPortNumber,
|
||||
const uint32_t mFramesPerFile,
|
||||
@@ -65,7 +65,8 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
|
||||
uint32_t nPixelsY{0};
|
||||
uint32_t dynamicRange{0};
|
||||
|
||||
std::string fileNamePrefix;
|
||||
std::filesystem::path m_filePath{};
|
||||
std::string fileNamePrefix{};
|
||||
uint64_t fileIndex{0};
|
||||
bool overWriteEnable{false};
|
||||
bool silentMode{false};
|
||||
|
||||
@@ -483,10 +483,14 @@ void Implementation::setFileFormat(const fileFormat f) {
|
||||
LOG(logINFO) << "File Format: " << ToString(fileFormatType);
|
||||
}
|
||||
|
||||
std::string Implementation::getFilePath() const { return filePath; }
|
||||
std::string Implementation::getFilePath() const { return filePath.string(); }
|
||||
|
||||
void Implementation::setFilePath(const std::string &c) {
|
||||
filePath = c;
|
||||
// check if filePath empty and throw error
|
||||
if (c.empty()) {
|
||||
throw ReceiverError("File path cannot be empty");
|
||||
}
|
||||
filePath = std::filesystem::path(c);
|
||||
LOG(logINFO) << "File path: " << filePath;
|
||||
}
|
||||
|
||||
@@ -651,7 +655,7 @@ void Implementation::startReceiver() {
|
||||
generalData->dynamicRange,
|
||||
numPorts,
|
||||
static_cast<size_t>(generalData->imageSize),
|
||||
filePath,
|
||||
filePath.string(),
|
||||
fileName,
|
||||
fileIndex,
|
||||
quadEnable,
|
||||
@@ -851,9 +855,7 @@ void Implementation::ResetParametersforNewAcquisition() {
|
||||
it->ResetParametersforNewAcquisition();
|
||||
|
||||
if (dataStreamEnable) {
|
||||
std::ostringstream os;
|
||||
os << filePath << '/' << fileName;
|
||||
std::string fnametostream = os.str();
|
||||
std::string fnametostream = (filePath / fileName).string();
|
||||
for (const auto &it : dataStreamer)
|
||||
it->ResetParametersforNewAcquisition(fnametostream);
|
||||
}
|
||||
@@ -874,21 +876,28 @@ void Implementation::CreateUDPSockets() {
|
||||
void Implementation::SetupWriter() {
|
||||
|
||||
try {
|
||||
// check if filePath empty and throw error
|
||||
if (filePath.empty()) {
|
||||
throw ReceiverError("File path cannot be empty");
|
||||
}
|
||||
// check if folder exists and throw if it cant create
|
||||
mkdir_p(filePath);
|
||||
if (filePath.empty()) {
|
||||
throw RuntimeError("File path cannot be empty. Please set file "
|
||||
"path before starting acquisition.");
|
||||
}
|
||||
if (!std::filesystem::exists(filePath)) {
|
||||
try {
|
||||
std::filesystem::create_directories(filePath);
|
||||
} catch (const std::filesystem::filesystem_error &e) {
|
||||
throw RuntimeError("Could not create directory: " +
|
||||
filePath.string() + ". Error: " + e.what());
|
||||
}
|
||||
}
|
||||
// create first files
|
||||
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
|
||||
std::ostringstream os;
|
||||
os << filePath << "/" << fileName << "_d"
|
||||
<< (modulePos * generalData->numUDPInterfaces + i);
|
||||
std::string fileNamePrefix = os.str();
|
||||
dataProcessor[i]->CreateFirstFiles(fileNamePrefix, fileIndex,
|
||||
overwriteEnable, silentMode,
|
||||
detectorDataStream[i]);
|
||||
|
||||
std::string fileNamePrefix =
|
||||
fileName + "_d" +
|
||||
std::to_string(modulePos * generalData->numUDPInterfaces + i);
|
||||
dataProcessor[i]->CreateFirstFiles(
|
||||
filePath, fileNamePrefix, fileIndex, overwriteEnable,
|
||||
silentMode, detectorDataStream[i]);
|
||||
}
|
||||
} catch (const RuntimeError &e) {
|
||||
shutDownUDPSockets();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -316,7 +317,7 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
|
||||
// file parameters
|
||||
fileFormat fileFormatType{BINARY};
|
||||
std::string filePath{};
|
||||
std::filesystem::path filePath{};
|
||||
std::string fileName{"run"};
|
||||
uint64_t fileIndex{0};
|
||||
bool fileWriteEnable{false};
|
||||
|
||||
@@ -9,16 +9,17 @@ namespace sls {
|
||||
|
||||
namespace masterFileUtility {
|
||||
|
||||
std::string CreateMasterBinaryFile(const std::string &filePath,
|
||||
std::string CreateMasterBinaryFile(const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable,
|
||||
const bool silentMode,
|
||||
MasterAttributes *attr) {
|
||||
std::ostringstream os;
|
||||
os << filePath << "/" << fileNamePrefix << "_master"
|
||||
<< "_" << fileIndex << ".json";
|
||||
std::string fileName = os.str();
|
||||
|
||||
std::filesystem::path p = filePath / (fileNamePrefix + "_master_" +
|
||||
std::to_string(fileIndex) + ".json");
|
||||
|
||||
std::string fileName = p.string();
|
||||
|
||||
std::string mode = "w";
|
||||
if (!overWriteEnable)
|
||||
@@ -112,17 +113,16 @@ void LinkHDF5FileInMaster(std::string &masterFileName,
|
||||
}
|
||||
}
|
||||
|
||||
std::string CreateMasterHDF5File(const std::string &filePath,
|
||||
std::string CreateMasterHDF5File(const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable,
|
||||
const bool silentMode, MasterAttributes *attr,
|
||||
std::mutex *hdf5LibMutex) {
|
||||
|
||||
std::ostringstream os;
|
||||
os << filePath << "/" << fileNamePrefix << "_master"
|
||||
<< "_" << fileIndex << ".h5";
|
||||
std::string fileName = os.str();
|
||||
std::filesystem::path p = filePath / (fileNamePrefix + "_master_" +
|
||||
std::to_string(fileIndex) + ".json");
|
||||
std::string fileName = p.string();
|
||||
|
||||
std::lock_guard<std::mutex> lock(*hdf5LibMutex);
|
||||
|
||||
@@ -185,7 +185,7 @@ int GetNumPortsInRoi(const defs::ROI roi, const defs::xy portSize) {
|
||||
|
||||
/** Will not be called if dynamic range is 4 and roi enabled */
|
||||
std::string CreateVirtualHDF5File(
|
||||
const std::string &filePath, const std::string &fileNamePrefix,
|
||||
const std::filesystem::path &filePath, const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode,
|
||||
const int modulePos, const int numUnitsPerReadout,
|
||||
const uint32_t maxFramesPerFile, const int nPixelsX, const int nPixelsY,
|
||||
@@ -202,10 +202,11 @@ std::string CreateVirtualHDF5File(
|
||||
}
|
||||
|
||||
// virtual file name
|
||||
std::ostringstream osfn;
|
||||
osfn << filePath << "/" << fileNamePrefix << "_virtual"
|
||||
<< "_" << fileIndex << ".h5";
|
||||
std::string fileName = osfn.str();
|
||||
std::filesystem::path p = filePath / (fileNamePrefix + "_virtual_" +
|
||||
std::to_string(fileIndex) + ".h5");
|
||||
|
||||
std::string fileName = p.string();
|
||||
|
||||
unsigned int paraSize = parameterNames.size();
|
||||
std::lock_guard<std::mutex> lock(*hdf5LibMutex);
|
||||
std::unique_ptr<H5::H5File> fd{nullptr};
|
||||
@@ -331,12 +332,15 @@ std::string CreateVirtualHDF5File(
|
||||
H5S_SELECT_SET, numBlocksPara, startLocationPara,
|
||||
strideBetweenBlocksPara, blockSizePara);
|
||||
|
||||
// source file name
|
||||
std::ostringstream os;
|
||||
os << filePath << "/" << fileNamePrefix << "_d"
|
||||
<< (modulePos * numUnitsPerReadout + iReadout) << "_f"
|
||||
<< iFile << '_' << fileIndex << ".h5";
|
||||
std::string srcFileName = os.str();
|
||||
std::filesystem::path p =
|
||||
filePath /
|
||||
(fileNamePrefix + "_d" +
|
||||
std::to_string(modulePos * numUnitsPerReadout +
|
||||
iReadout) +
|
||||
"_f" + std::to_string(iFile) + '_' +
|
||||
std::to_string(fileIndex) + ".h5");
|
||||
|
||||
std::string srcFileName = p.string();
|
||||
LOG(logDEBUG1) << srcFileName;
|
||||
|
||||
// find relative path
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
|
||||
#include "MasterAttributes.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <mutex>
|
||||
|
||||
namespace sls {
|
||||
|
||||
namespace masterFileUtility {
|
||||
|
||||
std::string CreateMasterBinaryFile(const std::string &filePath,
|
||||
std::string CreateMasterBinaryFile(const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable,
|
||||
@@ -24,7 +25,7 @@ void LinkHDF5FileInMaster(std::string &masterFileName,
|
||||
const bool silentMode, std::mutex *hdf5LibMutex,
|
||||
size_t multiRoiSize);
|
||||
|
||||
std::string CreateMasterHDF5File(const std::string &filePath,
|
||||
std::string CreateMasterHDF5File(const std::filesystem::path &filePath,
|
||||
const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable,
|
||||
@@ -35,7 +36,7 @@ defs::ROI GetGlobalPortRoi(const int iPort, const defs::xy portSize,
|
||||
int GetNumPortsInRoi(const defs::ROI roi, const defs::xy portSize);
|
||||
|
||||
std::string CreateVirtualHDF5File(
|
||||
const std::string &filePath, const std::string &fileNamePrefix,
|
||||
const std::filesystem::path &filePath, const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode,
|
||||
const int modulePos, const int numUnitsPerReadout,
|
||||
const uint32_t maxFramesPerFile, const int nPixelsX, const int nPixelsY,
|
||||
|
||||
Reference in New Issue
Block a user