mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 21:07:13 +02:00
rxr: removed return ok or fail and replaced with exceptions
This commit is contained in:
@ -42,20 +42,18 @@ slsDetectorDefs::fileFormat BinaryFile::GetFileType() {
|
||||
}
|
||||
|
||||
|
||||
int BinaryFile::CreateFile() {
|
||||
void BinaryFile::CreateFile() {
|
||||
numFramesInFile = 0;
|
||||
numActualPacketsInFile = 0;
|
||||
|
||||
currentFileName = BinaryFileStatic::CreateFileName(*filePath, *fileNamePrefix, *fileIndex,
|
||||
subFileIndex, *detIndex, *numUnitsPerDetector, index);
|
||||
|
||||
if (BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE) == FAIL)
|
||||
return FAIL;
|
||||
BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName, FILE_BUFFER_SIZE);
|
||||
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << "[" << *udpPortNumber << "]: Binary File created: " << currentFileName;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
void BinaryFile::CloseCurrentFile() {
|
||||
@ -68,7 +66,7 @@ void BinaryFile::CloseAllFiles() {
|
||||
BinaryFileStatic::CloseDataFile(masterfd);
|
||||
}
|
||||
|
||||
int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||
void BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||
// check if maxframesperfile = 0 for infinite
|
||||
if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) {
|
||||
CloseCurrentFile();
|
||||
@ -107,14 +105,12 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_
|
||||
|
||||
// if write error
|
||||
if (ret != buffersize) {
|
||||
FILE_LOG(logERROR) << index << " Error: Write to file failed for image number " << fnum;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError(std::to_string(index) + " : Write to file failed for image number " + std::to_string(fnum));
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
void BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
//beginning of every acquisition
|
||||
numFramesInFile = 0;
|
||||
numActualPacketsInFile = 0;
|
||||
@ -126,10 +122,9 @@ int BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
FILE_LOG(logINFO) << "Master File: " << masterFileName;
|
||||
}
|
||||
attr.version = BINARY_WRITER_VERSION;
|
||||
return BinaryFileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
BinaryFileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
*overWriteEnable, attr);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -268,7 +268,7 @@ void ClientInterface::VerifyLock() {
|
||||
void ClientInterface::VerifyIdle(Interface &socket) {
|
||||
if (impl()->getStatus() != IDLE) {
|
||||
std::ostringstream oss;
|
||||
oss << "Can not execute " << getFunctionNameFromEnum((enum detFuncs)fnum)
|
||||
oss << "Can not execute " << GetFunctionNameFromEnum((enum detFuncs)fnum)
|
||||
<< " when receiver is not idle";
|
||||
throw sls::SocketError(oss.str());
|
||||
}
|
||||
@ -286,7 +286,7 @@ int ClientInterface::exec_command(Interface &socket) {
|
||||
if (!pipe) {
|
||||
throw RuntimeError("Executing Command failed\n");
|
||||
} else {
|
||||
while (!feof(pipe.get())) {
|
||||
while (!feof(pipe.Get())) {
|
||||
if (fgets(temp.data(), tempsize, pipe.get()) != nullptr)
|
||||
sresult += temp.data();
|
||||
}
|
||||
@ -473,11 +473,11 @@ int ClientInterface::set_detector_type(Interface &socket) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (receiver == nullptr) {
|
||||
receiver = sls::make_unique<Implementation>();
|
||||
}
|
||||
myDetectorType = arg;
|
||||
if (impl()->setDetectorType(myDetectorType) == FAIL) {
|
||||
try {
|
||||
myDetectorType = GENERIC;
|
||||
receiver = sls::make_unique<Implementation>(arg);
|
||||
myDetectorType = arg;
|
||||
} catch (...) {
|
||||
throw RuntimeError("Could not set detector type");
|
||||
}
|
||||
|
||||
@ -525,8 +525,11 @@ int ClientInterface::set_roi(Interface &socket) {
|
||||
functionNotImplemented();
|
||||
|
||||
VerifyIdle(socket);
|
||||
if (impl()->setROI(arg) == FAIL)
|
||||
try {
|
||||
impl()->setROI(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set ROI");
|
||||
}
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
@ -543,7 +546,11 @@ int ClientInterface::set_num_analog_samples(Interface &socket) {
|
||||
if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) {
|
||||
functionNotImplemented();
|
||||
}
|
||||
ret = impl()->setNumberofAnalogSamples(value);
|
||||
try {
|
||||
impl()->setNumberofAnalogSamples(value);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set num analog samples to " + std::to_string(value) + " due to fifo structure memory allocation.");
|
||||
}
|
||||
|
||||
return socket.Send(OK);
|
||||
}
|
||||
@ -554,7 +561,11 @@ int ClientInterface::set_num_digital_samples(Interface &socket) {
|
||||
if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) {
|
||||
functionNotImplemented();
|
||||
}
|
||||
ret = impl()->setNumberofDigitalSamples(value);
|
||||
try {
|
||||
impl()->setNumberofDigitalSamples(value);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set num digital samples to " + std::to_string(value) + " due to fifo structure memory allocation.");
|
||||
}
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
@ -613,8 +624,9 @@ int ClientInterface::set_dynamic_range(Interface &socket) {
|
||||
if (!exists) {
|
||||
modeNotImplemented("Dynamic range", dr);
|
||||
} else {
|
||||
ret = impl()->setDynamicRange(dr);
|
||||
if (ret == FAIL) {
|
||||
try {
|
||||
impl()->setDynamicRange(dr);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not allocate memory for fifo or "
|
||||
"could not start listening/writing threads");
|
||||
}
|
||||
@ -631,10 +643,7 @@ int ClientInterface::set_streaming_frequency(Interface &socket) {
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting streaming frequency: " << index;
|
||||
ret = impl()->setStreamingFrequency(index);
|
||||
if (ret == FAIL) {
|
||||
throw RuntimeError("Could not allocate memory for listening fifo");
|
||||
}
|
||||
impl()->setStreamingFrequency(index);
|
||||
}
|
||||
int retval = impl()->getStreamingFrequency();
|
||||
validate(index, retval, "set streaming frequency", DEC);
|
||||
@ -650,11 +659,7 @@ int ClientInterface::get_status(Interface &socket) {
|
||||
int ClientInterface::start_receiver(Interface &socket) {
|
||||
if (impl()->getStatus() == IDLE) {
|
||||
FILE_LOG(logDEBUG1) << "Starting Receiver";
|
||||
std::string err;
|
||||
ret = impl()->startReceiver(err);
|
||||
if (ret == FAIL) {
|
||||
throw RuntimeError(err);
|
||||
}
|
||||
impl()->startReceiver();
|
||||
}
|
||||
return socket.Send(OK);
|
||||
}
|
||||
@ -797,7 +802,11 @@ int ClientInterface::enable_tengiga(Interface &socket) {
|
||||
if (val >= 0) {
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting 10GbE:" << val;
|
||||
ret = impl()->setTenGigaEnable(val);
|
||||
try {
|
||||
impl()->setTenGigaEnable(val);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set 10GbE.");
|
||||
}
|
||||
}
|
||||
int retval = impl()->getTenGigaEnable();
|
||||
validate(val, retval, "set 10GbE", DEC);
|
||||
@ -810,7 +819,11 @@ int ClientInterface::set_fifo_depth(Interface &socket) {
|
||||
if (value >= 0) {
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting fifo depth:" << value;
|
||||
impl()->setFifoDepth(value);
|
||||
try {
|
||||
impl()->setFifoDepth(value);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set fifo depth due to fifo structure memory allocation.");
|
||||
}
|
||||
}
|
||||
int retval = impl()->getFifoDepth();
|
||||
validate(value, retval, std::string("set fifo depth"), DEC);
|
||||
@ -839,7 +852,11 @@ int ClientInterface::set_data_stream_enable(Interface &socket) {
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting data stream enable:" << index;
|
||||
impl()->setDataStreamEnable(index);
|
||||
try {
|
||||
impl()->setDataStreamEnable(index);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set data stream enable to " + std::to_string(index));
|
||||
}
|
||||
}
|
||||
auto retval = static_cast<int>(impl()->getDataStreamEnable());
|
||||
validate(index, retval, "set data stream enable", DEC);
|
||||
@ -969,7 +986,11 @@ int ClientInterface::enable_gap_pixels(Interface &socket) {
|
||||
if (enable >= 0) {
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting gap pixels enable:" << enable;
|
||||
impl()->setGapPixelsEnable(static_cast<bool>(enable));
|
||||
try {
|
||||
impl()->setGapPixelsEnable(static_cast<bool>(enable));
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set gap pixels enable to " + std::to_string(enable));
|
||||
}
|
||||
}
|
||||
auto retval = static_cast<int>(impl()->getGapPixelsEnable());
|
||||
validate(enable, retval, "set gap pixels enable", DEC);
|
||||
@ -1013,10 +1034,7 @@ int ClientInterface::set_udp_socket_buffer_size(Interface &socket) {
|
||||
if (index >= 0) {
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting UDP Socket Buffer size: " << index;
|
||||
if (impl()->setUDPSocketBufferSize(index) == FAIL) {
|
||||
throw RuntimeError(
|
||||
"Could not create dummy UDP Socket to test buffer size");
|
||||
}
|
||||
impl()->setUDPSocketBufferSize(index);
|
||||
}
|
||||
int64_t retval = impl()->getUDPSocketBufferSize();
|
||||
if (index != 0)
|
||||
@ -1127,7 +1145,11 @@ int ClientInterface::set_readout_mode(Interface &socket) {
|
||||
if (arg >= 0) {
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting readout mode: " << arg;
|
||||
impl()->setReadoutMode(arg);
|
||||
try {
|
||||
impl()->setReadoutMode(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set read out mode due to fifo memory allocation.");
|
||||
}
|
||||
}
|
||||
auto retval = impl()->getReadoutMode();
|
||||
validate(static_cast<int>(arg), static_cast<int>(retval),
|
||||
@ -1140,7 +1162,11 @@ int ClientInterface::set_adc_mask(Interface &socket) {
|
||||
auto arg = socket.Receive<uint32_t>();
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting 1Gb ADC enable mask: " << arg;
|
||||
impl()->setADCEnableMask(arg);
|
||||
try {
|
||||
impl()->setADCEnableMask(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set adc enable mask due to fifo memory allcoation");
|
||||
}
|
||||
auto retval = impl()->getADCEnableMask();
|
||||
if (retval != arg) {
|
||||
std::ostringstream os;
|
||||
@ -1190,10 +1216,11 @@ int ClientInterface::set_quad_type(Interface &socket) {
|
||||
if (quadEnable >= 0) {
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting quad:" << quadEnable;
|
||||
ret = impl()->setQuad(quadEnable == 0 ? false : true);
|
||||
if (ret == FAIL) {
|
||||
throw RuntimeError("Could not set Quad due to fifo structure");
|
||||
}
|
||||
try {
|
||||
impl()->setQuad(quadEnable == 0 ? false : true);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set quad to " + std::to_string(quadEnable) + " due to fifo strucutre memory allocation");
|
||||
}
|
||||
}
|
||||
int retval = impl()->getQuad() ? 1 : 0;
|
||||
validate(quadEnable, retval, "set quad", DEC);
|
||||
@ -1296,8 +1323,10 @@ int ClientInterface::set_num_interfaces(Interface &socket) {
|
||||
throw RuntimeError("Number of interfaces not implemented for this detector");
|
||||
}
|
||||
FILE_LOG(logDEBUG1) << "Setting Number of UDP Interfaces:" << arg;
|
||||
if (impl()->setNumberofUDPInterfaces(arg) == FAIL) {
|
||||
throw RuntimeError("Failed to set number of interfaces");
|
||||
try {
|
||||
impl()->setNumberofUDPInterfaces(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Failed to set number of interfaces to " + std::to_string(arg));
|
||||
}
|
||||
return socket.Send(OK);
|
||||
}
|
||||
@ -1306,7 +1335,11 @@ int ClientInterface::set_adc_mask_10g(Interface &socket) {
|
||||
auto arg = socket.Receive<uint32_t>();
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting 10Gb ADC enable mask: " << arg;
|
||||
impl()->setTenGigaADCEnableMask(arg);
|
||||
try {
|
||||
impl()->setTenGigaADCEnableMask(arg);
|
||||
} catch(const RuntimeError &e) {
|
||||
throw RuntimeError("Could not set 10Gb adc enable mask due to fifo memory allcoation");
|
||||
}
|
||||
auto retval = impl()->getTenGigaADCEnableMask();
|
||||
if (retval != arg) {
|
||||
std::ostringstream os;
|
||||
|
@ -62,11 +62,8 @@ DataProcessor::DataProcessor(int ind, detectorType dtype, Fifo* f,
|
||||
rawDataModifyReadyCallBack(nullptr),
|
||||
pRawDataReady(nullptr)
|
||||
{
|
||||
if(ThreadObject::CreateThread() == FAIL)
|
||||
throw sls::RuntimeError("Could not create processing thread");
|
||||
|
||||
ThreadObject::CreateThread();
|
||||
FILE_LOG(logDEBUG) << "DataProcessor " << ind << " created";
|
||||
|
||||
memset((void*)&timerBegin, 0, sizeof(timespec));
|
||||
}
|
||||
|
||||
@ -158,13 +155,14 @@ void DataProcessor::SetGeneralData(GeneralData* g) {
|
||||
}
|
||||
|
||||
|
||||
int DataProcessor::SetThreadPriority(int priority) {
|
||||
void DataProcessor::SetThreadPriority(int priority) {
|
||||
struct sched_param param;
|
||||
param.sched_priority = priority;
|
||||
if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) == EPERM)
|
||||
return FAIL;
|
||||
if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) == EPERM) {
|
||||
throw sls::RuntimeError("Could not prioritize dataprocessing threads. "
|
||||
"(No Root Privileges?)");
|
||||
}
|
||||
FILE_LOG(logINFO) << "Processor Thread Priority set to " << priority;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@ -220,16 +218,14 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, uint32_t* maxf,
|
||||
}
|
||||
|
||||
// only the first file
|
||||
int DataProcessor::CreateNewFile(masterAttributes& attr) {
|
||||
if (file == nullptr)
|
||||
return FAIL;
|
||||
void DataProcessor::CreateNewFile(masterAttributes& attr) {
|
||||
if (file == nullptr) {
|
||||
throw sls::RuntimeError("file object not contstructed");
|
||||
}
|
||||
file->CloseAllFiles();
|
||||
file->resetSubFileIndex();
|
||||
if (file->CreateMasterFile(*masterFileWriteEnable, attr) == FAIL)
|
||||
return FAIL;
|
||||
if (file->CreateFile() == FAIL)
|
||||
return FAIL;
|
||||
return OK;
|
||||
file->CreateMasterFile(*masterFileWriteEnable, attr);
|
||||
file->CreateFile();
|
||||
}
|
||||
|
||||
|
||||
@ -240,7 +236,11 @@ void DataProcessor::CloseFiles() {
|
||||
|
||||
void DataProcessor::EndofAcquisition(bool anyPacketsCaught, uint64_t numf) {
|
||||
if ((file != nullptr) && file->GetFileType() == HDF5) {
|
||||
file->EndofAcquisition(anyPacketsCaught, numf);
|
||||
try {
|
||||
file->EndofAcquisition(anyPacketsCaught, numf);
|
||||
} catch (const sls::RuntimeError &e) {
|
||||
;// ignore for now //TODO: send error to client via stop receiver
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,10 +352,15 @@ void DataProcessor::ProcessAnImage(char* buf) {
|
||||
|
||||
|
||||
// write to file
|
||||
if (file != nullptr)
|
||||
file->WriteToFile(buf + FIFO_HEADER_NUMBYTES,
|
||||
sizeof(sls_receiver_header) + (uint32_t)(*((uint32_t*)buf)), //+ size of data (resizable from previous call back
|
||||
fnum-firstIndex, nump);
|
||||
if (file != nullptr) {
|
||||
try {
|
||||
file->WriteToFile(buf + FIFO_HEADER_NUMBYTES,
|
||||
sizeof(sls_receiver_header) + (uint32_t)(*((uint32_t*)buf)), //+ size of data (resizable from previous call back
|
||||
fnum-firstIndex, nump);
|
||||
} catch(const sls::RuntimeError &e) {
|
||||
; //ignore write exception for now (TODO: send error message via stopReceiver tcp)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,12 +38,8 @@ DataStreamer::DataStreamer(int ind, Fifo* f, uint32_t* dr, ROI* r,
|
||||
numDet[0] = nd[0];
|
||||
numDet[1] = nd[1];
|
||||
|
||||
if(ThreadObject::CreateThread() == FAIL)
|
||||
throw sls::RuntimeError("Could not create streaming thread");
|
||||
|
||||
ThreadObject::CreateThread();
|
||||
FILE_LOG(logDEBUG) << "DataStreamer " << ind << " created";
|
||||
|
||||
// memset(fileNametoStream, 0, MAX_STR_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
@ -82,7 +78,6 @@ void DataStreamer::ResetParametersforNewAcquisition(const std::string& fname){
|
||||
startedFlag = false;
|
||||
firstIndex = 0;
|
||||
|
||||
// strcpy(fileNametoStream, fname);
|
||||
fileNametoStream = fname;
|
||||
if (completeBuffer) {
|
||||
delete[] completeBuffer;
|
||||
@ -109,13 +104,14 @@ void DataStreamer::SetGeneralData(GeneralData* g) {
|
||||
generalData->Print();
|
||||
}
|
||||
|
||||
int DataStreamer::SetThreadPriority(int priority) {
|
||||
void DataStreamer::SetThreadPriority(int priority) {
|
||||
struct sched_param param;
|
||||
param.sched_priority = priority;
|
||||
if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) == EPERM)
|
||||
return FAIL;
|
||||
if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) == EPERM) {
|
||||
throw sls::RuntimeError("Could not prioritize datastreaming threads. "
|
||||
"(No Root Privileges?)");
|
||||
}
|
||||
FILE_LOG(logINFO) << "Streamer Thread Priority set to " << priority;
|
||||
return OK;
|
||||
}
|
||||
|
||||
void DataStreamer::SetNumberofDetectors(int* nd) {
|
||||
@ -258,14 +254,12 @@ int DataStreamer::SendHeader(sls_receiver_header* rheader, uint32_t size, uint32
|
||||
|
||||
|
||||
|
||||
int DataStreamer::RestreamStop() {
|
||||
void DataStreamer::RestreamStop() {
|
||||
//send dummy header
|
||||
int ret = zmqSocket->SendHeaderData(index, true, SLS_DETECTOR_JSON_HEADER_VERSION);
|
||||
if (!ret) {
|
||||
FILE_LOG(logERROR) << "Could not Restream Dummy Header via ZMQ for port " << zmqSocket->GetPortNumber();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not restream Dummy Header via ZMQ for port " + std::to_string(zmqSocket->GetPortNumber()));
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,8 +23,7 @@ Fifo::Fifo(int ind, uint32_t fifoItemSize, uint32_t depth):
|
||||
status_fifoBound(0),
|
||||
status_fifoFree(depth){
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
if(CreateFifos(fifoItemSize) == FAIL)
|
||||
throw sls::RuntimeError("Could not create FIFO");
|
||||
CreateFifos(fifoItemSize);
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +34,7 @@ Fifo::~Fifo() {
|
||||
|
||||
|
||||
|
||||
int Fifo::CreateFifos(uint32_t fifoItemSize) {
|
||||
void Fifo::CreateFifos(uint32_t fifoItemSize) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
//destroy if not already
|
||||
@ -49,8 +48,7 @@ int Fifo::CreateFifos(uint32_t fifoItemSize) {
|
||||
size_t mem_len = fifoItemSize * fifoDepth * sizeof(char);
|
||||
memory = (char*) malloc (mem_len);
|
||||
if (memory == nullptr){
|
||||
FILE_LOG(logERROR) << "Could not allocate memory for fifos";
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not allocate memory for fifos");
|
||||
}
|
||||
memset(memory, 0, mem_len);
|
||||
FILE_LOG(logDEBUG) << "Memory Allocated " << index << ": " << mem_len << " bytes";
|
||||
@ -64,7 +62,6 @@ int Fifo::CreateFifos(uint32_t fifoItemSize) {
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFO) << "Fifo " << index << " reconstructed Depth (rx_fifodepth): " << fifoFree->getDataValue();
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -128,7 +128,7 @@ void HDF5File::UpdateDataType() {
|
||||
}
|
||||
|
||||
|
||||
int HDF5File::CreateFile() {
|
||||
void HDF5File::CreateFile() {
|
||||
numFilesinAcquisition++;
|
||||
numFramesInFile = 0;
|
||||
numActualPacketsInFile = 0;
|
||||
@ -143,21 +143,22 @@ int HDF5File::CreateFile() {
|
||||
(((extNumImages - subFileIndex) > (*maxFramesPerFile)) ? // save up to maximum at a time
|
||||
(*maxFramesPerFile) : (extNumImages-subFileIndex)));
|
||||
pthread_mutex_lock(&Mutex);
|
||||
if (HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, (*numImages > 1),
|
||||
try{
|
||||
HDF5FileStatic::CreateDataFile(index, *overWriteEnable, currentFileName, (*numImages > 1),
|
||||
subFileIndex, framestosave, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||
datatype, filefd, dataspace, dataset,
|
||||
HDF5_WRITER_VERSION, MAX_CHUNKED_IMAGES,
|
||||
dataspace_para, dataset_para,
|
||||
parameterNames, parameterDataTypes) == FAIL) {
|
||||
parameterNames, parameterDataTypes);
|
||||
} catch(const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return FAIL;
|
||||
throw;
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << *udpPortNumber << ": HDF5 File created: " << currentFileName;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@ -195,7 +196,7 @@ void HDF5File::CloseAllFiles() {
|
||||
}
|
||||
|
||||
|
||||
int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||
void HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||
|
||||
// check if maxframesperfile = 0 for infinite
|
||||
if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) {
|
||||
@ -207,40 +208,38 @@ int HDF5File::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t
|
||||
numActualPacketsInFile += nump;
|
||||
pthread_mutex_lock(&Mutex);
|
||||
|
||||
try {
|
||||
// extend dataset (when receiver start followed by many status starts (jungfrau)))
|
||||
if (fnum >= extNumImages) {
|
||||
if (HDF5FileStatic::ExtendDataset(index, dataspace, dataset,
|
||||
dataspace_para, dataset_para, *numImages) == OK) {
|
||||
if (!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << index << " Extending HDF5 dataset by " <<
|
||||
extNumImages << ", Total x Dimension: " << (extNumImages + *numImages);
|
||||
}
|
||||
extNumImages += *numImages;
|
||||
HDF5FileStatic::ExtendDataset(index, dataspace, dataset,
|
||||
dataspace_para, dataset_para, *numImages);
|
||||
if (!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << index << " Extending HDF5 dataset by " <<
|
||||
extNumImages << ", Total x Dimension: " << (extNumImages + *numImages);
|
||||
}
|
||||
extNumImages += *numImages;
|
||||
}
|
||||
|
||||
if (HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_receiver_header),
|
||||
HDF5FileStatic::WriteDataFile(index, buffer + sizeof(sls_receiver_header),
|
||||
// infinite then no need for %maxframesperfile
|
||||
((*maxFramesPerFile == 0) ? fnum : fnum%(*maxFramesPerFile)),
|
||||
nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||
dataspace, dataset, datatype) == OK) {
|
||||
dataspace, dataset, datatype);
|
||||
|
||||
if (HDF5FileStatic::WriteParameterDatasets(index, dataspace_para,
|
||||
HDF5FileStatic::WriteParameterDatasets(index, dataspace_para,
|
||||
// infinite then no need for %maxframesperfile
|
||||
((*maxFramesPerFile == 0) ? fnum : fnum%(*maxFramesPerFile)),
|
||||
dataset_para, (sls_receiver_header*) (buffer),
|
||||
parameterDataTypes) == OK) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return OK;
|
||||
}
|
||||
parameterDataTypes);
|
||||
} catch (const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
throw;
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
FILE_LOG(logERROR) << index << "Write to file failed";
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
int HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
void HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
|
||||
//beginning of every acquisition
|
||||
numFramesInFile = 0;
|
||||
@ -256,12 +255,14 @@ int HDF5File::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
}
|
||||
pthread_mutex_lock(&Mutex);
|
||||
attr.version = HDF5_WRITER_VERSION;
|
||||
int ret = HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
try{
|
||||
HDF5FileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
*overWriteEnable, attr);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return ret;
|
||||
} catch (const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@ -286,15 +287,15 @@ void HDF5File::EndofAcquisition(bool anyPacketsCaught, uint64_t numf) {
|
||||
|
||||
|
||||
// called only by the one maser receiver
|
||||
int HDF5File::CreateVirtualFile(uint64_t numf) {
|
||||
void HDF5File::CreateVirtualFile(uint64_t numf) {
|
||||
pthread_mutex_lock(&Mutex);
|
||||
|
||||
std::string vname = HDF5FileStatic::CreateVirtualFileName(*filePath, *fileNamePrefix, *fileIndex);
|
||||
if(!(*silentMode)) {
|
||||
FILE_LOG(logINFO) << "Virtual File: " << vname;
|
||||
}
|
||||
|
||||
int ret = HDF5FileStatic::CreateVirtualDataFile(vname,
|
||||
try {
|
||||
HDF5FileStatic::CreateVirtualDataFile(vname,
|
||||
virtualfd, masterFileName,
|
||||
*filePath, *fileNamePrefix, *fileIndex, (*numImages > 1),
|
||||
*detIndex, *numUnitsPerDetector,
|
||||
@ -305,12 +306,15 @@ int HDF5File::CreateVirtualFile(uint64_t numf) {
|
||||
numDetY, numDetX, nPixelsY, ((*dynamicRange==4) ? (nPixelsX/2) : nPixelsX),
|
||||
HDF5_WRITER_VERSION,
|
||||
parameterNames, parameterDataTypes);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return ret;
|
||||
} catch (const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
throw;
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
|
||||
// called only by the one maser receiver
|
||||
int HDF5File::LinkVirtualFileinMasterFile() {
|
||||
void HDF5File::LinkVirtualFileinMasterFile() {
|
||||
//dataset name
|
||||
std::ostringstream osfn;
|
||||
osfn << "/data";
|
||||
@ -318,8 +322,12 @@ int HDF5File::LinkVirtualFileinMasterFile() {
|
||||
std::string dsetname = osfn.str();
|
||||
|
||||
pthread_mutex_lock(&Mutex);
|
||||
int ret = HDF5FileStatic::LinkVirtualInMaster(masterFileName, currentFileName,
|
||||
try {
|
||||
HDF5FileStatic::LinkVirtualInMaster(masterFileName, currentFileName,
|
||||
dsetname, parameterNames);
|
||||
} catch (const RuntimeError &e) {
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
throw;
|
||||
}
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
return ret;
|
||||
}
|
||||
|
@ -18,9 +18,10 @@
|
||||
|
||||
/** cosntructor & destructor */
|
||||
|
||||
Implementation::Implementation() {
|
||||
Implementation::Implementation(const detectorType d) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
InitializeMembers();
|
||||
setDetectorType(d);
|
||||
}
|
||||
|
||||
Implementation::~Implementation() {
|
||||
@ -162,11 +163,7 @@ void Implementation::SetThreadPriorities() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
for (const auto &it : listener) {
|
||||
if (it->SetThreadPriority(LISTENER_PRIORITY) == FAIL) {
|
||||
FILE_LOG(logWARNING) << "Could not prioritize listener threads. "
|
||||
"(No Root Privileges?)";
|
||||
return;
|
||||
}
|
||||
it->SetThreadPriority(LISTENER_PRIORITY);
|
||||
}
|
||||
std::ostringstream osfn;
|
||||
osfn << "Priorities set - "
|
||||
@ -176,7 +173,7 @@ void Implementation::SetThreadPriorities() {
|
||||
FILE_LOG(logINFO) << osfn.str();
|
||||
}
|
||||
|
||||
int Implementation::SetupFifoStructure() {
|
||||
void Implementation::SetupFifoStructure() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
fifo.clear();
|
||||
@ -189,11 +186,8 @@ int Implementation::SetupFifoStructure() {
|
||||
(generalData->imageSize) + (generalData->fifoBufferHeaderSize),
|
||||
fifoDepth));
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR)
|
||||
<< "Could not allocate memory for fifo structure of index "
|
||||
<< i;
|
||||
fifo.clear();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not allocate memory for fifo structure " + std::to_string(i));
|
||||
}
|
||||
// set the listener & dataprocessor threads to point to the right fifo
|
||||
if (listener.size())
|
||||
@ -210,7 +204,6 @@ int Implementation::SetupFifoStructure() {
|
||||
fifoDepth)
|
||||
<< " bytes";
|
||||
FILE_LOG(logINFO) << numThreads << " Fifo structure(s) reconstructed";
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@ -221,10 +214,8 @@ int Implementation::SetupFifoStructure() {
|
||||
* *
|
||||
* ************************************************/
|
||||
|
||||
int Implementation::setDetectorType(const detectorType d) {
|
||||
void Implementation::setDetectorType(const detectorType d) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
DeleteMembers();
|
||||
InitializeMembers();
|
||||
myDetectorType = d;
|
||||
switch (myDetectorType) {
|
||||
case GOTTHARD:
|
||||
@ -237,8 +228,7 @@ int Implementation::setDetectorType(const detectorType d) {
|
||||
<< " Receiver *****";
|
||||
break;
|
||||
default:
|
||||
FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("This is an unknown receiver type " + std::to_string(static_cast<int>(d)));
|
||||
}
|
||||
|
||||
// set detector specific variables
|
||||
@ -270,10 +260,7 @@ int Implementation::setDetectorType(const detectorType d) {
|
||||
framesPerFile = generalData->maxFramesPerFile;
|
||||
|
||||
SetLocalNetworkParameters();
|
||||
if (SetupFifoStructure() == FAIL) {
|
||||
FILE_LOG(logERROR) << "Could not allocate memory for fifo structure";
|
||||
return FAIL;
|
||||
}
|
||||
SetupFifoStructure();
|
||||
|
||||
// create threads
|
||||
for (int i = 0; i < numThreads; ++i) {
|
||||
@ -293,12 +280,9 @@ int Implementation::setDetectorType(const detectorType d) {
|
||||
&silentMode, &quadEnable, &ctbDbitList, &ctbDbitOffset,
|
||||
&ctbAnalogDataBytes));
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR)
|
||||
<< "Could not create listener/dataprocessor threads (index:"
|
||||
<< i << ")";
|
||||
listener.clear();
|
||||
dataProcessor.clear();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create listener/dataprocessor threads (index:" + std::to_string(i) + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,7 +295,6 @@ int Implementation::setDetectorType(const detectorType d) {
|
||||
SetThreadPriorities();
|
||||
|
||||
FILE_LOG(logDEBUG) << " Detector type set to " << sls::ToString(d);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int *Implementation::getMultiDetectorSize() const {
|
||||
@ -404,14 +387,12 @@ uint32_t Implementation::getFifoDepth() const {
|
||||
return fifoDepth;
|
||||
}
|
||||
|
||||
int Implementation::setFifoDepth(const uint32_t i) {
|
||||
void Implementation::setFifoDepth(const uint32_t i) {
|
||||
if (fifoDepth != i) {
|
||||
fifoDepth = i;
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
throw sls::RuntimeError("Failed to setup fifo structure");
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Fifo Depth: " << i;
|
||||
return OK;
|
||||
}
|
||||
|
||||
slsDetectorDefs::frameDiscardPolicy
|
||||
@ -625,18 +606,14 @@ std::vector<uint64_t> Implementation::getNumMissingPackets() const {
|
||||
return mp;
|
||||
}
|
||||
|
||||
int Implementation::startReceiver(std::string& err) {
|
||||
void Implementation::startReceiver() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
FILE_LOG(logINFO) << "Starting Receiver";
|
||||
stoppedFlag = false;
|
||||
ResetParametersforNewAcquisition();
|
||||
|
||||
// listener
|
||||
if (CreateUDPSockets() == FAIL) {
|
||||
err.assign("Could not create UDP Socket(s).");
|
||||
FILE_LOG(logERROR) << err;
|
||||
return FAIL;
|
||||
}
|
||||
CreateUDPSockets();
|
||||
|
||||
// callbacks
|
||||
if (startAcquisitionCallBack) {
|
||||
@ -651,11 +628,7 @@ int Implementation::startReceiver(std::string& err) {
|
||||
|
||||
// processor->writer
|
||||
if (fileWriteEnable) {
|
||||
if (SetupWriter() == FAIL) {
|
||||
err.assign("Could not create file.\n");
|
||||
FILE_LOG(logERROR) << err;
|
||||
return FAIL;
|
||||
}
|
||||
SetupWriter();
|
||||
} else
|
||||
FILE_LOG(logINFO) << "File Write Disabled";
|
||||
|
||||
@ -669,7 +642,6 @@ int Implementation::startReceiver(std::string& err) {
|
||||
|
||||
FILE_LOG(logINFO) << "Receiver Started";
|
||||
FILE_LOG(logINFO) << "Status: " << sls::ToString(status);
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Implementation::setStoppedFlag(bool stopped) {
|
||||
@ -817,14 +789,12 @@ void Implementation::closeFiles() {
|
||||
dataProcessor[0]->EndofAcquisition(anycaught, maxIndexCaught);
|
||||
}
|
||||
|
||||
int Implementation::restreamStop() {
|
||||
void Implementation::restreamStop() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
for (const auto &it : dataStreamer) {
|
||||
if (it->RestreamStop() == FAIL)
|
||||
throw sls::RuntimeError("Could not restream stop packet");
|
||||
it->RestreamStop();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Restreaming Dummy Header via ZMQ successful";
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Implementation::ResetParametersforNewAcquisition() {
|
||||
@ -844,29 +814,23 @@ void Implementation::ResetParametersforNewAcquisition() {
|
||||
}
|
||||
}
|
||||
|
||||
int Implementation::CreateUDPSockets() {
|
||||
void Implementation::CreateUDPSockets() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
bool error = false;
|
||||
|
||||
for (unsigned int i = 0; i < listener.size(); ++i) {
|
||||
if (listener[i]->CreateUDPSockets() == FAIL) {
|
||||
error = true;
|
||||
break;
|
||||
try{
|
||||
for (unsigned int i = 0; i < listener.size(); ++i) {
|
||||
listener[i]->CreateUDPSockets();
|
||||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
} catch(const sls::RuntimeError &e) {
|
||||
shutDownUDPSockets();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create UDP Socket(s).");
|
||||
}
|
||||
|
||||
FILE_LOG(logDEBUG) << "UDP socket(s) created successfully.";
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Implementation::SetupWriter() {
|
||||
void Implementation::SetupWriter() {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
bool error = false;
|
||||
masterAttributes attr;
|
||||
attr.detectorType = myDetectorType;
|
||||
attr.dynamicRange = dynamicRange;
|
||||
@ -892,18 +856,16 @@ int Implementation::SetupWriter() {
|
||||
for (auto &i : ctbDbitList) {
|
||||
attr.dbitlist |= (1 << i);
|
||||
}
|
||||
for (unsigned int i = 0; i < dataProcessor.size(); ++i)
|
||||
if (dataProcessor[i]->CreateNewFile(attr) == FAIL) {
|
||||
error = true;
|
||||
break;
|
||||
|
||||
try {
|
||||
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
|
||||
dataProcessor[i]->CreateNewFile(attr);
|
||||
}
|
||||
if (error) {
|
||||
} catch(const sls::RuntimeError &e) {
|
||||
shutDownUDPSockets();
|
||||
closeFiles();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create file.");
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Implementation::StartRunning() {
|
||||
@ -935,7 +897,7 @@ int Implementation::getNumberofUDPInterfaces() const {
|
||||
return numUDPInterfaces;
|
||||
}
|
||||
|
||||
int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
void Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
if (numUDPInterfaces != n) {
|
||||
@ -959,8 +921,7 @@ int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
udpSocketBufferSize = generalData->defaultUdpSocketBufferSize;
|
||||
|
||||
// fifo
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
|
||||
// create threads
|
||||
for (int i = 0; i < numThreads; ++i) {
|
||||
@ -984,12 +945,9 @@ int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
&ctbDbitOffset, &ctbAnalogDataBytes));
|
||||
dataProcessor[i]->SetGeneralData(generalData);
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR)
|
||||
<< "Could not create listener/dataprocessor threads (index:"
|
||||
<< i << ")";
|
||||
listener.clear();
|
||||
dataProcessor.clear();
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create listener/dataprocessor threads (index:" + std::to_string(i) + ")");
|
||||
}
|
||||
// streamer threads
|
||||
if (dataStreamEnable) {
|
||||
@ -1009,14 +967,11 @@ int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
&numThreads, streamingPort, streamingSrcIP);
|
||||
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR)
|
||||
<< "Could not create datastreamer threads (index:" << i
|
||||
<< ")";
|
||||
if (dataStreamEnable) {
|
||||
dataStreamer.clear();
|
||||
dataStreamEnable = false;
|
||||
}
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create datastreamer threads (index:" + std::to_string(i) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1041,13 +996,10 @@ int Implementation::setNumberofUDPInterfaces(const int n) {
|
||||
}
|
||||
|
||||
// test socket buffer size with current set up
|
||||
if (setUDPSocketBufferSize(0) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
setUDPSocketBufferSize(0);
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "Number of Interfaces: " << numUDPInterfaces;
|
||||
return OK;
|
||||
}
|
||||
|
||||
std::string Implementation::getEthernetInterface() const {
|
||||
@ -1103,22 +1055,17 @@ int64_t Implementation::getUDPSocketBufferSize() const {
|
||||
return udpSocketBufferSize;
|
||||
}
|
||||
|
||||
int Implementation::setUDPSocketBufferSize(const int64_t s) {
|
||||
void Implementation::setUDPSocketBufferSize(const int64_t s) {
|
||||
int64_t size = (s == 0) ? udpSocketBufferSize : s;
|
||||
size_t listSize = listener.size();
|
||||
|
||||
if (myDetectorType == JUNGFRAU && (int)listSize != numUDPInterfaces) {
|
||||
FILE_LOG(logERROR) << "Number of Interfaces " << numUDPInterfaces
|
||||
<< " do not match listener size " << listSize;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Number of Interfaces " + std::to_string(numUDPInterfaces) + " do not match listener size " + std::to_string(listSize));
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < listSize; ++i) {
|
||||
if (listener[i]->CreateDummySocketForUDPSocketBufferSize(size) == FAIL)
|
||||
return FAIL;
|
||||
listener[i]->CreateDummySocketForUDPSocketBufferSize(size);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int64_t Implementation::getActualUDPSocketBufferSize() const {
|
||||
@ -1137,7 +1084,7 @@ bool Implementation::getDataStreamEnable() const {
|
||||
return dataStreamEnable;
|
||||
}
|
||||
|
||||
int Implementation::setDataStreamEnable(const bool enable) {
|
||||
void Implementation::setDataStreamEnable(const bool enable) {
|
||||
|
||||
if (dataStreamEnable != enable) {
|
||||
dataStreamEnable = enable;
|
||||
@ -1164,14 +1111,13 @@ int Implementation::setDataStreamEnable(const bool enable) {
|
||||
} catch (...) {
|
||||
dataStreamer.clear();
|
||||
dataStreamEnable = false;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not set data stream enable.");
|
||||
}
|
||||
}
|
||||
SetThreadPriorities();
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFO) << "Data Send to Gui: " << dataStreamEnable;
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getStreamingFrequency() const {
|
||||
@ -1179,12 +1125,11 @@ uint32_t Implementation::getStreamingFrequency() const {
|
||||
return streamingFrequency;
|
||||
}
|
||||
|
||||
int Implementation::setStreamingFrequency(const uint32_t freq) {
|
||||
void Implementation::setStreamingFrequency(const uint32_t freq) {
|
||||
if (streamingFrequency != freq) {
|
||||
streamingFrequency = freq;
|
||||
}
|
||||
FILE_LOG(logINFO) << "Streaming Frequency: " << streamingFrequency;
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getStreamingTimer() const {
|
||||
@ -1307,7 +1252,7 @@ uint32_t Implementation::getNumberofAnalogSamples() const {
|
||||
return numberOfAnalogSamples;
|
||||
}
|
||||
|
||||
int Implementation::setNumberofAnalogSamples(const uint32_t i) {
|
||||
void Implementation::setNumberofAnalogSamples(const uint32_t i) {
|
||||
if (numberOfAnalogSamples != i) {
|
||||
numberOfAnalogSamples = i;
|
||||
|
||||
@ -1318,13 +1263,11 @@ int Implementation::setNumberofAnalogSamples(const uint32_t i) {
|
||||
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Number of Analog Samples: " << numberOfAnalogSamples;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getNumberofDigitalSamples() const {
|
||||
@ -1332,7 +1275,7 @@ uint32_t Implementation::getNumberofDigitalSamples() const {
|
||||
return numberOfDigitalSamples;
|
||||
}
|
||||
|
||||
int Implementation::setNumberofDigitalSamples(const uint32_t i) {
|
||||
void Implementation::setNumberofDigitalSamples(const uint32_t i) {
|
||||
if (numberOfDigitalSamples != i) {
|
||||
numberOfDigitalSamples = i;
|
||||
|
||||
@ -1343,14 +1286,12 @@ int Implementation::setNumberofDigitalSamples(const uint32_t i) {
|
||||
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Number of Digital Samples: "
|
||||
<< numberOfDigitalSamples;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getDynamicRange() const {
|
||||
@ -1358,7 +1299,7 @@ uint32_t Implementation::getDynamicRange() const {
|
||||
return dynamicRange;
|
||||
}
|
||||
|
||||
int Implementation::setDynamicRange(const uint32_t i) {
|
||||
void Implementation::setDynamicRange(const uint32_t i) {
|
||||
|
||||
if (dynamicRange != i) {
|
||||
dynamicRange = i;
|
||||
@ -1369,12 +1310,10 @@ int Implementation::setDynamicRange(const uint32_t i) {
|
||||
// to update npixelsx, npixelsy in file writer
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFO) << "Dynamic Range: " << dynamicRange;
|
||||
return OK;
|
||||
}
|
||||
|
||||
slsDetectorDefs::ROI Implementation::getROI() const {
|
||||
@ -1382,7 +1321,7 @@ slsDetectorDefs::ROI Implementation::getROI() const {
|
||||
return roi;
|
||||
}
|
||||
|
||||
int Implementation::setROI(slsDetectorDefs::ROI arg) {
|
||||
void Implementation::setROI(slsDetectorDefs::ROI arg) {
|
||||
if (roi.xmin != arg.xmin || roi.xmax != arg.xmax) {
|
||||
roi.xmin = arg.xmin;
|
||||
roi.xmax = arg.xmax;
|
||||
@ -1392,14 +1331,12 @@ int Implementation::setROI(slsDetectorDefs::ROI arg) {
|
||||
framesPerFile = generalData->maxFramesPerFile;
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "ROI: [" << roi.xmin << ", " << roi.xmax << "]";;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool Implementation::getTenGigaEnable() const {
|
||||
@ -1407,7 +1344,7 @@ bool Implementation::getTenGigaEnable() const {
|
||||
return tengigaEnable;
|
||||
}
|
||||
|
||||
int Implementation::setTenGigaEnable(const bool b) {
|
||||
void Implementation::setTenGigaEnable(const bool b) {
|
||||
if (tengigaEnable != b) {
|
||||
tengigaEnable = b;
|
||||
// side effects
|
||||
@ -1427,13 +1364,11 @@ int Implementation::setTenGigaEnable(const bool b) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Ten Giga: " << (tengigaEnable ? "enabled" : "disabled");
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Implementation::getFlippedDataX() const {
|
||||
@ -1465,7 +1400,7 @@ bool Implementation::getGapPixelsEnable() const {
|
||||
return gapPixelsEnable;
|
||||
}
|
||||
|
||||
int Implementation::setGapPixelsEnable(const bool b) {
|
||||
void Implementation::setGapPixelsEnable(const bool b) {
|
||||
if (gapPixelsEnable != b) {
|
||||
gapPixelsEnable = b;
|
||||
|
||||
@ -1473,11 +1408,9 @@ int Implementation::setGapPixelsEnable(const bool b) {
|
||||
generalData->SetGapPixelsEnable(b, dynamicRange, quadEnable);
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
FILE_LOG(logINFO) << "Gap Pixels Enable: " << gapPixelsEnable;
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool Implementation::getQuad() const {
|
||||
@ -1485,7 +1418,7 @@ bool Implementation::getQuad() const {
|
||||
return quadEnable;
|
||||
}
|
||||
|
||||
int Implementation::setQuad(const bool b) {
|
||||
void Implementation::setQuad(const bool b) {
|
||||
if (quadEnable != b) {
|
||||
quadEnable = b;
|
||||
|
||||
@ -1493,8 +1426,7 @@ int Implementation::setQuad(const bool b) {
|
||||
// to update npixelsx, npixelsy in file writer
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
|
||||
if (!quadEnable) {
|
||||
for (const auto &it : dataStreamer) {
|
||||
@ -1513,7 +1445,6 @@ int Implementation::setQuad(const bool b) {
|
||||
}
|
||||
}
|
||||
FILE_LOG(logINFO) << "Quad Enable: " << quadEnable;
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool Implementation::getActivate() const {
|
||||
@ -1557,7 +1488,7 @@ Implementation::getReadoutMode() const {
|
||||
return readoutType;
|
||||
}
|
||||
|
||||
int Implementation::setReadoutMode(const readoutMode f) {
|
||||
void Implementation::setReadoutMode(const readoutMode f) {
|
||||
if (readoutType != f) {
|
||||
readoutType = f;
|
||||
|
||||
@ -1568,14 +1499,12 @@ int Implementation::setReadoutMode(const readoutMode f) {
|
||||
tengigaEnable, readoutType);
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "Readout Mode: " << sls::ToString(f);
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getADCEnableMask() const {
|
||||
@ -1583,7 +1512,7 @@ uint32_t Implementation::getADCEnableMask() const {
|
||||
return adcEnableMaskOneGiga;
|
||||
}
|
||||
|
||||
int Implementation::setADCEnableMask(uint32_t mask) {
|
||||
void Implementation::setADCEnableMask(uint32_t mask) {
|
||||
if (adcEnableMaskOneGiga != mask) {
|
||||
adcEnableMaskOneGiga = mask;
|
||||
|
||||
@ -1594,15 +1523,13 @@ int Implementation::setADCEnableMask(uint32_t mask) {
|
||||
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "ADC Enable Mask for 1Gb mode: 0x" << std::hex << adcEnableMaskOneGiga
|
||||
<< std::dec;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getTenGigaADCEnableMask() const {
|
||||
@ -1610,7 +1537,7 @@ uint32_t Implementation::getTenGigaADCEnableMask() const {
|
||||
return adcEnableMaskTenGiga;
|
||||
}
|
||||
|
||||
int Implementation::setTenGigaADCEnableMask(uint32_t mask) {
|
||||
void Implementation::setTenGigaADCEnableMask(uint32_t mask) {
|
||||
if (adcEnableMaskTenGiga != mask) {
|
||||
adcEnableMaskTenGiga = mask;
|
||||
|
||||
@ -1621,15 +1548,13 @@ int Implementation::setTenGigaADCEnableMask(uint32_t mask) {
|
||||
|
||||
for (const auto &it : dataProcessor)
|
||||
it->SetPixelDimension();
|
||||
if (SetupFifoStructure() == FAIL)
|
||||
return FAIL;
|
||||
SetupFifoStructure();
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO) << "ADC Enable Mask for 10Gb mode: 0x" << std::hex << adcEnableMaskTenGiga
|
||||
<< std::dec;
|
||||
FILE_LOG(logINFO) << "Packets per Frame: "
|
||||
<< (generalData->packetsPerFrame);
|
||||
return OK;
|
||||
}
|
||||
|
||||
std::vector<int> Implementation::getDbitList() const {
|
||||
|
@ -55,9 +55,7 @@ Listener::Listener(int ind, detectorType dtype, Fifo* f, std::atomic<runStatus>*
|
||||
numFramesStatistic(0),
|
||||
oddStartingPacket(true)
|
||||
{
|
||||
if(ThreadObject::CreateThread() == FAIL)
|
||||
throw sls::RuntimeError("Could not create listener thread");
|
||||
|
||||
ThreadObject::CreateThread();
|
||||
FILE_LOG(logDEBUG) << "Listener " << ind << " created";
|
||||
}
|
||||
|
||||
@ -155,19 +153,20 @@ void Listener::SetGeneralData(GeneralData* g) {
|
||||
}
|
||||
|
||||
|
||||
int Listener::SetThreadPriority(int priority) {
|
||||
void Listener::SetThreadPriority(int priority) {
|
||||
struct sched_param param;
|
||||
param.sched_priority = priority;
|
||||
if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) == EPERM)
|
||||
return FAIL;
|
||||
if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) == EPERM) {
|
||||
throw sls::RuntimeError("Could not prioritize listener threads. "
|
||||
"(No Root Privileges?)");
|
||||
}
|
||||
FILE_LOG(logINFO) << "Listener Thread Priority set to " << priority;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Listener::CreateUDPSockets() {
|
||||
void Listener::CreateUDPSockets() {
|
||||
|
||||
if (!(*activated)) {
|
||||
return OK;
|
||||
return;
|
||||
}
|
||||
|
||||
//if eth is mistaken with ip address
|
||||
@ -186,8 +185,7 @@ int Listener::CreateUDPSockets() {
|
||||
*udpSocketBufferSize);
|
||||
FILE_LOG(logINFO) << index << ": UDP port opened at port " << *udpPortNumber;
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR) << "Could not create UDP socket on port " << *udpPortNumber;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create UDP socket on port "+ std::to_string(*udpPortNumber));
|
||||
}
|
||||
|
||||
udpSocketAlive = true;
|
||||
@ -195,8 +193,6 @@ int Listener::CreateUDPSockets() {
|
||||
|
||||
// doubled due to kernel bookkeeping (could also be less due to permissions)
|
||||
*actualUDPSocketBufferSize = udpSocket->getActualUDPSocketBufferSize();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@ -216,12 +212,12 @@ void Listener::ShutDownUDPSocket() {
|
||||
}
|
||||
|
||||
|
||||
int Listener::CreateDummySocketForUDPSocketBufferSize(int64_t s) {
|
||||
void Listener::CreateDummySocketForUDPSocketBufferSize(int64_t s) {
|
||||
FILE_LOG(logINFO) << "Testing UDP Socket Buffer size " << s << " with test port " << *udpPortNumber;
|
||||
|
||||
if (!(*activated)) {
|
||||
*actualUDPSocketBufferSize = (s*2);
|
||||
return OK;
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t temp = *udpSocketBufferSize;
|
||||
@ -247,12 +243,8 @@ int Listener::CreateDummySocketForUDPSocketBufferSize(int64_t s) {
|
||||
}
|
||||
|
||||
} catch (...) {
|
||||
FILE_LOG(logERROR) << "Could not create a test UDP socket on port " << *udpPortNumber;
|
||||
return FAIL;
|
||||
throw sls::RuntimeError("Could not create a test UDP socket on port " + std::to_string(*udpPortNumber));
|
||||
}
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Listener::SetHardCodedPosition(uint16_t r, uint16_t c) {
|
||||
|
@ -48,22 +48,18 @@ void ThreadObject::DestroyThread() {
|
||||
}
|
||||
|
||||
|
||||
int ThreadObject::CreateThread() {
|
||||
if(alive){
|
||||
FILE_LOG(logERROR) << "Cannot create thread " << index << ". Already alive";
|
||||
return FAIL;
|
||||
void ThreadObject::CreateThread() {
|
||||
if (alive) {
|
||||
throw sls::RuntimeError("Cannot create " + GetType() + " thread " + std::to_string(index) + ". Already alive");
|
||||
}
|
||||
sem_init(&semaphore,1,0);
|
||||
killThread = false;
|
||||
|
||||
if(pthread_create(&thread, nullptr,StartThread, (void*) this)){
|
||||
FILE_LOG(logERROR) << "Could not create " << GetType() << " thread with index " << index;
|
||||
return FAIL;
|
||||
if (pthread_create(&thread, nullptr,StartThread, (void*) this)){
|
||||
throw sls::RuntimeError("Could not create " + GetType() + " thread with index " + std::to_string(index));
|
||||
}
|
||||
alive = true;
|
||||
FILE_LOG(logDEBUG) << GetType() << " thread " << index << " created successfully.";
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user