This commit is contained in:
maliakal_d 2021-06-24 07:27:05 +02:00
parent 61c5018a46
commit d3c6996d80
9 changed files with 354 additions and 252 deletions

View File

@ -2234,8 +2234,12 @@ void *start_timer(void *arg) {
if (!isControlServer) { if (!isControlServer) {
return NULL; return NULL;
} }
if (!eiger_virtual_activate) {
return NULL; int skipData = 0;
if (!eiger_virtual_activate ||
(!eiger_virtual_left_datastream && !eiger_virtual_right_datastream)) {
skipData = 1;
LOG(logWARNING, ("Not sending Left and Right datastream\n"));
} }
if (!eiger_virtual_left_datastream) { if (!eiger_virtual_left_datastream) {
LOG(logWARNING, ("Not sending Left datastream\n")); LOG(logWARNING, ("Not sending Left datastream\n"));
@ -2305,7 +2309,7 @@ void *start_timer(void *arg) {
} }
// Send data // Send data
{ if (!skipData) {
uint64_t frameNr = 0; uint64_t frameNr = 0;
getNextFrameNumber(&frameNr); getNextFrameNumber(&frameNr);
// loop over number of frames // loop over number of frames

View File

@ -65,14 +65,12 @@ void BinaryFile::CreateFile() {
} }
} }
void BinaryFile::CloseCurrentFile() { void BinaryFile::CloseAllFiles() {
if (filefd) CloseCurrentDataFile();
fclose(filefd); CloseMasterFile();
filefd = nullptr;
} }
void BinaryFile::CloseAllFiles() { void BinaryFile::CloseMasterFile() {
CloseCurrentFile();
if (master) { if (master) {
if (masterfd) if (masterfd)
fclose(masterfd); fclose(masterfd);
@ -80,6 +78,12 @@ void BinaryFile::CloseAllFiles() {
} }
} }
void BinaryFile::CloseCurrentDataFile() {
if (filefd)
fclose(filefd);
filefd = nullptr;
}
int BinaryFile::WriteData(char *buf, int bsize) { int BinaryFile::WriteData(char *buf, int bsize) {
if (!filefd) if (!filefd)
return 0; return 0;
@ -133,14 +137,8 @@ void BinaryFile::WriteToFile(char *buffer, int buffersize,
} }
} }
void BinaryFile::CreateMasterFile(bool masterFileWriteEnable, void BinaryFile::CreateMasterFile(MasterAttributes *attr) {
MasterAttributes *attr) { if (master) {
// beginning of every acquisition
numFramesInFile = 0;
numActualPacketsInFile = 0;
if (masterFileWriteEnable && master) {
std::ostringstream os; std::ostringstream os;
os << *filePath << "/" << *fileNamePrefix << "_master" os << *filePath << "/" << *fileNamePrefix << "_master"
<< "_" << *fileIndex << ".raw"; << "_" << *fileIndex << ".raw";
@ -173,3 +171,8 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
masterfd = nullptr; masterfd = nullptr;
} }
} }
void BinaryFile::StartofAcquisition() {
numFramesInFile = 0;
numActualPacketsInFile = 0;
}

View File

@ -41,10 +41,11 @@ class BinaryFile : private virtual slsDetectorDefs, public File {
void PrintMembers(TLogLevel level = logDEBUG1) override; void PrintMembers(TLogLevel level = logDEBUG1) override;
void CreateFile() override; void CreateFile() override;
void CreateMasterFile(bool masterFileWriteEnable, void CreateMasterFile(MasterAttributes *attr) override;
MasterAttributes *attr) override; void StartofAcquisition() override;
void CloseCurrentFile() override;
void CloseAllFiles() override; void CloseAllFiles() override;
void CloseCurrentDataFile() override;
void CloseMasterFile() override;
void WriteToFile(char *buffer, int buffersize, uint64_t currentFrameNumber, void WriteToFile(char *buffer, int buffersize, uint64_t currentFrameNumber,
uint32_t numPacketsCaught) override; uint32_t numPacketsCaught) override;

View File

@ -22,25 +22,26 @@
const std::string DataProcessor::TypeName = "DataProcessor"; const std::string DataProcessor::TypeName = "DataProcessor";
DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo *f, DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo *f, bool act,
fileFormat *ftype, bool fwenable, bool *mfwenable, bool depaden, bool *dsEnable, uint32_t *freq,
bool *dsEnable, uint32_t *freq, uint32_t *timer, uint32_t *timer, uint32_t *sfnum, bool *fp,
uint32_t *sfnum, bool *fp, bool *act, bool *sm, std::vector<int> *cdl, int *cdo,
bool *depaden, bool *sm, std::vector<int> *cdl, int *cad)
int *cdo, int *cad)
: ThreadObject(ind, TypeName), fifo(f), myDetectorType(dtype), : ThreadObject(ind, TypeName), fifo(f), myDetectorType(dtype),
dataStreamEnable(dsEnable), fileFormatType(ftype), dataStreamEnable(dsEnable), activated(act),
fileWriteEnable(fwenable), masterFileWriteEnable(mfwenable), deactivatedPaddingEnable(depaden), streamingFrequency(freq),
streamingFrequency(freq), streamingTimerInMs(timer), streamingTimerInMs(timer), streamingStartFnum(sfnum), silentMode(sm),
streamingStartFnum(sfnum), activated(act), framePadding(fp), ctbDbitList(cdl), ctbDbitOffset(cdo),
deactivatedPaddingEnable(depaden), silentMode(sm), framePadding(fp), ctbAnalogDataBytes(cad), firstStreamerFrame(false) {
ctbDbitList(cdl), ctbDbitOffset(cdo), ctbAnalogDataBytes(cad),
firstStreamerFrame(false) {
LOG(logDEBUG) << "DataProcessor " << ind << " created"; LOG(logDEBUG) << "DataProcessor " << ind << " created";
memset((void *)&timerBegin, 0, sizeof(timespec)); memset((void *)&timerBegin, 0, sizeof(timespec));
} }
DataProcessor::~DataProcessor() { delete file; } DataProcessor::~DataProcessor() {
delete file;
delete masterFile;
delete virtualFile;
}
/** getters */ /** getters */
@ -83,74 +84,109 @@ void DataProcessor::SetGeneralData(GeneralData *g) {
generalData->nPixelsY); generalData->nPixelsY);
} }
} }
} if (masterFile != nullptr) {
if (masterFile->GetFileType() == HDF5) {
void DataProcessor::SetFileFormat(const fileFormat f) { masterFile->SetNumberofPixels(generalData->nPixelsX,
if ((file != nullptr) && file->GetFileType() != f) { generalData->nPixelsY);
// remember the pointer values before they are destroyed }
int nd[MAX_DIMENSIONS]; }
nd[0] = 0; if (virtualFile != nullptr) {
nd[1] = 0; if (virtualFile->GetFileType() == HDF5) {
uint32_t *maxf = nullptr; virtualFile->SetNumberofPixels(generalData->nPixelsX,
std::string *fname = nullptr; generalData->nPixelsY);
std::string *fpath = nullptr; }
uint64_t *findex = nullptr;
bool *owenable = nullptr;
int *dindex = nullptr;
int *nunits = nullptr;
uint64_t *nf = nullptr;
uint32_t *dr = nullptr;
uint32_t *port = nullptr;
file->GetMemberPointerValues(nd, maxf, fname, fpath, findex, owenable,
dindex, nunits, nf, dr, port);
// create file writer with same pointers
SetupFileWriter(fileWriteEnable, nd, maxf, fname, fpath, findex,
owenable, dindex, nunits, nf, dr, port);
} }
} }
void DataProcessor::SetupFileWriter(bool fwe, int *nd, uint32_t *maxf, void DataProcessor::SetupFileWriter(fileFormat ftype, bool fwe, int act,
int depaden, int *nd, uint32_t *maxf,
std::string *fname, std::string *fpath, std::string *fname, std::string *fpath,
uint64_t *findex, bool *owenable, uint64_t *findex, bool *owenable,
int *dindex, int *nunits, uint64_t *nf, int *dindex, int *nunits, uint64_t *nf,
uint32_t *dr, uint32_t *portno, uint32_t *dr, uint32_t *portno,
GeneralData *g) { GeneralData *g) {
fileWriteEnable = fwe; activated = act;
deactivatedPaddingEnable = depaden;
if (g != nullptr) if (g != nullptr)
generalData = g; generalData = g;
// close existing file objects
if (file != nullptr) { if (file != nullptr) {
delete file; delete file;
file = nullptr; file = nullptr;
} }
if (masterFile != nullptr) {
delete masterFile;
masterFile = nullptr;
}
if (virtualFile != nullptr) {
delete virtualFile;
virtualFile = nullptr;
}
// skip data file writing for deactivated non padded parts
bool skipDataFileWriting = false;
if (myDetectorType == EIGER && !activated && !deactivatedPaddingEnable) {
skipDataFileWriting = true;
}
if (fileWriteEnable) { // create file objects
switch (*fileFormatType) { if (fwe) {
switch (fileFormatType) {
#ifdef HDF5C #ifdef HDF5C
case HDF5: case HDF5:
file = new HDF5File(index, maxf, nd, fname, fpath, findex, owenable, // data file
dindex, nunits, nf, dr, portno, if (!skipDataFileWriting) {
generalData->nPixelsX, generalData->nPixelsY, file = new HDF5File(index, maxf, nd, fname, fpath, findex,
silentMode); owenable, dindex, nunits, nf, dr, portno,
generalData->nPixelsX,
generalData->nPixelsY, silentMode);
}
// master file
if ((index == 0) && (*dindex == 0)) {
masterFile = new HDF5File(index, maxf, nd, fname, fpath, findex,
owenable, dindex, nunits, nf, dr,
portno, generalData->nPixelsX,
generalData->nPixelsY, silentMode);
virtualFile = new HDF5File(index, maxf, nd, fname, fpath,
findex, owenable, dindex, nunits, nf,
dr, portno, generalData->nPixelsX,
generalData->nPixelsY, silentMode);
}
break; break;
#endif #endif
default: default:
file = // data file
new BinaryFile(index, maxf, nd, fname, fpath, findex, owenable, if (!skipDataFileWriting) {
dindex, nunits, nf, dr, portno, silentMode); file = new BinaryFile(index, maxf, nd, fname, fpath, findex,
owenable, dindex, nunits, nf, dr, portno,
silentMode);
}
// master file
if ((index == 0) && (*dindex == 0)) {
masterFile = new BinaryFile(index, maxf, nd, fname, fpath,
findex, owenable, dindex, nunits,
nf, dr, portno, silentMode);
}
break; break;
} }
} }
} }
// only the first file void DataProcessor::CreateMasterFile(MasterAttributes *attr) {
void DataProcessor::CreateNewFile(MasterAttributes *attr) { if (masterFile == nullptr) {
throw sls::RuntimeError("master file object not contstructed");
}
masterFile->CloseMasterFile();
masterFile->CreateMasterFile(attr);
}
void DataProcessor::CreateFirstDataFile() {
if (file == nullptr) { if (file == nullptr) {
throw sls::RuntimeError("file object not contstructed"); throw sls::RuntimeError("file object not contstructed");
} }
file->CloseAllFiles(); file->CloseCurrentDataFile();
file->resetSubFileIndex(); file->resetSubFileIndex();
file->CreateMasterFile(*masterFileWriteEnable, attr); file->StartofAcquisition();
file->CreateFile(); file->CreateFile();
} }
@ -249,11 +285,11 @@ uint64_t DataProcessor::ProcessAnImage(char *buf) {
} }
// frame padding // frame padding
if (*activated && *framePadding && nump < generalData->packetsPerFrame) if (activated && *framePadding && nump < generalData->packetsPerFrame)
PadMissingPackets(buf); PadMissingPackets(buf);
// deactivated and padding enabled // deactivated and padding enabled
else if (!(*activated) && *deactivatedPaddingEnable) else if (!activated && deactivatedPaddingEnable)
PadMissingPackets(buf); PadMissingPackets(buf);
// rearrange ctb digital bits (if ctbDbitlist is not empty) // rearrange ctb digital bits (if ctbDbitlist is not empty)

