somewhere in between.. next step include generalData pointer in listerner and dataprocessor calss in constructor and a setter

This commit is contained in:
Dhanya Maliakal
2017-01-31 08:42:16 +01:00
parent 01d54a7a4c
commit d95aaa2089
16 changed files with 1063 additions and 1275 deletions

View File

@ -23,9 +23,21 @@ uint64_t DataProcessor::RunningMask(0x0);
pthread_mutex_t DataProcessor::Mutex = PTHREAD_MUTEX_INITIALIZER;
bool DataProcessor::acquisitionStartedFlag(false);
DataProcessor::DataProcessor(Fifo*& f) : ThreadObject(NumberofDataProcessors), fifo(f) {
FILE_LOG(logDEBUG) << __AT__ << " called";
bool DataProcessor::measurementStartedFlag(false);
DataProcessor::DataProcessor(Fifo*& f) :
ThreadObject(NumberofDataProcessors),
fifo(f),
numTotalFramesCaught(0),
numFramesCaught(0),
firstAcquisitionIndex(0),
firstMeasurementIndex(0),
currentFrameIndex(0)
{
FILE_LOG (logDEBUG) << __AT__ << " called";
if(ThreadObject::CreateThread()){
pthread_mutex_lock(&Mutex);
@ -33,12 +45,12 @@ DataProcessor::DataProcessor(Fifo*& f) : ThreadObject(NumberofDataProcessors), f
pthread_mutex_unlock(&Mutex);
}
NumberofDataProcessors++;
FILE_LOG(logDEBUG) << "Number of DataProcessors: " << NumberofDataProcessors << endl;
FILE_LOG (logDEBUG) << "Number of DataProcessors: " << NumberofDataProcessors << endl;
}
DataProcessor::~DataProcessor() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
ThreadObject::DestroyThread();
NumberofDataProcessors--;
}
@ -47,35 +59,55 @@ DataProcessor::~DataProcessor() {
uint64_t DataProcessor::GetErrorMask() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
return ErrorMask;
}
void DataProcessor::ResetRunningMask() {
FILE_LOG(logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex);
RunningMask = 0x0;
pthread_mutex_unlock(&Mutex);
bool DataProcessor::GetAcquisitionStartedFlag(){
FILE_LOG (logDEBUG) << __AT__ << " called";
return acquisitionStartedFlag;
}
bool DataProcessor::GetMeasurementStartedFlag(){
FILE_LOG (logDEBUG) << __AT__ << " called";
return measurementStartedFlag;
}
/** non static functions */
string DataProcessor::GetType(){
return TypeName;
}
uint64_t DataProcessor::GetNumTotalFramesCaught() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return numTotalFramesCaught;
}
uint64_t DataProcessor::GetNumFramesCaught() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return numFramesCaught;
}
uint64_t DataProcessor::GetProcessedAcquisitionIndex() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return currentFrameIndex - firstAcquisitionIndex;
}
bool DataProcessor::IsRunning() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
return ((1 << index) & RunningMask);
}
void DataProcessor::StartRunning() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex);
RunningMask |= (1<<index);
pthread_mutex_unlock(&Mutex);
@ -83,7 +115,7 @@ void DataProcessor::StartRunning() {
void DataProcessor::StopRunning() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex);
RunningMask ^= (1<<index);
pthread_mutex_unlock(&Mutex);
@ -91,22 +123,74 @@ void DataProcessor::StopRunning() {
void DataProcessor::SetFifo(Fifo*& f) {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
fifo = f;
}
void DataProcessor::ResetParametersforNewAcquisition() {
FILE_LOG (logDEBUG) << __AT__ << " called";
numTotalFramesCaught = 0;
firstAcquisitionIndex = 0;
currentFrameIndex = 0;
if(acquisitionStartedFlag){
pthread_mutex_lock(&Mutex);
acquisitionStartedFlag = false;
pthread_mutex_unlock(&Mutex);
}
}
void DataProcessor::ResetParametersforNewMeasurement(){
FILE_LOG (logDEBUG) << __AT__ << " called";
numFramesCaught = 0;
firstMeasurementIndex = 0;
if(measurementStartedFlag){
pthread_mutex_lock(&Mutex);
measurementStartedFlag = false;
pthread_mutex_unlock(&Mutex);
}
if(RunningMask){
pthread_mutex_lock(&Mutex);
RunningMask = 0x0;
pthread_mutex_unlock(&Mutex);
}
}
void DataProcessor::ThreadExecution() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
char* buffer=0;
fifo->PopAddress(buffer);
#ifdef FIFODEBUG
cprintf(BLUE,"DataProcessor %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer);
#endif
uint32_t numPackets = (uint32_t)(*((uint32_t*)buffer));
if(!strcmp(buffer,"done")){
if(numPackets == DUMMY_PACKET_VALUE){
cprintf(GREEN,"DataProcessing %d: Got dummy value*****\n");
StopRunning();
fifo->FreeAddress(buffer);
return;
}
uint64_t fnum; uint32_t pnum; uint32_t snum; uint64_t bcid;
GetHeaderInfo(index,buffer+generalData->fifoBufferHeaderSize,16,fnum,pnum,snum,bcid);
cprintf(GREEN,"DataProcessing %d: fnum:%lld, pnum:%d\n",(long long int)fnum, pnum);
fifo->FreeAddress(buffer);
}
int DataProcessor::CreateNewFile() {
FILE_LOG (logDEBUG) << __AT__ << " called";
//create file fileWriter.push_back(new BinaryFileWriter(fileName))
return OK;
}
void DataProcessor::CloseFile() {
FILE_LOG (logDEBUG) << __AT__ << " called";
}

View File

@ -20,8 +20,10 @@ uint64_t DataStreamer::RunningMask(0x0);
pthread_mutex_t DataStreamer::Mutex = PTHREAD_MUTEX_INITIALIZER;
DataStreamer::DataStreamer() : ThreadObject(NumberofDataStreamers) {
FILE_LOG(logDEBUG) << __AT__ << " called";
DataStreamer::DataStreamer() :
ThreadObject(NumberofDataStreamers)
{
FILE_LOG (logDEBUG) << __AT__ << " called";
if(ThreadObject::CreateThread()){
pthread_mutex_lock(&Mutex);
@ -30,12 +32,12 @@ DataStreamer::DataStreamer() : ThreadObject(NumberofDataStreamers) {
}
NumberofDataStreamers++;
FILE_LOG(logDEBUG) << "Number of DataStreamers: " << NumberofDataStreamers << endl;
FILE_LOG (logDEBUG) << "Number of DataStreamers: " << NumberofDataStreamers << endl;
}
DataStreamer::~DataStreamer() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
ThreadObject::DestroyThread();
NumberofDataStreamers--;
}
@ -44,13 +46,13 @@ DataStreamer::~DataStreamer() {
uint64_t DataStreamer::GetErrorMask() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
return ErrorMask;
}
void DataStreamer::ResetRunningMask() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex);
RunningMask = 0x0;
pthread_mutex_unlock(&Mutex);
@ -66,13 +68,13 @@ string DataStreamer::GetType(){
bool DataStreamer::IsRunning() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
return ((1 << index) & RunningMask);
}
void DataStreamer::StartRunning() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex);
RunningMask |= (1<<index);
pthread_mutex_unlock(&Mutex);
@ -80,14 +82,14 @@ void DataStreamer::StartRunning() {
void DataStreamer::StopRunning() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex);
RunningMask ^= (1<<index);
pthread_mutex_unlock(&Mutex);
}
void DataStreamer::ThreadExecution() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
}

View File

