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

@@ -13,12 +13,15 @@ using namespace std;
FILE* BinaryFile::masterfd = 0;
BinaryFile::BinaryFile(int ind, int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr):
BinaryFile::BinaryFile(int ind, uint32_t maxf, const uint32_t* ppf,
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),
numFramesInFile(0)
numFramesInFile(0),
numActualPacketsInFile(0)
{
#ifdef VERBOSE
PrintMembers();
@@ -41,14 +44,31 @@ slsReceiverDefs::fileFormat BinaryFile::GetFileType() {
int BinaryFile::CreateFile(uint64_t fnum) {
//calculate packet loss
int64_t loss = -1;
if (numFramesInFile)
loss = (numFramesInFile*(*packetsPerFrame)) - numActualPacketsInFile;
numFramesInFile = 0;
numActualPacketsInFile = 0;
currentFileName = BinaryFileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex,
*frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index);
if (BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE) == 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;
}
@@ -62,12 +82,13 @@ void BinaryFile::CloseAllFiles() {
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) {
CloseCurrentFile();
CreateFile(fnum);
}
numFramesInFile++;
numActualPacketsInFile += nump;
if (BinaryFileStatic::WriteDataFile(filefd, buffer, buffersize, fnum) == buffersize)
return OK;
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,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) {
//beginning of every acquisition
numFramesInFile = 0;
numActualPacketsInFile = 0;
if (master && (*detIndex==0)) {
masterFileName = BinaryFileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex);
printf("Master File: %s\n", masterFileName.c_str());

View File

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

View File

@@ -10,9 +10,13 @@
using namespace std;
File::File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex,
bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr):
File::File(int ind, uint32_t maxf, const uint32_t* ppf,
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),
maxFramesPerFile(maxf),
packetsPerFrame(ppf),
numDetX(nd[0]),
numDetY(nd[1]),
fileNamePrefix(fname),
@@ -20,11 +24,12 @@ File::File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex,
fileIndex(findex),
frameIndexEnable(frindexenable),
overWriteEnable(owenable),
maxFramesPerFile(maxf),
detIndex(dindex),
numUnitsPerDetector(nunits),
numImages(nf),
dynamicRange(dr)
dynamicRange(dr),
udpPortNumber(portno)
{
master = index?false:true;
}
@@ -38,28 +43,47 @@ string File::GetCurrentFileName() {
void File::PrintMembers() {
printf("\nGeneral Writer Variables:"
"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 Path: %s\n"
"File Index: %lld\n"
"File Index: %lu\n"
"Frame Index Enable: %d\n"
"Over Write Enable: %d\n"
"Max Frames Per File: %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,
maxFramesPerFile,
*packetsPerFrame,
numDetX,
numDetY,
fileNamePrefix,
filePath,
(long long int)*fileIndex,
*frameIndexEnable,
*overWriteEnable,
maxFramesPerFile,
*fileIndex,
(int)*frameIndexEnable,
(int)*overWriteEnable,
*detIndex,
*numUnitsPerDetector);
*numUnitsPerDetector,
*numImages,
*dynamicRange,
*udpPortNumber,
masterFileName.c_str(),
currentFileName.c_str());
}
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[1] = numDetY;
@@ -72,8 +96,14 @@ void File::GetMemberPointerValues(int* nd, char*& fname, char*& fpath, uint64_t*
nunits = numUnitsPerDetector;
nf = numImages;
dr = dynamicRange;
portno = udpPortNumber;
}
void File::SetMaxFramesPerFile(uint32_t 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,
bool* frindexenable, bool* owenable, uint32_t maxf, int* dindex, int* nunits, uint64_t* nf, uint32_t* dr,
HDF5File::HDF5File(int ind, uint32_t maxf, const uint32_t* ppf,
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):
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),
dataspace(0),
dataset(0),
@@ -30,6 +32,7 @@ HDF5File::HDF5File(int ind, int* nd, char* fname, char* fpath, uint64_t* findex,
nPixelsX(nx),
nPixelsY(ny),
numFramesInFile(0),
numActualPacketsInFile(0),
numFilesinAcquisition(0),
dataspace_para(0)
{
@@ -81,8 +84,15 @@ void HDF5File::UpdateDataType() {
int HDF5File::CreateFile(uint64_t fnum) {
//calculate packet loss
int64_t loss = -1;
if (numFramesInFile)
loss = (numFramesInFile*(*packetsPerFrame)) - numActualPacketsInFile;
numFilesinAcquisition++;
numFramesInFile = 0;
numActualPacketsInFile = 0;
currentFileName = HDF5FileStatic::CreateFileName(filePath, fileNamePrefix, *fileIndex,
*frameIndexEnable, fnum, *detIndex, *numUnitsPerDetector, index);
@@ -102,7 +112,18 @@ int HDF5File::CreateFile(uint64_t fnum) {
pthread_mutex_unlock(&Mutex);
if (dataspace == NULL)
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;
}
@@ -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) {
CloseCurrentFile();
CreateFile(fnum);
}
numFramesInFile++;
numActualPacketsInFile += nump;
pthread_mutex_lock(&Mutex);
if (HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_detector_header),
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,
uint32_t nx, uint32_t ny, uint64_t at, uint64_t ap) {
//beginning of every acquisition
numFramesInFile = 0;
numActualPacketsInFile = 0;
if (master && (*detIndex==0)) {
virtualfd = 0;
masterFileName = HDF5FileStatic::CreateMasterFileName(filePath, fileNamePrefix, *fileIndex);

View File

@@ -405,9 +405,9 @@ void UDPStandardImplementation::setDetectorPositionId(const int i){
detID = i;
FILE_LOG(logINFO) << "Detector Position Id:" << detID;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it) {
(*it)->SetupFileWriter((int*)numDet, fileName, filePath, &fileIndex, &frameIndexEnable,
&overwriteEnable, &detID, &numThreads, &numberOfFrames, &dynamicRange, generalData);
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->SetupFileWriter((int*)numDet, fileName, filePath, &fileIndex, &frameIndexEnable,
&overwriteEnable, &detID, &numThreads, &numberOfFrames, &dynamicRange, &udpPortNum[i], generalData);
}
}
@@ -519,12 +519,12 @@ void UDPStandardImplementation::stopReceiver(){
if (missingpackets) {
cprintf(RED, "\n[Port %d]\n",udpPortNum[i]);
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());
}else{
cprintf(GREEN, "\n[Port %d]\n",udpPortNum[i]);
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());
}
}