View File

@ -31,27 +31,23 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
* @param ind self index * @param ind self index
* @param dtype detector type * @param dtype detector type
* @param f address of Fifo pointer * @param f address of Fifo pointer
* @param ftype pointer to file format type * @param act activated
* @param fwenable file writer enable * @param depaden deactivated padding enable
* @param mfwenable pointer to master file write enable
* @param dsEnable pointer to data stream enable * @param dsEnable pointer to data stream enable
* @param dr pointer to dynamic range * @param dr pointer to dynamic range
* @param freq pointer to streaming frequency * @param freq pointer to streaming frequency
* @param timer pointer to timer if streaming frequency is random * @param timer pointer to timer if streaming frequency is random
* @param sfnum pointer to streaming starting fnum * @param sfnum pointer to streaming starting fnum
* @param fp pointer to frame padding enable * @param fp pointer to frame padding enable
* @param act pointer to activated
* @param depaden pointer to deactivated padding enable
* @param sm pointer to silent mode * @param sm pointer to silent mode
* @param qe pointer to quad Enable * @param qe pointer to quad Enable
* @param cdl pointer to vector or ctb digital bits enable * @param cdl pointer to vector or ctb digital bits enable
* @param cdo pointer to digital bits offset * @param cdo pointer to digital bits offset
* @param cad pointer to ctb analog databytes * @param cad pointer to ctb analog databytes
*/ */
DataProcessor(int ind, detectorType dtype, Fifo *f, fileFormat *ftype, DataProcessor(int ind, detectorType dtype, Fifo *f, bool act, bool depaden,
bool fwenable, bool *mfwenable, bool *dsEnable, bool *dsEnable, uint32_t *freq, uint32_t *timer,
uint32_t *freq, uint32_t *timer, uint32_t *sfnum, bool *fp, uint32_t *sfnum, bool *fp, bool *sm, std::vector<int> *cdl,
bool *act, bool *depaden, bool *sm, std::vector<int> *cdl,
int *cdo, int *cad); int *cdo, int *cad);
/** /**
@ -104,15 +100,12 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
*/ */
void SetGeneralData(GeneralData *g); void SetGeneralData(GeneralData *g);
/**
* Set File Format
* @param fs file format
*/
void SetFileFormat(const fileFormat fs);
/** /**
* Set up file writer object and call backs * Set up file writer object and call backs
* @param ftype file format
* @param fwe file write enable * @param fwe file write enable
* @param act activated
* @param depad deactivated padding enable
* @param nd pointer to number of detectors in each dimension * @param nd pointer to number of detectors in each dimension
* @param maxf pointer to max frames per file * @param maxf pointer to max frames per file
* @param fname pointer to file name prefix * @param fname pointer to file name prefix
@ -126,16 +119,22 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
* @param portno pointer to udp port number * @param portno pointer to udp port number
* @param g address of GeneralData (Detector Data) pointer * @param g address of GeneralData (Detector Data) pointer
*/ */
void SetupFileWriter(bool fwe, int *nd, uint32_t *maxf, std::string *fname, void SetupFileWriter(fileFormat ftype, bool fwe, int act, int depaden,
int *nd, uint32_t *maxf, std::string *fname,
std::string *fpath, uint64_t *findex, bool *owenable, std::string *fpath, uint64_t *findex, bool *owenable,
int *dindex, int *nunits, uint64_t *nf, uint32_t *dr, int *dindex, int *nunits, uint64_t *nf, uint32_t *dr,
uint32_t *portno, GeneralData *g = nullptr); uint32_t *portno, GeneralData *g = nullptr);
/** /**
* Create New File * Create Master File (also virtual if hdf5)
* @param attr master file attributes * @param attr master file attributes
*/ */
void CreateNewFile(MasterAttributes *attr); void CreateMasterFile(MasterAttributes *attr);
/**
* Create First Data File
*/
void CreatFirsteDataFile();
/** /**
* Closes files * Closes files
@ -256,17 +255,20 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
/** File writer implemented as binary or hdf5 File */ /** File writer implemented as binary or hdf5 File */
File *file{nullptr}; File *file{nullptr};
/** master file */
File *masterFile{nullptr};
/** virtual file (for hdf5) */
File *virtualFile{nullptr};
/** Data Stream Enable */ /** Data Stream Enable */
bool *dataStreamEnable; bool *dataStreamEnable;
/** File Format Type */ /** Activated/Deactivated */
fileFormat *fileFormatType; bool activated;
/** File Write Enable */ /** Deactivated padding enable */
bool fileWriteEnable; bool deactivatedPaddingEnable;
/** Master File Write Enable */
bool *masterFileWriteEnable;
/** Pointer to Streaming frequency, if 0, sending random images with a timer /** Pointer to Streaming frequency, if 0, sending random images with a timer
*/ */
@ -284,12 +286,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
/** timer beginning stamp for random streaming */ /** timer beginning stamp for random streaming */
struct timespec timerBegin; struct timespec timerBegin;
/** Activated/Deactivated */
bool *activated;
/** Deactivated padding enable */
bool *deactivatedPaddingEnable;
/** Silent Mode */ /** Silent Mode */
bool *silentMode; bool *silentMode;

