print loss

This commit is contained in:
Dhanya Maliakal 2017-05-18 13:59:40 +02:00
parent a276b6b7f5
commit 4aa73c607f
9 changed files with 195 additions and 75 deletions

View File

@ -20,21 +20,24 @@ class BinaryFile : private virtual slsReceiverDefs, public File, public BinaryFi
* Constructor * Constructor
* creates the File Writer * creates the File Writer
* @param ind self index * @param ind self index
* @param maxf max frames per file
* @param ppf packets per frame
* @param nd pointer to number of detectors in each dimension * @param nd pointer to number of detectors in each dimension
* @param fname pointer to file name prefix * @param fname pointer to file name prefix
* @param fpath pointer to file path * @param fpath pointer to file path
* @param findex pointer to file index * @param findex pointer to file index
* @param frindexenable pointer to frame index enable * @param frindexenable pointer to frame index enable
* @param owenable pointer to over write enable * @param owenable pointer to over write enable
* @param maxf max frames per file
* @param dindex pointer to detector index * @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector * @param nunits pointer to number of theads/ units per detector
* @param nf pointer to number of frames * @param nf pointer to number of images in acquisition
* @param dr dynamic range * @param dr pointer to dynamic range
* @param portno pointer to udp port number for logging
*/ */
BinaryFile(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, BinaryFile(int ind, uint32_t maxf, const uint32_t* ppf,
bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, int* nd, char* fname, char* fpath, uint64_t* findex,
uint64_t* nf, uint32_t* dr); bool* frindexenable, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno);
/** /**
* Destructor * Destructor
@ -81,9 +84,10 @@ class BinaryFile : private virtual slsReceiverDefs, public File, public BinaryFi
* @param buffer buffer to write from * @param buffer buffer to write from
* @param buffersize size of buffer * @param buffersize size of buffer
* @param fnum current image number * @param fnum current image number
* @param nump number of packets caught
* @returns OK or FAIL * @returns OK or FAIL
*/ */
int WriteToFile(char* buffer, int buffersize, uint64_t fnum); int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump);
@ -106,5 +110,8 @@ class BinaryFile : private virtual slsReceiverDefs, public File, public BinaryFi
/** Number of frames in file */ /** Number of frames in file */
uint32_t numFramesInFile; uint32_t numFramesInFile;
/** Number of actual packets caught in file */
uint64_t numActualPacketsInFile;
}; };

View File

