slsReciever, slsDetector: configurable number of images per file, removed all the receiver threads from using generalData->maxframesperfile, yet to do: infinite images, bug fix, virtual hdf5 has -1 for all pixels in last image

This commit is contained in:
2018-05-18 13:47:10 +02:00
parent dcce66ee9f
commit 8b39443197
24 changed files with 269 additions and 58 deletions

View File

@ -14,7 +14,7 @@ using namespace std;
FILE* BinaryFile::masterfd = 0;
BinaryFile::BinaryFile(int ind, uint32_t maxf,
BinaryFile::BinaryFile(int ind, uint32_t* maxf,
int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
bool* smode):
@ -34,7 +34,7 @@ BinaryFile::~BinaryFile() {
void BinaryFile::PrintMembers() {
File::PrintMembers();
FILE_LOG(logINFO) << "Max Frames Per File: " << maxFramesPerFile;
FILE_LOG(logINFO) << "Max Frames Per File: " << *maxFramesPerFile;
FILE_LOG(logINFO) << "Number of Frames in File: " << numFramesInFile;
}
@ -70,7 +70,7 @@ void BinaryFile::CloseAllFiles() {
}
int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
if (numFramesInFile >= maxFramesPerFile) {
if (numFramesInFile >= (*maxFramesPerFile)) {
CloseCurrentFile();
CreateFile(fnum);
}

View File

@ -23,10 +23,12 @@ using namespace std;
const string DataProcessor::TypeName = "DataProcessor";
DataProcessor::DataProcessor(int ind, Fifo*& f, fileFormat* ftype, bool fwenable, bool* dsEnable, bool* gpEnable, uint32_t* dr,
DataProcessor::DataProcessor(int ind, Fifo*& f, fileFormat* ftype, bool fwenable,
bool* dsEnable, bool* gpEnable, uint32_t* dr,
uint32_t* freq, uint32_t* timer,
void (*dataReadycb)(uint64_t, uint32_t, uint32_t, uint64_t, uint64_t,
uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t, uint8_t, uint8_t,
uint16_t, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t,
uint8_t, uint8_t,
char*, uint32_t, void*),
void (*dataModifyReadycb)(uint64_t, uint32_t, uint32_t, uint64_t,
uint64_t, uint16_t, uint16_t, uint16_t, uint16_t,
@ -179,7 +181,6 @@ void DataProcessor::SetGeneralData(GeneralData* g) {
generalData->Print();
#endif
if (file) {
file->SetMaxFramesPerFile(generalData->maxFramesPerFile);
if (file->GetFileType() == HDF5) {
file->SetNumberofPixels(generalData->nPixelsX, generalData->nPixelsY);
}
@ -201,16 +202,17 @@ void DataProcessor::SetFileFormat(const fileFormat f) {
if (file && file->GetFileType() != f) {
//remember the pointer values before they are destroyed
int nd[MAX_DIMENSIONS];nd[0] = 0; nd[1] = 0;
uint32_t* maxf = 0;
char* fname=0; char* fpath=0; uint64_t* findex=0;
bool* owenable=0; int* dindex=0; int* nunits=0; uint64_t* nf = 0; uint32_t* dr = 0; uint32_t* port = 0;
file->GetMemberPointerValues(nd, fname, fpath, findex, owenable, dindex, nunits, nf, dr, port);
file->GetMemberPointerValues(nd, maxf, fname, fpath, findex, owenable, dindex, nunits, nf, dr, port);
//create file writer with same pointers
SetupFileWriter(fileWriteEnable, nd, fname, fpath, findex, owenable, dindex, nunits, nf, dr, port);
SetupFileWriter(fileWriteEnable, nd, maxf, fname, fpath, findex, owenable, dindex, nunits, nf, dr, port);
}
}
void DataProcessor::SetupFileWriter(bool fwe, int* nd, char* fname, char* fpath, uint64_t* findex,
void DataProcessor::SetupFileWriter(bool fwe, int* nd, uint32_t* maxf, char* fname, char* fpath, uint64_t* findex,
bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
GeneralData* g)
{
@ -229,14 +231,14 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, char* fname, char* fpath,
switch(*fileFormatType){
#ifdef HDF5C
case HDF5:
file = new HDF5File(index, generalData->maxFramesPerFile,
file = new HDF5File(index, maxf,
nd, fname, fpath, findex, owenable,
dindex, nunits, nf, dr, portno,
generalData->nPixelsX, generalData->nPixelsY, &silentMode);
break;
#endif
default:
file = new BinaryFile(index, generalData->maxFramesPerFile,
file = new BinaryFile(index, maxf,
nd, fname, fpath, findex, owenable,
dindex, nunits, nf, dr, portno, &silentMode);
break;

View File

@ -10,7 +10,7 @@
using namespace std;
File::File(int ind, uint32_t maxf,
File::File(int ind, uint32_t* maxf,
int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
bool* smode):
@ -42,7 +42,7 @@ string File::GetCurrentFileName() {
void File::PrintMembers() {
FILE_LOG(logINFO) << "\nGeneral Writer Variables:" << endl
<< "Index: " << index << endl
<< "Max Frames Per File: " << maxFramesPerFile << endl
<< "Max Frames Per File: " << *maxFramesPerFile << endl
<< "Number of Detectors in x dir: " << numDetX << endl
<< "Number of Detectors in y dir: " << numDetY << endl
<< "File Name Prefix: " << fileNamePrefix << endl
@ -61,11 +61,12 @@ void File::PrintMembers() {
}
void File::GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*& findex, bool*& owenable,
void File::GetMemberPointerValues(int* nd, uint32_t*& maxf, char*& fname, char*& fpath, uint64_t*& findex, bool*& owenable,
int*& dindex, int*& nunits, uint64_t*& nf, uint32_t*& dr, uint32_t*& portno)
{
nd[0] = numDetX;
nd[1] = numDetY;
maxf = maxFramesPerFile;
fname = fileNamePrefix;
fpath = filePath;
findex = fileIndex;
@ -77,7 +78,4 @@ void File::GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*
portno = udpPortNumber;
}
void File::SetMaxFramesPerFile(uint32_t maxf) {
maxFramesPerFile = maxf;
}

View File

@ -21,7 +21,7 @@ hid_t HDF5File::virtualfd = 0;
HDF5File::HDF5File(int ind, uint32_t maxf,
HDF5File::HDF5File(int ind, uint32_t* maxf,
int* nd, char* fname, char* fpath, uint64_t* findex, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
uint32_t nx, uint32_t ny,
@ -95,8 +95,7 @@ int HDF5File::CreateFile(uint64_t fnum) {
//first time
if(!fnum) UpdateDataType();
uint64_t framestosave = ((*numImages - fnum) > maxFramesPerFile) ? maxFramesPerFile : (*numImages-fnum);
uint64_t framestosave = ((*numImages - fnum) > (*maxFramesPerFile)) ? (*maxFramesPerFile) : (*numImages-fnum);
pthread_mutex_lock(&Mutex);
if (HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, (*numImages > 1),
fnum, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
@ -137,7 +136,7 @@ void HDF5File::CloseAllFiles() {
int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
if (numFramesInFile >= maxFramesPerFile) {
if (numFramesInFile >= (*maxFramesPerFile)) {
CloseCurrentFile();
CreateFile(fnum);
}
@ -145,12 +144,12 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t
numActualPacketsInFile += nump;
pthread_mutex_lock(&Mutex);
if (HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_detector_header),
fnum%maxFramesPerFile, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
fnum%(*maxFramesPerFile), nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
dataspace, dataset, datatype) == OK) {
sls_detector_header* header = (sls_detector_header*) (buffer);
/*header->xCoord = ((*detIndex) * (*numUnitsPerDetector) + index); */
if (HDF5FileStatic::WriteParameterDatasets(index, dataspace_para,
fnum%maxFramesPerFile,
fnum%(*maxFramesPerFile),
dataset_para, header) == OK) {
pthread_mutex_unlock(&Mutex);
return OK;
@ -220,7 +219,7 @@ int HDF5File::CreateVirtualFile(uint64_t numf) {
virtualfd, masterFileName,
filePath, fileNamePrefix, *fileIndex, (*numImages > 1),
*detIndex, *numUnitsPerDetector,
maxFramesPerFile, numf+1,
*maxFramesPerFile, numf+1,
"data", datatype,
numDetY, numDetX, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
HDF5_WRITER_VERSION);

View File

@ -21,7 +21,7 @@ const string Listener::TypeName = "Listener";
Listener::Listener(int ind, detectorType dtype, Fifo*& f, runStatus* s,
uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr,
uint32_t* us, uint32_t* as) :
uint32_t* us, uint32_t* as, uint32_t* fpf) :
ThreadObject(ind),
runningFlag(0),
generalData(0),
@ -34,6 +34,9 @@ Listener::Listener(int ind, detectorType dtype, Fifo*& f, runStatus* s,
activated(act),
numImages(nf),
dynamicRange(dr),
udpSocketBufferSize(us),
actualUDPSocketBufferSize(as),
framesPerFile(fpf),
acquisitionStartedFlag(false),
measurementStartedFlag(false),
firstAcquisitionIndex(0),
@ -45,9 +48,9 @@ Listener::Listener(int ind, detectorType dtype, Fifo*& f, runStatus* s,
carryOverPacket(0),
listeningPacket(0),
udpSocketAlive(0),
silentMode(false),
udpSocketBufferSize(us),
actualUDPSocketBufferSize(as)
numPacketsStatistic(0),
numFramesStatistic(0),
silentMode(false)
{
if(ThreadObject::CreateThread() == FAIL)
throw std::exception();
@ -335,7 +338,7 @@ void Listener::ThreadExecution() {
//Statistics
if(!silentMode) {
numFramesStatistic++;
if (numFramesStatistic >= generalData->maxFramesPerFile)
if (numFramesStatistic >= *framesPerFile)
PrintFifoStatistics();
}
}

View File

@ -74,6 +74,7 @@ void UDPBaseImplementation::initializeMembers(){
strcpy(fileName,"run");
strcpy(filePath,"");
fileIndex = 0;
framesPerFile = 0;
scanTag = 0;
fileWriteEnable = true;
overwriteEnable = true;
@ -174,6 +175,11 @@ uint64_t UDPBaseImplementation::getFileIndex() const{
return fileIndex;
}
uint32_t UDPBaseImplementation::getFramesPerFile() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return framesPerFile;
}
int UDPBaseImplementation::getScanTag() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return scanTag;
@ -438,6 +444,13 @@ void UDPBaseImplementation::setFileIndex(const uint64_t i){
FILE_LOG(logINFO) << "File Index: " << fileIndex;
}
void UDPBaseImplementation::setFramesPerFile(const uint32_t i){
FILE_LOG(logDEBUG) << __AT__ << " starting";
framesPerFile = i;
FILE_LOG(logINFO) << "Frames per file: " << framesPerFile;
}
//FIXME: needed?
void UDPBaseImplementation::setScanTag(const int i){
FILE_LOG(logDEBUG) << __AT__ << " starting";

View File

@ -112,6 +112,7 @@ int64_t UDPStandardImplementation::getAcquisitionIndex() const {
}
int UDPStandardImplementation::setGapPixelsEnable(const bool b) {
if (gapPixelsEnable != b) {
gapPixelsEnable = b;
@ -151,12 +152,13 @@ void UDPStandardImplementation::setFileFormat(const fileFormat f){
void UDPStandardImplementation::setFileWriteEnable(const bool b){
if (fileWriteEnable != b){
fileWriteEnable = b;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter(fileWriteEnable, (int*)numDet, fileName, filePath, &fileIndex,
&overwriteEnable, &detID, &numThreads, &numberOfFrames, &dynamicRange, &udpPortNum[i], generalData);
dataProcessor[i]->SetupFileWriter(fileWriteEnable, (int*)numDet,
&framesPerFile, fileName, filePath, &fileIndex, &overwriteEnable,
&detID, &numThreads, &numberOfFrames, &dynamicRange, &udpPortNum[i],
generalData);
}
}
@ -181,6 +183,8 @@ int UDPStandardImplementation::setShortFrameEnable(const int i) {
generalData = new ShortGotthardData();
else
generalData = new GotthardData();
framesPerFile = generalData->maxFramesPerFile;
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
if (SetupFifoStructure() == FAIL)
return FAIL;
@ -352,6 +356,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
numThreads = generalData->threadsPerReceiver;
fifoDepth = generalData->defaultFifoDepth;
udpSocketBufferSize = generalData->defaultUdpSocketBufferSize;
framesPerFile = generalData->maxFramesPerFile;
//local network parameters
SetLocalNetworkParameters();
@ -369,7 +374,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
try {
Listener* l = new Listener(i, myDetectorType, fifo[i], &status,
&udpPortNum[i], eth, &activated, &numberOfFrames, &dynamicRange,
&udpSocketBufferSize, &actualUDPSocketBufferSize);
&udpSocketBufferSize, &actualUDPSocketBufferSize, &framesPerFile);
listener.push_back(l);
DataProcessor* p = new DataProcessor(i, fifo[i], &fileFormatType,
@ -409,12 +414,13 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
void UDPStandardImplementation::setDetectorPositionId(const int i){
detID = i;
FILE_LOG(logINFO) << "Detector Position Id:" << detID;
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter(fileWriteEnable, (int*)numDet, fileName, filePath, &fileIndex,
&overwriteEnable, &detID, &numThreads, &numberOfFrames, &dynamicRange, &udpPortNum[i], generalData);
dataProcessor[i]->SetupFileWriter(fileWriteEnable, (int*)numDet,
&framesPerFile, fileName, filePath, &fileIndex, &overwriteEnable,
&detID, &numThreads, &numberOfFrames, &dynamicRange, &udpPortNum[i],
generalData);
}
}

View File

@ -296,6 +296,7 @@ const char* slsReceiverTCPIPInterface::getFunctionName(enum recFuncs func) {
case F_ADDITIONAL_JSON_HEADER: return "F_ADDITIONAL_JSON_HEADER";
case F_RECEIVER_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_UDP_SOCK_BUF_SIZE";
case F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE";
case F_SET_RECEIVER_FRAMES_PER_FILE:return "F_SET_RECEIVER_FRAMES_PER_FILE";
default: return "Unknown Function";
}
@ -348,6 +349,7 @@ int slsReceiverTCPIPInterface::function_table(){
flist[F_ADDITIONAL_JSON_HEADER] = &slsReceiverTCPIPInterface::set_additional_json_header;
flist[F_RECEIVER_UDP_SOCK_BUF_SIZE] = &slsReceiverTCPIPInterface::set_udp_socket_buffer_size;
flist[F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE]= &slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size;
flist[F_SET_RECEIVER_FRAMES_PER_FILE] = &slsReceiverTCPIPInterface::set_frames_per_file;
#ifdef VERYVERBOSE
for (int i = 0; i < NUM_REC_FUNCTIONS ; i++) {
@ -2704,3 +2706,55 @@ int slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size(){
}
int slsReceiverTCPIPInterface::set_frames_per_file() {
ret = OK;
memset(mess, 0, sizeof(mess));
int index = -1;
int retval = -1;
// receive arguments
if (mySock->ReceiveDataOnly(&index,sizeof(index)) < 0 )
return printSocketReadError();
// execute action
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL)
invalidReceiverObject();
else {
// set
if(index >= 0) {
if (mySock->differentClients && lockStatus)
receiverlocked();
else if (receiverBase->getStatus() != IDLE)
receiverNotIdle();
else {
receiverBase->setFramesPerFile(index);
}
}
//get
retval=receiverBase->getFramesPerFile();
if(index >= 0 && retval != index) {
ret = FAIL;
strcpy(mess, "Could not set frames per file\n");
FILE_LOG(logERROR) << mess;
}
}
#endif
#ifdef VERYVERBOSE
FILE_LOG(logDEBUG1) << "frames per file:" << retval;
#endif
if (ret == OK && mySock->differentClients)
ret = FORCE_UPDATE;
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
if (ret == FAIL)
mySock->SendDataOnly(mess,sizeof(mess));
mySock->SendDataOnly(&retval,sizeof(retval));
// return ok/fail
return ret;
}