View File

@ -70,8 +70,9 @@ class File : private virtual slsDetectorDefs {
uint32_t *&portno); uint32_t *&portno);
virtual void CreateFile() = 0; virtual void CreateFile() = 0;
virtual void CloseCurrentFile() = 0; virtual void CloseCurrentDataFile() = 0;
virtual void CloseAllFiles() = 0; virtual void CloseAllFiles() = 0;
virtual void CloseMasterFile() = 0;
/** /**
* Write data to file * Write data to file
@ -85,10 +86,9 @@ class File : private virtual slsDetectorDefs {
/** /**
* Create master file * Create master file
* @param mfwenable master file write enable
* @param attr master file attributes * @param attr master file attributes
*/ */
virtual void CreateMasterFile(bool mfwenable, MasterAttributes *attr) = 0; virtual void CreateMasterFile(MasterAttributes *attr) = 0;
// HDf5 specific // HDf5 specific
/** /**
@ -101,6 +101,14 @@ class File : private virtual slsDetectorDefs {
"should be overloaded by a derived class"; "should be overloaded by a derived class";
} }
/**
* Start of Acquisition
*/
virtual void StartofAcquisition() {
LOG(logERROR) << "This is a generic function StartofAcquisition that "
"should be overloaded by a derived class";
}
/** /**
* End of Acquisition * End of Acquisition
* @param anyPacketsCaught true if any packets are caught, else false * @param anyPacketsCaught true if any packets are caught, else false

View File

@ -86,7 +86,26 @@ void HDF5File::CreateFile() {
CreateDataFile(); CreateDataFile();
} }
void HDF5File::CloseCurrentFile() { void HDF5File::CloseAllFiles() {
CloseCurrentDataFile();
CloseMasterFile();
}
void HDF5File::CloseMasterFile() {
if (master) {
CloseFile(masterfd, true);
// close virtual file
// c code due to only c implementation of H5Pset_virtual available
if (virtualfd != 0) {
if (H5Fclose(virtualfd) < 0) {
LOG(logERROR) << "Could not close virtual HDF5 handles";
}
virtualfd = 0;
}
}
}
void HDF5File::CloseCurrentDataFile() {
CloseFile(filefd, false); CloseFile(filefd, false);
for (unsigned int i = 0; i < dataset_para.size(); ++i) for (unsigned int i = 0; i < dataset_para.size(); ++i)
delete dataset_para[i]; delete dataset_para[i];
@ -105,30 +124,6 @@ void HDF5File::CloseCurrentFile() {
} }
} }
void HDF5File::CloseAllFiles() {
numFilesinAcquisition = 0;
{
CloseFile(filefd, false);
if (master) {
CloseFile(masterfd, true);
// close virtual file
// c code due to only c implementation of H5Pset_virtual available
if (virtualfd != 0) {
if (H5Fclose(virtualfd) < 0) {
LOG(logERROR) << "Could not close virtual HDF5 handles";
}
virtualfd = 0;
}
}
}
for (unsigned int i = 0; i < dataset_para.size(); ++i)
delete dataset_para[i];
dataset_para.clear();
delete dataspace_para;
delete dataset;
delete dataspace;
}
void HDF5File::WriteToFile(char *buffer, int bufferSize, void HDF5File::WriteToFile(char *buffer, int bufferSize,
uint64_t currentFrameNumber, uint64_t currentFrameNumber,
uint32_t numPacketsCaught) { uint32_t numPacketsCaught) {
@ -152,20 +147,20 @@ void HDF5File::WriteToFile(char *buffer, int bufferSize,
WriteParameterDatasets(currentFrameNumber, (sls_receiver_header *)(buffer)); WriteParameterDatasets(currentFrameNumber, (sls_receiver_header *)(buffer));
} }
void HDF5File::CreateMasterFile(bool masterFileWriteEnable, void HDF5File::CreateMasterFile(MasterAttributes *attr) {
MasterAttributes *attr) { if (master) {
// beginning of every acquisition
numFramesInFile = 0;
numActualPacketsInFile = 0;
extNumImages = *numImages;
if (masterFileWriteEnable && master) {
virtualfd = 0; virtualfd = 0;
CreateMasterDataFile(attr); CreateMasterDataFile(attr);
} }
} }
void HDF5File::StartofAcquisition() {
numFilesinAcquisition = 0;
numFramesInFile = 0;
numActualPacketsInFile = 0;
extNumImages = *numImages;
}
void HDF5File::EndofAcquisition(bool anyPacketsCaught, void HDF5File::EndofAcquisition(bool anyPacketsCaught,
uint64_t numImagesCaught) { uint64_t numImagesCaught) {
// not created before // not created before

View File

@ -45,13 +45,14 @@ class HDF5File : private virtual slsDetectorDefs, public File {
uint32_t nx, uint32_t ny, bool *smode); uint32_t nx, uint32_t ny, bool *smode);
~HDF5File(); ~HDF5File();
void SetNumberofPixels(uint32_t nx, uint32_t ny); void SetNumberofPixels(uint32_t nx, uint32_t ny);
void CreateFile(); void CreateFile() override;
void CloseCurrentFile(); void CloseAllFiles() override;
void CloseAllFiles(); void CloseCurrentDataFile() override;
void CloseMasterFile() override;
void WriteToFile(char *buffer, int bufferSize, uint64_t currentFrameNumber, void WriteToFile(char *buffer, int bufferSize, uint64_t currentFrameNumber,
uint32_t numPacketsCaught); uint32_t numPacketsCaught) override;
void CreateMasterFile(bool masterFileWriteEnable, void CreateMasterFile(MasterAttributes *attr) override;
MasterAttributes *attr) override; void StartofAcquisition() override;
void EndofAcquisition(bool anyPacketsCaught, uint64_t numImagesCaught); void EndofAcquisition(bool anyPacketsCaught, uint64_t numImagesCaught);
private: private:

View File

@ -169,11 +169,11 @@ void Implementation::setDetectorType(const detectorType d) {
&actualUDPSocketBufferSize, &framesPerFile, &frameDiscardMode, &actualUDPSocketBufferSize, &framesPerFile, &frameDiscardMode,
&activated, &deactivatedPaddingEnable, &silentMode)); &activated, &deactivatedPaddingEnable, &silentMode));
dataProcessor.push_back(sls::make_unique<DataProcessor>( dataProcessor.push_back(sls::make_unique<DataProcessor>(
i, myDetectorType, fifo_ptr, &fileFormatType, fileWriteEnable, i, myDetectorType, fifo_ptr, activated,
&masterFileWriteEnable, &dataStreamEnable, &streamingFrequency, deactivatedPaddingEnable, &dataStreamEnable,
&streamingTimerInMs, &streamingStartFnum, &framePadding, &streamingFrequency, &streamingTimerInMs, &streamingStartFnum,
&activated, &deactivatedPaddingEnable, &silentMode, &framePadding, &silentMode, &ctbDbitList, &ctbDbitOffset,
&ctbDbitList, &ctbDbitOffset, &ctbAnalogDataBytes)); &ctbAnalogDataBytes));
} catch (...) { } catch (...) {
listener.clear(); listener.clear();
dataProcessor.clear(); dataProcessor.clear();
@ -236,7 +236,8 @@ void Implementation::setModulePositionId(const int id) {
for (unsigned int i = 0; i < dataProcessor.size(); ++i) { for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter( dataProcessor[i]->SetupFileWriter(
fileWriteEnable, (int *)numDet, &framesPerFile, &fileName, fileFormatType, fileWriteEnable, masterFileWriteEnable, activated,
deactivatedPaddingEnable, (int *)numDet, &framesPerFile, &fileName,
&filePath, &fileIndex, &overwriteEnable, &modulePos, &numThreads, &filePath, &fileIndex, &overwriteEnable, &modulePos, &numThreads,
&numberOfTotalFrames, &dynamicRange, &udpPortNum[i], generalData); &numberOfTotalFrames, &dynamicRange, &udpPortNum[i], generalData);
} }
@ -332,20 +333,30 @@ slsDetectorDefs::fileFormat Implementation::getFileFormat() const {
} }
void Implementation::setFileFormat(const fileFormat f) { void Implementation::setFileFormat(const fileFormat f) {
switch (f) { if (f != fileFormatType) {
switch (f) {
#ifdef HDF5C #ifdef HDF5C
case HDF5: case HDF5:
fileFormatType = HDF5; fileFormatType = HDF5;
break; break;
#endif #endif
default: default:
fileFormatType = BINARY; fileFormatType = BINARY;
break; break;
}
if (fileWriteEnable) {
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter(
fileFormatType, fileWriteEnable, masterFileWriteEnable,
activated, deactivatedPaddingEnable, (int *)numDet,
&framesPerFile, &fileName, &filePath, &fileIndex,
&overwriteEnable, &modulePos, &numThreads,
&numberOfTotalFrames, &dynamicRange, &udpPortNum[i],
generalData);
}
}
} }
for (const auto &it : dataProcessor)
it->SetFileFormat(f);
LOG(logINFO) << "File Format: " << sls::ToString(fileFormatType); LOG(logINFO) << "File Format: " << sls::ToString(fileFormatType);
} }
@ -380,10 +391,11 @@ void Implementation::setFileWriteEnable(const bool b) {
fileWriteEnable = b; fileWriteEnable = b;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) { for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter( dataProcessor[i]->SetupFileWriter(
fileWriteEnable, (int *)numDet, &framesPerFile, &fileName, fileFormatType, fileWriteEnable, masterFileWriteEnable,
&filePath, &fileIndex, &overwriteEnable, &modulePos, activated, deactivatedPaddingEnable, (int *)numDet,
&numThreads, &numberOfTotalFrames, &dynamicRange, &framesPerFile, &fileName, &filePath, &fileIndex,
&udpPortNum[i], generalData); &overwriteEnable, &modulePos, &numThreads, &numberOfTotalFrames,
&dynamicRange, &udpPortNum[i], generalData);
} }
} }
LOG(logINFO) << "File Write Enable: " LOG(logINFO) << "File Write Enable: "
@ -395,7 +407,17 @@ bool Implementation::getMasterFileWriteEnable() const {
} }
void Implementation::setMasterFileWriteEnable(const bool b) { void Implementation::setMasterFileWriteEnable(const bool b) {
masterFileWriteEnable = b; if (masterFileWriteEnable != b) {
masterFileWriteEnable = b;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter(
fileFormatType, fileWriteEnable, masterFileWriteEnable,
activated, deactivatedPaddingEnable, (int *)numDet,
&framesPerFile, &fileName, &filePath, &fileIndex,
&overwriteEnable, &modulePos, &numThreads, &numberOfTotalFrames,
&dynamicRange, &udpPortNum[i], generalData);
}
}
LOG(logINFO) << "Master File Write Enable: " LOG(logINFO) << "Master File Write Enable: "
<< (masterFileWriteEnable ? "enabled" : "disabled"); << (masterFileWriteEnable ? "enabled" : "disabled");
} }
@ -719,90 +741,104 @@ void Implementation::CreateUDPSockets() {
} }
void Implementation::SetupWriter() { void Implementation::SetupWriter() {
std::unique_ptr<MasterAttributes> masterAttributes; // master file
switch (myDetectorType) { if (masterFileWriteEnable) {
case GOTTHARD: std::unique_ptr<MasterAttributes> masterAttributes;
masterAttributes = sls::make_unique<GotthardMasterAttributes>(); switch (myDetectorType) {
break; case GOTTHARD:
case JUNGFRAU: masterAttributes = sls::make_unique<GotthardMasterAttributes>();
masterAttributes = sls::make_unique<JungfrauMasterAttributes>(); break;
break; case JUNGFRAU:
case EIGER: masterAttributes = sls::make_unique<JungfrauMasterAttributes>();
masterAttributes = sls::make_unique<EigerMasterAttributes>(); break;
break; case EIGER:
case MYTHEN3: masterAttributes = sls::make_unique<EigerMasterAttributes>();
masterAttributes = sls::make_unique<Mythen3MasterAttributes>(); break;
break; case MYTHEN3:
case GOTTHARD2: masterAttributes = sls::make_unique<Mythen3MasterAttributes>();
masterAttributes = sls::make_unique<Gotthard2MasterAttributes>(); break;
break; case GOTTHARD2:
case MOENCH: masterAttributes = sls::make_unique<Gotthard2MasterAttributes>();
masterAttributes = sls::make_unique<MoenchMasterAttributes>(); break;
break; case MOENCH:
case CHIPTESTBOARD: masterAttributes = sls::make_unique<MoenchMasterAttributes>();
masterAttributes = sls::make_unique<CtbMasterAttributes>(); break;
break; case CHIPTESTBOARD:
default: masterAttributes = sls::make_unique<CtbMasterAttributes>();
throw sls::RuntimeError( break;
"Unknown detector type to set up master file attributes"); default:
throw sls::RuntimeError(
"Unknown detector type to set up master file attributes");
}
masterAttributes->detType = myDetectorType;
masterAttributes->timingMode = timingMode;
masterAttributes->imageSize = generalData->imageSize;
masterAttributes->nPixels =
xy(generalData->nPixelsX, generalData->nPixelsY);
masterAttributes->maxFramesPerFile = framesPerFile;
masterAttributes->frameDiscardMode = frameDiscardMode;
masterAttributes->framePadding = framePadding;
masterAttributes->scanParams = scanParams;
masterAttributes->totalFrames = numberOfTotalFrames;
masterAttributes->exptime = acquisitionTime;
masterAttributes->period = acquisitionPeriod;
masterAttributes->burstMode = burstMode;
masterAttributes->numUDPInterfaces = numUDPInterfaces;
masterAttributes->dynamicRange = dynamicRange;
masterAttributes->tenGiga = tengigaEnable;
masterAttributes->thresholdEnergyeV = thresholdEnergyeV;
masterAttributes->thresholdAllEnergyeV = thresholdAllEnergyeV;
masterAttributes->subExptime = subExpTime;
masterAttributes->subPeriod = subPeriod;
masterAttributes->quad = quadEnable;
masterAttributes->numLinesReadout = numLinesReadout;
masterAttributes->ratecorr = rateCorrections;
masterAttributes->adcmask =
tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga;
masterAttributes->analog =
(readoutType == ANALOG_ONLY || readoutType == ANALOG_AND_DIGITAL)
? 1
: 0;
masterAttributes->analogSamples = numberOfAnalogSamples;
masterAttributes->digital =
(readoutType == DIGITAL_ONLY || readoutType == ANALOG_AND_DIGITAL)
? 1
: 0;
masterAttributes->digitalSamples = numberOfDigitalSamples;
masterAttributes->dbitoffset = ctbDbitOffset;
masterAttributes->dbitlist = 0;
for (auto &i : ctbDbitList) {
masterAttributes->dbitlist |= (1 << i);
}
masterAttributes->roi = roi;
masterAttributes->counterMask = counterMask;
masterAttributes->exptime1 = acquisitionTime1;
masterAttributes->exptime2 = acquisitionTime2;
masterAttributes->exptime3 = acquisitionTime3;
masterAttributes->gateDelay1 = gateDelay1;
masterAttributes->gateDelay2 = gateDelay2;
masterAttributes->gateDelay3 = gateDelay3;
masterAttributes->gates = numberOfGates;
masterAttributes->additionalJsonHeader = additionalJsonHeader;
try {
dataProcessor[0]->CreateMasterFile(masterAttributes.get());
} catch (const sls::RuntimeError &e) {
shutDownUDPSockets();
closeFiles();
throw sls::RuntimeError("Could not create master file.");
}
} }
masterAttributes->detType = myDetectorType;
masterAttributes->timingMode = timingMode;
masterAttributes->imageSize = generalData->imageSize;
masterAttributes->nPixels =
xy(generalData->nPixelsX, generalData->nPixelsY);
masterAttributes->maxFramesPerFile = framesPerFile;
masterAttributes->frameDiscardMode = frameDiscardMode;
masterAttributes->framePadding = framePadding;
masterAttributes->scanParams = scanParams;
masterAttributes->totalFrames = numberOfTotalFrames;
masterAttributes->exptime = acquisitionTime;
masterAttributes->period = acquisitionPeriod;
masterAttributes->burstMode = burstMode;
masterAttributes->numUDPInterfaces = numUDPInterfaces;
masterAttributes->dynamicRange = dynamicRange;
masterAttributes->tenGiga = tengigaEnable;
masterAttributes->thresholdEnergyeV = thresholdEnergyeV;
masterAttributes->thresholdAllEnergyeV = thresholdAllEnergyeV;
masterAttributes->subExptime = subExpTime;
masterAttributes->subPeriod = subPeriod;
masterAttributes->quad = quadEnable;
masterAttributes->numLinesReadout = numLinesReadout;
masterAttributes->ratecorr = rateCorrections;
masterAttributes->adcmask =
tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga;
masterAttributes->analog =
(readoutType == ANALOG_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1
: 0;
masterAttributes->analogSamples = numberOfAnalogSamples;
masterAttributes->digital =
(readoutType == DIGITAL_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1
: 0;
masterAttributes->digitalSamples = numberOfDigitalSamples;
masterAttributes->dbitoffset = ctbDbitOffset;
masterAttributes->dbitlist = 0;
for (auto &i : ctbDbitList) {
masterAttributes->dbitlist |= (1 << i);
}
masterAttributes->roi = roi;
masterAttributes->counterMask = counterMask;
masterAttributes->exptime1 = acquisitionTime1;
masterAttributes->exptime2 = acquisitionTime2;
masterAttributes->exptime3 = acquisitionTime3;
masterAttributes->gateDelay1 = gateDelay1;
masterAttributes->gateDelay2 = gateDelay2;
masterAttributes->gateDelay3 = gateDelay3;
masterAttributes->gates = numberOfGates;
masterAttributes->additionalJsonHeader = additionalJsonHeader;
// first data file
//->startofacquisition(which has all the start, and createfirstdatafile)
try { try {
for (unsigned int i = 0; i < dataProcessor.size(); ++i) { for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->CreateNewFile(masterAttributes.get()); dataProcessor[i]->CreateFirstDataFile();
} }
} catch (const sls::RuntimeError &e) { } catch (const sls::RuntimeError &e) {
shutDownUDPSockets(); shutDownUDPSockets();
closeFiles(); closeFiles();
throw sls::RuntimeError("Could not create file."); throw sls::RuntimeError("Could not create first data file.");
} }
} }
@ -872,12 +908,11 @@ void Implementation::setNumberofUDPInterfaces(const int n) {
listener[i]->SetGeneralData(generalData); listener[i]->SetGeneralData(generalData);
dataProcessor.push_back(sls::make_unique<DataProcessor>( dataProcessor.push_back(sls::make_unique<DataProcessor>(
i, myDetectorType, fifo_ptr, &fileFormatType, i, myDetectorType, fifo_ptr, activated,
fileWriteEnable, &masterFileWriteEnable, &dataStreamEnable, deactivatedPaddingEnable, &dataStreamEnable,
&streamingFrequency, &streamingTimerInMs, &streamingFrequency, &streamingTimerInMs,
&streamingStartFnum, &framePadding, &activated, &streamingStartFnum, &framePadding, &silentMode,
&deactivatedPaddingEnable, &silentMode, &ctbDbitList, &ctbDbitList, &ctbDbitOffset, &ctbAnalogDataBytes));
&ctbDbitOffset, &ctbAnalogDataBytes));
dataProcessor[i]->SetGeneralData(generalData); dataProcessor[i]->SetGeneralData(generalData);
} catch (...) { } catch (...) {
listener.clear(); listener.clear();
@ -1512,7 +1547,19 @@ void Implementation::setQuad(const bool b) {
bool Implementation::getActivate() const { return activated; } bool Implementation::getActivate() const { return activated; }
bool Implementation::setActivate(bool enable) { bool Implementation::setActivate(bool enable) {
activated = enable; if (activated != enable) {
activated = enable;
// disable file writing if deactivated and no padding
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter(
fileFormatType, fileWriteEnable, masterFileWriteEnable,
activated, deactivatedPaddingEnable, (int *)numDet,
&framesPerFile, &fileName, &filePath, &fileIndex,
&overwriteEnable, &modulePos, &numThreads, &numberOfTotalFrames,
&dynamicRange, &udpPortNum[i], generalData);
}
}
LOG(logINFO) << "Activation: " << (activated ? "enabled" : "disabled"); LOG(logINFO) << "Activation: " << (activated ? "enabled" : "disabled");
return activated; return activated;
} }
@ -1522,7 +1569,18 @@ bool Implementation::getDeactivatedPadding() const {
} }
void Implementation::setDeactivatedPadding(bool enable) { void Implementation::setDeactivatedPadding(bool enable) {
deactivatedPaddingEnable = enable; if (deactivatedPaddingEnable != enable) {
deactivatedPaddingEnable = enable;
// disable file writing if deactivated and no padding
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter(
fileFormatType, fileWriteEnable, masterFileWriteEnable,
activated, deactivatedPaddingEnable, (int *)numDet,
&framesPerFile, &fileName, &filePath, &fileIndex,
&overwriteEnable, &modulePos, &numThreads, &numberOfTotalFrames,
&dynamicRange, &udpPortNum[i], generalData);
}
}
LOG(logINFO) << "Deactivated Padding Enable: " LOG(logINFO) << "Deactivated Padding Enable: "
<< (deactivatedPaddingEnable ? "enabled" : "disabled"); << (deactivatedPaddingEnable ? "enabled" : "disabled");
} }