@ -17,7 +17,7 @@ Fifo::Fifo(uint32_t fifoItemSize, uint32_t fifoDepth, bool &success):
memory(0),
fifoBound(0),
fifoFree(0) {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
index = NumberofFifoClassObjects++;
if(CreateFifos(fifoItemSize, fifoDepth) == FAIL)
success = false;
@ -25,7 +25,7 @@ Fifo::Fifo(uint32_t fifoItemSize, uint32_t fifoDepth, bool &success):
Fifo::~Fifo() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
DestroyFifos();
NumberofFifoClassObjects--;
}
@ -33,7 +33,7 @@ Fifo::~Fifo() {
int Fifo::CreateFifos(uint32_t fifoItemSize, uint32_t fifoDepth) {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
//destroy if not already
DestroyFifos();
@ -43,7 +43,7 @@ int Fifo::CreateFifos(uint32_t fifoItemSize, uint32_t fifoDepth) {
//allocate memory
memory = (char*) calloc (fifoItemSize * fifoDepth, sizeof(char));
if (memory == NULL){
FILE_LOG(logERROR) << "Could not allocate memory for fifos";
FILE_LOG (logERROR) << "Could not allocate memory for fifos";
return FAIL;
}
@ -58,13 +58,13 @@ int Fifo::CreateFifos(uint32_t fifoItemSize, uint32_t fifoDepth) {
buffer += fifoItemSize;
}
}
FILE_LOG(logINFO) << "Fifo Structure " << index << " reconstructed";
FILE_LOG (logINFO) << "Fifo Structure " << index << " reconstructed";
return OK;
}
void Fifo::DestroyFifos(){
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
if (fifoBound) {
delete fifoBound;

View File

@ -8,6 +8,7 @@
#include "Listener.h"
#include "Fifo.h"
#include "genericSocket.h"
#include <iostream>
#include <cstring>
@ -23,22 +24,32 @@ uint64_t Listener::RunningMask(0x0);
pthread_mutex_t Listener::Mutex = PTHREAD_MUTEX_INITIALIZER;
Listener::Listener(Fifo*& f) : ThreadObject(NumberofListeners), fifo(f) {
FILE_LOG(logDEBUG) << __AT__ << " called";
bool Listener::acquisitionStartedFlag(false);
bool Listener::measurementStartedFlag(false);
Listener::Listener(Fifo*& f) :
ThreadObject(NumberofListeners),
fifo(f),
numTotalPacketsCaught(0),
numPacketsCaught(0),
firstAcquisitionIndex(0),
firstMeasurementIndex(0)
{
FILE_LOG (logDEBUG) << __AT__ << " called";
if(ThreadObject::CreateThread()){
pthread_mutex_lock(&Mutex);
ErrorMask ^= (1<<index);
pthread_mutex_unlock(&Mutex);
}
count = 0;
NumberofListeners++;
FILE_LOG(logDEBUG) << "Number of Listeners: " << NumberofListeners << endl;
FILE_LOG (logDEBUG) << "Number of Listeners: " << NumberofListeners << endl;
}
Listener::~Listener() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
ThreadObject::DestroyThread();
NumberofListeners--;
}
@ -47,16 +58,20 @@ Listener::~Listener() {
uint64_t Listener::GetErrorMask() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
return ErrorMask;
}
void Listener::ResetRunningMask() {
FILE_LOG(logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex);
RunningMask = 0x0;
pthread_mutex_unlock(&Mutex);
bool Listener::GetAcquisitionStartedFlag(){
FILE_LOG (logDEBUG) << __AT__ << " called";
return acquisitionStartedFlag;
}
bool Listener::GetMeasurementStartedFlag(){
FILE_LOG (logDEBUG) << __AT__ << " called";
return measurementStartedFlag;
}
@ -67,14 +82,26 @@ string Listener::GetType(){
}
uint64_t Listener::GetTotalPacketsCaught() {
FILE_LOG (logDEBUG) << __AT__ << " called";
return numTotalPacketsCaught;
}
uint64_t Listener::GetNumReceivedinUDPBuffer() {
FILE_LOG (logDEBUG) << __AT__ << " called";
if(!udpSocket)
return 0;
return udpSocket->getCurrentTotalReceived();
}
bool Listener::IsRunning() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
return ((1 << index) & RunningMask);
}
void Listener::StartRunning() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex);
RunningMask |= (1<<index);
pthread_mutex_unlock(&Mutex);
@ -82,7 +109,7 @@ void Listener::StartRunning() {
void Listener::StopRunning() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
pthread_mutex_lock(&Mutex);
RunningMask ^= (1<<index);
pthread_mutex_unlock(&Mutex);
@ -90,13 +117,42 @@ void Listener::StopRunning() {
void Listener::SetFifo(Fifo*& f) {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
fifo = f;
}
void Listener::ResetParametersforNewAcquisition() {
FILE_LOG (logDEBUG) << __AT__ << " called";
numTotalPacketsCaught = 0;
firstAcquisitionIndex = 0;
if(acquisitionStartedFlag){
pthread_mutex_lock(&Mutex);
acquisitionStartedFlag = false;
pthread_mutex_unlock(&Mutex);
}
}
void Listener::ResetParametersforNewMeasurement(){
FILE_LOG (logDEBUG) << __AT__ << " called";
numPacketsCaught = 0;
firstMeasurementIndex = 0;
if(measurementStartedFlag){
pthread_mutex_lock(&Mutex);
measurementStartedFlag = false;
pthread_mutex_unlock(&Mutex);
}
if(RunningMask){
pthread_mutex_lock(&Mutex);
RunningMask = 0x0;
pthread_mutex_unlock(&Mutex);
}
}
void Listener::ThreadExecution() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
char* buffer;
fifo->GetNewAddress(buffer);
@ -104,15 +160,50 @@ void Listener::ThreadExecution() {
cprintf(GREEN,"Listener %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer);
#endif
strcpy(buffer,"changed");
int rc;
if(count == 3){
strcpy(buffer,"done\0");
while ((rc>0 && rc < generalData->packetSize)) {
rc = udpSocket->ReceiveDataOnly(buffer + generalData->fifoBufferHeaderSize,fifoBufferSize);
cprintf(BLUE,"Listening %d: rc: %d\n",index,rc);
uint64_t fnum; uint32_t pnum; uint32_t snum; uint64_t bcid;
GetHeaderInfo(index,buffer,16,fnum,pnum,snum,bcid);
cprintf(BLUE,"Listening %d: fnum:%lld, pnum:%d\n",(long long int)fnum, pnum);
*((uint32_t*)(buffer[ithread])) = (rc/generalData->packetSize);
}
if(rc <=0 ){
cprintf(BLUE,"Listening %d: Gonna send dummy value*****\n");
(*((uint32_t*)buffer)) = DUMMY_PACKET_VALUE;
StopRunning();
}
fifo->PushAddress(buffer);
count++;
}
int Listener::CreateUDPSockets(uint32_t portnumber, uint32_t packetSize, const char* eth, uint32_t headerPacketSize) {
FILE_LOG (logDEBUG) << __AT__ << " called";
udpSocket = new genericSocket(portnumber, genericSocket::UDP, packetSize, eth, headerPacketSize);
int iret = udpSocket->getErrorStatus();
if(!iret){
cout << "UDP port opened at port " << portnumber << endl;
}else{
FILE_LOG(logERROR) << "Could not create UDP socket on port " << portnumber << " error: " << iret;
return FAIL;
}
return OK;
}
void Listener::ShutDownUDPSocket() {
FILE_LOG (logDEBUG) << __AT__ << " called";
if(udpSocket){
udpSocket->ShutDownSocket();
FILE_LOG(logINFO) << "Shut down UDP Socket " << index;
delete udpSocket;
udpSocket = 0;
}
}

View File

@ -17,20 +17,20 @@ ThreadObject::ThreadObject(int ind):
alive(false),
killThread(false),
thread(0) {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
PrintMembers();
}
ThreadObject::~ThreadObject() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
DestroyThread();
}
void ThreadObject::PrintMembers() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG(logDEBUG) << "Index : " << index
FILE_LOG (logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << "Index : " << index
<< "\nalive: " << alive
<< "\nkillThread: " << killThread
<< "\npthread: " << thread;
@ -38,7 +38,7 @@ void ThreadObject::PrintMembers() {
void ThreadObject::DestroyThread() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
if(alive){
killThread = true;
sem_post(&semaphore);
@ -46,40 +46,40 @@ void ThreadObject::DestroyThread() {
sem_destroy(&semaphore);
killThread = false;
alive = false;
FILE_LOG(logDEBUG) << GetType() << " thread with index " << index << " destroyed successfully.";
FILE_LOG (logDEBUG) << GetType() << " thread with index " << index << " destroyed successfully.";
}
}
int ThreadObject::CreateThread() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
if(alive){
FILE_LOG(logERROR) << "Cannot create thread " << index << ". Already alive";
FILE_LOG (logERROR) << "Cannot create thread " << index << ". Already alive";
return FAIL;
}
sem_init(&semaphore,1,0);
killThread = false;
if(pthread_create(&thread, NULL,StartThread, (void*) this)){
FILE_LOG(logERROR) << "Could not create " << GetType() << " thread with index " << index;
FILE_LOG (logERROR) << "Could not create " << GetType() << " thread with index " << index;
return FAIL;
}
alive = true;
FILE_LOG(logINFO) << GetType() << " thread " << index << " created successfully.";
FILE_LOG (logINFO) << GetType() << " thread " << index << " created successfully.";
return OK;
}
void* ThreadObject::StartThread(void* thisPointer) {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
((ThreadObject*)thisPointer)->RunningThread();
return thisPointer;
}
void ThreadObject::RunningThread() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
while(true) {

View File

@ -39,7 +39,6 @@ void UDPBaseImplementation::initializeMembers(){
//**detector parameters***
myDetectorType = GENERIC;
strcpy(detHostname,"");
packetsPerFrame = 0;
acquisitionPeriod = 0;
acquisitionTime = 0;
numberOfFrames = 0;
@ -70,13 +69,6 @@ void UDPBaseImplementation::initializeMembers(){
overwriteEnable = true;
dataCompressionEnable = false;
//***acquisition count parameters***
totalPacketsCaught = 0;
packetsCaught = 0;
//***acquisition indices parameters***
acquisitionIndex = 0;
//***acquisition parameters***
shortFrameEnable = -1;
frameToGuiFrequency = 0;
@ -156,17 +148,11 @@ bool UDPBaseImplementation::getOverwriteEnable() const{ FILE_LOG(logDEBUG) << __
bool UDPBaseImplementation::getDataCompressionEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return dataCompressionEnable;}
/***acquisition count parameters***/
uint64_t UDPBaseImplementation::getTotalFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return (totalPacketsCaught/packetsPerFrame);}
uint64_t UDPBaseImplementation::getTotalFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return 0;}
uint64_t UDPBaseImplementation::getFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return (packetsCaught/packetsPerFrame);}
uint64_t UDPBaseImplementation::getFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return 0;}
int64_t UDPBaseImplementation::getAcquisitionIndex() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
if(!totalPacketsCaught)
return -1;
return acquisitionIndex;
}
int64_t UDPBaseImplementation::getAcquisitionIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return -1;}
/***connection parameters***/
@ -469,8 +455,7 @@ void UDPBaseImplementation::initialize(const char *c){
void UDPBaseImplementation::resetAcquisitionCount(){
FILE_LOG(logDEBUG) << __AT__ << " starting";
totalPacketsCaught = 0;
FILE_LOG(logINFO) << "totalPacketsCaught:" << totalPacketsCaught;
//overriden by resetting of new acquisition parameters
}
int UDPBaseImplementation::startReceiver(char *c){
@ -489,12 +474,9 @@ void UDPBaseImplementation::startReadout(){
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
}
int UDPBaseImplementation::shutDownUDPSockets(){
void UDPBaseImplementation::shutDownUDPSockets(){
FILE_LOG(logWARNING) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
//overridden functions might return FAIL
return OK;
}
void UDPBaseImplementation::readFrame(int ithread, char* c,char** raw, int64_t &startAcquisitionIndex, int64_t &startFrameIndex){
@ -509,7 +491,7 @@ void UDPBaseImplementation::abort(){
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
}
void UDPBaseImplementation::closeFile(int ithread){
void UDPBaseImplementation::closeFiles(){
FILE_LOG(logWARNING) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";
}

View File

@ -23,22 +23,22 @@ using namespace std;
/** cosntructor & destructor */
UDPStandardImplementation::UDPStandardImplementation() {
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG (logDEBUG) << __AT__ << " called";
InitializeMembers();
}
UDPStandardImplementation::~UDPStandardImplementation(){
FILE_LOG(logDEBUG) << __AT__ << " called";
UDPStandardImplementation::~UDPStandardImplementation() {
FILE_LOG (logDEBUG) << __AT__ << " called";
DeleteMembers();
}
void UDPStandardImplementation::DeleteMembers() {
FILE_LOG(logDEBUG) << __AT__ << " starting";
FILE_LOG (logDEBUG) << __AT__ << " starting";
if (generalData){ delete generalData; generalData=0;}
if (generalData) { delete generalData; generalData=0;}
listener.clear();
dataProcessor.clear();
dataStreamer.clear();
@ -47,8 +47,8 @@ void UDPStandardImplementation::DeleteMembers() {
}
void UDPStandardImplementation::InitializeMembers(){
FILE_LOG(logDEBUG) << __AT__ << " starting";
void UDPStandardImplementation::InitializeMembers() {
FILE_LOG (logDEBUG) << __AT__ << " starting";
UDPBaseImplementation::initializeMembers();
acquisitionPeriod = SAMPLE_TIME_IN_NS;
@ -70,90 +70,40 @@ void UDPStandardImplementation::InitializeMembers(){
}
int UDPStandardImplementation::setDetectorType(const detectorType d) {
FILE_LOG(logDEBUG) << __AT__ << " starting";
/*** Overloaded Functions called by TCP Interface ***/
numThreads = EIGER_PORTS_PER_READOUT;
numberofJobs = 1;
//killing all threads, deleting members etc.
uint64_t UDPStandardImplementation::getTotalFramesCaught() const {
FILE_LOG (logDEBUG) << __AT__ << " starting";
uint64_t sum = 0;
vector<DataProcessor*>::const_iterator it;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
sum += (*it)->GetNumTotalFramesCaught();
return (sum/dataProcessor.size());
}
uint64_t UDPStandardImplementation::getFramesCaught() const {
FILE_LOG (logDEBUG) << __AT__ << " starting";
uint64_t sum = 0;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
sum += (*it)->GetNumFramesCaught();
return (sum/dataProcessor.size());
}
//generalData = new GotthardData();
//only at start or changing parameters
for ( int i=0; i < 1; i++ ) {//numthreads; i++ ) {
bool success = true;
fifo.push_back(new Fifo(1024*256,5, success));
if (!success) cprintf(RED,"not successful\n");
listener.push_back(new Listener(fifo[i]));
dataProcessor.push_back(new DataProcessor(fifo[i]));
//dataStreamer.push_back(new DataStreamer(fifo[i]));
//listener[i]->SetFifo(fifo[i]);
//dataProcessor[i]->SetFifo(fifo[i]);
fileWriter.push_back(new BinaryFileWriter(fileName));
}
if (Listener::GetErrorMask() || DataProcessor::GetErrorMask()){
cprintf(RED, "Error in creating threads\n");
}
//start receiver functions
//create udp sockets
//create file
//reset status
//reset all masks
Listener::ResetRunningMask();
DataProcessor::ResetRunningMask();
//DataStreamer::ResetRunningMask();
for( unsigned int i=0; i < listener.size();i++ ) {
listener[i]->StartRunning();
dataProcessor[i]->StartRunning();
listener[i]->Continue();
dataProcessor[i]->Continue();
}
// for (vector<Listener*>::iterator it = listener.begin(); it != listener.end(); ++it) {
//*it->StartRunning();
usleep (5 * 1000 * 1000);
SetLocalNetworkParameters();
return OK;
int64_t UDPStandardImplementation::getAcquisitionIndex() const {
FILE_LOG (logDEBUG) << __AT__ << " starting";
//no data processed
if(!DataProcessor::GetAcquisitionStartedFlag())
return -1;
uint64_t sum = 0;
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
sum += (*it)->GetProcessedAcquisitionIndex();
return (sum/dataProcessor.size());
}
uint64_t UDPStandardImplementation::getTotalFramesCaught() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//preventing divide by 0 using ternary operator
return (totalPacketsCaught/(packetsPerFrame*(listener.size()>0?listener.size():1)));
}
uint64_t UDPStandardImplementation::getFramesCaught() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
//preventing divide by 0 using ternary operator
return (packetsCaught/(packetsPerFrame*(listener.size()>0?listener.size():1)));
}
void UDPStandardImplementation::setFileName(const char c[]){
FILE_LOG(logDEBUG) << __AT__ << " starting";
void UDPStandardImplementation::setFileName(const char c[]) {
FILE_LOG (logDEBUG) << __AT__ << " starting";
if (strlen(c)) {
strcpy(fileName, c); //automatically update fileName in Filewriter (pointer)
@ -168,12 +118,12 @@ void UDPStandardImplementation::setFileName(const char c[]){
if (detindex == -1)
detID = 0;
}
FILE_LOG(logINFO) << "File name:" << fileName;
FILE_LOG (logINFO) << "File name:" << fileName;
}
int UDPStandardImplementation::setShortFrameEnable(const int i){
FILE_LOG(logDEBUG) << __AT__ << " called";
int UDPStandardImplementation::setShortFrameEnable(const int i) {
FILE_LOG (logDEBUG) << __AT__ << " called";
if (myDetectorType != GOTTHARD) {
cprintf(RED, "Error: Can not set short frame for this detector\n");
@ -190,47 +140,47 @@ int UDPStandardImplementation::setShortFrameEnable(const int i){
else
generalData = new GotthardData();
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
if(SetupFifoStructure() == FAIL)
if (SetupFifoStructure() == FAIL)
return FAIL;
}
FILE_LOG(logINFO) << "Short Frame Enable: " << shortFrameEnable;
FILE_LOG (logINFO) << "Short Frame Enable: " << shortFrameEnable;
return OK;
}
int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t freq){
FILE_LOG(logDEBUG) << __AT__ << " called";
int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t freq) {
FILE_LOG (logDEBUG) << __AT__ << " called";
if (frameToGuiFrequency != freq){
if (frameToGuiFrequency != freq) {
frameToGuiFrequency = freq;
//only the ones lisening to more than 1 frame at a time needs to change fifo structure
switch (myDetectorType) {
case GOTTHARD:
case PROPIX:
if(SetupFifoStructure() == FAIL)
if (SetupFifoStructure() == FAIL)
return FAIL;
break;
default:
break;
}
}
FILE_LOG(logINFO) << "Frame to Gui Frequency: " << frameToGuiFrequency;
FILE_LOG (logINFO) << "Frame to Gui Frequency: " << frameToGuiFrequency;
return OK;
}
int UDPStandardImplementation::setDataStreamEnable(const bool enable){
FILE_LOG(logDEBUG) << __AT__ << " called";
int UDPStandardImplementation::setDataStreamEnable(const bool enable) {
FILE_LOG (logDEBUG) << __AT__ << " called";
if (dataStreamEnable != enable) {
dataStreamEnable = enable;
//data sockets have to be created again as the client ones are
if(dataStreamer.size())
if (dataStreamer.size())
dataStreamer.clear();
if(enable){
if (enable) {
for ( int i=0; i < numThreads; ++i ) {
dataStreamer.push_back(new DataStreamer());
if (DataStreamer::GetErrorMask()) {
@ -240,13 +190,13 @@ int UDPStandardImplementation::setDataStreamEnable(const bool enable){
}
}
}
FILE_LOG(logINFO) << "Data Send to Gui: " << dataStreamEnable;
FILE_LOG (logINFO) << "Data Send to Gui: " << dataStreamEnable;
return OK;
}
int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){
FILE_LOG(logDEBUG) << __AT__ << " called";
int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i) {
FILE_LOG (logDEBUG) << __AT__ << " called";
if (acquisitionPeriod != i) {
acquisitionPeriod = i;
@ -255,27 +205,322 @@ int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){
switch (myDetectorType) {
case GOTTHARD:
case PROPIX:
if(setupFifoStructure() == FAIL)
if (SetupFifoStructure() == FAIL)
return FAIL;
break;
case EIGER:
if (fileFormatType == BINARY)
for (int i=0; i<numThreads; ++i )
updateFileHeader(i); /*????????*/
break;
default:
break;
}
}
FILE_LOG(logINFO) << "Acquisition Period: " << (double)acquisitionPeriod/(1E9) << "s";
FILE_LOG (logINFO) << "Acquisition Period: " << (double)acquisitionPeriod/(1E9) << "s";
return OK;
}
int UDPStandardImplementation::setAcquisitionTime(const uint64_t i) {
FILE_LOG (logDEBUG) << __AT__ << " called";
if (acquisitionTime != i) {
acquisitionTime = i;
//only the ones lisening to more than 1 frame at a time needs to change fifo structure
switch (myDetectorType) {
case GOTTHARD:
case PROPIX:
if (SetupFifoStructure() == FAIL)
return FAIL;
break;
default:
break;
}
}
FILE_LOG (logINFO) << "Acquisition Period: " << (double)acquisitionTime/(1E9) << "s";
return OK;
}
int UDPStandardImplementation::setNumberOfFrames(const uint64_t i) {
FILE_LOG (logDEBUG) << __AT__ << " called";
if (numberOfFrames != i) {
numberOfFrames = i;
//only the ones lisening to more than 1 frame at a time needs to change fifo structure
switch (myDetectorType) {
case GOTTHARD:
case PROPIX:
if (SetupFifoStructure() == FAIL)
return FAIL;
break;
default:
break;
}
}
FILE_LOG (logINFO) << "Number of Frames:" << numberOfFrames;
return OK;
}
int UDPStandardImplementation::setDynamicRange(const uint32_t i) {
FILE_LOG (logDEBUG) << __AT__ << " called";
if (dynamicRange != i) {
dynamicRange = i;
//side effects
generalData->SetDynamicRange(i,tengigaEnable);
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
if (SetupFifoStructure() == FAIL)
return FAIL;
}
FILE_LOG (logINFO) << "Dynamic Range: " << dynamicRange;
return OK;
}
int UDPStandardImplementation::setTenGigaEnable(const bool b) {
FILE_LOG (logDEBUG) << __AT__ << " called";
if (tengigaEnable != b) {
tengigaEnable = b;
//side effects
generalData->SetTenGigaEnable(tengigaEnable,b);
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
if (SetupFifoStructure() == FAIL)
return FAIL;
}
FILE_LOG (logINFO) << "Ten Giga: " << stringEnable(tengigaEnable);
return OK;
}
int UDPStandardImplementation::setFifoDepth(const uint32_t i) {
FILE_LOG (logDEBUG) << __AT__ << " called";
if (fifoDepth != i) {
fifoDepth = i;
numberofJobs = -1; //changes to imagesize has to be noted to recreate fifo structure
if (SetupFifoStructure() == FAIL)
return FAIL;
}
FILE_LOG (logINFO) << "Fifo Depth: " << i << endl;
return OK;
}
int UDPStandardImplementation::setDetectorType(const detectorType d) {
FILE_LOG (logDEBUG) << __AT__ << " starting";
void UDPStandardImplementation::SetLocalNetworkParameters(){
FILE_LOG (logDEBUG) << "Setting receiver type";
DeleteMembers();
InitializeMembers();
myDetectorType = d;
switch(myDetectorType) {
case GOTTHARD:
case PROPIX:
case MOENCH:
case EIGER:
case JUNGFRAUCTB:
case JUNGFRAU:
FILE_LOG (logINFO) << " ***** " << getDetectorType(d) << " Receiver *****";
break;
default:
FILE_LOG (logERROR) << "This is an unknown receiver type " << (int)d;
return FAIL;
}
//set detector specific variables
switch(myDetectorType) {
case GOTTHARD: generalData = new GotthardData(); break;
case PROPIX: generalData = new PropixData(); break;
case MOENCH: generalData = new Moench02Data(); break;
case EIGER: generalData = new EigerData(); break;
case JUNGFRAUCTB: generalData = new JCTBData(); break;
case JUNGFRAU: generalData = new JungfrauData(); break;
default: break;
}
numThreads = generalData->threadsPerReceiver;
for ( int i=0; i < numThreads; ++i ) {
//create fifo structure
numberofJobs = -1;
if (SetupFifoStructure() == FAIL) {
FILE_LOG (logERROR) << "Error: Could not allocate memory for fifo (index:" << i << ")";
return FAIL;
}
//create threads
listener.push_back(new Listener(fifo[i]));
dataProcessor.push_back(new DataProcessor(fifo[i]));
if (Listener::GetErrorMask() || DataProcessor::GetErrorMask()) {
FILE_LOG (logERROR) << "Error: Could not creates listener/dataprocessor threads (index:" << i << ")";
return FAIL;
}
}
//local network parameters
SetLocalNetworkParameters();
FILE_LOG (logDEBUG) << " Detector type set to " << getDetectorType(d);
return OK;
}
void UDPStandardImplementation::resetAcquisitionCount() {
FILE_LOG (logDEBUG) << __AT__ << " starting";
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->ResetParametersforNewAcquisition();
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->ResetParametersforNewAcquisition();
FILE_LOG (logINFO) << "Acquisition Count has been reset";
}
int UDPStandardImplementation::startReceiver(char *c) {
FILE_LOG (logDEBUG) << __AT__ << " called";
ResetParametersforNewMeasurement();
if (CreateUDPSockets() == FAIL) {
strcpy(c,"Could not create UDP Socket(s).");
FILE_LOG(logERROR) << c;
return FAIL;
}
if(fileWriteEnable){
if (SetupWriter() == FAIL) {
strcpy(c,"Could not create file.");
FILE_LOG(logERROR) << c;
return FAIL;
}
}
//Let Threads continue to be ready for acquisition
StartRunning();
FILE_LOG(logINFO) << "Receiver Started";
FILE_LOG(logINFO) << "Status: " << runStatusType(status);
}
void UDPStandardImplementation::stopReceiver(){
FILE_LOG(logDEBUG) << __AT__ << " called";
FILE_LOG(logINFO) << "Stopping Receiver";
//set status to transmitting
startReadout();
//wait until status is run_finished
while(status == TRANSMITTING){
usleep(5000);
}
/* //change status
pthread_mutex_lock(&statusMutex);
status = IDLE;
pthread_mutex_unlock(&(statusMutex));
*/
FILE_LOG(logINFO) << "Receiver Stopped";
FILE_LOG(logINFO) << "Status: " << runStatusType(status);
cout << endl << endl;
}
void UDPStandardImplementation::startReadout(){
FILE_LOG(logDEBUG) << __AT__ << " called";
if(status == RUNNING){
//needs to wait for packets only if activated
if(activated){
//current packets caught
int totalP = 0,prev=-1;
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
totalP += (*it)->GetTotalPacketsCaught();
//current udp buffer received
int currentReceivedInBuffer=0,prevReceivedInBuffer=-1;
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
currentReceivedInBuffer += (*it)->GetNumReceivedinUDPBuffer();
//wait for all packets
if((unsigned long long int)totalP!=numberOfFrames*generalData->packetsPerFrame*listener.size()){
//wait as long as there is change from prev totalP,
//and also change from received in buffer to previous value
//(as one listens to many at a time, shouldnt cut off in between)
while((prev != totalP) || (prevReceivedInBuffer!= currentReceivedInBuffer)){
#ifdef VERY_VERBOSE
cprintf(MAGENTA,"waiting for all packets prevP:%d totalP:%d PrevBuffer:%d currentBuffer:%d\n",prev,totalP,prevReceivedInBuffer,currentReceivedInBuffer);
#endif
//usleep(2*1000*1000);
usleep(5*1000);/* Need to find optimal time **/
prev = totalP;
totalP = 0;
prevReceivedInBuffer = currentReceivedInBuffer;
currentReceivedInBuffer = 0;
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it) {
totalP += (*it)->GetTotalPacketsCaught();
currentReceivedInBuffer += (*it)->GetNumReceivedinUDPBuffer();
}
#ifdef VERY_VERBOSE
cprintf(MAGENTA,"\tupdated: totalP:%d currently in buffer:%d\n",totalP,currentReceivedInBuffer);
#endif
}
}
}
/*//set status
pthread_mutex_lock(&statusMutex);
status = TRANSMITTING;
pthread_mutex_unlock(&statusMutex);*/
FILE_LOG(logINFO) << "Status: Transmitting";
}
//shut down udp sockets so as to make listeners push dummy (end) packets for processors
shutDownUDPSockets();
}
void UDPStandardImplementation::shutDownUDPSockets() {
FILE_LOG (logDEBUG) << __AT__ << " called";
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->ShutDownUDPSocket();
}
void UDPStandardImplementation::closeFiles() {
FILE_LOG (logDEBUG) << __AT__ << " called";
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->CloseFile();
}
void UDPStandardImplementation::SetLocalNetworkParameters() {
FILE_LOG (logDEBUG) << __AT__ << " called";
//to increase socket receiver buffer size and max length of input queue by changing kernel settings
if (myDetectorType == EIGER)
@ -285,30 +530,30 @@ void UDPStandardImplementation::SetLocalNetworkParameters(){
//to increase Socket Receiver Buffer size
sprintf(command,"echo $((%d)) > /proc/sys/net/core/rmem_max",RECEIVE_SOCKET_BUFFER_SIZE);
if (system(command)){
FILE_LOG(logWARNING) << "No root permission to change Socket Receiver Buffer size (/proc/sys/net/core/rmem_max)";
if (system(command)) {
FILE_LOG (logWARNING) << "No root permission to change Socket Receiver Buffer size (/proc/sys/net/core/rmem_max)";
return;
}
FILE_LOG(logINFO) << "Socket Receiver Buffer size (/proc/sys/net/core/rmem_max) modified to " << RECEIVE_SOCKET_BUFFER_SIZE ;
FILE_LOG (logINFO) << "Socket Receiver Buffer size (/proc/sys/net/core/rmem_max) modified to " << RECEIVE_SOCKET_BUFFER_SIZE ;
// to increase Max length of input packet queue
sprintf(command,"echo %d > /proc/sys/net/core/netdev_max_backlog",MAX_SOCKET_INPUT_PACKET_QUEUE);
if (system(command)){
FILE_LOG(logWARNING) << "No root permission to change Max length of input packet queue (/proc/sys/net/core/netdev_max_backlog)";
if (system(command)) {
FILE_LOG (logWARNING) << "No root permission to change Max length of input packet queue (/proc/sys/net/core/netdev_max_backlog)";
return;
}
FILE_LOG(logINFO) << "Max length of input packet queue (/proc/sys/net/core/netdev_max_backlog) modified to " << MAX_SOCKET_INPUT_PACKET_QUEUE ;
FILE_LOG (logINFO) << "Max length of input packet queue (/proc/sys/net/core/netdev_max_backlog) modified to " << MAX_SOCKET_INPUT_PACKET_QUEUE ;
}
int UDPStandardImplementation::SetupFifoStructure(){
FILE_LOG(logDEBUG) << __AT__ << " called";
int UDPStandardImplementation::SetupFifoStructure() {
FILE_LOG (logDEBUG) << __AT__ << " called";
//recalculate number of jobs & fifodepth, return if no change
if ((myDetectortype == GOTTHARD) || (myDetectortype = PROPIX)) {
if ((myDetectorType == GOTTHARD) || (myDetectorType = PROPIX)) {
int oldnumberofjobs = numberofJobs;
//listen to only n jobs at a time
@ -316,38 +561,40 @@ int UDPStandardImplementation::SetupFifoStructure(){
numberofJobs = frameToGuiFrequency;
else {
//random freq depends on acquisition period/time (calculate upto 100ms/period)
i = ((acquisitionPeriod > 0) ?
int i = ((acquisitionPeriod > 0) ?
(SAMPLE_TIME_IN_NS/acquisitionPeriod):
((acquisitionTime > 0) ? (SAMPLE_TIME_IN_NS/acquisitionTime) : SAMPLE_TIME_IN_NS));
//must be > 0 and < max jobs
numberofJobs = ((i < 1) ? 1 : ((i > MAX_JOBS_PER_THREAD) ? MAX_JOBS_PER_THREAD : i));
}
FILE_LOG(logINFO) << "Number of Jobs Per Thread:" << numberofJobs << endl;
FILE_LOG (logINFO) << "Number of Jobs Per Thread:" << numberofJobs << endl;
uint32_t oldfifodepth = fifoDepth;
//reduce fifo depth if numberofJobsPerBuffer > 1 (to save memory)
if(numberofJobsPerBuffer >1){
fifoDepth = ((fifoDepth % numberofJobsPerBuffer) ?
((fifoDepth/numberofJobsPerBuffer)+1) : //if not directly divisible
(fifoDepth/numberofJobsPerBuffer));
if (numberofJobs >1) {
fifoDepth = ((fifoDepth % numberofJobs) ?
((fifoDepth/numberofJobs)+1) : //if not directly divisible
(fifoDepth/numberofJobs));
}
FILE_LOG(logINFO) << "Total Fifo Size:" << fifoSize;
FILE_LOG (logINFO) << "Total Fifo Depth Recalculated:" << fifoDepth;
//no change, return
if ((oldnumberofjobs == numberofJobs) && (oldfifodepth == fifoDepth))
return OK;
}
}else
numberofJobs = 1;
//delete fifostructure
//create fifostructure
fifo.clear();
for ( int i=0; i < numThreads; i++ ) {
//create fifo structure
bool success = true;
fifo.push_back( new Fifo ((generalData->fifoBufferSize) * numberofJobs + (generalData->fifoBufferHeaderSize), success));
if (!success){
fifo.push_back( new Fifo (
(generalData->fifoBufferSize) * numberofJobs + (generalData->fifoBufferHeaderSize),
fifoDepth, success));
if (!success) {
cprintf(BG_RED,"Error: Could not allocate memory for listening \n");
return FAIL;
}
@ -356,7 +603,82 @@ int UDPStandardImplementation::SetupFifoStructure(){
listener[i]->SetFifo(fifo[i]);
dataProcessor[i]->SetFifo(fifo[i]);
}
FILE_LOG(logINFO) << "Fifo structure(s) reconstructed";
FILE_LOG (logINFO) << "Fifo structure(s) reconstructed";
return OK;
}
void UDPStandardImplementation::ResetParametersforNewMeasurement() {
FILE_LOG (logDEBUG) << __AT__ << " called";
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it)
(*it)->ResetParametersforNewMeasurement();
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it)
(*it)->ResetParametersforNewMeasurement();
}
int UDPStandardImplementation::CreateUDPSockets() {
FILE_LOG (logDEBUG) << __AT__ << " called";
shutDownUDPSockets();
//if eth is mistaken with ip address
if (strchr(eth,'.') != NULL){
strcpy(eth,"");
}
if(!strlen(eth)){
FILE_LOG(logWARNING) << "eth is empty. Listening to all";
}
bool error = false;
for (unsigned int i = 0; i < listener.size(); ++i)
if (listener[i]->CreateUDPSockets(udpPortNum[i], generalData->packetSize,
(strlen(eth)?eth:NULL), generalData->headerPacketSize) == FAIL) {
error = true;
break;
}
if (error) {
shutDownUDPSockets();
return FAIL;
}
FILE_LOG(logDEBUG) << "UDP socket(s) created successfully.";
cout << "Listener Ready ..." << endl;
return OK;
}
int UDPStandardImplementation::SetupWriter() {
FILE_LOG (logDEBUG) << __AT__ << " called";
bool error = false;
for (unsigned int i = 0; i < dataProcessor.size(); ++i)
if (dataProcessor[i]->CreateNewFile() == FAIL) {
error = true;
break;
}
if (error) {
shutDownUDPSockets();
closeFiles();
return FAIL;
}
cout << "Writer Ready ..." << endl;
return OK;
}
void UDPStandardImplementation::StartRunning() {
FILE_LOG (logDEBUG) << __AT__ << " called";
//set running mask and post semaphore to start the inner loop in execution thread
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it) {
(*it)->StartRunning();
(*it)->Continue();
}
for (vector<DataProcessor*>::const_iterator it = dataProcessor.begin(); it != dataProcessor.end(); ++it){
(*it)->StartRunning();
(*it)->Continue();
}
}

View File

@ -32,9 +32,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface*
receiverBase(rbase),
ret(OK),
lockStatus(0),
shortFrame(-1),
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
dynamicrange(16),
killTCPServerThread(0),
tenGigaEnable(0),
portNumber(DEFAULT_PORTNO+2),
@ -195,7 +192,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){
receiverBase->shutDownUDPSockets();
cout << "Closing Files... " << endl;
receiverBase->closeFile();
receiverBase->closeFiles();
}
mySock->exitServer();
@ -334,7 +331,7 @@ int slsReceiverTCPIPInterface::M_nofunc(){
void slsReceiverTCPIPInterface::closeFile(int p){
receiverBase->closeFile();
receiverBase->closeFiles();
}
@ -1098,11 +1095,6 @@ int slsReceiverTCPIPInterface::set_short_frame() {
else{
receiverBase->setShortFrameEnable(index);
retval = receiverBase->getShortFrameEnable();
shortFrame = retval;
if(shortFrame==-1)
packetsPerFrame=GOTTHARD_PACKETS_PER_FRAME;
else
packetsPerFrame=GOTTHARD_SHORT_PACKETS_PER_FRAME;
}
}
#endif
@ -1144,940 +1136,39 @@ int slsReceiverTCPIPInterface::read_frame(){
int slsReceiverTCPIPInterface::moench_read_frame(){
ret=OK;
char fName[MAX_STR_LENGTH]="";
int acquisitionIndex = -1;
int frameIndex= -1;
int i;
int slsReceiverTCPIPInterface::moench_read_frame(){ return FAIL;}
int bufferSize = MOENCH_BUFFER_SIZE;
int rnel = bufferSize/(sizeof(int));
int* retval = new int[rnel];
int* origVal = new int[rnel];
//all initialized to 0
for(i=0;i<rnel;i++) retval[i]=0;
for(i=0;i<rnel;i++) origVal[i]=0;
char* raw;
int64_t startAcquisitionIndex=0;
int64_t startFrameIndex=0;
uint32_t index = -1,bindex = 0, offset=0;
int slsReceiverTCPIPInterface::gotthard_read_frame(){ return FAIL;}
strcpy(mess,"Could not read frame\n");
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL){
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
ret=FAIL;
}
/**send garbage with -1 index to try again*/
else if(!receiverBase->getFramesCaught()){
startAcquisitionIndex = -1;
cout<<"haven't caught any frame yet"<<endl;
}
else{
ret = OK;
receiverBase->readFrame(0,fName,&raw,startAcquisitionIndex,startFrameIndex);
/**send garbage with -1 index to try again*/
if (raw == NULL){
startAcquisitionIndex = -1;
#ifdef VERYVERBOSE
cout<<"data not ready for gui yet"<<endl;
#endif
}
else{
bindex = ((uint32_t)(*((uint32_t*)raw)));
memcpy(origVal,raw + HEADER_SIZE_NUM_TOT_PACKETS,bufferSize);
raw=NULL;
//************** packet number order**********************
index = ((bindex & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET);
int slsReceiverTCPIPInterface::propix_read_frame(){ return FAIL;}
uint32_t numPackets = MOENCH_PACKETS_PER_FRAME; //40
uint32_t onePacketSize = MOENCH_DATA_BYTES / MOENCH_PACKETS_PER_FRAME; //1280*40 / 40 = 1280
uint32_t packetDatabytes_row = onePacketSize * (MOENCH_BYTES_IN_ONE_ROW / MOENCH_BYTES_PER_ADC); //1280 * 4 = 5120
uint32_t partsPerFrame = onePacketSize / MOENCH_BYTES_PER_ADC; // 1280 / 80 = 16
uint32_t packetOffset = 0;
int packetIndex,x,y;
int iPacket = 0;
offset = 4;
while (iPacket < (int)numPackets){
#ifdef VERYVERBOSE
printf("iPacket:%d\n",iPacket);cout << endl;
#endif
//if missing packets, dont send to gui
bindex = (*((uint32_t*)(((char*)origVal)+packetOffset)));
if (bindex == 0xFFFFFFFF){
cout << "Missing Packet,Not sending to gui" << endl;
index = startAcquisitionIndex - 1;
break;//use continue and change index above if you want to display missing packets with 0 value anyway in gui
}
packetIndex = bindex & MOENCH_PACKET_INDEX_MASK;
//cout<<"packetIndex:"<<packetIndex<<endl;
//the first packet is placed in the end
packetIndex--;
if(packetIndex ==-1)
packetIndex = 39;
//cout<<"packetIndexM:"<<packetIndex<<endl;
//check validity
if ((packetIndex >= 40) && (packetIndex < 0))
cout << "cannot decode packet index:" << packetIndex << endl;
else{
x = packetIndex / 10;
y = packetIndex % 10;
#ifdef VERYVERBOSE
cout<<"x:"<<x<<" y:"<<y<<endl;
#endif
//copy 16 times 80 bytes
for (i = 0; i < (int)partsPerFrame; i++) {
memcpy((((char*)retval) +
y * packetDatabytes_row +
i * MOENCH_BYTES_IN_ONE_ROW +
x * MOENCH_BYTES_PER_ADC),
(((char*) origVal) +
iPacket * offset +
iPacket * onePacketSize +
i * MOENCH_BYTES_PER_ADC + 4) ,
MOENCH_BYTES_PER_ADC);
}
}
//increment
offset=6;
iPacket++;
packetOffset = packetOffset + offset + onePacketSize;
//check if same frame number
}
acquisitionIndex = index-startAcquisitionIndex;
if(acquisitionIndex == -1)
startFrameIndex = -1;
else
frameIndex = index-startFrameIndex;
#ifdef VERY_VERY_DEBUG
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
cout << "frameIndex calculated is:" << frameIndex << endl;
cout << "index:" << index << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
#endif
}
}
int slsReceiverTCPIPInterface::eiger_read_frame(){ return FAIL;}
#ifdef VERYVERBOSE
cout << "fName:" << fName << endl;
cout << "acquisitionIndex:" << acquisitionIndex << endl;
cout << "frameIndex:" << frameIndex << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
#endif
#endif
if(ret==OK && mySock->differentClients){
FILE_LOG(logDEBUG) << "Force update";
ret=FORCE_UPDATE;
}
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL){
cprintf(RED,"%s\n",mess);
mySock->SendDataOnly(mess,sizeof(mess));
}
else{
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
mySock->SendDataOnly(retval,MOENCH_DATA_BYTES);
}
//return ok/fail
delete [] retval;
delete [] origVal;
delete [] raw;
return ret;
}
int slsReceiverTCPIPInterface::gotthard_read_frame(){
ret=OK;
char fName[MAX_STR_LENGTH]="";
int acquisitionIndex = -1;
int frameIndex= -1;
int i;
//retval is a full frame
int bufferSize = GOTTHARD_BUFFER_SIZE;
int rnel = bufferSize/(sizeof(int));
int* retval = new int[rnel];
int* origVal = new int[rnel];
//all initialized to 0
for(i=0;i<rnel;i++) retval[i]=0;
for(i=0;i<rnel;i++) origVal[i]=0;
//only for full frames
int onebuffersize = GOTTHARD_BUFFER_SIZE/GOTTHARD_PACKETS_PER_FRAME;
int onedatasize = GOTTHARD_DATA_BYTES/GOTTHARD_PACKETS_PER_FRAME;
//depending on shortframe or not
if(shortFrame!=-1)
bufferSize=GOTTHARD_SHORT_BUFFER_SIZE;
char* raw;
uint32_t index=-1,index2=0;
uint32_t pindex=0,pindex2=0;
uint32_t bindex=0,bindex2=0;
int64_t startAcquisitionIndex=0;
int64_t startFrameIndex=0;
strcpy(mess,"Could not read frame\n");
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL){
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
ret=FAIL;
}
/**send garbage with -1 index to try again*/
else if(!receiverBase->getFramesCaught()){
startAcquisitionIndex=-1;
cout<<"haven't caught any frame yet"<<endl;
}else{
ret = OK;
receiverBase->readFrame(0,fName,&raw,startAcquisitionIndex,startFrameIndex);
/**send garbage with -1 index to try again*/
if (raw == NULL){
startAcquisitionIndex = -1;
#ifdef VERYVERBOSE
cout<<"data not ready for gui yet"<<endl;
#endif
}else{
if(shortFrame!=-1){
bindex = (uint32_t)(*((uint32_t*)raw));
pindex = (bindex & GOTTHARD_SHORT_PACKET_INDEX_MASK);
index = ((bindex & GOTTHARD_SHORT_FRAME_INDEX_MASK) >> GOTTHARD_SHORT_FRAME_INDEX_OFFSET);
#ifdef VERYVERBOSE
cout << "index:" << hex << index << endl;
#endif
}else{
bindex = ((uint32_t)(*((uint32_t*)raw)))+1;
pindex = (bindex & GOTTHARD_PACKET_INDEX_MASK);
index = ((bindex & GOTTHARD_FRAME_INDEX_MASK) >> GOTTHARD_FRAME_INDEX_OFFSET);
bindex2 = ((uint32_t)(*((uint32_t*)((char*)(raw+onebuffersize)))))+1;
pindex2 =(bindex2 & GOTTHARD_PACKET_INDEX_MASK);
index2 =((bindex2 & GOTTHARD_FRAME_INDEX_MASK) >> GOTTHARD_FRAME_INDEX_OFFSET);
#ifdef VERYVERBOSE
cout << "index1:" << hex << index << endl;
cout << "index2:" << hex << index << endl;
#endif
}
memcpy(origVal,raw + HEADER_SIZE_NUM_TOT_PACKETS,bufferSize);
raw=NULL;
//1 adc
if(shortFrame!=-1){
if(bindex != 0xFFFFFFFF)
memcpy((((char*)retval)+(GOTTHARD_SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, GOTTHARD_SHORT_DATABYTES);
else{
index = startAcquisitionIndex - 1;
cout << "Missing Packet,Not sending to gui" << endl;
}
}
//all adc
else{
/*//ignore if half frame is missing
if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){*/
//should be same frame
if (index == index2){
//ideal situation (should be odd, even(index+1))
if(!pindex){
memcpy(retval,((char*) origVal)+4, onedatasize);
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
}
//swap to even,odd
else{
memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize);
memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize);
index=index2;
}
}else
cout << "different frames caught. frame1:"<< hex << index << ":"<<pindex<<" frame2:" << hex << index2 << ":"<<pindex2<<endl;
/*}
else{
index = startIndex - 1;
cout << "Missing Packet,Not sending to gui" << endl;
}*/
}
acquisitionIndex = index-startAcquisitionIndex;
if(acquisitionIndex == -1)
startFrameIndex = -1;
else
frameIndex = index-startFrameIndex;
#ifdef VERY_VERY_DEBUG
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
cout << "frameIndex calculated is:" << frameIndex << endl;
cout << "index:" << index << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
#endif
}
}
#ifdef VERYVERBOSE
if(frameIndex!=-1){
cout << "fName:" << fName << endl;
cout << "acquisitionIndex:" << acquisitionIndex << endl;
cout << "frameIndex:" << frameIndex << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
}
#endif
#endif
if(ret==OK && mySock->differentClients){
FILE_LOG(logDEBUG) << "Force update";
ret=FORCE_UPDATE;
}
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL){
cprintf(RED,"%s\n",mess);
mySock->SendDataOnly(mess,sizeof(mess));
}
else{
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
mySock->SendDataOnly(retval,GOTTHARD_DATA_BYTES);
}
delete [] retval;
delete [] origVal;
delete [] raw;
return ret;
}
int slsReceiverTCPIPInterface::propix_read_frame(){
ret=OK;
char fName[MAX_STR_LENGTH]="";
int acquisitionIndex = -1;
int frameIndex= -1;
int i;
//retval is a full frame
int bufferSize = PROPIX_BUFFER_SIZE;
int onebuffersize = bufferSize/PROPIX_PACKETS_PER_FRAME;
int onedatasize = PROPIX_DATA_BYTES;
char* raw;
int rnel = bufferSize/(sizeof(int));
int* retval = new int[rnel];
int* origVal = new int[rnel];
//all initialized to 0
for(i=0;i<rnel;i++) retval[i]=0;
for(i=0;i<rnel;i++) origVal[i]=0;
uint32_t index=-1,index2=0;
uint32_t pindex=0,pindex2=0;
uint32_t bindex=0,bindex2=0;
int64_t startAcquisitionIndex=0;
int64_t startFrameIndex=0;
strcpy(mess,"Could not read frame\n");
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL){
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
ret=FAIL;
}
/**send garbage with -1 index to try again*/
else if(!receiverBase->getFramesCaught()){
startAcquisitionIndex=-1;
cout<<"haven't caught any frame yet"<<endl;
}else{
ret = OK;
receiverBase->readFrame(0,fName,&raw,startAcquisitionIndex,startFrameIndex);
/**send garbage with -1 index to try again*/
if (raw == NULL){
startAcquisitionIndex = -1;
#ifdef VERYVERBOSE
cout<<"data not ready for gui yet"<<endl;
#endif
}else{
bindex = ((uint32_t)(*((uint32_t*)raw)))+1;
pindex = (bindex & PROPIX_PACKET_INDEX_MASK);
index = ((bindex & PROPIX_FRAME_INDEX_MASK) >> PROPIX_FRAME_INDEX_OFFSET);
bindex2 = ((uint32_t)(*((uint32_t*)((char*)(raw+onebuffersize)))))+1;
pindex2 =(bindex2 & PROPIX_PACKET_INDEX_MASK);
index2 =((bindex2 & PROPIX_FRAME_INDEX_MASK) >> PROPIX_FRAME_INDEX_OFFSET);
#ifdef VERYVERBOSE
cout << "index1:" << hex << index << endl;
cout << "index2:" << hex << index << endl;
#endif
memcpy(origVal,raw + HEADER_SIZE_NUM_TOT_PACKETS,bufferSize);
raw=NULL;
/*//ignore if half frame is missing
if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){*/
//should be same frame
if (index == index2){
//ideal situation (should be odd, even(index+1))
if(!pindex){
memcpy(retval,((char*) origVal)+4, onedatasize);
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
}
//swap to even,odd
else{
memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize);
memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize);
index=index2;
}
}else
cout << "different frames caught. frame1:"<< hex << index << ":"<<pindex<<" frame2:" << hex << index2 << ":"<<pindex2<<endl;
/*}
else{
index = startIndex - 1;
cout << "Missing Packet,Not sending to gui" << endl;
}*/
acquisitionIndex = index-startAcquisitionIndex;
if(acquisitionIndex == -1)
startFrameIndex = -1;
else
frameIndex = index-startFrameIndex;
#ifdef VERY_VERY_DEBUG
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
cout << "frameIndex calculated is:" << frameIndex << endl;
cout << "index:" << index << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
#endif
}
}
#ifdef VERYVERBOSE
if(frameIndex!=-1){
cout << "fName:" << fName << endl;
cout << "acquisitionIndex:" << acquisitionIndex << endl;
cout << "frameIndex:" << frameIndex << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
}
#endif
#endif
if(ret==OK && mySock->differentClients){
FILE_LOG(logDEBUG) << "Force update";
ret=FORCE_UPDATE;
}
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL){
cprintf(RED,"%s\n",mess);
mySock->SendDataOnly(mess,sizeof(mess));
}
else{
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
mySock->SendDataOnly(retval,PROPIX_DATA_BYTES);
}
delete [] retval;
delete [] origVal;
delete [] raw;
return ret;
}
int slsReceiverTCPIPInterface::eiger_read_frame(){
ret=OK;
/*
char fName[MAX_STR_LENGTH]="";
int acquisitionIndex = -1;
int frameIndex= -1;
int index=0;
int subframenumber=-1;
int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame * EIGER_MAX_PORTS;
int dataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE * packetsPerFrame * EIGER_MAX_PORTS;
int oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE;
int onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE;
if(tenGigaEnable){
frameSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE * packetsPerFrame * EIGER_MAX_PORTS;
dataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE * packetsPerFrame * EIGER_MAX_PORTS;
oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE;
onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE;
}
char* raw;
char* origVal = new char[frameSize]();
char* retval = new char[dataSize]();
memset(origVal,0xFF,frameSize);
memset(retval,0xFF,dataSize);
int64_t startAcquisitionIndex=0;
int64_t startFrameIndex=0;
strcpy(mess,"Could not read frame\n");
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL){
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
ret=FAIL;
}
//send garbage with -1 index to try again
else if(!receiverBase->getFramesCaught()){
startAcquisitionIndex=-1;
#ifdef VERYVERBOSE
cout<<"haven't caught any frame yet"<<endl;
#endif
}
// acq started
else{
ret = OK;
int fnum[EIGER_MAX_PORTS];
for(int i=0;i<EIGER_MAX_PORTS;i++)
fnum[i] = -1;
//read a frame
for(int i=0;i<EIGER_MAX_PORTS;i++){
receiverBase->readFrame(i,fName,&raw,startAcquisitionIndex,startFrameIndex);
//send garbage with -1 index to try again
if (raw == NULL){
startAcquisitionIndex = -1;
#ifdef VERYVERBOSE
cout<<"data not ready for gui yet for "<< i << endl;
#endif
raw=NULL;
break;
}
else{
eiger_packet_footer_t* wbuf_footer;
wbuf_footer = (eiger_packet_footer_t*)(raw + HEADER_SIZE_NUM_TOT_PACKETS + oneDataSize + sizeof(eiger_packet_header_t));
index =(uint32_t)(*( (uint64_t*) wbuf_footer));
index += (startFrameIndex-1);
fnum[i] = index;
if(dynamicrange == 32){
eiger_packet_header_t* wbuf_header;
wbuf_header = (eiger_packet_header_t*) (raw + HEADER_SIZE_NUM_TOT_PACKETS);
subframenumber = *( (uint32_t*) wbuf_header->subFrameNumber);
}
#ifdef VERYVERBOSE
cout << "index:" << dec << index << endl;
cout << "subframenumber:" << dec << subframenumber << endl;
#endif
int numpackets = (uint32_t)(*( (uint32_t*) raw));
memcpy(((char*)origVal)+(i*onePacketSize*packetsPerFrame),raw + HEADER_SIZE_NUM_TOT_PACKETS,numpackets*onePacketSize);
raw=NULL;
}
}
//proper frame
if(startAcquisitionIndex != -1){
//cout<<"**** got proper frame ******"<<endl;
//let them continue
//for(int i=0;i<EIGER_MAX_PORTS;++i)
//receiverBase->resetGuiPointer(i);
if(fnum[0]!=fnum[1])
cprintf(BG_RED,"Fnums differ %d and %d\n",fnum[0],fnum[1]);
int c1=8;//first port
int c2=(frameSize/2) + 8; //second port
int retindex=0;
int irow,ibytesperpacket;
int linesperpacket = (16*1/dynamicrange);// 16:1 line, 8:2 lines, 4:4 lines, 32: 0.5
int numbytesperlineperport=(EIGER_PIXELS_IN_ONE_ROW/EIGER_MAX_PORTS)*dynamicrange/8;//16:1024,8:512,4:256,32:2048
int datapacketlength = EIGER_ONE_GIGA_ONE_DATA_SIZE;
int total_num_bytes = EIGER_ONE_GIGA_ONE_PACKET_SIZE *(EIGER_ONE_GIGA_CONSTANT *dynamicrange)*2;
if(tenGigaEnable){
linesperpacket = (16*4/dynamicrange);// 16:4 line, 8:8 lines, 4:16 lines, 32: 2
datapacketlength = EIGER_TEN_GIGA_ONE_DATA_SIZE;
total_num_bytes = EIGER_TEN_GIGA_ONE_PACKET_SIZE*(EIGER_TEN_GIGA_CONSTANT*dynamicrange)*2;
}
//if 1GbE, one line is split into two packets for 32 bit mode, so its special
else if(dynamicrange == 32){
numbytesperlineperport = 1024;
linesperpacket = 1; //we repeat this twice anyway for 32 bit
}
if(!bottom){
for(irow=0;irow<EIGER_PIXELS_IN_ONE_COL/linesperpacket;++irow){
ibytesperpacket=0;
while(ibytesperpacket<datapacketlength){
//first port
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c1 += numbytesperlineperport;
if(dynamicrange == 32 && !tenGigaEnable){
c1 += 16;
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c1 += numbytesperlineperport;
c1 += 16;
}
//second port
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c2 += numbytesperlineperport;
if(dynamicrange == 32 && !tenGigaEnable){
c2 += 16;
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c2 += numbytesperlineperport;
c2 += 16;
}
ibytesperpacket += numbytesperlineperport;
}
if(dynamicrange != 32 || tenGigaEnable) {
c1 += 16;
c2 += 16;
}
}
}
//bottom half module
else{
c1 = (frameSize/2) - numbytesperlineperport - 8 ;
c2 = total_num_bytes - numbytesperlineperport - 8;
for(irow=0;irow<EIGER_PIXELS_IN_ONE_COL/linesperpacket;++irow){
ibytesperpacket=0;
while(ibytesperpacket<datapacketlength){
if(dynamicrange == 32 && !tenGigaEnable){
//first port first chip
c1 -= (numbytesperlineperport + 16);
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
//first port second chip
c1 += (numbytesperlineperport+16);
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c1 -= (numbytesperlineperport*2+32);//1024*2+16*2
//second port first chip
c2 -= (numbytesperlineperport + 16);
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport;
//second port second chip
c2 += (numbytesperlineperport + 16);
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c2 -= (numbytesperlineperport*2+32);
}else{
//first port
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c1 -= numbytesperlineperport;
//second port
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
retindex += numbytesperlineperport;
c2 -= numbytesperlineperport;
}
ibytesperpacket += numbytesperlineperport;
}
if(dynamicrange != 32 || tenGigaEnable) {
c1 -= 16;
c2 -= 16;
}
}
}
acquisitionIndex = index-startAcquisitionIndex;
if(acquisitionIndex == -1)
startFrameIndex = -1;
else
frameIndex = index-startFrameIndex;
#ifdef VERY_VERY_DEBUG
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
cout << "frameIndex calculated is:" << frameIndex << endl;
cout << "index:" << index << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
cout << "subframenumber:" << subframenumber << endl;
#endif
}
}
#ifdef VERYVERBOSE
if(frameIndex!=-1){
cout << "fName:" << fName << endl;
cout << "acquisitionIndex:" << acquisitionIndex << endl;
cout << "frameIndex:" << frameIndex << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
cout << "subframenumber:" << subframenumber << endl;
}
#endif
#endif
if(ret==OK && mySock->differentClients){
FILE_LOG(logDEBUG) << "Force update";
ret=FORCE_UPDATE;
}
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL){
cprintf(RED,"%s\n",mess);
mySock->SendDataOnly(mess,sizeof(mess));
}
else{
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
mySock->SendDataOnly(&subframenumber,sizeof(subframenumber));
mySock->SendDataOnly(retval,dataSize);
}
delete [] retval;
delete [] origVal;
delete [] raw;
*/
return ret;
}
int slsReceiverTCPIPInterface::jungfrau_read_frame(){
ret=OK;
char fName[MAX_STR_LENGTH]="";
int acquisitionIndex = -1;
int frameIndex= -1;
int64_t currentIndex=0;
int64_t startAcquisitionIndex=0;
int64_t startFrameIndex=0;
strcpy(mess,"Could not read frame\n");
int frameSize = JFRAU_ONE_PACKET_SIZE * packetsPerFrame;
int dataSize = JFRAU_ONE_DATA_SIZE * packetsPerFrame;
int oneDataSize = JFRAU_ONE_DATA_SIZE;
char* raw;
char* origVal = new char[frameSize]();
char* retval = new char[dataSize]();
char* blackpacket = new char[oneDataSize]();
for(int i=0;i<oneDataSize;i++)
blackpacket[i]='0';
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL){
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
ret=FAIL;
}
//send garbage with -1 currentIndex to try again
else if(!receiverBase->getFramesCaught()){
startAcquisitionIndex=-1;
#ifdef VERYVERBOSE
cout<<"haven't caught any frame yet"<<endl;
#endif
}
// acq started
else{
ret = OK;
//read a frame
receiverBase->readFrame(0,fName,&raw,startAcquisitionIndex,startFrameIndex);
//send garbage with -1 index to try again
if (raw == NULL){
startAcquisitionIndex = -1;
#ifdef VERYVERBOSE
cout<<"data not ready for gui yet"<<endl;
#endif
}
//proper frame
else{
//cout<<"**** got proper frame ******"<<endl;
memcpy(origVal,raw + HEADER_SIZE_NUM_TOT_PACKETS,frameSize);
raw=NULL;
//fixed frame number
jfrau_packet_header_t* header = (jfrau_packet_header_t*) origVal;
currentIndex = (*( (uint32_t*) header->frameNumber))&0xffffff;
#ifdef VERYVERBOSE
cout << "currentIndex:" << dec << currentIndex << endl;
#endif
int64_t currentPacket = packetsPerFrame-1;
int offsetsrc = 0;
int offsetdest = 0;
int64_t ifnum=-1;
int64_t ipnum=-1;
while(currentPacket >= 0){
header = (jfrau_packet_header_t*) (origVal + offsetsrc);
ifnum = (*( (uint32_t*) header->frameNumber))&0xffffff;
ipnum = (*( (uint8_t*) header->packetNumber));
if(ifnum != currentIndex) {
cout << "current packet " << currentPacket << " Wrong Frame number " << ifnum << ", copying blank packet" << endl;
memcpy(retval+offsetdest,blackpacket,oneDataSize);
offsetdest += oneDataSize;
//no need to increase offsetsrc as all packets will be wrong
currentPacket--;
continue;
}
if(ipnum!= currentPacket){
cout << "current packet " << currentPacket << " Wrong packet number " << ipnum << ", copying blank packet" << endl;
memcpy(retval+offsetdest,blackpacket,oneDataSize);
offsetdest += oneDataSize;
//no need to increase offsetsrc until we get the right packet
currentPacket--;
continue;
}
offsetsrc+=JFRAU_HEADER_LENGTH;
memcpy(retval+offsetdest,origVal+offsetsrc,oneDataSize);
offsetdest += oneDataSize;
offsetsrc += oneDataSize;
currentPacket--;
}
acquisitionIndex = (int)(currentIndex-startAcquisitionIndex);
if(acquisitionIndex == -1)
startFrameIndex = -1;
else
frameIndex = (int)(currentIndex-startFrameIndex);
#ifdef VERY_VERY_DEBUG
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
cout << "frameIndex calculated is:" << frameIndex << endl;
cout << "currentIndex:" << currentIndex << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
#endif
}
}
#ifdef VERYVERBOSE
if(frameIndex!=-1){
cout << "fName:" << fName << endl;
cout << "acquisitionIndex:" << acquisitionIndex << endl;
cout << "frameIndex:" << frameIndex << endl;
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
cout << "startFrameIndex:" << startFrameIndex << endl;
}
#endif
#endif
if(ret==OK && mySock->differentClients){
FILE_LOG(logDEBUG) << "Force update";
ret=FORCE_UPDATE;
}
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL){
cprintf(RED,"%s\n",mess);
mySock->SendDataOnly(mess,sizeof(mess));
}
else{
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
mySock->SendDataOnly(retval,dataSize);
}
delete [] retval;
delete [] origVal;
delete [] raw;
return ret;
}
int slsReceiverTCPIPInterface::jungfrau_read_frame(){ return FAIL;}
@ -2703,16 +1794,6 @@ int slsReceiverTCPIPInterface::set_dynamic_range() {
retval = receiverBase->getDynamicRange();
if(dr > 0 && retval != dr)
ret = FAIL;
else{
dynamicrange = retval;
if(myDetectorType == EIGER){
if(!tenGigaEnable)
packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange;
else
packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange;
}else if (myDetectorType == JUNGFRAU)
packetsPerFrame = JFRAU_PACKETS_PER_FRAME;
}
}
}
}