@ -156,11 +156,12 @@ class DataProcessor : private virtual slsReceiverDefs, public ThreadObject {
* @param dindex pointer to detector index * @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector * @param nunits pointer to number of theads/ units per detector
* @param nf pointer to number of images in acquisition * @param nf pointer to number of images in acquisition
* @param dr dynamic range * @param dr pointer to dynamic range
* @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(int* nd, char* fname, char* fpath, uint64_t* findex, void SetupFileWriter(int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, GeneralData* g = 0); bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno, GeneralData* g = 0);
/** /**

View File

@ -20,20 +20,24 @@ class File : private virtual slsReceiverDefs {
* Constructor * Constructor
* creates the File Writer * creates the File Writer
* @param ind self index * @param ind self index
* @param maxf max frames per file
* @param ppf packets per frame
* @param nd pointer to number of detectors in each dimension * @param nd pointer to number of detectors in each dimension
* @param fname pointer to file name prefix * @param fname pointer to file name prefix
* @param fpath pointer to file path * @param fpath pointer to file path
* @param findex pointer to file index * @param findex pointer to file index
* @param frindexenable pointer to frame index enable * @param frindexenable pointer to frame index enable
* @param owenable pointer to over write enable * @param owenable pointer to over write enable
* @param maxf max frames per file
* @param dindex pointer to detector index * @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector * @param nunits pointer to number of theads/ units per detector
* @param nf pointer to number of images in acquisition * @param nf pointer to number of images in acquisition
* @param dr dynamic range * @param dr pointer to dynamic range
* @param portno pointer to udp port number for logging
*/ */
File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, File(int ind, uint32_t maxf, const uint32_t* ppf,
bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr); int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno);
/** /**
* Destructor * Destructor
@ -68,10 +72,12 @@ class File : private virtual slsReceiverDefs {
* @param dindex pointer to detector index * @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector * @param nunits pointer to number of theads/ units per detector
* @param nf pointer to number of images in acquisition * @param nf pointer to number of images in acquisition
* @param dr dynamic range * @param dr pointer to dynamic range
* @param portno pointer to dynamic range
*/ */
void GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*& findex, void GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*& findex,
bool*& frindexenable, bool*& owenable, int*& dindex, int*& nunits, uint64_t*& nf, uint32_t*& dr); bool*& frindexenable, bool*& owenable,
int*& dindex, int*& nunits, uint64_t*& nf, uint32_t*& dr, uint32_t*& portno);
/** /**
* Set Max frames per file * Set Max frames per file
@ -79,6 +85,12 @@ class File : private virtual slsReceiverDefs {
*/ */
void SetMaxFramesPerFile(uint32_t maxf); void SetMaxFramesPerFile(uint32_t maxf);
/**
* Set Packets per frame (called only for each generalData construction)
* @param ppf pointer to packets per frame
*/
void SetPacketsPerFrame(const uint32_t* ppf);
/** /**
* Create file * Create file
* @param fnum current frame index to include in file name * @param fnum current frame index to include in file name
@ -107,9 +119,10 @@ class File : private virtual slsReceiverDefs {
* Write data to file * Write data to file
* @param buffer buffer to write from * @param buffer buffer to write from
* @param fnum current image number * @param fnum current image number
* @param nump number of packets caught
* @param OK or FAIL * @param OK or FAIL
*/ */
virtual int WriteToFile(char* buffer, int buffersize, uint64_t fnum) { virtual int WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
cprintf(RED,"This is a generic function WriteToFile that should be overloaded by a derived class\n"); cprintf(RED,"This is a generic function WriteToFile that should be overloaded by a derived class\n");
return FAIL; return FAIL;
} }
@ -156,15 +169,25 @@ class File : private virtual slsReceiverDefs {
/** Self Index */ /** Self Index */
int index; int index;
/** Maximum frames per file */
uint32_t maxFramesPerFile;
/** Packets per frame for logging */
//pointer because value in generalData could change
const uint32_t* packetsPerFrame;
/** Master File Name */
std::string masterFileName;
/** Current File Name */
std::string currentFileName;
/** Number of Detectors in X dimension */ /** Number of Detectors in X dimension */
int numDetX; int numDetX;
/** Number of Detectors in Y dimension */ /** Number of Detectors in Y dimension */
int numDetY; int numDetY;
/** Master File Name */
std::string masterFileName;
/** File Name Prefix */ /** File Name Prefix */
char* fileNamePrefix; char* fileNamePrefix;
@ -177,15 +200,9 @@ class File : private virtual slsReceiverDefs {
/** Frame Index */ /** Frame Index */
bool* frameIndexEnable; bool* frameIndexEnable;
/** File Write Enable */
bool* fileWriteEnable;
/** Over write enable */ /** Over write enable */
bool* overWriteEnable; bool* overWriteEnable;
/** Maximum frames per file */
uint32_t maxFramesPerFile;
/** Detector Index */ /** Detector Index */
int* detIndex; int* detIndex;
@ -198,7 +215,8 @@ class File : private virtual slsReceiverDefs {
/** Dynamic Range */ /** Dynamic Range */
uint32_t* dynamicRange; uint32_t* dynamicRange;
/** Current File Name */ /** UDP Port Number for logging */
std::string currentFileName; uint32_t* udpPortNumber;
}; };

View File

@ -26,22 +26,26 @@ class HDF5File : private virtual slsReceiverDefs, public File, public HDF5FileSt
* Constructor * Constructor
* creates the File Writer * creates the File Writer
* @param ind self index * @param ind self index
* @param maxf max frames per file
* @param ppf packets per frame
* @param nd pointer to number of detectors in each dimension * @param nd pointer to number of detectors in each dimension
* @param fname pointer to file name prefix * @param fname pointer to file name prefix
* @param fpath pointer to file path * @param fpath pointer to file path
* @param findex pointer to file index * @param findex pointer to file index
* @param frindexenable pointer to frame index enable * @param frindexenable pointer to frame index enable
* @param owenable pointer to over write enable * @param owenable pointer to over write enable
* @param maxf max frames per file
* @param dindex pointer to detector index * @param dindex pointer to detector index
* @param nunits pointer to number of theads/ units per detector * @param nunits pointer to number of theads/ units per detector
* @param nf pointer to number of frames * @param nf pointer to number of images in acquisition
* @param dr dynamic range * @param dr pointer to dynamic range
* @param portno pointer to udp port number for logging
* @param nx number of pixels in x direction * @param nx number of pixels in x direction
* @param ny number of pixels in y direction * @param ny number of pixels in y direction
*/ */
HDF5File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, HDF5File(int ind, uint32_t maxf, const uint32_t* ppf,
bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
uint32_t nx, uint32_t ny); uint32_t nx, uint32_t ny);
/** /**
@ -83,9 +87,10 @@ class HDF5File : private virtual slsReceiverDefs, public File, public HDF5FileSt
* @param buffer buffer to write from * @param buffer buffer to write from
* @param bsize size of buffer (not used) * @param bsize size of buffer (not used)
* @param fnum current image number * @param fnum current image number
* @param nump number of packets caught
* @returns OK or FAIL * @returns OK or FAIL
*/ */
int WriteToFile(char* buffer, int bsize, uint64_t fnum); int WriteToFile(char* buffer, int bsize, uint64_t fnum, uint32_t nump);
/** /**
* Create master file * Create master file
@ -159,6 +164,9 @@ class HDF5File : private virtual slsReceiverDefs, public File, public HDF5FileSt
/** Number of frames in file */ /** Number of frames in file */
uint32_t numFramesInFile; uint32_t numFramesInFile;
/** Number of actual packets caught in file */
uint64_t numActualPacketsInFile;
/** Number of files in an acquisition - to verify need of virtual file */ /** Number of files in an acquisition - to verify need of virtual file */
int numFilesinAcquisition; int numFilesinAcquisition;

