mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 07:20:01 +02:00
binary master json done, hdf5 left wip
This commit is contained in:
parent
90d1d0f8b8
commit
0f02ffdc9a
@ -3,17 +3,6 @@
|
|||||||
#include "BinaryMasterFile.h"
|
#include "BinaryMasterFile.h"
|
||||||
#include "MasterAttributes.h"
|
#include "MasterAttributes.h"
|
||||||
|
|
||||||
BinaryMasterFile::BinaryMasterFile() : File(BINARY) {}
|
|
||||||
|
|
||||||
BinaryMasterFile::~BinaryMasterFile() { CloseFile(); }
|
|
||||||
|
|
||||||
void BinaryMasterFile::CloseFile() {
|
|
||||||
if (fd_) {
|
|
||||||
fclose(fd_);
|
|
||||||
}
|
|
||||||
fd_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BinaryMasterFile::CreateMasterFile(const std::string filePath,
|
void BinaryMasterFile::CreateMasterFile(const std::string filePath,
|
||||||
const std::string fileNamePrefix,
|
const std::string fileNamePrefix,
|
||||||
const uint64_t fileIndex,
|
const uint64_t fileIndex,
|
||||||
@ -24,37 +13,26 @@ void BinaryMasterFile::CreateMasterFile(const std::string filePath,
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << filePath << "/" << fileNamePrefix << "_master"
|
os << filePath << "/" << fileNamePrefix << "_master"
|
||||||
<< "_" << fileIndex << ".json";
|
<< "_" << fileIndex << ".json";
|
||||||
fileName_ = os.str();
|
std::string fileName = os.str();
|
||||||
|
|
||||||
// create file
|
// create file
|
||||||
|
FILE *fd{nullptr};
|
||||||
if (!overWriteEnable) {
|
if (!overWriteEnable) {
|
||||||
if (nullptr == (fd_ = fopen((const char *)fileName_.c_str(), "wx"))) {
|
if (nullptr == (fd = fopen((const char *)fileName.c_str(), "wx"))) {
|
||||||
fd_ = nullptr;
|
fd = nullptr;
|
||||||
throw sls::RuntimeError("Could not create binary master file " +
|
throw sls::RuntimeError("Could not create binary master file " +
|
||||||
fileName_);
|
fileName);
|
||||||
}
|
}
|
||||||
} else if (nullptr == (fd_ = fopen((const char *)fileName_.c_str(), "w"))) {
|
} else if (nullptr == (fd = fopen((const char *)fileName.c_str(), "w"))) {
|
||||||
fd_ = nullptr;
|
fd = nullptr;
|
||||||
throw sls::RuntimeError(
|
throw sls::RuntimeError(
|
||||||
"Could not create/overwrite binary master file " + fileName_);
|
"Could not create/overwrite binary master file " + fileName);
|
||||||
}
|
}
|
||||||
if (!silentMode) {
|
if (!silentMode) {
|
||||||
LOG(logINFO) << "Master File: " << fileName_;
|
LOG(logINFO) << "Master File: " << fileName;
|
||||||
}
|
}
|
||||||
attr->WriteMasterBinaryAttributes(fd_);
|
attr->WriteMasterBinaryAttributes(fd);
|
||||||
CloseFile();
|
if (fd) {
|
||||||
}
|
fclose(fd);
|
||||||
|
|
||||||
void BinaryMasterFile::UpdateMasterFile(MasterAttributes *attr,
|
|
||||||
bool silentMode) {
|
|
||||||
if (nullptr == (fd_ = fopen((const char *)fileName_.c_str(), "a"))) {
|
|
||||||
fd_ = nullptr;
|
|
||||||
throw sls::RuntimeError("Could not append binary master file " +
|
|
||||||
fileName_);
|
|
||||||
}
|
|
||||||
attr->WriteFinalBinaryAttributes(fd_);
|
|
||||||
CloseFile();
|
|
||||||
if (!silentMode) {
|
|
||||||
LOG(logINFO) << "Updated Master File";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,21 +5,12 @@
|
|||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "MasterAttributes.h"
|
#include "MasterAttributes.h"
|
||||||
|
|
||||||
class BinaryMasterFile : private virtual slsDetectorDefs, public File {
|
class BinaryMasterFile : private virtual slsDetectorDefs {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BinaryMasterFile();
|
static void CreateMasterFile(const std::string filePath,
|
||||||
~BinaryMasterFile();
|
const std::string fileNamePrefix,
|
||||||
|
const uint64_t fileIndex,
|
||||||
void CloseFile() override;
|
const bool overWriteEnable,
|
||||||
void CreateMasterFile(const std::string filePath,
|
const bool silentMode, MasterAttributes *attr);
|
||||||
const std::string fileNamePrefix,
|
|
||||||
const uint64_t fileIndex, const bool overWriteEnable,
|
|
||||||
const bool silentMode,
|
|
||||||
MasterAttributes *attr) override;
|
|
||||||
void UpdateMasterFile(MasterAttributes *attr, bool silentMode) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
FILE *fd_{nullptr};
|
|
||||||
std::string fileName_;
|
|
||||||
};
|
};
|
@ -82,8 +82,6 @@ void DataProcessor::SetGeneralData(GeneralData *generalData) {
|
|||||||
void DataProcessor::CloseFiles() {
|
void DataProcessor::CloseFiles() {
|
||||||
if (dataFile_)
|
if (dataFile_)
|
||||||
dataFile_->CloseFile();
|
dataFile_->CloseFile();
|
||||||
if (masterFile_)
|
|
||||||
masterFile_->CloseFile();
|
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
if (virtualFile_)
|
if (virtualFile_)
|
||||||
virtualFile_->CloseFile();
|
virtualFile_->CloseFile();
|
||||||
@ -96,10 +94,10 @@ void DataProcessor::DeleteFiles() {
|
|||||||
delete dataFile_;
|
delete dataFile_;
|
||||||
dataFile_ = nullptr;
|
dataFile_ = nullptr;
|
||||||
}
|
}
|
||||||
if (masterFile_) {
|
/* if (masterFile_) {
|
||||||
delete masterFile_;
|
delete masterFile_;
|
||||||
masterFile_ = nullptr;
|
masterFile_ = nullptr;
|
||||||
}
|
}*/
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
if (virtualFile_) {
|
if (virtualFile_) {
|
||||||
delete virtualFile_;
|
delete virtualFile_;
|
||||||
@ -108,27 +106,18 @@ void DataProcessor::DeleteFiles() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void DataProcessor::SetupFileWriter(const bool filewriteEnable,
|
void DataProcessor::SetupFileWriter(const bool filewriteEnable,
|
||||||
const bool masterFilewriteEnable,
|
|
||||||
const fileFormat fileFormatType,
|
const fileFormat fileFormatType,
|
||||||
const int modulePos, std::mutex *hdf5Lib) {
|
std::mutex *hdf5Lib) {
|
||||||
DeleteFiles();
|
DeleteFiles();
|
||||||
if (filewriteEnable) {
|
if (filewriteEnable) {
|
||||||
switch (fileFormatType) {
|
switch (fileFormatType) {
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
case HDF5:
|
case HDF5:
|
||||||
dataFile_ = new HDF5DataFile(index, hdf5Lib);
|
dataFile_ = new HDF5DataFile(index, hdf5Lib);
|
||||||
if (modulePos == 0 && index == 0) {
|
|
||||||
if (masterFilewriteEnable) {
|
|
||||||
masterFile_ = new HDF5MasterFile(hdf5Lib);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case BINARY:
|
case BINARY:
|
||||||
dataFile_ = new BinaryDataFile(index);
|
dataFile_ = new BinaryDataFile(index);
|
||||||
if (modulePos == 0 && index == 0 && masterFilewriteEnable) {
|
|
||||||
masterFile_ = new BinaryMasterFile();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw sls::RuntimeError(
|
throw sls::RuntimeError(
|
||||||
@ -138,23 +127,17 @@ void DataProcessor::SetupFileWriter(const bool filewriteEnable,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DataProcessor::CreateFirstFiles(
|
void DataProcessor::CreateFirstFiles(
|
||||||
MasterAttributes *attr, const std::string filePath,
|
const std::string filePath, const std::string fileNamePrefix,
|
||||||
const std::string fileNamePrefix, const uint64_t fileIndex,
|
const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode,
|
||||||
const bool overWriteEnable, const bool silentMode, const int modulePos,
|
const int modulePos, const int numUnitsPerReadout,
|
||||||
const int numUnitsPerReadout, const uint32_t udpPortNumber,
|
const uint32_t udpPortNumber, const uint32_t maxFramesPerFile,
|
||||||
const uint32_t maxFramesPerFile, const uint64_t numImages,
|
const uint64_t numImages, const uint32_t dynamicRange,
|
||||||
const uint32_t dynamicRange, const bool detectorDataStream) {
|
const bool detectorDataStream) {
|
||||||
if (dataFile_ == nullptr) {
|
if (dataFile_ == nullptr) {
|
||||||
throw sls::RuntimeError("file object not contstructed");
|
throw sls::RuntimeError("file object not contstructed");
|
||||||
}
|
}
|
||||||
CloseFiles();
|
CloseFiles();
|
||||||
|
|
||||||
// master file write enabled
|
|
||||||
if (masterFile_) {
|
|
||||||
masterFile_->CreateMasterFile(filePath, fileNamePrefix, fileIndex,
|
|
||||||
overWriteEnable, silentMode, attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// deactivated (half module/ single port), dont write file
|
// deactivated (half module/ single port), dont write file
|
||||||
if ((!*activated_) || (!detectorDataStream)) {
|
if ((!*activated_) || (!detectorDataStream)) {
|
||||||
return;
|
return;
|
||||||
@ -238,38 +221,26 @@ void DataProcessor::LinkDataInMasterFile(const bool silentMode) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void DataProcessor::UpdateMasterFile(bool silentMode) {
|
void DataProcessor::CreateMasterFile(
|
||||||
if (masterFile_) {
|
const std::string filePath, const std::string fileNamePrefix,
|
||||||
// final attributes
|
const uint64_t fileIndex, const bool overWriteEnable, bool silentMode,
|
||||||
std::unique_ptr<MasterAttributes> masterAttributes;
|
const fileFormat fileFormatType, MasterAttributes *attr) {
|
||||||
switch (detectorType_) {
|
|
||||||
case GOTTHARD:
|
attr->framesInFile = numFramesCaught_;
|
||||||
masterAttributes = sls::make_unique<GotthardMasterAttributes>();
|
|
||||||
break;
|
std::unique_ptr<File> masterFile{nullptr};
|
||||||
case JUNGFRAU:
|
switch (fileFormatType) {
|
||||||
masterAttributes = sls::make_unique<JungfrauMasterAttributes>();
|
#ifdef HDF5C
|
||||||
break;
|
case HDF5:
|
||||||
case EIGER:
|
masterFile = sls::make_unique<HDF5MasterFile>(hdf5Lib);
|
||||||
masterAttributes = sls::make_unique<EigerMasterAttributes>();
|
break;
|
||||||
break;
|
#endif
|
||||||
case MYTHEN3:
|
case BINARY:
|
||||||
masterAttributes = sls::make_unique<Mythen3MasterAttributes>();
|
BinaryMasterFile::CreateMasterFile(filePath, fileNamePrefix, fileIndex,
|
||||||
break;
|
overWriteEnable, silentMode, attr);
|
||||||
case GOTTHARD2:
|
break;
|
||||||
masterAttributes = sls::make_unique<Gotthard2MasterAttributes>();
|
default:
|
||||||
break;
|
throw sls::RuntimeError("Unknown file format (compile with hdf5 flags");
|
||||||
case MOENCH:
|
|
||||||
masterAttributes = sls::make_unique<MoenchMasterAttributes>();
|
|
||||||
break;
|
|
||||||
case CHIPTESTBOARD:
|
|
||||||
masterAttributes = sls::make_unique<CtbMasterAttributes>();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw sls::RuntimeError(
|
|
||||||
"Unknown detector type to set up master file attributes");
|
|
||||||
}
|
|
||||||
masterAttributes->framesInFile = numFramesCaught_;
|
|
||||||
masterFile_->UpdateMasterFile(masterAttributes.get(), silentMode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +45,9 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
|||||||
void CloseFiles();
|
void CloseFiles();
|
||||||
void DeleteFiles();
|
void DeleteFiles();
|
||||||
void SetupFileWriter(const bool filewriteEnable,
|
void SetupFileWriter(const bool filewriteEnable,
|
||||||
const bool masterFilewriteEnable,
|
const fileFormat fileFormatType, std::mutex *hdf5Lib);
|
||||||
const fileFormat fileFormatType, const int modulePos,
|
|
||||||
std::mutex *hdf5Lib);
|
|
||||||
|
|
||||||
void CreateFirstFiles(MasterAttributes *attr, const std::string filePath,
|
void CreateFirstFiles(const std::string filePath,
|
||||||
const std::string fileNamePrefix,
|
const std::string fileNamePrefix,
|
||||||
const uint64_t fileIndex, const bool overWriteEnable,
|
const uint64_t fileIndex, const bool overWriteEnable,
|
||||||
const bool silentMode, const int modulePos,
|
const bool silentMode, const int modulePos,
|
||||||
@ -71,7 +69,11 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
|||||||
const int numModY, std::mutex *hdf5Lib);
|
const int numModY, std::mutex *hdf5Lib);
|
||||||
void LinkDataInMasterFile(const bool silentMode);
|
void LinkDataInMasterFile(const bool silentMode);
|
||||||
#endif
|
#endif
|
||||||
void UpdateMasterFile(bool silentMode);
|
void CreateMasterFile(const std::string filePath,
|
||||||
|
const std::string fileNamePrefix,
|
||||||
|
const uint64_t fileIndex, const bool overWriteEnable,
|
||||||
|
bool silentMode, const fileFormat fileFormatType,
|
||||||
|
MasterAttributes *attr);
|
||||||
/**
|
/**
|
||||||
* Call back for raw data
|
* Call back for raw data
|
||||||
* args to raw data ready callback are
|
* args to raw data ready callback are
|
||||||
@ -179,7 +181,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
|||||||
bool firstStreamerFrame_{false};
|
bool firstStreamerFrame_{false};
|
||||||
|
|
||||||
File *dataFile_{nullptr};
|
File *dataFile_{nullptr};
|
||||||
File *masterFile_{nullptr};
|
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
File *virtualFile_{nullptr};
|
File *virtualFile_{nullptr};
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,16 +103,6 @@ class File : private virtual slsDetectorDefs {
|
|||||||
"should be overloaded by a derived class";
|
"should be overloaded by a derived class";
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void CreateMasterFile(const std::string filePath,
|
|
||||||
const std::string fileNamePrefix,
|
|
||||||
const uint64_t fileIndex,
|
|
||||||
const bool overWriteEnable,
|
|
||||||
const bool silentMode,
|
|
||||||
MasterAttributes *attr) {
|
|
||||||
LOG(logERROR) << "This is a generic function CreateMasterFile that "
|
|
||||||
"should be overloaded by a derived class";
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual void WriteToFile(char *buffer, const int buffersize,
|
virtual void WriteToFile(char *buffer, const int buffersize,
|
||||||
const uint64_t currentFrameNumber,
|
const uint64_t currentFrameNumber,
|
||||||
const uint32_t numPacketsCaught) {
|
const uint32_t numPacketsCaught) {
|
||||||
@ -120,11 +110,6 @@ class File : private virtual slsDetectorDefs {
|
|||||||
"should be overloaded by a derived class";
|
"should be overloaded by a derived class";
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void UpdateMasterFile(MasterAttributes *attr, bool silentMode) {
|
|
||||||
LOG(logERROR) << "This is a generic function UpdateMasterFile that "
|
|
||||||
"should be overloaded by a derived class";
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
slsDetectorDefs::fileFormat format_;
|
slsDetectorDefs::fileFormat format_;
|
||||||
};
|
};
|
||||||
|
@ -12,7 +12,6 @@ class HDF5MasterFile : private virtual slsDetectorDefs, public File {
|
|||||||
HDF5MasterFile(std::mutex *hdf5Lib);
|
HDF5MasterFile(std::mutex *hdf5Lib);
|
||||||
~HDF5MasterFile();
|
~HDF5MasterFile();
|
||||||
|
|
||||||
void CloseFile() override;
|
|
||||||
void LinkDataFile(std::string dataFilename, std::string dataSetname,
|
void LinkDataFile(std::string dataFilename, std::string dataSetname,
|
||||||
const std::vector<std::string> parameterNames,
|
const std::vector<std::string> parameterNames,
|
||||||
const bool silentMode) override;
|
const bool silentMode) override;
|
||||||
@ -21,7 +20,6 @@ class HDF5MasterFile : private virtual slsDetectorDefs, public File {
|
|||||||
const uint64_t fileIndex, const bool overWriteEnable,
|
const uint64_t fileIndex, const bool overWriteEnable,
|
||||||
const bool silentMode,
|
const bool silentMode,
|
||||||
MasterAttributes *attr) override;
|
MasterAttributes *attr) override;
|
||||||
void UpdateMasterFile(MasterAttributes *attr, bool silentMode) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex *hdf5Lib_;
|
std::mutex *hdf5Lib_;
|
||||||
|
@ -240,9 +240,6 @@ void Implementation::setModulePositionId(const int id) {
|
|||||||
xy portGeometry = GetPortGeometry();
|
xy portGeometry = GetPortGeometry();
|
||||||
streamingPort = DEFAULT_ZMQ_RX_PORTNO + modulePos * portGeometry.x;
|
streamingPort = DEFAULT_ZMQ_RX_PORTNO + modulePos * portGeometry.x;
|
||||||
|
|
||||||
for (const auto &it : dataProcessor)
|
|
||||||
it->SetupFileWriter(fileWriteEnable, masterFileWriteEnable,
|
|
||||||
fileFormatType, modulePos, &hdf5Lib);
|
|
||||||
assert(numModules.y != 0);
|
assert(numModules.y != 0);
|
||||||
for (unsigned int i = 0; i < listener.size(); ++i) {
|
for (unsigned int i = 0; i < listener.size(); ++i) {
|
||||||
uint16_t row = 0, col = 0;
|
uint16_t row = 0, col = 0;
|
||||||
@ -372,8 +369,7 @@ void Implementation::setFileFormat(const fileFormat f) {
|
|||||||
throw sls::RuntimeError("Unknown file format");
|
throw sls::RuntimeError("Unknown file format");
|
||||||
}
|
}
|
||||||
for (const auto &it : dataProcessor)
|
for (const auto &it : dataProcessor)
|
||||||
it->SetupFileWriter(fileWriteEnable, masterFileWriteEnable,
|
it->SetupFileWriter(fileWriteEnable, fileFormatType, &hdf5Lib);
|
||||||
fileFormatType, modulePos, &hdf5Lib);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(logINFO) << "File Format: " << sls::ToString(fileFormatType);
|
LOG(logINFO) << "File Format: " << sls::ToString(fileFormatType);
|
||||||
@ -409,8 +405,7 @@ void Implementation::setFileWriteEnable(const bool b) {
|
|||||||
if (fileWriteEnable != b) {
|
if (fileWriteEnable != b) {
|
||||||
fileWriteEnable = b;
|
fileWriteEnable = b;
|
||||||
for (const auto &it : dataProcessor)
|
for (const auto &it : dataProcessor)
|
||||||
it->SetupFileWriter(fileWriteEnable, masterFileWriteEnable,
|
it->SetupFileWriter(fileWriteEnable, fileFormatType, &hdf5Lib);
|
||||||
fileFormatType, modulePos, &hdf5Lib);
|
|
||||||
}
|
}
|
||||||
LOG(logINFO) << "File Write Enable: "
|
LOG(logINFO) << "File Write Enable: "
|
||||||
<< (fileWriteEnable ? "enabled" : "disabled");
|
<< (fileWriteEnable ? "enabled" : "disabled");
|
||||||
@ -423,9 +418,6 @@ bool Implementation::getMasterFileWriteEnable() const {
|
|||||||
void Implementation::setMasterFileWriteEnable(const bool b) {
|
void Implementation::setMasterFileWriteEnable(const bool b) {
|
||||||
if (masterFileWriteEnable != b) {
|
if (masterFileWriteEnable != b) {
|
||||||
masterFileWriteEnable = b;
|
masterFileWriteEnable = b;
|
||||||
for (const auto &it : dataProcessor)
|
|
||||||
it->SetupFileWriter(fileWriteEnable, masterFileWriteEnable,
|
|
||||||
fileFormatType, modulePos, &hdf5Lib);
|
|
||||||
}
|
}
|
||||||
LOG(logINFO) << "Master File Write Enable: "
|
LOG(logINFO) << "Master File Write Enable: "
|
||||||
<< (masterFileWriteEnable ? "enabled" : "disabled");
|
<< (masterFileWriteEnable ? "enabled" : "disabled");
|
||||||
@ -584,29 +576,9 @@ void Implementation::stopReceiver() {
|
|||||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HDF5C
|
if (fileWriteEnable && modulePos == 0) {
|
||||||
if (fileWriteEnable && fileFormatType == HDF5) {
|
// master and virtual file (hdf5)
|
||||||
if (modulePos == 0) {
|
StartMasterWriter();
|
||||||
// more than 1 file, create virtual file
|
|
||||||
if (dataProcessor[0]->GetFilesInAcquisition() > 1 ||
|
|
||||||
(numModules.x * numModules.y) > 1) {
|
|
||||||
dataProcessor[0]->CreateVirtualFile(
|
|
||||||
filePath, fileName, fileIndex, overwriteEnable, silentMode,
|
|
||||||
modulePos, numUDPInterfaces, framesPerFile,
|
|
||||||
numberOfTotalFrames, dynamicRange, numModules.x,
|
|
||||||
numModules.y, &hdf5Lib);
|
|
||||||
}
|
|
||||||
// link file in master
|
|
||||||
dataProcessor[0]->LinkDataInMasterFile(silentMode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (fileWriteEnable && masterFileWriteEnable && modulePos == 0) {
|
|
||||||
try {
|
|
||||||
dataProcessor[0]->UpdateMasterFile(silentMode);
|
|
||||||
} catch (...) {
|
|
||||||
; // ignore it and just print it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for the processes (dataStreamer) to be done
|
// wait for the processes (dataStreamer) to be done
|
||||||
@ -753,9 +725,25 @@ void Implementation::CreateUDPSockets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Implementation::SetupWriter() {
|
void Implementation::SetupWriter() {
|
||||||
|
try {
|
||||||
|
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
|
||||||
|
dataProcessor[i]->CreateFirstFiles(
|
||||||
|
filePath, fileName, fileIndex, overwriteEnable, silentMode,
|
||||||
|
modulePos, numUDPInterfaces, udpPortNum[i], framesPerFile,
|
||||||
|
numberOfTotalFrames, dynamicRange, detectorDataStream[i]);
|
||||||
|
}
|
||||||
|
} catch (const sls::RuntimeError &e) {
|
||||||
|
shutDownUDPSockets();
|
||||||
|
for (const auto &it : dataProcessor)
|
||||||
|
it->CloseFiles();
|
||||||
|
throw sls::RuntimeError("Could not create first data file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Implementation::StartMasterWriter() {
|
||||||
// master file
|
// master file
|
||||||
std::unique_ptr<MasterAttributes> masterAttributes;
|
if (masterFileWriteEnable) {
|
||||||
if (masterFileWriteEnable && modulePos == 0) {
|
std::unique_ptr<MasterAttributes> masterAttributes;
|
||||||
switch (detType) {
|
switch (detType) {
|
||||||
case GOTTHARD:
|
case GOTTHARD:
|
||||||
masterAttributes = sls::make_unique<GotthardMasterAttributes>();
|
masterAttributes = sls::make_unique<GotthardMasterAttributes>();
|
||||||
@ -838,22 +826,31 @@ void Implementation::SetupWriter() {
|
|||||||
masterAttributes->gateDelay3 = gateDelay3;
|
masterAttributes->gateDelay3 = gateDelay3;
|
||||||
masterAttributes->gates = numberOfGates;
|
masterAttributes->gates = numberOfGates;
|
||||||
masterAttributes->additionalJsonHeader = additionalJsonHeader;
|
masterAttributes->additionalJsonHeader = additionalJsonHeader;
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
|
dataProcessor[0]->CreateMasterFile(
|
||||||
dataProcessor[i]->CreateFirstFiles(
|
filePath, fileName, fileIndex, overwriteEnable, silentMode,
|
||||||
masterAttributes.get(), filePath, fileName, fileIndex,
|
fileFormatType, masterAttributes.get());
|
||||||
overwriteEnable, silentMode, modulePos, numUDPInterfaces,
|
} catch (...) {
|
||||||
udpPortNum[i], framesPerFile, numberOfTotalFrames, dynamicRange,
|
; // ignore it and just print it
|
||||||
detectorDataStream[i]);
|
|
||||||
}
|
}
|
||||||
} catch (const sls::RuntimeError &e) {
|
|
||||||
shutDownUDPSockets();
|
|
||||||
for (const auto &it : dataProcessor)
|
|
||||||
it->CloseFiles();
|
|
||||||
throw sls::RuntimeError("Could not create first data file.");
|
|
||||||
}
|
}
|
||||||
|
#ifdef HDF5C
|
||||||
|
if (fileFormatType == HDF5) {
|
||||||
|
// virtual hdf5 file (if multiple files)
|
||||||
|
if (dataProcessor[0]->GetFilesInAcquisition() > 1 ||
|
||||||
|
(numModules.x * numModules.y) > 1) {
|
||||||
|
dataProcessor[0]->CreateVirtualFile(
|
||||||
|
filePath, fileName, fileIndex, overwriteEnable, silentMode,
|
||||||
|
modulePos, numUDPInterfaces, framesPerFile, numberOfTotalFrames,
|
||||||
|
dynamicRange, numModules.x, numModules.y, &hdf5Lib);
|
||||||
|
}
|
||||||
|
// link file in master
|
||||||
|
if (masterFileWriteEnable) {
|
||||||
|
dataProcessor[0]->LinkDataInMasterFile(silentMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Implementation::StartRunning() {
|
void Implementation::StartRunning() {
|
||||||
|
@ -274,6 +274,7 @@ class Implementation : private virtual slsDetectorDefs {
|
|||||||
void ResetParametersforNewAcquisition();
|
void ResetParametersforNewAcquisition();
|
||||||
void CreateUDPSockets();
|
void CreateUDPSockets();
|
||||||
void SetupWriter();
|
void SetupWriter();
|
||||||
|
void StartMasterWriter();
|
||||||
void StartRunning();
|
void StartRunning();
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
|
@ -4,15 +4,15 @@
|
|||||||
|
|
||||||
#include <rapidjson/stringbuffer.h>
|
#include <rapidjson/stringbuffer.h>
|
||||||
|
|
||||||
|
|
||||||
void MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
|
void MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) {
|
||||||
LOG(logERROR) << "WriteMasterBinaryAttributes should have been called "
|
LOG(logERROR) << "WriteMasterBinaryAttributes should have been called "
|
||||||
"by a child class";
|
"by a child class";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterAttributes::GetBinaryMasterAttributes(rapidjson::Writer<rapidjson::StringBuffer>* w) {
|
void MasterAttributes::GetBinaryMasterAttributes(
|
||||||
|
rapidjson::Writer<rapidjson::StringBuffer> *w) {
|
||||||
time_t t = time(nullptr);
|
time_t t = time(nullptr);
|
||||||
|
|
||||||
w->Key("Version");
|
w->Key("Version");
|
||||||
w->SetMaxDecimalPlaces(2);
|
w->SetMaxDecimalPlaces(2);
|
||||||
w->Double(BINARY_WRITER_VERSION);
|
w->Double(BINARY_WRITER_VERSION);
|
||||||
@ -38,10 +38,12 @@ void MasterAttributes::GetBinaryMasterAttributes(rapidjson::Writer<rapidjson::St
|
|||||||
w->Uint(imageSize);
|
w->Uint(imageSize);
|
||||||
|
|
||||||
w->Key("Pixels");
|
w->Key("Pixels");
|
||||||
w->StartArray();
|
w->StartObject();
|
||||||
|
w->Key("x");
|
||||||
w->Uint(nPixels.x);
|
w->Uint(nPixels.x);
|
||||||
|
w->Key("y");
|
||||||
w->Uint(nPixels.y);
|
w->Uint(nPixels.y);
|
||||||
w->EndArray();
|
w->EndObject();
|
||||||
|
|
||||||
w->Key("Max Frames Per File");
|
w->Key("Max Frames Per File");
|
||||||
w->Uint(maxFramesPerFile);
|
w->Uint(maxFramesPerFile);
|
||||||
@ -67,64 +69,49 @@ void MasterAttributes::WriteBinaryAttributes(FILE *fd, std::string message) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void MasterAttributes::WriteFinalBinaryAttributes(FILE *fd) {
|
void MasterAttributes::WriteFinalBinaryAttributes(
|
||||||
/*
|
rapidjson::Writer<rapidjson::StringBuffer> *w) {
|
||||||
FILE* fp = fopen(json_file_name.c_str(), "r");
|
|
||||||
char readBuffer[65536];
|
|
||||||
FileReadStream is(fp, readBuffer, sizeof(readBuffer));
|
|
||||||
|
|
||||||
Document d, d2;
|
|
||||||
d.ParseStream(is);
|
|
||||||
assert(d.IsArray());
|
|
||||||
fclose(fp);
|
|
||||||
d2.SetObject();
|
|
||||||
Value json_objects(kObjectType);
|
|
||||||
json_objects.AddMember("three", 3, d2.GetAllocator());
|
|
||||||
d.PushBack(json_objects, d2.GetAllocator());
|
|
||||||
|
|
||||||
FILE* outfile = fopen(json_file_name.c_str(), "w");
|
|
||||||
char writeBuffer[65536];
|
|
||||||
FileWriteStream os(outfile, writeBuffer, sizeof(writeBuffer));
|
|
||||||
|
|
||||||
Writer writer(os);
|
|
||||||
d.Accept (writer);
|
|
||||||
fclose(outfile);
|
|
||||||
*/
|
|
||||||
// adding few common parameters to the end
|
// adding few common parameters to the end
|
||||||
/*std::ostringstream oss;
|
|
||||||
|
|
||||||
if (!additionalJsonHeader.empty()) {
|
if (!additionalJsonHeader.empty()) {
|
||||||
oss << "Additional Json Header : "
|
w->Key("Additional Json Header");
|
||||||
<< sls::ToString(additionalJsonHeader) << '\n';
|
w->String(sls::ToString(additionalJsonHeader).c_str());
|
||||||
}
|
}
|
||||||
oss << "Frames in File : " << framesInFile << '\n';
|
|
||||||
|
|
||||||
// adding sls_receiver header format
|
w->Key("Frames in File");
|
||||||
oss << '\n'
|
w->Uint64(framesInFile);
|
||||||
<< "#Frame Header" << '\n'
|
|
||||||
<< "Frame Number : 8 bytes" << '\n'
|
|
||||||
<< "SubFrame Number/ExpLength : 4 bytes" << '\n'
|
|
||||||
<< "Packet Number : 4 bytes" << '\n'
|
|
||||||
<< "Bunch ID : 8 bytes" << '\n'
|
|
||||||
<< "Timestamp : 8 bytes" << '\n'
|
|
||||||
<< "Module Id : 2 bytes" << '\n'
|
|
||||||
<< "Row : 2 bytes" << '\n'
|
|
||||||
<< "Column : 2 bytes" << '\n'
|
|
||||||
<< "Reserved : 2 bytes" << '\n'
|
|
||||||
<< "Debug : 4 bytes" << '\n'
|
|
||||||
<< "Round Robin Number : 2 bytes" << '\n'
|
|
||||||
<< "Detector Type : 1 byte" << '\n'
|
|
||||||
<< "Header Version : 1 byte" << '\n'
|
|
||||||
<< "Packets Caught Mask : 64 bytes" << '\n';
|
|
||||||
|
|
||||||
std::string message = oss.str();
|
w->Key("Frame Header Format");
|
||||||
|
w->StartObject();
|
||||||
// writing to file
|
w->Key("Frame Number");
|
||||||
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
|
w->String("8 bytes");
|
||||||
message.length()) {
|
w->Key("SubFrame Number/ExpLength");
|
||||||
throw sls::RuntimeError(
|
w->String("4 bytes");
|
||||||
"Master binary file incorrect number of bytes written to file");
|
w->Key("Packet Number");
|
||||||
}*/
|
w->String("4 bytes");
|
||||||
|
w->Key("Bunch ID");
|
||||||
|
w->String("8 bytes");
|
||||||
|
w->Key("Timestamp");
|
||||||
|
w->String("8 bytes");
|
||||||
|
w->Key("Module Id");
|
||||||
|
w->String("2 bytes");
|
||||||
|
w->Key("Row");
|
||||||
|
w->String("2 bytes");
|
||||||
|
w->Key("Column");
|
||||||
|
w->String("2 bytes");
|
||||||
|
w->Key("Reserved");
|
||||||
|
w->String("2 bytes");
|
||||||
|
w->Key("Debug");
|
||||||
|
w->String("4 bytes");
|
||||||
|
w->Key("Round Robin Number");
|
||||||
|
w->String("2 bytes");
|
||||||
|
w->Key("Detector Type");
|
||||||
|
w->String("1 byte");
|
||||||
|
w->Key("Header Version");
|
||||||
|
w->String("1 byte");
|
||||||
|
w->Key("Packets Caught Mask");
|
||||||
|
w->String("64 bytes");
|
||||||
|
w->EndObject();
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
@ -373,8 +360,10 @@ void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) {
|
|||||||
writer.Key("Number of rows");
|
writer.Key("Number of rows");
|
||||||
writer.Uint(readNRows);
|
writer.Uint(readNRows);
|
||||||
|
|
||||||
|
MasterAttributes::WriteFinalBinaryAttributes(&writer);
|
||||||
|
|
||||||
writer.EndObject();
|
writer.EndObject();
|
||||||
|
|
||||||
std::string message = s.GetString();
|
std::string message = s.GetString();
|
||||||
MasterAttributes::WriteBinaryAttributes(fd, message);
|
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||||
};
|
};
|
||||||
|
@ -70,9 +70,11 @@ class MasterAttributes {
|
|||||||
MasterAttributes() = default;
|
MasterAttributes() = default;
|
||||||
virtual ~MasterAttributes() = default;
|
virtual ~MasterAttributes() = default;
|
||||||
virtual void WriteMasterBinaryAttributes(FILE *fd);
|
virtual void WriteMasterBinaryAttributes(FILE *fd);
|
||||||
void GetBinaryMasterAttributes(rapidjson::Writer<rapidjson::StringBuffer>* w);
|
void
|
||||||
|
GetBinaryMasterAttributes(rapidjson::Writer<rapidjson::StringBuffer> *w);
|
||||||
void WriteBinaryAttributes(FILE *fd, std::string message);
|
void WriteBinaryAttributes(FILE *fd, std::string message);
|
||||||
void WriteFinalBinaryAttributes(FILE *fd);
|
void
|
||||||
|
WriteFinalBinaryAttributes(rapidjson::Writer<rapidjson::StringBuffer> *w);
|
||||||
#ifdef HDF5C
|
#ifdef HDF5C
|
||||||
virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group);
|
virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group);
|
||||||
void WriteHDF5Attributes(H5File *fd, Group *group);
|
void WriteHDF5Attributes(H5File *fd, Group *group);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user