View File

@ -13,12 +13,15 @@ using namespace std;
FILE* BinaryFile::masterfd = 0; FILE* BinaryFile::masterfd = 0;
BinaryFile::BinaryFile(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, BinaryFile::BinaryFile(int ind, uint32_t maxf, const uint32_t* ppf,
bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr): int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno):
File(ind, nd, fname, fpath, findex, frindexenable, owenable, maxf, dindex, nunits, nf, dr), File(ind, maxf, ppf, nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr, portno),
filefd(0), filefd(0),
numFramesInFile(0) numFramesInFile(0),
numActualPacketsInFile(0)
{ {
#ifdef VERBOSE #ifdef VERBOSE
PrintMembers(); PrintMembers();
@ -41,14 +44,31 @@ slsReceiverDefs::fileFormat BinaryFile::GetFileType() {
int BinaryFile::CreateFile(uint64_t fnum) { int BinaryFile::CreateFile(uint64_t fnum) {
//calculate packet loss
int64_t loss = -1;
if (numFramesInFile)
loss = (numFramesInFile*(*packetsPerFrame)) - numActualPacketsInFile;
numFramesInFile = 0; numFramesInFile = 0;
numActualPacketsInFile = 0;
currentFileName = BinaryFileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex, currentFileName = BinaryFileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex,
*frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index); *frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index);
if (BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE) == FAIL) if (BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE) == FAIL)
return FAIL; return FAIL;
printf("%d Binary File created: %s\n", index, currentFileName.c_str()); //first file, print entrire path
if (loss == -1)
printf("[%u]: Binary File created: %s\n", *udpPortNumber, currentFileName.c_str());
//other files
else {
if (loss)
cprintf(RED,"[%u]: Packet_Loss:%lu \tNew_File:%s\n", *udpPortNumber,loss, basename(currentFileName.c_str()));
else
cprintf(GREEN,"[%u]: Packet_Loss:%lu \tNew_File:%s\n", *udpPortNumber,loss, basename(currentFileName.c_str()));
}
return OK; return OK;
} }
@ -62,12 +82,13 @@ void BinaryFile::CloseAllFiles() {
BinaryFileStatic::CloseDataFile(masterfd); BinaryFileStatic::CloseDataFile(masterfd);
} }
int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum) { int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
if (numFramesInFile >= maxFramesPerFile) { if (numFramesInFile >= maxFramesPerFile) {
CloseCurrentFile(); CloseCurrentFile();
CreateFile(fnum); CreateFile(fnum);
} }
numFramesInFile++; numFramesInFile++;
numActualPacketsInFile += nump;
if (BinaryFileStatic::WriteDataFile(filefd, buffer, buffersize, fnum) == buffersize) if (BinaryFileStatic::WriteDataFile(filefd, buffer, buffersize, fnum) == buffersize)
return OK; return OK;
cprintf(RED,"%d Error: Write to file failed for image number %lld\n", index, (long long int)fnum); cprintf(RED,"%d Error: Write to file failed for image number %lld\n", index, (long long int)fnum);
@ -77,6 +98,10 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum) {
int BinaryFile::CreateMasterFile(bool en, uint32_t size, int BinaryFile::CreateMasterFile(bool en, uint32_t size,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) { uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) {
//beginning of every acquisition
numFramesInFile = 0;
numActualPacketsInFile = 0;
if (master && (*detIndex==0)) { if (master && (*detIndex==0)) {
masterFileName = BinaryFileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex); masterFileName = BinaryFileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex);
printf("Master File: %s\n", masterFileName.c_str()); printf("Master File: %s\n", masterFileName.c_str());

View File

@ -178,9 +178,9 @@ void DataProcessor::SetGeneralData(GeneralData* g) {
generalData->Print(); generalData->Print();
#endif #endif
if (file) { if (file) {
if (file->GetFileType() == BINARY) file->SetPacketsPerFrame(&generalData->packetsPerFrame);
file->SetMaxFramesPerFile(generalData->maxFramesPerFile); file->SetMaxFramesPerFile(generalData->maxFramesPerFile);
else if (file->GetFileType() == HDF5) { if (file->GetFileType() == HDF5) {
file->SetNumberofPixels(generalData->nPixelsX, generalData->nPixelsY); file->SetNumberofPixels(generalData->nPixelsX, generalData->nPixelsY);
} }
} }
@ -202,17 +202,18 @@ void DataProcessor::SetFileFormat(const fileFormat f) {
//remember the pointer values before they are destroyed //remember the pointer values before they are destroyed
int nd[MAX_DIMENSIONS];nd[0] = 0; nd[1] = 0; int nd[MAX_DIMENSIONS];nd[0] = 0; nd[1] = 0;
char* fname=0; char* fpath=0; uint64_t* findex=0; bool* frindexenable=0; char* fname=0; char* fpath=0; uint64_t* findex=0; bool* frindexenable=0;
bool* owenable=0; int* dindex=0; int* nunits=0; uint64_t* nf = 0; uint32_t* dr = 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, frindexenable, owenable, dindex, nunits, nf, dr); file->GetMemberPointerValues(nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr, port);
//create file writer with same pointers //create file writer with same pointers
SetupFileWriter(nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr); SetupFileWriter(nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr, port);
} }
} }
void DataProcessor::SetupFileWriter(int* nd, char* fname, char* fpath, uint64_t* findex, void DataProcessor::SetupFileWriter(int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, GeneralData* g) bool* frindexenable, bool* owenable, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
GeneralData* g)
{ {
if (g) if (g)
generalData = g; generalData = g;
@ -223,14 +224,18 @@ void DataProcessor::SetupFileWriter(int* nd, char* fname, char* fpath, uint64_t*
switch(*fileFormatType){ switch(*fileFormatType){
#ifdef HDF5C #ifdef HDF5C
case HDF5: case HDF5:
file = new HDF5File(index, nd, fname, fpath, findex, file = new HDF5File(index, generalData->maxFramesPerFile, &generalData->packetsPerFrame,
frindexenable, owenable, generalData->maxFramesPerFile, dindex, nunits, nf, dr, nd, fname, fpath, findex,
frindexenable, owenable,
dindex, nunits, nf, dr, portno
generalData->nPixelsX, generalData->nPixelsY); generalData->nPixelsX, generalData->nPixelsY);
break; break;
#endif #endif
default: default:
file = new BinaryFile(index, nd, fname, fpath, findex, file = new BinaryFile(index, generalData->maxFramesPerFile, &generalData->packetsPerFrame,
frindexenable, owenable, generalData->maxFramesPerFile, dindex, nunits, nf, dr); nd, fname, fpath, findex,
frindexenable, owenable,
dindex, nunits, nf, dr, portno);
break; break;
} }
} }
@ -323,7 +328,7 @@ void DataProcessor::ProcessAnImage(char* buf) {
if (*fileWriteEnable) if (*fileWriteEnable)
file->WriteToFile(buf, generalData->fifoBufferSize + sizeof(sls_detector_header), fnum-firstMeasurementIndex); file->WriteToFile(buf, generalData->fifoBufferSize + sizeof(sls_detector_header), fnum-firstMeasurementIndex, nump);
if (rawDataReadyCallBack) { if (rawDataReadyCallBack) {
rawDataReadyCallBack( rawDataReadyCallBack(

View File

@ -10,9 +10,13 @@
using namespace std; using namespace std;
File::File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, File::File(int ind, uint32_t maxf, const uint32_t* ppf,
bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr): int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno):
index(ind), index(ind),
maxFramesPerFile(maxf),
packetsPerFrame(ppf),
numDetX(nd[0]), numDetX(nd[0]),
numDetY(nd[1]), numDetY(nd[1]),
fileNamePrefix(fname), fileNamePrefix(fname),
@ -20,11 +24,12 @@ File::File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex,
fileIndex(findex), fileIndex(findex),
frameIndexEnable(frindexenable), frameIndexEnable(frindexenable),
overWriteEnable(owenable), overWriteEnable(owenable),
maxFramesPerFile(maxf),
detIndex(dindex), detIndex(dindex),
numUnitsPerDetector(nunits), numUnitsPerDetector(nunits),
numImages(nf), numImages(nf),
dynamicRange(dr) dynamicRange(dr),
udpPortNumber(portno)
{ {
master = index?false:true; master = index?false:true;
} }
@ -38,28 +43,47 @@ string File::GetCurrentFileName() {
void File::PrintMembers() { void File::PrintMembers() {
printf("\nGeneral Writer Variables:" printf("\nGeneral Writer Variables:"
"Index: %d\n" "Index: %d\n"
"Max Frames Per File: %u\n"
"Packets per Frame: %u\n"
"Number of Detectors in x dir: %d\n"
"Number of Detectors in y dir: %d\n"
"File Name Prefix: %s\n" "File Name Prefix: %s\n"
"File Path: %s\n" "File Path: %s\n"
"File Index: %lld\n" "File Index: %lu\n"
"Frame Index Enable: %d\n" "Frame Index Enable: %d\n"
"Over Write Enable: %d\n" "Over Write Enable: %d\n"
"Max Frames Per File: %d\n"
"Detector Index: %d\n" "Detector Index: %d\n"
"Number of Units Per Detector: %d\n", "Number of Units Per Detector: %d\n"
"Number of Images in Acquisition: %lu\n"
"Dynamic Range: %u\n"
"UDP Port number: %u\n"
"Master File Name: %s\n"
"Current File Name: %s\n",
index, index,
maxFramesPerFile,
*packetsPerFrame,
numDetX,
numDetY,
fileNamePrefix, fileNamePrefix,
filePath, filePath,
(long long int)*fileIndex, *fileIndex,
*frameIndexEnable, (int)*frameIndexEnable,
*overWriteEnable, (int)*overWriteEnable,
maxFramesPerFile,
*detIndex, *detIndex,
*numUnitsPerDetector); *numUnitsPerDetector,
*numImages,
*dynamicRange,
*udpPortNumber,
masterFileName.c_str(),
currentFileName.c_str());
} }
void File::GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*& findex, void File::GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*& findex,
bool*& frindexenable, bool*& owenable, int*& dindex, int*& nunits, uint64_t*& nf, uint32_t*& dr) bool*& frindexenable, bool*& owenable,
int*& dindex, int*& nunits, uint64_t*& nf, uint32_t*& dr, uint32_t*& portno)
{ {
nd[0] = numDetX; nd[0] = numDetX;
nd[1] = numDetY; nd[1] = numDetY;
@ -72,8 +96,14 @@ void File::GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*
nunits = numUnitsPerDetector; nunits = numUnitsPerDetector;
nf = numImages; nf = numImages;
dr = dynamicRange; dr = dynamicRange;
portno = udpPortNumber;
} }
void File::SetMaxFramesPerFile(uint32_t maxf) { void File::SetMaxFramesPerFile(uint32_t maxf) {
maxFramesPerFile = maxf; maxFramesPerFile = maxf;
} }
void File::SetPacketsPerFrame(const uint32_t* ppf) {
packetsPerFrame = ppf;
}

View File

@ -18,11 +18,13 @@ hid_t HDF5File::virtualfd = 0;
HDF5File::HDF5File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex, HDF5File::HDF5File(int ind, uint32_t maxf, const uint32_t* ppf,
bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable,
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
uint32_t nx, uint32_t ny): uint32_t nx, uint32_t ny):
File(ind, nd, fname, fpath, findex, frindexenable, owenable, maxf, dindex, nunits, nf, dr), File(ind, maxf, ppf, nd, fname, fpath, findex, frindexenable, owenable, dindex, nunits, nf, dr, portno),
filefd(0), filefd(0),
dataspace(0), dataspace(0),
dataset(0), dataset(0),
@ -30,6 +32,7 @@ HDF5File::HDF5File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex,
nPixelsX(nx), nPixelsX(nx),
nPixelsY(ny), nPixelsY(ny),
numFramesInFile(0), numFramesInFile(0),
numActualPacketsInFile(0),
numFilesinAcquisition(0), numFilesinAcquisition(0),
dataspace_para(0) dataspace_para(0)
{ {
@ -81,8 +84,15 @@ void HDF5File::UpdateDataType() {
int HDF5File::CreateFile(uint64_t fnum) { int HDF5File::CreateFile(uint64_t fnum) {
//calculate packet loss
int64_t loss = -1;
if (numFramesInFile)
loss = (numFramesInFile*(*packetsPerFrame)) - numActualPacketsInFile;
numFilesinAcquisition++; numFilesinAcquisition++;
numFramesInFile = 0; numFramesInFile = 0;
numActualPacketsInFile = 0;
currentFileName = HDF5FileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex, currentFileName = HDF5FileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex,
*frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index); *frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index);
@ -102,7 +112,18 @@ int HDF5File::CreateFile(uint64_t fnum) {
pthread_mutex_unlock(&Mutex); pthread_mutex_unlock(&Mutex);
if (dataspace == NULL) if (dataspace == NULL)
cprintf(RED,"Got nothing!\n"); cprintf(RED,"Got nothing!\n");
printf("%d HDF5 File: %s\n", index, currentFileName.c_str());
//first file, print entrire path
if (loss == -1)
printf("[%u]: HDF5 File created: %s\n", *udpPortNumber, currentFileName.c_str());
//other files
else {
if (loss)
cprintf(RED,"[%u]: Packet_Loss:%lu \tNew_File:%s\n", *udpPortNumber,loss, basename(currentFileName.c_str()));
else
cprintf(GREEN,"[%u]: Packet_Loss:%lu \tNew_File:%s\n", *udpPortNumber,loss, basename(currentFileName.c_str()));
}
return OK; return OK;
} }
@ -126,13 +147,13 @@ void HDF5File::CloseAllFiles() {
} }
int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum) { int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
if (numFramesInFile >= maxFramesPerFile) { if (numFramesInFile >= maxFramesPerFile) {
CloseCurrentFile(); CloseCurrentFile();
CreateFile(fnum); CreateFile(fnum);
} }
numFramesInFile++; numFramesInFile++;
numActualPacketsInFile += nump;
pthread_mutex_lock(&Mutex); pthread_mutex_lock(&Mutex);
if (HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_detector_header), 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),
@ -154,6 +175,11 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum) {
int HDF5File::CreateMasterFile(bool en, uint32_t size, int HDF5File::CreateMasterFile(bool en, uint32_t size,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) { uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) {
//beginning of every acquisition
numFramesInFile = 0;
numActualPacketsInFile = 0;
if (master && (*detIndex==0)) { if (master && (*detIndex==0)) {
virtualfd = 0; virtualfd = 0;
masterFileName = HDF5FileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex); masterFileName = HDF5FileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex);

View File

@ -405,9 +405,9 @@ void UDPStandardImplementation::setDetectorPositionId(const int i){
detID = i; detID = i;
FILE_LOG(logINFO) << "Detector Position Id:" << detID; FILE_LOG(logINFO) << "Detector Position Id:" << detID;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) { for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
(*it)->SetupFileWriter((int*)numDet, fileName, filePath, &fileIndex, &frameIndexEnable, dataProcessor[i]->SetupFileWriter((int*)numDet, fileName, filePath, &fileIndex, &frameIndexEnable,
&overwriteEnable, &detID, &numThreads, &numberOfFrames, &dynamicRange, generalData); &overwriteEnable, &detID, &numThreads, &numberOfFrames, &dynamicRange, &udpPortNum[i], generalData);
} }
} }
@ -519,12 +519,12 @@ void UDPStandardImplementation::stopReceiver(){
if (missingpackets) { if (missingpackets) {
cprintf(RED, "\n[Port %d]\n",udpPortNum[i]); cprintf(RED, "\n[Port %d]\n",udpPortNum[i]);
cprintf(RED, "Missing Packets\t\t: %lld\n",(long long int)missingpackets); cprintf(RED, "Missing Packets\t\t: %lld\n",(long long int)missingpackets);
cprintf(RED, "Complete Frames\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught()); cprintf(RED, "Complete Frames\t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught());
cprintf(RED, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught()); cprintf(RED, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught());
}else{ }else{
cprintf(GREEN, "\n[Port %d]\n",udpPortNum[i]); cprintf(GREEN, "\n[Port %d]\n",udpPortNum[i]);
cprintf(GREEN, "Missing Packets\t\t: %lld\n",(long long int)missingpackets); cprintf(GREEN, "Missing Packets\t\t: %lld\n",(long long int)missingpackets);
cprintf(GREEN, "Complete Frames\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught()); cprintf(GREEN, "Complete Frames\t\t: %lld\n",(long long int)dataProcessor[i]->GetNumFramesCaught());
cprintf(GREEN, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught()); cprintf(GREEN, "Last Frame Caught\t: %lld\n",(long long int)listener[i]->GetLastFrameIndexCaught());
} }
} }