From 8c72246ce7e7d6442c0d811a55faa516ecd5aa6c Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Wed, 21 May 2014 09:59:37 +0200 Subject: [PATCH 001/222] new separate receiver --- slsReceiverSoftware/Makefile | 71 + slsReceiverSoftware/MySocketTCP/._.DS_Store | Bin 0 -> 82 bytes slsReceiverSoftware/MySocketTCP/Makefile | 23 + slsReceiverSoftware/MySocketTCP/MySocketTCP.c | 1 + .../MySocketTCP/MySocketTCP.cpp | 1 + .../MySocketTCP/MySocketTCP.cxx | 53 + slsReceiverSoftware/MySocketTCP/MySocketTCP.h | 79 + .../MySocketTCP/genericSocket.h | 686 ++++++ slsReceiverSoftware/MySocketTCP/rec | Bin 0 -> 14727 bytes slsReceiverSoftware/MySocketTCP/rec.cxx | 31 + slsReceiverSoftware/MySocketTCP/send | Bin 0 -> 14960 bytes slsReceiverSoftware/MySocketTCP/send.cxx | 40 + slsReceiverSoftware/includes/circularFifo.h | 261 +++ slsReceiverSoftware/includes/receiver_defs.h | 72 + .../includes/sls_receiver_defs.h | 118 + .../includes/sls_receiver_funcs.h | 55 + .../includes/svnInfoReceiver.h | 11 + .../includes/svnInfoReceiverTmp.h | 11 + .../slsDetectorCalibration/MovingStat.h | 130 ++ .../slsDetectorCalibration/RunningStat.h | 55 + .../chiptestBoardData.h | 89 + .../commonModeSubtraction.h | 82 + .../slsDetectorCalibration/demoCreateTree.C | 31 + .../slsDetectorCalibration/doxy.config | 85 + .../energyCalibration.cpp | 527 +++++ .../energyCalibration.h | 452 ++++ .../slsDetectorCalibration/gMapDemo.C | 11 + .../slsDetectorCalibration/gainMap.C | 228 ++ .../gotthardModuleData.h | 148 ++ .../gotthardShortModuleData.h | 127 ++ .../slsDetectorCalibration/jungfrau02Data.h | 156 ++ .../slsDetectorCalibration/jungfrauReadData.C | 264 +++ .../moench02ModuleData.h | 137 ++ .../slsDetectorCalibration/moenchCommonMode.h | 45 + .../slsDetectorCalibration/moenchMakeTree.C | 244 ++ .../slsDetectorCalibration/moenchReadData.C | 236 ++ .../slsDetectorCalibration/moenchReadDataMT.C | 52 + .../pedestalSubtraction.h | 48 + .../slsDetectorCalibration/raedNoiseData.C | 136 ++ .../slsDetectorCalibration/readJungfrauData.C | 31 + .../singlePhotonDetector.h | 387 ++++ .../single_photon_hit.h | 62 + .../slsDetectorCalibration/slsDetectorData.h | 251 +++ .../slsDetectorCalibration/slsReceiverData.h | 171 ++ slsReceiverSoftware/slsReceiver/.cproject | 51 + slsReceiverSoftware/slsReceiver/.project | 28 + slsReceiverSoftware/slsReceiver/Makefile | 68 + .../slsReceiver/eigerReceiver/RestHelper.h | 195 ++ .../eigerReceiver/eigerReceiver.cpp | 254 +++ .../slsReceiver/eigerReceiver/eigerReceiver.h | 211 ++ .../eigerReceiver/eigerReceiverDummy.cpp | 99 + .../eigerReceiver/eigerReceiverTest.cpp | 97 + .../slsReceiver/slsReceiver.cpp | 81 + .../slsReceiver/slsReceiverTCPIPInterface.cpp | 1991 +++++++++++++++++ .../slsReceiver/slsReceiverTCPIPInterface.h | 238 ++ .../slsReceiver/slsReceiverUDPFunctions.cpp | 1968 ++++++++++++++++ .../slsReceiver/slsReceiverUDPFunctions.h | 685 ++++++ .../slsReceiver/slsReceiverUsers.cpp | 43 + .../slsReceiver/slsReceiverUsers.h | 85 + 59 files changed, 11792 insertions(+) create mode 100644 slsReceiverSoftware/Makefile create mode 100644 slsReceiverSoftware/MySocketTCP/._.DS_Store create mode 100644 slsReceiverSoftware/MySocketTCP/Makefile create mode 120000 slsReceiverSoftware/MySocketTCP/MySocketTCP.c create mode 120000 slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp create mode 100644 slsReceiverSoftware/MySocketTCP/MySocketTCP.cxx create mode 100644 slsReceiverSoftware/MySocketTCP/MySocketTCP.h create mode 100644 slsReceiverSoftware/MySocketTCP/genericSocket.h create mode 100755 slsReceiverSoftware/MySocketTCP/rec create mode 100644 slsReceiverSoftware/MySocketTCP/rec.cxx create mode 100755 slsReceiverSoftware/MySocketTCP/send create mode 100644 slsReceiverSoftware/MySocketTCP/send.cxx create mode 100644 slsReceiverSoftware/includes/circularFifo.h create mode 100755 slsReceiverSoftware/includes/receiver_defs.h create mode 100755 slsReceiverSoftware/includes/sls_receiver_defs.h create mode 100644 slsReceiverSoftware/includes/sls_receiver_funcs.h create mode 100644 slsReceiverSoftware/includes/svnInfoReceiver.h create mode 100644 slsReceiverSoftware/includes/svnInfoReceiverTmp.h create mode 100755 slsReceiverSoftware/slsDetectorCalibration/MovingStat.h create mode 100755 slsReceiverSoftware/slsDetectorCalibration/RunningStat.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/chiptestBoardData.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/commonModeSubtraction.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/demoCreateTree.C create mode 100644 slsReceiverSoftware/slsDetectorCalibration/doxy.config create mode 100644 slsReceiverSoftware/slsDetectorCalibration/energyCalibration.cpp create mode 100644 slsReceiverSoftware/slsDetectorCalibration/energyCalibration.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/gMapDemo.C create mode 100644 slsReceiverSoftware/slsDetectorCalibration/gainMap.C create mode 100644 slsReceiverSoftware/slsDetectorCalibration/gotthardModuleData.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/gotthardShortModuleData.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/jungfrau02Data.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/jungfrauReadData.C create mode 100644 slsReceiverSoftware/slsDetectorCalibration/moench02ModuleData.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/moenchCommonMode.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/moenchMakeTree.C create mode 100644 slsReceiverSoftware/slsDetectorCalibration/moenchReadData.C create mode 100644 slsReceiverSoftware/slsDetectorCalibration/moenchReadDataMT.C create mode 100644 slsReceiverSoftware/slsDetectorCalibration/pedestalSubtraction.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/raedNoiseData.C create mode 100644 slsReceiverSoftware/slsDetectorCalibration/readJungfrauData.C create mode 100644 slsReceiverSoftware/slsDetectorCalibration/singlePhotonDetector.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/single_photon_hit.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/slsDetectorData.h create mode 100644 slsReceiverSoftware/slsDetectorCalibration/slsReceiverData.h create mode 100644 slsReceiverSoftware/slsReceiver/.cproject create mode 100644 slsReceiverSoftware/slsReceiver/.project create mode 100644 slsReceiverSoftware/slsReceiver/Makefile create mode 100644 slsReceiverSoftware/slsReceiver/eigerReceiver/RestHelper.h create mode 100644 slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp create mode 100644 slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.h create mode 100644 slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp create mode 100644 slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp create mode 100644 slsReceiverSoftware/slsReceiver/slsReceiver.cpp create mode 100644 slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp create mode 100644 slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h create mode 100644 slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp create mode 100644 slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h create mode 100644 slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp create mode 100644 slsReceiverSoftware/slsReceiver/slsReceiverUsers.h diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile new file mode 100644 index 0000000000..f8df056397 --- /dev/null +++ b/slsReceiverSoftware/Makefile @@ -0,0 +1,71 @@ + +include ../Makefile.include + +DESTDIR ?= ../bin +LIBDIR ?= $(DESTDIR) +DOCDIR ?= docs + + +CFLAGS= -g -DC_ONLY -fPIC +#FLAGS+= #-DVERBOSE -DVERYVERBOSE + +DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS + +INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -IslsReceiver/eigerReceiver -I$(ASM) +#-IslsReceiverInterface + +SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/slsReceiverUDPFunctions.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiverUsers.cpp +#slsReceiverInterface/receiverInterface.cpp + +OBJS = $(SRC_CLNT:.cpp=.o) +OBJS += slsReceiver/eigerReceiver.o + + +.PHONY: all intdoc package eigerReceiver clean + +all: package $(SRC_CLNT) + +intdoc: $(SRC_H) $(SRC_CLNT) + doxygen doxy.config + + +%.o : %.cpp %.h Makefile +ifeq ($(EIGERSLS),yes) + $(CXX) -DEIGERSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(EIGERFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) +else ifeq ($(ROOTSLS),yes) + echo "with root" + $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) +else + echo "without root" + $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) +endif + +# LEO: not satisfied by eigerReceiver +package: eigerReceiver $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a + +eigerReceiver: + cd slsReceiver && make eigerReceiver + +$(DESTDIR)/libSlsReceiver.so: $(OBJS) + $(CXX) -shared -Wl,-soname,libSlsReceiver.so -o libSlsReceiver.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread + $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) + mv libSlsReceiver.so $(DESTDIR) + +$(DESTDIR)/libSlsReceiver.a: $(OBJS) + ar rcs libSlsReceiver.a $(OBJS) + mv libSlsReceiver.a $(DESTDIR) + +clean: + rm -rf $(OBJS) + cd slsReceiver && make clean + cd + +#------------------------------------------------------------------------------- + +install: package + +install_inc: + $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) + cp -P slsReceiver/slsReceiverUsers.h $(DESTDIR) + + diff --git a/slsReceiverSoftware/MySocketTCP/._.DS_Store b/slsReceiverSoftware/MySocketTCP/._.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c9474ea62235481b7d27ae5a878d2b4070bc6e05 GIT binary patch literal 82 jcmZQz6=P>$V!#9-F-{;h0%8Rq2JwS{7!DlZEK~*nFE;@e literal 0 HcmV?d00001 diff --git a/slsReceiverSoftware/MySocketTCP/Makefile b/slsReceiverSoftware/MySocketTCP/Makefile new file mode 100644 index 0000000000..69634f361b --- /dev/null +++ b/slsReceiverSoftware/MySocketTCP/Makefile @@ -0,0 +1,23 @@ + +TOBECLEANED = MySocketTCP.o + +PROGRAMS = rec send + +all: $(PROGRAMS) + +clean: + @rm -f $(TOBECLEANED) $(PROGRAMS) + +rec: MySocketTCP.o rec.cxx + g++ -o $@ $^ + @echo "$@ done" + +send: MySocketTCP.o send.cxx + g++ -o $@ $^ + @echo "$@ done" + +MySocketTCP.o: MySocketTCP.cxx MySocketTCP.h + g++ -c $< + @echo "$@ done" + + diff --git a/slsReceiverSoftware/MySocketTCP/MySocketTCP.c b/slsReceiverSoftware/MySocketTCP/MySocketTCP.c new file mode 120000 index 0000000000..a995312db4 --- /dev/null +++ b/slsReceiverSoftware/MySocketTCP/MySocketTCP.c @@ -0,0 +1 @@ +MySocketTCP.cxx \ No newline at end of file diff --git a/slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp b/slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp new file mode 120000 index 0000000000..a995312db4 --- /dev/null +++ b/slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp @@ -0,0 +1 @@ +MySocketTCP.cxx \ No newline at end of file diff --git a/slsReceiverSoftware/MySocketTCP/MySocketTCP.cxx b/slsReceiverSoftware/MySocketTCP/MySocketTCP.cxx new file mode 100644 index 0000000000..ba9583c1ca --- /dev/null +++ b/slsReceiverSoftware/MySocketTCP/MySocketTCP.cxx @@ -0,0 +1,53 @@ + +//version 1.0, base development, Ian 19/01/09 + + +#include "MySocketTCP.h" +#include +#include +#include + +using namespace std; + + + + + + + + + +int MySocketTCP::SendData(void* buf,int length){//length in characters + int ndata = SendDataAndKeepConnection(buf,length); + Disconnect(); + return ndata; +} + +int MySocketTCP::SendDataAndKeepConnection(void* buf,int length){//length in characters + if(last_keep_connection_open_action_was_a_send) Disconnect(); //to keep a structured data flow; + + Connect(); + int total_sent=SendDataOnly(buf,length); + last_keep_connection_open_action_was_a_send=1; + return total_sent; +} + + + + +int MySocketTCP::ReceiveData(void* buf,int length){//length in characters + int ndata = ReceiveDataAndKeepConnection(buf,length); + Disconnect(); + return ndata; +} + +int MySocketTCP::ReceiveDataAndKeepConnection(void* buf,int length){//length in characters + if(!last_keep_connection_open_action_was_a_send) Disconnect(); //to a keep structured data flow; + + Connect(); + // should preform two reads one to receive incomming char count + int total_received=ReceiveDataOnly(buf,length); + last_keep_connection_open_action_was_a_send=0; + return total_received; +} + diff --git a/slsReceiverSoftware/MySocketTCP/MySocketTCP.h b/slsReceiverSoftware/MySocketTCP/MySocketTCP.h new file mode 100644 index 0000000000..31f56d453e --- /dev/null +++ b/slsReceiverSoftware/MySocketTCP/MySocketTCP.h @@ -0,0 +1,79 @@ + +#ifndef MY_SOCKET_TCP_H +#define MY_SOCKET_TCP_H + + + + +/** + * + * @libdoc The MySocketTCP class provides a simple interface for creating and sending/receiving data over a TCP socket. + * + * @short This class provides a simple interface for creating and sending/receiving data over a TCP socket. + * @author Ian Johnson + * @version 1.0 + */ + + + +//version 1.0, base development, Ian 19/01/09 + +/* Modified by anna on 19.01.2009 */ +/* + canceled SetupParameters() and varaibles intialized in the constructors' headers; + defined SEND_REC_MAX_SIZE (for compatibilty with mythen (and possibly other) pure C servers (i would move it to the common header file) + + added #ifndef C_ONLY... to cutout class definition when including in pure C servers (can be removed if SEND_REC_MAX_SIZE is moved to the common header file) + + defined private variables char hostname[1000] and int portno to store connection informations; + + defined public functions int getHostname(char *name) and int getPortNumber() to retrieve connection informations + + added public function int getErrorStatus() returning 1 if socketDescriptor<0 + + remove exits in the constructors and replace them with socketDescriptor=-1 + + replaced the argument of send/receive data with void (to avoid too much casting or compiler errors/warnings) + + added a function which really does not close the socket between send/receive (senddataonly, receivedataonly) + +*/ + + +/* Modified by Anna on 31.10.2012 + +developed and + +*/ + + +#include "genericSocket.h" +#define TCP_PACKET_SIZE 4096 + +class MySocketTCP: public genericSocket { + + public: + MySocketTCP(const char* const host_ip_or_name, unsigned short int const port_number): genericSocket(host_ip_or_name, port_number,TCP), last_keep_connection_open_action_was_a_send(0){setPacketSize(TCP_PACKET_SIZE);}; // sender (client): where to? ip + MySocketTCP(unsigned short int const port_number):genericSocket(port_number,TCP), last_keep_connection_open_action_was_a_send(0) {setPacketSize(TCP_PACKET_SIZE);}; // receiver (server) local no need for ip + + + //The following two functions will connectioned->send/receive->disconnect + int SendData(void* buf,int length);//length in characters + int ReceiveData(void* buf,int length); + + + //The following two functions stay connected, blocking other connections, and must be manually disconnected, + // when the last call is a SendData() or ReceiveData() the disconnection will be done automatically + //These function will also automatically disconnect->reconnect if + // two reads (or two writes) are called in a row to preserve the data send/receive structure + int SendDataAndKeepConnection(void* buf,int length); + int ReceiveDataAndKeepConnection(void* buf,int length); + + private: + + + bool last_keep_connection_open_action_was_a_send; + + +}; +#endif diff --git a/slsReceiverSoftware/MySocketTCP/genericSocket.h b/slsReceiverSoftware/MySocketTCP/genericSocket.h new file mode 100644 index 0000000000..28ae7b6502 --- /dev/null +++ b/slsReceiverSoftware/MySocketTCP/genericSocket.h @@ -0,0 +1,686 @@ + +#ifndef GENERIC_SOCKET_H +#define GENERIC_SOCKET_H + + + + + +/** + * + * @libdoc genericSocket provides some functions to open/close sockets both TCP and UDP + * + * @short some functions to open/close sockets both TCP and UDP + * @author Anna Bergamaschi + * @version 0.0 + */ + + + +//version 1.0, base development, Ian 19/01/09 + +/* Modified by anna on 19.01.2009 */ +/* + canceled SetupParameters() and varaibles intialized in the constructors' headers; + defined SEND_REC_MAX_SIZE (for compatibilty with mythen (and possibly other) pure C servers (i would move it to the common header file) + + added #ifndef C_ONLY... to cutout class definition when including in pure C servers (can be removed if SEND_REC_MAX_SIZE is moved to the common header file) + + defined private variables char hostname[1000] and int portno to store connection informations; + + defined public functions int getHostname(char *name) and int getPortNumber() to retrieve connection informations + + added public function int getErrorStatus() returning 1 if socketDescriptor<0 + + remove exits in the constructors and replace them with socketDescriptor=-1 + + replaced the argument of send/receive data with void (to avoid too much casting or compiler errors/warnings) + + added a function which really does not close the socket between send/receive (senddataonly, receivedataonly) +*/ + +#ifdef __CINT__ +//class sockaddr_in; +class socklen_t; +class uint32_t; +class uint32_t_ss; +// CINT view of types: +class sockaddr_in; +// { +// unsigned short int sa_family; +// unsigned char sa_data[14]; +// }; +#else + +#include +#include +#include +#include +#include +#include + +#endif + +#include +#include +#include + +#include +#include +#include + +using namespace std; + +#define DEFAULT_PACKET_SIZE 1286 +#define DEFAULT_PACKETS_PER_FRAME 2 +#define SOCKET_BUFFER_SIZE (100*1024*1024) //100MB +#define DEFAULT_PORTNO 1952 +#define DEFAULT_BACKLOG 5 +#define DEFAULT_UDP_PORTNO 50001 +#define DEFAULT_GUI_PORTNO 65000 + +class genericSocket{ + + public: + + /** + Communication protocol +*/ +enum communicationProtocol{ + TCP, /**< TCP/IP */ + UDP /**< UDP */ +}; + + + genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, int t = DEFAULT_PACKETS_PER_FRAME) : + // portno(port_number), + protocol(p), + is_a_server(0), + socketDescriptor(-1), + file_des(-1), + packet_size(ps), + nsending(0), + nsent(0), + total_sent(0), + packets_per_frame(t)// sender (client): where to? ip + { + + // strcpy(hostname,host_ip_or_name); + struct hostent *hostInfo = gethostbyname(host_ip_or_name); + if (hostInfo == NULL){ + cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n"; + } else { + // Set some fields in the serverAddress structure. + serverAddress.sin_family = hostInfo->h_addrtype; + memcpy((char *) &serverAddress.sin_addr.s_addr, + hostInfo->h_addr_list[0], hostInfo->h_length); + serverAddress.sin_port = htons(port_number); + socketDescriptor=0; //You can use send and recv, //would it work????? + } + clientAddress_length=sizeof(clientAddress); + } + + + int getProtocol(communicationProtocol p) { + switch (p) { + case TCP: + return SOCK_STREAM; + break; + case UDP: + return SOCK_DGRAM; + + default: + cerr << "unknow protocol " << p << endl; + return -1; + } + } + + int getProtocol() {return getProtocol(protocol);}; + + + + + /** + The constructor for a server + @short the contructor for a server + \param port_number port number to listen to + \param p TCP or UDP + \param eth interface name or IP address to listen to (if NULL, listen to all interfaces) + + */ + + genericSocket(unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, int t = DEFAULT_PACKETS_PER_FRAME, const char *eth=NULL): + //portno(port_number), + protocol(p), + is_a_server(1), + socketDescriptor(-1), + file_des(-1), + packet_size(ps), + nsending(0), + nsent(0), + total_sent(0), + packets_per_frame(t) + { + +/* // you can specify an IP address: */ +/* */ + +/* // or you can let it automatically select one: */ +/* myaddr.sin_addr.s_addr = INADDR_ANY; */ + + if(serverAddress.sin_port == htons(port_number)){ + socketDescriptor = -10; + return; + } + + char ip[20]; + + strcpy(ip,"0.0.0.0"); + clientAddress_length=sizeof(clientAddress); + if (eth) { + strcpy(ip,nameToIp(string(eth)).c_str()); + if (string(ip)==string("0.0.0.0")) + strcpy(ip,eth); + } + + // strcpy(hostname,"localhost"); //needed?!?!?!? + + + socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp + + if (socketDescriptor < 0) { + cerr << "Can not create socket "<= 0){ \ + close(socketDescriptor); \ + } \ + file_des=-1; \ + serverAddress.sin_port=-1; \ + }; + + +/* /\** @short if client returns hostname for connection */ +/* \param name string to write the hostname to */ +/* \returns 0 if client, 1 if server (in this case ignore name return value) */ + +/* *\/ */ +/* int getHostname(char *name){ */ +/* if (is_a_server==0) { */ +/* strcpy(name,getHostname().c_str()); */ +/* } */ +/* return is_a_server; */ +/* }; */ +/* /\** @short if client returns hostname for connection */ +/* \returns hostname */ + +/* *\/ */ +/* string getHostname(){return string(hostname);}; */ + +/* /\** @short returns port number for connection */ +/* \returns port number */ +/* *\/ */ +/* int getPortNumber(){return portno;}; */ + + /** @short returns communication protocol + \returns TCP or UDP + */ + int getCommunicationProtocol(){return protocol;}; + + + /** @short returns error status + \returns 1 if error + */ + int getErrorStatus(){if (socketDescriptor==-10) return -10; else if (socketDescriptor<0) return 1; else return 0;}; + + + /** @short etablishes connection; disconnect should always follow + \returns 1 if error + */ + int Connect(){//cout<<"connect"<0) return file_des; + if (protocol==UDP) return -1; + + if(is_a_server && protocol==TCP){ //server tcp; the server will wait for the clients connection + if (socketDescriptor>0) { + if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) { + cerr << "Error: with server accept, connection refused"<=0){ //then was open + if(is_a_server){ + close(file_des); + } + else { + close(socketDescriptor); + socketDescriptor=-1; + } + file_des=-1; + } + } + }; + + + void ShutDownSocket(){ + while(!shutdown(socketDescriptor, SHUT_RDWR)); + }; + + + + /** Set the socket timeout ts is in seconds */ + int SetTimeOut(int ts){ + + + if (ts<=0) + return -1; + + //cout << "socketdescriptor "<< socketDescriptor << endl; + struct timeval tout; + tout.tv_sec = 0; + tout.tv_usec = 0; + if(::setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVTIMEO, &tout, sizeof(struct timeval)) <0) + { + cerr << "Error in setsockopt SO_RCVTIMEO "<< 0 << endl; + } + tout.tv_sec = ts; + tout.tv_usec = 0; + if(::setsockopt(socketDescriptor, SOL_SOCKET, SO_SNDTIMEO, &tout, sizeof(struct timeval)) < 0) + { + cerr << "Error in setsockopt SO_SNDTIMEO " << ts << endl; + } + return 0; + + + }; + + + int setPacketSize(int i=-1) { if (i>=0) packet_size=i; return packet_size;}; + + + + static string ipToName(string ip) { + struct ifaddrs *addrs, *iap; + struct sockaddr_in *sa; + char buf[32]; + + strcpy(buf,"none"); + + getifaddrs(&addrs); + for (iap = addrs; iap != NULL; iap = iap->ifa_next) { + if (iap->ifa_addr && (iap->ifa_flags & IFF_UP) && iap->ifa_addr->sa_family == AF_INET) { + sa = (struct sockaddr_in *)(iap->ifa_addr); + inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, sizeof(buf)); + if (ip==string(buf)) { + //printf("%s\n", iap->ifa_name); + strcpy(buf,iap->ifa_name); + break; + } + } + } + freeifaddrs(addrs); + return string(buf); + }; + + static string nameToMac(string inf) { + struct ifreq ifr; + int sock, j, k; + char mac[32]; + + sock=getSock(inf,&ifr); + + if (-1==ioctl(sock, SIOCGIFHWADDR, &ifr)) { + perror("ioctl(SIOCGIFHWADDR) "); + return string("00:00:00:00:00:00"); + } + for (j=0, k=0; j<6; j++) { + k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X", + (int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]); + } + mac[sizeof(mac)-1]='\0'; + + return string(mac); + + }; + + + + static string nameToIp(string inf){ + struct ifreq ifr; + int sock; + char *p, addr[32]; + + sock=getSock(inf,&ifr); + + if (-1==ioctl(sock, SIOCGIFADDR, &ifr)) { + perror("ioctl(SIOCGIFADDR) "); + return string("0.0.0.0"); + } + p=inet_ntoa(((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr); + strncpy(addr,p,sizeof(addr)-1); + addr[sizeof(addr)-1]='\0'; + + return string(addr); + + }; + + static int getSock(string inf, struct ifreq *ifr) { + + int sock; + sock=socket(PF_INET, SOCK_STREAM, 0); + if (-1==sock) { + perror("socket() "); + return 1; + } + strncpy(ifr->ifr_name,inf.c_str(),sizeof(ifr->ifr_name)-1); + ifr->ifr_name[sizeof(ifr->ifr_name)-1]='\0'; + + return sock; + + }; + + + int ReceiveDataOnly(void* buf,int length=0){ + + + if (buf==NULL) return -1; + + + total_sent=0; + + switch(protocol) { + case TCP: + if (file_des<0) return -1; + while(length>0){ + nsending = (length>packet_size) ? packet_size:length; + nsent = read(file_des,(char*)buf+total_sent,nsending); + if(!nsent) break; + length-=nsent; + total_sent+=nsent; + } + break; + case UDP: + if (socketDescriptor<0) return -1; + //if length given + if(length){ + while(length>0){ + nsending=packet_size; + nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); + if(!nsent) break; + length-=nsent; + total_sent+=nsent; + } + } + //depends on packets per frame + else{ + for(int i=0;i0) + strcpy(thisClientIP,dummyClientIP); + + if (strcmp(lastClientIP,thisClientIP)) + differentClients=1; + else + differentClients=0; + + return total_sent; + + + + } + + + int SendDataOnly(void *buf, int length) { +#ifdef VERY_VERBOSE + cout << "want to send "<< length << " Bytes" << endl; +#endif + if (buf==NULL) return -1; + + total_sent=0; + + + switch(protocol) { + case TCP: + if (file_des<0) return -1; + while(length>0){ + nsending = (length>packet_size) ? packet_size:length; + nsent = write(file_des,(char*)buf+total_sent,nsending); + if(!nsent) break; + length-=nsent; + total_sent+=nsent; + } + break; + case UDP: + if (socketDescriptor<0) return -1; + while(length>0){ + nsending = (length>packet_size) ? packet_size:length; + nsent = sendto(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, clientAddress_length); + if(!nsent) break; + length-=nsent; + total_sent+=nsent; + } + + break; + default: + ; + } +#ifdef VERY_VERBOSE + cout << "sent "<< total_sent << " Bytes" << endl; +#endif + return total_sent; + + + } + + char lastClientIP[INET_ADDRSTRLEN]; + char thisClientIP[INET_ADDRSTRLEN]; + int differentClients; + + + protected: + + communicationProtocol protocol; + + + + int is_a_server; + + + int socketDescriptor; + int file_des; + + int packet_size; + + struct sockaddr_in clientAddress, serverAddress; + socklen_t clientAddress_length; + + + char dummyClientIP[INET_ADDRSTRLEN]; + + + private: + + int nsending; + int nsent; + int total_sent; + int packets_per_frame; + + + + // pthread_mutex_t mp; +}; +#endif diff --git a/slsReceiverSoftware/MySocketTCP/rec b/slsReceiverSoftware/MySocketTCP/rec new file mode 100755 index 0000000000000000000000000000000000000000..b652bb8f4795994f4cbe47c47317b9aff8e3a018 GIT binary patch literal 14727 zcmeHOeRNyJl^@x1P+F5XA2Pli-llheo?0Q z{ygrmv6ibSkpxylREWZkac*e3JRPUe}7$TnGo z2(x58FaBWJ#l$c}T!gr|yR`1U8_7d%#4*WYmaw~(9@o@8bO=9!PU!@<1{ z{v;^Fn@A`BQHS4(Yhv1`gC7?xR|h{X{>uTEf>Qop9efCtAb#7?cZb7&z`@r!_%#PV z0ZRG5bMPF8e*%V z-w}r&bFg;%c@9oH{0BiP|J^)&Ne7?h$iL{|FFW!daWL!2{P!aEJnQw{4?0hrFE)e! z%ICa3`q?}&M_dhBi*eQhN_iVmd~-&AKIEIgpMvv{FW`3xyCe9a57FsX3e)WBjz!Ic z9f;eeDa;#s&1S1BoUpBUT_li5SP5Z%EV}hJ{I}TERV|G%FsLSCK@+nJEpn zLgfmxXV|08uB$S7k=_w$BH7rI$F5gwWkS=M=9XBCX|M(Q`ph0H zo`^*Qk+9uw_Exf$x>W<=sw)^Y6GTRFUM?26)iDb7$v7pnA4UK5Tj&RgWCaeyT zhy`!AY=Nc-_VkO89g9Zfe?kOf(Wn))MNiUBAU_&93KN2T0W)A*ePOhbiB^fm%t$O4 zu*0#aXh(qpO$x1+O~tVuTXb1=2rb>-9}U2cU?i5XL?9Tnz%osm<#cIxARHB2<6+wp z*VomVS5{Pty3Lzct!^-@Dy|gQuWwilh~#Q@Z7#3KrsKL24pW3*v7Fa90~JfG(wNSx zlhG`2JW`tTu?N2@_#x*GKVs98{`YcLdk1L@9%$et`7H6rU%wsMN<=ZnFw^X15BXU3 z9AE~@Z*=q#CoT$Odi0759Qm?v_-xv}#E~Dv{5}gBIgUy=VPbrgVB(rW`dKU(>1RRK zONw#gBgFtKB}Kk6QViGyq_AWmDN0;K`X1DY6g4U*Efr!ZDJ-~*6cbk^>0I2)NKv60 zQcM`vkz!ERlH%r8Pr3m29MW@zSWkK$+KcpkLbQ@D6k;>!`9j=6`hFp{kotw_AiY3{ z5b1?Nw55NU8uMj5s9NS;{=J66UOFJAS4^Ph(~BqZkJ^jr#cYWXFHansMp(=i36Xc= zu*7Vc5WC{Ueu>#aAy^_#?3I`;74j4BmY6LTT1q@DFLVWi z6A~7)Cqe_n$0TNtgzhCiEHQf~G)%l-V)jtzG2*=vv!_D4iFZrP9t%B1JS;JLF0_|; zKw|b_XdiKp#O%q?e&Q_>vqwWO5;sZAo(&x)u9cWQ9D0Sg61eL1kEef;IzHai+8ipw zy&>es-;J9>|MFR{FY|Q>Obidh7g|zd-VE}Hn|B#hj znmJTL1)kJF@6ER!*l8~jJD=yW!12pHKFAL4x977R1TJQec*~hKeHeyF-(8qCrqXSb zsqIsqWYv!Clhe~eB$q<$5$Mf)`H$1nBlYFJqo^$??}!4tXYK>|efEK6KEVoXrakl`B|SO}Ga`}=PjF*5X;(QcW#2&vZ^W!vXuQQ85wtu`Ce90dVRSs-CFKVd&@KHP#~&?dWpXIL&nrHqYVEZVkh$ot{dP5zkI`ejea zlx7)YvL$+y`QmX!Gs(-U4I+ zr(}Yz@IqDwmiRD8Z;FKc@^ja&Rp`}sH8|` zyvnPsx%a%v3bjoRc^@s?g{kHkx?vNvWY$9b#E;l~-tsULu42M>RYHsjOPKJqO4!DP zbD6;B0%S=s!OMjER6?2wZ=v|nZD0=*{gNmO^jV^x5^Vwc0?|uE%|QP^^c|vlpl67_ zMzj*>Iie?sI0wE!^l73CfJTT?M5RDKB1!_GLvFf+)pfeY1zqX}G=cZ7Ktc_&!`DCx^DgWyT&U zBQ3gHPEG~1(wE$3c%)Kw*F^maNo`Y`$n$ET*k9bK1n)$}@im5#~J(Jh};Y*P&XU^uo^cFg;SH zlyWKpr)&uKVqXa#u+t;yBU5jEY3{d;u))Br}dPj7aIM`*gWpZZVzOcrYAcO>U`p# zmBF1O1N5dM-Vf*!nFYE*(!+Eo_|X*o=yF{i+|Ti&l6RRHZ$lQfevlL6zqx#VZk|Ok z;GEVQJs(ijh?et#oL1cP=FCd?ud6?9g=Nx@&Y(Z$LDtus=N_r( zn^Jfu)?9daoc_cVpZjjyF*a}j3j$-T38Ztxcysqz@aJ;)Z)O7W>A~UaIP(~9%6o)F zbf&&Aj^#Eh?u0^yBYL;-wEZJoZRBIc=AwM!nOAhl*2^)5(dH z+>)T2Yft1dSe6l}@lDtX!HPrfGlB>s9*@QS;i!LR|JC2pXg1evYHiqHH2O~?)3UKX zPv#o`*03Fds(7yz_p2@2%lyu+Ft&UBajR2qAzNEx$w)^#ZezFmtw0y|ajo`1N2jnT z9B7ZlZEQ4Koq=S;7FIZF$NAqIhzP5@GaRvm6?I5V?ivfLv1wytYfD>GlQ1?mu5Me? zLb}1&K+@7IjHc$s)<%(x-X4u@jry?*9gB;)K-3?N+5R9lpl!>q_O<;p$!a&-Z^yDM zw8n#8--CJahYzT<=Rqxp_ZufIUsmIJkh>i5qC8!i|JOhh?_%4Icj2E&9j-l%j)v3l zsQc$m8-Enn23{|Oqg~hdo8qzdh}8|3#%rFQxW!aIUngAS7w^gTE#Et2dv$iR6|};= zR)_x@;kmH*+85Ey7%!p&+anp!uYz*B<9ncf&?BJNfkrUQ`OeCV*}?|x038N>67*@% zW1xHoHi2<>9P~NNF<3&0`B=s*0<8zF0sS0kE9ewx59lJSbB95%!;*h5=*yTLUk1Ge z4@O=L-X}rJL7xMy2mKLf2dIAv<$_j%z6i=XFnI205}s|o68W;M)a$($wvgvXY{ibE z0V-C_@eLNOKATG@^7sz%bKqfX{v_UJBylH_J3;yRY$P25@6iIhVWizM3-tYDOZ2{hKq&;*B9ws?)7`z3b`F1Ws+VP!U-yyVXKCcG6uMT^CtY<#2 z6}+NPdwt6b@Or?j2CuCE?|$&^E0B+`Y@Pyd47`g#v*j6gd+$LXl20EheYh~6eU$Z2I=Md66Sf(FwJyu=x4Xlr5?7}7awTKUaPyZ;y z--2|m+UO(s{L7FwfXF@kjj+#qbdT3pU+NLFy`D9&K)d4VySynhfslR%>bawtrg|=P z`7mvXU~NOc&9)sbnO=jq1-vk5mRFZ5Q7y~eSkIhg$Y_+jSuAdsw?(-_OTTB`n2p;n zqzr6c9WTWNuleqel<(}YvJsEn`CC7$WPL0pNr25}Q&Ct@$6EEjKbukkO%5s_v7YP_#q?q6P6SyOpcWwn24 zGiKNEdH!GenehFES`V?irf~2I0^}Lhl7xgK{5U+WNAus zdjitISa-J-<*nz8170D^am%qL&tYNway;q4G0pG+L~Q@@wyn-ff#Jus4svb-s6xc; znlAzb$9xEK)wtGtQpRf$IqoUPxnLLM$^bY=;8MzP+qe#qW0`WCJLG+xzzLLPSck}Q zPZr1gQ7BrCYh5nW88;(xp5Qg-3O^>J0bH|OmZRmna6KE5a-3^+Lr&gDfEg&qf!c$p zRxqe*JR?dB#8y`bs$~6TrgD#hyr{(rSZZG5x>qH-I@~ z07lesVsrxAj$sf{>*HL!4`&B>PtZY^JA?$vvA#cn+)pUS262Lxdl*>D$#ZcyWcIQa z0@ZSRTyoEU!Rvb-XBhki^!=ktj<>&~7dvN|9GxtSfp2MeO%?LIALMi$k(4d>Ag;9> zUsQ`rR6kLMLEHBOTx&VLkoG}N^W1WW0oZ3OSDqt;+%a6!Ul^E&e(;}&S|87%j1|yF z*`K@Qc#j*0+%}}?KpDngBWisSyhDt9ps;VJ7$@*mxPu(qtONUpW5caaV8M6~8BuI3AcRd4CFK(XvmA;-VsD}y-B6_!M06 zgFydAD0XIS`mw@XF)4plSgow+mkQ&+5d!^BVKo!c&lKiNr~FA_97J-3VsU}=gD*L2 zl_IS8TvHGH_qWrWW3;^&k^J|g7Jn^ zKT$MaSb4Y?Sog1|=zW6EU2gf^d6;Kn-TZ@j_@}^nP3$Q;R~!S@{^G}-aTJ(=U`AiW?t|ZZKMAaZ z9~a-q!`}zyeU1LbGqv1D(9eU+{|iU{Qt)Zd+rYeE;u835@s7jSXPo`cq^8d#R{?YW zy&v*C!@JhuUnlbm@iAci+{^O%9KJpS{iuUEGqC)x0PAOH${%s~yBz*I4%X$r7ZuZc z1C;jz>t|u&6|6XdJ~Mp>u=|X08d&#d8T#`xj=b)_ryQ*7^Bl0=8=(Hzf%X0aaS=Nb z{;S*Ld|)2pq7Czk=7=TaBV2;W`qlvR2pZGo6`g};Q6YH5EiCz^qRo-lQ(V1_z%&8uMGgY3<)drD7Yf-iM%lJAk=PrH=X7FciT+B;q#)ds`Vh{fpZ8Ab9jN-EmW-y+Xzx7IaP z1pE4gdHwpv)vMNyGuzQVZhGX*S&ou2|r&)<3-NF3QQA?<6`$&E4nSXT*8%+&Q}*OeCevLKmCY3sqG(|GpL*);#@gG|7(v za=NLivcqx7^@o3;d)YuMYC*y}(xn{0Jde zR35*dsb?kh@q-AoWUie08X#9N*P5CZ^i@5&!)WSdt?~}~yR-6}gM>RFzh=u?MPvHyb4K5~mUbHBR4G%@3<>eZUt zIQ8<%opMr})Hts>*v6-9mYm8s6N2-FOP+aVM%$3W%3vMjB;$q6>1uIq9RK+FI9_H#y($ +#include "MySocketTCP.h" + +using namespace std; + +int main(){ + + char data[50000]; + int length=50000; + + unsigned short int portnum = 1952; + MySocketTCP* sock = new MySocketTCP(portnum); + + cout<<"\tReceived :"<ReceiveDataAndKeepConnection(data,23000)<ReceiveData(data,32200)<ReceiveData(data,33300)<ReceiveData(data,30000)<ReceiveData(data,3222)<tUs8btl_^5hG?LnEib2eRuL^ zIxSVt+2bF3=iK?e&;5Syz2E!2-+SME_uaR{w|=e5PMUvY(^QF7x5>T3c<+yqFC`y z0H64p+r!w03{MsaSugpx6yxBJgU5Ihn2~z14#suJvkrALdVv`=ul`q7+Y9dz;)Tz< zJ&ZpDk5Th)0Uz*;pv%9yGt_!@XWLbsp>VvXG!`jcuJS@P*|r-uHp{%!lX+$#(k2TL z*><*b@%xGw6aO9JBE-wOimIQy`IkeB-yEMce{WHBZ|z-AAvr62fteAQXCC5C8*j1k z$3YohLpu3;YD|4vSMaT{M?%Rgu1Cv5o-+L-NR{@sWz2i>0gLFbBhix%*E zKI`_-&*qBR;yTbOjI%~i%3FwOhx|Oq*MmO^=OJIf?_yS4;EF5gbSs5nbaX|+M$Ga@ zEyEDTOz(*-v?|PSTW4*c(JC(w1pQINiuyxVtTy2D zH6ZPpR(~uMFd{K4YWllsn~bJ1!`HYHg)(a(61Q-*u`$va^M&j*Ga8jwow3^UD>TrA zB3BsoHwR={R%Iv>Gf=NtQ5z0f)#bh|NN?+`C)wDT!>&&v;iCn5dW>!} z8jFPeogu5&*iuF-btwbksv{6EVnpS_Xbx`;h1+1GSiH-mSirVpZ5@o*7782jnAs*` zk-%N1C18p`cdrOqk#MK{kBLAe95w@%=#E=4W1upfE^IwLVt_yYkGEW@B$c9(YfLt(Ks8nR4r zV|BH0O=+2^ZfRM)rq(Dgy++))zIF{Dk}K4;vAi^sj_WcwOaXo~0GO5`{y#DvN5QHY7_6w)t1IcZYJ zj*?=WjFDo1jgunZ1StmWBq=lz$bSKABz>C@9#XWZh_nbglR|^}q?ouCkj}x}O^OD2 zNikuRkYZ3SCB@C{O49kT0qHw&?<2iPh)U9T32_7I0wJnM-z`K9Degh*NWDU=C%qW< zCA~z5=H#yuqn@-2O-t|QUjmgpe^^YdcnK|;y6hzWX}_tvcY=dDv4>~U<+}X#I$s9GqG1Ceil(A6td#RS;^q?fJulGT5?x z@9+5r93=k1L!($AU6sb)GZO^^EmQj~q+fS<%c6mUOITiF$n`}gP0jD8kj>tjK3d2E zT!|y@+ipKRU@Z{?Pjgvd`{n*I$o3Ce^JoWwi&?|&5~fWZgCf#*7bJa?$>xc~_DNT~ zeCPIwsVO1iOCh!m<))u_b82e1ro^)iw?k0g5e0Z(yAQlu!PBL9zQufUp^$z8EzYFt zf}WJZvc{#uzHye5@_ABy3s7YLQ16|?zBIk&beBwBh}7$S#oK3RP|`PgdS=R344U$d zCVdmB4HK#6qLgpk_5Dmi$@L|kWK)Sd=`Km%j0({-v`h5NOZg_3`HJ!H@{K397mFQ# zkBmuQI^|1iO_yd$fjYCaI$MT)lhpOJKcmUH^%_rY7?*lYo<*+!90KYmwoeEPdQC{Z zCS251={1?Hm&c)3&&?8yV*W&5z9Yk7dw+m(PrpYdje*akLr6lxa32$BT?uG$g69v* z-eCC@eo*mKQn-JpXKq$eUAm~V{B{7LJ+0DCJa(+qrk8ey(J(FIvYsji#avwd`UDAS4oUQ|l zX^@nLdGL=4b5X~(KL&ovSA=dkk9u*_$g1}fnR>5b9gjQeeG&D*8MI3-$fI4F~^2q0Kf010}0CRSI5^c|PQ~%JM2O^Yc_U!!rd}INqaGb92 zOhyKpcrZxh0J#a;Bsq4HgRDTx@Iu;f&aM&^#r8bsXwL;X4d?()U;002q)4RQ%B#&e z_rA;qHBY46dk#E`spcfQ;dPXfUI+1!f2H}{C9}XuU(1B=sDwF8Si*!SRl-6hypsuh zEN4AeoCASwb16UBjGx#=M`!tTu2yMJiMWH{&zN3e$@8PchZn z_NRwC^7K~H@Y_&6WTgW?09mGKhkX^88RXc&h3dl7FCV$P;>p6c^Lm&BM0WAg1t;83H_ z+m{z&hUSb8`*84~c{bxXj4Dg>9F--&HjZ-hWJp3cm4Q_}3m3`Cp*3-+v0utajqZ_? zQ=U@kOHMUhvQTx`MEmmONM-5q{wzH>&!+m+$c@vEs=-Cn_~qACcS^Rj;Dj#3=3~MerVs$$Z|!o2KOaIo<)Gj5vILPL4(q;4JH%em9_M z5jE!nIkmX=wds}c-&TLz4$Y(=okxGng{-qbJ_>x+{@68Lu(Llt_uDi4_O1Hkr^s@a z{@4MQQ=^xG&!<2BFy`nFjE%g{J$-!c`3fXaL+*3Wm-)2kca(Cj=N?(mK`A_dH5VQp zr#?E#=e}EZj&42z4;eUgJ@oG9f1=oMM zjx1(QmS=%edt^Op+=(G~O7ONb(7%LtDtIX6+lPIx?z>>vH&%aGuCq!oj?$fAB>RU@ z7lzcUyhq!akUb^SnZ1F_pFNaHHjmR@$8d`p=s(T`3gRIPQWn+`$;0fhVTY>U`VCS) zqSm5+dNsR4XRBs-_F^(QqqvXdE$%KyabL|T?t9=-y8~$18O2?hx44Cl;x^|L*KHT~ zC4Zjc{uAq~GaLIO6rmeCH>bG8c5y#Lr=FqR19^-4xTCo5zmjdcAA?83_a8woB)-Fc z5idJ^Q?macE>oYA|EkZh1~`b^NtGt~>@NX@QhS(@tAyhmT(U6ocCj|;gV0u_V_Em6W?5@u5wP={t~V=iv*nv6dKJnEoD~`vwwkVq+xf8&em{d}GgS zA1g>Tk73i~it?%C(E<5>1#6+iu#0|}wN{+EC~?$%-S)Bg%ZVckZ{zA9wXlRbaGZVn zBz8KmA+ul7i7BfnaoRm~EHxuBF%=(A$So7fIreO<1@L|L_pR8e;VO&!pbWlfG!pfO z!rtlqVQ*ud(NMjqsdj^}&U+4-#*H;OGON5>Lsk$)MYotyui8?+(rfQpV>{X#HQVJD zx4AVE?`&(uZT2p&>F?k^v)SrzYZoSk{jHIxWwr^k-5>9?gc%B3QT}i7cM7wsJ=AFm zGi;NH+|?FlUH!(orpD&_dg0qxx2Ab*Bk2a;29m}G;j3?`YpN6R@Ll1^*02}5Ewyx-Vqxw0D1h1^w$ zi*m}+{J#Yndkfumz6Jk$+Hn0j%BVdDk7fVNw(*B>?ZfMjP`G22w>}za?KHdK(s&Kk z9W|Ni4JFm&~~SIZ%u_(RUhK37|(oxux?nP%r3f zpf`Z-##F)ga$d|o7HA*nAn12Np9Gx*<$Jzj%w4BIIcss~mSR1!5OgzWCFoP2O`r>~ zgzE;a#QJd%v;}MW1E6U<-uw`>2X_TGCV=mPmVh1ytpWXS&^FMQ-ax&eqoB`$vJDKb zyX%E(o2O8|5G-=LcS9HQyogQMHT8jt)w4bQ1#2$kGLbyKC;bd~c>Qn&uLVimZRKuP zZaxc1N5R{Zhc}3{kEGn5Pv_xrgJm4N&3Sn2kEZ+Go)6^VokH5fXW?O@6vx1u51Omz zLZqDsg9^U=n-IpgHUQ3BDfj0`? zBG62IzI)vFq7TWZ4;4LdjdD$8=m*)?|s z4??`?D%@2l-gL>ktJ;aC@3Vc(ighVoB&a|W>v%aXc+Gd5q%(HV}SEyodmjrcm^%-wF! zMTkofS0b)O+=SSUxCQYZ#7`mq1L9MNM-h)B{u=Rh#F^OMz6fy%;!4D|h?@}G5w{@9 zdhy13m3JwQ!YuPv;Jx&6@A9&;%Cc+AD!fY@%r@^jzopWzT2Z!4@cs7xOXt|6G}hZ? z`CCOPP9i88)K}`}DoU|>GD~qF;3~`CAxb;K@zS6_78IpzyBMDAm zfEP78DX%WNvEC~U;W&mU#fb*|w*!C`Y4cltQECQ__9*VjMz9SzHA0a%WnuR41cL!h zu|6yfSdnN93Mg`C0OF{`-xUf#I)Z}nS1M~$CAY>P9f)*wnPJ|3&O6{$xg56~Yx2Aq z#xKW{4jj`A??uEjq+E5&b75e3fpw7c8$dZCZq47bOt5jmDA$GL;|cFq|(P?q6lM2>s1IObnML2GcW>t#A)3nJ$UUURPS zVlwK(HS1+PTD}9<))qALficC~<-lqaA2FhJHj{9_Qi~bU5z| zI_P>+NT3|;VnNP=+#NKC9kkpdz*67Z;=q*JmvkfLyot= zp-Y9(_W>5mx)}I2iq|Yco@<1hZX=R1^&Y{smg5WgG~_Z9xkK&;4mrMfAA_9M9jwgt zF+`RDK=`z5Qa+Kv}f|lbw?gZqvQNRwAVf-&d zE!Tuir>2rK%VU;T5LrL<<148a$X&^dcF=8q4cL(^D7VIupfBk{EK7&aTqeXD8h~m! z(gH{Nx+`!`hOhE$CC4_~!2aRbaF&%#b}QJSeONHvL{3ps}Sga3agojex@*II^|CaV_(P-W{8WWA3Sciw*V_X$JB$q|Lqj#7_F}hr!R5l zCZn$lcbH0Gt*;9!JRdO6(Xi)SIP2L6Do@bZxE1u6qrM*CGOSNQ;D=|{zYFQ7YVPgp?x0#*5ipd0Q@wb56f)+E@1s!Oa2#ub@1ZiYdM(DxV*2?zj$`|N5J}-kokXM z%U=#Y^?4nb_e)#?UnnMRzCO#n*q+q%+3V%NoPY0!JkKiE+WZ@2ew;f4*3Z7Iuh-`5 zv)-SwF=qzW|Bt}>Ihyh>+WbdtKF>5W==zJ$FugxO`NhEcd6;-58;+pQhJOs$d6xP< z=C{XxG5Yhn-2_yVxre;|JpSnoFwyRit+dmh9~fc0Jtu@86`#;Y#xCN3HfI4`n&L14Wn zMEM77zCJ7ec^m8Y9kem;Ow9i*a24i1&Wpqsg5lJEKCttw`wC`6&}Zv6+IR$M%-;^Y zO#631k=PEb_adm@CxE$5Wf}9Z@hG@c=r}Jg0#Pew#oOCUaT?vIZmMfA*4H*R@ff{P zlZ9@o&an72V}#mzN>^Na-8DE3-qqb{Vxyc8$IFejh|$p*Y4vv+^0CM8$9sf&TxyGV zb@l3cd>d?6F$WxZG1U%0lW;f2CoBBJ%0a zFswkkQHE3N;kMlB-1U5OY+ZWE=^$OwFwuS8u4T7JQ7%Xpwyizp6@}m6vDY?Uy0Wq|Ap6cA|Zz z-g&TpTAU~B?L+#3SX}BXbhSC%P+pFM{_C)d&13$)dim8uRzH=OHJVmasLQO2Tl}oT z;htyvoTI(l2yW%~5m^OQFZc2L41PP2(+2tYp67E4er=I0D!((BZf6WVW38 z>>*n)TboMm#n+%aeDzz{s+=zxoLTvCMa-Fy+p^^=bYZK*Z8w`{ceQ#cgpCYUdj2m( zvQ_5y7w4)(e_N7m({gFkM(Z#5z9qYQBm46b%oEeDs@~B#l~ZrQoGEA6q_V*bn4v8u zZG2XZ6ye+SPQZrzY8%^n8v)`FTs0aE@bMYj>BN zkMJc@cFpq3mvdz=U#@$E-1PLuz-*%2{4k z6N=eW2HPMfA^STh{Si`jn{qp=e1)TqOe^>Sk+b2`FMpk>^3x+{!e9O!SB{b +#include "MySocketTCP.h" + +using namespace std; + +int main(int argc, char *argv[]){ + + if(argc!=2){ + cout<<"Usage: send ip_addess/hostName"<SendDataAndKeepConnection(data,2000)<SendData(data,2200)<SendData(data,1200)<SendData(data,25000)<SendData(data,222)< +#include +#include +using namespace std; + +typedef double double32_t; +typedef float float32_t; +typedef int int32_t; + + + +/** Circular Fifo (a.k.a. Circular Buffer) +* Thread safe for one reader, and one writer */ +template +class CircularFifo { +public: + + CircularFifo(unsigned int Size) : tail(0), head(0){ + Capacity = Size + 1; + array.resize(Capacity); + sem_init(&free_mutex,0,0); + } + virtual ~CircularFifo() {} + + bool push(Element*& item_); + bool pop(Element*& item_); + + bool isEmpty() const; + bool isFull() const; + + int getSemValue(); + +private: + volatile unsigned int tail; // input index + vector array; + volatile unsigned int head; // output index + unsigned int Capacity; + sem_t free_mutex; + + unsigned int increment(unsigned int idx_) const; +}; + +template +int CircularFifo::getSemValue() +{ + int value; + sem_getvalue(&free_mutex, &value); + return value; +} + + +/** Producer only: Adds item to the circular queue. +* If queue is full at 'push' operation no update/overwrite +* will happen, it is up to the caller to handle this case +* +* \param item_ copy by reference the input item +* \return whether operation was successful or not */ +template +bool CircularFifo::push(Element*& item_) +{ + + int nextTail = increment(tail); + if(nextTail != head) + { + array[tail] = item_; + tail = nextTail; + sem_post(&free_mutex); + return true; + } + + // queue was full + return false; +} + +/** Consumer only: Removes and returns item from the queue +* If queue is empty at 'pop' operation no retrieve will happen +* It is up to the caller to handle this case +* +* \param item_ return by reference the wanted item +* \return whether operation was successful or not */ +template +bool CircularFifo::pop(Element*& item_) +{ + // if(head == tail) + // return false; // empty queue + sem_wait(&free_mutex); + + item_ = array[head]; + head = increment(head); + return true; +} + +/** Useful for testinng and Consumer check of status + * Remember that the 'empty' status can change quickly + * as the Procuder adds more items. + * + * \return true if circular buffer is empty */ +template +bool CircularFifo::isEmpty() const +{ + return (head == tail); +} + +/** Useful for testing and Producer check of status + * Remember that the 'full' status can change quickly + * as the Consumer catches up. + * + * \return true if circular buffer is full. */ +template +bool CircularFifo::isFull() const +{ + int tailCheck = (tail+1) % Capacity; + return (tailCheck == head); +} + +/** Increment helper function for index of the circular queue +* index is inremented or wrapped +* +* \param idx_ the index to the incremented/wrapped +* \return new value for the index */ +template +unsigned int CircularFifo::increment(unsigned int idx_) const +{ + // increment or wrap + // ================= + // index++; + // if(index == array.lenght) -> index = 0; + // + //or as written below: + // index = (index+1) % array.length + idx_ = (idx_+1) % Capacity; + return idx_; +} + +#endif /* CIRCULARFIFO_H_ */ + + + + + +/* +#ifndef CIRCULARFIFO_H_ +#define CIRCULARFIFO_H_ + +#include "sls_receiver_defs.h" + +#include "/usr/include/alsa/atomic.h" +#include +using namespace std; + +template +class CircularFifo { +public: + + CircularFifo(unsigned int Size) : tail(0), head(0){ + Capacity = Size + 1; + array.resize(Capacity); + } + virtual ~CircularFifo() {} + + bool push(Element*& item_); + bool pop(Element*& item_); + + bool wasEmpty() const; + bool wasFull() const; + bool isLockFree() const; + +private: + vector array; + unsigned int Capacity; + + std::atomic tail; // input index + std::atomic head; // output index + + unsigned int increment(unsigned int idx_) const; +}; + + +template +bool CircularFifo::push(Element*& item_) +{ + auto currentTail = tail.load(); + auto nextTail = increment(currentTail); + if(nextTail != head.load()) + { + array[currentTail] = item_; + tail.store(nextTail); + return true; + } + + // queue was full + return false; +} + + +template +bool CircularFifo::pop(Element*& item_) +{ + const auto currentHead = head.load(); + if(currentHead == tail.load()) + return false; // empty queue + + item_ = array[currentHead]; + head.store(increment(currentHead)); + return true; +} + + +template +bool CircularFifo::wasEmpty() const +{ + return (head.load() == tail.load()); +} + + +template +bool CircularFifo::wasFull() const +{ + const auto nextTail = increment(tail.load()); + return (nextTail == head.load()); +} + +template +bool CircularFifo::isLockFree() const +{ + return (tail.is_lock_free() && head.is_lock_free()); +} + + +template +unsigned int CircularFifo::increment(unsigned int idx_) const +{ + // increment or wrap + // ================= + // index++; + // if(index == array.lenght) -> index = 0; + // + //or as written below: + // index = (index+1) % array.length + return (idx_ + 1) % Capacity; +} + +#endif */ diff --git a/slsReceiverSoftware/includes/receiver_defs.h b/slsReceiverSoftware/includes/receiver_defs.h new file mode 100755 index 0000000000..8dfbf7c992 --- /dev/null +++ b/slsReceiverSoftware/includes/receiver_defs.h @@ -0,0 +1,72 @@ +#ifndef RECEIVER_DEFS_H +#define RECEIVER_DEFS_H + +#include "sls_receiver_defs.h" + +#include + +#define GOODBYE -200 + +#define DO_NOTHING 0 +#define CREATE_FILES 1 +#define DO_EVERYTHING 2 + +#define BUF_SIZE (16*1024*1024) //16mb +#define SAMPLE_TIME_IN_NS 100000000//100ms +#define MAX_JOBS_PER_THREAD 1000 +#define HEADER_SIZE_NUM_TOT_PACKETS 2 +#define HEADER_SIZE_NUM_FRAMES 2 +#define HEADER_SIZE_NUM_PACKETS 1 + + +//all max frames defined in sls_receiver_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench + + +#define GOTTHARD_FIFO_SIZE 25000 //cannot be less than max jobs per thread = 1000 +/*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/ +#define GOTTHARD_PACKETS_PER_FRAME 2 +#define GOTTHARD_ONE_PACKET_SIZE 1286 +#define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2 +#define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME) //1280*2 + +#define GOTTHARD_SHORT_PACKETS_PER_FRAME 1 +#define GOTTHARD_SHORT_BUFFER_SIZE 518 +#define GOTTHARD_SHORT_DATABYTES 512 +#define GOTTHARD_SHORT_FRAME_INDEX_MASK 0xFFFFFFFF +#define GOTTHARD_SHORT_FRAME_INDEX_OFFSET 0 +#define GOTTHARD_SHORT_PACKET_INDEX_MASK 0 +#define GOTTHARD_SHORT_PIXELS_IN_ROW 256 +#define GOTTHARD_SHORT_PIXELS_IN_COL 1 + + +#define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE +#define GOTTHARD_FRAME_INDEX_OFFSET 1 +#define GOTTHARD_PACKET_INDEX_MASK 0x1 + +#define GOTTHARD_PIXELS_IN_ROW 1280 +#define GOTTHARD_PIXELS_IN_COL 1 + + + +#define MOENCH_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 +/*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ +#define MOENCH_PACKETS_PER_FRAME 40 +#define MOENCH_ONE_PACKET_SIZE 1286 +#define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40 +#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) //1280*40 + +#define MOENCH_BYTES_PER_ADC (40*2) +#define MOENCH_PIXELS_IN_ONE_ROW 160 +#define MOENCH_BYTES_IN_ONE_ROW (MOENCH_PIXELS_IN_ONE_ROW*2) + + +#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 +#define MOENCH_FRAME_INDEX_OFFSET 8 +#define MOENCH_PACKET_INDEX_MASK 0xFF + + + + + +//#define THIS_SOFTWARE_VERSION 0x20120919 +#endif diff --git a/slsReceiverSoftware/includes/sls_receiver_defs.h b/slsReceiverSoftware/includes/sls_receiver_defs.h new file mode 100755 index 0000000000..c4c1fc63e4 --- /dev/null +++ b/slsReceiverSoftware/includes/sls_receiver_defs.h @@ -0,0 +1,118 @@ +#ifndef SLS_RECEIVER_DEFS_H +#define SLS_RECEIVER_DEFS_H + + +#ifdef __CINT__ +#define MYROOT +#define __cplusplus +#endif + +#include + + +typedef double double32_t; +typedef float float32_t; +typedef int int32_t; + +/** default maximum string length */ +#define MAX_STR_LENGTH 1000 +#define MAX_FRAMES_PER_FILE 20000 +#define SHORT_MAX_FRAMES_PER_FILE 100000 +#define MOENCH_MAX_FRAMES_PER_FILE 1000 + + +/** + \file sls_receiver_defs.h +This file contains all the basic definitions common to the slsReceiver class +and to the server programs running on the receiver + * @author Anna Bergamaschi + * @version 0.1alpha (any string) + * @see slsDetector +$Revision: 809 $ + */ + + +#ifdef __cplusplus + +/** @short class containing all the constants and enum definitions */ +class slsReceiverDefs { +public: + + slsReceiverDefs(){}; + +#endif + + /** + Type of the detector + */ + enum detectorType { + GET_DETECTOR_TYPE=-1, /**< the detector will return its type */ + GENERIC, /**< generic sls detector */ + MYTHEN, /**< mythen */ + PILATUS, /**< pilatus */ + EIGER, /**< eiger */ + GOTTHARD, /**< gotthard */ + PICASSO, /**< picasso */ + AGIPD, /**< agipd */ + MOENCH /**< moench */ + }; + + + /** + return values + */ + enum { + OK, /**< function succeeded */ + FAIL, /**< function failed */ + FINISHED, /**< acquisition finished */ + FORCE_UPDATE + }; + + + /** + indexes for the acquisition timers + */ + enum timerIndex { + FRAME_NUMBER, /**< number of real time frames: total number of acquisitions is number or frames*number of cycles */ + ACQUISITION_TIME, /**< exposure time */ + FRAME_PERIOD, /**< period between exposures */ + DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */ + GATES_NUMBER, /**< number of gates per frame (in gated mode) */ + PROBES_NUMBER, /**< number of probe types in pump-probe mode */ + CYCLES_NUMBER, /**< number of cycles: total number of acquisitions is number or frames*number of cycles */ + ACTUAL_TIME, /**< Actual time of the detector's internal timer */ + MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */ + + PROGRESS, /**< fraction of measurement elapsed - only get! */ + MEASUREMENTS_NUMBER + }; + + + /** + staus mask + */ + enum runStatus { + IDLE, /**< detector ready to start acquisition - no data in memory */ + ERROR, /**< error i.e. normally fifo full */ + WAITING, /**< waiting for trigger or gate signal */ + RUN_FINISHED, /**< acquisition not running but data in memory */ + TRANSMITTING, /**< acquisition running and data in memory */ + RUNNING /**< acquisition running, no data in memory */ + }; + + + +#ifdef __cplusplus +protected: +#endif + +#ifndef MYROOT +#include "sls_receiver_funcs.h" +#endif + +#ifdef __cplusplus +}; +#endif +; +#endif +; diff --git a/slsReceiverSoftware/includes/sls_receiver_funcs.h b/slsReceiverSoftware/includes/sls_receiver_funcs.h new file mode 100644 index 0000000000..298eb39b10 --- /dev/null +++ b/slsReceiverSoftware/includes/sls_receiver_funcs.h @@ -0,0 +1,55 @@ +/** + @internal + function indexes to call on the server + All set functions with argument -1 work as get, when possible + */ +#ifndef SLS_RECEIVER_FUNCS_H +#define SLS_RECEIVER_FUNCS_H + +enum { + //General functions + F_EXEC_RECEIVER_COMMAND=0, /**< command is executed */ + F_EXIT_RECEIVER, /**< turn off receiver server */ + F_LOCK_RECEIVER, /**< Locks/Unlocks server communication to the given client */ + F_GET_LAST_RECEIVER_CLIENT_IP, /**< returns the IP of the client last connected to the receiver */ + F_SET_RECEIVER_PORT, /**< Changes communication port of the receiver */ + F_UPDATE_RECEIVER_CLIENT, /**< Returns all the important parameters to update the shared memory of the client */ + + // Identification + F_GET_RECEIVER_ID, /**< get receiver id of version */ + F_GET_RECEIVER_TYPE, /**< return receiver type */ + F_SEND_RECEIVER_DETHOSTNAME, /**< set detector hostname to receiver */ + + //network functions + F_RECEIVER_SHORT_FRAME, /**< Sets receiver to receive short frames */ + F_SETUP_RECEIVER_UDP, /**< sets the receiver udp connection and returns receiver mac address */ + + //Acquisition setup functions + F_SET_RECEIVER_TIMER, /**< set/get timer value */ + F_SET_RECEIVER_DYNAMIC_RANGE, /**< set/get detector dynamic range */ + F_READ_RECEIVER_FREQUENCY, /**< sets the frequency of receiver sending frames to gui */ + + // Acquisition functions + F_GET_RECEIVER_STATUS, /**< gets the status of receiver listening mode */ + F_START_RECEIVER, /**< starts the receiver listening mode */ + F_STOP_RECEIVER, /**< stops the receiver listening mode */ + F_START_RECEIVER_READOUT, /**< acquisition has stopped. start remaining readout in receiver */ + F_READ_RECEIVER_FRAME, /**< read one frame to gui*/ + + //file functions + F_SET_RECEIVER_FILE_PATH, /**< sets receiver file directory */ + F_SET_RECEIVER_FILE_NAME, /**< sets receiver file name */ + F_SET_RECEIVER_FILE_INDEX, /**< sets receiver file index */ + F_SET_RECEIVER_FRAME_INDEX, /**< sets the receiver frame index */ + F_GET_RECEIVER_FRAME_INDEX, /**< gets the receiver frame index */ + F_GET_RECEIVER_FRAMES_CAUGHT, /**< gets the number of frames caught by receiver */ + F_RESET_RECEIVER_FRAMES_CAUGHT, /**< resets the frames caught by receiver */ + F_ENABLE_RECEIVER_FILE_WRITE, /**< sets the receiver file write */ + F_ENABLE_RECEIVER_COMPRESSION, /**< enable compression in receiver */ + F_ENABLE_RECEIVER_OVERWRITE /**< set overwrite flag in receiver */ + + /* Always append functions hereafter!!! */ +}; + +#endif +/** @endinternal */ diff --git a/slsReceiverSoftware/includes/svnInfoReceiver.h b/slsReceiverSoftware/includes/svnInfoReceiver.h new file mode 100644 index 0000000000..5b0ab940b1 --- /dev/null +++ b/slsReceiverSoftware/includes/svnInfoReceiver.h @@ -0,0 +1,11 @@ +//#define SVNPATH "" +#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsReceiverSoftware/includes" +//#define SVNREPPATH "" +#define SVNREPUUID "5644e8d6-1a0c-4dbd-ab0e-45e7522ac187" +//#define SVNREV 0x5 +//#define SVNKIND "" +//#define SVNSCHED "" +#define SVNAUTH "l_maliakal_d" +#define SVNREV 0x5 +#define SVNDATE 0x20140515 +// diff --git a/slsReceiverSoftware/includes/svnInfoReceiverTmp.h b/slsReceiverSoftware/includes/svnInfoReceiverTmp.h new file mode 100644 index 0000000000..58e48f4978 --- /dev/null +++ b/slsReceiverSoftware/includes/svnInfoReceiverTmp.h @@ -0,0 +1,11 @@ +//#define SVNPATH "" +#define SVNURL "" +//#define SVNREPPATH "" +#define SVNREPUUID "" +//#define SVNREV "" +//#define SVNKIND "" +//#define SVNSCHED "" +#define SVNAUTH "" +#define SVNREV "" +#define SVNDATE "" +// diff --git a/slsReceiverSoftware/slsDetectorCalibration/MovingStat.h b/slsReceiverSoftware/slsDetectorCalibration/MovingStat.h new file mode 100755 index 0000000000..9d3720b1b8 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/MovingStat.h @@ -0,0 +1,130 @@ +#ifndef MOVINGSTAT_H +#define MOVINGSTAT_H + +#include + + +class MovingStat + { + + /** @short approximated moving average structure */ + public: + + + /** constructor + \param nn number of samples parameter to be used + */ + MovingStat(int nn=1000) : n(nn), m_n(0) {} + + /** + clears the moving average number of samples parameter, mean and standard deviation + */ + void Clear() + { + m_n = 0; + m_newM=0; + m_newM2=0; + } + + + /** sets number of samples parameter + \param i number of samples parameter to be set + */ + + void SetN(int i) {if (i>=1) n=i;}; + + /** + gets number of samples parameter + \returns actual number of samples parameter + */ + int GetN() {return n;}; + + /** calculates the moving average i.e. adds if number of elements is lower than number of samples parameter, pushes otherwise + \param x value to calculate the moving average + */ + inline void Calc(double x) { + if (m_n 0) ? m_newM/m_n : 0.0; + } + + /** returns the squared mean, 0 if no elements are inside + \returns returns the squared average + */ + double M2() const + { + return ( (m_n > 1) ? m_newM2/m_n : 0.0 ); + } + + /** returns the variance, 0 if no elements are inside + \returns returns the variance + */ + inline double Variance() const + { + return ( (m_n > 1) ? (M2()-Mean()*Mean()) : 0.0 ); + } + + /** returns the standard deviation, 0 if no elements are inside + \returns returns the standard deviation + */ + inline double StandardDeviation() const + { + return ( (Variance() > 0) ? sqrt( Variance() ) : -1 ); + } + + private: + int n; /**< number of samples parameter */ + int m_n; /**< current number of elements */ + double m_newM; /**< accumulated average */ + double m_newM2; /**< accumulated squared average */ + }; +#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/RunningStat.h b/slsReceiverSoftware/slsDetectorCalibration/RunningStat.h new file mode 100755 index 0000000000..1197ffc0fa --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/RunningStat.h @@ -0,0 +1,55 @@ + class RunningStat + { + public: + RunningStat() : m_n(0) {} + + void Clear() + { + m_n = 0; + } + + void Push(double x) + { + m_n++; + + // See Knuth TAOCP vol 2, 3rd edition, page 232 + if (m_n == 1) + { + m_oldM = m_newM = x; + m_oldS = 0.0; + } + else + { + m_newM = m_oldM + (x - m_oldM)/m_n; + m_newS = m_oldS + (x - m_oldM)*(x - m_newM); + + // set up for next iteration + m_oldM = m_newM; + m_oldS = m_newS; + } + } + + int NumDataValues() const + { + return m_n; + } + + double Mean() const + { + return (m_n > 0) ? m_newM : 0.0; + } + + double Variance() const + { + return ( (m_n > 1) ? m_newS/(m_n - 1) : 0.0 ); + } + + double StandardDeviation() const + { + return sqrt( Variance() ); + } + + private: + int m_n; + double m_oldM, m_newM, m_oldS, m_newS; + }; diff --git a/slsReceiverSoftware/slsDetectorCalibration/chiptestBoardData.h b/slsReceiverSoftware/slsDetectorCalibration/chiptestBoardData.h new file mode 100644 index 0000000000..0ef633c44c --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/chiptestBoardData.h @@ -0,0 +1,89 @@ +#ifndef CHIPTESTDATA_H +#define CHIPTESTDATA_H + +#include "slsDetectorData.h" + +class chiptestBoardData : public slsDetectorData { + + + public: + + /** + chiptestBoard data structure. Works for data acquired using the chiptestBoard. + Inherits and implements slsDetectorData. + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param nadc number of adcs + \param offset offset at the beginning of the pattern + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. + + */ + chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; // should be? nadc*(npx*npy+offset) + + + + /** + + Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. + \param buff pointer to the dataset + \returns frame number + + */ + + virtual int getFrameNumber(char *buff){(void)buff; return iframe;}; + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param data pointer to the memory to be analyzed + \param ndata size of frame returned + \param dsize size of the memory slot to be analyzed + \returns always return the pointer to data (no frame loss!) + */ + + virtual char *findNextFrame(char *data, int &ndata, int dsize) {ndata=dsize;setDataSize(dsize); return data;}; + + /** + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param filebin input file stream (binary) + \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete + */ + + virtual char *readNextFrame(ifstream &filebin) { + + int afifo_length=0; + uint16_t *afifo_cont; + + if (filebin.is_open()) { + if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) { + setDataSize(afifo_length*nAdc*sizeof(uint16_t)); + afifo_cont=new uint16_t[afifo_length*nAdc]; + if (filebin.read((char*)afifo_cont,afifo_length*sizeof(uint16_t)*nAdc)) { + iframe++; + return (char*)afifo_cont; + } else { + delete [] afifo_cont; + return NULL; + } + } else { + return NULL; + } + } + return NULL; + }; + + private: + const int nAdc; /**0) cmStat[i].Calc(cmPed[i]/nCm[i]); + nCm[i]=0; + cmPed[i]=0; + }}; + + /** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest + \param val value to add + \param ix pixel x coordinate + \param iy pixel y coordinate + */ + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + (void) ix; (void) iy; + + //if (isc>=0 && isc0) return cmPed[0]/nCm[0]-cmStat[0].Mean(); + return 0;}; + + + + + + protected: + MovingStat *cmStat; /**SetName("cds_g4"); + hs2N->SetTitle("cds_g4"); + (TH2F*)(hs2N->GetHists()->At(0))->Write(); + + (TH2F*)(hs2N->GetHists()->At(1))->Write(); + (TH2F*)(hs2N->GetHists()->At(2))->Write(); + (TH2F*)(hs2N->GetHists()->At(3))->Write(); + (TH2F*)(hs2N->GetHists()->At(4))->Write(); + + + fout->Close(); + + + +} + diff --git a/slsReceiverSoftware/slsDetectorCalibration/doxy.config b/slsReceiverSoftware/slsDetectorCalibration/doxy.config new file mode 100644 index 0000000000..7d2a396ff4 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/doxy.config @@ -0,0 +1,85 @@ +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + + + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = YES + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +INTERNAL_DOCS = NO + +SHOW_INCLUDE_FILES = NO + +SHOW_FILES = NO + +SHOW_NAMESPACES = NO + +COMPACT_LATEX = YES + +PAPER_TYPE = a4 + +PDF_HYPERLINKS = YES + +USE_PDFLATEX = YES + +LATEX_HIDE_INDICES = YES + +PREDEFINED = __cplusplus + +INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h chiptestBoardData.h jungfrau02Data.h jungfrauReadData.C jungfrau02CommonMode.h +OUTPUT_DIRECTORY = docs + diff --git a/slsReceiverSoftware/slsDetectorCalibration/energyCalibration.cpp b/slsReceiverSoftware/slsDetectorCalibration/energyCalibration.cpp new file mode 100644 index 0000000000..6911220955 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/energyCalibration.cpp @@ -0,0 +1,527 @@ +#include "energyCalibration.h" + +#ifdef __CINT +#define MYROOT +#endif + + +#ifdef MYROOT +#include +#include +#include +#include +#endif + +#include + +#define max(a,b) ((a) > (b) ? (a) : (b)) +#define min(a,b) ((a) < (b) ? (a) : (b)) +#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; } + + +using namespace std; + +#ifdef MYROOT + +Double_t energyCalibrationFunctions::pedestal(Double_t *x, Double_t *par) { + return par[0]-par[1]*sign*x[0]; +} + + +Double_t energyCalibrationFunctions::gaussChargeSharing(Double_t *x, Double_t *par) { + Double_t f, arg=0; + if (par[3]!=0) arg=sign*(x[0]-par[2])/par[3]; + f=TMath::Exp(-1*arg*arg/2.); + f=f+par[5]/2.*(TMath::Erfc(arg/(TMath::Sqrt(2.)))); + return par[4]*f+pedestal(x,par); +} + +Double_t energyCalibrationFunctions::gaussChargeSharingPixel(Double_t *x, Double_t *par) { + Double_t f; + if (par[3]<=0 || par[2]*(*x)<=0 || par[5]<0 || par[4]<=0) return 0; + + Double_t pp[3]; + + pp[0]=0; + pp[1]=par[2]; + pp[2]=par[3]; + + + f=(par[5]-par[6]*(TMath::Log(*x/par[2])))*erfBox(x,pp); + f+=par[4]*TMath::Gaus(*x, par[2], par[3], kTRUE); + return f+pedestal(x,par); +} + +Double_t energyCalibrationFunctions::erfBox(Double_t *z, Double_t *par) { + + + + Double_t m=par[0]; + Double_t M=par[1]; + + if (par[0]>par[1]) { + m=par[1]; + M=par[0]; + } + + if (m==M) + return 0; + + + if (par[2]<=0) { + if (*z>=m && *z<=M) + return 1./(M-m); + else + return 0; + + } + + return (TMath::Erfc((z[0]-M)/par[2])-TMath::Erfc((z[0]-m)/par[2]))*0.5/(M-m); + +} + + +// basic erf function +Double_t energyCalibrationFunctions::erfFunction(Double_t *x, Double_t *par) { + double arg=0; + if (par[1]!=0) arg=(par[0]-x[0])/par[1]; + return ((par[2]/2.*(1+TMath::Erf(sign*arg/(TMath::Sqrt(2)))))); +}; + + +Double_t energyCalibrationFunctions::erfFunctionChargeSharing(Double_t *x, Double_t *par) { + Double_t f; + + f=erfFunction(x, par+2)*(1+par[5]*(par[2]-x[0]))+par[0]-par[1]*x[0]*sign; + return f; +}; + + +Double_t energyCalibrationFunctions::erfFuncFluo(Double_t *x, Double_t *par) { + Double_t f; + f=erfFunctionChargeSharing(x, par)+erfFunction(x, par+6)*(1+par[9]*(par[6]-x[0])); + return f; +}; +#endif + +double energyCalibrationFunctions::median(double *x, int n){ + // sorts x into xmed array and returns median + // n is number of values already in the xmed array + double xmed[n]; + int k,i,j; + + for (i=0; i*(x+j)) + k++; + if (*(x+i)==*(x+j)) { + if (i>j) + k++; + } + } + xmed[k]=*(x+i); + } + k=n/2; + return xmed[k]; +} + + +int energyCalibrationFunctions::quick_select(int arr[], int n){ + int low, high ; + int median; + int middle, ll, hh; + + low = 0 ; high = n-1 ; median = (low + high) / 2; + for (;;) { + if (high <= low) /* One element only */ + return arr[median] ; + + if (high == low + 1) { /* Two elements only */ + if (arr[low] > arr[high]) + ELEM_SWAP(arr[low], arr[high]) ; + return arr[median] ; + } + + /* Find median of low, middle and high items; swap into position low */ + middle = (low + high) / 2; + if (arr[middle] > arr[high]) ELEM_SWAP(arr[middle], arr[high]) ; + if (arr[low] > arr[high]) ELEM_SWAP(arr[low], arr[high]) ; + if (arr[middle] > arr[low]) ELEM_SWAP(arr[middle], arr[low]) ; + + /* Swap low item (now in position middle) into position (low+1) */ + ELEM_SWAP(arr[middle], arr[low+1]) ; + + /* Nibble from each end towards middle, swapping items when stuck */ + ll = low + 1; + hh = high; + for (;;) { + do ll++; while (arr[low] > arr[ll]) ; + do hh--; while (arr[hh] > arr[low]) ; + + if (hh < ll) + break; + + ELEM_SWAP(arr[ll], arr[hh]) ; + } + + /* Swap middle item (in position low) back into correct position */ + ELEM_SWAP(arr[low], arr[hh]) ; + + /* Re-set active partition */ + if (hh <= median) + low = ll; + if (hh >= median) + high = hh - 1; + } +} + +int energyCalibrationFunctions::kth_smallest(int *a, int n, int k){ + register int i,j,l,m ; + register double x ; + + l=0 ; m=n-1 ; + while (lSetParNames("Background Offset","Background Slope","Inflection Point","Noise RMS", "Number of Photons","Charge Sharing Slope"); + + fspectrum=new TF1("fspectrum",funcs,&energyCalibrationFunctions::spectrum,0,1000,6,"energyCalibrationFunctions","spectrum"); + fspectrum->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal"); + + fspixel=new TF1("fspixel",funcs,&energyCalibrationFunctions::spectrumPixel,0,1000,7,"energyCalibrationFunctions","spectrumPixel"); + fspixel->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal","Corner"); + +#endif + + +} + + + +void energyCalibration::fixParameter(int ip, Double_t val){ + + fscurve->FixParameter(ip, val); + fspectrum->FixParameter(ip, val); +} + + +void energyCalibration::releaseParameter(int ip){ + + fscurve->ReleaseParameter(ip); + fspectrum->ReleaseParameter(ip); +} + + + + + + + +energyCalibration::~energyCalibration(){ +#ifdef MYROOT + delete fscurve; + delete fspectrum; +#endif + +} + +#ifdef MYROOT + + + + + +TH1F* energyCalibration::createMedianHistogram(TH2F* h2, int ch0, int nch, int direction) { + + if (h2==NULL || nch==0) + return NULL; + + double *x=new double[nch]; + TH1F *h1=NULL; + + double val=-1; + + if (direction==0) { + h1=new TH1F("median","Median",h2->GetYaxis()->GetNbins(),h2->GetYaxis()->GetXmin(),h2->GetYaxis()->GetXmax()); + for (int ib=0; ibGetXaxis()->GetNbins(); ib++) { + for (int ich=0; ichGetBinContent(ch0+ich+1,ib+1); + } + val=energyCalibrationFunctions::median(x, nch); + h1->SetBinContent(ib+1,val); + } + } else if (direction==1) { + h1=new TH1F("median","Median",h2->GetXaxis()->GetNbins(),h2->GetXaxis()->GetXmin(),h2->GetXaxis()->GetXmax()); + for (int ib=0; ibGetYaxis()->GetNbins(); ib++) { + for (int ich=0; ichGetBinContent(ib+1,ch0+ich+1); + } + val=energyCalibrationFunctions::median(x, nch); + h1->SetBinContent(ib+1,val); + } + } + delete [] x; + + return h1; + +} + + + + + + + + + + + + + + +void energyCalibration::setStartParameters(Double_t *par){ + bg_offset=par[0]; + bg_slope=par[1]; + flex=par[2]; + noise=par[3]; + ampl=par[4]; + cs_slope=par[5]; +} + + +void energyCalibration::getStartParameters(Double_t *par){ + par[0]=bg_offset; + par[1]=bg_slope; + par[2]=flex; + par[3]=noise; + par[4]=ampl; + par[5]=cs_slope; +} + +#endif +int energyCalibration::setChargeSharing(int p) { + if (p>=0) { + cs_flag=p; +#ifdef MYROOT + if (p) { + fscurve->ReleaseParameter(5); + fspectrum->ReleaseParameter(1); + } else { + fscurve->FixParameter(5,0); + fspectrum->FixParameter(1,0); + } +#endif + } + + return cs_flag; +} + + +#ifdef MYROOT +void energyCalibration::initFitFunction(TF1 *fun, TH1 *h1) { + + Double_t min=fit_min, max=fit_max; + + Double_t mypar[6]; + + if (max==-1) + max=h1->GetXaxis()->GetXmax(); + + if (min==-1) + min=h1->GetXaxis()->GetXmin(); + + + if (bg_offset==-1) + mypar[0]=0; + else + mypar[0]=bg_offset; + + + if (bg_slope==-1) + mypar[1]=0; + else + mypar[1]=bg_slope; + + + if (flex==-1) + mypar[2]=(min+max)/2.; + else + mypar[2]=flex; + + + if (noise==-1) + mypar[3]=0.1; + else + mypar[3]=noise; + + if (ampl==-1) + mypar[4]=h1->GetBinContent(h1->GetXaxis()->FindBin(0.5*(max+min))); + else + mypar[4]=ampl; + + if (cs_slope==-1) + mypar[5]=0; + else + mypar[5]=cs_slope; + + fun->SetParameters(mypar); + + fun->SetRange(min,max); + +} + + +TF1* energyCalibration::fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t *emypar) { + + + TF1* fitfun; + + char fname[100]; + + strcpy(fname, fun->GetName()); + + if (plot_flag) { + h1->Fit(fname,"R0Q"); + } else + h1->Fit(fname,"R0Q"); + + + fitfun= h1->GetFunction(fname); + fitfun->GetParameters(mypar); + for (int ip=0; ip<6; ip++) { + emypar[ip]=fitfun->GetParError(ip); + } + return fitfun; +} + +TF1* energyCalibration::fitSCurve(TH1 *h1, Double_t *mypar, Double_t *emypar) { + initFitFunction(fscurve,h1); + return fitFunction(fscurve, h1, mypar, emypar); +} + + + + + +TF1* energyCalibration::fitSpectrum(TH1 *h1, Double_t *mypar, Double_t *emypar) { + initFitFunction(fspectrum,h1); + return fitFunction(fspectrum, h1, mypar, emypar); +} + + + +TGraphErrors* energyCalibration::linearCalibration(int nscan, Double_t *en, Double_t *een, Double_t *fl, Double_t *efl, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff) { + + TGraphErrors *gr; + + Double_t mypar[2]; + + gr = new TGraphErrors(nscan,en,fl,een,efl); + + if (plot_flag) { + gr->Fit("pol1"); + gr->SetMarkerStyle(20); + } else + gr->Fit("pol1","0Q"); + + TF1 *fitfun= gr->GetFunction("pol1"); + fitfun->GetParameters(mypar); + + egain=fitfun->GetParError(1); + eoff=fitfun->GetParError(0); + + gain=funcs->setScanSign()*mypar[1]; + + off=mypar[0]; + + return gr; +} + + +TGraphErrors* energyCalibration::calibrate(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff, int integral) { + + TH1F *h; + + Double_t mypar[6], emypar[6]; + Double_t fl[nscan], efl[nscan]; + + + for (int ien=0; ien +#include +class TH1F; +class TH2F; +class TGraphErrors; +#endif + + +using namespace std; + + + + +const double conven=1000./3.6; /**< electrons/keV */ +const double el=1.67E-4; /**< electron charge in fC */ + + + +/** + \mainpage Common Root library for SLS detectors data analysis + * + * \section intro_sec Introduction + We know very well s-curves etc. but at the end everybody uses different functions ;-). + + * \subsection mot_sec Motivation + It would be greate to use everybody the same functions... + +*/ + + +/** + * + * +@libdoc The energiCalibration class contains all the necessary functions for s-curve fitting and linear calibration of the threshold. + * + * @short Energy calibration functions + * @author Anna Bergamaschi + * @version 0.1alpha + + + */ + +/** + class containing all the possible energy calibration functions (scurves with and without charge sharing, gaussian spectrum with and without charge sharing, possibility of chosing the sign of the X-axis) + +*/ +class energyCalibrationFunctions { + + public: + + energyCalibrationFunctions(int s=-1) {setScanSign(s);}; + + /** sets scan sign + \param s can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) otherwise gets + \returns current scan sign can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) + */ + int setScanSign(int s=0) {if (s==1 || s==-1) sign=s; return sign;};; + + +#ifdef MYROOT + /** + Gaussian Function with charge sharing pedestal + par[0] is the absolute height of the background pedestal + par[1] is the slope of the background pedestal + */ + Double_t pedestal(Double_t *x, Double_t *par); + + /** + Gaussian Function with charge sharing pedestal + par[0] is the absolute height of the background pedestal + par[1] is the slope of the background pedestal + par[2] is the gaussian peak position + par[3] is the RMS of the gaussian (and of the pedestal) + par[4] is the height of the function + par[5] is the fractional height of the charge sharing pedestal (scales with par[3]) + */ + Double_t gaussChargeSharing(Double_t *x, Double_t *par); + /** + Gaussian Function with charge sharing pedestal + par[0] is the absolute height of the background pedestal + par[1] is the slope of the background pedestal + par[2] is the gaussian peak position + par[3] is the RMS of the gaussian (and of the pedestal) + par[4] is the height of the function + par[5] is the fractional height of the charge sharing pedestal (scales with par[3]) + */ + Double_t gaussChargeSharingPixel(Double_t *x, Double_t *par); + + /** + Basic erf function + par[0] is the inflection point + par[1] is the RMS + par[2] is the amplitude + */ +Double_t erfFunction(Double_t *x, Double_t *par) ; + Double_t erfBox(Double_t *z, Double_t *par); + /** Erf function with charge sharing slope + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point + par[3] is the RMS + par[4] is the amplitude + par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) + */ +Double_t erfFunctionChargeSharing(Double_t *x, Double_t *par); + + /** Double Erf function with charge sharing slope + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point of the first energy + par[3] is the RMS of the first energy + par[4] is the amplitude of the first energy + par[5] is the angual coefficient of the charge sharing slope of the first energy (scales with par[3]) + par[6] is the inflection point of the second energy + par[7] is the RMS of the second energy + par[8] is the amplitude of the second energy + par[9] is the angual coefficient of the charge sharing slope of the second energy (scales with par[8]) + */ + +Double_t erfFuncFluo(Double_t *x, Double_t *par); + + + /** + static function Gaussian with charge sharing pedestal with the correct scan sign + par[0] is the absolute height of the background pedestal + par[1] is the slope of the pedestal + par[2] is the gaussian peak position + par[3] is the RMS of the gaussian (and of the pedestal) + par[4] is the height of the function + par[5] is the fractional height of the charge sharing pedestal (scales with par[4] + */ + Double_t spectrum(Double_t *x, Double_t *par); + + /** + static function Gaussian with charge sharing pedestal with the correct scan sign + par[0] is the absolute height of the background pedestal + par[1] is the slope of the pedestal + par[2] is the gaussian peak position + par[3] is the RMS of the gaussian (and of the pedestal) + par[4] is the height of the function + par[5] is the fractional height of the charge sharing pedestal (scales with par[4] + */ + Double_t spectrumPixel(Double_t *x, Double_t *par); + + + /** Erf function with charge sharing slope with the correct scan sign + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point + par[3] is the RMS + par[4] is the amplitude + par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) + */ + Double_t scurve(Double_t *x, Double_t *par); + + + + /** Double Erf function with charge sharing slope + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point of the first energy + par[3] is the RMS of the first energy + par[4] is the amplitude of the first energy + par[5] is the angual coefficient of the charge sharing slope of the first energy (scales with par[3]) + par[6] is the inflection point of the second energy + par[7] is the RMS of the second energy + par[8] is the amplitude of the second energy + par[9] is the angual coefficient of the charge sharing slope of the second energy (scales with par[8]) + */ + Double_t scurveFluo(Double_t *x, Double_t *par); + +#endif + +/** Calculates the median of an array of n elements */ + static double median(double *x, int n); +/** Calculates the median of an array of n elements (swaps the arrays!)*/ + static int quick_select(int arr[], int n); +/** Calculates the median of an array of n elements (swaps the arrays!)*/ + static int kth_smallest(int *a, int n, int k); + + private: + int sign; + + +}; + +/** + class alowing the energy calibration of photon counting and anlogue detectors + +*/ + +class energyCalibration { + + + public: + /** + default constructor - creates the function with which the s-curves will be fitted + */ + energyCalibration(); + + /** + default destructor - deletes the function with which the s-curves will be fitted + */ + ~energyCalibration(); + + /** sets plot flag + \param p plot flag (-1 gets, 0 unsets, >0 plot) + \returns current plot flag + */ + int setPlotFlag(int p=-1) {if (p>=0) plot_flag=p; return plot_flag;}; + + /** sets scan sign + \param s can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) otherwise gets + \returns current scan sign can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) + */ + int setScanSign(int s=0) {return funcs->setScanSign(s);}; + + /** sets plot flag + \param p plot flag (-1 gets, 0 unsets, >0 plot) + \returns current plot flag + */ + int setChargeSharing(int p=-1); + + + void fixParameter(int ip, Double_t val); + + void releaseParameter(int ip); + +#ifdef MYROOT + + /** + Creates an histogram with the median of nchannels starting from a specified one. the direction on which it is mediated can be selected (defaults to x=0) + \param h2 2D histogram on which the median will be calculated + \param ch0 starting channel + \param nch number of channels to be mediated + \param direction can be either 0 (x, default) or 1 (y) + \returns a TH1F histogram with the X-axis as a clone of the h2 Y (if direction=0) or X (if direction=0) axis, and on the Y axis the median of the counts of the mediated channels f h2 + */ + static TH1F* createMedianHistogram(TH2F* h2, int ch0, int nch, int direction=0); + + + /** sets the s-curve fit range + \param mi minimum of the fit range (-1 is histogram x-min) + \param ma maximum of the fit range (-1 is histogram x-max) + */ + void setFitRange(Double_t mi, Double_t ma){fit_min=mi; fit_max=ma;}; + + /** gets the s-curve fit range + \param mi reference for minimum of the fit range (-1 is histogram x-min) + \param ma reference for maximum of the fit range (-1 is histogram x-max) + */ + void getFitRange(Double_t &mi, Double_t &ma){mi=fit_min; ma=fit_max;}; + + +/** set start parameters for the s-curve function + \param par parameters, -1 sets to auto-calculation + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point + par[3] is the RMS + par[4] is the amplitude + par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) -- always positive + */ + void setStartParameters(Double_t *par); + +/** get start parameters for the s-curve function + \param par parameters, -1 means auto-calculated + par[0] is the pedestal + par[1] is the slope of the pedestal + par[2] is the inflection point + par[3] is the RMS + par[4] is the amplitude + par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) -- always positive + */ + void getStartParameters(Double_t *par); + + /** + fits histogram with the s-curve function + \param h1 1d-histogram to be fitted + \param mypar pointer to fit parameters array + \param emypar pointer to fit parameter errors + \returns the fitted function - can be used e.g. to get the Chi2 or similar + */ + TF1 *fitSCurve(TH1 *h1, Double_t *mypar, Double_t *emypar); + + + /** + fits histogram with the spectrum + \param h1 1d-histogram to be fitted + \param mypar pointer to fit parameters array + \param emypar pointer to fit parameter errors + \returns the fitted function - can be used e.g. to get the Chi2 or similar + */ + TF1 *fitSpectrum(TH1 *h1, Double_t *mypar, Double_t *emypar); + + + /** + calculates gain and offset for the set of inflection points + \param nscan number of energy scans + \param en array of energies (nscan long) + \param een array of errors on energies (nscan long) - can be NULL! + \param fl array of inflection points (nscan long) + \param efl array of errors on the inflection points (nscan long) + \param gain reference to gain resulting from the fit + \param off reference to offset resulting from the fit + \param egain reference to error on the gain resulting from the fit + \param eoff reference to the error on the offset resulting from the fit + \returns graph energy vs inflection point + */ + TGraphErrors* linearCalibration(int nscan, Double_t *en, Double_t *een, Double_t *fl, Double_t *efl, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff); + + /** + calculates gain and offset for the set of energy scans + \param nscan number of energy scans + \param en array of energies (nscan long) + \param een array of errors on energies (nscan long) - can be NULL! + \param h1 array of TH1 + \param gain reference to gain resulting from the fit + \param off reference to offset resulting from the fit + \param egain reference to error on the gain resulting from the fit + \param eoff reference to the error on the offset resulting from the fit + \returns graph energy vs inflection point + */ + TGraphErrors* calibrateScurves(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff){return calibrate(nscan, en, een, h1, gain, off, egain, eoff, 1);}; + + /** + calculates gain and offset for the set of energy spectra + \param nscan number of energy scans + \param en array of energies (nscan long) + \param een array of errors on energies (nscan long) - can be NULL! + \param h1 array of TH1 + \param gain reference to gain resulting from the fit + \param off reference to offset resulting from the fit + \param egain reference to error on the gain resulting from the fit + \param eoff reference to the error on the offset resulting from the fit + \returns graph energy vs peak + */ + TGraphErrors* calibrateSpectra(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff){return calibrate(nscan, en, een, h1, gain, off, egain, eoff, 0);}; + + +#endif + private: + +#ifdef MYROOT + /** + calculates gain and offset for the set of energies + \param nscan number of energy scans + \param en array of energies (nscan long) + \param een array of errors on energies (nscan long) - can be NULL! + \param h1 array of TH1 + \param gain reference to gain resulting from the fit + \param off reference to offset resulting from the fit + \param egain reference to error on the gain resulting from the fit + \param eoff reference to the error on the offset resulting from the fit + \param integral 1 is an s-curve set (default), 0 spectra + \returns graph energy vs peak/inflection point + */ + TGraphErrors* calibrate(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff, int integral=1); + + + /** + Initializes the start parameters and the range of the fit depending on the histogram characteristics and/or on the start parameters specified by the user + \param fun pointer to function to be initialized + \param h1 histogram from which to extract the range and start parameters, if not already specified by the user + +*/ + + void initFitFunction(TF1 *fun, TH1 *h1); + + + /** + Performs the fit according to the flags specified and returns the fitted function + \param fun function to fit + \param h1 histogram to fit + \param mypar pointer to fit parameters array + \param emypar pointer to fit parameter errors + \returns the fitted function - can be used e.g. to get the Chi2 or similar + */ + TF1 *fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t *emypar); + +#endif + +#ifdef MYROOT + Double_t fit_min; /**< minimum of the s-curve fitting range, -1 is histogram x-min */ + Double_t fit_max; /**< maximum of the s-curve fitting range, -1 is histogram x-max */ + + Double_t bg_offset; /**< start value for the background pedestal */ + Double_t bg_slope; /**< start value for the background slope */ + Double_t flex; /**< start value for the inflection point */ + Double_t noise; /**< start value for the noise */ + Double_t ampl; /**< start value for the number of photons */ + Double_t cs_slope; /**< start value for the charge sharing slope */ + + + TF1 *fscurve; /**< function with which the s-curve will be fitted */ + + TF1 *fspectrum; /**< function with which the spectrum will be fitted */ + + TF1 *fspixel; /**< function with which the spectrum will be fitted */ + +#endif + + energyCalibrationFunctions *funcs; + int plot_flag; /**< 0 does not plot, >0 plots (flags?) */ + + int cs_flag; /**< 0 functions without charge sharing contribution, >0 with charge sharing contribution */ + +}; + +#endif + + + + + + + + + + + + + + + + + + + diff --git a/slsReceiverSoftware/slsDetectorCalibration/gMapDemo.C b/slsReceiverSoftware/slsDetectorCalibration/gMapDemo.C new file mode 100644 index 0000000000..51addf69a7 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/gMapDemo.C @@ -0,0 +1,11 @@ +{ + //.L energyCalibration.cpp+ + //.L gainMap.C+ + TFile fin("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_cds_g4.root"); + TH2F *h2=fin.Get("h2"); + TH2F *gMap=gainMap(h2,4); + gMap->Draw("colz"); + + + +} diff --git a/slsReceiverSoftware/slsDetectorCalibration/gainMap.C b/slsReceiverSoftware/slsDetectorCalibration/gainMap.C new file mode 100644 index 0000000000..7923fe687a --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/gainMap.C @@ -0,0 +1,228 @@ +#define MYROOT +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + + +#define FOPT "0" + +TH2F *gainMap(TH2F *h2, float g) { + // int npx, npy; + int npx=160, npy=160; + // det->getDetectorSize(npx, npy); + + TH2F *gMap=new TH2F("gmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); + + Double_t ens[3]={0,8,17.5}, eens[3]={0.,0.1,0.1}; + Double_t peaks[3], epeaks[3]; + + + + int ibin; + TH1D *px; + + + energyCalibration *enCal=new energyCalibration(); + enCal->setPlotFlag(0); + // enCal->setChargeSharing(0); + enCal->setScanSign(1); + + Double_t gain, off, egain, eoff; + + + TList *functions; + TPolyMarker *pm ; + Double_t *peakX, *peakY; + TSpectrum *s=new TSpectrum(); + Double_t mypar[10], emypar[10]; + Double_t prms, np; + int iit=0; + TGraph *glin; + Double_t peakdum, hpeakdum; + + for (int ix=1; ixProjectionX("px",ibin+1,ibin+1); + prms=10*g; + iit=0; + np=s->Search(px,prms,"",0.2); + while (np !=2) { + if (np>2) + prms+=0.5*prms; + else + prms-=0.5*prms; + iit++; + if (iit>=10) + break; + np=s->Search(px,prms,"",0.2); + } + if (np!=2) + cout << "peak search could not converge " << ibin << endl; + if (np==2) { + pm=NULL; + functions=px->GetListOfFunctions(); + if (functions) + pm = (TPolyMarker*)functions->FindObject("TPolyMarker"); + if (pm) { + peakX=pm->GetX(); + peakY=pm->GetY(); + + + if (peakX[0]>peakX[1]) { + peakdum=peakX[0]; + hpeakdum=peakY[0]; + peakX[0]= peakX[1]; + peakY[0]= peakY[1]; + peakX[1]= peakdum; + peakY[1]= hpeakdum; + + } + + cout << "("<< ix << "," << iy << ") " << endl; + for (int ip=0; ipsetFitRange(peakX[ip]-10*g,peakX[ip]+10*g); + mypar[0]=0; + mypar[1]=0; + mypar[2]=peakX[ip]; + mypar[3]=g*10; + mypar[4]=peakY[ip]; + mypar[5]=0; + + + + enCal->setStartParameters(mypar); + enCal->fitSpectrum(px,mypar,emypar); + + + peaks[ip+1]=mypar[2]; + epeaks[ip+1]=emypar[2]; + } + + peaks[0]=0; + epeaks[0]=1; + + // for (int i=0; i<3; i++) cout << i << " " << ens[i] << " " << eens[i]<< " "<< peaks[i]<< " " << epeaks[i] << endl; + + glin= enCal->linearCalibration(3,ens,eens,peaks,epeaks,gain,off,egain,eoff); + + // cout << "Gain " << gain << " off " << off << endl; + if (off>-10 && off<10) { + gMap->SetBinContent(ix+1,iy+1,gain); + gMap->SetBinError(ix+1,iy+1,egain); + } + if (glin) + delete glin; + } + } + + + } + } + + return gMap; +} + + +TH2F *noiseMap(TH2F *h2) { + // int npx, npy; + int npx=160, npy=160; + // det->getDetectorSize(npx, npy); + + TH2F *nMap=new TH2F("nmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); + + int ibin; + TH1D *px; + + for (int ix=0; ixProjectionX("px",ibin+1,ibin+1); + px->Fit("gaus", FOPT); + if (px->GetFunction("gaus")) { + nMap->SetBinContent(ix+1,iy+1,px->GetFunction("gaus")->GetParameter(2)); + } + // delete px; + } + } + + return nMap; +} + + +THStack *noiseHistos(char *tit) { + char fname[10000]; + + sprintf(fname,"/data/moench_xbox_20140116/noise_map_%s.root",tit); + TFile *fn=new TFile(fname); + TH2F *nmap=(TH2F*)fn->Get("nmap"); + + if (nmap==NULL) { + cout << "No noise map in file " << fname << endl; + + return NULL; + } + + sprintf(fname,"/data/moench_xbox_20140113/gain_map_%s.root",tit); + TFile *fg=new TFile(fname); + TH2F *gmap=(TH2F*)fg->Get("gmap"); + + if (gmap==NULL) { + cout << "No gain map in file " << fname << endl; + + return NULL; + } + + nmap->Divide(gmap); + nmap->Scale(1000./3.6); + + THStack *hs=new THStack(tit,tit); + hs->SetTitle(tit); + + TH1F *h; + char hname[100]; + + cout << tit << endl; + for (int is=0; is<4; is++) { + sprintf(hname,"h%ds",is+1); + + h=new TH1F(hname,tit,500,0,500); + hs->Add(h); + // cout << hs->GetHists()->GetEntries() << endl; + for (int ix=40*is+2; ix<40*(is+1)-2; ix++) { + + for (int iy=2; iy<158; iy++) { + if (ix<100 || ix>120) + h->Fill(nmap->GetBinContent(ix+1,iy+1)); + } + } + cout << is+1 << "SC: " << "" << h->GetMean() << "+-" << h->GetRMS(); + h->Fit("gaus","0Q"); + h->SetLineColor(is+1); + if (h->GetFunction("gaus")) { + h->GetFunction("gaus")->SetLineColor(is+1); + cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParError(1); + } + cout << endl; + } + + // cout << hs->GetHists()->GetEntries() << endl; + + return hs; + + +} diff --git a/slsReceiverSoftware/slsDetectorCalibration/gotthardModuleData.h b/slsReceiverSoftware/slsDetectorCalibration/gotthardModuleData.h new file mode 100644 index 0000000000..3f674af57c --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/gotthardModuleData.h @@ -0,0 +1,148 @@ +#ifndef GOTTHARDMODULEDATA_H +#define GOTTHARDMODULEDATA_H +#include "slsReceiverData.h" + + + + + +#define FRAMEMASK 0xFFFFFFFE +#define PACKETMASK 1 +#define FRAMEOFFSET 0x1 + + +class gotthardModuleData : public slsReceiverData { +public: + + + + + /** + Implements the slsReceiverData structure for the gotthard read out by a module i.e. using the slsReceiver + (1x1280 pixels, 2 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + gotthardModuleData(double c=0): slsReceiverData(xpixels, ypixels, npackets, buffersize), xtalk(c) { + + uint16_t **dMask; + int **dMap; + int ix, iy; + int initial_offset = 2; + int offset = initial_offset; + + dMask=new uint16_t*[ypixels]; + dMap=new int*[ypixels]; + for (int i = 0; i < ypixels; i++) { + dMap[i] = new int[xpixels]; + dMask[i] = new uint16_t[xpixels]; + } + + for(ix=0; ix>FRAMEOFFSET); + }; + + + + /** + gets the packets number (last packet is labelled with 0 and is replaced with 40) + \param buff pointer to the memory + \returns packet number + + */ + + int getPacketNumber(char *buff){ + int np=(*(int*)buff); + //gotthards frame header must be incremented + ++np; + //packet index should be 1 or 2 + return ((np&PACKETMASK)+1); + }; + + + /** + returns the pixel value as double correcting for the output buffer crosstalk + \param data pointer to the memory + \param ix coordinate in the x direction + \param iy coordinate in the y direction + \returns channel value as double + + */ + double getValue(char *data, int ix, int iy=0) { + //check how it is for gotthard + if (xtalk==0) + return slsDetectorData::getValue(data, ix, iy); + else + return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); + }; + + + + /** sets the output buffer crosstalk correction parameter + \param c output buffer crosstalk correction parameter to be set + \returns current value for the output buffer crosstalk correction parameter + + */ + double setXTalk(double c) {xtalk=c; return xtalk;} + + + /** gets the output buffer crosstalk parameter + \returns current value for the output buffer crosstalk correction parameter + */ + double getXTalk() {return xtalk;} + + + + + + + +private: + + double xtalk; /** { +public: + + + + + /** + Implements the slsReceiverData structure for the gotthard short read out by a module i.e. using the slsReceiver + (1x256 pixels, 1 packet 256 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + gotthardShortModuleData(double c=0): slsReceiverData(xpixels, ypixels, npackets, buffersize), xtalk(c){ + + uint16_t **dMask; + int **dMap; + int ix, iy; + int offset = 2; + + dMask=new uint16_t*[ypixels]; + dMap=new int*[ypixels]; + for (int i = 0; i < ypixels; i++) { + dMap[i] = new int[xpixels]; + dMask[i] = new uint16_t[xpixels]; + } + + for(ix=0; ix::getValue(data, ix, iy); + else + return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); + }; + + + + /** sets the output buffer crosstalk correction parameter + \param c output buffer crosstalk correction parameter to be set + \returns current value for the output buffer crosstalk correction parameter + + */ + double setXTalk(double c) {xtalk=c; return xtalk;} + + + /** gets the output buffer crosstalk parameter + \returns current value for the output buffer crosstalk correction parameter + */ + double getXTalk() {return xtalk;} + + + + + + + +private: + + double xtalk; /**=0 && ix=0 && iy=0 && dataMap[iy][ix]8000) //exchange if gainBits==2 is returned! + d|=(1<<14); // gain bit 1 + if (*((uint16_t*)(data)+dataMap[iy][ix]+1)>8000) //exchange if gainBits==2 is returned! + d|=(1<<15); // gain bit 0 + + } + + } + return d^m; + }; + + /** + returns the pixel value as double correcting for the output buffer crosstalk + \param data pointer to the memory + \param ix coordinate in the x direction + \param iy coordinate in the y direction + \returns channel value as double + + */ + double getValue(char *data, int ix, int iy=0) { + // cout << "##" << (void*)data << " " << ix << " " < the gain bits are read out the wrong way around (i.e. GB0 and GB1 have to be reversed!) + \param data pointer to the memory + \param ix coordinate in the x direction + \param iy coordinate in the y direction + \returns gain bits as int + */ + int getGainBits(char *data, int ix, int iy=0) { + uint16_t d=getChannel(data, ix, iy); + return ((d&0xc000)>>14); + }; + //*/ + + + + + /** sets the output buffer crosstalk correction parameter + \param c output buffer crosstalk correction parameter to be set + \returns current value for the output buffer crosstalk correction parameter + + */ + double setXTalk(double c) {xtalk=c; return xtalk;} + + + /** gets the output buffer crosstalk parameter + \returns current value for the output buffer crosstalk correction parameter + */ + double getXTalk() {return xtalk;} + + + + + + + + private: + + double xtalk; /** +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +//#include +//#include +#include +#include "jungfrau02Data.h" +#include "jungfrau02CommonMode.h" +#include "singlePhotonDetector.h" + +//#include "MovingStat.h" + +using namespace std; + +#define NC 48 +#define NR 48 + + +#define MY_DEBUG 1 +#ifdef MY_DEBUG +#include +#endif + +/** + +Loops over data file to find single photons, fills the tree (and writes it to file, although the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (48*x+y) on the y axis. + + \param fformat file name format + \param tit title of the tree etc. + \param runmin minimum run number + \param runmax max run number + \param nbins number of bins for spectrum hists + \param hmin histo minimum for spectrum hists + \param hmax histo maximum for spectrum hists + \param sign sign of the spectrum to find hits + \param hc readout correlation coefficient with previous pixel + \param xmin minimum x coordinate + \param xmax maximum x coordinate + \param ymin minimum y coordinate + \param ymax maximum y coordinate + \param cmsub enable commonmode subtraction + \param hitfinder if 0: performs pedestal subtraction, not hit finding; if 1: performs both pedestal subtraction and hit finding + \returns pointer to histo stack with cluster spectra +*/ + + +THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1){ +/* + // read in calibration file + ifstream calfile("/home/l_msdetect/TriesteBeam2014/dummy data for scripts/CalibrationParametersTest_fake.txt"); + if (calfile.is_open()==0){cout << "Unable to open calibration file!" << endl;} + int pix; + double of0,sl0,of1,sl1,of2,sl2; + double of_0[NC*NR], of_1[NC*NR], of_2[NC*NR], sl_0[NC*NR], sl_1[NC*NR], sl_2[NC*NR]; + while (calfile >> pix >> of0 >> sl0 >> of1 >> sl1 >> of2 >> sl2){ + of_0[pix]=of0; + sl_0[pix]=sl0; + of_1[pix]=of1; + sl_1[pix]=sl1; + of_2[pix]=of2; + sl_2[pix]=sl2; //if(pix==200) cout << "sl_2[200] " << sl_2[200] << endl; + } + calfile.close(); +*/ + double adc_value, num_photon; + + jungfrau02Data *decoder=new jungfrau02Data(1,0,0);//(1,0,0); // (adc,offset,crosstalk) //(1,0,0) //(3,0,0) for readout of GB + jungfrau02CommonMode *cmSub=NULL; + if (cmsub) + cmSub=new jungfrau02CommonMode(); + + int nph=0; + int iev=0; + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub); + + char *buff; + char fname[10000]; + int nf=0; + + eventType thisEvent=PEDESTAL; + + // int iframe; + // double *data, ped, sigma; + + // data=decoder->getCluster(); + + TH2F *h2; + TH2F *h3; + TH2F *hetaX; // not needed for JF? + TH2F *hetaY; // not needed for JF? + + THStack *hs=new THStack("hs",fformat); + + + TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h1); + + if (hitfinder) { + h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); // not needed for JF? + hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); // not needed for JF? + hs->Add(h2); + hs->Add(h3); + hs->Add(hetaX); // not needed for JF? + hs->Add(hetaY); // not needed for JF? + } + + + ifstream filebin; + + + int ix=20, iy=20, ir, ic; + + + Int_t iFrame; + TTree *tall; + if (hitfinder) + tall=filter->initEventTree(tit, &iFrame); + + + + +#ifdef MY_DEBUG + + TCanvas *myC; + TH2F *he; + TCanvas *cH1; + TCanvas *cH2; + TCanvas *cH3; + + if (hitfinder) { + myC=new TCanvas(); + he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); + he->SetStats(kFALSE); + he->Draw("colz"); + cH1=new TCanvas(); + cH1->SetLogz(); + h1->Draw("colz"); + cH2=new TCanvas(); + cH2->SetLogz(); + h2->Draw("colz"); + cH3=new TCanvas(); + cH3->SetLogz(); + h3->Draw("colz"); + } +#endif + filter->newDataSet(); + + + for (int irun=runmin; irun<=runmax; irun++){ + sprintf(fname,fformat,irun); + cout << "file name " << fname << endl; + filebin.open((const char *)(fname), ios::in | ios::binary); + nph=0; + while ((buff=decoder->readNextFrame(filebin))) { + + + if (hitfinder) { + filter->newFrame(); + + //calculate pedestals and common modes + if (cmsub) { + // cout << "cm" << endl; + for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); + } + } + } + + // cout << "new frame " << endl; + + for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); + int gainBits=decoder->getGainBits(buff,ix,iy); //XXX + +#ifdef MY_DEBUG + if (hitfinder) { + if (iev%1000==0) + //he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); // show single photon hits // original + //he->SetBinContent(ix+1-xmin, iy+1-ymin, cmSub->getCommonMode(ix,iy)); //show common mode! + he->SetBinContent(iy+1-ymin, ix+1-xmin, (int)gainBits); //show gain bits + //he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)gainBits); // rows and columns reversed!!! + } +#endif + + if (nf>1000) { // only start filing data after 1000 frames + + // h1->Fill(decoder->getValue(buff,ix,iy), iy+NR*ix); + h1->Fill(filter->getClusterTotal(1), iy+NR*ix); + + + if (hitfinder) { + + if (thisEvent==PHOTON_MAX ) { + nph++; + + h2->Fill(filter->getClusterTotal(2), iy+NR*ix); + h3->Fill(filter->getClusterTotal(3), iy+NR*ix); + iFrame=decoder->getFrameNumber(buff); + + tall->Fill(); + + + } + + + } + + + } + } + ////////////////////////////////////////////////////////// + +#ifdef MY_DEBUG + if (iev%1000==0) { + myC->Modified(); + myC->Update(); + cH1->Modified(); + cH1->Update(); + cH2->Modified(); + cH2->Update(); + cH3->Modified(); + cH3->Update(); + } + iev++; +#endif + nf++; + + cout << "="; // one "=" for every frame that's been processed + delete [] buff; + } + cout << nph << endl; // number of photons found in file + if (filebin.is_open()) + filebin.close(); + else + cout << "Could not open file :( ... " << fname << endl; + } + if (hitfinder) + tall->Write(tall->GetName(),TObject::kOverwrite); + + + + delete decoder; + cout << "Read " << nf << " frames." << endl; + return hs; +} + diff --git a/slsReceiverSoftware/slsDetectorCalibration/moench02ModuleData.h b/slsReceiverSoftware/slsDetectorCalibration/moench02ModuleData.h new file mode 100644 index 0000000000..34b4f17834 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/moench02ModuleData.h @@ -0,0 +1,137 @@ +#ifndef MOENCH02MODULEDATA_H +#define MOENCH02MODULEDATA_H +#include "slsReceiverData.h" + + + +class moench02ModuleData : public slsReceiverData { + public: + + + + + /** + Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver + (160x160 pixels, 40 packets 1286 large etc.) + \param c crosstalk parameter for the output buffer + + */ + + + moench02ModuleData(double c=0): slsReceiverData(160, 160, 40, 1286), + xtalk(c) { + + + + + uint16_t **dMask; + int **dMap; + int ix, iy; + + + + dMask=new uint16_t*[160]; + dMap=new int*[160]; + for (int i = 0; i < 160; i++) { + dMap[i] = new int[160]; + dMask[i] = new uint16_t[160]; + } + + for (int isc=0; isc<4; isc++) { + for (int ip=0; ip<10; ip++) { + + for (int ir=0; ir<16; ir++) { + for (int ic=0; ic<40; ic++) { + + ix=isc*40+ic; + iy=ip*16+ir; + + dMap[iy][ix]=1286*(isc*10+ip)+2*ir*40+2*ic+4; + // cout << ix << " " << iy << " " << dMap[ix][iy] << endl; + } + } + } + } + + for (ix=0; ix<120; ix++) { + for (iy=0; iy<160; iy++) + dMask[iy][ix]=0x3fff; + } + for (ix=120; ix<160; ix++) { + for (iy=0; iy<160; iy++) + dMask[iy][ix]=0x0; + } + + + setDataMap(dMap); + setDataMask(dMask); + + + + + }; + + + + /** + gets the packets number (last packet is labelled with 0 and is replaced with 40) + \param buff pointer to the memory + \returns packet number + + */ + + int getPacketNumber(char *buff){ + int np=(*(int*)buff)&0xff; + if (np==0) + np=40; + return np; + }; + + + /** + returns the pixel value as double correcting for the output buffer crosstalk + \param data pointer to the memory + \param ix coordinate in the x direction + \param iy coordinate in the y direction + \returns channel value as double + + */ + double getValue(char *data, int ix, int iy=0) { + // cout << "##" << (void*)data << " " << ix << " " <::getValue(data, ix, iy); + else + return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); + }; + + + + /** sets the output buffer crosstalk correction parameter + \param c output buffer crosstalk correction parameter to be set + \returns current value for the output buffer crosstalk correction parameter + + */ + double setXTalk(double c) {xtalk=c; return xtalk;} + + + /** gets the output buffer crosstalk parameter + \returns current value for the output buffer crosstalk correction parameter + */ + double getXTalk() {return xtalk;} + + + + + + + + private: + + double xtalk; /**=0 && isc=0 && isc0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); + } + return 0; + }; + +}; + + +#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/moenchMakeTree.C b/slsReceiverSoftware/slsDetectorCalibration/moenchMakeTree.C new file mode 100644 index 0000000000..372052285d --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/moenchMakeTree.C @@ -0,0 +1,244 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "RunningStat.h" +#include "MovingStat.h" +#include "moench02ModuleData.h" +#include + +using namespace std; + + +//tree variables + int xC,yC,iFrameC; + double meC,sigC; + Double_t dataC[3][3]; +TTree* tall; + +typedef struct task_s{ + char *fformat; + char *tname; + int runmin; + int runmax; + int sign; +} Task; + +void setUpTree(char *tname){ + tall=new TTree(tname,tname); + tall->Branch("iFrame",&iFrameC,"iframe/I"); + tall->Branch("x",&xC,"x/I"); + tall->Branch("y",&yC,"y/I"); + tall->Branch("data",dataC,"data[3][3]/D"); + tall->Branch("pedestal",&meC,"pedestal/D"); + tall->Branch("rms",&sigC,"rms/D"); +} + +inline void storeEvent(int iF,int x,int y, Double_t data[][3], double me, double sig){ + TThread::Lock(); + xC = x; yC = y; iFrameC = iF; + memcpy(dataC,data,sizeof(Double_t)*3*3); + //cout << "X: " << x << " Y: " << y << endl; + /* for(int i = 0; i < 3; i++){ + for(int j = 0; j < 3; j++){ + cout << "i: " << i << " j: " << j << " dataC " << dataC[i][j] << " data " << data[i][j] << endl; + } + }*/ + meC = me; sigC = sig; + tall->Fill(); + TThread::UnLock(); +} + +void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign=1) { + double nThSigma = 3.; + moench02ModuleData *decoder=new moench02ModuleData(); + char *buff; + char fname[10000]; + + int nf=0; + + int dum, nPhotons; + double me, sig, tot, maxNei, val, valNei; + + MovingStat stat[160][160]; + MovingStat nPhotonsStat; + + ifstream filebin; + + int nbg=20; + + int ix, iy, ir, ic, mx,my; + Double_t data[3][3]; + + nPhotonsStat.Clear(); + nPhotonsStat.SetN(1000); + + for (ir=0; ir<160; ir++) { + for (ic=0; ic<160; ic++) { + stat[ir][ic].Clear(); + stat[ir][ic].SetN(nbg); + } + } + + for (int irun=runmin; irunreadNextFrame(filebin))) { + nPhotons=0; + //for (ix=0; ix<160; ix++){ + for (ix=0; ix<40; ix++){ + for (iy=0; iy<160; iy++) { + + + + dum=0; //no hit + // tot=0; + + me=stat[iy][ix].Mean(); + sig=stat[iy][ix].StandardDeviation(); + val=sign*(decoder->getChannelShort(buff,ix,iy)-me); + + + if (nf>nbg) { + me=stat[iy][ix].Mean(); + sig=stat[iy][ix].StandardDeviation(); + val=sign*decoder->getChannel(buff,ix,iy)-me; + + // dum=0; //no hit + tot=0; + maxNei = 0; + + if (val>nThSigma*sig)//{ //hit check if neighbors are higher + dum=1; + for (ir=-1; ir<2; ir++){ + for (ic=-1; ic<2; ic++){ + if ((ix+ic)>=0 && (ix+ic)<160 && (iy+ir)>=0 && (iy+ir)<160) { + valNei = sign*decoder->getChannel(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean(); + if (sign*decoder->getChannel(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! + tot+=valNei; + data[ir+1][ic+1] = valNei; + if(valNei/stat[iy+ir][ix+ic].StandardDeviation() > maxNei){ + maxNei = valNei/stat[iy+ir][ix+ic].StandardDeviation(); + mx = ir; + my = ic; + } + } + } + } + // } + + if (val<(-nThSigma*sig)) dum=2; //discard negative events! + + if(dum == 1 && mx == 0 && my == 0){ // this is an event and we are in the center + storeEvent(nf,ix,iy,data,me,sig); + nPhotons++; + //cout << "BF X: " << ix << " Y: " << iy << " val: " << val << " tot: " << tot << " me: " << me << " sig: " << sig << endl; + } + + + //if (tot>9.*sig && dum == 1){ dum=3;} + //cout << dum; + } + //if (ix==20 && iy==40) + //cout << decoder->getChannelShort(buff,ix,iy)<< " " << val << " " << me << " " << sig << " " << dum << endl; + + if ( dum==0) { + + stat[iy][ix].Calc(decoder->getChannelShort(buff,ix,iy)); + } + if (nfgetChannel(buff,ix,iy)); + + } + } + delete [] buff; + //cout << "="; cout.flush(); + if(nf>nbg) nPhotonsStat.Calc((double)nPhotons); + nf++; + } + //cout << endl; + cout << "processed File " << fname << " done. Avg. Photons/Frame: " << nPhotonsStat.Mean() << " sig: " << nPhotonsStat.StandardDeviation() << " " << runmax-irun << " files need processing" << endl; + if (filebin.is_open()) + filebin.close(); + else + cout << "could not open file " << fname << endl; + } + + delete decoder; + cout << "Read " << nf << " frames" << endl; + + +} + +void *moenchMakeTreeTask(void *p){ + Task *t = (Task *)p; + moenchMakeTree(t->fformat,t->tname,t->runmin,t->runmax,t->sign); + return 0; +} + + +//to compile: g++ -DMYROOT -g `root-config --cflags --glibs` -o moenchMakeTree moenchMakeTree.C +int main(int argc, char **argv){ + if(argc != 6){ cout << "Usage: inFile outdir tname fileNrStart fileNrEnd" << endl; exit(-1); } + + int nThreads = 10; + TThread *threads[nThreads]; + + char *inFile = argv[1]; + char *outDir = argv[2]; + char *tName = argv[3]; + int start = atoi(argv[4]); + int end = atoi(argv[5]); + + TFile *f; + char outfname[1000]; + char threadName[1000]; + + sprintf(outfname,"%s/%s.root",outDir,tName); + f=new TFile(outfname,"RECREATE"); + + cout << "outputfile: " << outfname << endl; + setUpTree(tName); + + for(int i = 0; i < nThreads; i++){ + sprintf(threadName,"t%i",i); + Task *t = (Task *)malloc(sizeof(Task)); + t->fformat = inFile; + t->tname = tName; + t->sign = 1.; + t->runmin = start + (end-start)/(nThreads)*i; + t->runmax = start + (end-start)/(nThreads)*(i+1); + if(i == nThreads - 1) t->runmax = end; + cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; + threads[i] = new TThread(threadName, moenchMakeTreeTask, t); + threads[i]->Run(); + //moenchMakeTreeTask(t); + } + + + //TThread::Ps(); + + for(int i = 0; i < nThreads; i++){ + threads[i]->Join(); + } + + + tall->Write(); + tall->Print(); + f->Close(); +} + diff --git a/slsReceiverSoftware/slsDetectorCalibration/moenchReadData.C b/slsReceiverSoftware/slsDetectorCalibration/moenchReadData.C new file mode 100644 index 0000000000..bf7173f0bb --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/moenchReadData.C @@ -0,0 +1,236 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +//#include +//#include +#include +#include "moench02ModuleData.h" +#include "moenchCommonMode.h" +#include "singlePhotonDetector.h" + +//#include "MovingStat.h" + +using namespace std; + +#define NC 160 +#define NR 160 + + +#define MY_DEBUG 1 +#ifdef MY_DEBUG +#include +#endif + +/** + +Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis. + + \param fformat file name format + \param tit title of the tree etc. + \param runmin minimum run number + \param runmax max run number + \param nbins number of bins for spectrum hists + \param hmin histo minimum for spectrum hists + \param hmax histo maximum for spectrum hists + \param sign sign of the spectrum to find hits + \param hc readout correlation coefficient with previous pixel + \param xmin minimum x coordinate + \param xmax maximum x coordinate + \param ymin minimum y coordinate + \param ymax maximum y coordinate + \param cmsub enable commonmode subtraction + \returns pointer to histo stack with cluster spectra +*/ + + +THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1) { + + moench02ModuleData *decoder=new moench02ModuleData(hc); + moenchCommonMode *cmSub=NULL; + if (cmsub) + cmSub=new moenchCommonMode(); + + int nph=0; + + singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub); + + char *buff; + char fname[10000]; + int nf=0; + + eventType thisEvent=PEDESTAL; + + // int iframe; + // double *data, ped, sigma; + + // data=decoder->getCluster(); + + TH2F *h2; + TH2F *h3; + TH2F *hetaX; + TH2F *hetaY; + + THStack *hs=new THStack("hs",fformat); + + + + TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h1); + + if (hitfinder) { + h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); + hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); + hs->Add(h2); + hs->Add(h3); + hs->Add(hetaX); + hs->Add(hetaY); + } + + + + ifstream filebin; + + + int ix=20, iy=20, ir, ic; + + + Int_t iFrame; + TTree *tall; + if (hitfinder) + tall=filter->initEventTree(tit, &iFrame); + + + + +#ifdef MY_DEBUG + + TCanvas *myC; + TH2F *he; + TCanvas *cH1; + TCanvas *cH2; + TCanvas *cH3; + + if (hitfinder) { + myC=new TCanvas(); + he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); + he->SetStats(kFALSE); + he->Draw("colz"); + cH1=new TCanvas(); + cH1->SetLogz(); + h1->Draw("colz"); + cH2=new TCanvas(); + cH2->SetLogz(); + h2->Draw("colz"); + cH3=new TCanvas(); + cH3->SetLogz(); + h3->Draw("colz"); + } +#endif + filter->newDataSet(); + + + for (int irun=runmin; irunreadNextFrame(filebin))) { + + + if (hitfinder) { + filter->newFrame(); + + //calculate pedestals and common modes + if (cmsub) { + // cout << "cm" << endl; + for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); + } + } + } + + // cout << "new frame " << endl; + + for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); + +#ifdef MY_DEBUG + if (hitfinder) { + if (iev%1000==0) + he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); + } +#endif + + if (nf>1000) { + h1->Fill(filter->getClusterTotal(1), iy+NR*ix); + if (hitfinder) { + + if (thisEvent==PHOTON_MAX ) { + nph++; + + h2->Fill(filter->getClusterTotal(2), iy+NR*ix); + h3->Fill(filter->getClusterTotal(3), iy+NR*ix); + iFrame=decoder->getFrameNumber(buff); + + tall->Fill(); + + + } + + + } + + + } + } + ////////////////////////////////////////////////////////// + +#ifdef MY_DEBUG + if (iev%1000==0) { + myC->Modified(); + myC->Update(); + cH1->Modified(); + cH1->Update(); + cH2->Modified(); + cH2->Update(); + cH3->Modified(); + cH3->Update(); + } + iev++; +#endif + nf++; + + cout << "=" ; + delete [] buff; + } + cout << nph << endl; + if (filebin.is_open()) + filebin.close(); + else + cout << "could not open file " << fname << endl; + } + if (hitfinder) + tall->Write(tall->GetName(),TObject::kOverwrite); + + + + delete decoder; + cout << "Read " << nf << " frames" << endl; + return hs; +} + diff --git a/slsReceiverSoftware/slsDetectorCalibration/moenchReadDataMT.C b/slsReceiverSoftware/slsDetectorCalibration/moenchReadDataMT.C new file mode 100644 index 0000000000..0720909c4e --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/moenchReadDataMT.C @@ -0,0 +1,52 @@ +#include +#include +#include "moenchReadData.C" + +typedef struct task_s{ + char *fformat; + char *tname; + char *tdir; + int runmin; + int runmax; + int treeIndex; +} Task; + +void *moenchMakeTreeTask(void *p){ + TThread::Lock(); + char fname[1000]; + Task *t = (Task *)p; + sprintf(fname,"%s%s_%i.root",t->tdir,t->tname,t->treeIndex); + TFile *f = new TFile(fname,"RECREATE"); + cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<")" << endl; + TThread::UnLock(); + moenchReadData(t->fformat,t->tname,t->runmin,t->runmax); + f->Close(); + return 0; +} + + +void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0){ + char threadName[1000]; + TThread *threads[nThreads]; + for(int i = 0; i < nThreads; i++){ + sprintf(threadName,"t%i",i); + Task *t = (Task *)malloc(sizeof(Task)); + t->fformat = fformat; + t->tname = tit; + t->tdir = tdir; + t->runmin = runmin + i*runoffset; + t->runmax = runmin + (i+1)*runoffset - 1; + t->treeIndex = treeIndexStart + i; + cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; + threads[i] = new TThread(threadName, moenchMakeTreeTask, t); + threads[i]->Run(); + } + + for(int i = 0; i < nThreads; i++){ + threads[i]->Join(); + } + +} + + + diff --git a/slsReceiverSoftware/slsDetectorCalibration/pedestalSubtraction.h b/slsReceiverSoftware/slsDetectorCalibration/pedestalSubtraction.h new file mode 100644 index 0000000000..ee3aff8aa8 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/pedestalSubtraction.h @@ -0,0 +1,48 @@ +#ifndef PEDESTALSUBTRACTION_H +#define PEDESTALSUBTRACTION_H + +#include "MovingStat.h" + +class pedestalSubtraction { + /** @short class defining the pedestal subtraction based on an approximated moving average */ + public: + /** constructor + \param nn number of samples to calculate the moving average (defaults to 1000) + */ + pedestalSubtraction (int nn=1000) : stat(nn) {}; + + /** virtual destructorr + */ + virtual ~pedestalSubtraction() {}; + + /** clears the moving average */ + virtual void Clear() {stat.Clear();} + + /** adds the element to the moving average + \param val value to be added + */ + virtual void addToPedestal(double val){stat.Calc(val);}; + + /** returns the average value of the pedestal + \returns mean of the moving average + */ + virtual double getPedestal(){return stat.Mean();}; + + /** returns the standard deviation of the moving average + \returns standard deviation of the moving average + */ + virtual double getPedestalRMS(){return stat.StandardDeviation();}; + + /**sets/gets the number of samples for the moving average + \param i number of elements for the moving average. If -1 (default) or negative, gets. + \returns actual number of samples for the moving average + */ + virtual int SetNPedestals(int i=-1) {if (i>0) stat.SetN(i); return stat.GetN();}; + + + + private: + MovingStat stat; /**< approximated moving average struct */ + +}; +#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/raedNoiseData.C b/slsReceiverSoftware/slsDetectorCalibration/raedNoiseData.C new file mode 100644 index 0000000000..b2021b29fe --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/raedNoiseData.C @@ -0,0 +1,136 @@ +#include "moenchReadData.C" + + + +void raedNoiseData(char *tit, int sign=1){ + + + + + + char fname[1000]; + char f[1000]; + TFile *fout; + THStack *hs2N; + + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_0.root",tit); + fout=new TFile(fname,"RECREATE"); + + sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit); + + hs2N=moenchReadData(fname,0,3000,1500,-500,2500,1,0.,1,159,1,159, 0,1); + hs2N->SetName(tit); + hs2N->SetTitle(tit); + (TH2F*)(hs2N->GetHists()->At(0))->Write(); + + (TH2F*)(hs2N->GetHists()->At(1))->Write(); + (TH2F*)(hs2N->GetHists()->At(2))->Write(); + (TH2F*)(hs2N->GetHists()->At(3))->Write(); + (TH2F*)(hs2N->GetHists()->At(4))->Write(); + + + fout->Close(); + + + +} + + + +void raedNoiseDataN(char *tit, int sign=1){ + + + + char fname[1000]; + char f[1000]; + TFile *fout; + THStack *hs2N; + + sprintf(fname,"/data/moench_xbox_20140116/noise_%s.root",tit); + fout=new TFile(fname,"RECREATE"); + + sprintf(fname,"/data/moench_xbox_20140116/noise_%s_f00000%%04d000_0.raw",tit); + + hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,0); + hs2N->SetName(tit); + hs2N->SetTitle(tit); + (TH2F*)(hs2N->GetHists()->At(0))->Write(); + + // (TH2F*)(hs2N->GetHists()->At(1))->Write(); + // (TH2F*)(hs2N->GetHists()->At(2))->Write(); + // (TH2F*)(hs2N->GetHists()->At(3))->Write(); + // (TH2F*)(hs2N->GetHists()->At(4))->Write(); + + + fout->Close(); + + + +} + + + +void g4() { + + raedNoiseData("cds_g4_low_gain"); + raedNoiseData("cds_g4_sto1_only"); + raedNoiseData("cds_g4_no sto"); + + + +} + +void no_cds() { + + raedNoiseData("cds_disable_low_gain",-1); + raedNoiseData("cds_disable_sto1_only",-1); + raedNoiseData("cds_disable_no sto",-1); + + + +} + +void all_gains() { + + raedNoiseData("cds_g2"); + raedNoiseData("cds_g2HC"); + raedNoiseData("cds_g1_2"); + raedNoiseData("cds_g2_3"); + + + +} + +void all_low_gains() { + + raedNoiseData("cds_g2_low_gain"); + raedNoiseData("cds_g2HC_low_gain"); + raedNoiseData("cds_g1_2_low_gain"); + raedNoiseData("cds_g2_3_low_gain"); +} + +/* +clkdivider data +/data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv17_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 12:40 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv25_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 13:26 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv35_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:09 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv50_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:54 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv70_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 16:42 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv110_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 17:27 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv170_f000000010000_0.raw +*/ + + +/* oversampled data +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:12 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_0.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:47 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_1.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 19:22 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_2.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:02 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_3.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:41 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_4.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:16 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_5.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:56 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_6.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 22:35 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_7.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:11 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_8.raw +-rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:50 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_9.raw +*/ + diff --git a/slsReceiverSoftware/slsDetectorCalibration/readJungfrauData.C b/slsReceiverSoftware/slsDetectorCalibration/readJungfrauData.C new file mode 100644 index 0000000000..504a152586 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/readJungfrauData.C @@ -0,0 +1,31 @@ +{ // script to run Jungfrau data analysis + + gROOT->ProcessLine(".L jungfrauReadData.C++");//"); + + TFile *fout; // output file + THStack *hs2N; // collection of objects + + //fout=new TFile("/mnt/slitnas/datadir_jungfrau02/analysis_tests/tests_random.root","RECREATE"); // + fout=new TFile("/mnt/slitnas/datadir_jungfrau02/20140404_lowEXrays/test.root","RECREATE"); + + hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140404_lowEXrays/Ti_1000clk_13kV40mA_%d.bin","tit",0,86,3000,-499.5,2500.5,1,0,1,47,1,47,1,1); //1,1); + + //hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140228_GainBits/GSdata_laser_%d.bin","tit",0,5,1500,-500,2500,1,0.,1,47,1,47,0,1);//,"/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); //1,1); // data set test GB -> set (3,0,0) in junfrauReadData.C + + //hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/digital_bit_adc_test/vb_1825_%d.bin","tit",0,7,1500,-500,2500,1,0.,1,47,1,47,0,1);//,"/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); //1,1); // data set test GB -> set (3,0,0) in junfrauReadData.C + + //hs2N->SetName("cds_g4"); + //hs2N->SetTitle("cds_g4"); + + (TH2F*)(hs2N->GetHists()->At(0))->Write(); // write hists + (TH2F*)(hs2N->GetHists()->At(1))->Write(); + (TH2F*)(hs2N->GetHists()->At(2))->Write(); + (TH2F*)(hs2N->GetHists()->At(3))->Write(); + (TH2F*)(hs2N->GetHists()->At(4))->Write(); + //(TH2F*)(hs2N->GetHists()->At(5))->Write(); + //(TH2F*)(hs2N->GetHists()->At(6))->Write(); + + fout->Close(); // uncomment + +} + diff --git a/slsReceiverSoftware/slsDetectorCalibration/singlePhotonDetector.h b/slsReceiverSoftware/slsDetectorCalibration/singlePhotonDetector.h new file mode 100644 index 0000000000..f090730a10 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/singlePhotonDetector.h @@ -0,0 +1,387 @@ +#ifndef SINGLEPHOTONDETECTOR_H +#define SINGLEPHOTONDETECTOR_H + + +#include "slsDetectorData.h" + +#include "single_photon_hit.h" +#include "pedestalSubtraction.h" +#include "commonModeSubtraction.h" + + +//#define MYROOT1 + +#ifdef MYROOT1 +#include + +#endif + + +#include + +using namespace std; + + + enum eventType { + PEDESTAL=0, + NEIGHBOUR=1, + PHOTON=2, + PHOTON_MAX=3, + NEGATIVE_PEDESTAL=4, + UNDEFINED_EVENT=-1 + }; + + enum quadrant { + TOP_LEFT=0, + TOP_RIGHT=1, + BOTTOM_LEFT=2, + BOTTOM_RIGHT=3, + UNDEFINED_QUADRANT=-1 + }; + + + +template +class singlePhotonDetector { + + /** @short class to perform pedestal subtraction etc. and find single photon clusters for an analog detector */ + + public: + + + /** + + Constructor (no error checking if datasize and offsets are compatible!) + \param d detector data structure to be used + \param csize cluster size (should be an odd number). Defaults to 3 + \param nsigma number of rms to discriminate from the noise. Defaults to 5 + \param sign 1 if photons are positive, -1 if negative + \param cm common mode subtraction algorithm, if any. Defaults to NULL i.e. none + \param nped number of samples for pedestal averaging + \param nd number of dark frames to average as pedestals without photon discrimination at the beginning of the measurement + + + */ + + + singlePhotonDetector(slsDetectorData *d, + int csize=3, + double nsigma=5, + int sign=1, + commonModeSubtraction *cm=NULL, + int nped=1000, + int nd=100) : det(d), nx(0), ny(0), stat(NULL), cmSub(cm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), cluster(NULL), iframe(-1), dataSign(sign), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) { + + + det->getDetectorSize(nx,ny); + + + + stat=new pedestalSubtraction*[ny]; + eventMask=new eventType*[ny]; + for (int i=0; iSetNPedestals(nped); + eventMask[i]=new eventType[nx]; + } + + if (ny==1) + clusterSizeY=1; + + cluster=new single_photon_hit(clusterSize,clusterSizeY); + setClusterSize(csize); + + }; + /** + destructor. Deletes the cluster structure and the pdestalSubtraction array + */ + virtual ~singlePhotonDetector() {delete cluster; for (int i=0; iClear(); }; + + /** resets the eventMask to undefined and the commonModeSubtraction */ + void newFrame(){iframe++; for (int iy=0; iynewFrame();}; + + + /** sets the commonModeSubtraction algorithm to be used + \param cm commonModeSubtraction algorithm to be used (NULL unsets) + \returns pointer to the actual common mode subtraction algorithm + */ + commonModeSubtraction setCommonModeSubtraction(commonModeSubtraction *cm) {cmSub=cm; return cmSub;}; + + + /** + sets the sign of the data + \param sign 1 means positive values for photons, -1 negative, 0 gets + \returns current sign for the data + */ + int setDataSign(int sign=0) {if (sign==1 || sign==-1) dataSign=sign; return dataSign;}; + + + /** + adds value to pedestal (and common mode) for the given pixel + \param val value to be added + \param ix pixel x coordinate + \param iy pixel y coordinate + */ + virtual void addToPedestal(double val, int ix, int iy){ + // cout << "*"<< ix << " " << iy << " " << val << endl; + if (ix>=0 && ix=0 && iyisGood(ix, iy) ) + cmSub->addToCommonMode(val, ix, iy); + }; + }; + + /** + gets pedestal (and common mode) + \param ix pixel x coordinate + \param iy pixel y coordinate + \param cm 0 (default) without common mode subtraction, 1 with common mode subtraction (if defined) + */ + virtual double getPedestal(int ix, int iy, int cm=0){if (ix>=0 && ix=0 && iy0) return stat[iy][ix].getPedestal()-cmSub->getCommonMode(); else return stat[iy][ix].getPedestal(); else return -1;}; + + /** + gets pedestal rms (i.e. noise) + \param ix pixel x coordinate + \param iy pixel y coordinate + */ + double getPedestalRMS(int ix, int iy){if (ix>=0 && ix=0 && iy0) nSigma=n; return nSigma;} + + /** sets/gets cluster size + \param n cluster size to be set, (0 or negative gets). If even is incremented by 1. + \returns actual cluster size + */ + int setClusterSize(int n=-1){ + if (n>0 && n!=clusterSize) { + if (n%2==0) + n+=1; + clusterSize=n; + if (cluster) + delete cluster; + if (ny>1) + clusterSizeY=clusterSize; + cluster=new single_photon_hit(clusterSize,clusterSizeY); + } + return clusterSize; + } + + + + + /** finds event type for pixel and fills cluster structure. The algorithm loops only if the evenMask for this pixel is still undefined. + if pixel or cluster around it are above threshold (nsigma*pedestalRMS) cluster is filled and pixel mask is PHOTON_MAX (if maximum in cluster) or NEIGHBOUR; If PHOTON_MAX, the elements of the cluster are also set as NEIGHBOURs in order to speed up the looping + if below threshold the pixel is either marked as PEDESTAL (and added to the pedestal calculator) or NEGATIVE_PEDESTAL is case it's lower than -threshold, otherwise the pedestal average would drift to negative values while it should be 0. + + /param data pointer to the data + /param ix pixel x coordinate + /param iy pixel y coordinate + /param cm enable(1)/disable(0) common mode subtraction (if defined). + /returns event type for the given pixel + */ + eventType getEventType(char *data, int ix, int iy, int cm=0) { + + // eventType ret=PEDESTAL; + double max=0, tl=0, tr=0, bl=0,br=0, v; + // cout << iframe << endl; + + tot=0; + quadTot=0; + quad=UNDEFINED_QUADRANT; + + + if (iframex=ix; + cluster->y=iy; + cluster->rms=getPedestalRMS(ix,iy); + cluster->ped=getPedestal(ix,iy, cm); + + + for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { + for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { + if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(dataSign*(det->getValue(data, ix+ic, iy+ir)-getPedestal(ix+ic,iy+ir,cm)), ic, ir ); + v=cluster->get_data(ic,ir); + tot+=v; + if (ir<=0 && ic<=0) + bl+=v; + if (ir<=0 && ic>=0) + br+=v; + if (ir>=0 && ic<=0) + tl+=v; + if (ir>=0 && ic>=0) + tr+=v; + + if (cluster->get_data(ic,ir)>max) { + max=v; + } + if (ir==0 && ic==0) { + if (v>nSigma*cluster->rms) { + eventMask[iy][ix]=PHOTON; + } else if (cluster->get_data(ic,ir)<-nSigma*cluster->rms) + eventMask[iy][ix]=NEGATIVE_PEDESTAL; + } + } + } + } + + if (eventMask[iy][ix]!=PHOTON && tot>sqrt(clusterSizeY*clusterSize)*nSigma*cluster->rms) { + eventMask[iy][ix]=NEIGHBOUR; + } else if (eventMask[iy][ix]==PHOTON) { + if (cluster->get_data(0,0)>=max) { + eventMask[iy][ix]=PHOTON_MAX; + } + } else if (eventMask[iy][ix]==PEDESTAL) { + if (cm==0) + addToPedestal(det->getValue(data, ix, iy),ix,iy); + } + + + if (bl>=br && bl>=tl && bl>=tr) { + quad=BOTTOM_LEFT; + quadTot=bl; + } else if (br>=bl && br>=tl && br>=tr) { + quad=BOTTOM_RIGHT; + quadTot=br; + } else if (tl>=br && tl>=bl && tl>=tr) { + quad=TOP_LEFT; + quadTot=tl; + } else if (tr>=bl && tr>=tl && tr>=br) { + quad=TOP_RIGHT; + quadTot=tr; + } + + + return eventMask[iy][ix]; + + }; + + /**< + retrurns the total signal in a cluster + \param size cluser size should be 1,2 or 3 + \returns cluster center if size=1, sum of the maximum quadrant if size=2, total of the cluster if size=3 or anything else + */ + + double getClusterTotal(int size) { + switch (size) { + case 1: + return getClusterElement(0,0); + case 2: + return quadTot; + default: + return tot; + }; + }; + + /**< + retrurns the quadrant with maximum signal + \returns quadrant where the cluster is located */ + + quadrant getQuadrant() {return quad;}; + + /** sets/gets number of samples for moving average pedestal calculation + \param i number of samples to be set (0 or negative gets) + \returns actual number of samples + */ + int SetNPedestals(int i=-1) {int ix=0, iy=0; if (i>0) for (ix=0; ixget_data(ic,ir);}; + + /** returns event mask for the given pixel + \param ic x coordinate (center is (0,0)) + \param ir y coordinate (center is (0,0)) + \returns event mask enum for the given pixel + */ + eventType getEventMask(int ic, int ir=0){return eventMask[ir][ic];}; + + +#ifdef MYROOT1 + /** generates a tree and maps the branches + \param tname name for the tree + \param iFrame pointer to the frame number + \returns returns pointer to the TTree + */ + TTree *initEventTree(char *tname, int *iFrame=NULL) { + TTree* tall=new TTree(tname,tname); + + if (iFrame) + tall->Branch("iFrame",iFrame,"iframe/I"); + else + tall->Branch("iFrame",&(cluster->iframe),"iframe/I"); + + tall->Branch("x",&(cluster->x),"x/I"); + tall->Branch("y",&(cluster->y),"y/I"); + char tit[100]; + sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY); + tall->Branch("data",cluster->data,tit); + tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); + tall->Branch("rms",&(cluster->rms),"rms/D"); + return tall; + }; +#else + /** write cluster to filer*/ + void writeCluster(FILE* myFile){cluster->write(myFile);}; + +#endif + + + private: + + slsDetectorData *det; /**< slsDetectorData to be used */ + int nx; /**< Size of the detector in x direction */ + int ny; /**< Size of the detector in y direction */ + + + pedestalSubtraction **stat; /**< pedestalSubtraction class */ + commonModeSubtraction *cmSub;/**< commonModeSubtraction class */ + int nDark; /**< number of frames to be used at the beginning of the dataset to calculate pedestal without applying photon discrimination */ + eventType **eventMask; /**< matrix of event type or each pixel */ + double nSigma; /**< number of sigma parameter for photon discrimination */ + int clusterSize; /**< cluster size in the x direction */ + int clusterSizeY; /**< cluster size in the y direction i.e. 1 for strips, clusterSize for pixels */ + single_photon_hit *cluster; /**< single photon hit data structure */ + int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */ + int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */ + quadrant quad; /**< quadrant where the photon is located */ + double tot; /**< sum of the 3x3 cluster */ + double quadTot; /**< sum of the maximum 2x2cluster */ + + +}; + + + + + +#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/single_photon_hit.h b/slsReceiverSoftware/slsDetectorCalibration/single_photon_hit.h new file mode 100644 index 0000000000..dda4d75714 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/single_photon_hit.h @@ -0,0 +1,62 @@ +#ifndef SINGLE_PHOTON_HIT_H +#define SINGLE_PHOTON_HIT_h + +typedef double double32_t; +typedef float float32_t; +typedef int int32_t; + + +class single_photon_hit { + + /** @short Structure for a single photon hit */ + + public: + /** constructor, instantiates the data array -- all class elements are public! + \param nx cluster size in x direction + \param ny cluster size in y direction (defaults to 1 for 1D detectors) + */ + single_photon_hit(int nx, int ny=1): dx(nx), dy(ny) {data=new double[dx*dy];}; + + ~single_photon_hit(){delete [] data;}; /**< destructor, deletes the data array */ + + /** binary write to file of all elements of the structure, except size of the cluster + \param myFile file descriptor + */ + void write(FILE *myFile) {fwrite((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fwrite((void*)data, 1, dx*dy*sizeof(double), myFile);}; + + /** + binary read from file of all elements of the structure, except size of the cluster. The structure is then filled with those args + \param myFile file descriptor + */ + void read(FILE *myFile) {fread((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fread((void*)data, 1, dx*dy*sizeof(double), myFile);}; + + /** + assign the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0) + \param v value to be set + \param ix coordinate x within the cluster (center is (0,0)) + \param iy coordinate y within the cluster (center is (0,0)) + */ + void set_data(double v, int ix, int iy=0){data[(iy+dy/2)*dx+ix+dx/2]=v;}; + + + /** + gets the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0) + \param ix coordinate x within the cluster (center is (0,0)) + \param iy coordinate y within the cluster (center is (0,0)) + \returns value of the cluster element + */ + double get_data(int ix, int iy=0){return data[(iy+dy/2)*dx+ix+dx/2];}; + + int x; /**< x-coordinate of the center of hit */ + int y; /**< x-coordinate of the center of hit */ + double rms; /**< noise of central pixel l -- at some point it can be removed*/ + double ped; /**< pedestal of the central pixel -- at some point it can be removed*/ + int iframe; /**< frame number */ + double *data; /**< pointer to data */ + const int dx; /**< size of data cluster in x */ + const int dy; /**< size of data cluster in y */ +}; + + + +#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/slsDetectorData.h b/slsReceiverSoftware/slsDetectorCalibration/slsDetectorData.h new file mode 100644 index 0000000000..294f7c8717 --- /dev/null +++ b/slsReceiverSoftware/slsDetectorCalibration/slsDetectorData.h @@ -0,0 +1,251 @@ +#ifndef SLSDETECTORDATA_H +#define SLSDETECTORDATA_H + +#include +#include +#include + +using namespace std; + + +template +class slsDetectorData { + + + public: + + /** + + + General slsDetectors data structure. Works for data acquired using the slsDetectorReceiver. Can be generalized to other detectors (many virtual funcs). + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param dsize size of the data + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. + + */ + slsDetectorData(int npx, int npy, int dsize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), dataSize(dsize) { + + + + dataMask=new dataType*[ny]; + for(int i = 0; i < ny; i++) { + dataMask[i] = new dataType[nx]; + } + dataMap=new int*[ny]; + for(int i = 0; i < ny; i++) { + dataMap[i] = new int[nx]; + } + + dataROIMask=new int*[ny]; + for(int i = 0; i < ny; i++) { + dataROIMask[i] = new int[nx]; + for (int j=0; j=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && dataMap[iy][ix] +class slsReceiverData : public slsDetectorData { + + +public: + + /** + slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers. + Inherits and implements slsDetectorData. + + Constructor (no error checking if datasize and offsets are compatible!) + \param npx number of pixels in the x direction + \param npy number of pixels in the y direction (1 for strips) + \param np number of packets + \param psize packets size + \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) + \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) + \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. + + */ + slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; + + + /** + + Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. + \param buff pointer to the dataset + \returns frame number + + */ + + virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; + + /** + + Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. + \param buff pointer to the dataset + \returns packet number number + + */ + + virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;}; + + + + + /** + + Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param data pointer to the memory to be analyzed + \param ndata size of frame returned + \param dsize size of the memory slot to be analyzed + \returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found + + */ + + virtual char *findNextFrame(char *data, int &ndata, int dsize) { + char *retval=NULL, *p=data; + int dd=0; + int fn, fnum=-1, np=0, pnum=-1; + while (dd<=(dsize-packetSize)) { + pnum=getPacketNumber(p); + fn=getFrameNumber(p); + + + if (pnum<1 || pnum>nPackets) { + cout << "Bad packet number " << pnum << " frame "<< fn << endl; + retval=NULL; + np=0; + } else if (pnum==1) { + retval=p; + if (np>0) + /*cout << "*Incomplete frame number " << fnum << endl;*/ + np=0; + fnum=fn; + } else if (fn!=fnum) { + if (fnum!=-1) { + /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ + retval=NULL; + } + np=0; + } + p+=packetSize; + dd+=packetSize; + np++; + // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; + if (np==nPackets) + if (pnum==nPackets) { + // cout << "Frame found!" << endl; + break; + } else { + cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; + retval=NULL; + } + } + if (np0) + cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; + } + + ndata=np*packetSize; + // cout << "return " << ndata << endl; + return retval; + }; + + /** + + Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! + \param filebin input file stream (binary) + \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete + + */ + + virtual char *readNextFrame(ifstream &filebin) { + char *data=new char[packetSize*nPackets]; + char *retval=0; + int np=0, nd; + + if (filebin.is_open()) { + while (filebin.read(data+np*packetSize,packetSize)) { + + if (np==(nPackets-1)) { + + retval=findNextFrame(data,nd,packetSize*nPackets); + np=nd/packetSize; + // cout << np << endl; + + + if (retval==data && np==nPackets) { + // cout << "-" << endl; + return data; + + } else if (np>nPackets) { + cout << "too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else if (retval!=NULL) { + // cout << "+" << endl;; + for (int ip=0; ipnPackets) { + cout << "*******too many packets!!!!!!!!!!" << endl; + delete [] data; + return NULL; + } else { + // cout << "." << endl;; + np++; + } + } + } + delete [] data; + return NULL; + }; + + + +private: + const int nPackets; /** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/slsReceiverSoftware/slsReceiver/.project b/slsReceiverSoftware/slsReceiver/.project new file mode 100644 index 0000000000..3c7b965619 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/.project @@ -0,0 +1,28 @@ + + + Receiver + + + newMythenSoftware + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/slsReceiverSoftware/slsReceiver/Makefile b/slsReceiverSoftware/slsReceiver/Makefile new file mode 100644 index 0000000000..0fd416ca03 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/Makefile @@ -0,0 +1,68 @@ +include ../../Makefile.include + +DESTDIR ?= ../../bin +LIBDIR ?= $(DESTDIR) +PROGS = $(DESTDIR)/slsReceiver + + +CFLAGS += -DSLS_RECEIVER_UDP_FUNCTIONS -O3 +CPPFLAGS = ${CFLAGS} # for MAC + + +LDFLAGRXR ?= -L$(LIBDIR) -lSlsReceiver -L/usr/lib64/ -lpthread +LDFLAGRXR += -lm -lstdc++ + + +INCLUDES ?= -I ../MySocketTCP -I ../slsDetectorCalibration -I ../includes -I eigerReceiver -I . +SRC_CLNT = slsReceiver.cpp + + +INSTMODE = 0777 +OBJS = $(SRC_CLNT:.cpp=.o) + + +.PHONY: all receiver clean static_receiver boot eigerReceiver lib + +all: receiver + +receiver: $(DESTDIR)/slsReceiver + +static_receiver: $(DESTDIR)/sslsReceiver + +boot: $(OBJS) + +$(DESTDIR)/sslsReceiver: lib + echo $(OBJS) + echo $(LDFLAGRXR) + echo $(LIBS) + mkdir -p $(DESTDIR) + $(CXX) -static -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) + + +$(DESTDIR)/slsReceiver: eigerReceiver lib + $(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC +#$(EIGERFLAGS) + + +ifeq ($(EIGERSLS), yes) +eigerReceiver: + $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiverTest.o eigerReceiver/eigerReceiverTest.cpp $(EIGERFLAGS) + $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiver.cpp $(EIGERFLAGS) + $(CXX) eigerReceiverTest.o eigerReceiver.o -o eigerReceiver/eigerReceiverTest $(EIGERFLAGS) +else ifeq ($(ROOTSLS), yes) +eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp + echo "Compiling with root" + $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eeigerReceiverDummy.cpp $(ROOTFLAGS) +else +eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp + $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp +endif + +lib: + cd ../ && $(MAKE) DESTDIR=../bin LIBDIR=../bin + +clean: + rm -rf $(PROGS) *.o eigerReceiverTest $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so core + + + diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/RestHelper.h b/slsReceiverSoftware/slsReceiver/eigerReceiver/RestHelper.h new file mode 100644 index 0000000000..6f423f5e1e --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/eigerReceiver/RestHelper.h @@ -0,0 +1,195 @@ +/** + * @file RestHelper.h + * @author Leonardo Sala + * @date Tue Mar 25 09:28:19 2014 + * + * @brief + * + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "JsonBox/Value.h" + +#include +#include +#include + +/// HTTP timeout in seconds, default is 8 +#define HTTP_TIMEOUT 10 +/// Number of connection tries +#define N_CONNECTION_TRIES 3 + +using namespace Poco::Net; +using namespace Poco; +using namespace std; + +class RestHelper { + public: + + ~RestHelper(){}; + + void init(string hostname, int port){ + /** Initialize the RestHelper. Hostname and port parameters are not supposed to change. + * + * + * @param hostname FQDN of the host to connect to , e.g. www.iamfake.org, or sodoi.org + * @param port + * + * @return + */ + + full_hostname = "http://"+hostname; + session = new HTTPClientSession(hostname,port ); + session->setKeepAliveTimeout( Timespan( HTTP_TIMEOUT,0) ); + }; + + + int get_json(string request, string* answer){ + /** Retrieves a reply from the RESTful webservice. + * + * + * @param request Request without the hostname, e.g. if the full request would have been http://fake.org/fakemethod, request=fakemethod + * @param answer + * + * @return 0 if successful, -1 if failure happens. + */ + URI * uri = new URI(full_hostname+"/"+request); + string path(uri->getPathAndQuery()); + if (path.empty()) path = "/"; + + // send request + HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1); + req.setContentType("application/json\r\n"); + int code = send_request(session, req, answer); + delete uri; + return code; + }; + + + int get_json(string request, JsonBox::Value* json_value){ + /** + * + * + * @param request + * @param json_value + * + * @return + */ + URI *uri = new URI(full_hostname+"/"+request); + string path(uri->getPathAndQuery()); + if (path.empty()) path = "/"; + // send request + HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1); + req.setContentType("application/json\r\n"); + string answer; + int code = send_request(session, req, &answer); + json_value->loadFromString(answer); + delete uri; + return code; + }; + + + int post_json(string request, string *answer, string request_body=""){ + /** + * + * + * @param request + * @param answer + * @param request_body Eventual arguments to the URL, e.g. action=login&name=mammamia + * + * @return + */ + //from: http://stackoverflow.com/questions/1499086/poco-c-net-ssl-how-to-post-https-request + URI *uri = new URI(full_hostname+"/"+request); + string path(uri->getPathAndQuery()); + if (path.empty()) path = "/"; + HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); + req.setContentType("application/json\r\n"); + req.setContentLength( request.length() ); + int code = send_request(session, req, answer, request_body); + delete uri; + return code; + } + + + int post_json(string request, JsonBox::Value* json_value, string request_body=""){ + /** + * + * + * @param request + * @param json_value + * @param request_body Eventual arguments to the URL, e.g. action=login&name=mammamia + * + * @return + */ + + URI *uri = new URI(full_hostname+"/"+request); + string path(uri->getPathAndQuery()); + if (path.empty()) path = "/"; + HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); + req.setContentType("application/json\r\n"); + req.setContentLength( request.length() ); + string answer; + int code = send_request(session, req, &answer, request_body); + json_value->loadFromString(answer); + delete uri; + return code; + } + + + private: + //URI * uri; + HTTPClientSession *session; + string full_hostname; + + int send_request(HTTPClientSession *session, HTTPRequest &req, string *answer, string request_body=""){ + /** + * + * + * @param session + * @param req + * @param answer + * @param request_body + * + * @return + */ + + int n=0; + int code = -1; + while(nsendRequest( (req) ); + else + session->sendRequest( (req) ) << request_body; + + HTTPResponse res; + istream &is = session->receiveResponse(res); + StreamCopier::copyToString(is, *answer); + code = res.getStatus(); + if (code != 200){ + cout << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() << endl; + code = -1; + } + return code; + } + catch (exception& e){ + cout << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping " << HTTP_TIMEOUT << " seconds\n"; + sleep(HTTP_TIMEOUT); + } + n+=1; + } + + return code; + } + +}; diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp new file mode 100644 index 0000000000..fa19895beb --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp @@ -0,0 +1,254 @@ +/* + * eigerReceiver.cpp + * + * Created on: Mar 11, 2014 + * Author: billich + */ + +#include +#include +#include "eigerReceiver.h" + + +/* uncomment next line to enable debug output */ +#define EIGER_DEBUG + +/* macro for debug output http://stackoverflow.com/a/14256296 */ +#ifdef EIGER_DEBUG +#define DEBUG(x) do { std::cerr << x << std::endl; } while (0) +#else +#define DEBUG(x) +#endif + + +using namespace std; + +struct EigerReceiverInitializationConfiguration { + + string detectorHostname; +}; + +struct EigerReceiverScanConfiguration { + + string fileName; + string filePath; + int dynamicRange; + int scanTag; + int numberOfFrames; + bool doFileWrite; + bool doFileOverWrite; + + EigerReceiverScanConfiguration(): + dynamicRange(-1), + scanTag(-1), + numberOfFrames(-1), + doFileWrite(false), + doFileOverWrite(false){}; +}; + +class EigerReceiverImplementation: public EigerReceiver { + +public: + + EigerReceiverImplementation() : isInitialized(false), status(slsReceiverDefs::ERROR) {}; + + void initialize(const char *detectorHostname) { + + string name; + if (detectorHostname != NULL) { + name = detectorHostname; + } + + if (name.empty()) { + DEBUG("initialize(): can't initialize with empty string or NULL for detectorHostname"); + } else if (isInitialized == true) { + DEBUG("initialize(): already initialized, can't initialize several times"); + } else { + DEBUG("initialize(): initialize() with: detectorHostName=" << name << "."); + init_config.detectorHostname = name; + isInitialized = true; + status = slsReceiverDefs::IDLE; + } + +#ifdef SALA + //REST call - hardcoded + RestHelper rest ; + rest.init("localhost",8080); + std::string answer; + std::cout << "---- REST test 1: true, string "<< std::endl; + int code = rest.get_json("status", &answer); + std::cout << "Answer: " << answer << std::endl; + + std::cout << "---- REST test 2: 404, string "<< std::endl; + code = rest.get_json("statuss", &answer); + if (code != 0){ + //throw -1; + std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; + } + + std::cout << "---- REST test 3: true, json object "<< std::endl; + JsonBox::Value json_value; + code = rest.get_json("status", &json_value); + std::cout << "JSON " << json_value["status"] << std::endl; + + answer = ""; + std::cout << "---- REST test 4: POST, string "<< std::endl; + code = rest.post_json("recipes/cassoela", &answer); + std::cout << "POST answer: " << answer << std::endl; + if (code != 0){ + //throw -1; + std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; + } + + RestHelper rest2 ; + rest2.init("reallyfake",8080); + std::cout << "---- REST test 4: host not found, json object "<< std::endl; + JsonBox::Value json_value2; + code = rest2.get_json("status", &json_value2); + if (code != 0){ + //throw -1; + std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; + } + +#endif + } + + + char *getDetectorHostname() const { + string name = init_config.detectorHostname; + if (name.empty()) { + DEBUG("getDetectorHostname(): Return NULL"); + return(NULL); + } + char *c = new char[name.length()+1]; + name.copy(c, name.length()); + c[name.length()] = '\0'; + DEBUG("getDetectorHostname(): Return " << c << "."); + return(c); + } + + char *getFileName() const { + string name = scan_config.fileName; + + char *c = new char[name.length()+1]; + name.copy(c, name.length()); + c[name.length()] = '\0'; + DEBUG("getFileName(): Return " << c); + return(c); + } + + char *getFilePath() const { + string name = scan_config.filePath; + + char *c = new char[name.length()+1]; + name.copy(c, name.length()); + c[name.length()] = '\0'; + DEBUG("getFilePath(): Return " << c); + return(c); + } + + int getDynamicRange() const { + DEBUG("getDynamicRange(): Return " << scan_config.dynamicRange); + return(scan_config.dynamicRange); + } + + int getScanTag() const { + DEBUG("getScanTag(): returns " << scan_config.scanTag); + return(scan_config.scanTag); + } + + int getNumberOfFrames() const { + DEBUG("getNumberOfFrames(): return " << scan_config.numberOfFrames); + return(scan_config.numberOfFrames); + } + + int getEnableFileWrite() const { + DEBUG("getEnableFileWrite() returns " << scan_config.doFileWrite); + return(scan_config.doFileWrite); + } + + int getEnableOverwrite() const { + DEBUG("getEnableOverwrite() returns " << scan_config.doFileOverWrite); + return(scan_config.doFileOverWrite); + } + + slsReceiverDefs::runStatus getStatus() const { + DEBUG("getStatus(): return " <getFileName()); + } + + char *setFilePath(const char c[]) { + DEBUG("setFilePath() called with " << c << "."); + scan_config.filePath = c; + return(this->getFilePath()); + } + + int setDynamicRange (const int dr) { + DEBUG("setDynamicRange() called with " << dr << '.'); + scan_config.dynamicRange = dr; + return(getDynamicRange()); + } + + int setScanTag (const int tag) { + DEBUG("setScanTag() called with " << tag); + scan_config.scanTag = tag; + return(getScanTag()); + } + + int setNumberOfFrames (const int fnum) { + DEBUG("setNumberOfFrames() called with " << fnum); + scan_config.numberOfFrames = fnum; + return(getNumberOfFrames()); + } + + int setEnableFileWrite(const int i) { + DEBUG("enableFileWrite() called with " << i); + scan_config.doFileWrite = i; + return(getEnableFileWrite()); + } + + int setEnableOverwrite(const int i) { + DEBUG("setEnableOverwrite() called with " << i); + scan_config.doFileOverWrite = i; + return(getEnableOverwrite()); + } + + int startReceiver(char message[]) { + DEBUG("startReceiver(): return 0."); + status = slsReceiverDefs::RUNNING; + message = NULL; + return(0); + } + + int stopReceiver() { + DEBUG("stopReceiver(): return 0."); + status = slsReceiverDefs::IDLE; + return(0); + } + + void abort() { + DEBUG("abort(): return 0."); + status = slsReceiverDefs::IDLE; + } + +private: + EigerReceiverScanConfiguration scan_config; + EigerReceiverInitializationConfiguration init_config; + bool isInitialized; + slsReceiverDefs::runStatus status; +}; + +EigerReceiver *EigerReceiver::create(void) { + DEBUG("create(): Return new EigerReceiverImplementation instance."); + return new EigerReceiverImplementation(); +} + + + + diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.h b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.h new file mode 100644 index 0000000000..9d26b185be --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.h @@ -0,0 +1,211 @@ +#ifndef EIGERRECEIVER_H +#define EIGERRECEIVER_H +/*********************************************** + * @file eigerReceiver.h + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + ***********************************************/ + +/** + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + */ + +#include "sls_receiver_defs.h" +#ifdef SALA +#include "RestHelper.h" +#endif +class EigerReceiver { + /* abstract class that defines the public interface of an eiger data receiver. + * + * Use the factory method EigerReceiver::create() to get an instance: + * + * EigerReceiver *receiver = EigerReceiver::create() + * + * supported sequence of method-calls: + * + * initialize() : once and only once after create() + * + * get*() : anytime after initialize(), multiples times + * set*() : anytime after initialize(), multiple times + * + * startReceiver(): anytime after initialize(). Will fail if state already is 'running' + * + * abort(), + * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. + * + * getStatus() returns the actual state of the data receiver - running or idle. All other + * get*() and set*() methods access the local cache of configuration values only and *do not* modify the data receiver settings. + * + * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. + * + * get- and set-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: + * + * char *c = receiver->getFileName(); + * .... + * delete[] c; + * + * always: 1:YES 0:NO for int as bool-like arguments + * + */ + +public: + + /** + * factory method to create instances + */ + static EigerReceiver *create(); + + /** + * Destructor + */ + virtual ~EigerReceiver() {}; + + /** + * Initialize the Receiver + @param detectorHostName detector hostname + * you can call this function only once. You must call it before you call startReceiver() for the first time. + */ + virtual void initialize(const char *detectorHostName) = 0; + + + /* Returns detector hostname + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ + virtual char *getDetectorHostname() const = 0; + + /** + * Returns status of receiver: idle, running or error + */ + virtual slsReceiverDefs::runStatus getStatus() const = 0; + + /** + * Returns File Name + * caller is responsible to deallocate the returned char array. + */ + virtual char *getFileName() const = 0; + + + /** + * Returns File Path + * caller is responsible to deallocate the returned char array + */ + virtual char *getFilePath() const = 0; //FIXME: Does the caller need to free() the returned pointer? + + + /** + * Returns the number of bits per pixel + */ + virtual int getDynamicRange() const = 0; + + /** + * Returns scan tag + */ + virtual int getScanTag() const = 0; + + /* + * Returns number of frames to receive + * This is the number of frames to expect to receiver from the detector. + * The data receiver will change from running to idle when it got this number of frames + */ + virtual int getNumberOfFrames() const = 0; + + /** + * Returns file write enable + * 1: YES 0: NO + */ + virtual int getEnableFileWrite() const = 0; + + /** + * Returns file over write enable + * 1: YES 0: NO + */ + virtual int getEnableOverwrite() const = 0; + + /** + * Set File Name (without frame index, file index and extension) + @param c file name + /returns file name + * returns NULL on failure (like bad file name) + * does not check the existence of the file - we don't know which path we'll finally use, so no point to check. + * caller is responsible to deallocate the returned char array. + */ + virtual char* setFileName(const char c[]) = 0; + + /** + * Set File Path + @param c file path + /returns file path + * checks the existence of the directory. returns NULL if directory does not exist or is not readable. + * caller is responsible to deallocate the returned char array. + */ + virtual char* setFilePath(const char c[]) = 0; + + /** + * Returns the number of bits per pixel + @param dr sets dynamic range + /returns dynamic range + * returns -1 on failure + * FIXME: what are the allowd values - should we use an enum as argument? + */ + virtual int setDynamicRange(const int dr) = 0; + + + /** + * Set scan tag + @param tag scan tag + /returns scan tag (always non-negative) + * FIXME: valid range - only positive? 16bit ore 32bit? + * returns -1 on failure + */ + virtual int setScanTag(const int tag) = 0; + + /** + * Sets number of frames + @param fnum number of frames + /returns number of frames + */ + virtual int setNumberOfFrames(const int fnum) = 0; + + /** + * Set enable file write + * @param i file write enable + /returns file write enable + */ + virtual int setEnableFileWrite(const int i) = 0; + + /** + * Set enable file overwrite + * @param i file overwrite enable + /returns file overwrite enable + */ + virtual int setEnableOverwrite(const int i) = 0; + + /** + * Starts Receiver - activate all configuration settings to the eiger receiver and start to listen for packets + @param message is the error message if there is an error + /returns 0 on success or -1 on failure + */ + //FIXME: success == 0 or success == 1? + virtual int startReceiver(char message[]) = 0; //FIXME: who allocates message[]? + + /** + * Stops Receiver - stops listening for packets + /returns success + * same as abort(). Always returns 0. + */ + virtual int stopReceiver() = 0; + + /** + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + virtual void abort() = 0; + +protected: + +private: + +}; + +#endif /* #ifndef EIGERRECEIVER_H */ diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp new file mode 100644 index 0000000000..f45c7517ee --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp @@ -0,0 +1,99 @@ +/* + * eigerReceiver.cpp + * + * Created on: Mar 11, 2014 + * Author: billich + */ + +#include +#include +#include "eigerReceiver.h" + + +using namespace std; + +struct EigerReceiverInitializationConfiguration { + string detectorHostname; +}; + +struct EigerReceiverScanConfiguration { + + string fileName; + string filePath; + int dynamicRange; + int scanTag; + int numberOfFrames; + bool doFileWrite; + bool doFileOverWrite; + + EigerReceiverScanConfiguration(): + dynamicRange(-1), + scanTag(-1), + numberOfFrames(-1), + doFileWrite(false), + doFileOverWrite(false){}; +}; + +class EigerReceiverImplementation: public EigerReceiver { + +public: + + EigerReceiverImplementation(){}; + + ~EigerReceiverImplementation(){}; + + void initialize(const char *detectorHostname) {} + + char *getDetectorHostname() const { return (char*)"";} + + char *getFileName() const {return (char*)"";} + + char *getFilePath() const {return (char*)"";} + + int getDynamicRange() const { return 0;} + + int getScanTag() const {return 0;} + + int getNumberOfFrames() const {return 0;} + + int getEnableFileWrite() const {return 0;} + + int getEnableOverwrite() const {return 0;} + + slsReceiverDefs::runStatus getStatus() const { return slsReceiverDefs::IDLE;} + + char *setFileName(const char c[]) {return (char*)"";} + + char *setFilePath(const char c[]) {return (char*)"";} + + int setDynamicRange (const int dr) {return 0;} + + int setScanTag (const int tag) {return 0;} + + int setNumberOfFrames (const int fnum) {return 0;} + + int setEnableFileWrite(const int i) {return 0;} + + int setEnableOverwrite(const int i) {return 0;} + + int startReceiver(char message[]) {return 0;} + + int stopReceiver() {return 0;} + + void abort() {} + +private: + EigerReceiverScanConfiguration scan_config; + EigerReceiverInitializationConfiguration init_config; + bool isInitialized; + slsReceiverDefs::runStatus status; + +}; + +EigerReceiver *EigerReceiver::create(void) { + return new EigerReceiverImplementation(); +} + + + + diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp new file mode 100644 index 0000000000..bdfcba7a16 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp @@ -0,0 +1,97 @@ +/* + * eigerReceiverTest.cpp + + * + * Created on: Mar 11, 2014 + * Author: billich + */ + +#include +#include +#include "eigerReceiver.h" + +using namespace std; + +int main(int argc, char *argv[]){ + + const char *name = "detectors_host_name"; + const char *empty = ""; + std::string prefix = "main: "; + cout <getStatus(); + char *c0 = receiver->getDetectorHostname(); + if (c0 == NULL) { + cout <initialize(empty); + status = receiver->getStatus(); + receiver->initialize(name); + status = receiver->getStatus(); + receiver->initialize(name); + status = receiver->getStatus(); + receiver->initialize((char *)NULL); + + cout << endl; + + status = receiver->getStatus(); + char *c6 = receiver->getDetectorHostname(); + cout <getFileName(); + cout <." << endl; + delete[] c1; + + char *c2 = receiver->getFilePath(); + cout <." << endl; + delete[]c2; + + int range = receiver->getDynamicRange(); + cout <getScanTag(); + cout <setFileName( "some_other_name"); + cout < after setting to " << endl << endl; + delete[] c3; + + char *c4 = receiver->setFilePath( "some_other_path"); + cout < after setting to " << endl << endl; + delete[] c4; + + range = receiver->setDynamicRange(8); + cout <setScanTag(99); + cout << "got scan tag " << tag << " after setting to 99." << endl << endl; + + int n = receiver->setNumberOfFrames(11); + cout << "got number of frames " << n << " after setting to 11." << endl << endl; + + int w = receiver->setEnableFileWrite(1); + cout << "got enable file write " << w << " after setting to 1." << endl << endl; + + char *c5; + status = receiver->getStatus(); + receiver->startReceiver(c5); + status = receiver->getStatus(); + receiver->stopReceiver(); + status = receiver->getStatus(); + receiver->abort(); + status = receiver->getStatus(); + +} + + + + diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp new file mode 100644 index 0000000000..104fafad93 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp @@ -0,0 +1,81 @@ +/* A simple server in the internet domain using TCP + The port number is passed as an argument */ + +#include "sls_receiver_defs.h" +#include "slsReceiverUsers.h" + +#include +using namespace std; + + + + + + +int main(int argc, char *argv[]) { + int ret = slsReceiverDefs::OK; + + slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret); + + if(ret==slsReceiverDefs::FAIL) + return -1; + + + //register callbacks + + + /** + callback arguments are + filepath + filename + fileindex + datasize + + return value is + 0 raw data ready callback takes care of open,close,write file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + + + registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); + */ + + //receiver->registerCallBackStartAcquisition(func,arg); + + + /** + callback argument is + total farmes caught + registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); + */ + + + //receiver->registerCallBackAcquisitionFinished(func,arg); + + + + /** + args to raw data ready callback are + framenum + datapointer + file descriptor + guidatapointer (NULL, no data required) + + NEVER DELETE THE DATA POINTER + REMEMBER THAT THE CALLBACK IS BLOCKING + + registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg); + + */ + + //receiver->registerCallBackRawDataReady(func,arg); + + + + + user->start(); + + + return 0; +} + diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp new file mode 100644 index 0000000000..c3720ad05c --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -0,0 +1,1991 @@ +/********************************************//** + * @file slsReceiverTCPIPInterface.h + * @short interface between receiver and client + ***********************************************/ + +#include "slsReceiverTCPIPInterface.h" +#include "slsReceiverUDPFunctions.h" +#include "svnInfoReceiver.h" +#include "slsReceiverUsers.h" + +#include //SIGINT +#include //EXIT + +#include +#include +#include +#include +#include +using namespace std; + + +int slsReceiverTCPIPInterface::file_des(-1); +int slsReceiverTCPIPInterface::socketDescriptor(-1); + + +slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { + if(socket) delete socket; + closeFile(0); +} + + +slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int &success): + myDetectorType(GOTTHARD), + ret(OK), + lockStatus(0), + shortFrame(-1), + packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), + socket(NULL){ + + int port_no = DEFAULT_PORTNO+2; + ifstream infile; + string sLine,sargname; + int iline = 0; + + + success=OK; + string fname = ""; + + //parse command line for config + for(int iarg=1;iarg> sargname; + + //tcp port + if(sargname=="rx_tcpport"){ + if(sstr.good()) { + sstr >> sargname; + if(sscanf(sargname.c_str(),"%d",&port_no)) + cout<<"dataport:"<getErrorStatus()) { + success = FAIL; + delete socket; + socket=NULL; + } else { + //initialize variables + strcpy(socket->lastClientIP,"none"); + strcpy(socket->thisClientIP,"none1"); + strcpy(mess,"dummy message"); + + function_table(); +#ifdef VERBOSE + cout << "Function table assigned." << endl; +#endif + slsReceiverFunctions = new slsReceiverUDPFunctions(); + + //Catch signal SIGINT to close files properly + signal(SIGINT,staticCloseFile); + + + file_des=socket->getFileDes(); + socketDescriptor=socket->getsocketDescriptor(); + + //success = OK; + } + } + +} + +void slsReceiverTCPIPInterface::start(){ + + int v=slsReceiverDefs::OK; + + while(v!=GOODBYE) { +#ifdef VERBOSE + cout<< endl; +#endif +#ifdef VERY_VERBOSE + cout << "Waiting for client call" << endl; +#endif + if(socket->Connect()>=0){ +#ifdef VERY_VERBOSE + cout << "Conenction accepted" << endl; +#endif + v = decode_function(); +#ifdef VERY_VERBOSE + cout << "function executed" << endl; +#endif + socket->Disconnect(); +#ifdef VERY_VERBOSE + cout << "connection closed" << endl; +#endif + } + } + + + +} + + +int slsReceiverTCPIPInterface::function_table(){ + + for (int i=0;iReceiveDataOnly(&fnum,sizeof(fnum)); + if (n <= 0) { +#ifdef VERBOSE + cout << "ERROR reading from socket " << n << ", " << fnum << endl; +#endif + return FAIL; + } +#ifdef VERBOSE + else + cout << "size of data received " << n <numberOfFunctions-1) + fnum = numberOfFunctions-1; + //calling function + (this->*flist[fnum])(); + if (ret==FAIL) + cout << "Error executing the function = " << fnum << endl; + + return ret; +} + + + + + + +int slsReceiverTCPIPInterface::M_nofunc(){ + + ret=FAIL; + sprintf(mess,"Unrecognized Function\n"); + cout << mess << endl; + + socket->SendDataOnly(&ret,sizeof(ret)); + socket->SendDataOnly(mess,sizeof(mess)); + + return GOODBYE; +} + + + + +void slsReceiverTCPIPInterface::closeFile(int p){ + cout<<"Closing Files... "<closeFile(); + cout << "Goodbye!" << endl; + exit(-1); +} + +void slsReceiverTCPIPInterface::staticCloseFile(int p){ + slsReceiverUsers::receiver->closeFile(p); +} + + +int slsReceiverTCPIPInterface::set_detector_type(){ + ret=OK; + int retval=FAIL; + detectorType dr; + strcpy(mess,"Could not set detector type range\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&dr,sizeof(dr)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else{ + myDetectorType = dr; + ret=slsReceiverFunctions->setDetectorType(dr); + retval = myDetectorType; + } + } +//#ifdef VERBOSE + if(ret!=FAIL) + cout << "detector type" << dr << endl; + else + cout << mess << endl; +//#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + + + + +int slsReceiverTCPIPInterface::set_file_name() { + ret=OK; + char retval[MAX_STR_LENGTH]=""; + char fName[MAX_STR_LENGTH]; + strcpy(mess,"Could not set file name"); + + // receive arguments + if(socket->ReceiveDataOnly(fName,MAX_STR_LENGTH) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + strcpy(retval,slsReceiverFunctions->setFileName(fName)); + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "file name:" << retval << endl; + else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //return ok/fail + return ret; +} + + + + + + +int slsReceiverTCPIPInterface::set_file_dir() { + ret=OK; + char retval[MAX_STR_LENGTH]=""; + char fPath[MAX_STR_LENGTH]; + strcpy(mess,"Could not set file path\n"); + + // receive arguments + if(socket->ReceiveDataOnly(fPath,MAX_STR_LENGTH) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + }/* + else if((strlen(fPath))&&(slsReceiverFunctions->getStatus()==RUNNING)){ + strcpy(mess,"Can not set file path while receiver running\n"); + ret = FAIL; + }*/ + else{ + strcpy(retval,slsReceiverFunctions->setFilePath(fPath)); + // if file path doesnt exist + if(strlen(fPath)) + if (strcmp(retval,fPath)){ + strcpy(mess,"receiver file path does not exist\n"); + ret=FAIL; + } + } + + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "file path:" << retval << endl; + else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //return ok/fail + return ret; +} + + + + + + +int slsReceiverTCPIPInterface::set_file_index() { + ret=OK; + int retval=-1; + int index; + strcpy(mess,"Could not set file index\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + retval=slsReceiverFunctions->setFileIndex(index); + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "file index:" << retval << endl; + else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + + + + + +int slsReceiverTCPIPInterface::set_frame_index() { + ret=OK; + int retval=-1; + int index; + strcpy(mess,"Could not set frame index\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + retval=slsReceiverFunctions->setFrameIndexNeeded(index); + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "frame index:" << retval << endl; + else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + + + + +int slsReceiverTCPIPInterface::setup_udp(){ + ret=OK; + strcpy(mess,"could not set up udp connection"); + char retval[MAX_STR_LENGTH]=""; + char args[2][MAX_STR_LENGTH]; + + string temp; + int udpport; + char eth[MAX_STR_LENGTH]; + + + // receive arguments + + if(socket->ReceiveDataOnly(args,sizeof(args)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else if(slsReceiverFunctions->getStatus()==RUNNING){ + ret = FAIL; + strcpy(mess,"cannot set up udp when receiver is running\n"); + } + else{ + //set up udp port + sscanf(args[1],"%d",&udpport); + slsReceiverFunctions->setUDPPortNo(udpport); + + //setup udpip + //get ethernet interface or IP to listen to + temp = genericSocket::ipToName(args[0]); + if(temp=="none"){ + ret = FAIL; + strcpy(mess, "failed to get ethernet interface or IP to listen to\n"); + } + else{ + strcpy(eth,temp.c_str()); + if (strchr(eth,'.')!=NULL) { + strcpy(eth,""); + ret = FAIL; + } + cout<<"eth:"<setEthernetInterface(eth); + + //get mac address from ethernet interface + if (ret != FAIL) + temp = genericSocket::nameToMac(eth); + + + if ((temp=="00:00:00:00:00:00") || (ret == FAIL)){ + ret = FAIL; + strcpy(mess,"failed to get mac adddress to listen to\n"); + cout << "mess:" << mess << endl; + } + else{ + strcpy(retval,temp.c_str()); + cout<<"mac:"<differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //return ok/fail + return ret; +} + + + + + + +int slsReceiverTCPIPInterface::start_receiver(){ + ret=OK; + ret=OK; + enum runStatus s; + char cstatus[15]; + strcpy(mess,"Could not start receiver\n"); + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + /* + else if(!strlen(slsReceiverFunctions->getFilePath())){ + strcpy(mess,"receiver not set up. set receiver ip again.\n"); + ret = FAIL; + } + */ + else { + s = slsReceiverFunctions->getStatus(); + switch (s) { + case ERROR: strcpy(cstatus,"error"); break; + case WAITING: strcpy(cstatus,"waiting"); break; + case RUNNING: strcpy(cstatus,"running"); break; + case TRANSMITTING: strcpy(cstatus,"data"); break; + case RUN_FINISHED: strcpy(cstatus,"finished"); break; + default: strcpy(cstatus,"idle"); break; + } + if(s == IDLE) + ret=slsReceiverFunctions->startReceiver(mess); + else{ + sprintf(mess,"Cannot start Receiver as it is in %s state\n",cstatus); + ret=FAIL; + } + } + +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + cout<<"ret of start receiver:"<differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else if(slsReceiverFunctions->getStatus()!=IDLE) + ret=slsReceiverFunctions->stopReceiver(); +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + //return ok/fail + return ret; + + +} + + +int slsReceiverTCPIPInterface::get_status(){ + ret=OK; + enum runStatus retval; + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + retval=slsReceiverFunctions->getStatus(); +#endif + + if(socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + socket->SendDataOnly(&retval,sizeof(retval)); + //return ok/fail + return ret; + + +} + + +int slsReceiverTCPIPInterface::get_frames_caught(){ + ret=OK; + int retval=-1; + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + retval=slsReceiverFunctions->getTotalFramesCaught(); +#endif + if(socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + socket->SendDataOnly(&retval,sizeof(retval)); + //return ok/fail + return ret; + + +} + + +int slsReceiverTCPIPInterface::get_frame_index(){ + ret=OK; + int retval=-1; + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + retval=slsReceiverFunctions->getAcquisitionIndex(); +#endif + + if(socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + socket->SendDataOnly(&retval,sizeof(retval)); + //return ok/fail + return ret; + + +} + + +int slsReceiverTCPIPInterface::reset_frames_caught(){ + ret=OK; + + strcpy(mess,"Could not reset frames caught\n"); + + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + slsReceiverFunctions->resetTotalFramesCaught(); + } +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + + //return ok/fail + return ret; + + +} + + + + + + +int slsReceiverTCPIPInterface::set_short_frame() { + ret=OK; + int index=0; + int retval=-100; + strcpy(mess,"Could not set/reset short frame for receiver\n"); + + //does not exist for moench + if(myDetectorType==MOENCH){ + strcpy(mess,"can not set short frame for moench\n"); + ret = FAIL; + } + + // receive arguments + if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else if(slsReceiverFunctions->getStatus()==RUNNING){ + strcpy(mess,"Cannot set short frame while status is running\n"); + ret=FAIL; + } + else{ + retval=slsReceiverFunctions->setShortFrame(index); + shortFrame = retval; + if(shortFrame==-1) + packetsPerFrame=GOTTHARD_PACKETS_PER_FRAME; + else + packetsPerFrame=GOTTHARD_SHORT_PACKETS_PER_FRAME; + } + } +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + +int slsReceiverTCPIPInterface::read_frame(){ + switch(myDetectorType){ + case MOENCH: + return moench_read_frame(); + default: + return gotthard_read_frame(); + } +} + + + +int slsReceiverTCPIPInterface::moench_read_frame(){ + ret=OK; + char fName[MAX_STR_LENGTH]=""; + int arg = -1,i; + + + 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;igetFramesCaught()){ + arg = -1; + cout<<"haven't caught any frame yet"<getStartFrameIndex(); + slsReceiverFunctions->readFrame(fName,&raw); + + /**send garbage with -1 index to try again*/ + if (raw == NULL){ + arg = -1; +#ifdef VERBOSE + cout<<"data not ready for gui yet"<> MOENCH_FRAME_INDEX_OFFSET); + + 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 VERBOSE + 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 = startIndex - 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:"<= 40) && (packetIndex < 0)) + cout << "cannot decode packet index:" << packetIndex << endl; + else{ + + x = packetIndex / 10; + y = packetIndex % 10; +#ifdef VERBOSE + cout<<"x:"<differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL){ + cout << "mess:" << mess << endl; + socket->SendDataOnly(mess,sizeof(mess)); + } + else{ + socket->SendDataOnly(fName,MAX_STR_LENGTH); + socket->SendDataOnly(&arg,sizeof(arg)); + socket->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 arg = -1,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;igetFramesCaught()){ + arg=-1; + cout<<"haven't caught any frame yet"<getStartFrameIndex(); + slsReceiverFunctions->readFrame(fName,&raw); + + /**send garbage with -1 index to try again*/ + if (raw == NULL){ + arg = -1; +#ifdef VERBOSE + cout<<"data not ready for gui yet"<> GOTTHARD_SHORT_FRAME_INDEX_OFFSET); +#ifdef VERBOSE + 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 VERBOSE + cout << "index1:" << hex << index << endl; + cout << "index2:" << hex << index << endl; +#endif + } + + memcpy(origVal,raw,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 = startIndex - 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 << ":"<differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL){ + cout << "mess:" << mess << endl; + socket->SendDataOnly(mess,sizeof(mess)); + } + else{ + socket->SendDataOnly(fName,MAX_STR_LENGTH); + socket->SendDataOnly(&arg,sizeof(arg)); + socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES); + } + + delete [] retval; + delete [] origVal; + delete [] raw; + + return ret; +} + + + + +int slsReceiverTCPIPInterface::set_read_frequency(){ + ret=OK; + int retval=-1; + int index; + strcpy(mess,"Could not set receiver read frequency\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + }/* + else if((slsReceiverFunctions->getStatus()==RUNNING) && (index >= 0)){ + ret = FAIL; + strcpy(mess,"cannot set up receiver mode when receiver is running\n"); + }*/ + else + retval=slsReceiverFunctions->setNFrameToGui(index); + } + +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + + + +int slsReceiverTCPIPInterface::enable_file_write(){ + ret=OK; + int retval=-1; + int enable; + strcpy(mess,"Could not set/get enable file write\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&enable,sizeof(enable)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else{ + retval=slsReceiverFunctions->setEnableFileWrite(enable); + if((enable!=-1)&&(enable!=retval)) + ret=FAIL; + } + } +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + +int slsReceiverTCPIPInterface::get_id(){ + ret=OK; + int64_t retval=-1; + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + retval = get_version(); +#endif + + if(socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + +int64_t slsReceiverTCPIPInterface::get_version(){ + int64_t retval = SVNREV; + retval= (retval <<32) | SVNDATE; + return retval; +} + + + + +int slsReceiverTCPIPInterface::start_readout(){ + ret=OK; + enum runStatus retval; + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + slsReceiverFunctions->startReadout(); + retval = slsReceiverFunctions->getStatus(); + if((retval == TRANSMITTING) || (retval == RUN_FINISHED) || (retval == IDLE)) + ret = OK; + else + ret = FAIL; +#endif + + if(socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + socket->SendDataOnly(&retval,sizeof(retval)); + //return ok/fail + return ret; + + +} + + + + +int slsReceiverTCPIPInterface::set_timer() { + ret=OK; + int64_t retval = -1; + int64_t index[2]; + index[1] = -1; + strcpy(mess,"Could not set acquisition period or frame number in receiver\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(index,sizeof(index)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else{ + if(index[0] == slsReceiverDefs::FRAME_PERIOD) + retval=slsReceiverFunctions->setAcquisitionPeriod(index[1]); + else + retval=slsReceiverFunctions->setNumberOfFrames(index[1]); + } + } +#ifdef VERBOSE + if(ret!=FAIL){ + if(index[0] == slsReceiverDefs::FRAME_PERIOD) + cout << "acquisition period:" << retval << endl; + else + cout << "frame number:" << retval << endl; + }else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + + + +int slsReceiverTCPIPInterface::enable_compression() { + ret=OK; + int enable=-1; + int retval=-100; + strcpy(mess,"Could not enable/disable compression for receiver\n"); + + // receive arguments + if(socket->ReceiveDataOnly(&enable,sizeof(enable)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if(enable >= 0){ + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else if(slsReceiverFunctions->getStatus()==RUNNING){ + strcpy(mess,"Cannot enable/disable compression while status is running\n"); + ret=FAIL; + } + else + ret = slsReceiverFunctions->enableDataCompression(enable); + } + + retval=slsReceiverFunctions->getDataCompression(); + } +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + +int slsReceiverTCPIPInterface::set_detector_hostname() { + ret=OK; + char retval[MAX_STR_LENGTH]=""; + char hostname[MAX_STR_LENGTH]=""; + strcpy(mess,"Could not set detector hostname"); + + // receive arguments + if(socket->ReceiveDataOnly(hostname,MAX_STR_LENGTH) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + strcpy(retval,slsReceiverFunctions->setDetectorHostname(hostname)); + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "hostname:" << retval << endl; + else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //return ok/fail + return ret; +} + + + + + + + +int slsReceiverTCPIPInterface::set_dynamic_range() { + ret=OK; + int retval=-1; + int dr; + strcpy(mess,"Could not set dynamic range\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&dr,sizeof(dr)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + retval=slsReceiverFunctions->setDynamicRange(dr); + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "dynamic range" << dr << endl; + else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + + + + +int slsReceiverTCPIPInterface::enable_overwrite() { + ret=OK; + int retval=-1; + int index; + strcpy(mess,"Could not enable/disable overwrite\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + retval=slsReceiverFunctions->enableOverwrite(index); + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "overwrite:" << retval << endl; + else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +int slsReceiverTCPIPInterface::lock_receiver() { + ret=OK; + int lock; + + // receive arguments + if(socket->ReceiveDataOnly(&lock,sizeof(lock)) < 0 ){ + sprintf(mess,"Error reading from socket\n"); + cout << "Error reading from socket (lock)" << endl; + ret=FAIL; + } + // execute action if the arguments correctly arrived + if(ret==OK){ + if (lock>=0) { + if (lockStatus==0 || strcmp(socket->lastClientIP,socket->thisClientIP)==0 || strcmp(socket->lastClientIP,"none")==0) { + lockStatus=lock; + strcpy(socket->lastClientIP,socket->thisClientIP); + } else { + ret=FAIL; + sprintf(mess,"Receiver already locked by %s\n", socket->lastClientIP); + } + } + } + + if (socket->differentClients && ret==OK) + ret=FORCE_UPDATE; + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + else + socket->SendDataOnly(&lockStatus,sizeof(lockStatus)); + + //return ok/fail + return ret; +} + + + + + + + +int slsReceiverTCPIPInterface::set_port() { + ret=OK; + MySocketTCP* mySocket=NULL; + int sd=-1; + enum runStatus p_type; /* just to get the input */ + int p_number; + + // receive arguments + if(socket->ReceiveDataOnly(&p_type,sizeof(p_type)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + cout << mess << endl; + ret=FAIL; + } + + if(socket->ReceiveDataOnly(&p_number,sizeof(p_number)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + cout << mess << endl; + ret=FAIL; + } + + // execute action if the arguments correctly arrived + if (ret==OK) { + if (socket->differentClients==1 && lockStatus==1 ) { + ret=FAIL; + sprintf(mess,"Detector locked by %s\n",socket->lastClientIP); + } + else { + if (p_number<1024) { + sprintf(mess,"Too low port number %d\n", p_number); + cout << mess << endl; + ret=FAIL; + } + cout << "set port " << p_type << " to " << p_number <getErrorStatus(); + if (!sd){ + ret=OK; + if (mySocket->differentClients) + ret=FORCE_UPDATE; + } else { + ret=FAIL; + sprintf(mess,"Could not bind port %d\n", p_number); + cout << mess << endl; + if (sd==-10) { + sprintf(mess,"Port %d already set\n", p_number); + cout << mess << endl; + } + } + } + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + socket->SendDataOnly(mess,sizeof(mess)); + } else { + socket->SendDataOnly(&p_number,sizeof(p_number)); + if(sd>=0){ + socket->Disconnect(); + delete socket; + socket = mySocket; + file_des=socket->getFileDes(); + } + } + + //return ok/fail + return ret; +} + + + + + + +int slsReceiverTCPIPInterface::get_last_client_ip() { + ret=OK; + + if (socket->differentClients ) + ret=FORCE_UPDATE; + + socket->SendDataOnly(&ret,sizeof(ret)); + socket->SendDataOnly(socket->lastClientIP,sizeof(socket->lastClientIP)); + + return ret; +} + + + + + + + +int slsReceiverTCPIPInterface::send_update() { + ret=OK; + int ind; + char path[MAX_STR_LENGTH]; + + socket->SendDataOnly(socket->lastClientIP,sizeof(socket->lastClientIP)); + + //index +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + + /*if(myDetectorType != EIGER)*/ + ind=slsReceiverFunctions->getFileIndex(); + + socket->SendDataOnly(&ind,sizeof(ind)); +#endif + + //filepath +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + strcpy(path,slsReceiverFunctions->getFilePath()); +#endif + socket->SendDataOnly(path,MAX_STR_LENGTH); + + + //filename +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + strcpy(path,slsReceiverFunctions->getFileName()); +#endif + socket->SendDataOnly(path,MAX_STR_LENGTH); + + + if (lockStatus==0) { + strcpy(socket->lastClientIP,socket->thisClientIP); + } + + return ret; + + +} + + + + + + +int slsReceiverTCPIPInterface::update_client() { + ret=OK; + socket->SendDataOnly(&ret,sizeof(ret)); + + return send_update(); +} + + + + + + + +int slsReceiverTCPIPInterface::exit_server() { + ret=GOODBYE; + socket->SendDataOnly(&ret,sizeof(ret)); + strcpy(mess,"closing server"); + socket->SendDataOnly(mess,sizeof(mess)); + cout << mess << endl; + return ret; +} + + + + + +int slsReceiverTCPIPInterface::exec_command() { + ret = OK; + char cmd[MAX_STR_LENGTH]; + char answer[MAX_STR_LENGTH]; + int sysret=0; + + // receive arguments + if(socket->ReceiveDataOnly(cmd,MAX_STR_LENGTH) < 0 ){ + sprintf(mess,"Error reading from socket\n"); + ret=FAIL; + } + + // execute action if the arguments correctly arrived + if (ret==OK) { +#ifdef VERBOSE + cout << "executing command " << cmd << endl; +#endif + if (lockStatus==0 || socket->differentClients==0) + sysret=system(cmd); + + //should be replaced by popen + if (sysret==0) { + strcpy(answer,"Succeeded\n"); + if (lockStatus==1 && socket->differentClients==1) + sprintf(answer,"Detector locked by %s\n", socket->lastClientIP); + } else { + strcpy(answer,"Failed\n"); + ret=FAIL; + } + } else + strcpy(answer,"Could not receive the command\n"); + + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(socket->SendDataOnly(answer,MAX_STR_LENGTH) < 0){ + strcpy(mess,"Error writing to socket"); + ret=FAIL; + } + + //return ok/fail + return ret; +} + + + + + diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h new file mode 100644 index 0000000000..b0cd6e7806 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -0,0 +1,238 @@ + /********************************************//** + * @file slsReceiverTCPIPInterface.h + * @short interface between receiver and client + ***********************************************/ +#ifndef SLS_RECEIVER_TCP_IP_INTERFACE_H +#define SLS_RECEIVER_TCP_IP_INTERFACE_H + + +#include "sls_receiver_defs.h" +#include "receiver_defs.h" +#include "MySocketTCP.h" +#include "slsReceiverUDPFunctions.h" + + + +/** + *@short interface between receiver and client + */ + +class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { + +public: + /** + * Constructor + * reads config file, creates socket, assigns function table + * @param argc from command line + * @param argv from command line + * @param succecc socket creation was successfull + */ + slsReceiverTCPIPInterface(int argc, char *argv[], int &success); + + + /** starts listening on the TCP port for client comminication */ + + void start(); + + /** Destructor */ + virtual ~slsReceiverTCPIPInterface(); + + /** Close all threaded Files and exit */ + void closeFile(int p); + + /** Static function to call closeFile */ + static void staticCloseFile(int p); + + /** gets version */ + int64_t get_version(); + + /** + callback arguments are + filepath + filename + fileindex + data size + + return value is + 0 callback takes care of open,close,wrie file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + + */ + + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){slsReceiverFunctions->registerCallBackStartAcquisition(func,arg);};; + + + /** + callback argument is + toatal farmes caught + + */ + + + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){slsReceiverFunctions->registerCallBackAcquisitionFinished(func,arg);}; + + + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){slsReceiverFunctions->registerCallBackRawDataReady(func,arg);}; + + + private: + /** assigns functions to the fnum enum */ + int function_table(); + + /** Decodes Function */ + int decode_function(); + + /** Unrecognized Function */ + int M_nofunc(); + + /** Set detector type */ + int set_detector_type(); + + /** Set File name without frame index, file index and extension */ + int set_file_name(); + + /** Set File path */ + int set_file_dir(); + + /** Set up UDP Details */ + int setup_udp(); + + /** Set File index */ + int set_file_index(); + + /** Set Frame index */ + int set_frame_index(); + + /** Start Receiver - starts listening to udp packets from detector */ + int start_receiver(); + + /** Stop Receiver - stops listening to udp packets from detector*/ + int stop_receiver(); + + /** Gets receiver status */ + int get_status(); + + /** Gets Total Frames Caught */ + int get_frames_caught(); + + /** Gets frame index for each acquisition */ + int get_frame_index(); + + /** Resets Total Frames Caught */ + int reset_frames_caught(); + + /** set short frame */ + int set_short_frame(); + + /** Reads Frame/ buffer */ + int read_frame(); + + /** gotthard specific read frame */ + int gotthard_read_frame(); + + /** moench specific read frame */ + int moench_read_frame(); + + /** Sets the receiver to send every nth frame to gui, or only upon gui request */ + int set_read_frequency(); + + /** Enable File Write*/ + int enable_file_write(); + + /** get version, calls get_version */ + int get_id(); + + /** set status to transmitting and + * when fifo is empty later, sets status to run_finished */ + int start_readout(); + + /** set acquisition period, frame number etc */ + int set_timer(); + + /** enable compression */ + int enable_compression(); + + /** set detector hostname */ + int set_detector_hostname(); + + /** set dynamic range */ + int set_dynamic_range(); + + /** enable overwrite */ + int enable_overwrite(); + + + //General Functions + /** Locks Receiver */ + int lock_receiver(); + + /** Set port */ + int set_port(); + + /** Get Last Client IP*/ + int get_last_client_ip(); + + /** Updates Client if different clients connect */ + int update_client(); + + /** Sends the updated parameters to client */ + int send_update(); + + /** Exit Receiver Server */ + int exit_server(); + + /** Execute command */ + int exec_command(); + + + + //private: + /** detector type */ + detectorType myDetectorType; + + /** slsReceiverUDPFunctions object */ + slsReceiverUDPFunctions *slsReceiverFunctions; + + /** Number of functions */ + static const int numberOfFunctions = 256; + + /** Function List */ + int (slsReceiverTCPIPInterface::*flist[numberOfFunctions])(); + + /** Message */ + char mess[MAX_STR_LENGTH]; + + /** success/failure */ + int ret; + + /** Lock Status if server locked to a client */ + int lockStatus; + + /** Short frame */ + int shortFrame; + + /** Packets per frame */ + int packetsPerFrame; + + static int file_des; + static int socketDescriptor; + +//private: + protected: + /** Socket */ + MySocketTCP* socket; +}; + + +#endif diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp new file mode 100644 index 0000000000..0b710f1993 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -0,0 +1,1968 @@ +#ifdef SLS_RECEIVER_UDP_FUNCTIONS +/********************************************//** + * @file slsReceiverUDPFunctions.cpp + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + ***********************************************/ + + +#include "slsReceiverUDPFunctions.h" + +#include "moench02ModuleData.h" +#include "gotthardModuleData.h" +#include "gotthardShortModuleData.h" + + +#include // SIGINT +#include // stat +#include // socket(), bind(), listen(), accept(), shut down +#include // sock_addr_in, htonl, INADDR_ANY +#include // exit() +#include //set precision +#include //munmap + + + +#include +#include +using namespace std; + + + + +slsReceiverUDPFunctions::slsReceiverUDPFunctions(): + receiver(NULL), + server_port(DEFAULT_UDP_PORTNO), + thread_started(0), + udpSocket(NULL), + eth(NULL), + latestData(NULL), + guiFileName(NULL), + mem0(NULL), + fifo(NULL), + fifoFree(NULL){ + + for(int i=0;i /proc/sys/net/core/rmem_max")) + cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) + cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + /** permanent setting heiner + net.core.rmem_max = 104857600 # 100MiB + net.core.netdev_max_backlog = 250000 + sysctl -p + // from the manual + sysctl -w net.core.rmem_max=16777216 + sysctl -w net.core.netdev_max_backlog=250000 + */ +} + + + +slsReceiverUDPFunctions::~slsReceiverUDPFunctions(){ + createListeningThreads(true); + createWriterThreads(true); + deleteMembers(); +} + + + + +void slsReceiverUDPFunctions::deleteMembers(){ + //kill threads + if(thread_started){ + createListeningThreads(true); + createWriterThreads(true); + } + + for(int i=0;isetFileName(fileName); + } + + onePacketSize = bufferSize/packetsPerFrame; + latestData = new char[bufferSize]; + + + setupFifoStructure(); + + if(createListeningThreads() == FAIL){ + cout << "ERROR: Could not create listening thread" << endl; + exit (-1); + } + + if(createWriterThreads() == FAIL){ + cout << "ERROR: Could not create writer threads" << endl; + exit (-1); + } + + setThreadPriorities(); + + cout << "Ready..." << endl; + + return OK; +} + + + + + +/*Frame indices and numbers caught*/ + +bool slsReceiverUDPFunctions::getAcquistionStarted(){return acqStarted;}; + +bool slsReceiverUDPFunctions::getMeasurementStarted(){return measurementStarted;}; + +int slsReceiverUDPFunctions::getFramesCaught(){return (packetsCaught/packetsPerFrame);} + +int slsReceiverUDPFunctions::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);} + +uint32_t slsReceiverUDPFunctions::getStartFrameIndex(){return startFrameIndex;} + +uint32_t slsReceiverUDPFunctions::getFrameIndex(){ + if(!packetsCaught) + frameIndex=0; + else + frameIndex = currframenum - startFrameIndex; + return frameIndex; +} + +uint32_t slsReceiverUDPFunctions::getAcquisitionIndex(){ + if(!totalPacketsCaught) + acquisitionIndex=0; + else + acquisitionIndex = currframenum - startAcquisitionIndex; + return acquisitionIndex; +} + + +void slsReceiverUDPFunctions::resetTotalFramesCaught(){ + acqStarted = false; + startAcquisitionIndex = 0; + totalPacketsCaught = 0; +} + + + + + + + + + +/*file parameters*/ + +char* slsReceiverUDPFunctions::getFilePath(){ + if(myDetectorType == EIGER) + return receiver->getFilePath(); + else + return filePath; +} + +char* slsReceiverUDPFunctions::setFilePath(char c[]){ + if(strlen(c)){ + //check if filepath exists + struct stat st; + if(stat(c,&st) == 0){ + if(myDetectorType == EIGER) + receiver->setFilePath(c); + else + strcpy(filePath,c); + }else{ + strcpy(filePath,""); + cout << "FilePath does not exist:" << filePath << endl; + } + } + return getFilePath(); +} + + +char* slsReceiverUDPFunctions::getFileName(){ + if(myDetectorType == EIGER) + return receiver->getFileName(); + else + return fileName; +} + +char* slsReceiverUDPFunctions::setFileName(char c[]){ + if(strlen(c)){ + if(myDetectorType == EIGER) + receiver->setFileName(c); + else + strcpy(fileName,c); + + } + return getFileName(); + +} + + +int slsReceiverUDPFunctions::getFileIndex(){ + return fileIndex; +} + +int slsReceiverUDPFunctions::setFileIndex(int i){ + if(i>=0) + fileIndex = i; + return getFileIndex(); +} + + +int slsReceiverUDPFunctions::setFrameIndexNeeded(int i){ + frameIndexNeeded = i; + return frameIndexNeeded; +} + + +int slsReceiverUDPFunctions::setEnableFileWrite(int i){ + if(i!=-1){ + if(myDetectorType == EIGER) + receiver->setEnableFileWrite(i); + else + enableFileWrite=i; + + } + if(myDetectorType == EIGER) + return receiver->getEnableFileWrite(); + else + return enableFileWrite; + +} + + + +int slsReceiverUDPFunctions::enableOverwrite(int i){ + if(i!=-1){ + if(myDetectorType == EIGER) + receiver->setEnableOverwrite(i); + else + overwrite=i; + + } + if(myDetectorType == EIGER) + return receiver->getEnableOverwrite(); + else + return overwrite; + +} + + + + +/*other parameters*/ + +slsReceiverDefs::runStatus slsReceiverUDPFunctions::getStatus(){ + if(myDetectorType == EIGER) + return receiver->getStatus(); + else + return status; +} + + +char* slsReceiverUDPFunctions::setDetectorHostname(char c[]){ + if(strlen(c)){ + if(myDetectorType == EIGER){ + if(receiver->getDetectorHostname()== NULL) + receiver->initialize(c); + }else + strcpy(detHostname,c); + } + + if(myDetectorType == EIGER) + return receiver->getDetectorHostname(); + else + return detHostname; +} + + +void slsReceiverUDPFunctions::setEthernetInterface(char* c){ + strcpy(eth,c); +} + + +void slsReceiverUDPFunctions::setUDPPortNo(int p){ + server_port = p; +} + + +int32_t slsReceiverUDPFunctions::setNumberOfFrames(int32_t fnum){ + if(fnum >= 0){ + if(myDetectorType == EIGER) + receiver->setNumberOfFrames(fnum); + else + numberOfFrames = fnum; + } + + if(myDetectorType == EIGER) + return receiver->getNumberOfFrames(); + else + return numberOfFrames; +} + +int32_t slsReceiverUDPFunctions::setScanTag(int32_t stag){ + if(stag >= 0){ + if(myDetectorType == EIGER) + receiver->setScanTag(stag); + else + scanTag = stag; + } + + if(myDetectorType == EIGER) + return receiver->getScanTag(); + else + return scanTag; +} + +int32_t slsReceiverUDPFunctions::setDynamicRange(int32_t dr){ + if(dr >= 0){ + if(myDetectorType == EIGER) + receiver->setDynamicRange(dr); + else + dynamicRange = dr; + } + + if(myDetectorType == EIGER) + return receiver->getDynamicRange(); + else + return dynamicRange; +} + + + +int slsReceiverUDPFunctions::setShortFrame(int i){ + shortFrame=i; + + if(shortFrame!=-1){ + bufferSize = GOTTHARD_SHORT_BUFFER_SIZE; + maxPacketsPerFile = SHORT_MAX_FRAMES_PER_FILE * GOTTHARD_SHORT_PACKETS_PER_FRAME; + packetsPerFrame = GOTTHARD_SHORT_PACKETS_PER_FRAME; + frameIndexMask = GOTTHARD_SHORT_FRAME_INDEX_MASK; + frameIndexOffset = GOTTHARD_SHORT_FRAME_INDEX_OFFSET; + + }else{ + bufferSize = GOTTHARD_BUFFER_SIZE; + maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; + packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; + frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; + frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; + } + + onePacketSize = bufferSize/packetsPerFrame; + + deleteFilter(); + if(dataCompression) + setupFilter(); + + return shortFrame; +} + + +int slsReceiverUDPFunctions::setNFrameToGui(int i){ + if(i>=0){ + nFrameToGui = i; + setupFifoStructure(); + } + return nFrameToGui; +} + + + +int64_t slsReceiverUDPFunctions::setAcquisitionPeriod(int64_t index){ + + if(index >= 0){ + if(index != acquisitionPeriod){ + acquisitionPeriod = index; + if(myDetectorType != EIGER) + setupFifoStructure(); + } + } + return acquisitionPeriod; +} + + +bool slsReceiverUDPFunctions::getDataCompression(){return dataCompression;} + +int slsReceiverUDPFunctions::enableDataCompression(bool enable){ + cout << "Data compression "; + if(enable) + cout << "enabled" << endl; + else + cout << "disabled" << endl; +#ifdef MYROOT1 + cout << " WITH ROOT" << endl; +#else + cout << " WITHOUT ROOT" << endl; +#endif + //delete filter for the current number of threads + deleteFilter(); + + dataCompression = enable; + pthread_mutex_lock(&status_mutex); + writerthreads_mask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + createWriterThreads(true); + + if(enable) + numWriterThreads = MAX_NUM_WRITER_THREADS; + else + numWriterThreads = 1; + + if(createWriterThreads() == FAIL){ + cout << "ERROR: Could not create writer threads" << endl; + return FAIL; + } + setThreadPriorities(); + + + if(enable) + setupFilter(); + + return OK; +} + + + + + + + + + + + + +/*other functions*/ + + +void slsReceiverUDPFunctions::deleteFilter(){ + int i; + cmSub=NULL; + + for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); + +} + + + + +void slsReceiverUDPFunctions::setupFifoStructure(){ + int64_t i; + int oldn = numJobsPerThread; + + //if every nth frame mode + if(nFrameToGui) + numJobsPerThread = nFrameToGui; + + //random nth frame mode + else{ + if(!acquisitionPeriod) + i = SAMPLE_TIME_IN_NS; + else + i = SAMPLE_TIME_IN_NS/acquisitionPeriod; + if (i > MAX_JOBS_PER_THREAD) + numJobsPerThread = MAX_JOBS_PER_THREAD; + else if (i < 1) + numJobsPerThread = 1; + else + numJobsPerThread = i; + } + + //if same, return + if(oldn == numJobsPerThread) + return; + + + //otherwise memory too much if numjobsperthread is at max = 1000 + fifosize = GOTTHARD_FIFO_SIZE; + if(myDetectorType == MOENCH) + fifosize = MOENCH_FIFO_SIZE; + + if(fifosize % numJobsPerThread) + fifosize = (fifosize/numJobsPerThread)+1; + else + fifosize = fifosize/numJobsPerThread; + + + cout << "Number of Frames per buffer:" << numJobsPerThread << endl; + cout << "Fifo Size:" << fifosize << endl; + + /* + //for testing + numJobsPerThread = 3; fifosize = 11; + */ + + //deleting old structure and creating fifo structure + if(fifoFree){ + while(!fifoFree->isEmpty()) + fifoFree->pop(buffer); + delete fifoFree; + } + if(fifo) delete fifo; + if(mem0) free(mem0); + fifoFree = new CircularFifo(fifosize); + fifo = new CircularFifo(fifosize); + + + //allocate memory + mem0=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + /** shud let the client know about this */ + if (mem0==NULL){ + cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + exit(-1); + } + buffer=mem0; + //push the addresses into freed fifoFree and writingFifoFree + while (buffer<(mem0+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + fifoFree->push(buffer); + buffer+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + } + + cout << "Fifo structure reconstructed" << endl; +} + + + + + + + +/** acquisition functions */ + +void slsReceiverUDPFunctions::readFrame(char* c,char** raw){ + //point to gui data + if (guiData == NULL) + guiData = latestData; + + //copy data and filename + strcpy(c,guiFileName); + + //could not get gui data + if(!guiDataReady){ + *raw = NULL; + } + //data ready, set guidata to receive new data + else{ + *raw = guiData; + guiData = NULL; + + pthread_mutex_lock(&dataReadyMutex); + guiDataReady = 0; + pthread_mutex_unlock(&dataReadyMutex); + if((nFrameToGui) && (writerthreads_mask)){ + //release after getting data + sem_post(&smp); + } + } +} + + + + + +void slsReceiverUDPFunctions::copyFrameToGui(char* startbuf){ + + //random read when gui not ready + if((!nFrameToGui) && (!guiData)){ + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + pthread_mutex_unlock(&dataReadyMutex); + } + + //random read or nth frame read, gui needs data now + else{ + //nth frame read, block current process if the guireader hasnt read it yet + if(nFrameToGui) + sem_wait(&smp); + + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + //send the first one + memcpy(latestData,startbuf,bufferSize); + strcpy(guiFileName,savefilename); + guiDataReady=1; + pthread_mutex_unlock(&dataReadyMutex); + } +} + + + + + +int slsReceiverUDPFunctions::createUDPSocket(){ + + if(udpSocket) + udpSocket->ShutDownSocket(); + + //if eth is mistaken with ip address + if (strchr(eth,'.')!=NULL) + strcpy(eth,""); + + if(udpSocket){delete udpSocket; udpSocket = NULL;} + + //if no eth, listen to all + if(!strlen(eth)){ + cout<<"warning:eth is empty.listening to all"<getErrorStatus(); + if (iret){ +#ifdef VERBOSE + cout << "Could not create UDP socket on port " << server_port << " error:" << iret << endl; +#endif + + return FAIL; + } + return OK; +} + + + + +int slsReceiverUDPFunctions::createListeningThreads(bool destroy){ + void* status; + + killListeningThread = 0; + + pthread_mutex_lock(&status_mutex); + listening_thread_running = 0; + pthread_mutex_unlock(&(status_mutex)); + + if(!destroy){ + //listening thread + cout << "Creating Listening Thread" << endl; + sem_init(&listensmp,1,0); + if(pthread_create(&listening_thread, NULL,startListeningThread, (void*) this)){ + cout << "Could not create listening thread" << endl; + return FAIL; + } +#ifdef VERBOSE + cout << "Listening thread created successfully." << endl; +#endif + }else{ + cout<<"Destroying Listening Thread"<initEventTree(temp, &iframe); + //resets the pedestalSubtraction array and the commonModeSubtraction + singlePhotonDet[ithr]->newDataSet(); + if(myFile[ithr]==NULL){ + cout<<"file null"<IsOpen()){ + cout<<"file not open"< DO_NOTHING){ + //close + if(sfilefd){ + fclose(sfilefd); + sfilefd = NULL; + } + //open file + if(!overwrite){ + if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ + cout << "Error: Could not create new file " << savefilename << endl; + return FAIL; + } + }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ + cout << "Error: Could not create file " << savefilename << endl; + return FAIL; + } + //setting buffer + setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + + //printing packet losses and file names + if(!packetsCaught) + cout << savefilename << endl; + else{ + cout << savefilename + << "\tpacket loss " + << setw(4)<GetCurrentFile(); + + if(myFile[ithr]->Write()) + //->Write(tall->GetName(),TObject::kOverwrite); + cout << "Thread " << ithr <<": wrote frames to file" << endl; + else + cout << "Thread " << ithr << ": could not write frames to file" << endl; + + }else + cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; + //close file + if(myTree[ithr] && myFile[ithr]) + myFile[ithr] = myTree[ithr]->GetCurrentFile(); + if(myFile[ithr] != NULL) + myFile[ithr]->Close(); + myFile[ithr] = NULL; + myTree[ithr] = NULL; + pthread_mutex_unlock(&write_mutex); + +#endif + } +} + + + + + +int slsReceiverUDPFunctions::startReceiver(char message[]){ + + if(myDetectorType == EIGER) + return receiver->startReceiver(message); + + +// #ifdef VERBOSE + cout << "Starting Receiver" << endl; +//#endif + + + //reset listening thread variables + measurementStarted = false; + startFrameIndex = 0; + totalListeningFrameCount = 0; + + //udp socket + if(createUDPSocket() == FAIL){ + strcpy(message,"Could not create UDP Socket.\n"); + cout << endl << message << endl; + return FAIL; + } + cout << "UDP socket created successfully on port " << server_port << endl; + + + if(setupWriter() == FAIL){ + //stop udp socket + if(udpSocket) + udpSocket->ShutDownSocket(); + + sprintf(message,"Could not create file %s.\n",savefilename); + return FAIL; + } + cout << "Successfully created file(s)" << endl; + + //done to give the gui some proper name instead of always the last file name + if(dataCompression) + sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + + //initialize semaphore + sem_init(&smp,1,0); + + //status + pthread_mutex_lock(&status_mutex); + status = RUNNING; + for(int i=0;istopReceiver(); + + +//#ifdef VERBOSE + cout << "Stopping Receiver" << endl; +//#endif + + if(status == RUNNING) + startReadout(); + + while(status == TRANSMITTING) + usleep(5000); + + //semaphore destroy + sem_post(&smp); + sem_destroy(&smp); + + //change status + pthread_mutex_lock(&status_mutex); + status = IDLE; + pthread_mutex_unlock(&(status_mutex)); + + cout << "Receiver Stopped.\nStatus:" << status << endl; + return OK; +} + + + + + +void slsReceiverUDPFunctions::startReadout(){ + + if(myDetectorType == EIGER){ + receiver->stopReceiver(); + return; + } + + + //wait so that all packets which take time has arrived + usleep(50000); + + pthread_mutex_lock(&status_mutex); + status = TRANSMITTING; + pthread_mutex_unlock(&status_mutex); + cout << "Status: Transmitting" << endl; + + //kill udp socket to tell the listening thread to push last packet + if(udpSocket){ + udpSocket->ShutDownSocket(); + delete udpSocket; + udpSocket = NULL; + } + +} + + + +void* slsReceiverUDPFunctions::startListeningThread(void* this_pointer){ + ((slsReceiverUDPFunctions*)this_pointer)->startListening(); + + return this_pointer; +} + + + +void* slsReceiverUDPFunctions::startWritingThread(void* this_pointer){ + ((slsReceiverUDPFunctions*)this_pointer)->startWriting(); + return this_pointer; +} + + + + + + +int slsReceiverUDPFunctions::startListening(){ +#ifdef VERYVERBOSE + cout << "In startListening()" << endl; +#endif + + int lastpacketoffset, expected, rc, packetcount, maxBufferSize, carryonBufferSize; + uint32_t lastframeheader;// for moench to check for all the packets in last frame + char* tempchar = NULL; + + + while(1){ + //variables that need to be checked/set before each acquisition + carryonBufferSize = 0; + maxBufferSize = packetsPerFrame * numJobsPerThread * onePacketSize; + if(tempchar) {delete [] tempchar;tempchar = NULL;} + tempchar = new char[onePacketSize * (packetsPerFrame - 1)]; //gotthard: 1packet size, moench:39 packet size + + + while(listening_thread_running){ + + //pop + fifoFree->pop(buffer); +#ifdef VERYDEBUG + cout << "*** popped from fifo free" << (void*)buffer << endl; +#endif + + //receive + if(udpSocket == NULL) + rc = 0; + else if(!carryonBufferSize){ + rc = udpSocket->ReceiveDataOnly(buffer + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + expected = maxBufferSize; + }else{ +#ifdef VERYDEBUG + cout << "***carry on buffer" << carryonBufferSize << endl; + cout<<"framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) + & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); + expected = maxBufferSize - carryonBufferSize; + } + +#ifdef VERYDEBUG + cout << "*** rc:" << dec << rc << endl; + cout << "*** expected:" << dec << expected << endl; +#endif + //start indices + //start of scan + if((!measurementStarted) && (rc > 0)){ + //gotthard has +1 for frame number + if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset); + else + startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer+HEADER_SIZE_NUM_TOT_PACKETS)))) + & (frameIndexMask)) >> frameIndexOffset); + cout<<"startFrameIndex:"<push(buffer); + exit(-1); + continue; + } + //push the last buffer into fifo + if(rc > 0){ + packetcount = (rc/onePacketSize); +#ifdef VERYDEBUG + cout << "*** last packetcount:" << packetcount << endl; +#endif + (*((uint16_t*)(buffer))) = packetcount; + totalListeningFrameCount += packetcount; + while(!fifo->push(buffer)); +#ifdef VERYDEBUG + cout << "*** last lbuf1:" << (void*)buffer << endl; +#endif + } + + + //push dummy buffer + for(int i=0;ipop(buffer); + (*((uint16_t*)(buffer))) = 0xFFFF; + while(!fifo->push(buffer)); +#ifdef VERYDEBUG + cout << "pushed in dummy buffer:" << (void*)buffer << endl; +#endif + } + cout << "Total count listened to " << totalListeningFrameCount/packetsPerFrame << endl; + pthread_mutex_lock(&status_mutex); + listening_thread_running = 0; + pthread_mutex_unlock(&(status_mutex)); + break; + } + + + //reset + packetcount = packetsPerFrame * numJobsPerThread; + carryonBufferSize = 0; + + + //check if last packet valid and calculate packet count + switch(myDetectorType){ + + + + case MOENCH: + lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; + cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; + cout << "last packet offset:" << lastpacketoffset << endl; + cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (packetIndexMask)) << endl; + cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + //moench last packet value is 0 + if( ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (packetIndexMask))){ + lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; + carryonBufferSize += onePacketSize; + lastpacketoffset -= onePacketSize; + --packetcount; + while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ + carryonBufferSize += onePacketSize; + lastpacketoffset -= onePacketSize; + --packetcount; + } + memcpy(tempchar, buffer+(lastpacketoffset+onePacketSize), carryonBufferSize); +#ifdef VERYDEBUG + cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) + & (frameIndexMask)) >> frameIndexOffset) << endl; + cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) + & (packetIndexMask)) << endl; +#endif + } + break; + + + + default: + if(shortFrame == -1){ + lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cout << "last packet offset:" << lastpacketoffset << endl; +#endif + + if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))+1) & (packetIndexMask))){ + memcpy(tempchar,buffer+lastpacketoffset, onePacketSize); +#ifdef VERYDEBUG + cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) + & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + carryonBufferSize = onePacketSize; + --packetcount; + } + } +#ifdef VERYDEBUG + cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + break; + + + + + } +#ifdef VERYDEBUG + cout << "*** packetcount:" << packetcount << " carryonbuffer:" << carryonBufferSize << endl; +#endif + //write packet count and push + (*((uint16_t*)(buffer))) = packetcount; + totalListeningFrameCount += packetcount; + while(!fifo->push(buffer)); +#ifdef VERYDEBUG + cout << "*** pushed into listening fifo" << endl; +#endif + } + + sem_wait(&listensmp); + + //make sure its not exiting thread + if(killListeningThread) + pthread_exit(NULL); + } + + return OK; +} + + + + + + + + + + + + + + + +int slsReceiverUDPFunctions::startWriting(){ + int ithread = currentWriterThreadIndex; +#ifdef VERYVERBOSE + cout << ithread << "In startWriting()" <pop(wbuf); + numpackets = (uint16_t)(*((uint16_t*)wbuf)); +#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << endl; + cout << ithread << " *** popped from fifo " << numpackets << endl; +#endif + + + + + + + //last dummy packet + if(numpackets == 0xFFFF){ +#ifdef VERYDEBUG + cout << ithread << " **********************popped last dummy frame:" << (void*)wbuf << endl; +#endif + + //free fifo + while(!fifoFree->push(wbuf)); +#ifdef VERYDEBUG + cout << ithread << " fifo freed:" << (void*)wbuf << endl; +#endif + + + + //all threads need to close file, reset mask and exit loop + closeFile(ithread); + pthread_mutex_lock(&status_mutex); + writerthreads_mask^=(1<> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + pthread_mutex_lock(&progress_mutex); + if(tempframenum > currframenum) + currframenum = tempframenum; + pthread_mutex_unlock(&progress_mutex); + } +#ifdef VERYDEBUG + cout << ithread << " tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + + + + + + //without datacompression: write datacall back, or write data, free fifo + if(!dataCompression){ + if (cbAction < DO_EVERYTHING) + rawDataReadyCallBack(currframenum, wbuf, numpackets * onePacketSize, sfilefd, guiData,pRawDataReady); + else if (numpackets > 0){ + writeToFile_withoutCompression(wbuf, numpackets); + } + //copy to gui + copyFrameToGui(wbuf + HEADER_SIZE_NUM_TOT_PACKETS); + + while(!fifoFree->push(wbuf)); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuf<findNextFrame(data,ndata,remainingsize)){ + np = ndata/onePacketSize; + + //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); + + //only for moench + if(commonModeSubtractionEnable){ + for(ix = xmin - 1; ix < xmax+1; ix++){ + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); + } + } + } + + + for(ix = xmin - 1; ix < xmax+1; ix++) + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); + if (nf>1000) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + if (thisEvent==PHOTON_MAX) { + + iFrame=receiverdata[ithread]->getFrameNumber(buff); +#ifdef MYROOT1 + myTree[ithread]->Fill(); + //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; +#else + pthread_mutex_lock(&write_mutex); + if((enableFileWrite) && (sfilefd)) + singlePhotonDet[ithread]->writeCluster(sfilefd); + pthread_mutex_unlock(&write_mutex); +#endif + } + } + } + + nf++; +#ifndef ALLFILE + pthread_mutex_lock(&progress_mutex); + packetsInFile += packetsPerFrame; + packetsCaught += packetsPerFrame; + totalPacketsCaught += packetsPerFrame; + if(packetsInFile >= maxPacketsPerFile) + createNewFile(); + pthread_mutex_unlock(&progress_mutex); + +#endif + if(!once){ + copyFrameToGui(buff); + once = 1; + } + } + + remainingsize -= ((buff + ndata) - data); + data = buff + ndata; + if(data > (wbuf + HEADER_SIZE_NUM_TOT_PACKETS + numpackets * onePacketSize) ) + cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuf)); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuf< 0){ + + //for progress and packet loss calculation(new files) + if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + if(tempframenum > currframenum) + currframenum = tempframenum; + } +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + + //lock + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + + + //to create new file when max reached + packetsToSave = maxPacketsPerFile - packetsInFile; + if(packetsToSave > numpackets) + packetsToSave = numpackets; + + fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); + packetsInFile += packetsToSave; + packetsCaught += packetsToSave; + totalPacketsCaught += packetsToSave; + + + //new file + if(packetsInFile >= maxPacketsPerFile){ + //for packet loss + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); + if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + if(tempframenum > currframenum) + currframenum = tempframenum; + } +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + //create + createNewFile(); + } + + //unlock + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); + + + offset += (packetsToSave * onePacketSize); + numpackets -= packetsToSave; + } + + } + else{ + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + packetsInFile += numpackets; + packetsCaught += numpackets; + totalPacketsCaught += numpackets; + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); + } + + + +} + + +#endif diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h new file mode 100644 index 0000000000..c1408a12a2 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h @@ -0,0 +1,685 @@ +#ifdef SLS_RECEIVER_UDP_FUNCTIONS +#ifndef SLS_RECEIVER_UDP_FUNCTIONS_H +#define SLS_RECEIVER_UDP_FUNCTIONS_H +/********************************************//** + * @file slsReceiverUDPFunctions.h + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + ***********************************************/ + + +#include "sls_receiver_defs.h" +#include "receiver_defs.h" +#include "genericSocket.h" +#include "circularFifo.h" +#include "singlePhotonDetector.h" +#include "slsReceiverData.h" +#include "moenchCommonMode.h" +#include "eigerReceiver.h" + +#ifdef MYROOT1 +#include +#include +#endif + + +#include +#include +#include +#include + + +/** + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + */ + +class slsReceiverUDPFunctions : private virtual slsReceiverDefs { + +public: + /** + * Constructor + */ + slsReceiverUDPFunctions(); + + /** + * Destructor + */ + virtual ~slsReceiverUDPFunctions(); + + /** + * delete and free member parameters + */ + void deleteMembers(); + + /** + * initialize member parameters + */ + void initializeMembers(); + + /** + * Set receiver type + * @param det detector type + * Returns success or FAIL + */ + int setDetectorType(detectorType det); + + + //Frame indices and numbers caught + /** + * Returns current Frame Index Caught for an entire acquisition (including all scans) + */ + uint32_t getAcquisitionIndex(); + + /** + * Returns if acquisition started + */ + bool getAcquistionStarted(); + + /** + * Returns Frames Caught for each real time acquisition (eg. for each scan) + */ + int getFramesCaught(); + + /** + * Returns Total Frames Caught for an entire acquisition (including all scans) + */ + int getTotalFramesCaught(); + + /** + * Returns the frame index at start of each real time acquisition (eg. for each scan) + */ + uint32_t getStartFrameIndex(); + + /** + * Returns current Frame Index for each real time acquisition (eg. for each scan) + */ + uint32_t getFrameIndex(); + + /** + * Returns if measurement started + */ + bool getMeasurementStarted(); + + /** + * Resets the Total Frames Caught + * This is how the receiver differentiates between entire acquisitions + * Returns 0 + */ + void resetTotalFramesCaught(); + + + + + //file parameters + /** + * Returns File Path + */ + char* getFilePath(); + + /** + * Set File Path + * @param c file path + */ + char* setFilePath(char c[]); + + /** + * Returns File Name + */ + char* getFileName(); + + /** + * Set File Name (without frame index, file index and extension) + * @param c file name + */ + char* setFileName(char c[]); + + /** + * Returns File Index + */ + int getFileIndex(); + + /** + * Set File Index + * @param i file index + */ + int setFileIndex(int i); + + /** + * Set Frame Index Needed + * @param i frame index needed + */ + int setFrameIndexNeeded(int i); + + /** + * Set enable file write + * @param i file write enable + * Returns file write enable + */ + int setEnableFileWrite(int i); + + /** + * Enable/disable overwrite + * @param i enable + * Returns enable over write + */ + int enableOverwrite(int i); + + + +//other parameters + + /** + * Returns status of receiver: idle, running or error + */ + runStatus getStatus(); + + /** + * Set detector hostname + * @param c hostname + */ + char* setDetectorHostname(char c[]); + + /** + * Set Ethernet Interface or IP to listen to + */ + void setEthernetInterface(char* c); + + /** + * Set UDP Port Number + */ + void setUDPPortNo(int p); + + /** + * set frame number if a positive number + */ + int32_t setNumberOfFrames(int32_t fnum); + + /** + * set scan tag if its is a positive number + */ + int32_t setScanTag(int32_t stag); + + /** + * set dynamic range if its is a positive number + */ + int32_t setDynamicRange(int32_t dr); + + /** + * Set short frame + * @param i if shortframe i=1 + */ + int setShortFrame(int i); + + /** + * Set the variable to send every nth frame to gui + * or if 0,send frame only upon gui request + */ + int setNFrameToGui(int i); + + /** set acquisition period if a positive number + */ + int64_t setAcquisitionPeriod(int64_t index); + + /** get data compression, by saving only hits + */ + bool getDataCompression(); + + /** enabl data compression, by saving only hits + /returns if failed + */ + int enableDataCompression(bool enable); + + + + + + +//other functions + + /** + * Returns the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + */ + void readFrame(char* c,char** raw); + + /** + * Closes all files + * @param ithr thread index + */ + void closeFile(int ithr = -1); + + /** + * Starts Receiver - starts to listen for packets + * @param message is the error message if there is an error + * Returns success + */ + int startReceiver(char message[]); + + /** + * Stops Receiver - stops listening for packets + * Returns success + */ + int stopReceiver(); + + /** set status to transmitting and + * when fifo is empty later, sets status to run_finished + */ + void startReadout(); + + +private: + /** + * Deletes all the filter objects for single photon data + */ + void deleteFilter(); + + /** + * Constructs the filter for single photon data + */ + void setupFilter(); + + /** + * set up fifo according to the new numjobsperthread + */ + void setupFifoStructure (); + + /** + * Copy frames to gui + * uses semaphore for nth frame mode + */ + void copyFrameToGui(char* startbuf); + + /** + * creates udp socket + * \returns if success or fail + */ + int createUDPSocket(); + + /** + * create listening thread + * @param destroy is true to kill all threads and start again + */ + int createListeningThreads(bool destroy = false); + + /** + * create writer threads + * @param destroy is true to kill all threads and start again + */ + int createWriterThreads(bool destroy = false); + + /** + * set thread priorities + */ + void setThreadPriorities(); + + /** + * initializes variables and creates the first file + * also does the startAcquisitionCallBack + * \returns FAIL or OK + */ + int setupWriter(); + + /** + * Creates new tree and file for compression + * @param ithr thread number + * @param iframe frame number + *\returns OK for succces or FAIL for failure + */ + int createCompressionFile(int ithr, int iframe); + + /** + * Creates new file + *\returns OK for succces or FAIL for failure + */ + int createNewFile(); + + /** + * Static function - Thread started which listens to packets. + * Called by startReceiver() + * @param this_pointer pointer to this object + */ + static void* startListeningThread(void *this_pointer); + + /** + * Static function - Thread started which writes packets to file. + * Called by startReceiver() + * @param this_pointer pointer to this object + */ + static void* startWritingThread(void *this_pointer); + + /** + * Thread started which listens to packets. + * Called by startReceiver() + * + */ + int startListening(); + + /** + * Thread started which writes packets to file. + * Called by startReceiver() + * + */ + int startWriting(); + + + /** + * Writing to file without compression + * @param buf is the address of buffer popped out of fifo + * @param numpackets is the number of packets + */ + void writeToFile_withoutCompression(char* buf,int numpackets); + + + + + /** Eiger Receiver */ + EigerReceiver *receiver; + + /** detector type */ + detectorType myDetectorType; + + /** detector hostname */ + char detHostname[MAX_STR_LENGTH]; + + /** status of receiver */ + runStatus status; + + /** UDP Socket between Receiver and Detector */ + genericSocket* udpSocket; + + /** Server UDP Port*/ + int server_port; + + /** ethernet interface or IP to listen to */ + char *eth; + + /** max packets per file **/ + int maxPacketsPerFile; + + /** File write enable */ + int enableFileWrite; + + /** File over write enable */ + int overwrite; + + /** Complete File name */ + char savefilename[MAX_STR_LENGTH]; + + /** File Name without frame index, file index and extension*/ + char fileName[MAX_STR_LENGTH]; + + /** File Path */ + char filePath[MAX_STR_LENGTH]; + + /** File Index */ + int fileIndex; + + /** scan tag */ + int scanTag; + + /** if frame index required in file name */ + int frameIndexNeeded; + + /* Acquisition started */ + bool acqStarted; + + /* Measurement started */ + bool measurementStarted; + + /** Frame index at start of each real time acquisition (eg. for each scan) */ + uint32_t startFrameIndex; + + /** Actual current frame index of each time acquisition (eg. for each scan) */ + uint32_t frameIndex; + + /** Frames Caught for each real time acquisition (eg. for each scan) */ + int packetsCaught; + + /** Total packets caught for an entire acquisition (including all scans) */ + int totalPacketsCaught; + + /** Pckets currently in current file, starts new file when it reaches max */ + int packetsInFile; + + /** Frame index at start of an entire acquisition (including all scans) */ + uint32_t startAcquisitionIndex; + + /** Actual current frame index of an entire acquisition (including all scans) */ + uint32_t acquisitionIndex; + + /** number of packets per frame*/ + int packetsPerFrame; + + /** frame index mask */ + uint32_t frameIndexMask; + + /** packet index mask */ + uint32_t packetIndexMask; + + /** frame index offset */ + int frameIndexOffset; + + /** acquisition period */ + int64_t acquisitionPeriod; + + /** frame number */ + int32_t numberOfFrames; + + /** dynamic range */ + int dynamicRange; + + /** short frames */ + int shortFrame; + + /** current frame number */ + uint32_t currframenum; + + /** Previous Frame number from buffer */ + uint32_t prevframenum; + + /** buffer size can be 1286*2 or 518 or 1286*40 */ + int bufferSize; + + /** oen buffer size */ + int onePacketSize; + + /** latest data */ + char* latestData; + + /** gui data ready */ + int guiDataReady; + + /** points to the data to send to gui */ + char* guiData; + + /** points to the filename to send to gui */ + char* guiFileName; + + /** send every nth frame to gui or only upon gui request*/ + int nFrameToGui; + + /** fifo size */ + unsigned int fifosize; + + /** number of jobs per thread for data compression */ + int numJobsPerThread; + + /** memory allocated for the buffer */ + char *mem0; + + /** datacompression - save only hits */ + bool dataCompression; + + /** circular fifo to store addresses of data read */ + CircularFifo* fifo; + + /** circular fifo to store addresses of data already written and ready to be resued*/ + CircularFifo* fifoFree; + + /** Receiver buffer */ + char *buffer; + + /** max number of writer threads */ + const static int MAX_NUM_WRITER_THREADS = 15; + + /** number of writer threads */ + int numWriterThreads; + + /** to know if listening and writer threads created properly */ + int thread_started; + + /** current writer thread index*/ + int currentWriterThreadIndex; + + /** thread listening to packets */ + pthread_t listening_thread; + + /** thread writing packets */ + pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; + + /** total frame count the listening thread has listened to */ + int totalListeningFrameCount; + + /** mask showing which threads are running */ + volatile uint32_t writerthreads_mask; + + /** mask showing which threads have created files*/ + volatile uint32_t createfile_mask; + + /** OK if file created was successful */ + int ret_createfile; + + /** 0 if listening thread is idle, 1 otherwise */ + int listening_thread_running; + + /** variable used to self terminate threads waiting for semaphores */ + int killListeningThread; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllWritingThreads; + + + + +//semaphores + /** semaphore to synchronize writer and guireader threads */ + sem_t smp; + /** semaphore to synchronize listener thread */ + sem_t listensmp; + /** semaphore to synchronize writer threads */ + sem_t writersmp[MAX_NUM_WRITER_THREADS]; + + +//mutex + /** guiDataReady mutex */ + pthread_mutex_t dataReadyMutex; + + /** mutex for status */ + pthread_mutex_t status_mutex; + + /** mutex for progress variable currframenum */ + pthread_mutex_t progress_mutex; + + /** mutex for writing data to file */ + pthread_mutex_t write_mutex; + + /** File Descriptor */ + FILE *sfilefd; + + //filter + singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + moenchCommonMode *cmSub; + bool commonModeSubtractionEnable; + +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUM_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUM_WRITER_THREADS]; +#endif + + + + /** + callback arguments are + filepath + filename + fileindex + data size + + return value is + 0 callback takes care of open,close,write file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + + */ + int (*startAcquisitionCallBack)(char*, char*,int, int, void*); + void *pStartAcquisition; + + /** + args to acquisition finished callback + total frames caught + + */ + void (*acquisitionFinishedCallBack)(int, void*); + void *pAcquisitionFinished; + + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); + void *pRawDataReady; + + /** The action which decides what the user and default responsibilites to save data are + * 0 raw data ready callback takes care of open,close,write file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ + int cbAction; + + +public: + + + /** + callback arguments are + filepath + filename + fileindex + datasize + + return value is + 0 callback takes care of open,close,wrie file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + */ + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; + + /** + callback argument is + toatal frames caught + */ + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; +}; + + +#endif + +#endif diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp new file mode 100644 index 0000000000..ce20017214 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp @@ -0,0 +1,43 @@ +#include "slsReceiverUsers.h" +#include "slsReceiverTCPIPInterface.h" + +slsReceiverTCPIPInterface* slsReceiverUsers::receiver(NULL); + +slsReceiverUsers::slsReceiverUsers(int argc, char *argv[], int &success) { + slsReceiverUsers::receiver=new slsReceiverTCPIPInterface(argc, argv, success); +} + +slsReceiverUsers::~slsReceiverUsers() { + delete slsReceiverUsers::receiver; +} + +void slsReceiverUsers::start() { + slsReceiverUsers::receiver->start(); +} + + +void slsReceiverUsers::closeFile(int p) { + slsReceiverUsers::receiver->closeFile(p); +} + +int64_t slsReceiverUsers::getReceiverVersion(){ + slsReceiverUsers::receiver->get_version(); +} + + +void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ + slsReceiverUsers::receiver->registerCallBackStartAcquisition(func,arg); +} + + + +void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ + slsReceiverUsers::receiver->registerCallBackAcquisitionFinished(func,arg); +} + + +void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ + slsReceiverUsers::receiver->registerCallBackRawDataReady(func,arg); +} + + diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h new file mode 100644 index 0000000000..aab02b699c --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h @@ -0,0 +1,85 @@ + +#ifndef SLS_RECEIVER_USERS_H +#define SLS_RECEIVER_USERS_H + +#include +#include + +class slsReceiverTCPIPInterface; + + /** +@short Class for implementing the SLS data receiver in the users application. Callbacks can be defined for processing and/or saving data + */ +/** + + + @libdoc slsReceiverUsers is a class that can be instantiated in the users software to receive the data from the detectors. Callbacks can be defined for processing and/or saving data + + + ***********************************************/ + +class slsReceiverUsers { + +public: + /** + * Constructor + * reads config file, creates socket, assigns function table + * @param argc from command line + * @param argv from command line + * @param succecc socket creation was successfull + */ + slsReceiverUsers(int argc, char *argv[], int &success); + + + /** Destructor */ + ~slsReceiverUsers(); + + /** Close File and exits receiver server */ + void closeFile(int p); + + /** starts listening on the TCP port for client comminication */ + void start(); + + /** + get get Receiver Version + \returns id + */ + int64_t getReceiverVersion(); + + /** + + @sort register calbback for starting the acquisition + \param func callback to be called when starting the acquisition. Its arguments are filepath filename fileindex data size + + \returns 0 callback takes care of open,close,write file; 1 callback writes file, we have to open, close it; 2 we open, close, write file, callback does not do anything + + */ + + void registerCallBackStartAcquisition(int (*func)(char* filepath, char* filename,int fileindex, int datasize, void*),void *arg); + + + /** + @sort register callback for end of acquisition + \param func end of acquisition callback. Argument nf is total frames caught + \returns nothing + */ + + + void registerCallBackAcquisitionFinished(void (*func)(int nf, void*),void *arg); + + + + /** + @sort register callback to be called when data are available (to process and/or save the data). + \param func raw data ready callback. arguments are framenum datapointer datasize file descriptor guidatapointer (NULL, no data required) + \returns nothing + */ + + void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); + + // made static to close thread files with ctrl+c + static slsReceiverTCPIPInterface* receiver; +}; + + +#endif From af89269c0c94e7dc8a7ae0ad90e5d7f7275c2672 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Wed, 21 May 2014 10:41:33 +0200 Subject: [PATCH 002/222] ignoring binaries --- slsReceiverSoftware/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 slsReceiverSoftware/.gitignore diff --git a/slsReceiverSoftware/.gitignore b/slsReceiverSoftware/.gitignore new file mode 100644 index 0000000000..5761abcfdf --- /dev/null +++ b/slsReceiverSoftware/.gitignore @@ -0,0 +1 @@ +*.o From 567501c6f762e05450de2c59456cdce9fa89eced Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Fri, 23 May 2014 14:50:11 +0200 Subject: [PATCH 003/222] included the stop receiver function for the users --- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 14 ++++++- .../slsReceiver/slsReceiverTCPIPInterface.h | 39 ++++++++++--------- .../slsReceiver/slsReceiverUDPFunctions.cpp | 32 +++++++++------ .../slsReceiver/slsReceiverUDPFunctions.h | 5 +++ .../slsReceiver/slsReceiverUsers.cpp | 4 ++ .../slsReceiver/slsReceiverUsers.h | 3 ++ 6 files changed, 64 insertions(+), 33 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index c3720ad05c..2c9e9b5f44 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -31,6 +31,7 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int &success): myDetectorType(GOTTHARD), + slsReceiverFunctions(NULL), ret(OK), lockStatus(0), shortFrame(-1), @@ -168,7 +169,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int //Catch signal SIGINT to close files properly signal(SIGINT,staticCloseFile); - file_des=socket->getFileDes(); socketDescriptor=socket->getsocketDescriptor(); @@ -178,6 +178,7 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int } + void slsReceiverTCPIPInterface::start(){ int v=slsReceiverDefs::OK; @@ -203,9 +204,18 @@ void slsReceiverTCPIPInterface::start(){ #endif } } - +} +void slsReceiverTCPIPInterface::stop(){ + //shut down udp socket + if(slsReceiverFunctions) + slsReceiverFunctions->shutDownUDPSocket(); + //disconnect and delete socket + socket->Disconnect(); + delete socket; + //close file and exit + closeFile(0); } diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index b0cd6e7806..75dc920a8f 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -1,4 +1,4 @@ - /********************************************//** +/********************************************//** * @file slsReceiverTCPIPInterface.h * @short interface between receiver and client ***********************************************/ @@ -14,8 +14,8 @@ /** - *@short interface between receiver and client - */ + *@short interface between receiver and client + */ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { @@ -27,13 +27,14 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { * @param argv from command line * @param succecc socket creation was successfull */ - slsReceiverTCPIPInterface(int argc, char *argv[], int &success); + slsReceiverTCPIPInterface(int argc, char *argv[], int &success); - - /** starts listening on the TCP port for client comminication */ - + /** starts listening on the TCP port for client comminication */ void start(); + /** stop listening on the TCP & UDP port for client comminication and exit receiver */ + void stop(); + /** Destructor */ virtual ~slsReceiverTCPIPInterface(); @@ -52,14 +53,14 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { filename fileindex data size - + return value is 0 callback takes care of open,close,wrie file 1 callback writes file, we have to open, close it 2 we open, close, write file, callback does not do anything - */ - + */ + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){slsReceiverFunctions->registerCallBackStartAcquisition(func,arg);};; @@ -67,11 +68,11 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { callback argument is toatal farmes caught - */ - - + */ + + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){slsReceiverFunctions->registerCallBackAcquisitionFinished(func,arg);}; - + /** @@ -81,12 +82,12 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { datasize in bytes file descriptor guidatapointer (NULL, no data required) - */ - + */ + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){slsReceiverFunctions->registerCallBackRawDataReady(func,arg);}; - private: +private: /** assigns functions to the fnum enum */ int function_table(); @@ -228,8 +229,8 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { static int file_des; static int socketDescriptor; -//private: - protected: + //private: +protected: /** Socket */ MySocketTCP* socket; }; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index 0b710f1993..4fc0fabecf 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -105,7 +105,7 @@ void slsReceiverUDPFunctions::deleteMembers(){ receiverdata[i] = NULL; } } - if(udpSocket) {delete udpSocket; udpSocket = NULL;} + shutDownUDPSocket(); if(eth) {delete [] eth; eth = NULL;} if(latestData) {delete [] latestData; latestData = NULL;} if(guiFileName) {delete [] guiFileName; guiFileName = NULL;} @@ -802,14 +802,11 @@ void slsReceiverUDPFunctions::copyFrameToGui(char* startbuf){ int slsReceiverUDPFunctions::createUDPSocket(){ - if(udpSocket) - udpSocket->ShutDownSocket(); - //if eth is mistaken with ip address if (strchr(eth,'.')!=NULL) strcpy(eth,""); - if(udpSocket){delete udpSocket; udpSocket = NULL;} + shutDownUDPSocket(); //if no eth, listen to all if(!strlen(eth)){ @@ -838,6 +835,22 @@ int slsReceiverUDPFunctions::createUDPSocket(){ + + + +int slsReceiverUDPFunctions::shutDownUDPSocket(){ + if(udpSocket){ + udpSocket->ShutDownSocket(); + delete udpSocket; + udpSocket = NULL; + } + return OK; +} + + + + + int slsReceiverUDPFunctions::createListeningThreads(bool destroy){ void* status; @@ -1224,8 +1237,7 @@ int slsReceiverUDPFunctions::startReceiver(char message[]){ if(setupWriter() == FAIL){ //stop udp socket - if(udpSocket) - udpSocket->ShutDownSocket(); + shutDownUDPSocket(); sprintf(message,"Could not create file %s.\n",savefilename); return FAIL; @@ -1312,11 +1324,7 @@ void slsReceiverUDPFunctions::startReadout(){ cout << "Status: Transmitting" << endl; //kill udp socket to tell the listening thread to push last packet - if(udpSocket){ - udpSocket->ShutDownSocket(); - delete udpSocket; - udpSocket = NULL; - } + shutDownUDPSocket(); } diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h index c1408a12a2..2029b31264 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h @@ -266,6 +266,11 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { */ void startReadout(); + /** + * shuts down the udp socket + * \returns if success or fail + */ + int shutDownUDPSocket(); private: /** diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp index ce20017214..7e97ef63fa 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp @@ -15,6 +15,10 @@ void slsReceiverUsers::start() { slsReceiverUsers::receiver->start(); } +void slsReceiverUsers::stop() { + slsReceiverUsers::receiver->stop(); +} + void slsReceiverUsers::closeFile(int p) { slsReceiverUsers::receiver->closeFile(p); diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h index aab02b699c..a2b5502b60 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h @@ -40,6 +40,9 @@ class slsReceiverUsers { /** starts listening on the TCP port for client comminication */ void start(); + /** stops listening to the TCP & UDP port and exit receiver program*/ + void stop(); + /** get get Receiver Version \returns id From 90f5fb39dba7dd1c787f374306ef29423ea7f8db Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Fri, 23 May 2014 18:28:42 +0200 Subject: [PATCH 004/222] started receiver start on a separate thread and returns, whereas stop receiver will end udp, tcp socket and exit thread --- .../slsReceiver/slsReceiver.cpp | 49 +++++---- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 104 +++++++++++++----- .../slsReceiver/slsReceiverTCPIPInterface.h | 31 +++++- .../slsReceiver/slsReceiverUsers.cpp | 4 +- .../slsReceiver/slsReceiverUsers.h | 7 +- 5 files changed, 137 insertions(+), 58 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp index 104fafad93..3513a26c74 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp @@ -5,6 +5,7 @@ #include "slsReceiverUsers.h" #include +#include using namespace std; @@ -13,15 +14,15 @@ using namespace std; int main(int argc, char *argv[]) { - int ret = slsReceiverDefs::OK; - - slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret); - - if(ret==slsReceiverDefs::FAIL) - return -1; - + int ret = slsReceiverDefs::OK; - //register callbacks + slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret); + + if(ret==slsReceiverDefs::FAIL) + return -1; + + + //register callbacks /** @@ -30,7 +31,7 @@ int main(int argc, char *argv[]) { filename fileindex datasize - + return value is 0 raw data ready callback takes care of open,close,write file 1 callback writes file, we have to open, close it @@ -38,8 +39,8 @@ int main(int argc, char *argv[]) { registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); - */ - + */ + //receiver->registerCallBackStartAcquisition(func,arg); @@ -47,11 +48,11 @@ int main(int argc, char *argv[]) { callback argument is total farmes caught registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); - */ - + */ + //receiver->registerCallBackAcquisitionFinished(func,arg); - + /** @@ -60,22 +61,30 @@ int main(int argc, char *argv[]) { datapointer file descriptor guidatapointer (NULL, no data required) - + NEVER DELETE THE DATA POINTER REMEMBER THAT THE CALLBACK IS BLOCKING registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg); - */ + */ //receiver->registerCallBackRawDataReady(func,arg); + //start tcp server thread + if(user->start() == slsReceiverDefs::OK){ + string str; + cin>>str; + //wait and look for an exit keyword + while(str.find("exit") == string::npos) + cin>>str; + //stop tcp server thread, stop udp socket + user->stop(); + } - user->start(); - - - return 0; + cout << "Goodbye!" << endl; + return 0; } diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index 2c9e9b5f44..244c685b11 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -19,8 +19,6 @@ using namespace std; -int slsReceiverTCPIPInterface::file_des(-1); -int slsReceiverTCPIPInterface::socketDescriptor(-1); slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { @@ -36,7 +34,8 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int lockStatus(0), shortFrame(-1), packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), - socket(NULL){ + socket(NULL), + killTCPServerThread(0){ int port_no = DEFAULT_PORTNO+2; ifstream infile; @@ -169,21 +168,64 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int //Catch signal SIGINT to close files properly signal(SIGINT,staticCloseFile); - file_des=socket->getFileDes(); - socketDescriptor=socket->getsocketDescriptor(); - - //success = OK; } } } -void slsReceiverTCPIPInterface::start(){ +int slsReceiverTCPIPInterface::start(){ + cout << "Creating TCP Server Thread" << endl; + killTCPServerThread = 0; + if(pthread_create(&TCPServer_thread, NULL,startTCPServerThread, (void*) this)){ + cout << "Could not create TCP Server thread" << endl; + return FAIL; + } +#ifdef VERBOSE + cout << "TCP Server thread created successfully." << endl; +#endif + return OK; +} + + +void slsReceiverTCPIPInterface::stop(){ + + cout << "Shutting down UDP Socket" << endl; + if(slsReceiverFunctions) + slsReceiverFunctions->shutDownUDPSocket(); + + cout << "Closing Files... " << endl; + slsReceiverFunctions->closeFile(); + + + cout<<"Shutting down TCP Socket and TCP thread"<ShutDownSocket(); + void* status; + pthread_join(TCPServer_thread, &status); + killTCPServerThread = 0; + +} + + + - int v=slsReceiverDefs::OK; - while(v!=GOODBYE) { +void* slsReceiverTCPIPInterface::startTCPServerThread(void *this_pointer){ + ((slsReceiverTCPIPInterface*)this_pointer)->startTCPServer(); + return this_pointer; +} + + +void slsReceiverTCPIPInterface::startTCPServer(){ + + +#ifdef VERYVERBOSE + cout << "Starting Receiver TCP Server" << endl; +#endif + int v=slsReceiverDefs::OK; + + while(1) { #ifdef VERBOSE cout<< endl; #endif @@ -192,31 +234,39 @@ void slsReceiverTCPIPInterface::start(){ #endif if(socket->Connect()>=0){ #ifdef VERY_VERBOSE - cout << "Conenction accepted" << endl; + cout << "Conenction accepted" << endl; #endif - v = decode_function(); + v = decode_function(); #ifdef VERY_VERBOSE - cout << "function executed" << endl; + cout << "function executed" << endl; #endif - socket->Disconnect(); + socket->Disconnect(); #ifdef VERY_VERBOSE - cout << "connection closed" << endl; + cout << "connection closed" << endl; #endif } + + //if tcp command was to exit server + if(v==GOODBYE){ + cout << "Shutting down UDP Socket" << endl; + if(slsReceiverFunctions) + slsReceiverFunctions->shutDownUDPSocket(); + + cout << "Closing Files... " << endl; + slsReceiverFunctions->closeFile(); + + pthread_exit(NULL); + } + + //if user entered exit + if(killTCPServerThread) + pthread_exit(NULL); + } } -void slsReceiverTCPIPInterface::stop(){ - //shut down udp socket - if(slsReceiverFunctions) - slsReceiverFunctions->shutDownUDPSocket(); - //disconnect and delete socket - socket->Disconnect(); - delete socket; - //close file and exit - closeFile(0); -} + int slsReceiverTCPIPInterface::function_table(){ @@ -330,8 +380,7 @@ int slsReceiverTCPIPInterface::M_nofunc(){ void slsReceiverTCPIPInterface::closeFile(int p){ - cout<<"Closing Files... "<closeFile(); + stop(); cout << "Goodbye!" << endl; exit(-1); } @@ -1850,7 +1899,6 @@ int slsReceiverTCPIPInterface::set_port() { socket->Disconnect(); delete socket; socket = mySocket; - file_des=socket->getFileDes(); } } diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index 75dc920a8f..cc0d487521 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -29,10 +29,13 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { */ slsReceiverTCPIPInterface(int argc, char *argv[], int &success); - /** starts listening on the TCP port for client comminication */ - void start(); + /** + * Starts listening on the TCP port for client comminication + \returns OK or FAIL + */ + int start(); - /** stop listening on the TCP & UDP port for client comminication and exit receiver */ + /** stop listening on the TCP & UDP port for client comminication */ void stop(); /** Destructor */ @@ -88,6 +91,20 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { private: + + /** + * Static function - Thread started which is a TCP server + * Called by start() + * @param this_pointer pointer to this object + */ + static void* startTCPServerThread(void *this_pointer); + + /** + * Thread started which is a TCP server + * Called by start() + */ + void startTCPServer(); + /** assigns functions to the fnum enum */ int function_table(); @@ -226,10 +243,12 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** Packets per frame */ int packetsPerFrame; - static int file_des; - static int socketDescriptor; + /** kill tcp server thread */ + int killTCPServerThread; + + /** thread for TCP server */ + pthread_t TCPServer_thread; - //private: protected: /** Socket */ MySocketTCP* socket; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp index 7e97ef63fa..f0e655f3c4 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp @@ -11,8 +11,8 @@ slsReceiverUsers::~slsReceiverUsers() { delete slsReceiverUsers::receiver; } -void slsReceiverUsers::start() { - slsReceiverUsers::receiver->start(); +int slsReceiverUsers::start() { + return slsReceiverUsers::receiver->start(); } void slsReceiverUsers::stop() { diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h index a2b5502b60..2dee1e1514 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h @@ -37,8 +37,11 @@ class slsReceiverUsers { /** Close File and exits receiver server */ void closeFile(int p); - /** starts listening on the TCP port for client comminication */ - void start(); + /** + * starts listening on the TCP port for client comminication + \return 0 for success or 1 for FAIL in creating TCP server + */ + int start(); /** stops listening to the TCP & UDP port and exit receiver program*/ void stop(); From d133d7eb8f46d1e641032d96aed7a195374bc6fa Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Wed, 28 May 2014 18:06:00 +0200 Subject: [PATCH 005/222] some changes on the eiger receiver side --- slsReceiverSoftware/includes/receiver_defs.h | 38 +++++--- .../includes/sls_receiver_defs.h | 1 + slsReceiverSoftware/slsReceiver/Makefile | 2 +- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 4 +- .../slsReceiver/slsReceiverUDPFunctions.cpp | 94 +++++++++++-------- 5 files changed, 86 insertions(+), 53 deletions(-) diff --git a/slsReceiverSoftware/includes/receiver_defs.h b/slsReceiverSoftware/includes/receiver_defs.h index 8dfbf7c992..42ee131a18 100755 --- a/slsReceiverSoftware/includes/receiver_defs.h +++ b/slsReceiverSoftware/includes/receiver_defs.h @@ -19,16 +19,24 @@ #define HEADER_SIZE_NUM_PACKETS 1 -//all max frames defined in sls_receiver_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench +//all max frames defined in sls_receiver_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench, eiger 20000 #define GOTTHARD_FIFO_SIZE 25000 //cannot be less than max jobs per thread = 1000 -/*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/ +/*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/ #define GOTTHARD_PACKETS_PER_FRAME 2 #define GOTTHARD_ONE_PACKET_SIZE 1286 #define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2 #define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME) //1280*2 +#define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE +#define GOTTHARD_FRAME_INDEX_OFFSET 1 +#define GOTTHARD_PACKET_INDEX_MASK 0x1 + +#define GOTTHARD_PIXELS_IN_ROW 1280 +#define GOTTHARD_PIXELS_IN_COL 1 + + #define GOTTHARD_SHORT_PACKETS_PER_FRAME 1 #define GOTTHARD_SHORT_BUFFER_SIZE 518 #define GOTTHARD_SHORT_DATABYTES 512 @@ -39,13 +47,6 @@ #define GOTTHARD_SHORT_PIXELS_IN_COL 1 -#define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE -#define GOTTHARD_FRAME_INDEX_OFFSET 1 -#define GOTTHARD_PACKET_INDEX_MASK 0x1 - -#define GOTTHARD_PIXELS_IN_ROW 1280 -#define GOTTHARD_PIXELS_IN_COL 1 - #define MOENCH_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 @@ -55,18 +56,29 @@ #define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40 #define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) //1280*40 +#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 +#define MOENCH_FRAME_INDEX_OFFSET 8 +#define MOENCH_PACKET_INDEX_MASK 0xFF + #define MOENCH_BYTES_PER_ADC (40*2) #define MOENCH_PIXELS_IN_ONE_ROW 160 #define MOENCH_BYTES_IN_ONE_ROW (MOENCH_PIXELS_IN_ONE_ROW*2) -#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 -#define MOENCH_FRAME_INDEX_OFFSET 8 -#define MOENCH_PACKET_INDEX_MASK 0xFF +#define EIGER_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 +/*#define EIGER_ALIGNED_FRAME_SIZE 65536*/ +#define EIGER_PACKETS_PER_FRAME 1 //default for 16B +#define EIGER_ONE_PACKET_SIZE 1040 //default for 16B +#define EIGER_BUFFER_SIZE (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME) //1040*1 //default for 16B +#define EIGER_DATA_BYTES (1032*EIGER_PACKETS_PER_FRAME) //1280*40 //default for 16B + +#define EIGER_FRAME_INDEX_MASK 0xFFFFFF00 +#define EIGER_FRAME_INDEX_OFFSET 8 +#define EIGER_PACKET_INDEX_MASK 0xFF + -//#define THIS_SOFTWARE_VERSION 0x20120919 #endif diff --git a/slsReceiverSoftware/includes/sls_receiver_defs.h b/slsReceiverSoftware/includes/sls_receiver_defs.h index c4c1fc63e4..70fc6ece87 100755 --- a/slsReceiverSoftware/includes/sls_receiver_defs.h +++ b/slsReceiverSoftware/includes/sls_receiver_defs.h @@ -19,6 +19,7 @@ typedef int int32_t; #define MAX_FRAMES_PER_FILE 20000 #define SHORT_MAX_FRAMES_PER_FILE 100000 #define MOENCH_MAX_FRAMES_PER_FILE 1000 +#define EIGER_MAX_FRAMES_PER_FILE 20000 /** diff --git a/slsReceiverSoftware/slsReceiver/Makefile b/slsReceiverSoftware/slsReceiver/Makefile index 0fd416ca03..92428c9571 100644 --- a/slsReceiverSoftware/slsReceiver/Makefile +++ b/slsReceiverSoftware/slsReceiver/Makefile @@ -40,7 +40,7 @@ $(DESTDIR)/sslsReceiver: lib $(DESTDIR)/slsReceiver: eigerReceiver lib - $(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC + $(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC #$(EIGERFLAGS) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index 244c685b11..74c12dbca6 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -798,9 +798,9 @@ int slsReceiverTCPIPInterface::start_receiver(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ socket->SendDataOnly(mess,sizeof(mess)); - cout<<"ret of start receiver:"<setFileName(fileName); - } +#endif - onePacketSize = bufferSize/packetsPerFrame; + } latestData = new char[bufferSize]; @@ -322,7 +336,7 @@ void slsReceiverUDPFunctions::resetTotalFramesCaught(){ /*file parameters*/ char* slsReceiverUDPFunctions::getFilePath(){ - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->getFilePath(); else return filePath; @@ -333,7 +347,7 @@ char* slsReceiverUDPFunctions::setFilePath(char c[]){ //check if filepath exists struct stat st; if(stat(c,&st) == 0){ - if(myDetectorType == EIGER) + if(receiver != NULL) receiver->setFilePath(c); else strcpy(filePath,c); @@ -347,7 +361,7 @@ char* slsReceiverUDPFunctions::setFilePath(char c[]){ char* slsReceiverUDPFunctions::getFileName(){ - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->getFileName(); else return fileName; @@ -355,7 +369,7 @@ char* slsReceiverUDPFunctions::getFileName(){ char* slsReceiverUDPFunctions::setFileName(char c[]){ if(strlen(c)){ - if(myDetectorType == EIGER) + if(receiver != NULL) receiver->setFileName(c); else strcpy(fileName,c); @@ -385,13 +399,13 @@ int slsReceiverUDPFunctions::setFrameIndexNeeded(int i){ int slsReceiverUDPFunctions::setEnableFileWrite(int i){ if(i!=-1){ - if(myDetectorType == EIGER) + if(receiver != NULL) receiver->setEnableFileWrite(i); else enableFileWrite=i; } - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->getEnableFileWrite(); else return enableFileWrite; @@ -402,13 +416,13 @@ int slsReceiverUDPFunctions::setEnableFileWrite(int i){ int slsReceiverUDPFunctions::enableOverwrite(int i){ if(i!=-1){ - if(myDetectorType == EIGER) + if(receiver != NULL) receiver->setEnableOverwrite(i); else overwrite=i; } - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->getEnableOverwrite(); else return overwrite; @@ -421,7 +435,7 @@ int slsReceiverUDPFunctions::enableOverwrite(int i){ /*other parameters*/ slsReceiverDefs::runStatus slsReceiverUDPFunctions::getStatus(){ - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->getStatus(); else return status; @@ -430,14 +444,14 @@ slsReceiverDefs::runStatus slsReceiverUDPFunctions::getStatus(){ char* slsReceiverUDPFunctions::setDetectorHostname(char c[]){ if(strlen(c)){ - if(myDetectorType == EIGER){ + if(receiver != NULL){ if(receiver->getDetectorHostname()== NULL) receiver->initialize(c); }else strcpy(detHostname,c); } - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->getDetectorHostname(); else return detHostname; @@ -456,13 +470,13 @@ void slsReceiverUDPFunctions::setUDPPortNo(int p){ int32_t slsReceiverUDPFunctions::setNumberOfFrames(int32_t fnum){ if(fnum >= 0){ - if(myDetectorType == EIGER) + if(receiver != NULL) receiver->setNumberOfFrames(fnum); else numberOfFrames = fnum; } - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->getNumberOfFrames(); else return numberOfFrames; @@ -470,13 +484,13 @@ int32_t slsReceiverUDPFunctions::setNumberOfFrames(int32_t fnum){ int32_t slsReceiverUDPFunctions::setScanTag(int32_t stag){ if(stag >= 0){ - if(myDetectorType == EIGER) + if(receiver != NULL) receiver->setScanTag(stag); else scanTag = stag; } - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->getScanTag(); else return scanTag; @@ -484,13 +498,13 @@ int32_t slsReceiverUDPFunctions::setScanTag(int32_t stag){ int32_t slsReceiverUDPFunctions::setDynamicRange(int32_t dr){ if(dr >= 0){ - if(myDetectorType == EIGER) + if(receiver != NULL) receiver->setDynamicRange(dr); else dynamicRange = dr; } - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->getDynamicRange(); else return dynamicRange; @@ -541,7 +555,7 @@ int64_t slsReceiverUDPFunctions::setAcquisitionPeriod(int64_t index){ if(index >= 0){ if(index != acquisitionPeriod){ acquisitionPeriod = index; - if(myDetectorType != EIGER) + if(receiver != NULL) setupFifoStructure(); } } @@ -658,6 +672,10 @@ void slsReceiverUDPFunctions::setupFilter(){ void slsReceiverUDPFunctions::setupFifoStructure(){ + + if(receiver != NULL) + return; + int64_t i; int oldn = numJobsPerThread; @@ -688,6 +706,8 @@ void slsReceiverUDPFunctions::setupFifoStructure(){ fifosize = GOTTHARD_FIFO_SIZE; if(myDetectorType == MOENCH) fifosize = MOENCH_FIFO_SIZE; + else if(myDetectorType == EIGER) + fifosize = EIGER_FIFO_SIZE; if(fifosize % numJobsPerThread) fifosize = (fifosize/numJobsPerThread)+1; @@ -1212,7 +1232,7 @@ void slsReceiverUDPFunctions::closeFile(int ithr){ int slsReceiverUDPFunctions::startReceiver(char message[]){ - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->startReceiver(message); @@ -1276,7 +1296,7 @@ int slsReceiverUDPFunctions::startReceiver(char message[]){ int slsReceiverUDPFunctions::stopReceiver(){ - if(myDetectorType == EIGER) + if(receiver != NULL) return receiver->stopReceiver(); @@ -1309,7 +1329,7 @@ int slsReceiverUDPFunctions::stopReceiver(){ void slsReceiverUDPFunctions::startReadout(){ - if(myDetectorType == EIGER){ + if(receiver != NULL){ receiver->stopReceiver(); return; } From 21a3b68d812f8a11881c2aeaccd8304f21a5f4a3 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Tue, 3 Jun 2014 12:06:57 +0200 Subject: [PATCH 006/222] git version history --- slsReceiverSoftware/gitInfo.txt | 9 +++++++++ slsReceiverSoftware/includes/gitInfoReceiver.h | 11 +++++++++++ .../{svnInfoReceiverTmp.h => gitInfoReceiverTmp.h} | 0 slsReceiverSoftware/includes/svnInfoReceiver.h | 11 ----------- 4 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 slsReceiverSoftware/gitInfo.txt create mode 100644 slsReceiverSoftware/includes/gitInfoReceiver.h rename slsReceiverSoftware/includes/{svnInfoReceiverTmp.h => gitInfoReceiverTmp.h} (100%) delete mode 100644 slsReceiverSoftware/includes/svnInfoReceiver.h diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt new file mode 100644 index 0000000000..b09cfef5cf --- /dev/null +++ b/slsReceiverSoftware/gitInfo.txt @@ -0,0 +1,9 @@ +Path: slsDetectorsPackage/slsReceiverSoftware +URL: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git +Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git +Repsitory UUID: 77af4677a040fe113b5115475c18fd27f2453def +Revision: 5 +Branch: master +Last Changed Author: Maliakal_Dhanya +Last Changed Rev: 5 +Last Changed Date: 2014-05-28 18:06:00 +0200 diff --git a/slsReceiverSoftware/includes/gitInfoReceiver.h b/slsReceiverSoftware/includes/gitInfoReceiver.h new file mode 100644 index 0000000000..641a0bdef7 --- /dev/null +++ b/slsReceiverSoftware/includes/gitInfoReceiver.h @@ -0,0 +1,11 @@ +//#define SVNPATH "" +#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git" +//#define SVNREPPATH "" +#define SVNREPUUID "77af4677a040fe113b5115475c18fd27f2453def" +//#define SVNREV 0x5 +//#define SVNKIND "" +//#define SVNSCHED "" +#define SVNAUTH "Maliakal_Dhanya" +#define SVNREV 0x5 +#define SVNDATE 0x20140528 +// diff --git a/slsReceiverSoftware/includes/svnInfoReceiverTmp.h b/slsReceiverSoftware/includes/gitInfoReceiverTmp.h similarity index 100% rename from slsReceiverSoftware/includes/svnInfoReceiverTmp.h rename to slsReceiverSoftware/includes/gitInfoReceiverTmp.h diff --git a/slsReceiverSoftware/includes/svnInfoReceiver.h b/slsReceiverSoftware/includes/svnInfoReceiver.h deleted file mode 100644 index 5b0ab940b1..0000000000 --- a/slsReceiverSoftware/includes/svnInfoReceiver.h +++ /dev/null @@ -1,11 +0,0 @@ -//#define SVNPATH "" -#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsReceiverSoftware/includes" -//#define SVNREPPATH "" -#define SVNREPUUID "5644e8d6-1a0c-4dbd-ab0e-45e7522ac187" -//#define SVNREV 0x5 -//#define SVNKIND "" -//#define SVNSCHED "" -#define SVNAUTH "l_maliakal_d" -#define SVNREV 0x5 -#define SVNDATE 0x20140515 -// From c922005f07c7f768e694b600507284b8090c44fd Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Tue, 3 Jun 2014 13:56:16 +0200 Subject: [PATCH 007/222] git version history --- slsReceiverSoftware/gitInfo.txt | 8 ++++---- slsReceiverSoftware/includes/gitInfoReceiver.h | 8 ++++---- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index b09cfef5cf..cf5def048f 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repsitory UUID: 77af4677a040fe113b5115475c18fd27f2453def -Revision: 5 +Repsitory UUID: 1c259aeba8b068b9f6e550d63a9a3a14bd7d3ab7 +Revision: 6 Branch: master Last Changed Author: Maliakal_Dhanya -Last Changed Rev: 5 -Last Changed Date: 2014-05-28 18:06:00 +0200 +Last Changed Rev: 6 +Last Changed Date: 2014-06-03 12:06:57 +0200 diff --git a/slsReceiverSoftware/includes/gitInfoReceiver.h b/slsReceiverSoftware/includes/gitInfoReceiver.h index 641a0bdef7..05f3c2ab6e 100644 --- a/slsReceiverSoftware/includes/gitInfoReceiver.h +++ b/slsReceiverSoftware/includes/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "77af4677a040fe113b5115475c18fd27f2453def" -//#define SVNREV 0x5 +#define SVNREPUUID "1c259aeba8b068b9f6e550d63a9a3a14bd7d3ab7" +//#define SVNREV 0x6 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Maliakal_Dhanya" -#define SVNREV 0x5 -#define SVNDATE 0x20140528 +#define SVNREV 0x6 +#define SVNDATE 0x20140603 // diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index 74c12dbca6..ebb3d954d6 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -5,7 +5,7 @@ #include "slsReceiverTCPIPInterface.h" #include "slsReceiverUDPFunctions.h" -#include "svnInfoReceiver.h" +#include "gitInfoReceiver.h" #include "slsReceiverUsers.h" #include //SIGINT From 3a71049f1cca6d4c6070ec1161748024f8ec1229 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Mon, 16 Jun 2014 16:53:36 +0200 Subject: [PATCH 008/222] added multiple listenign threads to incorporate multiple eiger ports, refactored the code a little bit --- .../MySocketTCP/genericSocket.h | 31 +- slsReceiverSoftware/includes/receiver_defs.h | 18 +- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 4 +- .../slsReceiver/slsReceiverUDPFunctions.cpp | 660 +++++++++++------- .../slsReceiver/slsReceiverUDPFunctions.h | 100 ++- 5 files changed, 514 insertions(+), 299 deletions(-) diff --git a/slsReceiverSoftware/MySocketTCP/genericSocket.h b/slsReceiverSoftware/MySocketTCP/genericSocket.h index 28ae7b6502..59126cf671 100644 --- a/slsReceiverSoftware/MySocketTCP/genericSocket.h +++ b/slsReceiverSoftware/MySocketTCP/genericSocket.h @@ -72,7 +72,6 @@ class sockaddr_in; using namespace std; #define DEFAULT_PACKET_SIZE 1286 -#define DEFAULT_PACKETS_PER_FRAME 2 #define SOCKET_BUFFER_SIZE (100*1024*1024) //100MB #define DEFAULT_PORTNO 1952 #define DEFAULT_BACKLOG 5 @@ -91,8 +90,7 @@ enum communicationProtocol{ UDP /**< UDP */ }; - - genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, int t = DEFAULT_PACKETS_PER_FRAME) : + genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : // portno(port_number), protocol(p), is_a_server(0), @@ -101,8 +99,7 @@ enum communicationProtocol{ packet_size(ps), nsending(0), nsent(0), - total_sent(0), - packets_per_frame(t)// sender (client): where to? ip + total_sent(0)// sender (client): where to? ip { // strcpy(hostname,host_ip_or_name); @@ -149,7 +146,7 @@ enum communicationProtocol{ */ - genericSocket(unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, int t = DEFAULT_PACKETS_PER_FRAME, const char *eth=NULL): + genericSocket(unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, const char *eth=NULL): //portno(port_number), protocol(p), is_a_server(1), @@ -158,8 +155,7 @@ enum communicationProtocol{ packet_size(ps), nsending(0), nsent(0), - total_sent(0), - packets_per_frame(t) + total_sent(0) { /* // you can specify an IP address: */ @@ -562,25 +558,23 @@ enum communicationProtocol{ break; case UDP: if (socketDescriptor<0) return -1; - //if length given + //if length given, listens to length, else listens for packetsize till length is reached if(length){ while(length>0){ - nsending=packet_size; + nsending = (length>packet_size) ? packet_size:length; nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); if(!nsent) break; length-=nsent; total_sent+=nsent; } } - //depends on packets per frame + //listens to only 1 packet else{ - for(int i=0;ishutDownUDPSocket(); + slsReceiverFunctions->shutDownUDPSockets(); cout << "Closing Files... " << endl; slsReceiverFunctions->closeFile(); @@ -250,7 +250,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){ if(v==GOODBYE){ cout << "Shutting down UDP Socket" << endl; if(slsReceiverFunctions) - slsReceiverFunctions->shutDownUDPSocket(); + slsReceiverFunctions->shutDownUDPSockets(); cout << "Closing Files... " << endl; slsReceiverFunctions->closeFile(); diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index b30d58aa23..18ba264a00 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -1,4 +1,4 @@ -#ifdef SLS_RECEIVER_UDP_FUNCTIONS +/*#ifdef SLS_RECEIVER_UDP_FUNCTIONS*/ /********************************************//** * @file slsReceiverUDPFunctions.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -31,17 +31,19 @@ using namespace std; slsReceiverUDPFunctions::slsReceiverUDPFunctions(): receiver(NULL), - server_port(DEFAULT_UDP_PORTNO), thread_started(0), - udpSocket(NULL), eth(NULL), latestData(NULL), - guiFileName(NULL), - mem0(NULL), - fifo(NULL), - fifoFree(NULL){ + guiFileName(NULL){ + for(int i=0;iisEmpty()) - fifoFree->pop(buffer); - delete fifoFree; - } - if(fifo) delete fifo; - if(mem0) free(mem0); - fifoFree = new CircularFifo(fifosize); - fifo = new CircularFifo(fifosize); - - - //allocate memory - mem0=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - /** shud let the client know about this */ - if (mem0==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; - exit(-1); - } - buffer=mem0; - //push the addresses into freed fifoFree and writingFifoFree - while (buffer<(mem0+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree->push(buffer); - buffer+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + for(int i=0;iisEmpty()) + fifoFree[i]->pop(buffer[i]); + delete fifoFree[i]; + } + if(fifo[i]) delete fifo[i]; + if(mem0[i]) free(mem0[i]); + fifoFree[i] = new CircularFifo(fifosize); + fifo[i] = new CircularFifo(fifosize); + + + //allocate memory + mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + /** shud let the client know about this */ + if (mem0[i]==NULL){ + cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + exit(-1); + } + buffer[i]=mem0[i]; + //push the addresses into freed fifoFree and writingFifoFree + while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); + buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + } } - - cout << "Fifo structure reconstructed" << endl; + cout << "Fifo structure(s) reconstructed" << endl; } @@ -792,7 +820,6 @@ void slsReceiverUDPFunctions::readFrame(char* c,char** raw){ void slsReceiverUDPFunctions::copyFrameToGui(char* startbuf){ - //random read when gui not ready if((!nFrameToGui) && (!guiData)){ pthread_mutex_lock(&dataReadyMutex); @@ -809,7 +836,8 @@ void slsReceiverUDPFunctions::copyFrameToGui(char* startbuf){ pthread_mutex_lock(&dataReadyMutex); guiDataReady=0; //send the first one - memcpy(latestData,startbuf,bufferSize); + for(int i=0;igetErrorStatus(); - if (iret){ + int iret; + for(int i=0;igetErrorStatus(); + if(iret){ #ifdef VERBOSE - cout << "Could not create UDP socket on port " << server_port << " error:" << iret << endl; + cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; #endif - - return FAIL; + return FAIL; + } } + return OK; } @@ -858,11 +893,13 @@ int slsReceiverUDPFunctions::createUDPSocket(){ -int slsReceiverUDPFunctions::shutDownUDPSocket(){ - if(udpSocket){ - udpSocket->ShutDownSocket(); - delete udpSocket; - udpSocket = NULL; +int slsReceiverUDPFunctions::shutDownUDPSockets(){ + for(int i=0;iShutDownSocket(); + delete udpSocket[i]; + udpSocket[i] = NULL; + } } return OK; } @@ -872,37 +909,53 @@ int slsReceiverUDPFunctions::shutDownUDPSocket(){ int slsReceiverUDPFunctions::createListeningThreads(bool destroy){ + int i; void* status; - killListeningThread = 0; + killAllListeningThreads = 0; pthread_mutex_lock(&status_mutex); - listening_thread_running = 0; + listeningthreads_mask = 0x0; pthread_mutex_unlock(&(status_mutex)); if(!destroy){ - //listening thread - cout << "Creating Listening Thread" << endl; - sem_init(&listensmp,1,0); - if(pthread_create(&listening_thread, NULL,startListeningThread, (void*) this)){ - cout << "Could not create listening thread" << endl; - return FAIL; + + //start listening threads + cout << "Creating Listening Threads(s)"; + + currentListeningThreadIndex = -1; + + for(i = 0; i < numListeningThreads; ++i){ + sem_init(&listensmp[i],1,0); + thread_started = 0; + currentListeningThreadIndex = i; + if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ + cout << "Could not create listening thread with index " << i << endl; + return FAIL; + } + while(!thread_started); + cout << "."; + cout << flush; } #ifdef VERBOSE - cout << "Listening thread created successfully." << endl; + cout << "Listening thread(s) created successfully." << endl; +#else + cout << endl; #endif }else{ - cout<<"Destroying Listening Thread"<startReceiver(message); @@ -1244,20 +1303,21 @@ int slsReceiverUDPFunctions::startReceiver(char message[]){ //reset listening thread variables measurementStarted = false; startFrameIndex = 0; - totalListeningFrameCount = 0; + for(int i = 0; i < numListeningThreads; ++i) + totalListeningFrameCount[i] = 0; //udp socket - if(createUDPSocket() == FAIL){ - strcpy(message,"Could not create UDP Socket.\n"); + if(createUDPSockets() == FAIL){ + strcpy(message,"Could not create UDP Socket(s).\n"); cout << endl << message << endl; return FAIL; } - cout << "UDP socket created successfully on port " << server_port << endl; + cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; if(setupWriter() == FAIL){ //stop udp socket - shutDownUDPSocket(); + shutDownUDPSockets(); sprintf(message,"Could not create file %s.\n",savefilename); return FAIL; @@ -1274,17 +1334,19 @@ int slsReceiverUDPFunctions::startReceiver(char message[]){ //status pthread_mutex_lock(&status_mutex); status = RUNNING; - for(int i=0;istopReceiver(); return; } - + //#ifdef VERBOSE + cout << "Start Receiver Readout" << endl; + //#endif //wait so that all packets which take time has arrived usleep(50000); @@ -1344,7 +1408,7 @@ void slsReceiverUDPFunctions::startReadout(){ cout << "Status: Transmitting" << endl; //kill udp socket to tell the listening thread to push last packet - shutDownUDPSocket(); + shutDownUDPSockets(); } @@ -1369,152 +1433,142 @@ void* slsReceiverUDPFunctions::startWritingThread(void* this_pointer){ int slsReceiverUDPFunctions::startListening(){ + int ithread = currentListeningThreadIndex; #ifdef VERYVERBOSE - cout << "In startListening()" << endl; + cout << "In startListening() " << endl; #endif + thread_started = 1; + + int i,total; int lastpacketoffset, expected, rc, packetcount, maxBufferSize, carryonBufferSize; uint32_t lastframeheader;// for moench to check for all the packets in last frame char* tempchar = NULL; + int imageheader = 0; + if(myDetectorType==EIGER) + imageheader = EIGER_IMAGE_HEADER_SIZE; while(1){ //variables that need to be checked/set before each acquisition carryonBufferSize = 0; - maxBufferSize = packetsPerFrame * numJobsPerThread * onePacketSize; + //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later + maxBufferSize = bufferSize * numJobsPerThread; +#ifdef VERYDEBUG + cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; +#endif + if(tempchar) {delete [] tempchar;tempchar = NULL;} - tempchar = new char[onePacketSize * (packetsPerFrame - 1)]; //gotthard: 1packet size, moench:39 packet size + if(myDetectorType == EIGER) + tempchar = new char[bufferSize]; + else + tempchar = new char[onePacketSize * (packetsPerFrame - 1)]; //gotthard: 1packet size, moench:39 packet size + - while(listening_thread_running){ + while((1<pop(buffer); + fifoFree[ithread]->pop(buffer[ithread]); #ifdef VERYDEBUG - cout << "*** popped from fifo free" << (void*)buffer << endl; + cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; #endif + //receive - if(udpSocket == NULL) + if(udpSocket[ithread] == NULL){ rc = 0; + cout << ithread << "UDP Socket is NULL" << endl; + } + //normal listening else if(!carryonBufferSize){ - rc = udpSocket->ReceiveDataOnly(buffer + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - expected = maxBufferSize; - }else{ + //eiger + if (imageheader){ + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); + //if it was the header + if(rc == EIGER_HEADER_LENGTH){ #ifdef VERYDEBUG - cout << "***carry on buffer" << carryonBufferSize << endl; - cout<<"framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) + cout << "rc for header2:" << dec << rc << endl; +#endif + expected = EIGER_HEADER_LENGTH; + }else{ + expected = maxBufferSize; + } + } + //not eiger + else{ + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + expected = maxBufferSize; + } + } + //the remaining packets from previous buffer + else{ +#ifdef VERYDEBUG + cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; + cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); + memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, tempchar, carryonBufferSize); + rc = udpSocket[ithread]->ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); expected = maxBufferSize - carryonBufferSize; } #ifdef VERYDEBUG - cout << "*** rc:" << dec << rc << endl; - cout << "*** expected:" << dec << expected << endl; + cout << ithread << " *** rc:" << dec << rc << endl; + cout << ithread << " *** expected:" << dec << expected << endl; #endif - //start indices - //start of scan - if((!measurementStarted) && (rc > 0)){ - //gotthard has +1 for frame number - if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset); - else - startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer+HEADER_SIZE_NUM_TOT_PACKETS)))) - & (frameIndexMask)) >> frameIndexOffset); - cout<<"startFrameIndex:"<push(buffer); - exit(-1); - continue; - } - //push the last buffer into fifo - if(rc > 0){ - packetcount = (rc/onePacketSize); -#ifdef VERYDEBUG - cout << "*** last packetcount:" << packetcount << endl; -#endif - (*((uint16_t*)(buffer))) = packetcount; - totalListeningFrameCount += packetcount; - while(!fifo->push(buffer)); -#ifdef VERYDEBUG - cout << "*** last lbuf1:" << (void*)buffer << endl; -#endif - } - //push dummy buffer - for(int i=0;ipop(buffer); - (*((uint16_t*)(buffer))) = 0xFFFF; - while(!fifo->push(buffer)); -#ifdef VERYDEBUG - cout << "pushed in dummy buffer:" << (void*)buffer << endl; -#endif - } - cout << "Total count listened to " << totalListeningFrameCount/packetsPerFrame << endl; - pthread_mutex_lock(&status_mutex); - listening_thread_running = 0; - pthread_mutex_unlock(&(status_mutex)); - break; + //start indices for each start of scan/acquisition - eiger does it before + if((!measurementStarted) && (rc > 0)) + startFrameIndices(ithread); + + //problem in receiving or end of acquisition + if((rc < expected)||(rc <= 0)){ + stopListening(ithread,rc,packetcount,total); + continue; } + //reset packetcount = packetsPerFrame * numJobsPerThread; carryonBufferSize = 0; + //check if last packet valid and calculate packet count switch(myDetectorType){ - - case MOENCH: lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYDEBUG - cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; - cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; + cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; + cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; cout << "last packet offset:" << lastpacketoffset << endl; - cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (packetIndexMask)) << endl; - cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; + cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; + cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; #endif //moench last packet value is 0 - if( ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (packetIndexMask))){ - lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; + if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ + lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; carryonBufferSize += onePacketSize; lastpacketoffset -= onePacketSize; --packetcount; - while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ + while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ carryonBufferSize += onePacketSize; lastpacketoffset -= onePacketSize; --packetcount; } - memcpy(tempchar, buffer+(lastpacketoffset+onePacketSize), carryonBufferSize); + memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); #ifdef VERYDEBUG cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) & (frameIndexMask)) >> frameIndexOffset) << endl; @@ -1524,17 +1578,15 @@ int slsReceiverUDPFunctions::startListening(){ } break; - - - default: + case GOTTHARD: if(shortFrame == -1){ lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYDEBUG cout << "last packet offset:" << lastpacketoffset << endl; #endif - if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer+lastpacketoffset))))+1) & (packetIndexMask))){ - memcpy(tempchar,buffer+lastpacketoffset, onePacketSize); + if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ + memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); #ifdef VERYDEBUG cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) & (frameIndexMask)) >> frameIndexOffset) << endl; @@ -1544,32 +1596,45 @@ int slsReceiverUDPFunctions::startListening(){ } } #ifdef VERYDEBUG - cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) & (frameIndexMask)) >> frameIndexOffset) << endl; #endif break; + default: + if(rc==EIGER_HEADER_LENGTH) + packetcount=0; + else + packetcount = 1; + break; + + } + - } #ifdef VERYDEBUG cout << "*** packetcount:" << packetcount << " carryonbuffer:" << carryonBufferSize << endl; #endif //write packet count and push - (*((uint16_t*)(buffer))) = packetcount; - totalListeningFrameCount += packetcount; - while(!fifo->push(buffer)); + (*((uint16_t*)(buffer[ithread]))) = packetcount; + totalListeningFrameCount[ithread] += packetcount; +#ifdef VERYDEBUG + if(!ithread) cout << "totalListeningFrameCount[" << ithread << "]:" << totalListeningFrameCount[ithread] << endl; +#endif + while(!fifo[ithread]->push(buffer[ithread])); #ifdef VERYDEBUG cout << "*** pushed into listening fifo" << endl; #endif } - sem_wait(&listensmp); + sem_wait(&listensmp[ithread]); //make sure its not exiting thread - if(killListeningThread) + if(killAllListeningThreads){ + cout << ithread << " good bye listening thread" << endl; pthread_exit(NULL); + } } return OK; @@ -1599,12 +1664,11 @@ int slsReceiverUDPFunctions::startWriting(){ int numpackets, nf; uint32_t tempframenum; - char* wbuf; + char* wbuf[MAX_NUM_LISTENING_THREADS]; char *data=new char[bufferSize]; int iFrame = 0; int xmax=0,ymax=0; - int ret; - + int ret,i; while(1){ @@ -1626,11 +1690,12 @@ int slsReceiverUDPFunctions::startWriting(){ while((1<pop(wbuf); - numpackets = (uint16_t)(*((uint16_t*)wbuf)); + for(i=0;ipop(wbuf[i]); + numpackets = (uint16_t)(*((uint16_t*)wbuf[0])); #ifdef VERYDEBUG cout << ithread << " numpackets:" << dec << numpackets << endl; cout << ithread << " *** popped from fifo " << numpackets << endl; @@ -1644,13 +1709,14 @@ int slsReceiverUDPFunctions::startWriting(){ //last dummy packet if(numpackets == 0xFFFF){ #ifdef VERYDEBUG - cout << ithread << " **********************popped last dummy frame:" << (void*)wbuf << endl; + cout << ithread << " **********************popped last dummy frame:" << (void*)wbuf[0] << endl; #endif //free fifo - while(!fifoFree->push(wbuf)); + for(i=0;ipush(wbuf[i])); #ifdef VERYDEBUG - cout << ithread << " fifo freed:" << (void*)wbuf << endl; + cout << ithread << " fifo freed:" << (void*)wbuf[i] << endl; #endif @@ -1660,7 +1726,7 @@ int slsReceiverUDPFunctions::startWriting(){ pthread_mutex_lock(&status_mutex); writerthreads_mask^=(1<> frameIndexOffset); + if(myDetectorType == EIGER){ + if(!numpackets) + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); if(numWriterThreads == 1) currframenum = tempframenum; @@ -1715,28 +1784,38 @@ int slsReceiverUDPFunctions::startWriting(){ pthread_mutex_unlock(&progress_mutex); } #ifdef VERYDEBUG - cout << ithread << " tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; + cout << endl <num2)&0xff)<<"\t\t"< 0){ - writeToFile_withoutCompression(wbuf, numpackets); - } - //copy to gui - copyFrameToGui(wbuf + HEADER_SIZE_NUM_TOT_PACKETS); + if(!dataCompression){ + + if (cbAction < DO_EVERYTHING){ + for(i=0;i 0){ + for(i=0;i 0){ + cout<<"numpackets:"<push(wbuf)); + for(i=0;ipush(wbuf[i])); #ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf< (wbuf + HEADER_SIZE_NUM_TOT_PACKETS + numpackets * onePacketSize) ) + if(data > (wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS + numpackets * onePacketSize) ) cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuf)); + while(!fifoFree[0]->push(wbuf[0])); #ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf<fnum); + //gotthard has +1 for frame number and not a short frame + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset); + else + startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) + & (frameIndexMask)) >> frameIndexOffset); + + + cout << "startFrameIndex:" << startFrameIndex<push(buffer[ithread]); + exit(-1); + } + //push the last buffer into fifo + if(rc > 0){ + pc = (rc/onePacketSize); +#ifdef VERYDEBUG + cout << ithread << " *** last packetcount:" << packetcount << endl; +#endif + (*((uint16_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef VERYDEBUG + cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; +#endif + } + + //push dummy buffer to all writer threads + for(i=0;ipop(buffer[ithread]); + (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef VERYDEBUG + cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; +#endif + } + //reset mask and exit loop + pthread_mutex_lock(&status_mutex); + listeningthreads_mask^=(1< 1) + cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; +#endif + while(listeningthreads_mask) + usleep(5000); +#ifdef VERYDEBUG + t = 0; + for(i=0;i 0){ //for progress and packet loss calculation(new files) - if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + if(myDetectorType == EIGER){ + if(((uint16_t)(*((uint16_t*)buf)))==0) + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buf + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); @@ -1950,7 +2119,10 @@ void slsReceiverUDPFunctions::writeToFile_withoutCompression(char* buf,int numpa if(packetsInFile >= maxPacketsPerFile){ //for packet loss lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + if(myDetectorType == EIGER){ + if(((uint16_t)(*((uint16_t*)buf)))==0) + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buf + lastpacket)))->fnum); + }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); else tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); @@ -1993,4 +2165,4 @@ void slsReceiverUDPFunctions::writeToFile_withoutCompression(char* buf,int numpa } -#endif +/*#endif*/ diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h index 2029b31264..691c417bed 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h @@ -1,4 +1,4 @@ -#ifdef SLS_RECEIVER_UDP_FUNCTIONS +/*#ifdef SLS_RECEIVER_UDP_FUNCTIONS*/ #ifndef SLS_RECEIVER_UDP_FUNCTIONS_H #define SLS_RECEIVER_UDP_FUNCTIONS_H /********************************************//** @@ -267,10 +267,10 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { void startReadout(); /** - * shuts down the udp socket + * shuts down the udp sockets * \returns if success or fail */ - int shutDownUDPSocket(); + int shutDownUDPSockets(); private: /** @@ -295,10 +295,10 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { void copyFrameToGui(char* startbuf); /** - * creates udp socket + * creates udp sockets * \returns if success or fail */ - int createUDPSocket(); + int createUDPSockets(); /** * create listening thread @@ -366,16 +366,54 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { */ int startWriting(); - /** * Writing to file without compression * @param buf is the address of buffer popped out of fifo * @param numpackets is the number of packets + * @param framenum current frame number + */ + void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); + + /** + * Its called for the first packet of a scan or acquistion + * Sets the startframeindices and the variables to know if acquisition started + * @param ithread listening thread number + */ + void startFrameIndices(int ithread); + + /** + * This is called when udp socket is shut down + * It pops ffff instead of packet number into fifo + * to inform writers about the end of listening session + * @param ithread listening thread number + * @param rc number of bytes received + * @param pc packet count + * @param t total packets listened to */ - void writeToFile_withoutCompression(char* buf,int numpackets); + void stopListening(int ithread, int rc, int &pc, int &t); + + + /** structure of an eiger image header*/ + typedef struct + { + unsigned char header_before[20]; + unsigned char fnum[4]; + unsigned char header_after[24]; + } eiger_image_header; + /** structure of an eiger image header*/ + typedef struct + { + unsigned char num1[4]; + unsigned char num2[4]; + } eiger_packet_header; + /** max number of listening threads */ + const static int MAX_NUM_LISTENING_THREADS = MAX_EIGER_PORTS; + + /** max number of writer threads */ + const static int MAX_NUM_WRITER_THREADS = 15; /** Eiger Receiver */ EigerReceiver *receiver; @@ -390,10 +428,10 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { runStatus status; /** UDP Socket between Receiver and Detector */ - genericSocket* udpSocket; + genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; /** Server UDP Port*/ - int server_port; + int server_port[MAX_NUM_LISTENING_THREADS]; /** ethernet interface or IP to listen to */ char *eth; @@ -482,7 +520,10 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { /** Previous Frame number from buffer */ uint32_t prevframenum; - /** buffer size can be 1286*2 or 518 or 1286*40 */ + /** size of one frame */ + int frameSize; + + /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ int bufferSize; /** oen buffer size */ @@ -509,23 +550,23 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { /** number of jobs per thread for data compression */ int numJobsPerThread; - /** memory allocated for the buffer */ - char *mem0; - /** datacompression - save only hits */ bool dataCompression; + /** memory allocated for the buffer */ + char *mem0[MAX_NUM_LISTENING_THREADS]; + /** circular fifo to store addresses of data read */ - CircularFifo* fifo; + CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; /** circular fifo to store addresses of data already written and ready to be resued*/ - CircularFifo* fifoFree; + CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; /** Receiver buffer */ - char *buffer; + char *buffer[MAX_NUM_LISTENING_THREADS]; - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; + /** number of writer threads */ + int numListeningThreads; /** number of writer threads */ int numWriterThreads; @@ -533,19 +574,25 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { /** to know if listening and writer threads created properly */ int thread_started; + /** current listening thread index*/ + int currentListeningThreadIndex; + /** current writer thread index*/ int currentWriterThreadIndex; /** thread listening to packets */ - pthread_t listening_thread; + pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; /** thread writing packets */ pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; /** total frame count the listening thread has listened to */ - int totalListeningFrameCount; + int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - /** mask showing which threads are running */ + /** mask showing which listening threads are running */ + volatile uint32_t listeningthreads_mask; + + /** mask showing which writer threads are running */ volatile uint32_t writerthreads_mask; /** mask showing which threads have created files*/ @@ -554,11 +601,8 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { /** OK if file created was successful */ int ret_createfile; - /** 0 if listening thread is idle, 1 otherwise */ - int listening_thread_running; - /** variable used to self terminate threads waiting for semaphores */ - int killListeningThread; + int killAllListeningThreads; /** variable used to self terminate threads waiting for semaphores */ int killAllWritingThreads; @@ -569,8 +613,8 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { //semaphores /** semaphore to synchronize writer and guireader threads */ sem_t smp; - /** semaphore to synchronize listener thread */ - sem_t listensmp; + /** semaphore to synchronize listener threads */ + sem_t listensmp[MAX_NUM_LISTENING_THREADS]; /** semaphore to synchronize writer threads */ sem_t writersmp[MAX_NUM_WRITER_THREADS]; @@ -687,4 +731,4 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { #endif -#endif +/*#endif*/ From 5f82381b1e5677d2e41bee21fefbdbc31e954e3b Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Wed, 18 Jun 2014 16:35:34 +0200 Subject: [PATCH 009/222] eiger gui works and can read frames, other gui functionalities not implemented --- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 130 ++++- .../slsReceiver/slsReceiverTCPIPInterface.h | 3 + .../slsReceiver/slsReceiverUDPFunctions.cpp | 481 +++++++++++------- .../slsReceiver/slsReceiverUDPFunctions.h | 33 +- 4 files changed, 445 insertions(+), 202 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index c5fa0eab31..19f74baa8c 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -1012,6 +1012,8 @@ int slsReceiverTCPIPInterface::read_frame(){ switch(myDetectorType){ case MOENCH: return moench_read_frame(); + case EIGER: + return eiger_read_frame(); default: return gotthard_read_frame(); } @@ -1036,7 +1038,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ char* raw = new char[bufferSize]; uint32_t startIndex=0; - int index = 0,bindex = 0, offset=0; + uint32_t index = 0,bindex = 0, offset=0; strcpy(mess,"Could not read frame\n"); @@ -1053,7 +1055,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ else{ ret = OK; startIndex=slsReceiverFunctions->getStartFrameIndex(); - slsReceiverFunctions->readFrame(fName,&raw); + slsReceiverFunctions->readFrame(fName,&raw,index); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1223,7 +1225,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ }else{ ret = OK; startIndex=slsReceiverFunctions->getStartFrameIndex(); - slsReceiverFunctions->readFrame(fName,&raw); + slsReceiverFunctions->readFrame(fName,&raw,index); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1334,6 +1336,128 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ + + + + + +int slsReceiverTCPIPInterface::eiger_read_frame(){ + ret=OK; + char fName[MAX_STR_LENGTH]=""; + int arg = -1,i; + uint32_t index=0; + + int bufferSize = EIGER_BUFFER_SIZE; + int onebuffersize = EIGER_BUFFER_SIZE/EIGER_PACKETS_PER_FRAME; + int onedatasize = EIGER_DATA_BYTES/EIGER_PACKETS_PER_FRAME; + int numpackets = EIGER_PACKETS_PER_FRAME; + + char* raw = new char[bufferSize]; + char* origVal = new char[bufferSize]; + char* retval = new char[EIGER_DATA_BYTES]; + + /* + //retval is a full frame + int rnel = bufferSize/(sizeof(int)); + int* retval = new int[rnel]; + int* origVal = new int[rnel]; + //all initialized to 0 + for(i=0;igetFramesCaught()){ + arg=-1; + cout<<"haven't caught any frame yet"<readFrame(fName,&raw, index); +#ifdef VERBOSE + cout << "index:" << dec << index << endl; +#endif + /**send garbage with -1 index to try again*/ + if (raw == NULL){ + arg = -1; +#ifdef VERBOSE + cout<<"data not ready for gui yet"<num2)&0xff)<<"\t\t"; + memcpy(retval+retindex ,origVal+copyindex ,onedatasize); + copyindex += 16+onedatasize; + retindex += onedatasize; + } + arg = index-1; + } + } + +#ifdef VERBOSE + if(arg!=-1){ + cout << "fName:" << fName << endl; + cout << "findex:" << arg << endl; + } +#endif + + + +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL){ + cout << "mess:" << mess << endl; + socket->SendDataOnly(mess,sizeof(mess)); + } + else{ + socket->SendDataOnly(fName,MAX_STR_LENGTH); + socket->SendDataOnly(&arg,sizeof(arg)); + socket->SendDataOnly(retval,EIGER_DATA_BYTES); + } + + delete [] retval; + delete [] origVal; + delete [] raw; + + return ret; +} + + int slsReceiverTCPIPInterface::set_read_frequency(){ ret=OK; int retval=-1; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index cc0d487521..94126d59ff 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -162,6 +162,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** moench specific read frame */ int moench_read_frame(); + /** eiger specific read frame */ + int eiger_read_frame(); + /** Sets the receiver to send every nth frame to gui, or only upon gui request */ int set_read_frequency(); diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index 18ba264a00..470a41efb7 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -1,4 +1,4 @@ -/*#ifdef SLS_RECEIVER_UDP_FUNCTIONS*/ +#ifdef SLS_RECEIVER_UDP_FUNCTIONS /********************************************//** * @file slsReceiverUDPFunctions.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -34,7 +34,8 @@ slsReceiverUDPFunctions::slsReceiverUDPFunctions(): thread_started(0), eth(NULL), latestData(NULL), - guiFileName(NULL){ + guiFileName(NULL), + guiFrameNumber(0){ for(int i=0;inum2)&0xff)<<"\t\t"; + } + guiFrameNumber = fnum; + }else//other detectors + memcpy(latestData,buf,bufferSize); + + strcpy(guiFileName,savefilename); guiDataReady=1; pthread_mutex_unlock(&dataReadyMutex); @@ -1071,6 +1084,7 @@ int slsReceiverUDPFunctions::setupWriter(){ guiData = NULL; guiDataReady=0; strcpy(guiFileName,""); + guiFrameNumber = 0; cbAction = DO_EVERYTHING; pthread_mutex_lock(&status_mutex); @@ -1402,6 +1416,8 @@ void slsReceiverUDPFunctions::startReadout(){ //wait so that all packets which take time has arrived usleep(50000); + /********************************************/ + usleep(1000000); pthread_mutex_lock(&status_mutex); status = TRANSMITTING; pthread_mutex_unlock(&status_mutex); @@ -1528,7 +1544,7 @@ int slsReceiverUDPFunctions::startListening(){ //start indices for each start of scan/acquisition - eiger does it before - if((!measurementStarted) && (rc > 0)) + if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); //problem in receiving or end of acquisition @@ -1620,11 +1636,11 @@ int slsReceiverUDPFunctions::startListening(){ (*((uint16_t*)(buffer[ithread]))) = packetcount; totalListeningFrameCount[ithread] += packetcount; #ifdef VERYDEBUG - if(!ithread) cout << "totalListeningFrameCount[" << ithread << "]:" << totalListeningFrameCount[ithread] << endl; + cout<push(buffer[ithread])); #ifdef VERYDEBUG - cout << "*** pushed into listening fifo" << endl; + if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; #endif } @@ -1652,8 +1668,6 @@ int slsReceiverUDPFunctions::startListening(){ - - int slsReceiverUDPFunctions::startWriting(){ int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE @@ -1664,16 +1678,17 @@ int slsReceiverUDPFunctions::startWriting(){ int numpackets, nf; uint32_t tempframenum; - char* wbuf[MAX_NUM_LISTENING_THREADS]; - char *data=new char[bufferSize]; - int iFrame = 0; + char* wbuf[packetsPerFrame+numListeningThreads];//interleaved + 2 ports header + char *d=new char[bufferSize]; int xmax=0,ymax=0; - int ret,i; + int ret,i,j; + int w_index=0; + int packetsPerThread = packetsPerFrame/numListeningThreads; while(1){ nf = 0; - iFrame = 0; + w_index = 0; if(myDetectorType == MOENCH){ xmax = MOENCH_PIXELS_IN_ONE_ROW-1; ymax = MOENCH_PIXELS_IN_ONE_ROW-1; @@ -1688,92 +1703,48 @@ int slsReceiverUDPFunctions::startWriting(){ } + + while((1<pop(wbuf[i]); - numpackets = (uint16_t)(*((uint16_t*)wbuf[0])); + for(i=0;ipop(wbuf[w_index+i]); + numpackets = (uint16_t)(*((uint16_t*)wbuf[w_index])); #ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** popped from fifo " << numpackets << endl; + if((!w_index)||(!numpackets)) cout << ithread << " numpackets:" << dec << numpackets << endl; #endif + } - - - - - - //last dummy packet - if(numpackets == 0xFFFF){ -#ifdef VERYDEBUG - cout << ithread << " **********************popped last dummy frame:" << (void*)wbuf[0] << endl; -#endif - - //free fifo - for(i=0;ipush(wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << " fifo freed:" << (void*)wbuf[i] << endl; -#endif - - - - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&status_mutex); - writerthreads_mask^=(1<fnum); + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); if(numWriterThreads == 1) currframenum = tempframenum; @@ -1784,136 +1755,58 @@ int slsReceiverUDPFunctions::startWriting(){ pthread_mutex_unlock(&progress_mutex); } #ifdef VERYDEBUG - cout << endl <num2)&0xff)<<"\t\t"< 0){ - for(i=0;i 0){ - cout<<"numpackets:"<push(wbuf[i])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]<findNextFrame(data,ndata,remainingsize)){ - np = ndata/onePacketSize; - - //cout<<"buff framnum:"<> frameIndexOffset)< 0){ + for(i=0;inewFrame(); - //only for moench - if(commonModeSubtractionEnable){ - for(ix = xmin - 1; ix < xmax+1; ix++){ - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); - } + if(myDetectorType == EIGER) { + //last packet + if((packetsPerThread-1)==(htonl(*(uint32_t*)((eiger_packet_header *)((uint32_t*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS)))->num2)&0xff)){ + copyFrameToGui(wbuf,currframenum); + for(j=0;jpush(wbuf[j+i])); } } - - - for(ix = xmin - 1; ix < xmax+1; ix++) - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); - if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - if (thisEvent==PHOTON_MAX) { - - iFrame=receiverdata[ithread]->getFrameNumber(buff); -#ifdef MYROOT1 - myTree[ithread]->Fill(); - //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; -#else - pthread_mutex_lock(&write_mutex); - if((enableFileWrite) && (sfilefd)) - singlePhotonDet[ithread]->writeCluster(sfilefd); - pthread_mutex_unlock(&write_mutex); + w_index = 0; + }else + w_index+=numListeningThreads; + } + else{ + //copy to gui + copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYVERBOSE + cout << ithread << " finished copying" << endl; #endif - } - } - } - - nf++; -#ifndef ALLFILE - pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; - packetsCaught += packetsPerFrame; - totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= maxPacketsPerFile) - createNewFile(); - pthread_mutex_unlock(&progress_mutex); - + while(!fifoFree[0]->push(wbuf[0])); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuf[0]< (wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS + numpackets * onePacketSize) ) - cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuf[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]< 0){ pc = (rc/onePacketSize); #ifdef VERYDEBUG - cout << ithread << " *** last packetcount:" << packetcount << endl; + cout << ithread << " *** last packetcount:" << pc << endl; #endif (*((uint16_t*)(buffer[ithread]))) = pc; totalListeningFrameCount[ithread] += pc; @@ -2031,6 +1924,9 @@ int i; for(i=0;ipop(buffer[ithread]); (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; +#ifdef VERYDEBUG + cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; +#endif while(!fifo[ithread]->push(buffer[ithread])); #ifdef VERYDEBUG cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; @@ -2046,7 +1942,7 @@ int i; pthread_mutex_unlock(&(status_mutex)); #ifdef VERYDEBUG - cout << ithread << ": Frames listened to " << ((totalListeningFrameCount[ithread]/packetsPerFrame)/numListeningThreads) << endl; + cout << ithread << ": Frames listened to " << dec << ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame) << endl; #endif //waiting for all listening threads to be done, to print final count of frames listened to @@ -2061,7 +1957,7 @@ int i; t = 0; for(i=0;ipush(wbuffer[wIndex+j])); +#ifdef VERYDEBUG + cout << ithread << " fifo freed:" << (void*)wbuffer[wIndex+j] << endl; +#endif + } + + + //all threads need to close file, reset mask and exit loop + closeFile(ithread); + pthread_mutex_lock(&status_mutex); + writerthreads_mask^=(1< 1) pthread_mutex_unlock(&write_mutex); } +} + + + + + + + + + + + + + + +void slsReceiverUDPFunctions::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ + +#if defined(MYROOT1) && defined(ALLFILE_DEBUG) + writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); +#endif + + eventType thisEvent = PEDESTAL; + int ndata; + char* buff = 0; + data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; + int remainingsize = npackets * onePacketSize; + int np; + int once = 0; + double tot, tl, tr, bl, br; + int xmin = 1, ymin = 1, ix, iy; + + + while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ + np = ndata/onePacketSize; + + //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); + + //only for moench + if(commonModeSubtractionEnable){ + for(ix = xmin - 1; ix < xmax+1; ix++){ + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); + } + } + } + for(ix = xmin - 1; ix < xmax+1; ix++) + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); + if (nf>1000) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + if (thisEvent==PHOTON_MAX) { + receiverdata[ithread]->getFrameNumber(buff); + //iFrame=receiverdata[ithread]->getFrameNumber(buff); +#ifdef MYROOT1 + myTree[ithread]->Fill(); + //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; +#else + pthread_mutex_lock(&write_mutex); + if((enableFileWrite) && (sfilefd)) + singlePhotonDet[ithread]->writeCluster(sfilefd); + pthread_mutex_unlock(&write_mutex); +#endif + } + } + } + + nf++; +#ifndef ALLFILE + pthread_mutex_lock(&progress_mutex); + packetsInFile += packetsPerFrame; + packetsCaught += packetsPerFrame; + totalPacketsCaught += packetsPerFrame; + if(packetsInFile >= maxPacketsPerFile) + createNewFile(); + pthread_mutex_unlock(&progress_mutex); + +#endif + if(!once){ + copyFrameToGui(NULL,-1,buff); + once = 1; + } + } + + remainingsize -= ((buff + ndata) - data); + data = buff + ndata; + if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) + cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuffer[0]< Date: Wed, 2 Jul 2014 10:51:13 +0200 Subject: [PATCH 010/222] eiger receiver, receiving many packets at a time, with 16,8, 4 bitmode sort of working --- .../MySocketTCP/genericSocket.h | 3 +- slsReceiverSoftware/includes/circularFifo.h | 112 +-------- slsReceiverSoftware/includes/receiver_defs.h | 17 +- .../includes/sls_receiver_funcs.h | 4 +- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 169 +++++++++++--- .../slsReceiver/slsReceiverTCPIPInterface.h | 5 + .../slsReceiver/slsReceiverUDPFunctions.cpp | 212 ++++++++++-------- .../slsReceiver/slsReceiverUDPFunctions.h | 5 +- 8 files changed, 284 insertions(+), 243 deletions(-) diff --git a/slsReceiverSoftware/MySocketTCP/genericSocket.h b/slsReceiverSoftware/MySocketTCP/genericSocket.h index 59126cf671..bb899f35b6 100644 --- a/slsReceiverSoftware/MySocketTCP/genericSocket.h +++ b/slsReceiverSoftware/MySocketTCP/genericSocket.h @@ -570,10 +570,9 @@ enum communicationProtocol{ } //listens to only 1 packet else{ + //normal nsending=packet_size; nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); - if(!nsent) break; - length-=nsent; total_sent+=nsent; } break; diff --git a/slsReceiverSoftware/includes/circularFifo.h b/slsReceiverSoftware/includes/circularFifo.h index 8eaa133828..6f779aafce 100644 --- a/slsReceiverSoftware/includes/circularFifo.h +++ b/slsReceiverSoftware/includes/circularFifo.h @@ -38,7 +38,9 @@ class CircularFifo { array.resize(Capacity); sem_init(&free_mutex,0,0); } - virtual ~CircularFifo() {} + virtual ~CircularFifo() { + sem_destroy(&free_mutex); + } bool push(Element*& item_); bool pop(Element*& item_); @@ -151,111 +153,3 @@ unsigned int CircularFifo::increment(unsigned int idx_) const } #endif /* CIRCULARFIFO_H_ */ - - - - - -/* -#ifndef CIRCULARFIFO_H_ -#define CIRCULARFIFO_H_ - -#include "sls_receiver_defs.h" - -#include "/usr/include/alsa/atomic.h" -#include -using namespace std; - -template -class CircularFifo { -public: - - CircularFifo(unsigned int Size) : tail(0), head(0){ - Capacity = Size + 1; - array.resize(Capacity); - } - virtual ~CircularFifo() {} - - bool push(Element*& item_); - bool pop(Element*& item_); - - bool wasEmpty() const; - bool wasFull() const; - bool isLockFree() const; - -private: - vector array; - unsigned int Capacity; - - std::atomic tail; // input index - std::atomic head; // output index - - unsigned int increment(unsigned int idx_) const; -}; - - -template -bool CircularFifo::push(Element*& item_) -{ - auto currentTail = tail.load(); - auto nextTail = increment(currentTail); - if(nextTail != head.load()) - { - array[currentTail] = item_; - tail.store(nextTail); - return true; - } - - // queue was full - return false; -} - - -template -bool CircularFifo::pop(Element*& item_) -{ - const auto currentHead = head.load(); - if(currentHead == tail.load()) - return false; // empty queue - - item_ = array[currentHead]; - head.store(increment(currentHead)); - return true; -} - - -template -bool CircularFifo::wasEmpty() const -{ - return (head.load() == tail.load()); -} - - -template -bool CircularFifo::wasFull() const -{ - const auto nextTail = increment(tail.load()); - return (nextTail == head.load()); -} - -template -bool CircularFifo::isLockFree() const -{ - return (tail.is_lock_free() && head.is_lock_free()); -} - - -template -unsigned int CircularFifo::increment(unsigned int idx_) const -{ - // increment or wrap - // ================= - // index++; - // if(index == array.lenght) -> index = 0; - // - //or as written below: - // index = (index+1) % array.length - return (idx_ + 1) % Capacity; -} - -#endif */ diff --git a/slsReceiverSoftware/includes/receiver_defs.h b/slsReceiverSoftware/includes/receiver_defs.h index 0df2113b3e..2ffd4500da 100755 --- a/slsReceiverSoftware/includes/receiver_defs.h +++ b/slsReceiverSoftware/includes/receiver_defs.h @@ -69,21 +69,24 @@ -#define MAX_EIGER_PORTS 2 +#define EIGER_MAX_PORTS 2 #define EIGER_HEADER_LENGTH 48 -#define EIGER_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 +#define EIGER_FIFO_SIZE 250 //cannot be less than max jobs per thread = 1000 /*#define EIGER_ALIGNED_FRAME_SIZE 65536*/ -#define EIGER_PACKETS_PER_FRAME (256*MAX_EIGER_PORTS) //default for 16B -#define EIGER_ONE_PACKET_SIZE 1040 //default for 16B -#define EIGER_BUFFER_SIZE (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME) //1040*256//default for 16B -#define EIGER_DATA_BYTES (1024*EIGER_PACKETS_PER_FRAME) //1024*256 //default for 16B +#define EIGER_PACKETS_PER_FRAME_COSTANT (16*EIGER_MAX_PORTS)//*bit mode 4*16=64, 8*16=128, 16*16=256, 32*16=512 +#define EIGER_ONE_PACKET_SIZE 1040 +#define EIGER_ONE_DATA_SIZE 1024 +#define EIGER_BUFFER_SIZE_CONSTANT (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT)//1040*16*2//*bit mode +#define EIGER_DATA_BYTES_CONSTANT (EIGER_ONE_DATA_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT) //1024*16*2//*bit mode #define EIGER_FRAME_INDEX_MASK 0xFFFF #define EIGER_FRAME_INDEX_OFFSET 0 #define EIGER_PACKET_INDEX_MASK 0x0 -#define EIGER_IMAGE_HEADER_SIZE 32 +#define EIGER_IMAGE_HEADER_SIZE 48 + +#define EIGER_PIXELS_IN_ONE_ROW (256*4) diff --git a/slsReceiverSoftware/includes/sls_receiver_funcs.h b/slsReceiverSoftware/includes/sls_receiver_funcs.h index 298eb39b10..bb7655481b 100644 --- a/slsReceiverSoftware/includes/sls_receiver_funcs.h +++ b/slsReceiverSoftware/includes/sls_receiver_funcs.h @@ -46,7 +46,9 @@ enum { F_RESET_RECEIVER_FRAMES_CAUGHT, /**< resets the frames caught by receiver */ F_ENABLE_RECEIVER_FILE_WRITE, /**< sets the receiver file write */ F_ENABLE_RECEIVER_COMPRESSION, /**< enable compression in receiver */ - F_ENABLE_RECEIVER_OVERWRITE /**< set overwrite flag in receiver */ + F_ENABLE_RECEIVER_OVERWRITE, /**< set overwrite flag in receiver */ + + F_ENABLE_RECEIVER_TEN_GIGA /**< enable 10Gbe in receiver */ /* Always append functions hereafter!!! */ }; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index 19f74baa8c..bbd1dc094d 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -34,6 +34,7 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int lockStatus(0), shortFrame(-1), packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), + dynamicrange(16), socket(NULL), killTCPServerThread(0){ @@ -1347,37 +1348,23 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ int arg = -1,i; uint32_t index=0; - int bufferSize = EIGER_BUFFER_SIZE; - int onebuffersize = EIGER_BUFFER_SIZE/EIGER_PACKETS_PER_FRAME; - int onedatasize = EIGER_DATA_BYTES/EIGER_PACKETS_PER_FRAME; - int numpackets = EIGER_PACKETS_PER_FRAME; - + int bufferSize = EIGER_BUFFER_SIZE_CONSTANT * dynamicrange; char* raw = new char[bufferSize]; char* origVal = new char[bufferSize]; - char* retval = new char[EIGER_DATA_BYTES]; - - /* - //retval is a full frame - int rnel = bufferSize/(sizeof(int)); - int* retval = new int[rnel]; - int* origVal = new int[rnel]; - //all initialized to 0 - for(i=0;inum2)&0xff)<<"\t\t"; - memcpy(retval+retindex ,origVal+copyindex ,onedatasize); - copyindex += 16+onedatasize; - retindex += onedatasize; + //cout <<"linesperpacket:" <num2)&0xff)<<"\t\t"; + memcpy(retval+retindex ,origVal+c1 ,EIGER_ONE_DATA_SIZE); + c1 += 16+EIGER_ONE_DATA_SIZE; + retindex += EIGER_ONE_DATA_SIZE; + + //cout<num2)&0xff)<differentClients){ cout << "Force update" << endl; @@ -1447,7 +1497,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ else{ socket->SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(&arg,sizeof(arg)); - socket->SendDataOnly(retval,EIGER_DATA_BYTES); + socket->SendDataOnly(retval,(EIGER_DATA_BYTES_CONSTANT*dynamicrange)); } delete [] retval; @@ -1799,8 +1849,24 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else + else if(myDetectorType == EIGER){ + switch(dr){ + case 4: + case 8: + case 16: + case 32:break; + default: + sprintf(mess,"This dynamic range does not exist for eiger: %d\n",dr); + ret=FAIL; + break; + } + } + if(ret!=FAIL){ retval=slsReceiverFunctions->setDynamicRange(dr); + dynamicrange = dr; + if(myDetectorType == EIGER) + packetsPerFrame = dr*EIGER_PACKETS_PER_FRAME_COSTANT; + } } #ifdef VERBOSE if(ret!=FAIL) @@ -1883,7 +1949,51 @@ int slsReceiverTCPIPInterface::enable_overwrite() { +int slsReceiverTCPIPInterface::enable_tengiga() { + ret=OK; + int retval=-1; + int val; + strcpy(mess,"Could not enable/disable 10Gbe\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&val,sizeof(val)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else + ;//retval=slsReceiverFunctions->enable10GbE(val); + } +#ifdef VERBOSE + if(ret!=FAIL) + cout << "10Gbe:" << val << endl; + else + cout << mess << endl; +#endif +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} @@ -2063,8 +2173,7 @@ int slsReceiverTCPIPInterface::send_update() { //index #ifdef SLS_RECEIVER_UDP_FUNCTIONS - /*if(myDetectorType != EIGER)*/ - ind=slsReceiverFunctions->getFileIndex(); + ind=slsReceiverFunctions->getFileIndex(); socket->SendDataOnly(&ind,sizeof(ind)); #endif diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index 94126d59ff..63016e7d73 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -193,6 +193,8 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** enable overwrite */ int enable_overwrite(); + /** enable 10Gbe */ + int enable_tengiga(); //General Functions /** Locks Receiver */ @@ -246,6 +248,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** Packets per frame */ int packetsPerFrame; + /** Dynamic Range */ + int dynamicrange; + /** kill tcp server thread */ int killTCPServerThread; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index 470a41efb7..d659945ba5 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -143,7 +143,7 @@ void slsReceiverUDPFunctions::initializeMembers(){ frameIndexOffset = 0; acquisitionPeriod = SAMPLE_TIME_IN_NS; numberOfFrames = 0; - dynamicRange = 0; + dynamicRange = 16; shortFrame = -1; currframenum = 0; prevframenum = 0; @@ -262,11 +262,11 @@ int slsReceiverUDPFunctions::setDetectorType(detectorType det){ #ifndef EIGERSLS cout << "SLS Eiger Receiver" << endl; fifosize = EIGER_FIFO_SIZE; - packetsPerFrame = EIGER_PACKETS_PER_FRAME; + packetsPerFrame = EIGER_PACKETS_PER_FRAME_COSTANT * dynamicRange; onePacketSize = EIGER_ONE_PACKET_SIZE; - frameSize = EIGER_BUFFER_SIZE; - bufferSize = EIGER_ONE_PACKET_SIZE; // because if you listen to a whole frame on one port, it will be interleaved - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * EIGER_PACKETS_PER_FRAME; + frameSize = EIGER_BUFFER_SIZE_CONSTANT * dynamicRange; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//for only one port + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; frameIndexMask = EIGER_FRAME_INDEX_MASK; frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; packetIndexMask = EIGER_PACKET_INDEX_MASK; @@ -522,11 +522,52 @@ int32_t slsReceiverUDPFunctions::setScanTag(int32_t stag){ } int32_t slsReceiverUDPFunctions::setDynamicRange(int32_t dr){ + cout << "Setting Dynamic Range" << endl; + + int olddr = dynamicRange; if(dr >= 0){ if(receiver != NULL) receiver->setDynamicRange(dr); - else + else{ dynamicRange = dr; + packetsPerFrame = EIGER_PACKETS_PER_FRAME_COSTANT * dynamicRange; + frameSize = EIGER_BUFFER_SIZE_CONSTANT * dynamicRange; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//for only one port + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + + if(olddr != dr){ + + //del + if(thread_started){ + createListeningThreads(true); + createWriterThreads(true); + } + for(int i=0;inum2)&0xff)<<"\t\t"; + int offset = 0; + int size = frameSize/EIGER_MAX_PORTS; + for(int j=0;jReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); - //if it was the header - if(rc == EIGER_HEADER_LENGTH){ -#ifdef VERYDEBUG - cout << "rc for header2:" << dec << rc << endl; -#endif - expected = EIGER_HEADER_LENGTH; - }else{ - expected = maxBufferSize; - } - } - //not eiger - else{ - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - expected = maxBufferSize; - } + + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + expected = maxBufferSize; + } //the remaining packets from previous buffer else{ @@ -1536,10 +1571,17 @@ int slsReceiverUDPFunctions::startListening(){ } #ifdef VERYDEBUG - cout << ithread << " *** rc:" << dec << rc << endl; - cout << ithread << " *** expected:" << dec << expected << endl; + cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; #endif +/* + if(ithread){ + for(int j=25;j<27;++j) + for(int i=1000;i<1010;i=i+2) + //cout<<"startbuf:"<pop(wbuf[w_index+i]); - numpackets = (uint16_t)(*((uint16_t*)wbuf[w_index])); + fifo[i]->pop(wbuf[i]); + numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); #ifdef VERYDEBUG - if((!w_index)||(!numpackets)) cout << ithread << " numpackets:" << dec << numpackets << endl; + cout << ithread << " numpackets:" << dec << numpackets << endl; #endif } #ifdef VERYDEBUG cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[w_index]<< endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[w_index+1]<< endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; #endif - - //last dummy packet if(numpackets == 0xFFFF){ - stopWriting(ithread,wbuf,w_index); + stopWriting(ithread,wbuf); continue; } - //for progress if(myDetectorType == EIGER){ - if(!numpackets) - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[w_index] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); if(numWriterThreads == 1) currframenum = tempframenum; @@ -1754,12 +1791,9 @@ int slsReceiverUDPFunctions::startWriting(){ currframenum = tempframenum; pthread_mutex_unlock(&progress_mutex); } -#ifdef VERYDEBUG - if(!numpackets) cout << endl < 0){ for(i=0;inum2)&0xff)){ - copyFrameToGui(wbuf,currframenum); - for(j=0;jpush(wbuf[j+i])); - } - } - w_index = 0; - }else - w_index+=numListeningThreads; + copyFrameToGui(wbuf,currframenum); + for(i=0;ipush(wbuf[i])); +#ifdef VERYDEBUG + cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; +#endif + } + + } else{ //copy to gui @@ -1972,20 +2004,20 @@ int i; -void slsReceiverUDPFunctions::stopWriting(int ithread, char* wbuffer[], int wIndex){ +void slsReceiverUDPFunctions::stopWriting(int ithread, char* wbuffer[]){ int i,j; #ifdef VERYDEBUG cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl; #endif //free fifo - for(i=0;ipush(wbuffer[wIndex+j])); + for(i=0;ipush(wbuffer[i])); #ifdef VERYDEBUG - cout << ithread << " fifo freed:" << (void*)wbuffer[wIndex+j] << endl; + cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; #endif - } + } + //all threads need to close file, reset mask and exit loop @@ -2047,13 +2079,13 @@ void slsReceiverUDPFunctions::writeToFile_withoutCompression(char* buf,int numpa if((enableFileWrite) && (sfilefd)){ offset = HEADER_SIZE_NUM_TOT_PACKETS; + if(myDetectorType == EIGER) + offset += EIGER_HEADER_LENGTH; while(numpackets > 0){ //for progress and packet loss calculation(new files) - if(myDetectorType == EIGER){ - if(((uint16_t)(*((uint16_t*)buf)))==0) - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buf + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + if(myDetectorType == EIGER); + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); @@ -2077,7 +2109,7 @@ void slsReceiverUDPFunctions::writeToFile_withoutCompression(char* buf,int numpa packetsToSave = maxPacketsPerFile - packetsInFile; if(packetsToSave > numpackets) packetsToSave = numpackets; - +/**next time offset is still plus header length*/ fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); packetsInFile += packetsToSave; packetsCaught += packetsToSave; @@ -2088,10 +2120,8 @@ void slsReceiverUDPFunctions::writeToFile_withoutCompression(char* buf,int numpa if(packetsInFile >= maxPacketsPerFile){ //for packet loss lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER){ - if(((uint16_t)(*((uint16_t*)buf)))==0) - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buf + lastpacket)))->fnum); - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + if(myDetectorType == EIGER); + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); else tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h index 43319ecd00..6cafcfcfff 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h @@ -397,9 +397,8 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { * When acquisition is over, this is called * @param ithread listening thread number * @param wbuffer writer buffer - * @param wIndex writer Index */ - void stopWriting(int ithread, char* wbuffer[], int wIndex); + void stopWriting(int ithread, char* wbuffer[]); /** @@ -432,7 +431,7 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { } eiger_packet_header; /** max number of listening threads */ - const static int MAX_NUM_LISTENING_THREADS = MAX_EIGER_PORTS; + const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; /** max number of writer threads */ const static int MAX_NUM_WRITER_THREADS = 15; From bbb0a05fca7fe888e1d734a37107aa51d636467c Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Fri, 11 Jul 2014 12:53:53 +0200 Subject: [PATCH 011/222] incorporating ten giga into the receiver --- slsReceiverSoftware/includes/receiver_defs.h | 16 +- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 132 +++++++------ .../slsReceiver/slsReceiverTCPIPInterface.h | 3 + .../slsReceiver/slsReceiverUDPFunctions.cpp | 187 +++++++++++++----- .../slsReceiver/slsReceiverUDPFunctions.h | 15 +- 5 files changed, 226 insertions(+), 127 deletions(-) diff --git a/slsReceiverSoftware/includes/receiver_defs.h b/slsReceiverSoftware/includes/receiver_defs.h index 2ffd4500da..4b0d10161b 100755 --- a/slsReceiverSoftware/includes/receiver_defs.h +++ b/slsReceiverSoftware/includes/receiver_defs.h @@ -74,11 +74,15 @@ #define EIGER_FIFO_SIZE 250 //cannot be less than max jobs per thread = 1000 /*#define EIGER_ALIGNED_FRAME_SIZE 65536*/ -#define EIGER_PACKETS_PER_FRAME_COSTANT (16*EIGER_MAX_PORTS)//*bit mode 4*16=64, 8*16=128, 16*16=256, 32*16=512 -#define EIGER_ONE_PACKET_SIZE 1040 -#define EIGER_ONE_DATA_SIZE 1024 -#define EIGER_BUFFER_SIZE_CONSTANT (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT)//1040*16*2//*bit mode -#define EIGER_DATA_BYTES_CONSTANT (EIGER_ONE_DATA_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT) //1024*16*2//*bit mode +#define EIGER_ONE_GIGA_CONSTANT 16 +#define EIGER_TEN_GIGA_CONSTANT 4 +//#define EIGER_PACKETS_PER_FRAME_COSTANT (16*EIGER_MAX_PORTS)//*bit mode 4*16=64, 8*16=128, 16*16=256, 32*16=512 +#define EIGER_ONE_GIGA_ONE_PACKET_SIZE 1040 +#define EIGER_ONE_GIGA_ONE_DATA_SIZE 1024 +#define EIGER_TEN_GIGA_ONE_PACKET_SIZE 4112 +#define EIGER_TEN_GIGA_ONE_DATA_SIZE 4096 +//#define EIGER_BUFFER_SIZE_CONSTANT (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT)//1040*16*2//*bit mode +//#define EIGER_DATA_BYTES_CONSTANT (EIGER_ONE_DATA_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT) //1024*16*2//*bit mode #define EIGER_FRAME_INDEX_MASK 0xFFFF #define EIGER_FRAME_INDEX_OFFSET 0 @@ -87,7 +91,7 @@ #define EIGER_IMAGE_HEADER_SIZE 48 #define EIGER_PIXELS_IN_ONE_ROW (256*4) - +#define EIGER_PIXELS_IN_ONE_COL (256) #endif diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index bbd1dc094d..7039878223 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -36,7 +36,8 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), dynamicrange(16), socket(NULL), - killTCPServerThread(0){ + killTCPServerThread(0), + tenGigaEnable(0){ int port_no = DEFAULT_PORTNO+2; ifstream infile; @@ -316,6 +317,9 @@ int slsReceiverTCPIPInterface::function_table(){ flist[F_ENABLE_RECEIVER_COMPRESSION] = &slsReceiverTCPIPInterface::enable_compression; flist[F_ENABLE_RECEIVER_OVERWRITE] = &slsReceiverTCPIPInterface::enable_overwrite; + flist[F_ENABLE_RECEIVER_TEN_GIGA] = &slsReceiverTCPIPInterface::enable_tengiga; + + #ifdef VERBOSE for (int i=0;inum2)&0xff)<<"\t\t"; - memcpy(retval+retindex ,origVal+c1 ,EIGER_ONE_DATA_SIZE); - c1 += 16+EIGER_ONE_DATA_SIZE; - retindex += EIGER_ONE_DATA_SIZE; - - //cout<num2)&0xff)<> 8) & 0x00FF00FF00FF00FFULL ); + temp = ((temp << 16) & 0xFFFF0000FFFF0000ULL ) | ((temp >> 16) & 0x0000FFFF0000FFFFULL ); + temp = (temp << 32) | ((temp >> 32) & 0xFFFFFFFFULL); + (*(((uint64_t*)retval)+i)) = temp; } - -*/ - - - for(i=0;i<(1024*(16*dynamicrange)*2)/4;i++) - (*((uint32_t*)retval+i)) = htonl((uint32_t)(*((uint32_t*)retval+i))); - +/* + ( (((val) >> 56) & 0x00000000000000FF) | (((val) >> 40) & 0x000000000000FF00) | \ + (((val) >> 24) & 0x0000000000FF0000) | (((val) >> 8) & 0x00000000FF000000) | \ + (((val) << 8) & 0x000000FF00000000) | (((val) << 24) & 0x0000FF0000000000) | \ + (((val) << 40) & 0x00FF000000000000) | (((val) << 56) & 0xFF00000000000000) ) + */ /* - for(int j=25;j<27;++j) - for(int i=1000;i<1010;i=i+2) - //cout<<"retval:"<differentClients){ cout << "Force update" << endl; @@ -1497,7 +1489,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ else{ socket->SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(&arg,sizeof(arg)); - socket->SendDataOnly(retval,(EIGER_DATA_BYTES_CONSTANT*dynamicrange)); + socket->SendDataOnly(retval,dataSize); } delete [] retval; @@ -1508,6 +1500,11 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ } + + + + + int slsReceiverTCPIPInterface::set_read_frequency(){ ret=OK; int retval=-1; @@ -1864,8 +1861,12 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { if(ret!=FAIL){ retval=slsReceiverFunctions->setDynamicRange(dr); dynamicrange = dr; - if(myDetectorType == EIGER) - packetsPerFrame = dr*EIGER_PACKETS_PER_FRAME_COSTANT; + if(myDetectorType == EIGER){ + if(!tenGigaEnable) + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + else + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + } } } #ifdef VERBOSE @@ -1969,8 +1970,13 @@ int slsReceiverTCPIPInterface::enable_tengiga() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else - ;//retval=slsReceiverFunctions->enable10GbE(val); + else{ + retval=slsReceiverFunctions->enableTenGiga(val); + if((val!=-1) && (val != retval)) + ret = FAIL; + else + tenGigaEnable = retval; + } } #ifdef VERBOSE if(ret!=FAIL) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index 63016e7d73..bddce2bd89 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -257,6 +257,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** thread for TCP server */ pthread_t TCPServer_thread; + /** size of one frame*/ + int tenGigaEnable; + protected: /** Socket */ MySocketTCP* socket; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index d659945ba5..382fae74e8 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -1,4 +1,4 @@ -#ifdef SLS_RECEIVER_UDP_FUNCTIONS +//#ifdef SLS_RECEIVER_UDP_FUNCTIONS /********************************************//** * @file slsReceiverUDPFunctions.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -35,7 +35,8 @@ slsReceiverUDPFunctions::slsReceiverUDPFunctions(): eth(NULL), latestData(NULL), guiFileName(NULL), - guiFrameNumber(0){ + guiFrameNumber(0), + tengigaEnable(0){ for(int i=0;isetDynamicRange(dr); else{ dynamicRange = dr; - packetsPerFrame = EIGER_PACKETS_PER_FRAME_COSTANT * dynamicRange; - frameSize = EIGER_BUFFER_SIZE_CONSTANT * dynamicRange; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//for only one port - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - if(olddr != dr){ + if(myDetectorType == EIGER){ - //del - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - for(int i=0;ifnum)<push(buffer[ithread]); @@ -1960,37 +1965,37 @@ int i; cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; #endif while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -#endif +//#endif } //reset mask and exit loop pthread_mutex_lock(&status_mutex); listeningthreads_mask^=(1< 1) cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; -#endif +//#endif while(listeningthreads_mask) usleep(5000); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG t = 0; for(i=0;i= 0){ + if(receiver != NULL) + ;/*receiver->setTenGigaBitEthernet(enable);*/ + else{ + tengigaEnable = enable; + if(myDetectorType == EIGER){ + if(!tengigaEnable){ + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + }else{ + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; + } + frameSize = onePacketSize * packetsPerFrame; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) + //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + cout<<"packetsPerFrame:"<getTenGigaBitEthernet();*/ + else + return tengigaEnable; + +} + + + + + + + + + + + + + +//#endif diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h index 6cafcfcfff..3cb1872cf5 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h @@ -1,4 +1,4 @@ -#ifdef SLS_RECEIVER_UDP_FUNCTIONS +//#ifdef SLS_RECEIVER_UDP_FUNCTIONS #ifndef SLS_RECEIVER_UDP_FUNCTIONS_H #define SLS_RECEIVER_UDP_FUNCTIONS_H /********************************************//** @@ -228,8 +228,12 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { */ int enableDataCompression(bool enable); - - + /** + * enable 10Gbe + @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out + \returns enable for 10Gbe + */ + int enableTenGiga(int enable = -1); @@ -631,6 +635,9 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { /** variable used to self terminate threads waiting for semaphores */ int killAllWritingThreads; + /** 10Gbe enable*/ + int tengigaEnable; + @@ -755,4 +762,4 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { #endif -#endif +//#endif From 4814fd56c17d97c8583fd04052ed71a03aeb89cf Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Wed, 16 Jul 2014 15:34:58 +0200 Subject: [PATCH 012/222] slsdetectorcalibration is a repository on its own --- .../slsDetectorCalibration/MovingStat.h | 130 ----- .../slsDetectorCalibration/RunningStat.h | 55 -- .../chiptestBoardData.h | 89 --- .../commonModeSubtraction.h | 82 --- .../slsDetectorCalibration/demoCreateTree.C | 31 -- .../slsDetectorCalibration/doxy.config | 85 --- .../energyCalibration.cpp | 527 ------------------ .../energyCalibration.h | 452 --------------- .../slsDetectorCalibration/gMapDemo.C | 11 - .../slsDetectorCalibration/gainMap.C | 228 -------- .../gotthardModuleData.h | 148 ----- .../gotthardShortModuleData.h | 127 ----- .../slsDetectorCalibration/jungfrau02Data.h | 156 ------ .../slsDetectorCalibration/jungfrauReadData.C | 264 --------- .../moench02ModuleData.h | 137 ----- .../slsDetectorCalibration/moenchCommonMode.h | 45 -- .../slsDetectorCalibration/moenchMakeTree.C | 244 -------- .../slsDetectorCalibration/moenchReadData.C | 236 -------- .../slsDetectorCalibration/moenchReadDataMT.C | 52 -- .../pedestalSubtraction.h | 48 -- .../slsDetectorCalibration/raedNoiseData.C | 136 ----- .../slsDetectorCalibration/readJungfrauData.C | 31 -- .../singlePhotonDetector.h | 387 ------------- .../single_photon_hit.h | 62 --- .../slsDetectorCalibration/slsDetectorData.h | 251 --------- .../slsDetectorCalibration/slsReceiverData.h | 171 ------ 26 files changed, 4185 deletions(-) delete mode 100755 slsReceiverSoftware/slsDetectorCalibration/MovingStat.h delete mode 100755 slsReceiverSoftware/slsDetectorCalibration/RunningStat.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/chiptestBoardData.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/commonModeSubtraction.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/demoCreateTree.C delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/doxy.config delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/energyCalibration.cpp delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/energyCalibration.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/gMapDemo.C delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/gainMap.C delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/gotthardModuleData.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/gotthardShortModuleData.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/jungfrau02Data.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/jungfrauReadData.C delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/moench02ModuleData.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/moenchCommonMode.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/moenchMakeTree.C delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/moenchReadData.C delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/moenchReadDataMT.C delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/pedestalSubtraction.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/raedNoiseData.C delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/readJungfrauData.C delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/singlePhotonDetector.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/single_photon_hit.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/slsDetectorData.h delete mode 100644 slsReceiverSoftware/slsDetectorCalibration/slsReceiverData.h diff --git a/slsReceiverSoftware/slsDetectorCalibration/MovingStat.h b/slsReceiverSoftware/slsDetectorCalibration/MovingStat.h deleted file mode 100755 index 9d3720b1b8..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/MovingStat.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef MOVINGSTAT_H -#define MOVINGSTAT_H - -#include - - -class MovingStat - { - - /** @short approximated moving average structure */ - public: - - - /** constructor - \param nn number of samples parameter to be used - */ - MovingStat(int nn=1000) : n(nn), m_n(0) {} - - /** - clears the moving average number of samples parameter, mean and standard deviation - */ - void Clear() - { - m_n = 0; - m_newM=0; - m_newM2=0; - } - - - /** sets number of samples parameter - \param i number of samples parameter to be set - */ - - void SetN(int i) {if (i>=1) n=i;}; - - /** - gets number of samples parameter - \returns actual number of samples parameter - */ - int GetN() {return n;}; - - /** calculates the moving average i.e. adds if number of elements is lower than number of samples parameter, pushes otherwise - \param x value to calculate the moving average - */ - inline void Calc(double x) { - if (m_n 0) ? m_newM/m_n : 0.0; - } - - /** returns the squared mean, 0 if no elements are inside - \returns returns the squared average - */ - double M2() const - { - return ( (m_n > 1) ? m_newM2/m_n : 0.0 ); - } - - /** returns the variance, 0 if no elements are inside - \returns returns the variance - */ - inline double Variance() const - { - return ( (m_n > 1) ? (M2()-Mean()*Mean()) : 0.0 ); - } - - /** returns the standard deviation, 0 if no elements are inside - \returns returns the standard deviation - */ - inline double StandardDeviation() const - { - return ( (Variance() > 0) ? sqrt( Variance() ) : -1 ); - } - - private: - int n; /**< number of samples parameter */ - int m_n; /**< current number of elements */ - double m_newM; /**< accumulated average */ - double m_newM2; /**< accumulated squared average */ - }; -#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/RunningStat.h b/slsReceiverSoftware/slsDetectorCalibration/RunningStat.h deleted file mode 100755 index 1197ffc0fa..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/RunningStat.h +++ /dev/null @@ -1,55 +0,0 @@ - class RunningStat - { - public: - RunningStat() : m_n(0) {} - - void Clear() - { - m_n = 0; - } - - void Push(double x) - { - m_n++; - - // See Knuth TAOCP vol 2, 3rd edition, page 232 - if (m_n == 1) - { - m_oldM = m_newM = x; - m_oldS = 0.0; - } - else - { - m_newM = m_oldM + (x - m_oldM)/m_n; - m_newS = m_oldS + (x - m_oldM)*(x - m_newM); - - // set up for next iteration - m_oldM = m_newM; - m_oldS = m_newS; - } - } - - int NumDataValues() const - { - return m_n; - } - - double Mean() const - { - return (m_n > 0) ? m_newM : 0.0; - } - - double Variance() const - { - return ( (m_n > 1) ? m_newS/(m_n - 1) : 0.0 ); - } - - double StandardDeviation() const - { - return sqrt( Variance() ); - } - - private: - int m_n; - double m_oldM, m_newM, m_oldS, m_newS; - }; diff --git a/slsReceiverSoftware/slsDetectorCalibration/chiptestBoardData.h b/slsReceiverSoftware/slsDetectorCalibration/chiptestBoardData.h deleted file mode 100644 index 0ef633c44c..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/chiptestBoardData.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef CHIPTESTDATA_H -#define CHIPTESTDATA_H - -#include "slsDetectorData.h" - -class chiptestBoardData : public slsDetectorData { - - - public: - - /** - chiptestBoard data structure. Works for data acquired using the chiptestBoard. - Inherits and implements slsDetectorData. - - Constructor (no error checking if datasize and offsets are compatible!) - \param npx number of pixels in the x direction - \param npy number of pixels in the y direction (1 for strips) - \param nadc number of adcs - \param offset offset at the beginning of the pattern - \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) - \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) - \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. - - */ - chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; // should be? nadc*(npx*npy+offset) - - - - /** - - Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. - \param buff pointer to the dataset - \returns frame number - - */ - - virtual int getFrameNumber(char *buff){(void)buff; return iframe;}; - - - /** - - Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! - \param data pointer to the memory to be analyzed - \param ndata size of frame returned - \param dsize size of the memory slot to be analyzed - \returns always return the pointer to data (no frame loss!) - */ - - virtual char *findNextFrame(char *data, int &ndata, int dsize) {ndata=dsize;setDataSize(dsize); return data;}; - - /** - Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! - \param filebin input file stream (binary) - \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete - */ - - virtual char *readNextFrame(ifstream &filebin) { - - int afifo_length=0; - uint16_t *afifo_cont; - - if (filebin.is_open()) { - if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) { - setDataSize(afifo_length*nAdc*sizeof(uint16_t)); - afifo_cont=new uint16_t[afifo_length*nAdc]; - if (filebin.read((char*)afifo_cont,afifo_length*sizeof(uint16_t)*nAdc)) { - iframe++; - return (char*)afifo_cont; - } else { - delete [] afifo_cont; - return NULL; - } - } else { - return NULL; - } - } - return NULL; - }; - - private: - const int nAdc; /**0) cmStat[i].Calc(cmPed[i]/nCm[i]); - nCm[i]=0; - cmPed[i]=0; - }}; - - /** adds the pixel to the sum of pedestals -- virtual func must be overloaded to define the regions of interest - \param val value to add - \param ix pixel x coordinate - \param iy pixel y coordinate - */ - virtual void addToCommonMode(double val, int ix=0, int iy=0) { - (void) ix; (void) iy; - - //if (isc>=0 && isc0) return cmPed[0]/nCm[0]-cmStat[0].Mean(); - return 0;}; - - - - - - protected: - MovingStat *cmStat; /**SetName("cds_g4"); - hs2N->SetTitle("cds_g4"); - (TH2F*)(hs2N->GetHists()->At(0))->Write(); - - (TH2F*)(hs2N->GetHists()->At(1))->Write(); - (TH2F*)(hs2N->GetHists()->At(2))->Write(); - (TH2F*)(hs2N->GetHists()->At(3))->Write(); - (TH2F*)(hs2N->GetHists()->At(4))->Write(); - - - fout->Close(); - - - -} - diff --git a/slsReceiverSoftware/slsDetectorCalibration/doxy.config b/slsReceiverSoftware/slsDetectorCalibration/doxy.config deleted file mode 100644 index 7d2a396ff4..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/doxy.config +++ /dev/null @@ -1,85 +0,0 @@ -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES - -EXTRACT_ALL = YES - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. - -EXTRACT_PRIVATE = NO - - - -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. - -EXTRACT_STATIC = YES - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. - -EXTRACT_LOCAL_METHODS = YES - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base -# name of the file that contains the anonymous namespace. By default -# anonymous namespace are hidden. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. - -HIDE_FRIEND_COMPOUNDS = NO - -INTERNAL_DOCS = NO - -SHOW_INCLUDE_FILES = NO - -SHOW_FILES = NO - -SHOW_NAMESPACES = NO - -COMPACT_LATEX = YES - -PAPER_TYPE = a4 - -PDF_HYPERLINKS = YES - -USE_PDFLATEX = YES - -LATEX_HIDE_INDICES = YES - -PREDEFINED = __cplusplus - -INPUT = MovingStat.h slsDetectorData.h slsReceiverData.h moench02ModuleData.h pedestalSubtraction.h commonModeSubtraction.h moenchCommonMode.h singlePhotonDetector.h energyCalibration.h moenchReadData.C single_photon_hit.h chiptestBoardData.h jungfrau02Data.h jungfrauReadData.C jungfrau02CommonMode.h -OUTPUT_DIRECTORY = docs - diff --git a/slsReceiverSoftware/slsDetectorCalibration/energyCalibration.cpp b/slsReceiverSoftware/slsDetectorCalibration/energyCalibration.cpp deleted file mode 100644 index 6911220955..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/energyCalibration.cpp +++ /dev/null @@ -1,527 +0,0 @@ -#include "energyCalibration.h" - -#ifdef __CINT -#define MYROOT -#endif - - -#ifdef MYROOT -#include -#include -#include -#include -#endif - -#include - -#define max(a,b) ((a) > (b) ? (a) : (b)) -#define min(a,b) ((a) < (b) ? (a) : (b)) -#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; } - - -using namespace std; - -#ifdef MYROOT - -Double_t energyCalibrationFunctions::pedestal(Double_t *x, Double_t *par) { - return par[0]-par[1]*sign*x[0]; -} - - -Double_t energyCalibrationFunctions::gaussChargeSharing(Double_t *x, Double_t *par) { - Double_t f, arg=0; - if (par[3]!=0) arg=sign*(x[0]-par[2])/par[3]; - f=TMath::Exp(-1*arg*arg/2.); - f=f+par[5]/2.*(TMath::Erfc(arg/(TMath::Sqrt(2.)))); - return par[4]*f+pedestal(x,par); -} - -Double_t energyCalibrationFunctions::gaussChargeSharingPixel(Double_t *x, Double_t *par) { - Double_t f; - if (par[3]<=0 || par[2]*(*x)<=0 || par[5]<0 || par[4]<=0) return 0; - - Double_t pp[3]; - - pp[0]=0; - pp[1]=par[2]; - pp[2]=par[3]; - - - f=(par[5]-par[6]*(TMath::Log(*x/par[2])))*erfBox(x,pp); - f+=par[4]*TMath::Gaus(*x, par[2], par[3], kTRUE); - return f+pedestal(x,par); -} - -Double_t energyCalibrationFunctions::erfBox(Double_t *z, Double_t *par) { - - - - Double_t m=par[0]; - Double_t M=par[1]; - - if (par[0]>par[1]) { - m=par[1]; - M=par[0]; - } - - if (m==M) - return 0; - - - if (par[2]<=0) { - if (*z>=m && *z<=M) - return 1./(M-m); - else - return 0; - - } - - return (TMath::Erfc((z[0]-M)/par[2])-TMath::Erfc((z[0]-m)/par[2]))*0.5/(M-m); - -} - - -// basic erf function -Double_t energyCalibrationFunctions::erfFunction(Double_t *x, Double_t *par) { - double arg=0; - if (par[1]!=0) arg=(par[0]-x[0])/par[1]; - return ((par[2]/2.*(1+TMath::Erf(sign*arg/(TMath::Sqrt(2)))))); -}; - - -Double_t energyCalibrationFunctions::erfFunctionChargeSharing(Double_t *x, Double_t *par) { - Double_t f; - - f=erfFunction(x, par+2)*(1+par[5]*(par[2]-x[0]))+par[0]-par[1]*x[0]*sign; - return f; -}; - - -Double_t energyCalibrationFunctions::erfFuncFluo(Double_t *x, Double_t *par) { - Double_t f; - f=erfFunctionChargeSharing(x, par)+erfFunction(x, par+6)*(1+par[9]*(par[6]-x[0])); - return f; -}; -#endif - -double energyCalibrationFunctions::median(double *x, int n){ - // sorts x into xmed array and returns median - // n is number of values already in the xmed array - double xmed[n]; - int k,i,j; - - for (i=0; i*(x+j)) - k++; - if (*(x+i)==*(x+j)) { - if (i>j) - k++; - } - } - xmed[k]=*(x+i); - } - k=n/2; - return xmed[k]; -} - - -int energyCalibrationFunctions::quick_select(int arr[], int n){ - int low, high ; - int median; - int middle, ll, hh; - - low = 0 ; high = n-1 ; median = (low + high) / 2; - for (;;) { - if (high <= low) /* One element only */ - return arr[median] ; - - if (high == low + 1) { /* Two elements only */ - if (arr[low] > arr[high]) - ELEM_SWAP(arr[low], arr[high]) ; - return arr[median] ; - } - - /* Find median of low, middle and high items; swap into position low */ - middle = (low + high) / 2; - if (arr[middle] > arr[high]) ELEM_SWAP(arr[middle], arr[high]) ; - if (arr[low] > arr[high]) ELEM_SWAP(arr[low], arr[high]) ; - if (arr[middle] > arr[low]) ELEM_SWAP(arr[middle], arr[low]) ; - - /* Swap low item (now in position middle) into position (low+1) */ - ELEM_SWAP(arr[middle], arr[low+1]) ; - - /* Nibble from each end towards middle, swapping items when stuck */ - ll = low + 1; - hh = high; - for (;;) { - do ll++; while (arr[low] > arr[ll]) ; - do hh--; while (arr[hh] > arr[low]) ; - - if (hh < ll) - break; - - ELEM_SWAP(arr[ll], arr[hh]) ; - } - - /* Swap middle item (in position low) back into correct position */ - ELEM_SWAP(arr[low], arr[hh]) ; - - /* Re-set active partition */ - if (hh <= median) - low = ll; - if (hh >= median) - high = hh - 1; - } -} - -int energyCalibrationFunctions::kth_smallest(int *a, int n, int k){ - register int i,j,l,m ; - register double x ; - - l=0 ; m=n-1 ; - while (lSetParNames("Background Offset","Background Slope","Inflection Point","Noise RMS", "Number of Photons","Charge Sharing Slope"); - - fspectrum=new TF1("fspectrum",funcs,&energyCalibrationFunctions::spectrum,0,1000,6,"energyCalibrationFunctions","spectrum"); - fspectrum->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal"); - - fspixel=new TF1("fspixel",funcs,&energyCalibrationFunctions::spectrumPixel,0,1000,7,"energyCalibrationFunctions","spectrumPixel"); - fspixel->SetParNames("Background Pedestal","Background slope", "Peak position","Noise RMS", "Number of Photons","Charge Sharing Pedestal","Corner"); - -#endif - - -} - - - -void energyCalibration::fixParameter(int ip, Double_t val){ - - fscurve->FixParameter(ip, val); - fspectrum->FixParameter(ip, val); -} - - -void energyCalibration::releaseParameter(int ip){ - - fscurve->ReleaseParameter(ip); - fspectrum->ReleaseParameter(ip); -} - - - - - - - -energyCalibration::~energyCalibration(){ -#ifdef MYROOT - delete fscurve; - delete fspectrum; -#endif - -} - -#ifdef MYROOT - - - - - -TH1F* energyCalibration::createMedianHistogram(TH2F* h2, int ch0, int nch, int direction) { - - if (h2==NULL || nch==0) - return NULL; - - double *x=new double[nch]; - TH1F *h1=NULL; - - double val=-1; - - if (direction==0) { - h1=new TH1F("median","Median",h2->GetYaxis()->GetNbins(),h2->GetYaxis()->GetXmin(),h2->GetYaxis()->GetXmax()); - for (int ib=0; ibGetXaxis()->GetNbins(); ib++) { - for (int ich=0; ichGetBinContent(ch0+ich+1,ib+1); - } - val=energyCalibrationFunctions::median(x, nch); - h1->SetBinContent(ib+1,val); - } - } else if (direction==1) { - h1=new TH1F("median","Median",h2->GetXaxis()->GetNbins(),h2->GetXaxis()->GetXmin(),h2->GetXaxis()->GetXmax()); - for (int ib=0; ibGetYaxis()->GetNbins(); ib++) { - for (int ich=0; ichGetBinContent(ib+1,ch0+ich+1); - } - val=energyCalibrationFunctions::median(x, nch); - h1->SetBinContent(ib+1,val); - } - } - delete [] x; - - return h1; - -} - - - - - - - - - - - - - - -void energyCalibration::setStartParameters(Double_t *par){ - bg_offset=par[0]; - bg_slope=par[1]; - flex=par[2]; - noise=par[3]; - ampl=par[4]; - cs_slope=par[5]; -} - - -void energyCalibration::getStartParameters(Double_t *par){ - par[0]=bg_offset; - par[1]=bg_slope; - par[2]=flex; - par[3]=noise; - par[4]=ampl; - par[5]=cs_slope; -} - -#endif -int energyCalibration::setChargeSharing(int p) { - if (p>=0) { - cs_flag=p; -#ifdef MYROOT - if (p) { - fscurve->ReleaseParameter(5); - fspectrum->ReleaseParameter(1); - } else { - fscurve->FixParameter(5,0); - fspectrum->FixParameter(1,0); - } -#endif - } - - return cs_flag; -} - - -#ifdef MYROOT -void energyCalibration::initFitFunction(TF1 *fun, TH1 *h1) { - - Double_t min=fit_min, max=fit_max; - - Double_t mypar[6]; - - if (max==-1) - max=h1->GetXaxis()->GetXmax(); - - if (min==-1) - min=h1->GetXaxis()->GetXmin(); - - - if (bg_offset==-1) - mypar[0]=0; - else - mypar[0]=bg_offset; - - - if (bg_slope==-1) - mypar[1]=0; - else - mypar[1]=bg_slope; - - - if (flex==-1) - mypar[2]=(min+max)/2.; - else - mypar[2]=flex; - - - if (noise==-1) - mypar[3]=0.1; - else - mypar[3]=noise; - - if (ampl==-1) - mypar[4]=h1->GetBinContent(h1->GetXaxis()->FindBin(0.5*(max+min))); - else - mypar[4]=ampl; - - if (cs_slope==-1) - mypar[5]=0; - else - mypar[5]=cs_slope; - - fun->SetParameters(mypar); - - fun->SetRange(min,max); - -} - - -TF1* energyCalibration::fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t *emypar) { - - - TF1* fitfun; - - char fname[100]; - - strcpy(fname, fun->GetName()); - - if (plot_flag) { - h1->Fit(fname,"R0Q"); - } else - h1->Fit(fname,"R0Q"); - - - fitfun= h1->GetFunction(fname); - fitfun->GetParameters(mypar); - for (int ip=0; ip<6; ip++) { - emypar[ip]=fitfun->GetParError(ip); - } - return fitfun; -} - -TF1* energyCalibration::fitSCurve(TH1 *h1, Double_t *mypar, Double_t *emypar) { - initFitFunction(fscurve,h1); - return fitFunction(fscurve, h1, mypar, emypar); -} - - - - - -TF1* energyCalibration::fitSpectrum(TH1 *h1, Double_t *mypar, Double_t *emypar) { - initFitFunction(fspectrum,h1); - return fitFunction(fspectrum, h1, mypar, emypar); -} - - - -TGraphErrors* energyCalibration::linearCalibration(int nscan, Double_t *en, Double_t *een, Double_t *fl, Double_t *efl, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff) { - - TGraphErrors *gr; - - Double_t mypar[2]; - - gr = new TGraphErrors(nscan,en,fl,een,efl); - - if (plot_flag) { - gr->Fit("pol1"); - gr->SetMarkerStyle(20); - } else - gr->Fit("pol1","0Q"); - - TF1 *fitfun= gr->GetFunction("pol1"); - fitfun->GetParameters(mypar); - - egain=fitfun->GetParError(1); - eoff=fitfun->GetParError(0); - - gain=funcs->setScanSign()*mypar[1]; - - off=mypar[0]; - - return gr; -} - - -TGraphErrors* energyCalibration::calibrate(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff, int integral) { - - TH1F *h; - - Double_t mypar[6], emypar[6]; - Double_t fl[nscan], efl[nscan]; - - - for (int ien=0; ien -#include -class TH1F; -class TH2F; -class TGraphErrors; -#endif - - -using namespace std; - - - - -const double conven=1000./3.6; /**< electrons/keV */ -const double el=1.67E-4; /**< electron charge in fC */ - - - -/** - \mainpage Common Root library for SLS detectors data analysis - * - * \section intro_sec Introduction - We know very well s-curves etc. but at the end everybody uses different functions ;-). - - * \subsection mot_sec Motivation - It would be greate to use everybody the same functions... - -*/ - - -/** - * - * -@libdoc The energiCalibration class contains all the necessary functions for s-curve fitting and linear calibration of the threshold. - * - * @short Energy calibration functions - * @author Anna Bergamaschi - * @version 0.1alpha - - - */ - -/** - class containing all the possible energy calibration functions (scurves with and without charge sharing, gaussian spectrum with and without charge sharing, possibility of chosing the sign of the X-axis) - -*/ -class energyCalibrationFunctions { - - public: - - energyCalibrationFunctions(int s=-1) {setScanSign(s);}; - - /** sets scan sign - \param s can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) otherwise gets - \returns current scan sign can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) - */ - int setScanSign(int s=0) {if (s==1 || s==-1) sign=s; return sign;};; - - -#ifdef MYROOT - /** - Gaussian Function with charge sharing pedestal - par[0] is the absolute height of the background pedestal - par[1] is the slope of the background pedestal - */ - Double_t pedestal(Double_t *x, Double_t *par); - - /** - Gaussian Function with charge sharing pedestal - par[0] is the absolute height of the background pedestal - par[1] is the slope of the background pedestal - par[2] is the gaussian peak position - par[3] is the RMS of the gaussian (and of the pedestal) - par[4] is the height of the function - par[5] is the fractional height of the charge sharing pedestal (scales with par[3]) - */ - Double_t gaussChargeSharing(Double_t *x, Double_t *par); - /** - Gaussian Function with charge sharing pedestal - par[0] is the absolute height of the background pedestal - par[1] is the slope of the background pedestal - par[2] is the gaussian peak position - par[3] is the RMS of the gaussian (and of the pedestal) - par[4] is the height of the function - par[5] is the fractional height of the charge sharing pedestal (scales with par[3]) - */ - Double_t gaussChargeSharingPixel(Double_t *x, Double_t *par); - - /** - Basic erf function - par[0] is the inflection point - par[1] is the RMS - par[2] is the amplitude - */ -Double_t erfFunction(Double_t *x, Double_t *par) ; - Double_t erfBox(Double_t *z, Double_t *par); - /** Erf function with charge sharing slope - par[0] is the pedestal - par[1] is the slope of the pedestal - par[2] is the inflection point - par[3] is the RMS - par[4] is the amplitude - par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) - */ -Double_t erfFunctionChargeSharing(Double_t *x, Double_t *par); - - /** Double Erf function with charge sharing slope - par[0] is the pedestal - par[1] is the slope of the pedestal - par[2] is the inflection point of the first energy - par[3] is the RMS of the first energy - par[4] is the amplitude of the first energy - par[5] is the angual coefficient of the charge sharing slope of the first energy (scales with par[3]) - par[6] is the inflection point of the second energy - par[7] is the RMS of the second energy - par[8] is the amplitude of the second energy - par[9] is the angual coefficient of the charge sharing slope of the second energy (scales with par[8]) - */ - -Double_t erfFuncFluo(Double_t *x, Double_t *par); - - - /** - static function Gaussian with charge sharing pedestal with the correct scan sign - par[0] is the absolute height of the background pedestal - par[1] is the slope of the pedestal - par[2] is the gaussian peak position - par[3] is the RMS of the gaussian (and of the pedestal) - par[4] is the height of the function - par[5] is the fractional height of the charge sharing pedestal (scales with par[4] - */ - Double_t spectrum(Double_t *x, Double_t *par); - - /** - static function Gaussian with charge sharing pedestal with the correct scan sign - par[0] is the absolute height of the background pedestal - par[1] is the slope of the pedestal - par[2] is the gaussian peak position - par[3] is the RMS of the gaussian (and of the pedestal) - par[4] is the height of the function - par[5] is the fractional height of the charge sharing pedestal (scales with par[4] - */ - Double_t spectrumPixel(Double_t *x, Double_t *par); - - - /** Erf function with charge sharing slope with the correct scan sign - par[0] is the pedestal - par[1] is the slope of the pedestal - par[2] is the inflection point - par[3] is the RMS - par[4] is the amplitude - par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) - */ - Double_t scurve(Double_t *x, Double_t *par); - - - - /** Double Erf function with charge sharing slope - par[0] is the pedestal - par[1] is the slope of the pedestal - par[2] is the inflection point of the first energy - par[3] is the RMS of the first energy - par[4] is the amplitude of the first energy - par[5] is the angual coefficient of the charge sharing slope of the first energy (scales with par[3]) - par[6] is the inflection point of the second energy - par[7] is the RMS of the second energy - par[8] is the amplitude of the second energy - par[9] is the angual coefficient of the charge sharing slope of the second energy (scales with par[8]) - */ - Double_t scurveFluo(Double_t *x, Double_t *par); - -#endif - -/** Calculates the median of an array of n elements */ - static double median(double *x, int n); -/** Calculates the median of an array of n elements (swaps the arrays!)*/ - static int quick_select(int arr[], int n); -/** Calculates the median of an array of n elements (swaps the arrays!)*/ - static int kth_smallest(int *a, int n, int k); - - private: - int sign; - - -}; - -/** - class alowing the energy calibration of photon counting and anlogue detectors - -*/ - -class energyCalibration { - - - public: - /** - default constructor - creates the function with which the s-curves will be fitted - */ - energyCalibration(); - - /** - default destructor - deletes the function with which the s-curves will be fitted - */ - ~energyCalibration(); - - /** sets plot flag - \param p plot flag (-1 gets, 0 unsets, >0 plot) - \returns current plot flag - */ - int setPlotFlag(int p=-1) {if (p>=0) plot_flag=p; return plot_flag;}; - - /** sets scan sign - \param s can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) otherwise gets - \returns current scan sign can be 1 (energy and x-axis have the same direction) or -1 (energy and x-axis have opposite directions) - */ - int setScanSign(int s=0) {return funcs->setScanSign(s);}; - - /** sets plot flag - \param p plot flag (-1 gets, 0 unsets, >0 plot) - \returns current plot flag - */ - int setChargeSharing(int p=-1); - - - void fixParameter(int ip, Double_t val); - - void releaseParameter(int ip); - -#ifdef MYROOT - - /** - Creates an histogram with the median of nchannels starting from a specified one. the direction on which it is mediated can be selected (defaults to x=0) - \param h2 2D histogram on which the median will be calculated - \param ch0 starting channel - \param nch number of channels to be mediated - \param direction can be either 0 (x, default) or 1 (y) - \returns a TH1F histogram with the X-axis as a clone of the h2 Y (if direction=0) or X (if direction=0) axis, and on the Y axis the median of the counts of the mediated channels f h2 - */ - static TH1F* createMedianHistogram(TH2F* h2, int ch0, int nch, int direction=0); - - - /** sets the s-curve fit range - \param mi minimum of the fit range (-1 is histogram x-min) - \param ma maximum of the fit range (-1 is histogram x-max) - */ - void setFitRange(Double_t mi, Double_t ma){fit_min=mi; fit_max=ma;}; - - /** gets the s-curve fit range - \param mi reference for minimum of the fit range (-1 is histogram x-min) - \param ma reference for maximum of the fit range (-1 is histogram x-max) - */ - void getFitRange(Double_t &mi, Double_t &ma){mi=fit_min; ma=fit_max;}; - - -/** set start parameters for the s-curve function - \param par parameters, -1 sets to auto-calculation - par[0] is the pedestal - par[1] is the slope of the pedestal - par[2] is the inflection point - par[3] is the RMS - par[4] is the amplitude - par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) -- always positive - */ - void setStartParameters(Double_t *par); - -/** get start parameters for the s-curve function - \param par parameters, -1 means auto-calculated - par[0] is the pedestal - par[1] is the slope of the pedestal - par[2] is the inflection point - par[3] is the RMS - par[4] is the amplitude - par[5] is the angual coefficient of the charge sharing slope (scales with par[3]) -- always positive - */ - void getStartParameters(Double_t *par); - - /** - fits histogram with the s-curve function - \param h1 1d-histogram to be fitted - \param mypar pointer to fit parameters array - \param emypar pointer to fit parameter errors - \returns the fitted function - can be used e.g. to get the Chi2 or similar - */ - TF1 *fitSCurve(TH1 *h1, Double_t *mypar, Double_t *emypar); - - - /** - fits histogram with the spectrum - \param h1 1d-histogram to be fitted - \param mypar pointer to fit parameters array - \param emypar pointer to fit parameter errors - \returns the fitted function - can be used e.g. to get the Chi2 or similar - */ - TF1 *fitSpectrum(TH1 *h1, Double_t *mypar, Double_t *emypar); - - - /** - calculates gain and offset for the set of inflection points - \param nscan number of energy scans - \param en array of energies (nscan long) - \param een array of errors on energies (nscan long) - can be NULL! - \param fl array of inflection points (nscan long) - \param efl array of errors on the inflection points (nscan long) - \param gain reference to gain resulting from the fit - \param off reference to offset resulting from the fit - \param egain reference to error on the gain resulting from the fit - \param eoff reference to the error on the offset resulting from the fit - \returns graph energy vs inflection point - */ - TGraphErrors* linearCalibration(int nscan, Double_t *en, Double_t *een, Double_t *fl, Double_t *efl, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff); - - /** - calculates gain and offset for the set of energy scans - \param nscan number of energy scans - \param en array of energies (nscan long) - \param een array of errors on energies (nscan long) - can be NULL! - \param h1 array of TH1 - \param gain reference to gain resulting from the fit - \param off reference to offset resulting from the fit - \param egain reference to error on the gain resulting from the fit - \param eoff reference to the error on the offset resulting from the fit - \returns graph energy vs inflection point - */ - TGraphErrors* calibrateScurves(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff){return calibrate(nscan, en, een, h1, gain, off, egain, eoff, 1);}; - - /** - calculates gain and offset for the set of energy spectra - \param nscan number of energy scans - \param en array of energies (nscan long) - \param een array of errors on energies (nscan long) - can be NULL! - \param h1 array of TH1 - \param gain reference to gain resulting from the fit - \param off reference to offset resulting from the fit - \param egain reference to error on the gain resulting from the fit - \param eoff reference to the error on the offset resulting from the fit - \returns graph energy vs peak - */ - TGraphErrors* calibrateSpectra(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff){return calibrate(nscan, en, een, h1, gain, off, egain, eoff, 0);}; - - -#endif - private: - -#ifdef MYROOT - /** - calculates gain and offset for the set of energies - \param nscan number of energy scans - \param en array of energies (nscan long) - \param een array of errors on energies (nscan long) - can be NULL! - \param h1 array of TH1 - \param gain reference to gain resulting from the fit - \param off reference to offset resulting from the fit - \param egain reference to error on the gain resulting from the fit - \param eoff reference to the error on the offset resulting from the fit - \param integral 1 is an s-curve set (default), 0 spectra - \returns graph energy vs peak/inflection point - */ - TGraphErrors* calibrate(int nscan, Double_t *en, Double_t *een, TH1F **h1, Double_t &gain, Double_t &off, Double_t &egain, Double_t &eoff, int integral=1); - - - /** - Initializes the start parameters and the range of the fit depending on the histogram characteristics and/or on the start parameters specified by the user - \param fun pointer to function to be initialized - \param h1 histogram from which to extract the range and start parameters, if not already specified by the user - -*/ - - void initFitFunction(TF1 *fun, TH1 *h1); - - - /** - Performs the fit according to the flags specified and returns the fitted function - \param fun function to fit - \param h1 histogram to fit - \param mypar pointer to fit parameters array - \param emypar pointer to fit parameter errors - \returns the fitted function - can be used e.g. to get the Chi2 or similar - */ - TF1 *fitFunction(TF1 *fun, TH1 *h1, Double_t *mypar, Double_t *emypar); - -#endif - -#ifdef MYROOT - Double_t fit_min; /**< minimum of the s-curve fitting range, -1 is histogram x-min */ - Double_t fit_max; /**< maximum of the s-curve fitting range, -1 is histogram x-max */ - - Double_t bg_offset; /**< start value for the background pedestal */ - Double_t bg_slope; /**< start value for the background slope */ - Double_t flex; /**< start value for the inflection point */ - Double_t noise; /**< start value for the noise */ - Double_t ampl; /**< start value for the number of photons */ - Double_t cs_slope; /**< start value for the charge sharing slope */ - - - TF1 *fscurve; /**< function with which the s-curve will be fitted */ - - TF1 *fspectrum; /**< function with which the spectrum will be fitted */ - - TF1 *fspixel; /**< function with which the spectrum will be fitted */ - -#endif - - energyCalibrationFunctions *funcs; - int plot_flag; /**< 0 does not plot, >0 plots (flags?) */ - - int cs_flag; /**< 0 functions without charge sharing contribution, >0 with charge sharing contribution */ - -}; - -#endif - - - - - - - - - - - - - - - - - - - diff --git a/slsReceiverSoftware/slsDetectorCalibration/gMapDemo.C b/slsReceiverSoftware/slsDetectorCalibration/gMapDemo.C deleted file mode 100644 index 51addf69a7..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/gMapDemo.C +++ /dev/null @@ -1,11 +0,0 @@ -{ - //.L energyCalibration.cpp+ - //.L gainMap.C+ - TFile fin("/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_cds_g4.root"); - TH2F *h2=fin.Get("h2"); - TH2F *gMap=gainMap(h2,4); - gMap->Draw("colz"); - - - -} diff --git a/slsReceiverSoftware/slsDetectorCalibration/gainMap.C b/slsReceiverSoftware/slsDetectorCalibration/gainMap.C deleted file mode 100644 index 7923fe687a..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/gainMap.C +++ /dev/null @@ -1,228 +0,0 @@ -#define MYROOT -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - - -#define FOPT "0" - -TH2F *gainMap(TH2F *h2, float g) { - // int npx, npy; - int npx=160, npy=160; - // det->getDetectorSize(npx, npy); - - TH2F *gMap=new TH2F("gmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); - - Double_t ens[3]={0,8,17.5}, eens[3]={0.,0.1,0.1}; - Double_t peaks[3], epeaks[3]; - - - - int ibin; - TH1D *px; - - - energyCalibration *enCal=new energyCalibration(); - enCal->setPlotFlag(0); - // enCal->setChargeSharing(0); - enCal->setScanSign(1); - - Double_t gain, off, egain, eoff; - - - TList *functions; - TPolyMarker *pm ; - Double_t *peakX, *peakY; - TSpectrum *s=new TSpectrum(); - Double_t mypar[10], emypar[10]; - Double_t prms, np; - int iit=0; - TGraph *glin; - Double_t peakdum, hpeakdum; - - for (int ix=1; ixProjectionX("px",ibin+1,ibin+1); - prms=10*g; - iit=0; - np=s->Search(px,prms,"",0.2); - while (np !=2) { - if (np>2) - prms+=0.5*prms; - else - prms-=0.5*prms; - iit++; - if (iit>=10) - break; - np=s->Search(px,prms,"",0.2); - } - if (np!=2) - cout << "peak search could not converge " << ibin << endl; - if (np==2) { - pm=NULL; - functions=px->GetListOfFunctions(); - if (functions) - pm = (TPolyMarker*)functions->FindObject("TPolyMarker"); - if (pm) { - peakX=pm->GetX(); - peakY=pm->GetY(); - - - if (peakX[0]>peakX[1]) { - peakdum=peakX[0]; - hpeakdum=peakY[0]; - peakX[0]= peakX[1]; - peakY[0]= peakY[1]; - peakX[1]= peakdum; - peakY[1]= hpeakdum; - - } - - cout << "("<< ix << "," << iy << ") " << endl; - for (int ip=0; ipsetFitRange(peakX[ip]-10*g,peakX[ip]+10*g); - mypar[0]=0; - mypar[1]=0; - mypar[2]=peakX[ip]; - mypar[3]=g*10; - mypar[4]=peakY[ip]; - mypar[5]=0; - - - - enCal->setStartParameters(mypar); - enCal->fitSpectrum(px,mypar,emypar); - - - peaks[ip+1]=mypar[2]; - epeaks[ip+1]=emypar[2]; - } - - peaks[0]=0; - epeaks[0]=1; - - // for (int i=0; i<3; i++) cout << i << " " << ens[i] << " " << eens[i]<< " "<< peaks[i]<< " " << epeaks[i] << endl; - - glin= enCal->linearCalibration(3,ens,eens,peaks,epeaks,gain,off,egain,eoff); - - // cout << "Gain " << gain << " off " << off << endl; - if (off>-10 && off<10) { - gMap->SetBinContent(ix+1,iy+1,gain); - gMap->SetBinError(ix+1,iy+1,egain); - } - if (glin) - delete glin; - } - } - - - } - } - - return gMap; -} - - -TH2F *noiseMap(TH2F *h2) { - // int npx, npy; - int npx=160, npy=160; - // det->getDetectorSize(npx, npy); - - TH2F *nMap=new TH2F("nmap",h2->GetTitle(), npx, -0.5, npx-0.5, npy, -0.5, npy-0.5); - - int ibin; - TH1D *px; - - for (int ix=0; ixProjectionX("px",ibin+1,ibin+1); - px->Fit("gaus", FOPT); - if (px->GetFunction("gaus")) { - nMap->SetBinContent(ix+1,iy+1,px->GetFunction("gaus")->GetParameter(2)); - } - // delete px; - } - } - - return nMap; -} - - -THStack *noiseHistos(char *tit) { - char fname[10000]; - - sprintf(fname,"/data/moench_xbox_20140116/noise_map_%s.root",tit); - TFile *fn=new TFile(fname); - TH2F *nmap=(TH2F*)fn->Get("nmap"); - - if (nmap==NULL) { - cout << "No noise map in file " << fname << endl; - - return NULL; - } - - sprintf(fname,"/data/moench_xbox_20140113/gain_map_%s.root",tit); - TFile *fg=new TFile(fname); - TH2F *gmap=(TH2F*)fg->Get("gmap"); - - if (gmap==NULL) { - cout << "No gain map in file " << fname << endl; - - return NULL; - } - - nmap->Divide(gmap); - nmap->Scale(1000./3.6); - - THStack *hs=new THStack(tit,tit); - hs->SetTitle(tit); - - TH1F *h; - char hname[100]; - - cout << tit << endl; - for (int is=0; is<4; is++) { - sprintf(hname,"h%ds",is+1); - - h=new TH1F(hname,tit,500,0,500); - hs->Add(h); - // cout << hs->GetHists()->GetEntries() << endl; - for (int ix=40*is+2; ix<40*(is+1)-2; ix++) { - - for (int iy=2; iy<158; iy++) { - if (ix<100 || ix>120) - h->Fill(nmap->GetBinContent(ix+1,iy+1)); - } - } - cout << is+1 << "SC: " << "" << h->GetMean() << "+-" << h->GetRMS(); - h->Fit("gaus","0Q"); - h->SetLineColor(is+1); - if (h->GetFunction("gaus")) { - h->GetFunction("gaus")->SetLineColor(is+1); - cout << " or " << h->GetFunction("gaus")->GetParameter(1) << "+-" << h->GetFunction("gaus")->GetParError(1); - } - cout << endl; - } - - // cout << hs->GetHists()->GetEntries() << endl; - - return hs; - - -} diff --git a/slsReceiverSoftware/slsDetectorCalibration/gotthardModuleData.h b/slsReceiverSoftware/slsDetectorCalibration/gotthardModuleData.h deleted file mode 100644 index 3f674af57c..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/gotthardModuleData.h +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef GOTTHARDMODULEDATA_H -#define GOTTHARDMODULEDATA_H -#include "slsReceiverData.h" - - - - - -#define FRAMEMASK 0xFFFFFFFE -#define PACKETMASK 1 -#define FRAMEOFFSET 0x1 - - -class gotthardModuleData : public slsReceiverData { -public: - - - - - /** - Implements the slsReceiverData structure for the gotthard read out by a module i.e. using the slsReceiver - (1x1280 pixels, 2 packets 1286 large etc.) - \param c crosstalk parameter for the output buffer - - */ - - - gotthardModuleData(double c=0): slsReceiverData(xpixels, ypixels, npackets, buffersize), xtalk(c) { - - uint16_t **dMask; - int **dMap; - int ix, iy; - int initial_offset = 2; - int offset = initial_offset; - - dMask=new uint16_t*[ypixels]; - dMap=new int*[ypixels]; - for (int i = 0; i < ypixels; i++) { - dMap[i] = new int[xpixels]; - dMask[i] = new uint16_t[xpixels]; - } - - for(ix=0; ix>FRAMEOFFSET); - }; - - - - /** - gets the packets number (last packet is labelled with 0 and is replaced with 40) - \param buff pointer to the memory - \returns packet number - - */ - - int getPacketNumber(char *buff){ - int np=(*(int*)buff); - //gotthards frame header must be incremented - ++np; - //packet index should be 1 or 2 - return ((np&PACKETMASK)+1); - }; - - - /** - returns the pixel value as double correcting for the output buffer crosstalk - \param data pointer to the memory - \param ix coordinate in the x direction - \param iy coordinate in the y direction - \returns channel value as double - - */ - double getValue(char *data, int ix, int iy=0) { - //check how it is for gotthard - if (xtalk==0) - return slsDetectorData::getValue(data, ix, iy); - else - return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); - }; - - - - /** sets the output buffer crosstalk correction parameter - \param c output buffer crosstalk correction parameter to be set - \returns current value for the output buffer crosstalk correction parameter - - */ - double setXTalk(double c) {xtalk=c; return xtalk;} - - - /** gets the output buffer crosstalk parameter - \returns current value for the output buffer crosstalk correction parameter - */ - double getXTalk() {return xtalk;} - - - - - - - -private: - - double xtalk; /** { -public: - - - - - /** - Implements the slsReceiverData structure for the gotthard short read out by a module i.e. using the slsReceiver - (1x256 pixels, 1 packet 256 large etc.) - \param c crosstalk parameter for the output buffer - - */ - - - gotthardShortModuleData(double c=0): slsReceiverData(xpixels, ypixels, npackets, buffersize), xtalk(c){ - - uint16_t **dMask; - int **dMap; - int ix, iy; - int offset = 2; - - dMask=new uint16_t*[ypixels]; - dMap=new int*[ypixels]; - for (int i = 0; i < ypixels; i++) { - dMap[i] = new int[xpixels]; - dMask[i] = new uint16_t[xpixels]; - } - - for(ix=0; ix::getValue(data, ix, iy); - else - return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); - }; - - - - /** sets the output buffer crosstalk correction parameter - \param c output buffer crosstalk correction parameter to be set - \returns current value for the output buffer crosstalk correction parameter - - */ - double setXTalk(double c) {xtalk=c; return xtalk;} - - - /** gets the output buffer crosstalk parameter - \returns current value for the output buffer crosstalk correction parameter - */ - double getXTalk() {return xtalk;} - - - - - - - -private: - - double xtalk; /**=0 && ix=0 && iy=0 && dataMap[iy][ix]8000) //exchange if gainBits==2 is returned! - d|=(1<<14); // gain bit 1 - if (*((uint16_t*)(data)+dataMap[iy][ix]+1)>8000) //exchange if gainBits==2 is returned! - d|=(1<<15); // gain bit 0 - - } - - } - return d^m; - }; - - /** - returns the pixel value as double correcting for the output buffer crosstalk - \param data pointer to the memory - \param ix coordinate in the x direction - \param iy coordinate in the y direction - \returns channel value as double - - */ - double getValue(char *data, int ix, int iy=0) { - // cout << "##" << (void*)data << " " << ix << " " < the gain bits are read out the wrong way around (i.e. GB0 and GB1 have to be reversed!) - \param data pointer to the memory - \param ix coordinate in the x direction - \param iy coordinate in the y direction - \returns gain bits as int - */ - int getGainBits(char *data, int ix, int iy=0) { - uint16_t d=getChannel(data, ix, iy); - return ((d&0xc000)>>14); - }; - //*/ - - - - - /** sets the output buffer crosstalk correction parameter - \param c output buffer crosstalk correction parameter to be set - \returns current value for the output buffer crosstalk correction parameter - - */ - double setXTalk(double c) {xtalk=c; return xtalk;} - - - /** gets the output buffer crosstalk parameter - \returns current value for the output buffer crosstalk correction parameter - */ - double getXTalk() {return xtalk;} - - - - - - - - private: - - double xtalk; /** -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -//#include -//#include -#include -#include "jungfrau02Data.h" -#include "jungfrau02CommonMode.h" -#include "singlePhotonDetector.h" - -//#include "MovingStat.h" - -using namespace std; - -#define NC 48 -#define NR 48 - - -#define MY_DEBUG 1 -#ifdef MY_DEBUG -#include -#endif - -/** - -Loops over data file to find single photons, fills the tree (and writes it to file, although the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (48*x+y) on the y axis. - - \param fformat file name format - \param tit title of the tree etc. - \param runmin minimum run number - \param runmax max run number - \param nbins number of bins for spectrum hists - \param hmin histo minimum for spectrum hists - \param hmax histo maximum for spectrum hists - \param sign sign of the spectrum to find hits - \param hc readout correlation coefficient with previous pixel - \param xmin minimum x coordinate - \param xmax maximum x coordinate - \param ymin minimum y coordinate - \param ymax maximum y coordinate - \param cmsub enable commonmode subtraction - \param hitfinder if 0: performs pedestal subtraction, not hit finding; if 1: performs both pedestal subtraction and hit finding - \returns pointer to histo stack with cluster spectra -*/ - - -THStack *jungfrauReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1){ -/* - // read in calibration file - ifstream calfile("/home/l_msdetect/TriesteBeam2014/dummy data for scripts/CalibrationParametersTest_fake.txt"); - if (calfile.is_open()==0){cout << "Unable to open calibration file!" << endl;} - int pix; - double of0,sl0,of1,sl1,of2,sl2; - double of_0[NC*NR], of_1[NC*NR], of_2[NC*NR], sl_0[NC*NR], sl_1[NC*NR], sl_2[NC*NR]; - while (calfile >> pix >> of0 >> sl0 >> of1 >> sl1 >> of2 >> sl2){ - of_0[pix]=of0; - sl_0[pix]=sl0; - of_1[pix]=of1; - sl_1[pix]=sl1; - of_2[pix]=of2; - sl_2[pix]=sl2; //if(pix==200) cout << "sl_2[200] " << sl_2[200] << endl; - } - calfile.close(); -*/ - double adc_value, num_photon; - - jungfrau02Data *decoder=new jungfrau02Data(1,0,0);//(1,0,0); // (adc,offset,crosstalk) //(1,0,0) //(3,0,0) for readout of GB - jungfrau02CommonMode *cmSub=NULL; - if (cmsub) - cmSub=new jungfrau02CommonMode(); - - int nph=0; - int iev=0; - singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub); - - char *buff; - char fname[10000]; - int nf=0; - - eventType thisEvent=PEDESTAL; - - // int iframe; - // double *data, ped, sigma; - - // data=decoder->getCluster(); - - TH2F *h2; - TH2F *h3; - TH2F *hetaX; // not needed for JF? - TH2F *hetaY; // not needed for JF? - - THStack *hs=new THStack("hs",fformat); - - - TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - hs->Add(h1); - - if (hitfinder) { - h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); // not needed for JF? - hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); // not needed for JF? - hs->Add(h2); - hs->Add(h3); - hs->Add(hetaX); // not needed for JF? - hs->Add(hetaY); // not needed for JF? - } - - - ifstream filebin; - - - int ix=20, iy=20, ir, ic; - - - Int_t iFrame; - TTree *tall; - if (hitfinder) - tall=filter->initEventTree(tit, &iFrame); - - - - -#ifdef MY_DEBUG - - TCanvas *myC; - TH2F *he; - TCanvas *cH1; - TCanvas *cH2; - TCanvas *cH3; - - if (hitfinder) { - myC=new TCanvas(); - he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); - he->SetStats(kFALSE); - he->Draw("colz"); - cH1=new TCanvas(); - cH1->SetLogz(); - h1->Draw("colz"); - cH2=new TCanvas(); - cH2->SetLogz(); - h2->Draw("colz"); - cH3=new TCanvas(); - cH3->SetLogz(); - h3->Draw("colz"); - } -#endif - filter->newDataSet(); - - - for (int irun=runmin; irun<=runmax; irun++){ - sprintf(fname,fformat,irun); - cout << "file name " << fname << endl; - filebin.open((const char *)(fname), ios::in | ios::binary); - nph=0; - while ((buff=decoder->readNextFrame(filebin))) { - - - if (hitfinder) { - filter->newFrame(); - - //calculate pedestals and common modes - if (cmsub) { - // cout << "cm" << endl; - for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); - } - } - } - - // cout << "new frame " << endl; - - for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); - int gainBits=decoder->getGainBits(buff,ix,iy); //XXX - -#ifdef MY_DEBUG - if (hitfinder) { - if (iev%1000==0) - //he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); // show single photon hits // original - //he->SetBinContent(ix+1-xmin, iy+1-ymin, cmSub->getCommonMode(ix,iy)); //show common mode! - he->SetBinContent(iy+1-ymin, ix+1-xmin, (int)gainBits); //show gain bits - //he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)gainBits); // rows and columns reversed!!! - } -#endif - - if (nf>1000) { // only start filing data after 1000 frames - - // h1->Fill(decoder->getValue(buff,ix,iy), iy+NR*ix); - h1->Fill(filter->getClusterTotal(1), iy+NR*ix); - - - if (hitfinder) { - - if (thisEvent==PHOTON_MAX ) { - nph++; - - h2->Fill(filter->getClusterTotal(2), iy+NR*ix); - h3->Fill(filter->getClusterTotal(3), iy+NR*ix); - iFrame=decoder->getFrameNumber(buff); - - tall->Fill(); - - - } - - - } - - - } - } - ////////////////////////////////////////////////////////// - -#ifdef MY_DEBUG - if (iev%1000==0) { - myC->Modified(); - myC->Update(); - cH1->Modified(); - cH1->Update(); - cH2->Modified(); - cH2->Update(); - cH3->Modified(); - cH3->Update(); - } - iev++; -#endif - nf++; - - cout << "="; // one "=" for every frame that's been processed - delete [] buff; - } - cout << nph << endl; // number of photons found in file - if (filebin.is_open()) - filebin.close(); - else - cout << "Could not open file :( ... " << fname << endl; - } - if (hitfinder) - tall->Write(tall->GetName(),TObject::kOverwrite); - - - - delete decoder; - cout << "Read " << nf << " frames." << endl; - return hs; -} - diff --git a/slsReceiverSoftware/slsDetectorCalibration/moench02ModuleData.h b/slsReceiverSoftware/slsDetectorCalibration/moench02ModuleData.h deleted file mode 100644 index 34b4f17834..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/moench02ModuleData.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef MOENCH02MODULEDATA_H -#define MOENCH02MODULEDATA_H -#include "slsReceiverData.h" - - - -class moench02ModuleData : public slsReceiverData { - public: - - - - - /** - Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver - (160x160 pixels, 40 packets 1286 large etc.) - \param c crosstalk parameter for the output buffer - - */ - - - moench02ModuleData(double c=0): slsReceiverData(160, 160, 40, 1286), - xtalk(c) { - - - - - uint16_t **dMask; - int **dMap; - int ix, iy; - - - - dMask=new uint16_t*[160]; - dMap=new int*[160]; - for (int i = 0; i < 160; i++) { - dMap[i] = new int[160]; - dMask[i] = new uint16_t[160]; - } - - for (int isc=0; isc<4; isc++) { - for (int ip=0; ip<10; ip++) { - - for (int ir=0; ir<16; ir++) { - for (int ic=0; ic<40; ic++) { - - ix=isc*40+ic; - iy=ip*16+ir; - - dMap[iy][ix]=1286*(isc*10+ip)+2*ir*40+2*ic+4; - // cout << ix << " " << iy << " " << dMap[ix][iy] << endl; - } - } - } - } - - for (ix=0; ix<120; ix++) { - for (iy=0; iy<160; iy++) - dMask[iy][ix]=0x3fff; - } - for (ix=120; ix<160; ix++) { - for (iy=0; iy<160; iy++) - dMask[iy][ix]=0x0; - } - - - setDataMap(dMap); - setDataMask(dMask); - - - - - }; - - - - /** - gets the packets number (last packet is labelled with 0 and is replaced with 40) - \param buff pointer to the memory - \returns packet number - - */ - - int getPacketNumber(char *buff){ - int np=(*(int*)buff)&0xff; - if (np==0) - np=40; - return np; - }; - - - /** - returns the pixel value as double correcting for the output buffer crosstalk - \param data pointer to the memory - \param ix coordinate in the x direction - \param iy coordinate in the y direction - \returns channel value as double - - */ - double getValue(char *data, int ix, int iy=0) { - // cout << "##" << (void*)data << " " << ix << " " <::getValue(data, ix, iy); - else - return slsDetectorData::getValue(data, ix, iy)-xtalk*slsDetectorData::getValue(data, ix-1, iy); - }; - - - - /** sets the output buffer crosstalk correction parameter - \param c output buffer crosstalk correction parameter to be set - \returns current value for the output buffer crosstalk correction parameter - - */ - double setXTalk(double c) {xtalk=c; return xtalk;} - - - /** gets the output buffer crosstalk parameter - \returns current value for the output buffer crosstalk correction parameter - */ - double getXTalk() {return xtalk;} - - - - - - - - private: - - double xtalk; /**=0 && isc=0 && isc0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); - } - return 0; - }; - -}; - - -#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/moenchMakeTree.C b/slsReceiverSoftware/slsDetectorCalibration/moenchMakeTree.C deleted file mode 100644 index 372052285d..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/moenchMakeTree.C +++ /dev/null @@ -1,244 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "RunningStat.h" -#include "MovingStat.h" -#include "moench02ModuleData.h" -#include - -using namespace std; - - -//tree variables - int xC,yC,iFrameC; - double meC,sigC; - Double_t dataC[3][3]; -TTree* tall; - -typedef struct task_s{ - char *fformat; - char *tname; - int runmin; - int runmax; - int sign; -} Task; - -void setUpTree(char *tname){ - tall=new TTree(tname,tname); - tall->Branch("iFrame",&iFrameC,"iframe/I"); - tall->Branch("x",&xC,"x/I"); - tall->Branch("y",&yC,"y/I"); - tall->Branch("data",dataC,"data[3][3]/D"); - tall->Branch("pedestal",&meC,"pedestal/D"); - tall->Branch("rms",&sigC,"rms/D"); -} - -inline void storeEvent(int iF,int x,int y, Double_t data[][3], double me, double sig){ - TThread::Lock(); - xC = x; yC = y; iFrameC = iF; - memcpy(dataC,data,sizeof(Double_t)*3*3); - //cout << "X: " << x << " Y: " << y << endl; - /* for(int i = 0; i < 3; i++){ - for(int j = 0; j < 3; j++){ - cout << "i: " << i << " j: " << j << " dataC " << dataC[i][j] << " data " << data[i][j] << endl; - } - }*/ - meC = me; sigC = sig; - tall->Fill(); - TThread::UnLock(); -} - -void moenchMakeTree(char *fformat, char *tname, int runmin, int runmax, int sign=1) { - double nThSigma = 3.; - moench02ModuleData *decoder=new moench02ModuleData(); - char *buff; - char fname[10000]; - - int nf=0; - - int dum, nPhotons; - double me, sig, tot, maxNei, val, valNei; - - MovingStat stat[160][160]; - MovingStat nPhotonsStat; - - ifstream filebin; - - int nbg=20; - - int ix, iy, ir, ic, mx,my; - Double_t data[3][3]; - - nPhotonsStat.Clear(); - nPhotonsStat.SetN(1000); - - for (ir=0; ir<160; ir++) { - for (ic=0; ic<160; ic++) { - stat[ir][ic].Clear(); - stat[ir][ic].SetN(nbg); - } - } - - for (int irun=runmin; irunreadNextFrame(filebin))) { - nPhotons=0; - //for (ix=0; ix<160; ix++){ - for (ix=0; ix<40; ix++){ - for (iy=0; iy<160; iy++) { - - - - dum=0; //no hit - // tot=0; - - me=stat[iy][ix].Mean(); - sig=stat[iy][ix].StandardDeviation(); - val=sign*(decoder->getChannelShort(buff,ix,iy)-me); - - - if (nf>nbg) { - me=stat[iy][ix].Mean(); - sig=stat[iy][ix].StandardDeviation(); - val=sign*decoder->getChannel(buff,ix,iy)-me; - - // dum=0; //no hit - tot=0; - maxNei = 0; - - if (val>nThSigma*sig)//{ //hit check if neighbors are higher - dum=1; - for (ir=-1; ir<2; ir++){ - for (ic=-1; ic<2; ic++){ - if ((ix+ic)>=0 && (ix+ic)<160 && (iy+ir)>=0 && (iy+ir)<160) { - valNei = sign*decoder->getChannel(buff,ix+ic,iy+ir)-stat[iy+ir][ix+ic].Mean(); - if (sign*decoder->getChannel(buff,ix+ic,iy+ir)>(stat[iy+ir][ix+ic].Mean()+3.*stat[iy+ir][ix+ic].StandardDeviation())) dum=1; //is a hit or neighbour is a hit! - tot+=valNei; - data[ir+1][ic+1] = valNei; - if(valNei/stat[iy+ir][ix+ic].StandardDeviation() > maxNei){ - maxNei = valNei/stat[iy+ir][ix+ic].StandardDeviation(); - mx = ir; - my = ic; - } - } - } - } - // } - - if (val<(-nThSigma*sig)) dum=2; //discard negative events! - - if(dum == 1 && mx == 0 && my == 0){ // this is an event and we are in the center - storeEvent(nf,ix,iy,data,me,sig); - nPhotons++; - //cout << "BF X: " << ix << " Y: " << iy << " val: " << val << " tot: " << tot << " me: " << me << " sig: " << sig << endl; - } - - - //if (tot>9.*sig && dum == 1){ dum=3;} - //cout << dum; - } - //if (ix==20 && iy==40) - //cout << decoder->getChannelShort(buff,ix,iy)<< " " << val << " " << me << " " << sig << " " << dum << endl; - - if ( dum==0) { - - stat[iy][ix].Calc(decoder->getChannelShort(buff,ix,iy)); - } - if (nfgetChannel(buff,ix,iy)); - - } - } - delete [] buff; - //cout << "="; cout.flush(); - if(nf>nbg) nPhotonsStat.Calc((double)nPhotons); - nf++; - } - //cout << endl; - cout << "processed File " << fname << " done. Avg. Photons/Frame: " << nPhotonsStat.Mean() << " sig: " << nPhotonsStat.StandardDeviation() << " " << runmax-irun << " files need processing" << endl; - if (filebin.is_open()) - filebin.close(); - else - cout << "could not open file " << fname << endl; - } - - delete decoder; - cout << "Read " << nf << " frames" << endl; - - -} - -void *moenchMakeTreeTask(void *p){ - Task *t = (Task *)p; - moenchMakeTree(t->fformat,t->tname,t->runmin,t->runmax,t->sign); - return 0; -} - - -//to compile: g++ -DMYROOT -g `root-config --cflags --glibs` -o moenchMakeTree moenchMakeTree.C -int main(int argc, char **argv){ - if(argc != 6){ cout << "Usage: inFile outdir tname fileNrStart fileNrEnd" << endl; exit(-1); } - - int nThreads = 10; - TThread *threads[nThreads]; - - char *inFile = argv[1]; - char *outDir = argv[2]; - char *tName = argv[3]; - int start = atoi(argv[4]); - int end = atoi(argv[5]); - - TFile *f; - char outfname[1000]; - char threadName[1000]; - - sprintf(outfname,"%s/%s.root",outDir,tName); - f=new TFile(outfname,"RECREATE"); - - cout << "outputfile: " << outfname << endl; - setUpTree(tName); - - for(int i = 0; i < nThreads; i++){ - sprintf(threadName,"t%i",i); - Task *t = (Task *)malloc(sizeof(Task)); - t->fformat = inFile; - t->tname = tName; - t->sign = 1.; - t->runmin = start + (end-start)/(nThreads)*i; - t->runmax = start + (end-start)/(nThreads)*(i+1); - if(i == nThreads - 1) t->runmax = end; - cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; - threads[i] = new TThread(threadName, moenchMakeTreeTask, t); - threads[i]->Run(); - //moenchMakeTreeTask(t); - } - - - //TThread::Ps(); - - for(int i = 0; i < nThreads; i++){ - threads[i]->Join(); - } - - - tall->Write(); - tall->Print(); - f->Close(); -} - diff --git a/slsReceiverSoftware/slsDetectorCalibration/moenchReadData.C b/slsReceiverSoftware/slsDetectorCalibration/moenchReadData.C deleted file mode 100644 index bf7173f0bb..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/moenchReadData.C +++ /dev/null @@ -1,236 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -//#include -//#include -#include -#include "moench02ModuleData.h" -#include "moenchCommonMode.h" -#include "singlePhotonDetector.h" - -//#include "MovingStat.h" - -using namespace std; - -#define NC 160 -#define NR 160 - - -#define MY_DEBUG 1 -#ifdef MY_DEBUG -#include -#endif - -/** - -Loops over data file to find single photons, fills the tree (and writes it to file, althoug the root file should be opened before) and creates 1x1, 2x2, 3x3 cluster histograms with ADCu on the x axis, channel number (160*x+y) on the y axis. - - \param fformat file name format - \param tit title of the tree etc. - \param runmin minimum run number - \param runmax max run number - \param nbins number of bins for spectrum hists - \param hmin histo minimum for spectrum hists - \param hmax histo maximum for spectrum hists - \param sign sign of the spectrum to find hits - \param hc readout correlation coefficient with previous pixel - \param xmin minimum x coordinate - \param xmax maximum x coordinate - \param ymin minimum y coordinate - \param ymax maximum y coordinate - \param cmsub enable commonmode subtraction - \returns pointer to histo stack with cluster spectra -*/ - - -THStack *moenchReadData(char *fformat, char *tit, int runmin, int runmax, int nbins=1500, int hmin=-500, int hmax=1000, int sign=1, double hc=0, int xmin=1, int xmax=NC-1, int ymin=1, int ymax=NR-1, int cmsub=0, int hitfinder=1) { - - moench02ModuleData *decoder=new moench02ModuleData(hc); - moenchCommonMode *cmSub=NULL; - if (cmsub) - cmSub=new moenchCommonMode(); - - int nph=0; - - singlePhotonDetector *filter=new singlePhotonDetector(decoder, 3, 5, sign, cmSub); - - char *buff; - char fname[10000]; - int nf=0; - - eventType thisEvent=PEDESTAL; - - // int iframe; - // double *data, ped, sigma; - - // data=decoder->getCluster(); - - TH2F *h2; - TH2F *h3; - TH2F *hetaX; - TH2F *hetaY; - - THStack *hs=new THStack("hs",fformat); - - - - TH2F *h1=new TH2F("h1",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - hs->Add(h1); - - if (hitfinder) { - h2=new TH2F("h2",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - h3=new TH2F("h3",tit,nbins,hmin-0.5,hmax-0.5,NC*NR,-0.5,NC*NR-0.5); - hetaX=new TH2F("hetaX",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); - hetaY=new TH2F("hetaY",tit,nbins,-1,2,NC*NR,-0.5,NC*NR-0.5); - hs->Add(h2); - hs->Add(h3); - hs->Add(hetaX); - hs->Add(hetaY); - } - - - - ifstream filebin; - - - int ix=20, iy=20, ir, ic; - - - Int_t iFrame; - TTree *tall; - if (hitfinder) - tall=filter->initEventTree(tit, &iFrame); - - - - -#ifdef MY_DEBUG - - TCanvas *myC; - TH2F *he; - TCanvas *cH1; - TCanvas *cH2; - TCanvas *cH3; - - if (hitfinder) { - myC=new TCanvas(); - he=new TH2F("he","Event Mask",xmax-xmin, xmin, xmax, ymax-ymin, ymin, ymax); - he->SetStats(kFALSE); - he->Draw("colz"); - cH1=new TCanvas(); - cH1->SetLogz(); - h1->Draw("colz"); - cH2=new TCanvas(); - cH2->SetLogz(); - h2->Draw("colz"); - cH3=new TCanvas(); - cH3->SetLogz(); - h3->Draw("colz"); - } -#endif - filter->newDataSet(); - - - for (int irun=runmin; irunreadNextFrame(filebin))) { - - - if (hitfinder) { - filter->newFrame(); - - //calculate pedestals and common modes - if (cmsub) { - // cout << "cm" << endl; - for (ix=xmin-1; ixgetEventType(buff, ix, iy,0); - } - } - } - - // cout << "new frame " << endl; - - for (ix=xmin-1; ixgetEventType(buff, ix, iy, cmsub); - -#ifdef MY_DEBUG - if (hitfinder) { - if (iev%1000==0) - he->SetBinContent(ix+1-xmin, iy+1-ymin, (int)thisEvent); - } -#endif - - if (nf>1000) { - h1->Fill(filter->getClusterTotal(1), iy+NR*ix); - if (hitfinder) { - - if (thisEvent==PHOTON_MAX ) { - nph++; - - h2->Fill(filter->getClusterTotal(2), iy+NR*ix); - h3->Fill(filter->getClusterTotal(3), iy+NR*ix); - iFrame=decoder->getFrameNumber(buff); - - tall->Fill(); - - - } - - - } - - - } - } - ////////////////////////////////////////////////////////// - -#ifdef MY_DEBUG - if (iev%1000==0) { - myC->Modified(); - myC->Update(); - cH1->Modified(); - cH1->Update(); - cH2->Modified(); - cH2->Update(); - cH3->Modified(); - cH3->Update(); - } - iev++; -#endif - nf++; - - cout << "=" ; - delete [] buff; - } - cout << nph << endl; - if (filebin.is_open()) - filebin.close(); - else - cout << "could not open file " << fname << endl; - } - if (hitfinder) - tall->Write(tall->GetName(),TObject::kOverwrite); - - - - delete decoder; - cout << "Read " << nf << " frames" << endl; - return hs; -} - diff --git a/slsReceiverSoftware/slsDetectorCalibration/moenchReadDataMT.C b/slsReceiverSoftware/slsDetectorCalibration/moenchReadDataMT.C deleted file mode 100644 index 0720909c4e..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/moenchReadDataMT.C +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include "moenchReadData.C" - -typedef struct task_s{ - char *fformat; - char *tname; - char *tdir; - int runmin; - int runmax; - int treeIndex; -} Task; - -void *moenchMakeTreeTask(void *p){ - TThread::Lock(); - char fname[1000]; - Task *t = (Task *)p; - sprintf(fname,"%s%s_%i.root",t->tdir,t->tname,t->treeIndex); - TFile *f = new TFile(fname,"RECREATE"); - cout << "Call moenchReadData(" << t->fformat << "," << t->tname << "," << t->runmin<< "," << t->runmax <<")" << endl; - TThread::UnLock(); - moenchReadData(t->fformat,t->tname,t->runmin,t->runmax); - f->Close(); - return 0; -} - - -void moenchReadDataMT(char *fformat, char *tit, char *tdir, int runmin, int runoffset, int nThreads, int treeIndexStart=0){ - char threadName[1000]; - TThread *threads[nThreads]; - for(int i = 0; i < nThreads; i++){ - sprintf(threadName,"t%i",i); - Task *t = (Task *)malloc(sizeof(Task)); - t->fformat = fformat; - t->tname = tit; - t->tdir = tdir; - t->runmin = runmin + i*runoffset; - t->runmax = runmin + (i+1)*runoffset - 1; - t->treeIndex = treeIndexStart + i; - cout << "start thread " << i << " start: " << t->runmin << " end " << t->runmax << endl; - threads[i] = new TThread(threadName, moenchMakeTreeTask, t); - threads[i]->Run(); - } - - for(int i = 0; i < nThreads; i++){ - threads[i]->Join(); - } - -} - - - diff --git a/slsReceiverSoftware/slsDetectorCalibration/pedestalSubtraction.h b/slsReceiverSoftware/slsDetectorCalibration/pedestalSubtraction.h deleted file mode 100644 index ee3aff8aa8..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/pedestalSubtraction.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef PEDESTALSUBTRACTION_H -#define PEDESTALSUBTRACTION_H - -#include "MovingStat.h" - -class pedestalSubtraction { - /** @short class defining the pedestal subtraction based on an approximated moving average */ - public: - /** constructor - \param nn number of samples to calculate the moving average (defaults to 1000) - */ - pedestalSubtraction (int nn=1000) : stat(nn) {}; - - /** virtual destructorr - */ - virtual ~pedestalSubtraction() {}; - - /** clears the moving average */ - virtual void Clear() {stat.Clear();} - - /** adds the element to the moving average - \param val value to be added - */ - virtual void addToPedestal(double val){stat.Calc(val);}; - - /** returns the average value of the pedestal - \returns mean of the moving average - */ - virtual double getPedestal(){return stat.Mean();}; - - /** returns the standard deviation of the moving average - \returns standard deviation of the moving average - */ - virtual double getPedestalRMS(){return stat.StandardDeviation();}; - - /**sets/gets the number of samples for the moving average - \param i number of elements for the moving average. If -1 (default) or negative, gets. - \returns actual number of samples for the moving average - */ - virtual int SetNPedestals(int i=-1) {if (i>0) stat.SetN(i); return stat.GetN();}; - - - - private: - MovingStat stat; /**< approximated moving average struct */ - -}; -#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/raedNoiseData.C b/slsReceiverSoftware/slsDetectorCalibration/raedNoiseData.C deleted file mode 100644 index b2021b29fe..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/raedNoiseData.C +++ /dev/null @@ -1,136 +0,0 @@ -#include "moenchReadData.C" - - - -void raedNoiseData(char *tit, int sign=1){ - - - - - - char fname[1000]; - char f[1000]; - TFile *fout; - THStack *hs2N; - - sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_0.root",tit); - fout=new TFile(fname,"RECREATE"); - - sprintf(fname,"/data/moench_xbox_20140113/MoTarget_45kV_0_8mA_120V_%s_f00000%%04d000_0.raw",tit); - - hs2N=moenchReadData(fname,0,3000,1500,-500,2500,1,0.,1,159,1,159, 0,1); - hs2N->SetName(tit); - hs2N->SetTitle(tit); - (TH2F*)(hs2N->GetHists()->At(0))->Write(); - - (TH2F*)(hs2N->GetHists()->At(1))->Write(); - (TH2F*)(hs2N->GetHists()->At(2))->Write(); - (TH2F*)(hs2N->GetHists()->At(3))->Write(); - (TH2F*)(hs2N->GetHists()->At(4))->Write(); - - - fout->Close(); - - - -} - - - -void raedNoiseDataN(char *tit, int sign=1){ - - - - char fname[1000]; - char f[1000]; - TFile *fout; - THStack *hs2N; - - sprintf(fname,"/data/moench_xbox_20140116/noise_%s.root",tit); - fout=new TFile(fname,"RECREATE"); - - sprintf(fname,"/data/moench_xbox_20140116/noise_%s_f00000%%04d000_0.raw",tit); - - hs2N=moenchReadData(fname,tit,0,3000,1500,-500,2500,sign,0.,1,159,1,159, 0,0); - hs2N->SetName(tit); - hs2N->SetTitle(tit); - (TH2F*)(hs2N->GetHists()->At(0))->Write(); - - // (TH2F*)(hs2N->GetHists()->At(1))->Write(); - // (TH2F*)(hs2N->GetHists()->At(2))->Write(); - // (TH2F*)(hs2N->GetHists()->At(3))->Write(); - // (TH2F*)(hs2N->GetHists()->At(4))->Write(); - - - fout->Close(); - - - -} - - - -void g4() { - - raedNoiseData("cds_g4_low_gain"); - raedNoiseData("cds_g4_sto1_only"); - raedNoiseData("cds_g4_no sto"); - - - -} - -void no_cds() { - - raedNoiseData("cds_disable_low_gain",-1); - raedNoiseData("cds_disable_sto1_only",-1); - raedNoiseData("cds_disable_no sto",-1); - - - -} - -void all_gains() { - - raedNoiseData("cds_g2"); - raedNoiseData("cds_g2HC"); - raedNoiseData("cds_g1_2"); - raedNoiseData("cds_g2_3"); - - - -} - -void all_low_gains() { - - raedNoiseData("cds_g2_low_gain"); - raedNoiseData("cds_g2HC_low_gain"); - raedNoiseData("cds_g1_2_low_gain"); - raedNoiseData("cds_g2_3_low_gain"); -} - -/* -clkdivider data -/data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv17_f000000010000_0.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 12:40 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv25_f000000010000_0.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 13:26 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv35_f000000010000_0.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:09 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv50_f000000010000_0.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 14:54 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv70_f000000010000_0.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 16:42 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv110_f000000010000_0.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 17:27 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_cds_g1_clkdiv170_f000000010000_0.raw -*/ - - -/* oversampled data --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:12 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_0.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 18:47 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_1.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 19:22 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_2.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:02 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_3.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 20:41 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_4.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:16 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_5.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 21:56 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_6.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 22:35 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_7.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:11 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_8.raw --rw-rw-r-- 1 l_msdetect l_msdetect 51440000 Jan 14 23:50 /data/moench_xbox_20140114/MoTarget_45kV_0_8mA_12us_120V_os10_16rows_f000000010000_9.raw -*/ - diff --git a/slsReceiverSoftware/slsDetectorCalibration/readJungfrauData.C b/slsReceiverSoftware/slsDetectorCalibration/readJungfrauData.C deleted file mode 100644 index 504a152586..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/readJungfrauData.C +++ /dev/null @@ -1,31 +0,0 @@ -{ // script to run Jungfrau data analysis - - gROOT->ProcessLine(".L jungfrauReadData.C++");//"); - - TFile *fout; // output file - THStack *hs2N; // collection of objects - - //fout=new TFile("/mnt/slitnas/datadir_jungfrau02/analysis_tests/tests_random.root","RECREATE"); // - fout=new TFile("/mnt/slitnas/datadir_jungfrau02/20140404_lowEXrays/test.root","RECREATE"); - - hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140404_lowEXrays/Ti_1000clk_13kV40mA_%d.bin","tit",0,86,3000,-499.5,2500.5,1,0,1,47,1,47,1,1); //1,1); - - //hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/20140228_GainBits/GSdata_laser_%d.bin","tit",0,5,1500,-500,2500,1,0.,1,47,1,47,0,1);//,"/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); //1,1); // data set test GB -> set (3,0,0) in junfrauReadData.C - - //hs2N=jungfrauReadData("/mnt/slitnas/datadir_jungfrau02/digital_bit_adc_test/vb_1825_%d.bin","tit",0,7,1500,-500,2500,1,0.,1,47,1,47,0,1);//,"/mnt/slitnas/datadir_jungfrau02/analysis_tests/CalibrationParametersTest_fake.txt"); //1,1); // data set test GB -> set (3,0,0) in junfrauReadData.C - - //hs2N->SetName("cds_g4"); - //hs2N->SetTitle("cds_g4"); - - (TH2F*)(hs2N->GetHists()->At(0))->Write(); // write hists - (TH2F*)(hs2N->GetHists()->At(1))->Write(); - (TH2F*)(hs2N->GetHists()->At(2))->Write(); - (TH2F*)(hs2N->GetHists()->At(3))->Write(); - (TH2F*)(hs2N->GetHists()->At(4))->Write(); - //(TH2F*)(hs2N->GetHists()->At(5))->Write(); - //(TH2F*)(hs2N->GetHists()->At(6))->Write(); - - fout->Close(); // uncomment - -} - diff --git a/slsReceiverSoftware/slsDetectorCalibration/singlePhotonDetector.h b/slsReceiverSoftware/slsDetectorCalibration/singlePhotonDetector.h deleted file mode 100644 index f090730a10..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/singlePhotonDetector.h +++ /dev/null @@ -1,387 +0,0 @@ -#ifndef SINGLEPHOTONDETECTOR_H -#define SINGLEPHOTONDETECTOR_H - - -#include "slsDetectorData.h" - -#include "single_photon_hit.h" -#include "pedestalSubtraction.h" -#include "commonModeSubtraction.h" - - -//#define MYROOT1 - -#ifdef MYROOT1 -#include - -#endif - - -#include - -using namespace std; - - - enum eventType { - PEDESTAL=0, - NEIGHBOUR=1, - PHOTON=2, - PHOTON_MAX=3, - NEGATIVE_PEDESTAL=4, - UNDEFINED_EVENT=-1 - }; - - enum quadrant { - TOP_LEFT=0, - TOP_RIGHT=1, - BOTTOM_LEFT=2, - BOTTOM_RIGHT=3, - UNDEFINED_QUADRANT=-1 - }; - - - -template -class singlePhotonDetector { - - /** @short class to perform pedestal subtraction etc. and find single photon clusters for an analog detector */ - - public: - - - /** - - Constructor (no error checking if datasize and offsets are compatible!) - \param d detector data structure to be used - \param csize cluster size (should be an odd number). Defaults to 3 - \param nsigma number of rms to discriminate from the noise. Defaults to 5 - \param sign 1 if photons are positive, -1 if negative - \param cm common mode subtraction algorithm, if any. Defaults to NULL i.e. none - \param nped number of samples for pedestal averaging - \param nd number of dark frames to average as pedestals without photon discrimination at the beginning of the measurement - - - */ - - - singlePhotonDetector(slsDetectorData *d, - int csize=3, - double nsigma=5, - int sign=1, - commonModeSubtraction *cm=NULL, - int nped=1000, - int nd=100) : det(d), nx(0), ny(0), stat(NULL), cmSub(cm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), cluster(NULL), iframe(-1), dataSign(sign), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0) { - - - det->getDetectorSize(nx,ny); - - - - stat=new pedestalSubtraction*[ny]; - eventMask=new eventType*[ny]; - for (int i=0; iSetNPedestals(nped); - eventMask[i]=new eventType[nx]; - } - - if (ny==1) - clusterSizeY=1; - - cluster=new single_photon_hit(clusterSize,clusterSizeY); - setClusterSize(csize); - - }; - /** - destructor. Deletes the cluster structure and the pdestalSubtraction array - */ - virtual ~singlePhotonDetector() {delete cluster; for (int i=0; iClear(); }; - - /** resets the eventMask to undefined and the commonModeSubtraction */ - void newFrame(){iframe++; for (int iy=0; iynewFrame();}; - - - /** sets the commonModeSubtraction algorithm to be used - \param cm commonModeSubtraction algorithm to be used (NULL unsets) - \returns pointer to the actual common mode subtraction algorithm - */ - commonModeSubtraction setCommonModeSubtraction(commonModeSubtraction *cm) {cmSub=cm; return cmSub;}; - - - /** - sets the sign of the data - \param sign 1 means positive values for photons, -1 negative, 0 gets - \returns current sign for the data - */ - int setDataSign(int sign=0) {if (sign==1 || sign==-1) dataSign=sign; return dataSign;}; - - - /** - adds value to pedestal (and common mode) for the given pixel - \param val value to be added - \param ix pixel x coordinate - \param iy pixel y coordinate - */ - virtual void addToPedestal(double val, int ix, int iy){ - // cout << "*"<< ix << " " << iy << " " << val << endl; - if (ix>=0 && ix=0 && iyisGood(ix, iy) ) - cmSub->addToCommonMode(val, ix, iy); - }; - }; - - /** - gets pedestal (and common mode) - \param ix pixel x coordinate - \param iy pixel y coordinate - \param cm 0 (default) without common mode subtraction, 1 with common mode subtraction (if defined) - */ - virtual double getPedestal(int ix, int iy, int cm=0){if (ix>=0 && ix=0 && iy0) return stat[iy][ix].getPedestal()-cmSub->getCommonMode(); else return stat[iy][ix].getPedestal(); else return -1;}; - - /** - gets pedestal rms (i.e. noise) - \param ix pixel x coordinate - \param iy pixel y coordinate - */ - double getPedestalRMS(int ix, int iy){if (ix>=0 && ix=0 && iy0) nSigma=n; return nSigma;} - - /** sets/gets cluster size - \param n cluster size to be set, (0 or negative gets). If even is incremented by 1. - \returns actual cluster size - */ - int setClusterSize(int n=-1){ - if (n>0 && n!=clusterSize) { - if (n%2==0) - n+=1; - clusterSize=n; - if (cluster) - delete cluster; - if (ny>1) - clusterSizeY=clusterSize; - cluster=new single_photon_hit(clusterSize,clusterSizeY); - } - return clusterSize; - } - - - - - /** finds event type for pixel and fills cluster structure. The algorithm loops only if the evenMask for this pixel is still undefined. - if pixel or cluster around it are above threshold (nsigma*pedestalRMS) cluster is filled and pixel mask is PHOTON_MAX (if maximum in cluster) or NEIGHBOUR; If PHOTON_MAX, the elements of the cluster are also set as NEIGHBOURs in order to speed up the looping - if below threshold the pixel is either marked as PEDESTAL (and added to the pedestal calculator) or NEGATIVE_PEDESTAL is case it's lower than -threshold, otherwise the pedestal average would drift to negative values while it should be 0. - - /param data pointer to the data - /param ix pixel x coordinate - /param iy pixel y coordinate - /param cm enable(1)/disable(0) common mode subtraction (if defined). - /returns event type for the given pixel - */ - eventType getEventType(char *data, int ix, int iy, int cm=0) { - - // eventType ret=PEDESTAL; - double max=0, tl=0, tr=0, bl=0,br=0, v; - // cout << iframe << endl; - - tot=0; - quadTot=0; - quad=UNDEFINED_QUADRANT; - - - if (iframex=ix; - cluster->y=iy; - cluster->rms=getPedestalRMS(ix,iy); - cluster->ped=getPedestal(ix,iy, cm); - - - for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { - for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { - if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(dataSign*(det->getValue(data, ix+ic, iy+ir)-getPedestal(ix+ic,iy+ir,cm)), ic, ir ); - v=cluster->get_data(ic,ir); - tot+=v; - if (ir<=0 && ic<=0) - bl+=v; - if (ir<=0 && ic>=0) - br+=v; - if (ir>=0 && ic<=0) - tl+=v; - if (ir>=0 && ic>=0) - tr+=v; - - if (cluster->get_data(ic,ir)>max) { - max=v; - } - if (ir==0 && ic==0) { - if (v>nSigma*cluster->rms) { - eventMask[iy][ix]=PHOTON; - } else if (cluster->get_data(ic,ir)<-nSigma*cluster->rms) - eventMask[iy][ix]=NEGATIVE_PEDESTAL; - } - } - } - } - - if (eventMask[iy][ix]!=PHOTON && tot>sqrt(clusterSizeY*clusterSize)*nSigma*cluster->rms) { - eventMask[iy][ix]=NEIGHBOUR; - } else if (eventMask[iy][ix]==PHOTON) { - if (cluster->get_data(0,0)>=max) { - eventMask[iy][ix]=PHOTON_MAX; - } - } else if (eventMask[iy][ix]==PEDESTAL) { - if (cm==0) - addToPedestal(det->getValue(data, ix, iy),ix,iy); - } - - - if (bl>=br && bl>=tl && bl>=tr) { - quad=BOTTOM_LEFT; - quadTot=bl; - } else if (br>=bl && br>=tl && br>=tr) { - quad=BOTTOM_RIGHT; - quadTot=br; - } else if (tl>=br && tl>=bl && tl>=tr) { - quad=TOP_LEFT; - quadTot=tl; - } else if (tr>=bl && tr>=tl && tr>=br) { - quad=TOP_RIGHT; - quadTot=tr; - } - - - return eventMask[iy][ix]; - - }; - - /**< - retrurns the total signal in a cluster - \param size cluser size should be 1,2 or 3 - \returns cluster center if size=1, sum of the maximum quadrant if size=2, total of the cluster if size=3 or anything else - */ - - double getClusterTotal(int size) { - switch (size) { - case 1: - return getClusterElement(0,0); - case 2: - return quadTot; - default: - return tot; - }; - }; - - /**< - retrurns the quadrant with maximum signal - \returns quadrant where the cluster is located */ - - quadrant getQuadrant() {return quad;}; - - /** sets/gets number of samples for moving average pedestal calculation - \param i number of samples to be set (0 or negative gets) - \returns actual number of samples - */ - int SetNPedestals(int i=-1) {int ix=0, iy=0; if (i>0) for (ix=0; ixget_data(ic,ir);}; - - /** returns event mask for the given pixel - \param ic x coordinate (center is (0,0)) - \param ir y coordinate (center is (0,0)) - \returns event mask enum for the given pixel - */ - eventType getEventMask(int ic, int ir=0){return eventMask[ir][ic];}; - - -#ifdef MYROOT1 - /** generates a tree and maps the branches - \param tname name for the tree - \param iFrame pointer to the frame number - \returns returns pointer to the TTree - */ - TTree *initEventTree(char *tname, int *iFrame=NULL) { - TTree* tall=new TTree(tname,tname); - - if (iFrame) - tall->Branch("iFrame",iFrame,"iframe/I"); - else - tall->Branch("iFrame",&(cluster->iframe),"iframe/I"); - - tall->Branch("x",&(cluster->x),"x/I"); - tall->Branch("y",&(cluster->y),"y/I"); - char tit[100]; - sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY); - tall->Branch("data",cluster->data,tit); - tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); - tall->Branch("rms",&(cluster->rms),"rms/D"); - return tall; - }; -#else - /** write cluster to filer*/ - void writeCluster(FILE* myFile){cluster->write(myFile);}; - -#endif - - - private: - - slsDetectorData *det; /**< slsDetectorData to be used */ - int nx; /**< Size of the detector in x direction */ - int ny; /**< Size of the detector in y direction */ - - - pedestalSubtraction **stat; /**< pedestalSubtraction class */ - commonModeSubtraction *cmSub;/**< commonModeSubtraction class */ - int nDark; /**< number of frames to be used at the beginning of the dataset to calculate pedestal without applying photon discrimination */ - eventType **eventMask; /**< matrix of event type or each pixel */ - double nSigma; /**< number of sigma parameter for photon discrimination */ - int clusterSize; /**< cluster size in the x direction */ - int clusterSizeY; /**< cluster size in the y direction i.e. 1 for strips, clusterSize for pixels */ - single_photon_hit *cluster; /**< single photon hit data structure */ - int iframe; /**< frame number (not from file but incremented within the dataset every time newFrame is called */ - int dataSign; /**< sign of the data i.e. 1 if photon is positive, -1 if negative */ - quadrant quad; /**< quadrant where the photon is located */ - double tot; /**< sum of the 3x3 cluster */ - double quadTot; /**< sum of the maximum 2x2cluster */ - - -}; - - - - - -#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/single_photon_hit.h b/slsReceiverSoftware/slsDetectorCalibration/single_photon_hit.h deleted file mode 100644 index dda4d75714..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/single_photon_hit.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef SINGLE_PHOTON_HIT_H -#define SINGLE_PHOTON_HIT_h - -typedef double double32_t; -typedef float float32_t; -typedef int int32_t; - - -class single_photon_hit { - - /** @short Structure for a single photon hit */ - - public: - /** constructor, instantiates the data array -- all class elements are public! - \param nx cluster size in x direction - \param ny cluster size in y direction (defaults to 1 for 1D detectors) - */ - single_photon_hit(int nx, int ny=1): dx(nx), dy(ny) {data=new double[dx*dy];}; - - ~single_photon_hit(){delete [] data;}; /**< destructor, deletes the data array */ - - /** binary write to file of all elements of the structure, except size of the cluster - \param myFile file descriptor - */ - void write(FILE *myFile) {fwrite((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fwrite((void*)data, 1, dx*dy*sizeof(double), myFile);}; - - /** - binary read from file of all elements of the structure, except size of the cluster. The structure is then filled with those args - \param myFile file descriptor - */ - void read(FILE *myFile) {fread((void*)this, 1, 3*sizeof(int)+2*sizeof(double), myFile); fread((void*)data, 1, dx*dy*sizeof(double), myFile);}; - - /** - assign the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0) - \param v value to be set - \param ix coordinate x within the cluster (center is (0,0)) - \param iy coordinate y within the cluster (center is (0,0)) - */ - void set_data(double v, int ix, int iy=0){data[(iy+dy/2)*dx+ix+dx/2]=v;}; - - - /** - gets the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0) - \param ix coordinate x within the cluster (center is (0,0)) - \param iy coordinate y within the cluster (center is (0,0)) - \returns value of the cluster element - */ - double get_data(int ix, int iy=0){return data[(iy+dy/2)*dx+ix+dx/2];}; - - int x; /**< x-coordinate of the center of hit */ - int y; /**< x-coordinate of the center of hit */ - double rms; /**< noise of central pixel l -- at some point it can be removed*/ - double ped; /**< pedestal of the central pixel -- at some point it can be removed*/ - int iframe; /**< frame number */ - double *data; /**< pointer to data */ - const int dx; /**< size of data cluster in x */ - const int dy; /**< size of data cluster in y */ -}; - - - -#endif diff --git a/slsReceiverSoftware/slsDetectorCalibration/slsDetectorData.h b/slsReceiverSoftware/slsDetectorCalibration/slsDetectorData.h deleted file mode 100644 index 294f7c8717..0000000000 --- a/slsReceiverSoftware/slsDetectorCalibration/slsDetectorData.h +++ /dev/null @@ -1,251 +0,0 @@ -#ifndef SLSDETECTORDATA_H -#define SLSDETECTORDATA_H - -#include -#include -#include - -using namespace std; - - -template -class slsDetectorData { - - - public: - - /** - - - General slsDetectors data structure. Works for data acquired using the slsDetectorReceiver. Can be generalized to other detectors (many virtual funcs). - - Constructor (no error checking if datasize and offsets are compatible!) - \param npx number of pixels in the x direction - \param npy number of pixels in the y direction (1 for strips) - \param dsize size of the data - \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) - \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) - \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. - - */ - slsDetectorData(int npx, int npy, int dsize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), dataSize(dsize) { - - - - dataMask=new dataType*[ny]; - for(int i = 0; i < ny; i++) { - dataMask[i] = new dataType[nx]; - } - dataMap=new int*[ny]; - for(int i = 0; i < ny; i++) { - dataMap[i] = new int[nx]; - } - - dataROIMask=new int*[ny]; - for(int i = 0; i < ny; i++) { - dataROIMask[i] = new int[nx]; - for (int j=0; j=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && dataMap[iy][ix] -class slsReceiverData : public slsDetectorData { - - -public: - - /** - slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers. - Inherits and implements slsDetectorData. - - Constructor (no error checking if datasize and offsets are compatible!) - \param npx number of pixels in the x direction - \param npy number of pixels in the y direction (1 for strips) - \param np number of packets - \param psize packets size - \param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset) - \param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) - \param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s. - - */ - slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {}; - - - /** - - Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded. - \param buff pointer to the dataset - \returns frame number - - */ - - virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; - - /** - - Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded. - \param buff pointer to the dataset - \returns packet number number - - */ - - virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;}; - - - - - /** - - Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! - \param data pointer to the memory to be analyzed - \param ndata size of frame returned - \param dsize size of the memory slot to be analyzed - \returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found - - */ - - virtual char *findNextFrame(char *data, int &ndata, int dsize) { - char *retval=NULL, *p=data; - int dd=0; - int fn, fnum=-1, np=0, pnum=-1; - while (dd<=(dsize-packetSize)) { - pnum=getPacketNumber(p); - fn=getFrameNumber(p); - - - if (pnum<1 || pnum>nPackets) { - cout << "Bad packet number " << pnum << " frame "<< fn << endl; - retval=NULL; - np=0; - } else if (pnum==1) { - retval=p; - if (np>0) - /*cout << "*Incomplete frame number " << fnum << endl;*/ - np=0; - fnum=fn; - } else if (fn!=fnum) { - if (fnum!=-1) { - /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ - retval=NULL; - } - np=0; - } - p+=packetSize; - dd+=packetSize; - np++; - // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; - if (np==nPackets) - if (pnum==nPackets) { - // cout << "Frame found!" << endl; - break; - } else { - cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; - retval=NULL; - } - } - if (np0) - cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; - } - - ndata=np*packetSize; - // cout << "return " << ndata << endl; - return retval; - }; - - /** - - Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! - \param filebin input file stream (binary) - \returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete - - */ - - virtual char *readNextFrame(ifstream &filebin) { - char *data=new char[packetSize*nPackets]; - char *retval=0; - int np=0, nd; - - if (filebin.is_open()) { - while (filebin.read(data+np*packetSize,packetSize)) { - - if (np==(nPackets-1)) { - - retval=findNextFrame(data,nd,packetSize*nPackets); - np=nd/packetSize; - // cout << np << endl; - - - if (retval==data && np==nPackets) { - // cout << "-" << endl; - return data; - - } else if (np>nPackets) { - cout << "too many packets!!!!!!!!!!" << endl; - delete [] data; - return NULL; - } else if (retval!=NULL) { - // cout << "+" << endl;; - for (int ip=0; ipnPackets) { - cout << "*******too many packets!!!!!!!!!!" << endl; - delete [] data; - return NULL; - } else { - // cout << "." << endl;; - np++; - } - } - } - delete [] data; - return NULL; - }; - - - -private: - const int nPackets; /** Date: Fri, 18 Jul 2014 12:27:32 +0200 Subject: [PATCH 013/222] added receiver interface, have not separated from eigerDummyReceiver yet --- slsReceiverSoftware/.gitignore | 1 + slsReceiverSoftware/Makefile | 3 +- slsReceiverSoftware/slsReceiver/Makefile | 2 +- slsReceiverSoftware/slsReceiver/main.cpp | 90 +++++ .../slsReceiver/slsReceiver.cpp | 102 ++--- slsReceiverSoftware/slsReceiver/slsReceiver.h | 89 +++++ .../slsReceiver/slsReceiverBase.h | 335 +++++++++++++++++ .../slsReceiver/slsReceiverTCPIPInterface.cpp | 127 ++++--- .../slsReceiver/slsReceiverTCPIPInterface.h | 17 +- .../slsReceiver/slsReceiverUDPFunctions.cpp | 347 +++++++----------- .../slsReceiver/slsReceiverUDPFunctions.h | 63 +++- .../slsReceiver/slsReceiverUsers.cpp | 8 +- .../slsReceiver/slsReceiverUsers.h | 5 +- slsReceiverSoftware/slsReceiverUsers.doxy | 86 +++++ 14 files changed, 911 insertions(+), 364 deletions(-) create mode 100644 slsReceiverSoftware/slsReceiver/main.cpp create mode 100644 slsReceiverSoftware/slsReceiver/slsReceiver.h create mode 100644 slsReceiverSoftware/slsReceiver/slsReceiverBase.h create mode 100644 slsReceiverSoftware/slsReceiverUsers.doxy diff --git a/slsReceiverSoftware/.gitignore b/slsReceiverSoftware/.gitignore index 5761abcfdf..ccb33f18f2 100644 --- a/slsReceiverSoftware/.gitignore +++ b/slsReceiverSoftware/.gitignore @@ -1 +1,2 @@ *.o +slsDetectorCalibration diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index f8df056397..4aa0c3fdec 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -14,7 +14,7 @@ DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -IslsReceiver/eigerReceiver -I$(ASM) #-IslsReceiverInterface -SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/slsReceiverUDPFunctions.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiverUsers.cpp +SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUDPFunctions.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiverUsers.cpp #slsReceiverInterface/receiverInterface.cpp OBJS = $(SRC_CLNT:.cpp=.o) @@ -44,6 +44,7 @@ endif package: eigerReceiver $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a eigerReceiver: + echo "src client:" $(SRC_CLNT) cd slsReceiver && make eigerReceiver $(DESTDIR)/libSlsReceiver.so: $(OBJS) diff --git a/slsReceiverSoftware/slsReceiver/Makefile b/slsReceiverSoftware/slsReceiver/Makefile index 92428c9571..d5f02c2ea6 100644 --- a/slsReceiverSoftware/slsReceiver/Makefile +++ b/slsReceiverSoftware/slsReceiver/Makefile @@ -14,7 +14,7 @@ LDFLAGRXR += -lm -lstdc++ INCLUDES ?= -I ../MySocketTCP -I ../slsDetectorCalibration -I ../includes -I eigerReceiver -I . -SRC_CLNT = slsReceiver.cpp +SRC_CLNT = main.cpp INSTMODE = 0777 diff --git a/slsReceiverSoftware/slsReceiver/main.cpp b/slsReceiverSoftware/slsReceiver/main.cpp new file mode 100644 index 0000000000..3513a26c74 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/main.cpp @@ -0,0 +1,90 @@ +/* A simple server in the internet domain using TCP + The port number is passed as an argument */ + +#include "sls_receiver_defs.h" +#include "slsReceiverUsers.h" + +#include +#include +using namespace std; + + + + + + +int main(int argc, char *argv[]) { + int ret = slsReceiverDefs::OK; + + slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret); + + if(ret==slsReceiverDefs::FAIL) + return -1; + + + //register callbacks + + + /** + callback arguments are + filepath + filename + fileindex + datasize + + return value is + 0 raw data ready callback takes care of open,close,write file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + + + registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); + */ + + //receiver->registerCallBackStartAcquisition(func,arg); + + + /** + callback argument is + total farmes caught + registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); + */ + + + //receiver->registerCallBackAcquisitionFinished(func,arg); + + + + /** + args to raw data ready callback are + framenum + datapointer + file descriptor + guidatapointer (NULL, no data required) + + NEVER DELETE THE DATA POINTER + REMEMBER THAT THE CALLBACK IS BLOCKING + + registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg); + + */ + + //receiver->registerCallBackRawDataReady(func,arg); + + + + //start tcp server thread + if(user->start() == slsReceiverDefs::OK){ + string str; + cin>>str; + //wait and look for an exit keyword + while(str.find("exit") == string::npos) + cin>>str; + //stop tcp server thread, stop udp socket + user->stop(); + } + + cout << "Goodbye!" << endl; + return 0; +} + diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp index 3513a26c74..9491c3a920 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp @@ -1,90 +1,60 @@ -/* A simple server in the internet domain using TCP - The port number is passed as an argument */ +/********************************************//** + * @file slsReceiver.cpp + * @short creates the UDP and TCP class objects + ***********************************************/ -#include "sls_receiver_defs.h" -#include "slsReceiverUsers.h" +#include "slsReceiver.h" +#include "slsReceiverUDPFunctions.h" +#include "eigerReceiver.h" -#include -#include -using namespace std; +slsReceiver::slsReceiver(int argc, char *argv[], int &success){ + //creating base receiver + cout << "SLS Receiver" << endl; + receiverBase = new slsReceiverUDPFunctions(); + //tcp ip interface + tcpipInterface = new slsReceiverTCPIPInterface(argc,argv,success,receiverBase); +} +slsReceiver::~slsReceiver() {if(receiverBase) delete receiverBase; if(tcpipInterface) delete tcpipInterface;} -int main(int argc, char *argv[]) { - int ret = slsReceiverDefs::OK; - - slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret); - - if(ret==slsReceiverDefs::FAIL) - return -1; - - - //register callbacks - - - /** - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 raw data ready callback takes care of open,close,write file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - - - registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); - */ - - //receiver->registerCallBackStartAcquisition(func,arg); - +int slsReceiver::start() { + return tcpipInterface->start(); +} - /** - callback argument is - total farmes caught - registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); - */ +void slsReceiver::stop() { + tcpipInterface->stop(); +} - //receiver->registerCallBackAcquisitionFinished(func,arg); +void slsReceiver::closeFile(int p) { + tcpipInterface->closeFile(p); +} - /** - args to raw data ready callback are - framenum - datapointer - file descriptor - guidatapointer (NULL, no data required) - NEVER DELETE THE DATA POINTER - REMEMBER THAT THE CALLBACK IS BLOCKING +int64_t slsReceiver::getReceiverVersion(){ + tcpipInterface->getReceiverVersion(); +} - registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg); - */ +void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ + tcpipInterface->registerCallBackStartAcquisition(func,arg); +} - //receiver->registerCallBackRawDataReady(func,arg); +void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ + tcpipInterface->registerCallBackAcquisitionFinished(func,arg); +} - //start tcp server thread - if(user->start() == slsReceiverDefs::OK){ - string str; - cin>>str; - //wait and look for an exit keyword - while(str.find("exit") == string::npos) - cin>>str; - //stop tcp server thread, stop udp socket - user->stop(); - } - cout << "Goodbye!" << endl; - return 0; +void slsReceiver::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ + tcpipInterface->registerCallBackRawDataReady(func,arg); } + diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.h b/slsReceiverSoftware/slsReceiver/slsReceiver.h new file mode 100644 index 0000000000..1ab8c764a7 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.h @@ -0,0 +1,89 @@ +/********************************************//** + * @file slsReceiver.h + * @short creates the UDP and TCP class objects + ***********************************************/ +#ifndef SLS_RECEIVER_H +#define SLS_RECEIVER_H + + +#include "slsReceiverTCPIPInterface.h" +#include "slsReceiverBase.h" + + + + +/** + *@short creates the UDP and TCP class objects + */ + +class slsReceiver : private virtual slsReceiverDefs { + +public: + /** + * Constructor + * creates the tcp interface and the udp class + * @param argc from command line + * @param argv from command line + * @param succecc socket creation was successfull + */ + slsReceiver(int argc, char *argv[], int &success); + + /** + * Destructor + */ + ~slsReceiver(); + + /** + * starts listening on the TCP port for client comminication + \return 0 for success or 1 for FAIL in creating TCP server + */ + int start(); + + /** + * stops listening to the TCP & UDP port and exit receiver program + */ + void stop(); + + /** + * Close File and exits receiver server + */ + void closeFile(int p); + + /** + * get get Receiver Version + \returns id + */ + int64_t getReceiverVersion(); + + /** + @sort register calbback for starting the acquisition + @param func callback to be called when starting the acquisition. Its arguments are filepath filename fileindex data size + \returns 0 callback takes care of open,close,write file; 1 callback writes file, we have to open, close it; 2 we open, close, write file, callback does not do anything + */ + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); + + + /** + callback argument is + toatal farmes caught + */ + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg); + + +private: + slsReceiverTCPIPInterface* tcpipInterface; + slsReceiverBase* receiverBase; +}; + + +#endif diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverBase.h b/slsReceiverSoftware/slsReceiver/slsReceiverBase.h new file mode 100644 index 0000000000..007bf4a970 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/slsReceiverBase.h @@ -0,0 +1,335 @@ +#ifndef SLSRECEIVERBASE_H +#define SLSRECEIVERBASE_H +/*********************************************** + * @file slsReceiverBase.h + * @short base class with all the functions for a receiver, set/get parameters, start/stop etc. + ***********************************************/ +/** + * \mainpage Base class with all the functions for a receiver, set/get parameters, start/stop etc. + */ + +/** + * @short base class with all the functions for a receiver, set/get parameters, start/stop etc. + */ + +class slsReceiverBase { + +public: + + /** + * constructor + */ + slsReceiverBase(){}; + + /** + * Destructor + */ + virtual ~slsReceiverBase() {}; + + /** + * Initialize the Receiver + @param detectorHostName detector hostname + * you can call this function only once. You must call it before you call startReceiver() for the first time. + */ + virtual void initialize(const char *detectorHostName) = 0; + + + /* Returns detector hostname + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ + virtual char *getDetectorHostname() const = 0; + + /** + * Returns status of receiver: idle, running or error + */ + virtual slsReceiverDefs::runStatus getStatus() const = 0; + + /** + * Returns File Name + * caller is responsible to deallocate the returned char array. + */ + virtual char *getFileName() const = 0; + + + /** + * Returns File Path + * caller is responsible to deallocate the returned char array + */ + virtual char *getFilePath() const = 0; //FIXME: Does the caller need to free() the returned pointer? + + + /** + * Returns the number of bits per pixel + */ + virtual int getDynamicRange() const = 0; + + /** + * Returns scan tag + */ + virtual int getScanTag() const = 0; + + /* + * Returns number of frames to receive + * This is the number of frames to expect to receiver from the detector. + * The data receiver will change from running to idle when it got this number of frames + */ + virtual int getNumberOfFrames() const = 0; + + /** + * Returns file write enable + * 1: YES 0: NO + */ + virtual int getEnableFileWrite() const = 0; + + /** + * Returns file over write enable + * 1: YES 0: NO + */ + virtual int getEnableOverwrite() const = 0; + + /** + * Set File Name (without frame index, file index and extension) + @param c file name + /returns file name + * returns NULL on failure (like bad file name) + * does not check the existence of the file - we don't know which path we'll finally use, so no point to check. + * caller is responsible to deallocate the returned char array. + */ + virtual char* setFileName(const char c[]) = 0; + + /** + * Set File Path + @param c file path + /returns file path + * checks the existence of the directory. returns NULL if directory does not exist or is not readable. + * caller is responsible to deallocate the returned char array. + */ + virtual char* setFilePath(const char c[]) = 0; + + /** + * Returns the number of bits per pixel + @param dr sets dynamic range + /returns dynamic range + * returns -1 on failure + * FIXME: what are the allowd values - should we use an enum as argument? + */ + virtual int setDynamicRange(const int dr) = 0; + + + /** + * Set scan tag + @param tag scan tag + /returns scan tag (always non-negative) + * FIXME: valid range - only positive? 16bit ore 32bit? + * returns -1 on failure + */ + virtual int setScanTag(const int tag) = 0; + + /** + * Sets number of frames + @param fnum number of frames + /returns number of frames + */ + virtual int setNumberOfFrames(const int fnum) = 0; + + /** + * Set enable file write + * @param i file write enable + /returns file write enable + */ + virtual int setEnableFileWrite(const int i) = 0; + + /** + * Set enable file overwrite + * @param i file overwrite enable + /returns file overwrite enable + */ + virtual int setEnableOverwrite(const int i) = 0; + + /** + * Starts Receiver - activate all configuration settings to the eiger receiver and start to listen for packets + @param message is the error message if there is an error + /returns 0 on success or -1 on failure + */ + //FIXME: success == 0 or success == 1? + virtual int startReceiver(char *message=NULL) = 0; //FIXME: who allocates message[]? + + /** + * Stops Receiver - stops listening for packets + /returns success + * same as abort(). Always returns 0. + */ + virtual int stopReceiver() = 0; + + /** + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + virtual void abort() = 0; + + + +/******************************************************************************************************************* + **************************************** Added by Dhanya ********************************************************* + *******************************************************************************************************************/ + + /** + * Returns File Index + */ + virtual int getFileIndex() = 0; + + /** + * Returns Total Frames Caught for an entire acquisition (including all scans) + */ + virtual int getTotalFramesCaught() = 0; + + /** + * Returns Frames Caught for each real time acquisition (eg. for each scan) + */ + virtual int getFramesCaught() = 0; + + /** + * Returns current Frame Index Caught for an entire acquisition (including all scans) + */ + virtual uint32_t getAcquisitionIndex() = 0; + + /** + * Returns the frame index at start of each real time acquisition (eg. for each scan) + */ + virtual uint32_t getStartFrameIndex() = 0; + + /** get data compression, by saving only hits + */ + virtual bool getDataCompression() = 0; + + /** + * Set receiver type + * @param det detector type + * Returns success or FAIL + */ + virtual int setDetectorType(slsReceiverDefs::detectorType det) = 0; + + /** + * Set File Index + * @param i file index + */ + virtual int setFileIndex(int i) = 0; + + /** set acquisition period if a positive number + */ + virtual int64_t setAcquisitionPeriod(int64_t index) = 0; + + /** + * Set Frame Index Needed + * @param i frame index needed + */ + virtual int setFrameIndexNeeded(int i) = 0; + + /** + * Set UDP Port Number + */ + virtual void setUDPPortNo(int p) = 0; + + /** + * Set Ethernet Interface or IP to listen to + */ + virtual void setEthernetInterface(char* c) = 0; + + /** + * Set short frame + * @param i if shortframe i=1 + */ + virtual int setShortFrame(int i) = 0; + + /** + * Set the variable to send every nth frame to gui + * or if 0,send frame only upon gui request + */ + virtual int setNFrameToGui(int i) = 0; + + /** + * Resets the Total Frames Caught + * This is how the receiver differentiates between entire acquisitions + * Returns 0 + */ + virtual void resetTotalFramesCaught() = 0; + + /** enabl data compression, by saving only hits + /returns if failed + */ + virtual int enableDataCompression(bool enable) = 0; + + /** + * enable 10Gbe + @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out + \returns enable for 10Gbe + */ + virtual int enableTenGiga(int enable = -1) = 0; + + /** + * Returns the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param fnum frame number for eiger as it is not in the packet + */ + virtual void readFrame(char* c,char** raw, uint32_t &fnum) = 0; + + /** set status to transmitting and + * when fifo is empty later, sets status to run_finished + */ + virtual void startReadout() = 0; + + /** + * shuts down the udp sockets + * \returns if success or fail + */ + virtual int shutDownUDPSockets() = 0; + + /** + * Closes all files + * @param ithr thread index, -1 for all threads + */ + virtual void closeFile(int ithr = -1) = 0; + + /** + * Call back for start acquisition + callback arguments are + filepath + filename + fileindex + datasize + + return value is + 0 callback takes care of open,close,wrie file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + */ + virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg) = 0; + + /** + * Call back for acquisition finished + callback argument is + total frames caught + */ + virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg) = 0; + + /** + * Call back for raw data + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg) = 0; + +protected: + +private: + +}; + +#endif /* #ifndef SLSRECEIVERBASE_H */ diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index 7039878223..da7d26cbb5 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -1,12 +1,13 @@ /********************************************//** - * @file slsReceiverTCPIPInterface.h + * @file slsReceiverTCPIPInterface.cpp * @short interface between receiver and client ***********************************************/ #include "slsReceiverTCPIPInterface.h" -#include "slsReceiverUDPFunctions.h" +#include "slsReceiverBase.h" #include "gitInfoReceiver.h" #include "slsReceiverUsers.h" +#include "slsReceiver.h" #include //SIGINT #include //EXIT @@ -27,9 +28,9 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { } -slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int &success): +slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int &success, slsReceiverBase* rbase): myDetectorType(GOTTHARD), - slsReceiverFunctions(NULL), + receiverBase(rbase), ret(OK), lockStatus(0), shortFrame(-1), @@ -165,7 +166,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int #ifdef VERBOSE cout << "Function table assigned." << endl; #endif - slsReceiverFunctions = new slsReceiverUDPFunctions(); //Catch signal SIGINT to close files properly signal(SIGINT,staticCloseFile); @@ -193,11 +193,11 @@ int slsReceiverTCPIPInterface::start(){ void slsReceiverTCPIPInterface::stop(){ cout << "Shutting down UDP Socket" << endl; - if(slsReceiverFunctions) - slsReceiverFunctions->shutDownUDPSockets(); + if(receiverBase) + receiverBase->shutDownUDPSockets(); cout << "Closing Files... " << endl; - slsReceiverFunctions->closeFile(); + receiverBase->closeFile(); cout<<"Shutting down TCP Socket and TCP thread"<shutDownUDPSockets(); + if(receiverBase) + receiverBase->shutDownUDPSockets(); cout << "Closing Files... " << endl; - slsReceiverFunctions->closeFile(); + receiverBase->closeFile(); pthread_exit(NULL); } @@ -417,7 +417,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){ } else{ myDetectorType = dr; - ret=slsReceiverFunctions->setDetectorType(dr); + ret=receiverBase->setDetectorType(dr); retval = myDetectorType; } } @@ -471,7 +471,7 @@ int slsReceiverTCPIPInterface::set_file_name() { ret=FAIL; } else - strcpy(retval,slsReceiverFunctions->setFileName(fName)); + strcpy(retval,receiverBase->setFileName(fName)); } #ifdef VERBOSE if(ret!=FAIL) @@ -520,12 +520,12 @@ int slsReceiverTCPIPInterface::set_file_dir() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; }/* - else if((strlen(fPath))&&(slsReceiverFunctions->getStatus()==RUNNING)){ + else if((strlen(fPath))&&(receiverBase->getStatus()==RUNNING)){ strcpy(mess,"Can not set file path while receiver running\n"); ret = FAIL; }*/ else{ - strcpy(retval,slsReceiverFunctions->setFilePath(fPath)); + strcpy(retval,receiverBase->setFilePath(fPath)); // if file path doesnt exist if(strlen(fPath)) if (strcmp(retval,fPath)){ @@ -584,7 +584,7 @@ int slsReceiverTCPIPInterface::set_file_index() { ret=FAIL; } else - retval=slsReceiverFunctions->setFileIndex(index); + retval=receiverBase->setFileIndex(index); } #ifdef VERBOSE if(ret!=FAIL) @@ -637,7 +637,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { ret=FAIL; } else - retval=slsReceiverFunctions->setFrameIndexNeeded(index); + retval=receiverBase->setFrameIndexNeeded(index); } #ifdef VERBOSE if(ret!=FAIL) @@ -693,14 +693,14 @@ int slsReceiverTCPIPInterface::setup_udp(){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else if(slsReceiverFunctions->getStatus()==RUNNING){ + else if(receiverBase->getStatus()==RUNNING){ ret = FAIL; strcpy(mess,"cannot set up udp when receiver is running\n"); } else{ //set up udp port sscanf(args[1],"%d",&udpport); - slsReceiverFunctions->setUDPPortNo(udpport); + receiverBase->setUDPPortNo(udpport); //setup udpip //get ethernet interface or IP to listen to @@ -716,7 +716,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ ret = FAIL; } cout<<"eth:"<setEthernetInterface(eth); + receiverBase->setEthernetInterface(eth); //get mac address from ethernet interface if (ret != FAIL) @@ -771,13 +771,13 @@ int slsReceiverTCPIPInterface::start_receiver(){ ret=FAIL; } /* - else if(!strlen(slsReceiverFunctions->getFilePath())){ + else if(!strlen(receiverBase->getFilePath())){ strcpy(mess,"receiver not set up. set receiver ip again.\n"); ret = FAIL; } */ else { - s = slsReceiverFunctions->getStatus(); + s = receiverBase->getStatus(); switch (s) { case ERROR: strcpy(cstatus,"error"); break; case WAITING: strcpy(cstatus,"waiting"); break; @@ -787,7 +787,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ default: strcpy(cstatus,"idle"); break; } if(s == IDLE) - ret=slsReceiverFunctions->startReceiver(mess); + ret=receiverBase->startReceiver(mess); else{ sprintf(mess,"Cannot start Receiver as it is in %s state\n",cstatus); ret=FAIL; @@ -824,8 +824,8 @@ int slsReceiverTCPIPInterface::stop_receiver(){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else if(slsReceiverFunctions->getStatus()!=IDLE) - ret=slsReceiverFunctions->stopReceiver(); + else if(receiverBase->getStatus()!=IDLE) + ret=receiverBase->stopReceiver(); #endif if(ret==OK && socket->differentClients){ @@ -850,7 +850,7 @@ int slsReceiverTCPIPInterface::get_status(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - retval=slsReceiverFunctions->getStatus(); + retval=receiverBase->getStatus(); #endif if(socket->differentClients){ @@ -874,7 +874,7 @@ int slsReceiverTCPIPInterface::get_frames_caught(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - retval=slsReceiverFunctions->getTotalFramesCaught(); + retval=receiverBase->getTotalFramesCaught(); #endif if(socket->differentClients){ cout << "Force update" << endl; @@ -897,7 +897,7 @@ int slsReceiverTCPIPInterface::get_frame_index(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - retval=slsReceiverFunctions->getAcquisitionIndex(); + retval=receiverBase->getAcquisitionIndex(); #endif if(socket->differentClients){ @@ -929,7 +929,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ ret=FAIL; } else - slsReceiverFunctions->resetTotalFramesCaught(); + receiverBase->resetTotalFramesCaught(); } #endif @@ -980,12 +980,12 @@ int slsReceiverTCPIPInterface::set_short_frame() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else if(slsReceiverFunctions->getStatus()==RUNNING){ + else if(receiverBase->getStatus()==RUNNING){ strcpy(mess,"Cannot set short frame while status is running\n"); ret=FAIL; } else{ - retval=slsReceiverFunctions->setShortFrame(index); + retval=receiverBase->setShortFrame(index); shortFrame = retval; if(shortFrame==-1) packetsPerFrame=GOTTHARD_PACKETS_PER_FRAME; @@ -1052,15 +1052,15 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ #ifdef SLS_RECEIVER_UDP_FUNCTIONS /**send garbage with -1 index to try again*/ - if(!slsReceiverFunctions->getFramesCaught()){ + if(!receiverBase->getFramesCaught()){ arg = -1; cout<<"haven't caught any frame yet"<getStartFrameIndex(); - slsReceiverFunctions->readFrame(fName,&raw,index); + startIndex=receiverBase->getStartFrameIndex(); + receiverBase->readFrame(fName,&raw,index); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1224,13 +1224,13 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ /**send garbage with -1 index to try again*/ - if(!slsReceiverFunctions->getFramesCaught()){ + if(!receiverBase->getFramesCaught()){ arg=-1; cout<<"haven't caught any frame yet"<getStartFrameIndex(); - slsReceiverFunctions->readFrame(fName,&raw,index); + startIndex=receiverBase->getStartFrameIndex(); + receiverBase->readFrame(fName,&raw,index); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1375,7 +1375,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**send garbage with -1 index to try again*/ - if(!slsReceiverFunctions->getFramesCaught()){ + if(!receiverBase->getFramesCaught()){ arg=-1; cout<<"haven't caught any frame yet"<readFrame(fName,&raw, index); + receiverBase->readFrame(fName,&raw, index); #ifdef VERBOSE cout << "index:" << dec << index << endl; #endif @@ -1525,12 +1525,12 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; }/* - else if((slsReceiverFunctions->getStatus()==RUNNING) && (index >= 0)){ + else if((receiverBase->getStatus()==RUNNING) && (index >= 0)){ ret = FAIL; strcpy(mess,"cannot set up receiver mode when receiver is running\n"); }*/ else - retval=slsReceiverFunctions->setNFrameToGui(index); + retval=receiverBase->setNFrameToGui(index); } #endif @@ -1576,7 +1576,9 @@ int slsReceiverTCPIPInterface::enable_file_write(){ ret=FAIL; } else{ - retval=slsReceiverFunctions->setEnableFileWrite(enable); + if(enable >= 0) + receiverBase->setEnableFileWrite(enable); + retval=receiverBase->getEnableFileWrite(); if((enable!=-1)&&(enable!=retval)) ret=FAIL; } @@ -1606,7 +1608,7 @@ int slsReceiverTCPIPInterface::get_id(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - retval = get_version(); + retval = getReceiverVersion(); #endif if(socket->differentClients){ @@ -1624,7 +1626,7 @@ int slsReceiverTCPIPInterface::get_id(){ -int64_t slsReceiverTCPIPInterface::get_version(){ +int64_t slsReceiverTCPIPInterface::getReceiverVersion(){ int64_t retval = SVNREV; retval= (retval <<32) | SVNDATE; return retval; @@ -1639,8 +1641,8 @@ int slsReceiverTCPIPInterface::start_readout(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - slsReceiverFunctions->startReadout(); - retval = slsReceiverFunctions->getStatus(); + receiverBase->startReadout(); + retval = receiverBase->getStatus(); if((retval == TRANSMITTING) || (retval == RUN_FINISHED) || (retval == IDLE)) ret = OK; else @@ -1687,9 +1689,9 @@ int slsReceiverTCPIPInterface::set_timer() { } else{ if(index[0] == slsReceiverDefs::FRAME_PERIOD) - retval=slsReceiverFunctions->setAcquisitionPeriod(index[1]); + retval=receiverBase->setAcquisitionPeriod(index[1]); else - retval=slsReceiverFunctions->setNumberOfFrames(index[1]); + retval=receiverBase->setNumberOfFrames(index[1]); } } #ifdef VERBOSE @@ -1744,15 +1746,15 @@ int slsReceiverTCPIPInterface::enable_compression() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else if(slsReceiverFunctions->getStatus()==RUNNING){ + else if(receiverBase->getStatus()==RUNNING){ strcpy(mess,"Cannot enable/disable compression while status is running\n"); ret=FAIL; } else - ret = slsReceiverFunctions->enableDataCompression(enable); + ret = receiverBase->enableDataCompression(enable); } - retval=slsReceiverFunctions->getDataCompression(); + retval=receiverBase->getDataCompression(); } #endif @@ -1794,8 +1796,10 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else - strcpy(retval,slsReceiverFunctions->setDetectorHostname(hostname)); + else{ + receiverBase->initialize(hostname); + strcpy(retval,receiverBase->getDetectorHostname()); + } } #ifdef VERBOSE if(ret!=FAIL) @@ -1859,7 +1863,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } } if(ret!=FAIL){ - retval=slsReceiverFunctions->setDynamicRange(dr); + retval=receiverBase->setDynamicRange(dr); dynamicrange = dr; if(myDetectorType == EIGER){ if(!tenGigaEnable) @@ -1918,8 +1922,11 @@ int slsReceiverTCPIPInterface::enable_overwrite() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else - retval=slsReceiverFunctions->enableOverwrite(index); + else{ + if(index >= 0) + receiverBase->setEnableOverwrite(index); + retval=receiverBase->getEnableOverwrite(); + } } #ifdef VERBOSE if(ret!=FAIL) @@ -1971,7 +1978,7 @@ int slsReceiverTCPIPInterface::enable_tengiga() { ret=FAIL; } else{ - retval=slsReceiverFunctions->enableTenGiga(val); + retval=receiverBase->enableTenGiga(val); if((val!=-1) && (val != retval)) ret = FAIL; else @@ -2179,21 +2186,21 @@ int slsReceiverTCPIPInterface::send_update() { //index #ifdef SLS_RECEIVER_UDP_FUNCTIONS - ind=slsReceiverFunctions->getFileIndex(); + ind=receiverBase->getFileIndex(); socket->SendDataOnly(&ind,sizeof(ind)); #endif //filepath #ifdef SLS_RECEIVER_UDP_FUNCTIONS - strcpy(path,slsReceiverFunctions->getFilePath()); + strcpy(path,receiverBase->getFilePath()); #endif socket->SendDataOnly(path,MAX_STR_LENGTH); //filename #ifdef SLS_RECEIVER_UDP_FUNCTIONS - strcpy(path,slsReceiverFunctions->getFileName()); + strcpy(path,receiverBase->getFileName()); #endif socket->SendDataOnly(path,MAX_STR_LENGTH); diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index bddce2bd89..9ceacb21e5 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -9,7 +9,7 @@ #include "sls_receiver_defs.h" #include "receiver_defs.h" #include "MySocketTCP.h" -#include "slsReceiverUDPFunctions.h" +#include "slsReceiverBase.h" @@ -26,8 +26,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { * @param argc from command line * @param argv from command line * @param succecc socket creation was successfull + * rbase pointer to the receiver base */ - slsReceiverTCPIPInterface(int argc, char *argv[], int &success); + slsReceiverTCPIPInterface(int argc, char *argv[], int &success, slsReceiverBase* rbase); /** * Starts listening on the TCP port for client comminication @@ -48,7 +49,7 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { static void staticCloseFile(int p); /** gets version */ - int64_t get_version(); + int64_t getReceiverVersion(); /** callback arguments are @@ -64,7 +65,7 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){slsReceiverFunctions->registerCallBackStartAcquisition(func,arg);};; + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){receiverBase->registerCallBackStartAcquisition(func,arg);};; /** @@ -74,7 +75,7 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){slsReceiverFunctions->registerCallBackAcquisitionFinished(func,arg);}; + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){receiverBase->registerCallBackAcquisitionFinished(func,arg);}; @@ -87,7 +88,7 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { guidatapointer (NULL, no data required) */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){slsReceiverFunctions->registerCallBackRawDataReady(func,arg);}; + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){receiverBase->registerCallBackRawDataReady(func,arg);}; private: @@ -224,8 +225,8 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** detector type */ detectorType myDetectorType; - /** slsReceiverUDPFunctions object */ - slsReceiverUDPFunctions *slsReceiverFunctions; + /** slsReceiverBase object */ + slsReceiverBase *receiverBase; /** Number of functions */ static const int numberOfFunctions = 256; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index 382fae74e8..2a630f1de7 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -30,7 +30,6 @@ using namespace std; slsReceiverUDPFunctions::slsReceiverUDPFunctions(): - receiver(NULL), thread_started(0), eth(NULL), latestData(NULL), @@ -261,8 +260,6 @@ int slsReceiverUDPFunctions::setDetectorType(detectorType det){ packetIndexMask = MOENCH_PACKET_INDEX_MASK; } else if(myDetectorType == EIGER){ -#ifndef EIGERSLS - cout << "SLS Eiger Receiver" << endl; fifosize = EIGER_FIFO_SIZE; packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; @@ -280,14 +277,6 @@ int slsReceiverUDPFunctions::setDetectorType(detectorType det){ createListeningThreads(true); numListeningThreads = MAX_NUM_LISTENING_THREADS; - -#else - cout << "Heiner's Receiver" << endl; - if(receiver == NULL) - receiver = EigerReceiver::create(); - receiver->setFileName(fileName); -#endif - } latestData = new char[frameSize]; @@ -360,23 +349,17 @@ void slsReceiverUDPFunctions::resetTotalFramesCaught(){ /*file parameters*/ -char* slsReceiverUDPFunctions::getFilePath(){ - if(receiver != NULL) - return receiver->getFilePath(); - else - return filePath; +char* slsReceiverUDPFunctions::getFilePath() const{ + return (char*)filePath; } -char* slsReceiverUDPFunctions::setFilePath(char c[]){ +char* slsReceiverUDPFunctions::setFilePath(const char c[]){ if(strlen(c)){ //check if filepath exists struct stat st; - if(stat(c,&st) == 0){ - if(receiver != NULL) - receiver->setFilePath(c); - else - strcpy(filePath,c); - }else{ + if(stat(c,&st) == 0) + strcpy(filePath,c); + else{ strcpy(filePath,""); cout << "FilePath does not exist:" << filePath << endl; } @@ -385,23 +368,14 @@ char* slsReceiverUDPFunctions::setFilePath(char c[]){ } -char* slsReceiverUDPFunctions::getFileName(){ - if(receiver != NULL) - return receiver->getFileName(); - else - return fileName; +char* slsReceiverUDPFunctions::getFileName() const{ + return (char*)fileName; } -char* slsReceiverUDPFunctions::setFileName(char c[]){ - if(strlen(c)){ - if(receiver != NULL) - receiver->setFileName(c); - else - strcpy(fileName,c); - - } +char* slsReceiverUDPFunctions::setFileName(const char c[]){ + if(strlen(c)) + strcpy(fileName,c); return getFileName(); - } @@ -422,67 +396,45 @@ int slsReceiverUDPFunctions::setFrameIndexNeeded(int i){ } -int slsReceiverUDPFunctions::setEnableFileWrite(int i){ - if(i!=-1){ - if(receiver != NULL) - receiver->setEnableFileWrite(i); - else - enableFileWrite=i; - - } - if(receiver != NULL) - return receiver->getEnableFileWrite(); - else - return enableFileWrite; - +int slsReceiverUDPFunctions::getEnableFileWrite() const{ + return enableFileWrite; } +int slsReceiverUDPFunctions::setEnableFileWrite(int i){ + enableFileWrite=i; + return getEnableFileWrite(); +} +int slsReceiverUDPFunctions::getEnableOverwrite() const{ + return overwrite; +} -int slsReceiverUDPFunctions::enableOverwrite(int i){ - if(i!=-1){ - if(receiver != NULL) - receiver->setEnableOverwrite(i); - else - overwrite=i; - - } - if(receiver != NULL) - return receiver->getEnableOverwrite(); - else - return overwrite; - +int slsReceiverUDPFunctions::setEnableOverwrite(int i){ + overwrite=i; + return getEnableOverwrite(); } + /*other parameters*/ -slsReceiverDefs::runStatus slsReceiverUDPFunctions::getStatus(){ - if(receiver != NULL) - return receiver->getStatus(); - else - return status; +slsReceiverDefs::runStatus slsReceiverUDPFunctions::getStatus() const{ + return status; } -char* slsReceiverUDPFunctions::setDetectorHostname(char c[]){ - if(strlen(c)){ - if(receiver != NULL){ - if(receiver->getDetectorHostname()== NULL) - receiver->initialize(c); - }else - strcpy(detHostname,c); - } - - if(receiver != NULL) - return receiver->getDetectorHostname(); - else - return detHostname; +void slsReceiverUDPFunctions::initialize(const char *detectorHostName){ + if(strlen(detectorHostName)) + strcpy(detHostname,detectorHostName); } +char *slsReceiverUDPFunctions::getDetectorHostname() const{ + return (char*)detHostname; +} + void slsReceiverUDPFunctions::setEthernetInterface(char* c){ strcpy(eth,c); } @@ -495,32 +447,33 @@ void slsReceiverUDPFunctions::setUDPPortNo(int p){ } +int slsReceiverUDPFunctions::getNumberOfFrames() const { + return numberOfFrames; +} + + int32_t slsReceiverUDPFunctions::setNumberOfFrames(int32_t fnum){ - if(fnum >= 0){ - if(receiver != NULL) - receiver->setNumberOfFrames(fnum); - else - numberOfFrames = fnum; - } + if(fnum >= 0) + numberOfFrames = fnum; - if(receiver != NULL) - return receiver->getNumberOfFrames(); - else - return numberOfFrames; + return getNumberOfFrames(); +} + +int slsReceiverUDPFunctions::getScanTag() const{ + return scanTag; } + int32_t slsReceiverUDPFunctions::setScanTag(int32_t stag){ - if(stag >= 0){ - if(receiver != NULL) - receiver->setScanTag(stag); - else - scanTag = stag; - } + if(stag >= 0) + scanTag = stag; - if(receiver != NULL) - return receiver->getScanTag(); - else - return scanTag; + return getScanTag(); +} + + +int slsReceiverUDPFunctions::getDynamicRange() const{ + return dynamicRange; } int32_t slsReceiverUDPFunctions::setDynamicRange(int32_t dr){ @@ -528,63 +481,57 @@ int32_t slsReceiverUDPFunctions::setDynamicRange(int32_t dr){ int olddr = dynamicRange; if(dr >= 0){ - if(receiver != NULL) - receiver->setDynamicRange(dr); - else{ - dynamicRange = dr; - - if(myDetectorType == EIGER){ + dynamicRange = dr; + if(myDetectorType == EIGER){ - if(!tengigaEnable) - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - else - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + if(!tengigaEnable) + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + else + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + frameSize = onePacketSize * packetsPerFrame; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - if(olddr != dr){ - //del - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - for(int i=0;igetDynamicRange(); - else - return dynamicRange; + return getDynamicRange(); } @@ -634,8 +581,7 @@ int64_t slsReceiverUDPFunctions::setAcquisitionPeriod(int64_t index){ if(index >= 0){ if(index != acquisitionPeriod){ acquisitionPeriod = index; - if(receiver != NULL) - setupFifoStructure(); + setupFifoStructure(); } } return acquisitionPeriod; @@ -752,9 +698,6 @@ void slsReceiverUDPFunctions::setupFilter(){ void slsReceiverUDPFunctions::setupFifoStructure(){ - if(receiver != NULL) - return; - int64_t i; int oldn = numJobsPerThread; @@ -1368,9 +1311,6 @@ void slsReceiverUDPFunctions::closeFile(int ithr){ int slsReceiverUDPFunctions::startReceiver(char message[]){ int i; - if(receiver != NULL) - return receiver->startReceiver(message); - // #ifdef VERBOSE cout << "Starting Receiver" << endl; @@ -1435,9 +1375,6 @@ int slsReceiverUDPFunctions::startReceiver(char message[]){ int slsReceiverUDPFunctions::stopReceiver(){ - if(receiver != NULL) - return receiver->stopReceiver(); - //#ifdef VERBOSE cout << "Stopping Receiver" << endl; @@ -1468,10 +1405,6 @@ int slsReceiverUDPFunctions::stopReceiver(){ void slsReceiverUDPFunctions::startReadout(){ - if(receiver != NULL){ - receiver->stopReceiver(); - return; - } //#ifdef VERBOSE cout << "Start Receiver Readout" << endl; //#endif @@ -2283,74 +2216,68 @@ int slsReceiverUDPFunctions::enableTenGiga(int enable){ int oldtengiga = tengigaEnable; if(enable >= 0){ - if(receiver != NULL) - ;/*receiver->setTenGigaBitEthernet(enable);*/ - else{ - tengigaEnable = enable; - if(myDetectorType == EIGER){ + tengigaEnable = enable; - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; - } - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + if(myDetectorType == EIGER){ + if(!tengigaEnable){ + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + }else{ + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; + } + frameSize = onePacketSize * packetsPerFrame; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) + //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - cout<<"packetsPerFrame:"<getTenGigaBitEthernet();*/ - else - return tengigaEnable; + } + return tengigaEnable; } diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h index 3cb1872cf5..99424aaea1 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h @@ -14,7 +14,9 @@ #include "singlePhotonDetector.h" #include "slsReceiverData.h" #include "moenchCommonMode.h" -#include "eigerReceiver.h" + +#include "slsReceiverBase.h" + #ifdef MYROOT1 #include @@ -32,7 +34,7 @@ * @short does all the functions for a receiver, set/get parameters, start/stop etc. */ -class slsReceiverUDPFunctions : private virtual slsReceiverDefs { +class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public slsReceiverBase { public: /** @@ -113,24 +115,24 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { /** * Returns File Path */ - char* getFilePath(); + char* getFilePath() const; /** * Set File Path * @param c file path */ - char* setFilePath(char c[]); + char* setFilePath(const char c[]); /** * Returns File Name */ - char* getFileName(); + char* getFileName() const; /** * Set File Name (without frame index, file index and extension) * @param c file name */ - char* setFileName(char c[]); + char* setFileName(const char c[]); /** * Returns File Index @@ -161,22 +163,45 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { * @param i enable * Returns enable over write */ - int enableOverwrite(int i); + int setEnableOverwrite(int i); + /** + * Returns file write enable + * 1: YES 0: NO + */ + int getEnableFileWrite() const; + /** + * Returns file over write enable + * 1: YES 0: NO + */ + int getEnableOverwrite() const; //other parameters + /** + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + void abort() {}; + /** * Returns status of receiver: idle, running or error */ - runStatus getStatus(); + runStatus getStatus() const; /** * Set detector hostname * @param c hostname */ - char* setDetectorHostname(char c[]); + void initialize(const char *detectorHostName); + + /* Returns detector hostname + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ + char *getDetectorHostname() const; /** * Set Ethernet Interface or IP to listen to @@ -188,16 +213,33 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { */ void setUDPPortNo(int p); + /* + * Returns number of frames to receive + * This is the number of frames to expect to receiver from the detector. + * The data receiver will change from running to idle when it got this number of frames + */ + int getNumberOfFrames() const; + /** * set frame number if a positive number */ int32_t setNumberOfFrames(int32_t fnum); + /** + * Returns scan tag + */ + int getScanTag() const; + /** * set scan tag if its is a positive number */ int32_t setScanTag(int32_t stag); + /** + * Returns the number of bits per pixel + */ + int getDynamicRange() const; + /** * set dynamic range if its is a positive number */ @@ -440,9 +482,6 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs { /** max number of writer threads */ const static int MAX_NUM_WRITER_THREADS = 15; - /** Eiger Receiver */ - EigerReceiver *receiver; - /** detector type */ detectorType myDetectorType; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp index f0e655f3c4..9b1f147dad 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.cpp @@ -1,10 +1,10 @@ #include "slsReceiverUsers.h" -#include "slsReceiverTCPIPInterface.h" +#include "slsReceiver.h" -slsReceiverTCPIPInterface* slsReceiverUsers::receiver(NULL); +slsReceiver* slsReceiverUsers::receiver(NULL); slsReceiverUsers::slsReceiverUsers(int argc, char *argv[], int &success) { - slsReceiverUsers::receiver=new slsReceiverTCPIPInterface(argc, argv, success); + slsReceiverUsers::receiver=new slsReceiver(argc, argv, success); } slsReceiverUsers::~slsReceiverUsers() { @@ -25,7 +25,7 @@ void slsReceiverUsers::closeFile(int p) { } int64_t slsReceiverUsers::getReceiverVersion(){ - slsReceiverUsers::receiver->get_version(); + slsReceiverUsers::receiver->getReceiverVersion(); } diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h index 2dee1e1514..a9d3626d28 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h @@ -5,7 +5,8 @@ #include #include -class slsReceiverTCPIPInterface; + +class slsReceiver; /** @short Class for implementing the SLS data receiver in the users application. Callbacks can be defined for processing and/or saving data @@ -84,7 +85,7 @@ class slsReceiverUsers { void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); // made static to close thread files with ctrl+c - static slsReceiverTCPIPInterface* receiver; + static slsReceiver* receiver; }; diff --git a/slsReceiverSoftware/slsReceiverUsers.doxy b/slsReceiverSoftware/slsReceiverUsers.doxy new file mode 100644 index 0000000000..b5d37ae18e --- /dev/null +++ b/slsReceiverSoftware/slsReceiverUsers.doxy @@ -0,0 +1,86 @@ +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + + + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = YES + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +INTERNAL_DOCS = NO + +SHOW_INCLUDE_FILES = NO + +SHOW_FILES = NO + +SHOW_NAMESPACES = NO + +COMPACT_LATEX = YES + +PAPER_TYPE = a4 + +PDF_HYPERLINKS = YES + +USE_PDFLATEX = YES + +LATEX_HIDE_INDICES = YES + + +PREDEFINED = __cplusplus + +INPUT = slsReceiver/slsReceiverBase.h + +OUTPUT_DIRECTORY = slsReceiverUsersDocs From 4f04fc54575e4275e0acde23933304f2cc4e4789 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Fri, 18 Jul 2014 12:57:10 +0200 Subject: [PATCH 014/222] removed callbacks from tcpip interface --- .../slsReceiver/slsReceiver.cpp | 9 ++-- .../slsReceiver/slsReceiverTCPIPInterface.h | 52 +++++++++---------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp index 9491c3a920..72e9bf7fb4 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp @@ -43,18 +43,21 @@ int64_t slsReceiver::getReceiverVersion(){ void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ - tcpipInterface->registerCallBackStartAcquisition(func,arg); + //tcpipInterface + receiverBase->registerCallBackStartAcquisition(func,arg); } void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ - tcpipInterface->registerCallBackAcquisitionFinished(func,arg); + //tcpipInterface + receiverBase->registerCallBackAcquisitionFinished(func,arg); } void slsReceiver::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ - tcpipInterface->registerCallBackRawDataReady(func,arg); + //tcpipInterface + receiverBase->registerCallBackRawDataReady(func,arg); } diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index 9ceacb21e5..d4c1681b54 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -51,44 +51,44 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** gets version */ int64_t getReceiverVersion(); - /** - callback arguments are - filepath - filename - fileindex - data size +/* /\** */ +/* callback arguments are */ +/* filepath */ +/* filename */ +/* fileindex */ +/* data size */ - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything +/* return value is */ +/* 0 callback takes care of open,close,wrie file */ +/* 1 callback writes file, we have to open, close it */ +/* 2 we open, close, write file, callback does not do anything */ - */ +/* *\/ */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){receiverBase->registerCallBackStartAcquisition(func,arg);};; +/* void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){receiverBase->registerCallBackStartAcquisition(func,arg);};; */ - /** - callback argument is - toatal farmes caught +/* /\** */ +/* callback argument is */ +/* toatal farmes caught */ - */ +/* *\/ */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){receiverBase->registerCallBackAcquisitionFinished(func,arg);}; +/* void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){receiverBase->registerCallBackAcquisitionFinished(func,arg);}; */ - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ +/* /\** */ +/* args to raw data ready callback are */ +/* framenum */ +/* datapointer */ +/* datasize in bytes */ +/* file descriptor */ +/* guidatapointer (NULL, no data required) */ +/* *\/ */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){receiverBase->registerCallBackRawDataReady(func,arg);}; +/* void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){receiverBase->registerCallBackRawDataReady(func,arg);}; */ private: From 91c0a083b3d87f5e9b24a733bbfa9e42e00d48e7 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Fri, 25 Jul 2014 10:28:56 +0200 Subject: [PATCH 015/222] argv, argc moved from tcpip interface to slsReceiver --- .../slsReceiver/slsReceiver.cpp | 126 +++++++++++++- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 155 ++++++------------ .../slsReceiver/slsReceiverTCPIPInterface.h | 20 ++- 3 files changed, 188 insertions(+), 113 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp index 72e9bf7fb4..cd5ab551d1 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp @@ -3,18 +3,140 @@ * @short creates the UDP and TCP class objects ***********************************************/ +#include +#include +#include +#include +#include + #include "slsReceiver.h" #include "slsReceiverUDPFunctions.h" #include "eigerReceiver.h" +using namespace std; slsReceiver::slsReceiver(int argc, char *argv[], int &success){ //creating base receiver cout << "SLS Receiver" << endl; receiverBase = new slsReceiverUDPFunctions(); + int tcpip_port_no=-1; + + + + ifstream infile; + string sLine,sargname; + int iline = 0; + + + success=OK; + + string fname = ""; + + //parse command line for config + for(int iarg=1;iarg> sargname; + + //tcp port + if(sargname=="rx_tcpport"){ + if(sstr.good()) { + sstr >> sargname; + if(sscanf(sargname.c_str(),"%d",&tcpip_port_no)) + cout<<"dataport:"<> sargname; - - //tcp port - if(sargname=="rx_tcpport"){ - if(sstr.good()) { - sstr >> sargname; - if(sscanf(sargname.c_str(),"%d",&port_no)) - cout<<"dataport:"<0) + port_no = pn; + success=OK; //create socket if(success == OK){ @@ -157,6 +56,7 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int delete socket; socket=NULL; } else { + portNumber=port_no; //initialize variables strcpy(socket->lastClientIP,"none"); strcpy(socket->thisClientIP,"none1"); @@ -175,6 +75,47 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int argc, char *argv[], int } +int slsReceiverTCPIPInterface::setPortNumber(int pn){ + int p_number; + MySocketTCP *oldsocket=NULL;; + int sd=0; + + if (pn>0) { + p_number = pn; + + if (p_number<1024) { + sprintf(mess,"Too low port number %d\n", p_number); + cout << mess << endl; + } else { + + oldsocket=socket; + socket = new MySocketTCP(p_number); + if(socket){ + sd = socket->getErrorStatus(); + if (!sd){ + portNumber=p_number; + delete oldsocket; + } else { + cout << "Could not bind port " << p_number << endl; + if (sd==-10) { + + cout << "Port "<< p_number << " already set" << endl; + } else { + delete socket; + socket=oldsocket; + } + } + + } else { + socket=oldsocket; + } + } + } + + return portNumber; +} + + int slsReceiverTCPIPInterface::start(){ cout << "Creating TCP Server Thread" << endl; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index d4c1681b54..423d0949ab 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -23,12 +23,19 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** * Constructor * reads config file, creates socket, assigns function table - * @param argc from command line - * @param argv from command line * @param succecc socket creation was successfull - * rbase pointer to the receiver base + * @param rbase pointer to the receiver base + * @param pn port number (defaults to default port number) */ - slsReceiverTCPIPInterface(int argc, char *argv[], int &success, slsReceiverBase* rbase); + slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn=-1); + + /** + * Sets the port number to listen to. + Take care that the client must know to whcih port it has to listen to, so normally it is better to use a fixes port from the instatiation or change it from the client. + @param pn port number (-1 only get) + \returns actual port number + */ + int setPortNumber(int pn=-1); /** * Starts listening on the TCP port for client comminication @@ -100,6 +107,7 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { */ static void* startTCPServerThread(void *this_pointer); + /** * Thread started which is a TCP server * Called by start() @@ -261,6 +269,10 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** size of one frame*/ int tenGigaEnable; + /** port number */ + int portNumber; + + protected: /** Socket */ MySocketTCP* socket; From 3e36b603f95f7e50c0489a470ee454387c73dbb4 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Thu, 31 Jul 2014 12:13:15 +0200 Subject: [PATCH 016/222] receiver nth frame and acquisition indices for eiger --- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 3 + .../slsReceiver/slsReceiverUDPFunctions.cpp | 63 ++++++++++++------- .../slsReceiver/slsReceiverUDPFunctions.h | 4 +- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index cadde65088..cc143efc45 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -1318,7 +1318,9 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**send garbage with -1 index to try again*/ if(!receiverBase->getFramesCaught()){ arg=-1; +#ifdef VERBOSE cout<<"haven't caught any frame yet"<fnum); + tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else @@ -1840,6 +1852,7 @@ int loop; void slsReceiverUDPFunctions::startFrameIndices(int ithread){ if (myDetectorType == EIGER) + //add currframenum later in this method for scans startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); //gotthard has +1 for frame number and not a short frame else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) @@ -1850,9 +1863,6 @@ void slsReceiverUDPFunctions::startFrameIndices(int ithread){ & (frameIndexMask)) >> frameIndexOffset); - cout << "startFrameIndex:" << startFrameIndex<push(buffer[ithread]); @@ -1898,37 +1917,37 @@ int i; cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; #endif while(!fifo[ithread]->push(buffer[ithread])); -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -//#endif +#endif } //reset mask and exit loop pthread_mutex_lock(&status_mutex); listeningthreads_mask^=(1< 1) cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; -//#endif +#endif while(listeningthreads_mask) usleep(5000); -//#ifdef VERYDEBUG +#ifdef VERYDEBUG t = 0; for(i=0;i Date: Tue, 5 Aug 2014 11:08:11 +0200 Subject: [PATCH 017/222] added old (workaround) EigerReceiver. Still not using slsReceiverBase --- slsReceiverSoftware/Makefile | 3 +- slsReceiverSoftware/slsReceiver/Makefile | 10 +- .../eigerReceiver/eigerReceiver.cpp | 169 +++++++++--------- .../eigerReceiver/eigerReceiverDummy.cpp | 2 + .../eigerReceiver/eigerReceiverTest.cpp | 2 +- .../slsReceiver/slsReceiverBase.h | 70 ++++++-- 6 files changed, 153 insertions(+), 103 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 4aa0c3fdec..338686cef9 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -11,7 +11,7 @@ CFLAGS= -g -DC_ONLY -fPIC DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS -INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -IslsReceiver/eigerReceiver -I$(ASM) +INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -IslsReceiver/eigerReceiver -I$(ASM) -I../slsDetectorSoftware/commonFiles #-IslsReceiverInterface SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUDPFunctions.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiverUsers.cpp @@ -37,6 +37,7 @@ else ifeq ($(ROOTSLS),yes) $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) else echo "without root" + echo $(INCLUDES) $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) endif diff --git a/slsReceiverSoftware/slsReceiver/Makefile b/slsReceiverSoftware/slsReceiver/Makefile index d5f02c2ea6..c94528eeb9 100644 --- a/slsReceiverSoftware/slsReceiver/Makefile +++ b/slsReceiverSoftware/slsReceiver/Makefile @@ -13,7 +13,7 @@ LDFLAGRXR ?= -L$(LIBDIR) -lSlsReceiver -L/usr/lib64/ -lpthread LDFLAGRXR += -lm -lstdc++ -INCLUDES ?= -I ../MySocketTCP -I ../slsDetectorCalibration -I ../includes -I eigerReceiver -I . +INCLUDES ?= -I ../MySocketTCP -I ../slsDetectorCalibration -I ../includes -I eigerReceiver -I . -I ../slsDetectorSoftware/commonFiles SRC_CLNT = main.cpp @@ -46,13 +46,13 @@ $(DESTDIR)/slsReceiver: eigerReceiver lib ifeq ($(EIGERSLS), yes) eigerReceiver: - $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiverTest.o eigerReceiver/eigerReceiverTest.cpp $(EIGERFLAGS) - $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiver.cpp $(EIGERFLAGS) + $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiverTest.o eigerReceiver/eigerReceiverTest.cpp $(EIGERFLAGS) + $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiver.cpp $(EIGERFLAGS) $(CXX) eigerReceiverTest.o eigerReceiver.o -o eigerReceiver/eigerReceiverTest $(EIGERFLAGS) else ifeq ($(ROOTSLS), yes) eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp echo "Compiling with root" - $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eeigerReceiverDummy.cpp $(ROOTFLAGS) + $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp $(ROOTFLAGS) else eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp @@ -63,6 +63,6 @@ lib: clean: rm -rf $(PROGS) *.o eigerReceiverTest $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so core - + diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp index fa19895beb..48024c5d03 100644 --- a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp +++ b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp @@ -39,77 +39,77 @@ struct EigerReceiverScanConfiguration { bool doFileOverWrite; EigerReceiverScanConfiguration(): - dynamicRange(-1), - scanTag(-1), - numberOfFrames(-1), - doFileWrite(false), - doFileOverWrite(false){}; + dynamicRange(-1), + scanTag(-1), + numberOfFrames(-1), + doFileWrite(false), + doFileOverWrite(false){}; }; class EigerReceiverImplementation: public EigerReceiver { - + public: - + EigerReceiverImplementation() : isInitialized(false), status(slsReceiverDefs::ERROR) {}; - + void initialize(const char *detectorHostname) { - - string name; - if (detectorHostname != NULL) { - name = detectorHostname; - } - - if (name.empty()) { - DEBUG("initialize(): can't initialize with empty string or NULL for detectorHostname"); - } else if (isInitialized == true) { - DEBUG("initialize(): already initialized, can't initialize several times"); - } else { - DEBUG("initialize(): initialize() with: detectorHostName=" << name << "."); - init_config.detectorHostname = name; - isInitialized = true; - status = slsReceiverDefs::IDLE; - } - + + string name; + if (detectorHostname != NULL) { + name = detectorHostname; + } + + if (name.empty()) { + DEBUG("initialize(): can't initialize with empty string or NULL for detectorHostname"); + } else if (isInitialized == true) { + DEBUG("initialize(): already initialized, can't initialize several times"); + } else { + DEBUG("initialize(): initialize() with: detectorHostName=" << name << "."); + init_config.detectorHostname = name; + isInitialized = true; + status = slsReceiverDefs::IDLE; + } + #ifdef SALA - //REST call - hardcoded - RestHelper rest ; - rest.init("localhost",8080); - std::string answer; - std::cout << "---- REST test 1: true, string "<< std::endl; - int code = rest.get_json("status", &answer); - std::cout << "Answer: " << answer << std::endl; - - std::cout << "---- REST test 2: 404, string "<< std::endl; - code = rest.get_json("statuss", &answer); - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; - } - - std::cout << "---- REST test 3: true, json object "<< std::endl; - JsonBox::Value json_value; - code = rest.get_json("status", &json_value); - std::cout << "JSON " << json_value["status"] << std::endl; - - answer = ""; - std::cout << "---- REST test 4: POST, string "<< std::endl; - code = rest.post_json("recipes/cassoela", &answer); - std::cout << "POST answer: " << answer << std::endl; - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; - } - - RestHelper rest2 ; - rest2.init("reallyfake",8080); - std::cout << "---- REST test 4: host not found, json object "<< std::endl; - JsonBox::Value json_value2; - code = rest2.get_json("status", &json_value2); - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; - } - + //REST call - hardcoded + RestHelper rest ; + rest.init("localhost",8080); + std::string answer; + std::cout << "---- REST test 1: true, string "<< std::endl; + int code = rest.get_json("status", &answer); + std::cout << "Answer: " << answer << std::d::endl; + + std::cout << "---- REST test 2: 404, string "<< std::endl; + code = rest.get_json("statuss", &answer); + if (code != 0){ + //throw -1; + std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; + } + + std::cout << "---- REST test 3: true, json object "<< std::endl; + JsonBox::Value json_value; + code = rest.get_json("status", &json_value); + std::cout << "JSON " << json_value["status"] << std::endl; + + answer = ""; + std::cout << "---- REST test 4: POST, string "<< std::endl; + code = rest.post_json("recipes/cassoela", &answer); + std::cout << "POST answer: " << answer << std::endl; + if (code != 0){ + //throw -1; + std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; + } + + RestHelper rest2 ; + rest2.init("reallyfake",8080); + std::cout << "---- REST test 4: host not found, json object "<< std::endl; + JsonBox::Value json_value2; + code = rest2.get_json("status", &json_value2); + if (code != 0){ + //throw -1; + std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; + } + #endif } @@ -120,31 +120,31 @@ class EigerReceiverImplementation: public EigerReceiver { DEBUG("getDetectorHostname(): Return NULL"); return(NULL); } - char *c = new char[name.length()+1]; - name.copy(c, name.length()); - c[name.length()] = '\0'; - DEBUG("getDetectorHostname(): Return " << c << "."); - return(c); + char *c = new char[name.length()+1]; + name.copy(c, name.length()); + c[name.length()] = '\0'; + DEBUG("getDetectorHostname(): Return " << c << "."); + return(c); } - + char *getFileName() const { string name = scan_config.fileName; - - char *c = new char[name.length()+1]; - name.copy(c, name.length()); - c[name.length()] = '\0'; - DEBUG("getFileName(): Return " << c); - return(c); + + char *c = new char[name.length()+1]; + name.copy(c, name.length()); + c[name.length()] = '\0'; + DEBUG("getFileName(): Return " << c); + return(c); } - + char *getFilePath() const { string name = scan_config.filePath; - char *c = new char[name.length()+1]; - name.copy(c, name.length()); - c[name.length()] = '\0'; - DEBUG("getFilePath(): Return " << c); - return(c); + char *c = new char[name.length()+1]; + name.copy(c, name.length()); + c[name.length()] = '\0'; + DEBUG("getFilePath(): Return " << c); + return(c); } int getDynamicRange() const { @@ -237,6 +237,11 @@ class EigerReceiverImplementation: public EigerReceiver { status = slsReceiverDefs::IDLE; } + // Temporary workaround + int setDetectorType(slsReceiverDefs::detectorType det){ + return 0; + } + private: EigerReceiverScanConfiguration scan_config; EigerReceiverInitializationConfiguration init_config; diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp index f45c7517ee..ad8139cd87 100644 --- a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp +++ b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp @@ -49,6 +49,8 @@ class EigerReceiverImplementation: public EigerReceiver { char *getFileName() const {return (char*)"";} char *getFilePath() const {return (char*)"";} + + int getFileIndex() const {return 0;} int getDynamicRange() const { return 0;} diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp index bdfcba7a16..7eb80f690e 100644 --- a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp +++ b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp @@ -29,7 +29,7 @@ int main(int argc, char *argv[]){ } delete[] c0; - cout <initialize(empty); status = receiver->getStatus(); receiver->initialize(name); diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverBase.h b/slsReceiverSoftware/slsReceiver/slsReceiverBase.h index 007bf4a970..5ea2e570e1 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverBase.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverBase.h @@ -1,5 +1,6 @@ #ifndef SLSRECEIVERBASE_H #define SLSRECEIVERBASE_H + /*********************************************** * @file slsReceiverBase.h * @short base class with all the functions for a receiver, set/get parameters, start/stop etc. @@ -12,20 +13,61 @@ * @short base class with all the functions for a receiver, set/get parameters, start/stop etc. */ -class slsReceiverBase { -public: - - /** - * constructor - */ - slsReceiverBase(){}; - - /** - * Destructor - */ - virtual ~slsReceiverBase() {}; +#include "sls_detector_defs.h" +class slsReceiverBase { + /* abstract class that defines the public interface of an sls detector data receiver. + * + * Use the factory method slsReceiverBase::create() to get an instance: + * + * slsReceiverBase *receiver = slsReceiverBase::create() + * + * supported sequence of method-calls: + * + * initialize() : once and only once after create() + * + * get*() : anytime after initialize(), multiples times + * set*() : anytime after initialize(), multiple times + * + * startReceiver(): anytime after initialize(). Will fail if state already is 'running' + * + * abort(), + * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. + * + * getStatus() returns the actual state of the data receiver - running or idle. All other + * get*() and set*() methods access the local cache of configuration values only and *do not* modify the data receiver settings. + * + * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. + * + * get- and set-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: + * + * char *c = receiver->getFileName(); + * .... + * delete[] c; + * + * always: 1:YES 0:NO for int as bool-like arguments + * + */ +public: + + // Using Factory instead + /** + * constructor + */ + //slsReceiverBase(){}; + + /** + * factory method to create instances + */ + static slsReceiverBase *create(); + + + /** + * Destructor + */ + virtual ~slsReceiverBase() {}; + /** * Initialize the Receiver @param detectorHostName detector hostname @@ -44,8 +86,8 @@ class slsReceiverBase { /** * Returns status of receiver: idle, running or error */ - virtual slsReceiverDefs::runStatus getStatus() const = 0; - + virtual slsReceiverDefs::runStatus getStatus() const = 0; + /** * Returns File Name * caller is responsible to deallocate the returned char array. From dc6045a14c80e7faed1ea6c20aa0864fa83c706a Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Fri, 5 Sep 2014 16:54:32 +0200 Subject: [PATCH 018/222] first factory-based version compiling, still very very preliminary --- slsReceiverSoftware/Makefile | 4 +- slsReceiverSoftware/slsReceiver/Makefile | 14 +- .../slsReceiver/UDPBaseImplementation.cpp | 2317 +++++++++++++++++ .../slsReceiver/UDPBaseImplementation.h | 811 ++++++ .../slsReceiver/UDPInterface.cpp | 43 + .../{slsReceiverBase.h => UDPInterface.h} | 48 +- slsReceiverSoftware/slsReceiver/main.cpp | 1 + .../slsReceiver/slsReceiver.cpp | 76 +- slsReceiverSoftware/slsReceiver/slsReceiver.h | 16 +- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 14 +- .../slsReceiver/slsReceiverTCPIPInterface.h | 18 +- .../slsReceiver/slsReceiverUDPFunctions.cpp | 7 +- .../slsReceiver/slsReceiverUDPFunctions.h | 15 +- .../slsReceiver/slsReceiverUsers.h | 3 +- 14 files changed, 3295 insertions(+), 92 deletions(-) create mode 100644 slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp create mode 100644 slsReceiverSoftware/slsReceiver/UDPBaseImplementation.h create mode 100644 slsReceiverSoftware/slsReceiver/UDPInterface.cpp rename slsReceiverSoftware/slsReceiver/{slsReceiverBase.h => UDPInterface.h} (93%) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 4aa0c3fdec..8f6e00910c 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -14,8 +14,10 @@ DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -IslsReceiver/eigerReceiver -I$(ASM) #-IslsReceiverInterface -SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUDPFunctions.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiverUsers.cpp +SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/slsReceiver.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiverUsers.cpp + #slsReceiverInterface/receiverInterface.cpp +#slsReceiver/slsReceiverUDPFunctions.cpp OBJS = $(SRC_CLNT:.cpp=.o) OBJS += slsReceiver/eigerReceiver.o diff --git a/slsReceiverSoftware/slsReceiver/Makefile b/slsReceiverSoftware/slsReceiver/Makefile index d5f02c2ea6..b4a681c3f2 100644 --- a/slsReceiverSoftware/slsReceiver/Makefile +++ b/slsReceiverSoftware/slsReceiver/Makefile @@ -13,7 +13,7 @@ LDFLAGRXR ?= -L$(LIBDIR) -lSlsReceiver -L/usr/lib64/ -lpthread LDFLAGRXR += -lm -lstdc++ -INCLUDES ?= -I ../MySocketTCP -I ../slsDetectorCalibration -I ../includes -I eigerReceiver -I . +INCLUDES ?= -I ../MySocketTCP -I ../slsDetectorCalibration -I ../includes/ -I eigerReceiver -I . SRC_CLNT = main.cpp @@ -40,19 +40,21 @@ $(DESTDIR)/sslsReceiver: lib $(DESTDIR)/slsReceiver: eigerReceiver lib + echo "AAAAAAAAAAAA" $(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC $(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC #$(EIGERFLAGS) ifeq ($(EIGERSLS), yes) eigerReceiver: - $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiverTest.o eigerReceiver/eigerReceiverTest.cpp $(EIGERFLAGS) - $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiver.cpp $(EIGERFLAGS) - $(CXX) eigerReceiverTest.o eigerReceiver.o -o eigerReceiver/eigerReceiverTest $(EIGERFLAGS) +# $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiverTest.o eigerReceiver/eigerReceiverTest.cpp $(EIGERFLAGS) +# $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiver.cpp $(EIGERFLAGS) +# $(CXX) eigerReceiverTest.o eigerReceiver.o -o eigerReceiver/eigerReceiverTest $(EIGERFLAGS) + $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiverImplementation.cpp $(EIGERFLAGS) else ifeq ($(ROOTSLS), yes) eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp echo "Compiling with root" - $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eeigerReceiverDummy.cpp $(ROOTFLAGS) + $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp $(ROOTFLAGS) else eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp @@ -63,6 +65,6 @@ lib: clean: rm -rf $(PROGS) *.o eigerReceiverTest $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so core - + diff --git a/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp b/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp new file mode 100644 index 0000000000..aa0aa77e1c --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp @@ -0,0 +1,2317 @@ +#ifdef SLS_RECEIVER_UDP_FUNCTIONS +/********************************************//** + * @file UDPBaseImplementation.cpp + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + ***********************************************/ + + +#include "UDPBaseImplementation.h" + +#include "moench02ModuleData.h" +#include "gotthardModuleData.h" +#include "gotthardShortModuleData.h" + + +#include // SIGINT +#include // stat +#include // socket(), bind(), listen(), accept(), shut down +#include // sock_addr_in, htonl, INADDR_ANY +#include // exit() +#include //set precision +#include //munmap + + + +#include +#include + + + +using namespace std; + + + +UDPBaseImplementation::UDPBaseImplementation(): + thread_started(0), + eth(NULL), + latestData(NULL), + guiFileName(NULL), + guiFrameNumber(0), + tengigaEnable(0){ + + for(int i=0;i /proc/sys/net/core/rmem_max")) + cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) + cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + /** permanent setting heiner + net.core.rmem_max = 104857600 # 100MiB + net.core.netdev_max_backlog = 250000 + sysctl -p + // from the manual + sysctl -w net.core.rmem_max=16777216 + sysctl -w net.core.netdev_max_backlog=250000 + */ +} + + + +UDPBaseImplementation::~UDPBaseImplementation(){ + createListeningThreads(true); + createWriterThreads(true); + deleteMembers(); +} + + + + +void UDPBaseImplementation::deleteMembers(){ + //kill threads + if(thread_started){ + createListeningThreads(true); + createWriterThreads(true); + } + + for(int i=0;i=0) + fileIndex = i; + return getFileIndex(); +} + + +int UDPBaseImplementation::setFrameIndexNeeded(int i){ + frameIndexNeeded = i; + return frameIndexNeeded; +} + + +int UDPBaseImplementation::getEnableFileWrite() const{ + return enableFileWrite; +} + +int UDPBaseImplementation::setEnableFileWrite(int i){ + enableFileWrite=i; + return getEnableFileWrite(); +} + +int UDPBaseImplementation::getEnableOverwrite() const{ + return overwrite; +} + +int UDPBaseImplementation::setEnableOverwrite(int i){ + overwrite=i; + return getEnableOverwrite(); +} + + + + + +/*other parameters*/ + +slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ + return status; +} + + +void UDPBaseImplementation::initialize(const char *detectorHostName){ + if(strlen(detectorHostName)) + strcpy(detHostname,detectorHostName); +} + + +char *UDPBaseImplementation::getDetectorHostname() const{ + return (char*)detHostname; +} + +void UDPBaseImplementation::setEthernetInterface(char* c){ + strcpy(eth,c); +} + + +void UDPBaseImplementation::setUDPPortNo(int p){ + for(int i=0;i= 0) + numberOfFrames = fnum; + + return getNumberOfFrames(); +} + +int UDPBaseImplementation::getScanTag() const{ + return scanTag; +} + + +int32_t UDPBaseImplementation::setScanTag(int32_t stag){ + if(stag >= 0) + scanTag = stag; + + return getScanTag(); +} + + +int UDPBaseImplementation::getDynamicRange() const{ + return dynamicRange; +} + +int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ + cout << "Setting Dynamic Range" << endl; + + int olddr = dynamicRange; + if(dr >= 0){ + dynamicRange = dr; + + if(myDetectorType == EIGER){ + + + if(!tengigaEnable) + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + else + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + frameSize = onePacketSize * packetsPerFrame; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + + + + if(olddr != dr){ + + //del + if(thread_started){ + createListeningThreads(true); + createWriterThreads(true); + } + for(int i=0;i=0){ + nFrameToGui = i; + setupFifoStructure(); + } + return nFrameToGui; +} + + + +int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ + + if(index >= 0){ + if(index != acquisitionPeriod){ + acquisitionPeriod = index; + setupFifoStructure(); + } + } + return acquisitionPeriod; +} + + +bool UDPBaseImplementation::getDataCompression(){return dataCompression;} + +int UDPBaseImplementation::enableDataCompression(bool enable){ + cout << "Data compression "; + if(enable) + cout << "enabled" << endl; + else + cout << "disabled" << endl; +#ifdef MYROOT1 + cout << " WITH ROOT" << endl; +#else + cout << " WITHOUT ROOT" << endl; +#endif + //delete filter for the current number of threads + deleteFilter(); + + dataCompression = enable; + pthread_mutex_lock(&status_mutex); + writerthreads_mask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + createWriterThreads(true); + + if(enable) + numWriterThreads = MAX_NUM_WRITER_THREADS; + else + numWriterThreads = 1; + + if(createWriterThreads() == FAIL){ + cout << "ERROR: Could not create writer threads" << endl; + return FAIL; + } + setThreadPriorities(); + + + if(enable) + setupFilter(); + + return OK; +} + + + + + + + + + + + + +/*other functions*/ + + +void UDPBaseImplementation::deleteFilter(){ + int i; + cmSub=NULL; + + for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); + +} + + + +//LEO: it is not clear to me.. +void UDPBaseImplementation::setupFifoStructure(){ + + int64_t i; + int oldn = numJobsPerThread; + + //if every nth frame mode + if(nFrameToGui) + numJobsPerThread = nFrameToGui; + + //random nth frame mode + else{ + if(!acquisitionPeriod) + i = SAMPLE_TIME_IN_NS; + else + i = SAMPLE_TIME_IN_NS/acquisitionPeriod; + if (i > MAX_JOBS_PER_THREAD) + numJobsPerThread = MAX_JOBS_PER_THREAD; + else if (i < 1) + numJobsPerThread = 1; + else + numJobsPerThread = i; + } + + //if same, return + if(oldn == numJobsPerThread) + return; + + if(myDetectorType == EIGER) + numJobsPerThread = 1; + + //otherwise memory too much if numjobsperthread is at max = 1000 + fifosize = GOTTHARD_FIFO_SIZE; + if(myDetectorType == MOENCH) + fifosize = MOENCH_FIFO_SIZE; + else if(myDetectorType == EIGER) + fifosize = EIGER_FIFO_SIZE; + + if(fifosize % numJobsPerThread) + fifosize = (fifosize/numJobsPerThread)+1; + else + fifosize = fifosize/numJobsPerThread; + + + cout << "Number of Frames per buffer:" << numJobsPerThread << endl; + cout << "Fifo Size:" << fifosize << endl; + + /* + //for testing + numJobsPerThread = 3; fifosize = 11; + */ + + for(int i=0;iisEmpty()) + fifoFree[i]->pop(buffer[i]); + delete fifoFree[i]; + } + if(fifo[i]) delete fifo[i]; + if(mem0[i]) free(mem0[i]); + fifoFree[i] = new CircularFifo(fifosize); + fifo[i] = new CircularFifo(fifosize); + + + //allocate memory + mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + /** shud let the client know about this */ + if (mem0[i]==NULL){ + cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + exit(-1); + } + buffer[i]=mem0[i]; + //push the addresses into freed fifoFree and writingFifoFree + while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); + buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + } + } + cout << "Fifo structure(s) reconstructed" << endl; +} + + + + + + + +/** acquisition functions */ + +void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ + //point to gui data + if (guiData == NULL) + guiData = latestData; + + //copy data and filename + strcpy(c,guiFileName); + fnum = guiFrameNumber; + + + //could not get gui data + if(!guiDataReady){ + *raw = NULL; + } + //data ready, set guidata to receive new data + else{ + *raw = guiData; + guiData = NULL; + + pthread_mutex_lock(&dataReadyMutex); + guiDataReady = 0; + pthread_mutex_unlock(&dataReadyMutex); + if((nFrameToGui) && (writerthreads_mask)){ + /*if(nFrameToGui){*/ + //release after getting data + sem_post(&smp); + } + } +} + + + + + +void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ + + //random read when gui not ready + if((!nFrameToGui) && (!guiData)){ + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + pthread_mutex_unlock(&dataReadyMutex); + } + + //random read or nth frame read, gui needs data now + else{ + /* + //nth frame read, block current process if the guireader hasnt read it yet + if(nFrameToGui) + sem_wait(&smp); +*/ + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + //eiger + if(startbuf != NULL){ + int offset = 0; + int size = frameSize/EIGER_MAX_PORTS; + for(int j=0;jgetErrorStatus(); + if(iret){ +#ifdef VERBOSE + cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; +#endif + return FAIL; + } + } + + return OK; +} + + + + + + + +int UDPBaseImplementation::shutDownUDPSockets(){ + for(int i=0;iShutDownSocket(); + delete udpSocket[i]; + udpSocket[i] = NULL; + } + } + return OK; +} + + + + + +int UDPBaseImplementation::createListeningThreads(bool destroy){ + int i; + void* status; + + killAllListeningThreads = 0; + + pthread_mutex_lock(&status_mutex); + listeningthreads_mask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + if(!destroy){ + + //start listening threads + cout << "Creating Listening Threads(s)"; + + currentListeningThreadIndex = -1; + + for(i = 0; i < numListeningThreads; ++i){ + sem_init(&listensmp[i],1,0); + thread_started = 0; + currentListeningThreadIndex = i; + if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ + cout << "Could not create listening thread with index " << i << endl; + return FAIL; + } + while(!thread_started); + cout << "."; + cout << flush; + } +#ifdef VERBOSE + cout << "Listening thread(s) created successfully." << endl; +#else + cout << endl; +#endif + }else{ + cout<<"Destroying Listening Thread(s)"<initEventTree(temp, &iframe); + //resets the pedestalSubtraction array and the commonModeSubtraction + singlePhotonDet[ithr]->newDataSet(); + if(myFile[ithr]==NULL){ + cout<<"file null"<IsOpen()){ + cout<<"file not open"< DO_NOTHING){ + //close + if(sfilefd){ + fclose(sfilefd); + sfilefd = NULL; + } + //open file + if(!overwrite){ + if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ + cout << "Error: Could not create new file " << savefilename << endl; + return FAIL; + } + }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ + cout << "Error: Could not create file " << savefilename << endl; + return FAIL; + } + //setting buffer + setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + + //printing packet losses and file names + if(!packetsCaught) + cout << savefilename << endl; + else{ + cout << savefilename + << "\tpacket loss " + << setw(4)<GetCurrentFile(); + + if(myFile[ithr]->Write()) + //->Write(tall->GetName(),TObject::kOverwrite); + cout << "Thread " << ithr <<": wrote frames to file" << endl; + else + cout << "Thread " << ithr << ": could not write frames to file" << endl; + + }else + cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; + //close file + if(myTree[ithr] && myFile[ithr]) + myFile[ithr] = myTree[ithr]->GetCurrentFile(); + if(myFile[ithr] != NULL) + myFile[ithr]->Close(); + myFile[ithr] = NULL; + myTree[ithr] = NULL; + pthread_mutex_unlock(&write_mutex); + +#endif + } +} + + + + + +int UDPBaseImplementation::startReceiver(char message[]){ + int i; + + +// #ifdef VERBOSE + cout << "Starting Receiver" << endl; +//#endif + + + //reset listening thread variables + measurementStarted = false; + //should be set to zero as its added to get next start frame indices for scans for eiger + if(!acqStarted) currframenum = 0; + startFrameIndex = 0; + + for(int i = 0; i < numListeningThreads; ++i) + totalListeningFrameCount[i] = 0; + + //udp socket + if(createUDPSockets() == FAIL){ + strcpy(message,"Could not create UDP Socket(s).\n"); + cout << endl << message << endl; + return FAIL; + } + cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; + + + if(setupWriter() == FAIL){ + //stop udp socket + shutDownUDPSockets(); + + sprintf(message,"Could not create file %s.\n",savefilename); + return FAIL; + } + cout << "Successfully created file(s)" << endl; + + //done to give the gui some proper name instead of always the last file name + if(dataCompression) + sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + + //initialize semaphore + sem_init(&smp,1,0); + + //status + pthread_mutex_lock(&status_mutex); + status = RUNNING; + for(i=0;istartListening(); + + return this_pointer; +} + + + +void* UDPBaseImplementation::startWritingThread(void* this_pointer){ + ((UDPBaseImplementation*)this_pointer)->startWriting(); + return this_pointer; +} + + + + + + +int UDPBaseImplementation::startListening(){ + int ithread = currentListeningThreadIndex; +#ifdef VERYVERBOSE + cout << "In startListening() " << endl; +#endif + + thread_started = 1; + + int i,total; + int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; + uint32_t lastframeheader;// for moench to check for all the packets in last frame + char* tempchar = NULL; + int imageheader = 0; + if(myDetectorType==EIGER) + imageheader = EIGER_IMAGE_HEADER_SIZE; + + + while(1){ + //variables that need to be checked/set before each acquisition + carryonBufferSize = 0; + //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later + maxBufferSize = bufferSize * numJobsPerThread; +#ifdef VERYDEBUG + cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; +#endif + + if(tempchar) {delete [] tempchar;tempchar = NULL;} + if(myDetectorType != EIGER) + tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size + + + while((1<pop(buffer[ithread]); +#ifdef VERYDEBUG + cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; +#endif + + + //receive + if(udpSocket[ithread] == NULL){ + rc = 0; + cout << ithread << "UDP Socket is NULL" << endl; + } + //normal listening + else if(!carryonBufferSize){ + + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + expected = maxBufferSize; + + } + //the remaining packets from previous buffer + else{ +#ifdef VERYDEBUG + cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; + cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) + & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); + expected = maxBufferSize - carryonBufferSize; + } + +#ifdef VERYDEBUG + cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; +#endif + + + + + //start indices for each start of scan/acquisition - eiger does it before + if((!measurementStarted) && (rc > 0) && (!ithread)) + startFrameIndices(ithread); + + //problem in receiving or end of acquisition + if((rc < expected)||(rc <= 0)){ + stopListening(ithread,rc,packetcount,total); + continue; + } + + + + //reset + packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; + carryonBufferSize = 0; + + + + //check if last packet valid and calculate packet count + switch(myDetectorType){ + + case MOENCH: + lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; + cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; + cout << "last packet offset:" << lastpacketoffset << endl; + cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; + cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + //moench last packet value is 0 + if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ + lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; + carryonBufferSize += onePacketSize; + lastpacketoffset -= onePacketSize; + --packetcount; + while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ + carryonBufferSize += onePacketSize; + lastpacketoffset -= onePacketSize; + --packetcount; + } + memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); +#ifdef VERYDEBUG + cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) + & (frameIndexMask)) >> frameIndexOffset) << endl; + cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) + & (packetIndexMask)) << endl; +#endif + } + break; + + case GOTTHARD: + if(shortFrame == -1){ + lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cout << "last packet offset:" << lastpacketoffset << endl; +#endif + + if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ + memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); +#ifdef VERYDEBUG + cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) + & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + carryonBufferSize = onePacketSize; + --packetcount; + } + } +#ifdef VERYDEBUG + cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + break; + default: + + break; + + } + + + // cout<<"*********** "<fnum)<push(buffer[ithread])); +#ifdef VERYDEBUG + if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; +#endif + } + + sem_wait(&listensmp[ithread]); + + //make sure its not exiting thread + if(killAllListeningThreads){ + cout << ithread << " good bye listening thread" << endl; + if(tempchar) {delete [] tempchar;tempchar = NULL;} + pthread_exit(NULL); + } + } + + return OK; +} + + + + + + + + + + + + + +int UDPBaseImplementation::startWriting(){ + int ithread = currentWriterThreadIndex; +#ifdef VERYVERBOSE + cout << ithread << "In startWriting()" <pop(wbuf[i]); + numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); +#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << endl; +#endif + } + +#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; +#endif + + + //last dummy packet + if(numpackets == 0xFFFF){ + stopWriting(ithread,wbuf); + continue; + } + + + + + //for progress + if(myDetectorType == EIGER){ + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 + }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + pthread_mutex_lock(&progress_mutex); + if(tempframenum > currframenum) + currframenum = tempframenum; + pthread_mutex_unlock(&progress_mutex); + } +//#ifdef VERYDEBUG + if(myDetectorType == EIGER) + cout << endl < 0){ + for(i=0;ipush(wbuf[i])); +#ifdef VERYDEBUG + cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; +#endif + } + + + } + else{ + //copy to gui + copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYVERBOSE + cout << ithread << " finished copying" << endl; +#endif + while(!fifoFree[0]->push(wbuf[0])); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuf[0]<fnum); + //gotthard has +1 for frame number and not a short frame + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset); + else + startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) + & (frameIndexMask)) >> frameIndexOffset); + + + //start of acquisition + if(!acqStarted){ + startAcquisitionIndex=startFrameIndex; + currframenum = startAcquisitionIndex; + acqStarted = true; + cout << "startAcquisitionIndex:" << startAcquisitionIndex<push(buffer[ithread]); + exit(-1); + } + //push the last buffer into fifo + if(rc > 0){ + pc = (rc/onePacketSize); +#ifdef VERYDEBUG + cout << ithread << " *** last packetcount:" << pc << endl; +#endif + (*((uint16_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef VERYDEBUG + cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; +#endif + } + + + //push dummy buffer to all writer threads + for(i=0;ipop(buffer[ithread]); + (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; +#ifdef VERYDEBUG + cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; +#endif + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef VERYDEBUG + cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; +#endif + } + + //reset mask and exit loop + pthread_mutex_lock(&status_mutex); + listeningthreads_mask^=(1< 1) + cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; +#endif + while(listeningthreads_mask) + usleep(5000); +#ifdef VERYDEBUG + t = 0; + for(i=0;ipush(wbuffer[i])); +#ifdef VERYDEBUG + cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; +#endif + } + + + + //all threads need to close file, reset mask and exit loop + closeFile(ithread); + pthread_mutex_lock(&status_mutex); + writerthreads_mask^=(1< 0){ + + //for progress and packet loss calculation(new files) + if(myDetectorType == EIGER); + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + if(tempframenum > currframenum) + currframenum = tempframenum; + } +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + + //lock + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + + + //to create new file when max reached + packetsToSave = maxPacketsPerFile - packetsInFile; + if(packetsToSave > numpackets) + packetsToSave = numpackets; +/**next time offset is still plus header length*/ + fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); + packetsInFile += packetsToSave; + packetsCaught += packetsToSave; + totalPacketsCaught += packetsToSave; + + + //new file + if(packetsInFile >= maxPacketsPerFile){ + //for packet loss + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); + if(myDetectorType == EIGER); + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + if(tempframenum > currframenum) + currframenum = tempframenum; + } +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + //create + createNewFile(); + } + + //unlock + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); + + + offset += (packetsToSave * onePacketSize); + numpackets -= packetsToSave; + } + + } + else{ + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + packetsInFile += numpackets; + packetsCaught += numpackets; + totalPacketsCaught += numpackets; + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); + } +} + + + + + + + + + + + + + + +void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ + +#if defined(MYROOT1) && defined(ALLFILE_DEBUG) + writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); +#endif + + eventType thisEvent = PEDESTAL; + int ndata; + char* buff = 0; + data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; + int remainingsize = npackets * onePacketSize; + int np; + int once = 0; + double tot, tl, tr, bl, br; + int xmin = 1, ymin = 1, ix, iy; + + + while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ + np = ndata/onePacketSize; + + //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); + + //only for moench + if(commonModeSubtractionEnable){ + for(ix = xmin - 1; ix < xmax+1; ix++){ + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); + } + } + } + + + for(ix = xmin - 1; ix < xmax+1; ix++) + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); + if (nf>1000) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + if (thisEvent==PHOTON_MAX) { + receiverdata[ithread]->getFrameNumber(buff); + //iFrame=receiverdata[ithread]->getFrameNumber(buff); +#ifdef MYROOT1 + myTree[ithread]->Fill(); + //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; +#else + pthread_mutex_lock(&write_mutex); + if((enableFileWrite) && (sfilefd)) + singlePhotonDet[ithread]->writeCluster(sfilefd); + pthread_mutex_unlock(&write_mutex); +#endif + } + } + } + + nf++; +#ifndef ALLFILE + pthread_mutex_lock(&progress_mutex); + packetsInFile += packetsPerFrame; + packetsCaught += packetsPerFrame; + totalPacketsCaught += packetsPerFrame; + if(packetsInFile >= maxPacketsPerFile) + createNewFile(); + pthread_mutex_unlock(&progress_mutex); + +#endif + if(!once){ + copyFrameToGui(NULL,-1,buff); + once = 1; + } + } + + remainingsize -= ((buff + ndata) - data); + data = buff + ndata; + if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) + cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuffer[0]<= 0){ + + tengigaEnable = enable; + + if(myDetectorType == EIGER){ + + if(!tengigaEnable){ + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + }else{ + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; + } + frameSize = onePacketSize * packetsPerFrame; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) + //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + + + cout<<"packetsPerFrame:"< +#include +#endif + + +#include +#include +#include +#include + + +/** + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + */ + +class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterface { + + public: + /** + * Constructor + */ + UDPBaseImplementation(); + + /** + * Destructor + */ + virtual ~UDPBaseImplementation(); + + + + /** + * delete and free member parameters + */ + void deleteMembers(); + + /** + * initialize member parameters + */ + void initializeMembers(); + + /** + * Set receiver type + * @param det detector type + * Returns success or FAIL + */ + int setDetectorType(detectorType det); + + + //Frame indices and numbers caught + /** + * Returns current Frame Index Caught for an entire acquisition (including all scans) + */ + uint32_t getAcquisitionIndex(); + + /** + * Returns if acquisition started + */ + bool getAcquistionStarted(); + + /** + * Returns Frames Caught for each real time acquisition (eg. for each scan) + */ + int getFramesCaught(); + + /** + * Returns Total Frames Caught for an entire acquisition (including all scans) + */ + int getTotalFramesCaught(); + + /** + * Returns the frame index at start of each real time acquisition (eg. for each scan) + */ + uint32_t getStartFrameIndex(); + + /** + * Returns current Frame Index for each real time acquisition (eg. for each scan) + */ + uint32_t getFrameIndex(); + + /** + * Returns if measurement started + */ + bool getMeasurementStarted(); + + /** + * Resets the Total Frames Caught + * This is how the receiver differentiates between entire acquisitions + * Returns 0 + */ + void resetTotalFramesCaught(); + + + + + //file parameters + /** + * Returns File Path + */ + char* getFilePath() const; + + /** + * Set File Path + * @param c file path + */ + char* setFilePath(const char c[]); + + /** + * Returns File Name + */ + char* getFileName() const; + + /** + * Set File Name (without frame index, file index and extension) + * @param c file name + */ + char* setFileName(const char c[]); + + /** + * Returns File Index + */ + int getFileIndex(); + + /** + * Set File Index + * @param i file index + */ + int setFileIndex(int i); + + /** + * Set Frame Index Needed + * @param i frame index needed + */ + int setFrameIndexNeeded(int i); + + /** + * Set enable file write + * @param i file write enable + * Returns file write enable + */ + int setEnableFileWrite(int i); + + /** + * Enable/disable overwrite + * @param i enable + * Returns enable over write + */ + int setEnableOverwrite(int i); + + /** + * Returns file write enable + * 1: YES 0: NO + */ + int getEnableFileWrite() const; + + /** + * Returns file over write enable + * 1: YES 0: NO + */ + int getEnableOverwrite() const; + +//other parameters + + /** + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + void abort() {}; + + /** + * Returns status of receiver: idle, running or error + */ + runStatus getStatus() const; + + /** + * Set detector hostname + * @param c hostname + */ + void initialize(const char *detectorHostName); + + /* Returns detector hostname + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ + char *getDetectorHostname() const; + + /** + * Set Ethernet Interface or IP to listen to + */ + void setEthernetInterface(char* c); + + /** + * Set UDP Port Number + */ + void setUDPPortNo(int p); + + /* + * Returns number of frames to receive + * This is the number of frames to expect to receiver from the detector. + * The data receiver will change from running to idle when it got this number of frames + */ + int getNumberOfFrames() const; + + /** + * set frame number if a positive number + */ + int32_t setNumberOfFrames(int32_t fnum); + + /** + * Returns scan tag + */ + int getScanTag() const; + + /** + * set scan tag if its is a positive number + */ + int32_t setScanTag(int32_t stag); + + /** + * Returns the number of bits per pixel + */ + int getDynamicRange() const; + + /** + * set dynamic range if its is a positive number + */ + int32_t setDynamicRange(int32_t dr); + + /** + * Set short frame + * @param i if shortframe i=1 + */ + int setShortFrame(int i); + + /** + * Set the variable to send every nth frame to gui + * or if 0,send frame only upon gui request + */ + int setNFrameToGui(int i); + + /** set acquisition period if a positive number + */ + int64_t setAcquisitionPeriod(int64_t index); + + /** get data compression, by saving only hits + */ + bool getDataCompression(); + + /** enabl data compression, by saving only hits + /returns if failed + */ + int enableDataCompression(bool enable); + + /** + * enable 10Gbe + @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out + \returns enable for 10Gbe + */ + int enableTenGiga(int enable = -1); + + + +//other functions + + /** + * Returns the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param fnum frame number for eiger as it is not in the packet + */ + void readFrame(char* c,char** raw, uint32_t &fnum); + + /** + * Closes all files + * @param ithr thread index + */ + void closeFile(int ithr = -1); + + /** + * Starts Receiver - starts to listen for packets + * @param message is the error message if there is an error + * Returns success + */ + int startReceiver(char message[]); + + /** + * Stops Receiver - stops listening for packets + * Returns success + */ + int stopReceiver(); + + /** set status to transmitting and + * when fifo is empty later, sets status to run_finished + */ + void startReadout(); + + /** + * shuts down the udp sockets + * \returns if success or fail + */ + int shutDownUDPSockets(); + +private: + + /* + void not_implemented(string method_name){ + std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; + }; + */ + /** + * Deletes all the filter objects for single photon data + */ + void deleteFilter(); + + /** + * Constructs the filter for single photon data + */ + void setupFilter(); + + /** + * set up fifo according to the new numjobsperthread + */ + void setupFifoStructure (); + + /** + * Copy frames to gui + * uses semaphore for nth frame mode + */ + void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); + + /** + * creates udp sockets + * \returns if success or fail + */ + int createUDPSockets(); + + /** + * create listening thread + * @param destroy is true to kill all threads and start again + */ + int createListeningThreads(bool destroy = false); + + /** + * create writer threads + * @param destroy is true to kill all threads and start again + */ + int createWriterThreads(bool destroy = false); + + /** + * set thread priorities + */ + void setThreadPriorities(); + + /** + * initializes variables and creates the first file + * also does the startAcquisitionCallBack + * \returns FAIL or OK + */ + int setupWriter(); + + /** + * Creates new tree and file for compression + * @param ithr thread number + * @param iframe frame number + *\returns OK for succces or FAIL for failure + */ + int createCompressionFile(int ithr, int iframe); + + /** + * Creates new file + *\returns OK for succces or FAIL for failure + */ + int createNewFile(); + + /** + * Static function - Thread started which listens to packets. + * Called by startReceiver() + * @param this_pointer pointer to this object + */ + static void* startListeningThread(void *this_pointer); + + /** + * Static function - Thread started which writes packets to file. + * Called by startReceiver() + * @param this_pointer pointer to this object + */ + static void* startWritingThread(void *this_pointer); + + /** + * Thread started which listens to packets. + * Called by startReceiver() + * + */ + int startListening(); + + /** + * Thread started which writes packets to file. + * Called by startReceiver() + * + */ + int startWriting(); + + /** + * Writing to file without compression + * @param buf is the address of buffer popped out of fifo + * @param numpackets is the number of packets + * @param framenum current frame number + */ + void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); + + /** + * Its called for the first packet of a scan or acquistion + * Sets the startframeindices and the variables to know if acquisition started + * @param ithread listening thread number + */ + void startFrameIndices(int ithread); + + /** + * This is called when udp socket is shut down + * It pops ffff instead of packet number into fifo + * to inform writers about the end of listening session + * @param ithread listening thread number + * @param rc number of bytes received + * @param pc packet count + * @param t total packets listened to + */ + void stopListening(int ithread, int rc, int &pc, int &t); + + /** + * When acquisition is over, this is called + * @param ithread listening thread number + * @param wbuffer writer buffer + */ + void stopWriting(int ithread, char* wbuffer[]); + + + /** + * data compression for each fifo output + * @param ithread listening thread number + * @param wbuffer writer buffer + * @param npackets number of packets from the fifo + * @param data pointer to the next packet start + * @param xmax max pixels in x direction + * @param ymax max pixels in y direction + * @param nf nf + */ + void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); + + + /** structure of an eiger image header*/ + typedef struct + { + unsigned char header_before[20]; + unsigned char fnum[4]; + unsigned char header_after[24]; + } eiger_image_header; + + + /** structure of an eiger image header*/ + typedef struct + { + unsigned char num1[4]; + unsigned char num2[4]; + } eiger_packet_header; + + /** max number of listening threads */ + const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; + + /** max number of writer threads */ + const static int MAX_NUM_WRITER_THREADS = 15; + + /** detector type */ + detectorType myDetectorType; + + /** detector hostname */ + char detHostname[MAX_STR_LENGTH]; + + /** status of receiver */ + runStatus status; + + /** UDP Socket between Receiver and Detector */ + genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; + + /** Server UDP Port*/ + int server_port[MAX_NUM_LISTENING_THREADS]; + + /** ethernet interface or IP to listen to */ + char *eth; + + /** max packets per file **/ + int maxPacketsPerFile; + + /** File write enable */ + int enableFileWrite; + + /** File over write enable */ + int overwrite; + + /** Complete File name */ + char savefilename[MAX_STR_LENGTH]; + + /** File Name without frame index, file index and extension*/ + char fileName[MAX_STR_LENGTH]; + + /** File Path */ + char filePath[MAX_STR_LENGTH]; + + /** File Index */ + int fileIndex; + + /** scan tag */ + int scanTag; + + /** if frame index required in file name */ + int frameIndexNeeded; + + /* Acquisition started */ + bool acqStarted; + + /* Measurement started */ + bool measurementStarted; + + /** Frame index at start of each real time acquisition (eg. for each scan) */ + uint32_t startFrameIndex; + + /** Actual current frame index of each time acquisition (eg. for each scan) */ + uint32_t frameIndex; + + /** Frames Caught for each real time acquisition (eg. for each scan) */ + int packetsCaught; + + /** Total packets caught for an entire acquisition (including all scans) */ + int totalPacketsCaught; + + /** Pckets currently in current file, starts new file when it reaches max */ + int packetsInFile; + + /** Frame index at start of an entire acquisition (including all scans) */ + uint32_t startAcquisitionIndex; + + /** Actual current frame index of an entire acquisition (including all scans) */ + uint32_t acquisitionIndex; + + /** number of packets per frame*/ + int packetsPerFrame; + + /** frame index mask */ + uint32_t frameIndexMask; + + /** packet index mask */ + uint32_t packetIndexMask; + + /** frame index offset */ + int frameIndexOffset; + + /** acquisition period */ + int64_t acquisitionPeriod; + + /** frame number */ + int32_t numberOfFrames; + + /** dynamic range */ + int dynamicRange; + + /** short frames */ + int shortFrame; + + /** current frame number */ + uint32_t currframenum; + + /** Previous Frame number from buffer */ + uint32_t prevframenum; + + /** size of one frame */ + int frameSize; + + /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ + int bufferSize; + + /** oen buffer size */ + int onePacketSize; + + /** latest data */ + char* latestData; + + /** gui data ready */ + int guiDataReady; + + /** points to the data to send to gui */ + char* guiData; + + /** points to the filename to send to gui */ + char* guiFileName; + + /** temporary number for eiger frame number as its not included in the packet */ + uint32_t guiFrameNumber; + + /** send every nth frame to gui or only upon gui request*/ + int nFrameToGui; + + /** fifo size */ + unsigned int fifosize; + + /** number of jobs per thread for data compression */ + int numJobsPerThread; + + /** datacompression - save only hits */ + bool dataCompression; + + /** memory allocated for the buffer */ + char *mem0[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data read */ + CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data already written and ready to be resued*/ + CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; + + /** Receiver buffer */ + char *buffer[MAX_NUM_LISTENING_THREADS]; + + /** number of writer threads */ + int numListeningThreads; + + /** number of writer threads */ + int numWriterThreads; + + /** to know if listening and writer threads created properly */ + int thread_started; + + /** current listening thread index*/ + int currentListeningThreadIndex; + + /** current writer thread index*/ + int currentWriterThreadIndex; + + /** thread listening to packets */ + pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; + + /** thread writing packets */ + pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; + + /** total frame count the listening thread has listened to */ + int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; + + /** mask showing which listening threads are running */ + volatile uint32_t listeningthreads_mask; + + /** mask showing which writer threads are running */ + volatile uint32_t writerthreads_mask; + + /** mask showing which threads have created files*/ + volatile uint32_t createfile_mask; + + /** OK if file created was successful */ + int ret_createfile; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllListeningThreads; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllWritingThreads; + + /** 10Gbe enable*/ + int tengigaEnable; + + + + +//semaphores + /** semaphore to synchronize writer and guireader threads */ + sem_t smp; + /** semaphore to synchronize listener threads */ + sem_t listensmp[MAX_NUM_LISTENING_THREADS]; + /** semaphore to synchronize writer threads */ + sem_t writersmp[MAX_NUM_WRITER_THREADS]; + + +//mutex + /** guiDataReady mutex */ + pthread_mutex_t dataReadyMutex; + + /** mutex for status */ + pthread_mutex_t status_mutex; + + /** mutex for progress variable currframenum */ + pthread_mutex_t progress_mutex; + + /** mutex for writing data to file */ + pthread_mutex_t write_mutex; + + /** File Descriptor */ + FILE *sfilefd; + + //filter + singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + moenchCommonMode *cmSub; + bool commonModeSubtractionEnable; + +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUM_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUM_WRITER_THREADS]; +#endif + + + + /** + callback arguments are + filepath + filename + fileindex + data size + + return value is + 0 callback takes care of open,close,write file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + + */ + int (*startAcquisitionCallBack)(char*, char*,int, int, void*); + void *pStartAcquisition; + + /** + args to acquisition finished callback + total frames caught + + */ + void (*acquisitionFinishedCallBack)(int, void*); + void *pAcquisitionFinished; + + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); + void *pRawDataReady; + + /** The action which decides what the user and default responsibilites to save data are + * 0 raw data ready callback takes care of open,close,write file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ + int cbAction; + + +public: + + + /** + callback arguments are + filepath + filename + fileindex + datasize + + return value is + 0 callback takes care of open,close,wrie file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + */ + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; + + /** + callback argument is + toatal frames caught + */ + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; +}; + + +#endif + +//#endif diff --git a/slsReceiverSoftware/slsReceiver/UDPInterface.cpp b/slsReceiverSoftware/slsReceiver/UDPInterface.cpp new file mode 100644 index 0000000000..d53166f9e6 --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/UDPInterface.cpp @@ -0,0 +1,43 @@ +//#ifdef SLS_RECEIVER_UDP_FUNCTIONS +/********************************************//** + * @file slsReceiverUDPFunctions.cpp + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + ***********************************************/ + + + + +#include // SIGINT +#include // stat +#include // socket(), bind(), listen(), accept(), shut down +#include // sock_addr_in, htonl, INADDR_ANY +#include // exit() +#include //set precision +#include //munmap + +#include +#include +using namespace std; + +#include "UDPInterface.h" +#include "UDPBaseImplementation.h" + +#include "moench02ModuleData.h" +#include "gotthardModuleData.h" +#include "gotthardShortModuleData.h" + + +using namespace std; + +UDPInterface * UDPInterface::create(string receiver_type){ + + if (receiver_type == "standard") + return new UDPBaseImplementation(); + else{ + cout << "[ERROR] UDP interface not supported, using standard implementation" << endl; + return new UDPBaseImplementation(); + } +} + + +//#endif diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverBase.h b/slsReceiverSoftware/slsReceiver/UDPInterface.h similarity index 93% rename from slsReceiverSoftware/slsReceiver/slsReceiverBase.h rename to slsReceiverSoftware/slsReceiver/UDPInterface.h index 007bf4a970..74f471ae09 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverBase.h +++ b/slsReceiverSoftware/slsReceiver/UDPInterface.h @@ -1,7 +1,7 @@ -#ifndef SLSRECEIVERBASE_H -#define SLSRECEIVERBASE_H +#ifndef UDPINTERFACE_H +#define UDPINTERFACE_H /*********************************************** - * @file slsReceiverBase.h + * @file UDPInterface.h * @short base class with all the functions for a receiver, set/get parameters, start/stop etc. ***********************************************/ /** @@ -12,19 +12,35 @@ * @short base class with all the functions for a receiver, set/get parameters, start/stop etc. */ -class slsReceiverBase { +#include "sls_receiver_defs.h" +#include "receiver_defs.h" +#include "MySocketTCP.h" -public: +/* +void print_not_implemented(string method_name){ + std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; +} +*/ - /** - * constructor - */ - slsReceiverBase(){}; - - /** - * Destructor - */ - virtual ~slsReceiverBase() {}; +class UDPInterface { + + public: + + /** + * constructor + */ + //UDPInterface(){}; + + /** + * Destructor + */ + virtual ~UDPInterface() {}; + + /** + * Factory create method + */ + static UDPInterface *create(string receiver_type = "standard"); + /** * Initialize the Receiver @@ -32,7 +48,7 @@ class slsReceiverBase { * you can call this function only once. You must call it before you call startReceiver() for the first time. */ virtual void initialize(const char *detectorHostName) = 0; - + /* Returns detector hostname /returns hostname @@ -44,7 +60,7 @@ class slsReceiverBase { /** * Returns status of receiver: idle, running or error */ - virtual slsReceiverDefs::runStatus getStatus() const = 0; + virtual slsReceiverDefs::runStatus getStatus() const = 0; /** * Returns File Name diff --git a/slsReceiverSoftware/slsReceiver/main.cpp b/slsReceiverSoftware/slsReceiver/main.cpp index 3513a26c74..87d947a7db 100644 --- a/slsReceiverSoftware/slsReceiver/main.cpp +++ b/slsReceiverSoftware/slsReceiver/main.cpp @@ -75,6 +75,7 @@ int main(int argc, char *argv[]) { //start tcp server thread if(user->start() == slsReceiverDefs::OK){ + cout << "DONE!" << endl; string str; cin>>str; //wait and look for an exit keyword diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp index cd5ab551d1..45359d02f1 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp @@ -10,24 +10,26 @@ #include #include "slsReceiver.h" -#include "slsReceiverUDPFunctions.h" -#include "eigerReceiver.h" +//#include "slsReceiverUDPFunctions.h" +//#include "eigerReceiver.h" + +#include "UDPInterface.h" +//#include "UDPBaseImplementation.h" + + +#include "utilities.h" using namespace std; slsReceiver::slsReceiver(int argc, char *argv[], int &success){ + //creating base receiver - cout << "SLS Receiver" << endl; - receiverBase = new slsReceiverUDPFunctions(); int tcpip_port_no=-1; - - ifstream infile; string sLine,sargname; int iline = 0; - success=OK; string fname = ""; @@ -38,34 +40,34 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ if(iarg+1==argc){ cout << "no config file name given. Exiting." << endl; success=FAIL; - }else + } + else fname.assign(argv[iarg+1]); } } if((!fname.empty()) && (success == OK)){ -#ifdef VERBOSE - std::cout<< "config file name "<< fname << std::endl; -#endif + + VERBOSE_PRINT("config file name " + fname ); + infile.open(fname.c_str(), ios_base::in); if (infile.is_open()) { while(infile.good()){ getline(infile,sLine); iline++; -#ifdef VERBOSE - cout << sLine << endl; -#endif + + VERBOSE_PRINT(sLine); + if(sLine.find('#')!=string::npos){ -#ifdef VERBOSE - cout << "Line is a comment " << endl; -#endif + VERBOSE_PRINT( "Line is a comment "); continue; - }else if(sLine.length()<2){ -#ifdef VERBOSE - cout << "Empty line " << endl; -#endif + } + else if(sLine.length()<2){ + VERBOSE_PRINT("Empty line "); continue; - }else{ + } + else{ istringstream sstr(sLine); + //parameter name if(sstr.good()) sstr >> sargname; @@ -85,14 +87,13 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ } } infile.close(); - }else { + } + else { cout << "Error opening configuration file " << fname << endl; success = FAIL; } -#ifdef VERBOSE - cout << "Read configuration file of " << iline << " lines" << endl; -#endif + VERBOSE_PRINT("Read configuration file of " + iline + " lines"); } @@ -131,16 +132,16 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ } - if (success==OK) - tcpipInterface = new slsReceiverTCPIPInterface(success,receiverBase, tcpip_port_no); - //tcp ip interface - - - + if (success==OK){ + cout << "SLS Receiver" << endl; + udp_interface = UDPInterface::create("stasndard"); + tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no); + //tcp ip interface + } } -slsReceiver::~slsReceiver() {if(receiverBase) delete receiverBase; if(tcpipInterface) delete tcpipInterface;} +slsReceiver::~slsReceiver() {if(udp_interface) delete udp_interface; if(tcpipInterface) delete tcpipInterface;} int slsReceiver::start() { @@ -158,7 +159,6 @@ void slsReceiver::closeFile(int p) { } - int64_t slsReceiver::getReceiverVersion(){ tcpipInterface->getReceiverVersion(); } @@ -166,20 +166,20 @@ int64_t slsReceiver::getReceiverVersion(){ void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ //tcpipInterface - receiverBase->registerCallBackStartAcquisition(func,arg); + udp_interface->registerCallBackStartAcquisition(func,arg); } void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ //tcpipInterface - receiverBase->registerCallBackAcquisitionFinished(func,arg); + udp_interface->registerCallBackAcquisitionFinished(func,arg); } void slsReceiver::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ - //tcpipInterface - receiverBase->registerCallBackRawDataReady(func,arg); + //tcpipInterface + udp_interface->registerCallBackRawDataReady(func,arg); } diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.h b/slsReceiverSoftware/slsReceiver/slsReceiver.h index 1ab8c764a7..899dabe8d2 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.h @@ -7,8 +7,12 @@ #include "slsReceiverTCPIPInterface.h" -#include "slsReceiverBase.h" +#include "UDPInterface.h" +#include "UDPBaseImplementation.h" +#include "sls_receiver_defs.h" +#include "receiver_defs.h" +#include "MySocketTCP.h" @@ -17,8 +21,8 @@ */ class slsReceiver : private virtual slsReceiverDefs { - -public: + + public: /** * Constructor * creates the tcp interface and the udp class @@ -80,9 +84,9 @@ class slsReceiver : private virtual slsReceiverDefs { void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg); -private: - slsReceiverTCPIPInterface* tcpipInterface; - slsReceiverBase* receiverBase; + private: + slsReceiverTCPIPInterface* tcpipInterface; + UDPInterface* udp_interface; }; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index cc143efc45..ea59d4bce1 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -4,7 +4,7 @@ ***********************************************/ #include "slsReceiverTCPIPInterface.h" -#include "slsReceiverBase.h" +#include "UDPInterface.h" #include "gitInfoReceiver.h" #include "slsReceiverUsers.h" #include "slsReceiver.h" @@ -28,7 +28,7 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { } -slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn): +slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn): myDetectorType(GOTTHARD), receiverBase(rbase), ret(OK), @@ -124,9 +124,9 @@ int slsReceiverTCPIPInterface::start(){ cout << "Could not create TCP Server thread" << endl; return FAIL; } -#ifdef VERBOSE + //#ifdef VERBOSE cout << "TCP Server thread created successfully." << endl; -#endif + //#endif return OK; } @@ -503,7 +503,7 @@ int slsReceiverTCPIPInterface::set_file_dir() { - +// LEO: do we need it in the base class? int slsReceiverTCPIPInterface::set_file_index() { ret=OK; int retval=-1; @@ -608,7 +608,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { - +//LEO: is the client that commands the setup, or you just need the args? int slsReceiverTCPIPInterface::setup_udp(){ ret=OK; strcpy(mess,"could not set up udp connection"); @@ -1773,7 +1773,7 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { - +//LEO: why the receiver should set the dynamic range? int slsReceiverTCPIPInterface::set_dynamic_range() { ret=OK; int retval=-1; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index 423d0949ab..adff81697b 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -9,7 +9,7 @@ #include "sls_receiver_defs.h" #include "receiver_defs.h" #include "MySocketTCP.h" -#include "slsReceiverBase.h" +#include "UDPInterface.h" @@ -18,8 +18,8 @@ */ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { - -public: + + public: /** * Constructor * reads config file, creates socket, assigns function table @@ -27,16 +27,16 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { * @param rbase pointer to the receiver base * @param pn port number (defaults to default port number) */ - slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn=-1); - + slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn=-1); + /** * Sets the port number to listen to. Take care that the client must know to whcih port it has to listen to, so normally it is better to use a fixes port from the instatiation or change it from the client. @param pn port number (-1 only get) \returns actual port number - */ - int setPortNumber(int pn=-1); - + */ + int setPortNumber(int pn=-1); + /** * Starts listening on the TCP port for client comminication \returns OK or FAIL @@ -234,7 +234,7 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { detectorType myDetectorType; /** slsReceiverBase object */ - slsReceiverBase *receiverBase; + UDPInterface *receiverBase; /** Number of functions */ static const int numberOfFunctions = 256; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index 3cc4fef383..bb8f213a51 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -6,6 +6,8 @@ #include "slsReceiverUDPFunctions.h" +#include "UDPBaseImplementation.h" + #include "moench02ModuleData.h" #include "gotthardModuleData.h" @@ -28,6 +30,9 @@ using namespace std; +slsReceiverUDPFunctions * slsReceiverUDPFunctions::create(void){ + return slsReceiverUDPFunctions(); +} slsReceiverUDPFunctions::slsReceiverUDPFunctions(): thread_started(0), @@ -695,7 +700,7 @@ void slsReceiverUDPFunctions::setupFilter(){ - +//LEO: it is not clear to me.. void slsReceiverUDPFunctions::setupFifoStructure(){ int64_t i; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h index 347a143581..6adce30ada 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h @@ -7,15 +7,17 @@ ***********************************************/ -#include "sls_receiver_defs.h" -#include "receiver_defs.h" -#include "genericSocket.h" +//#include "sls_receiver_defs.h" +//#include "receiver_defs.h" +//#include "genericSocket.h" #include "circularFifo.h" #include "singlePhotonDetector.h" #include "slsReceiverData.h" #include "moenchCommonMode.h" -#include "slsReceiverBase.h" + +#include "UDPInterface.h" +#include "UDPBaseImplementation.h" #ifdef MYROOT1 @@ -34,9 +36,10 @@ * @short does all the functions for a receiver, set/get parameters, start/stop etc. */ -class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public slsReceiverBase { -public: +class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public UDPInterface { + + public: /** * Constructor */ diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h index a9d3626d28..50d6f38feb 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUsers.h @@ -1,4 +1,3 @@ - #ifndef SLS_RECEIVER_USERS_H #define SLS_RECEIVER_USERS_H @@ -29,7 +28,7 @@ class slsReceiverUsers { * @param argv from command line * @param succecc socket creation was successfull */ - slsReceiverUsers(int argc, char *argv[], int &success); + slsReceiverUsers(int argc, char *argv[], int &success); /** Destructor */ From 9489cb8040cc7de4fee7acca82e56e9c12bfdb88 Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Mon, 8 Sep 2014 11:44:58 +0200 Subject: [PATCH 019/222] moved config reading to utilities.h using GetOpt for CLI option reading --- .../slsReceiver/slsReceiver.cpp | 165 +++++++----------- 1 file changed, 66 insertions(+), 99 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp index 45359d02f1..fd1223b71d 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp @@ -9,132 +9,99 @@ #include #include -#include "slsReceiver.h" -//#include "slsReceiverUDPFunctions.h" -//#include "eigerReceiver.h" +#include +#include "slsReceiver.h" #include "UDPInterface.h" -//#include "UDPBaseImplementation.h" - #include "utilities.h" using namespace std; + + slsReceiver::slsReceiver(int argc, char *argv[], int &success){ + + /** + * Constructor method to start up a Receiver server. Reads configuration file, options, and + * assembles a Receiver using TCP and UDP detector interfaces + * + * @param iarg + * + * @return + */ //creating base receiver - int tcpip_port_no=-1; - - ifstream infile; - string sLine,sargname; - int iline = 0; - + int tcpip_port_no = 1984; success=OK; - string fname = ""; //parse command line for config - for(int iarg=1;iarg> sargname; - - //tcp port - if(sargname=="rx_tcpport"){ - if(sstr.good()) { - sstr >> sargname; - if(sscanf(sargname.c_str(),"%d",&tcpip_port_no)) - cout<<"dataport:"< Date: Mon, 8 Sep 2014 11:45:33 +0200 Subject: [PATCH 020/222] cleaning --- .../slsReceiver/slsReceiverUDPFunctions.cpp | 2319 ----------------- 1 file changed, 2319 deletions(-) delete mode 100644 slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp deleted file mode 100644 index bb8f213a51..0000000000 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ /dev/null @@ -1,2319 +0,0 @@ -#ifdef SLS_RECEIVER_UDP_FUNCTIONS -/********************************************//** - * @file slsReceiverUDPFunctions.cpp - * @short does all the functions for a receiver, set/get parameters, start/stop etc. - ***********************************************/ - - -#include "slsReceiverUDPFunctions.h" -#include "UDPBaseImplementation.h" - - -#include "moench02ModuleData.h" -#include "gotthardModuleData.h" -#include "gotthardShortModuleData.h" - - -#include // SIGINT -#include // stat -#include // socket(), bind(), listen(), accept(), shut down -#include // sock_addr_in, htonl, INADDR_ANY -#include // exit() -#include //set precision -#include //munmap - - - -#include -#include -using namespace std; - - - -slsReceiverUDPFunctions * slsReceiverUDPFunctions::create(void){ - return slsReceiverUDPFunctions(); -} - -slsReceiverUDPFunctions::slsReceiverUDPFunctions(): - thread_started(0), - eth(NULL), - latestData(NULL), - guiFileName(NULL), - guiFrameNumber(0), - tengigaEnable(0){ - for(int i=0;i /proc/sys/net/core/rmem_max")) - cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; - else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) - cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; - /** permanent setting heiner - net.core.rmem_max = 104857600 # 100MiB - net.core.netdev_max_backlog = 250000 - sysctl -p - // from the manual - sysctl -w net.core.rmem_max=16777216 - sysctl -w net.core.netdev_max_backlog=250000 - */ -} - - - -slsReceiverUDPFunctions::~slsReceiverUDPFunctions(){ - createListeningThreads(true); - createWriterThreads(true); - deleteMembers(); -} - - - - -void slsReceiverUDPFunctions::deleteMembers(){ - //kill threads - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - - for(int i=0;i=0) - fileIndex = i; - return getFileIndex(); -} - - -int slsReceiverUDPFunctions::setFrameIndexNeeded(int i){ - frameIndexNeeded = i; - return frameIndexNeeded; -} - - -int slsReceiverUDPFunctions::getEnableFileWrite() const{ - return enableFileWrite; -} - -int slsReceiverUDPFunctions::setEnableFileWrite(int i){ - enableFileWrite=i; - return getEnableFileWrite(); -} - -int slsReceiverUDPFunctions::getEnableOverwrite() const{ - return overwrite; -} - -int slsReceiverUDPFunctions::setEnableOverwrite(int i){ - overwrite=i; - return getEnableOverwrite(); -} - - - - - -/*other parameters*/ - -slsReceiverDefs::runStatus slsReceiverUDPFunctions::getStatus() const{ - return status; -} - - -void slsReceiverUDPFunctions::initialize(const char *detectorHostName){ - if(strlen(detectorHostName)) - strcpy(detHostname,detectorHostName); -} - - -char *slsReceiverUDPFunctions::getDetectorHostname() const{ - return (char*)detHostname; -} - -void slsReceiverUDPFunctions::setEthernetInterface(char* c){ - strcpy(eth,c); -} - - -void slsReceiverUDPFunctions::setUDPPortNo(int p){ - for(int i=0;i= 0) - numberOfFrames = fnum; - - return getNumberOfFrames(); -} - -int slsReceiverUDPFunctions::getScanTag() const{ - return scanTag; -} - - -int32_t slsReceiverUDPFunctions::setScanTag(int32_t stag){ - if(stag >= 0) - scanTag = stag; - - return getScanTag(); -} - - -int slsReceiverUDPFunctions::getDynamicRange() const{ - return dynamicRange; -} - -int32_t slsReceiverUDPFunctions::setDynamicRange(int32_t dr){ - cout << "Setting Dynamic Range" << endl; - - int olddr = dynamicRange; - if(dr >= 0){ - dynamicRange = dr; - - if(myDetectorType == EIGER){ - - - if(!tengigaEnable) - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - else - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - - if(olddr != dr){ - - //del - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - for(int i=0;i=0){ - nFrameToGui = i; - setupFifoStructure(); - } - return nFrameToGui; -} - - - -int64_t slsReceiverUDPFunctions::setAcquisitionPeriod(int64_t index){ - - if(index >= 0){ - if(index != acquisitionPeriod){ - acquisitionPeriod = index; - setupFifoStructure(); - } - } - return acquisitionPeriod; -} - - -bool slsReceiverUDPFunctions::getDataCompression(){return dataCompression;} - -int slsReceiverUDPFunctions::enableDataCompression(bool enable){ - cout << "Data compression "; - if(enable) - cout << "enabled" << endl; - else - cout << "disabled" << endl; -#ifdef MYROOT1 - cout << " WITH ROOT" << endl; -#else - cout << " WITHOUT ROOT" << endl; -#endif - //delete filter for the current number of threads - deleteFilter(); - - dataCompression = enable; - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - createWriterThreads(true); - - if(enable) - numWriterThreads = MAX_NUM_WRITER_THREADS; - else - numWriterThreads = 1; - - if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; - return FAIL; - } - setThreadPriorities(); - - - if(enable) - setupFilter(); - - return OK; -} - - - - - - - - - - - - -/*other functions*/ - - -void slsReceiverUDPFunctions::deleteFilter(){ - int i; - cmSub=NULL; - - for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); - -} - - - -//LEO: it is not clear to me.. -void slsReceiverUDPFunctions::setupFifoStructure(){ - - int64_t i; - int oldn = numJobsPerThread; - - //if every nth frame mode - if(nFrameToGui) - numJobsPerThread = nFrameToGui; - - //random nth frame mode - else{ - if(!acquisitionPeriod) - i = SAMPLE_TIME_IN_NS; - else - i = SAMPLE_TIME_IN_NS/acquisitionPeriod; - if (i > MAX_JOBS_PER_THREAD) - numJobsPerThread = MAX_JOBS_PER_THREAD; - else if (i < 1) - numJobsPerThread = 1; - else - numJobsPerThread = i; - } - - //if same, return - if(oldn == numJobsPerThread) - return; - - if(myDetectorType == EIGER) - numJobsPerThread = 1; - - //otherwise memory too much if numjobsperthread is at max = 1000 - fifosize = GOTTHARD_FIFO_SIZE; - if(myDetectorType == MOENCH) - fifosize = MOENCH_FIFO_SIZE; - else if(myDetectorType == EIGER) - fifosize = EIGER_FIFO_SIZE; - - if(fifosize % numJobsPerThread) - fifosize = (fifosize/numJobsPerThread)+1; - else - fifosize = fifosize/numJobsPerThread; - - - cout << "Number of Frames per buffer:" << numJobsPerThread << endl; - cout << "Fifo Size:" << fifosize << endl; - - /* - //for testing - numJobsPerThread = 3; fifosize = 11; - */ - - for(int i=0;iisEmpty()) - fifoFree[i]->pop(buffer[i]); - delete fifoFree[i]; - } - if(fifo[i]) delete fifo[i]; - if(mem0[i]) free(mem0[i]); - fifoFree[i] = new CircularFifo(fifosize); - fifo[i] = new CircularFifo(fifosize); - - - //allocate memory - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - /** shud let the client know about this */ - if (mem0[i]==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; - exit(-1); - } - buffer[i]=mem0[i]; - //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); - } - } - cout << "Fifo structure(s) reconstructed" << endl; -} - - - - - - - -/** acquisition functions */ - -void slsReceiverUDPFunctions::readFrame(char* c,char** raw, uint32_t &fnum){ - //point to gui data - if (guiData == NULL) - guiData = latestData; - - //copy data and filename - strcpy(c,guiFileName); - fnum = guiFrameNumber; - - - //could not get gui data - if(!guiDataReady){ - *raw = NULL; - } - //data ready, set guidata to receive new data - else{ - *raw = guiData; - guiData = NULL; - - pthread_mutex_lock(&dataReadyMutex); - guiDataReady = 0; - pthread_mutex_unlock(&dataReadyMutex); - if((nFrameToGui) && (writerthreads_mask)){ - /*if(nFrameToGui){*/ - //release after getting data - sem_post(&smp); - } - } -} - - - - - -void slsReceiverUDPFunctions::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ - - //random read when gui not ready - if((!nFrameToGui) && (!guiData)){ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - pthread_mutex_unlock(&dataReadyMutex); - } - - //random read or nth frame read, gui needs data now - else{ - /* - //nth frame read, block current process if the guireader hasnt read it yet - if(nFrameToGui) - sem_wait(&smp); -*/ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - //eiger - if(startbuf != NULL){ - int offset = 0; - int size = frameSize/EIGER_MAX_PORTS; - for(int j=0;jgetErrorStatus(); - if(iret){ -#ifdef VERBOSE - cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; -#endif - return FAIL; - } - } - - return OK; -} - - - - - - - -int slsReceiverUDPFunctions::shutDownUDPSockets(){ - for(int i=0;iShutDownSocket(); - delete udpSocket[i]; - udpSocket[i] = NULL; - } - } - return OK; -} - - - - - -int slsReceiverUDPFunctions::createListeningThreads(bool destroy){ - int i; - void* status; - - killAllListeningThreads = 0; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - if(!destroy){ - - //start listening threads - cout << "Creating Listening Threads(s)"; - - currentListeningThreadIndex = -1; - - for(i = 0; i < numListeningThreads; ++i){ - sem_init(&listensmp[i],1,0); - thread_started = 0; - currentListeningThreadIndex = i; - if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ - cout << "Could not create listening thread with index " << i << endl; - return FAIL; - } - while(!thread_started); - cout << "."; - cout << flush; - } -#ifdef VERBOSE - cout << "Listening thread(s) created successfully." << endl; -#else - cout << endl; -#endif - }else{ - cout<<"Destroying Listening Thread(s)"<initEventTree(temp, &iframe); - //resets the pedestalSubtraction array and the commonModeSubtraction - singlePhotonDet[ithr]->newDataSet(); - if(myFile[ithr]==NULL){ - cout<<"file null"<IsOpen()){ - cout<<"file not open"< DO_NOTHING){ - //close - if(sfilefd){ - fclose(sfilefd); - sfilefd = NULL; - } - //open file - if(!overwrite){ - if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cout << "Error: Could not create new file " << savefilename << endl; - return FAIL; - } - }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not create file " << savefilename << endl; - return FAIL; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - - //printing packet losses and file names - if(!packetsCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)<GetCurrentFile(); - - if(myFile[ithr]->Write()) - //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Thread " << ithr <<": wrote frames to file" << endl; - else - cout << "Thread " << ithr << ": could not write frames to file" << endl; - - }else - cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; - //close file - if(myTree[ithr] && myFile[ithr]) - myFile[ithr] = myTree[ithr]->GetCurrentFile(); - if(myFile[ithr] != NULL) - myFile[ithr]->Close(); - myFile[ithr] = NULL; - myTree[ithr] = NULL; - pthread_mutex_unlock(&write_mutex); - -#endif - } -} - - - - - -int slsReceiverUDPFunctions::startReceiver(char message[]){ - int i; - - -// #ifdef VERBOSE - cout << "Starting Receiver" << endl; -//#endif - - - //reset listening thread variables - measurementStarted = false; - //should be set to zero as its added to get next start frame indices for scans for eiger - if(!acqStarted) currframenum = 0; - startFrameIndex = 0; - - for(int i = 0; i < numListeningThreads; ++i) - totalListeningFrameCount[i] = 0; - - //udp socket - if(createUDPSockets() == FAIL){ - strcpy(message,"Could not create UDP Socket(s).\n"); - cout << endl << message << endl; - return FAIL; - } - cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; - - - if(setupWriter() == FAIL){ - //stop udp socket - shutDownUDPSockets(); - - sprintf(message,"Could not create file %s.\n",savefilename); - return FAIL; - } - cout << "Successfully created file(s)" << endl; - - //done to give the gui some proper name instead of always the last file name - if(dataCompression) - sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); - - //initialize semaphore - sem_init(&smp,1,0); - - //status - pthread_mutex_lock(&status_mutex); - status = RUNNING; - for(i=0;istartListening(); - - return this_pointer; -} - - - -void* slsReceiverUDPFunctions::startWritingThread(void* this_pointer){ - ((slsReceiverUDPFunctions*)this_pointer)->startWriting(); - return this_pointer; -} - - - - - - -int slsReceiverUDPFunctions::startListening(){ - int ithread = currentListeningThreadIndex; -#ifdef VERYVERBOSE - cout << "In startListening() " << endl; -#endif - - thread_started = 1; - - int i,total; - int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader;// for moench to check for all the packets in last frame - char* tempchar = NULL; - int imageheader = 0; - if(myDetectorType==EIGER) - imageheader = EIGER_IMAGE_HEADER_SIZE; - - - while(1){ - //variables that need to be checked/set before each acquisition - carryonBufferSize = 0; - //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later - maxBufferSize = bufferSize * numJobsPerThread; -#ifdef VERYDEBUG - cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; -#endif - - if(tempchar) {delete [] tempchar;tempchar = NULL;} - if(myDetectorType != EIGER) - tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - - - while((1<pop(buffer[ithread]); -#ifdef VERYDEBUG - cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; -#endif - - - //receive - if(udpSocket[ithread] == NULL){ - rc = 0; - cout << ithread << "UDP Socket is NULL" << endl; - } - //normal listening - else if(!carryonBufferSize){ - - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - expected = maxBufferSize; - - } - //the remaining packets from previous buffer - else{ -#ifdef VERYDEBUG - cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; - cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) - & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); - expected = maxBufferSize - carryonBufferSize; - } - -#ifdef VERYDEBUG - cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif - - - - - //start indices for each start of scan/acquisition - eiger does it before - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); - - //problem in receiving or end of acquisition - if((rc < expected)||(rc <= 0)){ - stopListening(ithread,rc,packetcount,total); - continue; - } - - - - //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - - - - //check if last packet valid and calculate packet count - switch(myDetectorType){ - - case MOENCH: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; - cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; - cout << "last packet offset:" << lastpacketoffset << endl; - cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; - cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - //moench last packet value is 0 - if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ - lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) - & (frameIndexMask)) >> frameIndexOffset) << endl; - cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask)) << endl; -#endif - } - break; - - case GOTTHARD: - if(shortFrame == -1){ - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout << "last packet offset:" << lastpacketoffset << endl; -#endif - - if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ - memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - carryonBufferSize = onePacketSize; - --packetcount; - } - } -#ifdef VERYDEBUG - cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - break; - default: - - break; - - } - - - // cout<<"*********** "<fnum)<push(buffer[ithread])); -#ifdef VERYDEBUG - if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; -#endif - } - - sem_wait(&listensmp[ithread]); - - //make sure its not exiting thread - if(killAllListeningThreads){ - cout << ithread << " good bye listening thread" << endl; - if(tempchar) {delete [] tempchar;tempchar = NULL;} - pthread_exit(NULL); - } - } - - return OK; -} - - - - - - - - - - - - - -int slsReceiverUDPFunctions::startWriting(){ - int ithread = currentWriterThreadIndex; -#ifdef VERYVERBOSE - cout << ithread << "In startWriting()" <pop(wbuf[i]); - numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; -#endif - } - -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -#endif - - - //last dummy packet - if(numpackets == 0xFFFF){ - stopWriting(ithread,wbuf); - continue; - } - - - - - //for progress - if(myDetectorType == EIGER){ - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - pthread_mutex_lock(&progress_mutex); - if(tempframenum > currframenum) - currframenum = tempframenum; - pthread_mutex_unlock(&progress_mutex); - } -//#ifdef VERYDEBUG - if(myDetectorType == EIGER) - cout << endl < 0){ - for(i=0;ipush(wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; -#endif - } - - - } - else{ - //copy to gui - copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; -#endif - while(!fifoFree[0]->push(wbuf[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]<fnum); - //gotthard has +1 for frame number and not a short frame - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset); - else - startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) - & (frameIndexMask)) >> frameIndexOffset); - - - //start of acquisition - if(!acqStarted){ - startAcquisitionIndex=startFrameIndex; - currframenum = startAcquisitionIndex; - acqStarted = true; - cout << "startAcquisitionIndex:" << startAcquisitionIndex<push(buffer[ithread]); - exit(-1); - } - //push the last buffer into fifo - if(rc > 0){ - pc = (rc/onePacketSize); -#ifdef VERYDEBUG - cout << ithread << " *** last packetcount:" << pc << endl; -#endif - (*((uint16_t*)(buffer[ithread]))) = pc; - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; -#endif - } - - - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); - (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; -#ifdef VERYDEBUG - cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -#endif - } - - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1< 1) - cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; -#endif - while(listeningthreads_mask) - usleep(5000); -#ifdef VERYDEBUG - t = 0; - for(i=0;ipush(wbuffer[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; -#endif - } - - - - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&status_mutex); - writerthreads_mask^=(1< 0){ - - //for progress and packet loss calculation(new files) - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - //lock - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - - - //to create new file when max reached - packetsToSave = maxPacketsPerFile - packetsInFile; - if(packetsToSave > numpackets) - packetsToSave = numpackets; -/**next time offset is still plus header length*/ - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); - packetsInFile += packetsToSave; - packetsCaught += packetsToSave; - totalPacketsCaught += packetsToSave; - - - //new file - if(packetsInFile >= maxPacketsPerFile){ - //for packet loss - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - //create - createNewFile(); - } - - //unlock - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - - - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; - } - - } - else{ - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - packetsInFile += numpackets; - packetsCaught += numpackets; - totalPacketsCaught += numpackets; - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - } -} - - - - - - - - - - - - - - -void slsReceiverUDPFunctions::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ - -#if defined(MYROOT1) && defined(ALLFILE_DEBUG) - writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); -#endif - - eventType thisEvent = PEDESTAL; - int ndata; - char* buff = 0; - data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; - int remainingsize = npackets * onePacketSize; - int np; - int once = 0; - double tot, tl, tr, bl, br; - int xmin = 1, ymin = 1, ix, iy; - - - while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ - np = ndata/onePacketSize; - - //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); - - //only for moench - if(commonModeSubtractionEnable){ - for(ix = xmin - 1; ix < xmax+1; ix++){ - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); - } - } - } - - - for(ix = xmin - 1; ix < xmax+1; ix++) - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); - if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - if (thisEvent==PHOTON_MAX) { - receiverdata[ithread]->getFrameNumber(buff); - //iFrame=receiverdata[ithread]->getFrameNumber(buff); -#ifdef MYROOT1 - myTree[ithread]->Fill(); - //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; -#else - pthread_mutex_lock(&write_mutex); - if((enableFileWrite) && (sfilefd)) - singlePhotonDet[ithread]->writeCluster(sfilefd); - pthread_mutex_unlock(&write_mutex); -#endif - } - } - } - - nf++; -#ifndef ALLFILE - pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; - packetsCaught += packetsPerFrame; - totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= maxPacketsPerFile) - createNewFile(); - pthread_mutex_unlock(&progress_mutex); - -#endif - if(!once){ - copyFrameToGui(NULL,-1,buff); - once = 1; - } - } - - remainingsize -= ((buff + ndata) - data); - data = buff + ndata; - if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) - cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuffer[0]<= 0){ - - tengigaEnable = enable; - - if(myDetectorType == EIGER){ - - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; - } - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - cout<<"packetsPerFrame:"< Date: Mon, 8 Sep 2014 11:45:52 +0200 Subject: [PATCH 021/222] cleaning --- slsReceiverSoftware/slsReceiver/UDPInterface.cpp | 6 ++---- slsReceiverSoftware/slsReceiver/slsReceiver.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/UDPInterface.cpp b/slsReceiverSoftware/slsReceiver/UDPInterface.cpp index d53166f9e6..b82d497b66 100644 --- a/slsReceiverSoftware/slsReceiver/UDPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/UDPInterface.cpp @@ -6,7 +6,7 @@ - +/* #include // SIGINT #include // stat #include // socket(), bind(), listen(), accept(), shut down @@ -14,6 +14,7 @@ #include // exit() #include //set precision #include //munmap +*/ #include #include @@ -22,9 +23,6 @@ using namespace std; #include "UDPInterface.h" #include "UDPBaseImplementation.h" -#include "moench02ModuleData.h" -#include "gotthardModuleData.h" -#include "gotthardShortModuleData.h" using namespace std; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.h b/slsReceiverSoftware/slsReceiver/slsReceiver.h index 899dabe8d2..0cd195c722 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.h @@ -10,7 +10,6 @@ #include "UDPInterface.h" #include "UDPBaseImplementation.h" -#include "sls_receiver_defs.h" #include "receiver_defs.h" #include "MySocketTCP.h" From 56411017051d85b5bcbc807227edf073dd4af978 Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Mon, 8 Sep 2014 16:01:18 +0200 Subject: [PATCH 022/222] added logger --- slsReceiverSoftware/Makefile | 24 ++-- slsReceiverSoftware/slsReceiver/Makefile | 26 ++-- .../slsReceiver/UDPBaseImplementation.cpp | 113 +++--------------- .../slsReceiver/UDPBaseImplementation.h | 1 - .../slsReceiver/UDPInterface.cpp | 5 +- .../slsReceiver/UDPInterface.h | 3 + slsReceiverSoftware/slsReceiver/main.cpp | 3 + .../slsReceiver/slsReceiver.cpp | 35 ++++-- slsReceiverSoftware/slsReceiver/slsReceiver.h | 4 +- 9 files changed, 76 insertions(+), 138 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 8f6e00910c..2b159dad32 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -11,16 +11,16 @@ CFLAGS= -g -DC_ONLY -fPIC DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS -INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -IslsReceiver/eigerReceiver -I$(ASM) +INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -I$(ASM) #-IslsReceiverInterface -SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/slsReceiver.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiverUsers.cpp - +SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/UDPStandardImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUsers.cpp includes/utilities.h #slsReceiverInterface/receiverInterface.cpp #slsReceiver/slsReceiverUDPFunctions.cpp OBJS = $(SRC_CLNT:.cpp=.o) -OBJS += slsReceiver/eigerReceiver.o +OBJS += includes/utilities.h +#OBJS += slsReceiver/eigerReceiver.o .PHONY: all intdoc package eigerReceiver clean @@ -31,10 +31,8 @@ intdoc: $(SRC_H) $(SRC_CLNT) doxygen doxy.config -%.o : %.cpp %.h Makefile -ifeq ($(EIGERSLS),yes) - $(CXX) -DEIGERSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(EIGERFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) -else ifeq ($(ROOTSLS),yes) +%.o : %.cpp Makefile +ifeq ($(ROOTSLS),yes) echo "with root" $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) else @@ -43,14 +41,14 @@ else endif # LEO: not satisfied by eigerReceiver -package: eigerReceiver $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a +package: $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a -eigerReceiver: - echo "src client:" $(SRC_CLNT) - cd slsReceiver && make eigerReceiver +#eigerReceiver: +# echo "src client:" $(SRC_CLNT) +# cd slsReceiver && make eigerReceiver $(DESTDIR)/libSlsReceiver.so: $(OBJS) - $(CXX) -shared -Wl,-soname,libSlsReceiver.so -o libSlsReceiver.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread + $(CXX) -shared -Wl,-soname,libSlsReceiver.so -o libSlsReceiver.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) mv libSlsReceiver.so $(DESTDIR) diff --git a/slsReceiverSoftware/slsReceiver/Makefile b/slsReceiverSoftware/slsReceiver/Makefile index b4a681c3f2..0592e962e5 100644 --- a/slsReceiverSoftware/slsReceiver/Makefile +++ b/slsReceiverSoftware/slsReceiver/Makefile @@ -39,26 +39,26 @@ $(DESTDIR)/sslsReceiver: lib $(CXX) -static -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -$(DESTDIR)/slsReceiver: eigerReceiver lib +$(DESTDIR)/slsReceiver: lib echo "AAAAAAAAAAAA" $(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC $(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC #$(EIGERFLAGS) -ifeq ($(EIGERSLS), yes) -eigerReceiver: -# $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiverTest.o eigerReceiver/eigerReceiverTest.cpp $(EIGERFLAGS) +#ifeq ($(EIGERSLS), yes) +#eigerReceiver: +# $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiverTest.o eigerReceiver/eigerReceiverTest.cpp #$(EIGERFLAGS) # $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiver.cpp $(EIGERFLAGS) # $(CXX) eigerReceiverTest.o eigerReceiver.o -o eigerReceiver/eigerReceiverTest $(EIGERFLAGS) - $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiverImplementation.cpp $(EIGERFLAGS) -else ifeq ($(ROOTSLS), yes) -eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp - echo "Compiling with root" - $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp $(ROOTFLAGS) -else -eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp - $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp -endif +# $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiverImplementation.cpp $(EIGERFLAGS) +#else ifeq ($(ROOTSLS), yes) +#eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp +# echo "Compiling with root" +# $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp $(ROOTFLAGS) +#else +#eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp +# $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp +#endif lib: cd ../ && $(MAKE) DESTDIR=../bin LIBDIR=../bin diff --git a/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp b/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp index aa0aa77e1c..2cb7773cca 100644 --- a/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp @@ -20,12 +20,10 @@ #include //set precision #include //munmap - - #include #include - +//#include "utilities.h" using namespace std; @@ -216,90 +214,9 @@ void UDPBaseImplementation::initializeMembers(){ } -int UDPBaseImplementation::setDetectorType(detectorType det){ - cout << "Setting Receiver Type " << endl; - - deleteMembers(); - initializeMembers(); - - myDetectorType = det; - - switch(myDetectorType){ - case GOTTHARD: - cout << endl << "***** This is a GOTTHARD Receiver *****" << endl << endl; - break; - case MOENCH: - cout << endl << "***** This is a MOENCH Receiver *****" << endl << endl; - break; - case EIGER: - cout << endl << "***** This is a EIGER Receiver *****" << endl << endl; - break; - default: - cout << endl << "***** Unknown Receiver *****" << endl << endl; - return FAIL; - break; - } - - //moench variables - if(myDetectorType == GOTTHARD){ - fifosize = GOTTHARD_FIFO_SIZE; - packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; - onePacketSize = GOTTHARD_ONE_PACKET_SIZE; - frameSize = GOTTHARD_BUFFER_SIZE; - bufferSize = GOTTHARD_BUFFER_SIZE; - maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; - frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; - packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; - }else if(myDetectorType == MOENCH){ - fifosize = MOENCH_FIFO_SIZE; - packetsPerFrame = MOENCH_PACKETS_PER_FRAME; - onePacketSize = MOENCH_ONE_PACKET_SIZE; - frameSize = MOENCH_BUFFER_SIZE; - bufferSize = MOENCH_BUFFER_SIZE; - maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; - frameIndexMask = MOENCH_FRAME_INDEX_MASK; - frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; - packetIndexMask = MOENCH_PACKET_INDEX_MASK; - } - else if(myDetectorType == EIGER){ - fifosize = EIGER_FIFO_SIZE; - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - frameIndexMask = EIGER_FRAME_INDEX_MASK; - frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; - packetIndexMask = EIGER_PACKET_INDEX_MASK; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - if(thread_started) - createListeningThreads(true); - - numListeningThreads = MAX_NUM_LISTENING_THREADS; - } - latestData = new char[frameSize]; - - - setupFifoStructure(); - - if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; - exit (-1); - } - - if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; - exit (-1); - } - - setThreadPriorities(); - - cout << "Ready..." << endl; +int UDPBaseImplementation::setDetectorType(detectorType det){ + cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; return OK; } @@ -327,6 +244,7 @@ uint32_t UDPBaseImplementation::getFrameIndex(){ return frameIndex; } + uint32_t UDPBaseImplementation::getAcquisitionIndex(){ if(!totalPacketsCaught) acquisitionIndex=-1; @@ -343,20 +261,17 @@ void UDPBaseImplementation::resetTotalFramesCaught(){ } - - - - - - - /*file parameters*/ char* UDPBaseImplementation::getFilePath() const{ - return (char*)filePath; + FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects.x" << endl; + return (char*)filePath; } char* UDPBaseImplementation::setFilePath(const char c[]){ + cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; + + /* if(strlen(c)){ //check if filepath exists struct stat st; @@ -367,6 +282,7 @@ char* UDPBaseImplementation::setFilePath(const char c[]){ cout << "FilePath does not exist:" << filePath << endl; } } + */ return getFilePath(); } @@ -376,8 +292,11 @@ char* UDPBaseImplementation::getFileName() const{ } char* UDPBaseImplementation::setFileName(const char c[]){ - if(strlen(c)) + cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; + /* + if(strlen(c)) strcpy(fileName,c); + */ return getFileName(); } @@ -387,13 +306,17 @@ int UDPBaseImplementation::getFileIndex(){ } int UDPBaseImplementation::setFileIndex(int i){ + cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; + /* if(i>=0) fileIndex = i; + */ return getFileIndex(); } int UDPBaseImplementation::setFrameIndexNeeded(int i){ + cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; frameIndexNeeded = i; return frameIndexNeeded; } diff --git a/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.h b/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.h index 8a1f841782..7b9068a63d 100644 --- a/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.h +++ b/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.h @@ -28,7 +28,6 @@ #include #include - /** * @short does all the functions for a receiver, set/get parameters, start/stop etc. */ diff --git a/slsReceiverSoftware/slsReceiver/UDPInterface.cpp b/slsReceiverSoftware/slsReceiver/UDPInterface.cpp index b82d497b66..4a14933ae3 100644 --- a/slsReceiverSoftware/slsReceiver/UDPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/UDPInterface.cpp @@ -22,6 +22,7 @@ using namespace std; #include "UDPInterface.h" #include "UDPBaseImplementation.h" +#include "UDPStandardImplementation.h" @@ -30,7 +31,9 @@ using namespace std; UDPInterface * UDPInterface::create(string receiver_type){ if (receiver_type == "standard") - return new UDPBaseImplementation(); + return new UDPStandardImplementation(); + //else if (receiver_type == "REST") + // return new UDPRESTImplementation(); else{ cout << "[ERROR] UDP interface not supported, using standard implementation" << endl; return new UDPBaseImplementation(); diff --git a/slsReceiverSoftware/slsReceiver/UDPInterface.h b/slsReceiverSoftware/slsReceiver/UDPInterface.h index 74f471ae09..77cfe3e7e8 100644 --- a/slsReceiverSoftware/slsReceiver/UDPInterface.h +++ b/slsReceiverSoftware/slsReceiver/UDPInterface.h @@ -16,6 +16,9 @@ #include "receiver_defs.h" #include "MySocketTCP.h" +#include "utilities.h" + + /* void print_not_implemented(string method_name){ std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; diff --git a/slsReceiverSoftware/slsReceiver/main.cpp b/slsReceiverSoftware/slsReceiver/main.cpp index 87d947a7db..14fb01d0e4 100644 --- a/slsReceiverSoftware/slsReceiver/main.cpp +++ b/slsReceiverSoftware/slsReceiver/main.cpp @@ -6,6 +6,9 @@ #include #include + +#include "utilities.h" + using namespace std; diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp index fd1223b71d..5dbeaea322 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp @@ -12,9 +12,7 @@ #include #include "slsReceiver.h" -#include "UDPInterface.h" - -#include "utilities.h" +//#include "UDPInterface.h" using namespace std; @@ -35,6 +33,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ int tcpip_port_no = 1984; success=OK; string fname = ""; + string udp_interface_type = "standard"; //parse command line for config static struct option long_options[] = { @@ -42,6 +41,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ //{"verbose", no_argument, &verbose_flag, 1}, /* These options don’t set a flag. We distinguish them by their indices. */ + {"type", required_argument, 0, 't'}, {"config", required_argument, 0, 'f'}, {"rx_tcpport", required_argument, 0, 'b'}, {"help", no_argument, 0, 'h'}, @@ -52,7 +52,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ int c; while ( c != -1 ){ - c = getopt_long (argc, argv, "bfh", long_options, &option_index); + c = getopt_long (argc, argv, "bfht", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) @@ -61,12 +61,15 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ switch(c){ case 'f': fname = optarg; - cout << long_options[option_index].name << " " << optarg << endl; + //cout << long_options[option_index].name << " " << optarg << endl; break; case 'b': - sscanf(optarg,"%d",&tcpip_port_no); - cout << long_options[option_index].name << " " << optarg << endl; + sscanf(optarg, "%d", &tcpip_port_no); + break; + + case 't': + udp_interface_type = optarg; break; case 'h': @@ -74,6 +77,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ help_message += """usage: slsReceiver --config config_fname [--rx_tcpport port]\n\n"""; help_message += """\t--config:\t configuration filename for SLS Detector receiver\n"""; help_message += """\t--rx_tcpport:\t TCP Communication Port with the client. Default: 1954.\n\n"""; + help_message += """\t--type:\t Type of the receiver. Possible arguments are: standard, REST. Default: standard.\n\n"""; cout << help_message << endl; break; @@ -85,30 +89,35 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ success = FAIL; if((!fname.empty()) && (success == OK)){ - VERBOSE_PRINT("config file name " + fname ); + FILE_LOG(logINFO) << "config file name " << fname; success = read_config_file(fname, &tcpip_port_no); - VERBOSE_PRINT("Read configuration file of " + iline + " lines"); + //VERBOSE_PRINT("Read configuration file of " + iline + " lines"); } else { - cout << "Error opening configuration file " << fname << endl; + FILE_LOG(logERROR) << "Error opening configuration file " << fname ; success = FAIL; } if(success != OK){ - cout << "Failed: see output above for more information " << endl; + FILE_LOG(logERROR) << "Failed: see output above for more information " ; } if (success==OK){ cout << "SLS Receiver starting" << endl; - udp_interface = UDPInterface::create("standard"); + udp_interface = UDPInterface::create(udp_interface_type); tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no); //tcp ip interface } } -slsReceiver::~slsReceiver() {if(udp_interface) delete udp_interface; if(tcpipInterface) delete tcpipInterface;} +slsReceiver::~slsReceiver() { + if(udp_interface) + delete udp_interface; + if(tcpipInterface) + delete tcpipInterface; +} int slsReceiver::start() { diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.h b/slsReceiverSoftware/slsReceiver/slsReceiver.h index 0cd195c722..4eb0247764 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.h @@ -8,11 +8,11 @@ #include "slsReceiverTCPIPInterface.h" #include "UDPInterface.h" -#include "UDPBaseImplementation.h" +//#include "UDPBaseImplementation.h" #include "receiver_defs.h" #include "MySocketTCP.h" - +//#include "utilities.h" /** From 59980a4b9033149adc318c0d470feb596b8959af Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Tue, 9 Sep 2014 15:46:58 +0200 Subject: [PATCH 023/222] beginning of reimplementation of the REST interface --- slsReceiverSoftware/Makefile | 4 +- .../slsReceiver/UDPBaseImplementation.cpp | 195 +----------------- .../slsReceiver/UDPInterface.cpp | 6 +- .../slsReceiver/slsReceiver.cpp | 2 +- 4 files changed, 18 insertions(+), 189 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 2b159dad32..07de136724 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -14,7 +14,7 @@ DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -I$(ASM) #-IslsReceiverInterface -SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/UDPStandardImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUsers.cpp includes/utilities.h +SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/UDPStandardImplementation.cpp slsReceiver/UDPRESTImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUsers.cpp includes/utilities.h #slsReceiverInterface/receiverInterface.cpp #slsReceiver/slsReceiverUDPFunctions.cpp @@ -35,7 +35,7 @@ intdoc: $(SRC_H) $(SRC_CLNT) ifeq ($(ROOTSLS),yes) echo "with root" $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) -else +else echo "without root" $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) endif diff --git a/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp b/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp index 2cb7773cca..14207ce658 100644 --- a/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/slsReceiver/UDPBaseImplementation.cpp @@ -29,189 +29,19 @@ using namespace std; -UDPBaseImplementation::UDPBaseImplementation(): - thread_started(0), - eth(NULL), - latestData(NULL), - guiFileName(NULL), - guiFrameNumber(0), - tengigaEnable(0){ - - for(int i=0;i /proc/sys/net/core/rmem_max")) - cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; - else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) - cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; - /** permanent setting heiner - net.core.rmem_max = 104857600 # 100MiB - net.core.netdev_max_backlog = 250000 - sysctl -p - // from the manual - sysctl -w net.core.rmem_max=16777216 - sysctl -w net.core.netdev_max_backlog=250000 - */ -} - - - -UDPBaseImplementation::~UDPBaseImplementation(){ - createListeningThreads(true); - createWriterThreads(true); - deleteMembers(); -} +UDPBaseImplementation::UDPBaseImplementation(){} +UDPBaseImplementation::~UDPBaseImplementation(){} void UDPBaseImplementation::deleteMembers(){ - //kill threads - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - - for(int i=0;i Date: Tue, 9 Sep 2014 16:37:35 +0200 Subject: [PATCH 024/222] added logger --- slsReceiverSoftware/includes/logger.h | 172 +++++++++++++++++++++++ slsReceiverSoftware/includes/utilities.h | 29 ++++ 2 files changed, 201 insertions(+) create mode 100644 slsReceiverSoftware/includes/logger.h create mode 100644 slsReceiverSoftware/includes/utilities.h diff --git a/slsReceiverSoftware/includes/logger.h b/slsReceiverSoftware/includes/logger.h new file mode 100644 index 0000000000..a230a52662 --- /dev/null +++ b/slsReceiverSoftware/includes/logger.h @@ -0,0 +1,172 @@ +#ifndef __LOG_H__ +#define __LOG_H__ + +#include +#include +#include + +inline std::string NowTime(); + +enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4}; + +template +class Log +{ +public: + Log(); + virtual ~Log(); + std::ostringstream& Get(TLogLevel level = logINFO); +public: + static TLogLevel& ReportingLevel(); + static std::string ToString(TLogLevel level); + static TLogLevel FromString(const std::string& level); +protected: + std::ostringstream os; +private: + Log(const Log&); + Log& operator =(const Log&); +}; + +template +Log::Log() +{ +} + +template +std::ostringstream& Log::Get(TLogLevel level) +{ + os << "- " << NowTime(); + os << " " << ToString(level) << ": "; + os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t'); + return os; +} + +template +Log::~Log() +{ + os << std::endl; + T::Output(os.str()); +} + +template +TLogLevel& Log::ReportingLevel() +{ + static TLogLevel reportingLevel = logDEBUG4; + return reportingLevel; +} + +template +std::string Log::ToString(TLogLevel level) +{ + static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"}; + return buffer[level]; +} + +template +TLogLevel Log::FromString(const std::string& level) +{ + if (level == "DEBUG4") + return logDEBUG4; + if (level == "DEBUG3") + return logDEBUG3; + if (level == "DEBUG2") + return logDEBUG2; + if (level == "DEBUG1") + return logDEBUG1; + if (level == "DEBUG") + return logDEBUG; + if (level == "INFO") + return logINFO; + if (level == "WARNING") + return logWARNING; + if (level == "ERROR") + return logERROR; + Log().Get(logWARNING) << "Unknown logging level '" << level << "'. Using INFO level as default."; + return logINFO; +} + +class Output2FILE +{ +public: + static FILE*& Stream(); + static void Output(const std::string& msg); +}; + +inline FILE*& Output2FILE::Stream() +{ + static FILE* pStream = stderr; + return pStream; +} + +inline void Output2FILE::Output(const std::string& msg) +{ + FILE* pStream = Stream(); + if (!pStream) + return; + fprintf(pStream, "%s", msg.c_str()); + fflush(pStream); +} + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) +# if defined (BUILDING_FILELOG_DLL) +# define FILELOG_DECLSPEC __declspec (dllexport) +# elif defined (USING_FILELOG_DLL) +# define FILELOG_DECLSPEC __declspec (dllimport) +# else +# define FILELOG_DECLSPEC +# endif // BUILDING_DBSIMPLE_DLL +#else +# define FILELOG_DECLSPEC +#endif // _WIN32 + +class FILELOG_DECLSPEC FILELog : public Log {}; +//typedef Log FILELog; + +#ifndef FILELOG_MAX_LEVEL +#define FILELOG_MAX_LEVEL logDEBUG4 +#endif + +#define FILE_LOG(level) \ + if (level > FILELOG_MAX_LEVEL) ; \ + else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ + else FILELog().Get(level) + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) + +#include + +inline std::string NowTime() +{ + const int MAX_LEN = 200; + char buffer[MAX_LEN]; + if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, + "HH':'mm':'ss", buffer, MAX_LEN) == 0) + return "Error in NowTime()"; + + char result[100] = {0}; + static DWORD first = GetTickCount(); + sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000); + return result; +} + +#else + +#include + +inline std::string NowTime() +{ + char buffer[11]; + time_t t; + time(&t); + tm r = {0}; + strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r)); + struct timeval tv; + gettimeofday(&tv, 0); + char result[100] = {0}; + sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000); + return result; +} + +#endif //WIN32 + +#endif //__LOG_H__ diff --git a/slsReceiverSoftware/includes/utilities.h b/slsReceiverSoftware/includes/utilities.h new file mode 100644 index 0000000000..e55d81598f --- /dev/null +++ b/slsReceiverSoftware/includes/utilities.h @@ -0,0 +1,29 @@ +#include +#include +#include +#include +using namespace std; + +/* uncomment next line to enable debug output */ +//#define EIGER_DEBUG + +/* macro for debug output http://stackoverflow.com/a/14256296 */ +#ifdef EIGER_DEBUG +#define DEBUG(x) do { std::cerr << x << std::endl; } while (0) +#else +#define DEBUG(x) +#endif + +#ifdef VERBOSE +#define VERBOSE_PRINT(x) do { std::cout << "[VERBOSE]" << x << std::endl; } while (0) +#else +#define VERBOSE_PRINT(x) +#endif + + + + + + +inline int read_config_file(string fname, int *tcpip_port_no); + From c62594c7abb4892efffe30f13835ea0c00fc473e Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Tue, 9 Sep 2014 16:38:27 +0200 Subject: [PATCH 025/222] added REST and Standard implementations --- slsReceiverSoftware/slsReceiver/RestHelper.h | 295 +++ .../slsReceiver/UDPRESTImplementation.cpp | 2009 ++++++++++++++ .../slsReceiver/UDPRESTImplementation.h | 819 ++++++ .../slsReceiver/UDPStandardImplementation.cpp | 2330 +++++++++++++++++ .../slsReceiver/UDPStandardImplementation.h | 810 ++++++ 5 files changed, 6263 insertions(+) create mode 100644 slsReceiverSoftware/slsReceiver/RestHelper.h create mode 100644 slsReceiverSoftware/slsReceiver/UDPRESTImplementation.cpp create mode 100644 slsReceiverSoftware/slsReceiver/UDPRESTImplementation.h create mode 100644 slsReceiverSoftware/slsReceiver/UDPStandardImplementation.cpp create mode 100644 slsReceiverSoftware/slsReceiver/UDPStandardImplementation.h diff --git a/slsReceiverSoftware/slsReceiver/RestHelper.h b/slsReceiverSoftware/slsReceiver/RestHelper.h new file mode 100644 index 0000000000..fc4056c43d --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/RestHelper.h @@ -0,0 +1,295 @@ +/** + * @file RestHelper.h + * @author Leonardo Sala + * @date Tue Mar 25 09:28:19 2014 + * + * @brief + * + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "JsonBox/Value.h" + +#include +#include +#include +#include + +#define EIGER_DEBUG +#ifdef EIGER_DEBUG +#define DEBUG(x) do { std::cerr << "[DEBUG] " << x << std::endl; } while (0) +#else +#define DEBUG(x) +#endif + + +using namespace Poco::Net; +using namespace Poco; +using namespace std; + +class RestHelper { + public: + + RestHelper(int timeout=10, int n_tries=3){ + /** + * + * + * @param timeout default=10 + * @param n_tries default=3 + */ + + http_timeout = timeout; + n_connection_tries = n_tries; + } + + ~RestHelper(){}; + + + void set_connection_params(int timeout, int n_tries){ + http_timeout = timeout; + n_connection_tries = n_tries; + } + + + void get_connection_params(int *timeout, int *n_tries){ + *timeout = http_timeout; + *n_tries = n_connection_tries; + + } + + + void init(string hostname, int port){ + /** Initialize the RestHelper. Hostname and port parameters are not supposed to change. + * + * + * @param hostname FQDN of the host to connect to , e.g. www.iamfake.org, or sodoi.org + * @param port + * + * @return + */ + + //Check for http:// string + string proto_str = "http://"; + if( size_t found = hostname.find(proto_str) != string::npos ){ + char c1[hostname.size()-found-1]; + size_t length1 = hostname.copy(c1, hostname.size()-found-1, proto_str.size()); + c1[length1]='\0'; + hostname = c1; + } + + full_hostname = "http://"+hostname; + session = new HTTPClientSession(hostname,port ); + session->setKeepAliveTimeout( Timespan( http_timeout,0) ); + + }; + + + void init(string hostname_port){ + /** Initialize the RestHelper. Hostname_port parameters are not supposed to change. + * + * + * @param hostname FQDN and port of the host to connect to , e.g. www.iamfake.org:8080, or sodoi.org:1111. Default port is 8080 + * + * @return + */ + + //Check for http:// string + string proto_str = "http://"; + if( size_t found = hostname_port.find(proto_str) != string::npos ){ + char c1[hostname_port.size()-found-1]; + size_t length1 = hostname_port.copy(c1, hostname_port.size()-found-1, proto_str.size()); + c1[length1]='\0'; + hostname_port = c1; + } + + size_t found = hostname_port.rfind(":"); + char c1[ found ], c2[hostname_port.size()-found-1]; + string hostname; + size_t length1 = hostname_port.copy(c1, found); + + c1[length1]='\0'; + hostname = c1; + size_t length2 = hostname_port.copy(c2, found-1, found+1); + c2[length2]='\0'; + int port = atoi(c2); + + full_hostname = proto_str+hostname; + session = new HTTPClientSession(hostname,port ); + session->setKeepAliveTimeout( Timespan( http_timeout,0) ); + }; + + + int get_json(string request, string* answer){ + /** Retrieves a reply from the RESTful webservice. + * + * + * @param request Request without the hostname, e.g. if the full request would have been http://fake.org/fakemethod, request=fakemethod + * @param answer + * + * @return 0 if successful, -1 if failure happens. + */ + URI * uri = new URI(full_hostname+"/"+request); + string path(uri->getPathAndQuery()); + if (path.empty()) path = "/"; + + // send request + HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1); + req.setContentType("application/json\r\n"); + int code = send_request(session, req, answer); + delete uri; + return code; + }; + + + int get_json(string request, JsonBox::Value* json_value){ + /** + * + * + * @param request + * @param json_value + * + * @return + */ + URI *uri = new URI(full_hostname+"/"+request); + string path(uri->getPathAndQuery()); + if (path.empty()) path = "/"; + // send request + HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1); + req.setContentType("application/json\r\n"); + string answer; + int code = send_request(session, req, &answer); + if(code == 0 ) { + DEBUG("ANSWER " << answer ); + json_value->loadFromString(answer); + } + delete uri; + return code; + }; + + + int post_json(string request, string *answer, string request_body=""){ + /** + * + * + * @param request + * @param answer + * @param request_body Eventual arguments to the URL, e.g. action=login&name=mammamia + * + * @return + */ + //from: http://stackoverflow.com/questions/1499086/poco-c-net-ssl-how-to-post-https-request + URI *uri = new URI(full_hostname+"/"+request); + string path(uri->getPathAndQuery()); + if (path.empty()) path = "/"; + HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); + req.setContentType("application/json\r\n"); + req.setContentLength( request.length() ); + + int code = send_request(session, req, answer, request_body); + delete uri; + return code; + } + + + int post_json(string request, JsonBox::Value* json_value, string request_body=""){ + /** + * + * + * @param request + * @param json_value + * @param request_body Eventual arguments to the URL, e.g. action=login&name=mammamia + * + * @return + */ + + URI *uri = new URI(full_hostname+"/"+request); + string path(uri->getPathAndQuery()); + if (path.empty()) path = "/"; + HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); + //this does not work + //req.setContentType("application/json\r\n"); + //req.setContentLength( request.length() ); + string answer; + int code = send_request(session, req, &answer, request_body); + if(code==0){ + json_value->loadFromString(answer); + } + delete uri; + return code; + } + + + private: + + HTTPClientSession *session; + string full_hostname; + /// HTTP timeout in seconds, default is 8 + int http_timeout; + /// Number of connection tries + int n_connection_tries; + + + int send_request(HTTPClientSession *session, HTTPRequest &req, string *answer, string request_body=""){ + /** + * + * + * @param session + * @param req + * @param answer + * @param request_body + * + * @return + */ + + int n=0; + int code = -1; + while(nsendRequest( (req) ); + else{ + cout << request_body << endl; + ostream &os = session->sendRequest( req ) ; + os << request_body; + } + + HTTPResponse res; + istream &is = session->receiveResponse(res); + StreamCopier::copyToString(is, *answer); + code = res.getStatus(); + if (code != 200){ + cout << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() << endl; + code = -1; + } + else + code = 0; + return code; + } + catch (exception& e){ + cout << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"< // SIGINT +#include // stat +#include // socket(), bind(), listen(), accept(), shut down +#include // sock_addr_in, htonl, INADDR_ANY +#include // exit() +#include //set precision +#include //munmap + +#include +#include + +//#include "utilities.h" + +using namespace std; + + + +UDPRESTImplementation::UDPRESTImplementation() : isInitialized(false), status(slsReceiverDefs::ERROR) {} + + +UDPRESTImplementation::~UDPRESTImplementation(){} + + +void UDPRESTImplementation::initialize(const char *detectorHostName){ + + string name; + if (detectorHostName != NULL) + name = detectorHostName; + + if (name.empty()) { + FILE_LOG(logDEBUG) << "initialize(): can't initialize with empty string or NULL for detectorHostname"; + } else if (isInitialized == true) { + FILE_LOG(logDEBUG) << "initialize(): already initialized, can't initialize several times"; + } else { + FILE_LOG(logDEBUG) << "initialize(): initialize() with: detectorHostName=" << name; + strcpy(detHostname,detectorHostName); + //init_config.detectorHostname = name; + + //REST call - hardcoded + //RestHelper rest ; + rest->init(detHostname, 8080); + std::string answer; + int code = rest->get_json("status", &answer); + if (code != 0){ + //throw -1; + std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; + } + else{ + isInitialized = true; + status = slsReceiverDefs::IDLE; + } + std::cout << "Answer: " << answer << std::endl; + + + /* + std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl; + JsonBox::Value json_value; + code = rest.get_json("status", &json_value); + std::cout << "JSON " << json_value["status"] << std::endl; + */ + } +} + + +int UDPRESTImplementation::setDetectorType(detectorType det){ + cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; + return OK; +} + + + +/*Frame indices and numbers caught*/ + +bool UDPRESTImplementation::getAcquistionStarted(){return acqStarted;}; + +bool UDPRESTImplementation::getMeasurementStarted(){return measurementStarted;}; + +int UDPRESTImplementation::getFramesCaught(){return (packetsCaught/packetsPerFrame);} + +int UDPRESTImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);} + +uint32_t UDPRESTImplementation::getStartFrameIndex(){return startFrameIndex;} + +uint32_t UDPRESTImplementation::getFrameIndex(){ + if(!packetsCaught) + frameIndex=-1; + else + frameIndex = currframenum - startFrameIndex; + return frameIndex; +} + + +uint32_t UDPRESTImplementation::getAcquisitionIndex(){ + if(!totalPacketsCaught) + acquisitionIndex=-1; + else + acquisitionIndex = currframenum - startAcquisitionIndex; + return acquisitionIndex; +} + + +void UDPRESTImplementation::resetTotalFramesCaught(){ + acqStarted = false; + startAcquisitionIndex = 0; + totalPacketsCaught = 0; +} + + +/*file parameters*/ +int UDPRESTImplementation::getFileIndex(){ + return fileIndex; +} + +int UDPRESTImplementation::setFileIndex(int i){ + cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; + /* + if(i>=0) + fileIndex = i; + */ + return getFileIndex(); +} + + +int UDPRESTImplementation::setFrameIndexNeeded(int i){ + cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; + frameIndexNeeded = i; + return frameIndexNeeded; +} + + +/* +int UDPRESTImplementation::getEnableFileWrite() const{ + return enableFileWrite; +} + +int UDPRESTImplementation::setEnableFileWrite(int i){ + enableFileWrite=i; + return getEnableFileWrite(); +} + +int UDPRESTImplementation::getEnableOverwrite() const{ + return overwrite; +} + +int UDPRESTImplementation::setEnableOverwrite(int i){ + overwrite=i; + return getEnableOverwrite(); +} +*/ + + + + +/*other parameters*/ + +slsReceiverDefs::runStatus UDPRESTImplementation::getStatus() const{ + return status; +} + + + +/* +char *UDPRESTImplementation::getDetectorHostname() const{ + return (char*)detHostname; +} +*/ + +void UDPRESTImplementation::setEthernetInterface(char* c){ + strcpy(eth,c); +} + + +void UDPRESTImplementation::setUDPPortNo(int p){ + for(int i=0;i= 0) + numberOfFrames = fnum; + + return getNumberOfFrames(); +} +*/ +/* +int UDPRESTImplementation::getScanTag() const{ + return scanTag; +} +*/ + +/* +int32_t UDPRESTImplementation::setScanTag(int32_t stag){ + if(stag >= 0) + scanTag = stag; + + return getScanTag(); +} +*/ + +int32_t UDPRESTImplementation::setDynamicRange(int32_t dr){ + cout << "Setting Dynamic Range" << endl; + + int olddr = dynamicRange; + if(dr >= 0){ + dynamicRange = dr; + } + + return getDynamicRange(); +} + + + +int UDPRESTImplementation::setShortFrame(int i){ + shortFrame=i; + + if(shortFrame!=-1){ + bufferSize = GOTTHARD_SHORT_ONE_PACKET_SIZE; + frameSize = GOTTHARD_SHORT_BUFFER_SIZE; + maxPacketsPerFile = SHORT_MAX_FRAMES_PER_FILE * GOTTHARD_SHORT_PACKETS_PER_FRAME; + packetsPerFrame = GOTTHARD_SHORT_PACKETS_PER_FRAME; + frameIndexMask = GOTTHARD_SHORT_FRAME_INDEX_MASK; + frameIndexOffset = GOTTHARD_SHORT_FRAME_INDEX_OFFSET; + + }else{ + onePacketSize = GOTTHARD_ONE_PACKET_SIZE; + bufferSize = GOTTHARD_BUFFER_SIZE; + frameSize = GOTTHARD_BUFFER_SIZE; + maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; + packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; + frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; + frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; + } + + + deleteFilter(); + if(dataCompression) + setupFilter(); + + return shortFrame; +} + + +int UDPRESTImplementation::setNFrameToGui(int i){ + if(i>=0){ + nFrameToGui = i; + setupFifoStructure(); + } + return nFrameToGui; +} + + + +int64_t UDPRESTImplementation::setAcquisitionPeriod(int64_t index){ + + if(index >= 0){ + if(index != acquisitionPeriod){ + acquisitionPeriod = index; + setupFifoStructure(); + } + } + return acquisitionPeriod; +} + + +bool UDPRESTImplementation::getDataCompression(){return dataCompression;} + +int UDPRESTImplementation::enableDataCompression(bool enable){ + cout << "Data compression "; + if(enable) + cout << "enabled" << endl; + else + cout << "disabled" << endl; +#ifdef MYROOT1 + cout << " WITH ROOT" << endl; +#else + cout << " WITHOUT ROOT" << endl; +#endif + //delete filter for the current number of threads + deleteFilter(); + + dataCompression = enable; + pthread_mutex_lock(&status_mutex); + writerthreads_mask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + createWriterThreads(true); + + if(enable) + numWriterThreads = MAX_NUM_WRITER_THREADS; + else + numWriterThreads = 1; + + if(createWriterThreads() == FAIL){ + cout << "ERROR: Could not create writer threads" << endl; + return FAIL; + } + setThreadPriorities(); + + + if(enable) + setupFilter(); + + return OK; +} + + + + + + + + + + + + +/*other functions*/ + + +void UDPRESTImplementation::deleteFilter(){ + int i; + cmSub=NULL; + + for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); + +} + + + +//LEO: it is not clear to me.. +void UDPRESTImplementation::setupFifoStructure(){ + + int64_t i; + int oldn = numJobsPerThread; + + //if every nth frame mode + if(nFrameToGui) + numJobsPerThread = nFrameToGui; + + //random nth frame mode + else{ + if(!acquisitionPeriod) + i = SAMPLE_TIME_IN_NS; + else + i = SAMPLE_TIME_IN_NS/acquisitionPeriod; + if (i > MAX_JOBS_PER_THREAD) + numJobsPerThread = MAX_JOBS_PER_THREAD; + else if (i < 1) + numJobsPerThread = 1; + else + numJobsPerThread = i; + } + + //if same, return + if(oldn == numJobsPerThread) + return; + + if(myDetectorType == EIGER) + numJobsPerThread = 1; + + //otherwise memory too much if numjobsperthread is at max = 1000 + fifosize = GOTTHARD_FIFO_SIZE; + if(myDetectorType == MOENCH) + fifosize = MOENCH_FIFO_SIZE; + else if(myDetectorType == EIGER) + fifosize = EIGER_FIFO_SIZE; + + if(fifosize % numJobsPerThread) + fifosize = (fifosize/numJobsPerThread)+1; + else + fifosize = fifosize/numJobsPerThread; + + + cout << "Number of Frames per buffer:" << numJobsPerThread << endl; + cout << "Fifo Size:" << fifosize << endl; + + /* + //for testing + numJobsPerThread = 3; fifosize = 11; + */ + + for(int i=0;iisEmpty()) + fifoFree[i]->pop(buffer[i]); + delete fifoFree[i]; + } + if(fifo[i]) delete fifo[i]; + if(mem0[i]) free(mem0[i]); + fifoFree[i] = new CircularFifo(fifosize); + fifo[i] = new CircularFifo(fifosize); + + + //allocate memory + mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + /** shud let the client know about this */ + if (mem0[i]==NULL){ + cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + exit(-1); + } + buffer[i]=mem0[i]; + //push the addresses into freed fifoFree and writingFifoFree + while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); + buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + } + } + cout << "Fifo structure(s) reconstructed" << endl; +} + + + + + + + +/** acquisition functions */ + +void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ + //point to gui data + if (guiData == NULL) + guiData = latestData; + + //copy data and filename + strcpy(c,guiFileName); + fnum = guiFrameNumber; + + + //could not get gui data + if(!guiDataReady){ + *raw = NULL; + } + //data ready, set guidata to receive new data + else{ + *raw = guiData; + guiData = NULL; + + pthread_mutex_lock(&dataReadyMutex); + guiDataReady = 0; + pthread_mutex_unlock(&dataReadyMutex); + if((nFrameToGui) && (writerthreads_mask)){ + /*if(nFrameToGui){*/ + //release after getting data + sem_post(&smp); + } + } +} + + + + + +void UDPRESTImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ + + //random read when gui not ready + if((!nFrameToGui) && (!guiData)){ + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + pthread_mutex_unlock(&dataReadyMutex); + } + + //random read or nth frame read, gui needs data now + else{ + /* + //nth frame read, block current process if the guireader hasnt read it yet + if(nFrameToGui) + sem_wait(&smp); +*/ + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + //eiger + if(startbuf != NULL){ + int offset = 0; + int size = frameSize/EIGER_MAX_PORTS; + for(int j=0;jgetErrorStatus(); + if(iret){ +#ifdef VERBOSE + cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; +#endif + return FAIL; + } + } + + return OK; +} + + + + + + + +int UDPRESTImplementation::shutDownUDPSockets(){ + for(int i=0;iShutDownSocket(); + delete udpSocket[i]; + udpSocket[i] = NULL; + } + } + return OK; +} + + + + + +int UDPRESTImplementation::createListeningThreads(bool destroy){ + int i; + void* status; + + killAllListeningThreads = 0; + + pthread_mutex_lock(&status_mutex); + listeningthreads_mask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + if(!destroy){ + + //start listening threads + cout << "Creating Listening Threads(s)"; + + currentListeningThreadIndex = -1; + + for(i = 0; i < numListeningThreads; ++i){ + sem_init(&listensmp[i],1,0); + thread_started = 0; + currentListeningThreadIndex = i; + if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ + cout << "Could not create listening thread with index " << i << endl; + return FAIL; + } + while(!thread_started); + cout << "."; + cout << flush; + } +#ifdef VERBOSE + cout << "Listening thread(s) created successfully." << endl; +#else + cout << endl; +#endif + }else{ + cout<<"Destroying Listening Thread(s)"<initEventTree(temp, &iframe); + //resets the pedestalSubtraction array and the commonModeSubtraction + singlePhotonDet[ithr]->newDataSet(); + if(myFile[ithr]==NULL){ + cout<<"file null"<IsOpen()){ + cout<<"file not open"< DO_NOTHING){ + //close + if(sfilefd){ + fclose(sfilefd); + sfilefd = NULL; + } + //open file + if(!overwrite){ + if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ + cout << "Error: Could not create new file " << savefilename << endl; + return FAIL; + } + }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ + cout << "Error: Could not create file " << savefilename << endl; + return FAIL; + } + //setting buffer + setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + + //printing packet losses and file names + if(!packetsCaught) + cout << savefilename << endl; + else{ + cout << savefilename + << "\tpacket loss " + << setw(4)<GetCurrentFile(); + + if(myFile[ithr]->Write()) + //->Write(tall->GetName(),TObject::kOverwrite); + cout << "Thread " << ithr <<": wrote frames to file" << endl; + else + cout << "Thread " << ithr << ": could not write frames to file" << endl; + + }else + cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; + //close file + if(myTree[ithr] && myFile[ithr]) + myFile[ithr] = myTree[ithr]->GetCurrentFile(); + if(myFile[ithr] != NULL) + myFile[ithr]->Close(); + myFile[ithr] = NULL; + myTree[ithr] = NULL; + pthread_mutex_unlock(&write_mutex); + +#endif + } +} + + + + + +int UDPRESTImplementation::startReceiver(char message[]){ + int i; + + +// #ifdef VERBOSE + cout << "Starting Receiver" << endl; +//#endif + + + //reset listening thread variables + measurementStarted = false; + //should be set to zero as its added to get next start frame indices for scans for eiger + if(!acqStarted) currframenum = 0; + startFrameIndex = 0; + + for(int i = 0; i < numListeningThreads; ++i) + totalListeningFrameCount[i] = 0; + + //udp socket + if(createUDPSockets() == FAIL){ + strcpy(message,"Could not create UDP Socket(s).\n"); + cout << endl << message << endl; + return FAIL; + } + cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; + + + if(setupWriter() == FAIL){ + //stop udp socket + shutDownUDPSockets(); + + sprintf(message,"Could not create file %s.\n",savefilename); + return FAIL; + } + cout << "Successfully created file(s)" << endl; + + //done to give the gui some proper name instead of always the last file name + if(dataCompression) + sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + + //initialize semaphore + sem_init(&smp,1,0); + + //status + pthread_mutex_lock(&status_mutex); + status = RUNNING; + for(i=0;istartListening(); + + return this_pointer; +} + + + +void* UDPRESTImplementation::startWritingThread(void* this_pointer){ + ((UDPRESTImplementation*)this_pointer)->startWriting(); + return this_pointer; +} + + + + + + +int UDPRESTImplementation::startListening(){ + int ithread = currentListeningThreadIndex; +#ifdef VERYVERBOSE + cout << "In startListening() " << endl; +#endif + + thread_started = 1; + + int i,total; + int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; + uint32_t lastframeheader;// for moench to check for all the packets in last frame + char* tempchar = NULL; + int imageheader = 0; + if(myDetectorType==EIGER) + imageheader = EIGER_IMAGE_HEADER_SIZE; + + + while(1){ + //variables that need to be checked/set before each acquisition + carryonBufferSize = 0; + //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later + maxBufferSize = bufferSize * numJobsPerThread; +#ifdef VERYDEBUG + cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; +#endif + + if(tempchar) {delete [] tempchar;tempchar = NULL;} + if(myDetectorType != EIGER) + tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size + + + while((1<pop(buffer[ithread]); +#ifdef VERYDEBUG + cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; +#endif + + + //receive + if(udpSocket[ithread] == NULL){ + rc = 0; + cout << ithread << "UDP Socket is NULL" << endl; + } + //normal listening + else if(!carryonBufferSize){ + + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + expected = maxBufferSize; + + } + //the remaining packets from previous buffer + else{ +#ifdef VERYDEBUG + cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; + cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) + & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); + expected = maxBufferSize - carryonBufferSize; + } + +#ifdef VERYDEBUG + cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; +#endif + + + + + //start indices for each start of scan/acquisition - eiger does it before + if((!measurementStarted) && (rc > 0) && (!ithread)) + startFrameIndices(ithread); + + //problem in receiving or end of acquisition + if((rc < expected)||(rc <= 0)){ + stopListening(ithread,rc,packetcount,total); + continue; + } + + + + //reset + packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; + carryonBufferSize = 0; + + + + //check if last packet valid and calculate packet count + switch(myDetectorType){ + + case MOENCH: + lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; + cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; + cout << "last packet offset:" << lastpacketoffset << endl; + cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; + cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + //moench last packet value is 0 + if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ + lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; + carryonBufferSize += onePacketSize; + lastpacketoffset -= onePacketSize; + --packetcount; + while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ + carryonBufferSize += onePacketSize; + lastpacketoffset -= onePacketSize; + --packetcount; + } + memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); +#ifdef VERYDEBUG + cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) + & (frameIndexMask)) >> frameIndexOffset) << endl; + cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) + & (packetIndexMask)) << endl; +#endif + } + break; + + case GOTTHARD: + if(shortFrame == -1){ + lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cout << "last packet offset:" << lastpacketoffset << endl; +#endif + + if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ + memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); +#ifdef VERYDEBUG + cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) + & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + carryonBufferSize = onePacketSize; + --packetcount; + } + } +#ifdef VERYDEBUG + cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + break; + default: + + break; + + } + + + // cout<<"*********** "<fnum)<push(buffer[ithread])); +#ifdef VERYDEBUG + if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; +#endif + } + + sem_wait(&listensmp[ithread]); + + //make sure its not exiting thread + if(killAllListeningThreads){ + cout << ithread << " good bye listening thread" << endl; + if(tempchar) {delete [] tempchar;tempchar = NULL;} + pthread_exit(NULL); + } + } + + return OK; +} + + + + + + + + + + + + + +int UDPRESTImplementation::startWriting(){ + int ithread = currentWriterThreadIndex; +#ifdef VERYVERBOSE + cout << ithread << "In startWriting()" <pop(wbuf[i]); + numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); +#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << endl; +#endif + } + +#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; +#endif + + + //last dummy packet + if(numpackets == 0xFFFF){ + stopWriting(ithread,wbuf); + continue; + } + + + + + //for progress + if(myDetectorType == EIGER){ + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 + }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + pthread_mutex_lock(&progress_mutex); + if(tempframenum > currframenum) + currframenum = tempframenum; + pthread_mutex_unlock(&progress_mutex); + } +//#ifdef VERYDEBUG + if(myDetectorType == EIGER) + cout << endl < 0){ + for(i=0;ipush(wbuf[i])); +#ifdef VERYDEBUG + cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; +#endif + } + + + } + else{ + //copy to gui + copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYVERBOSE + cout << ithread << " finished copying" << endl; +#endif + while(!fifoFree[0]->push(wbuf[0])); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuf[0]<fnum); + //gotthard has +1 for frame number and not a short frame + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset); + else + startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) + & (frameIndexMask)) >> frameIndexOffset); + + + //start of acquisition + if(!acqStarted){ + startAcquisitionIndex=startFrameIndex; + currframenum = startAcquisitionIndex; + acqStarted = true; + cout << "startAcquisitionIndex:" << startAcquisitionIndex<push(buffer[ithread]); + exit(-1); + } + //push the last buffer into fifo + if(rc > 0){ + pc = (rc/onePacketSize); +#ifdef VERYDEBUG + cout << ithread << " *** last packetcount:" << pc << endl; +#endif + (*((uint16_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef VERYDEBUG + cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; +#endif + } + + + //push dummy buffer to all writer threads + for(i=0;ipop(buffer[ithread]); + (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; +#ifdef VERYDEBUG + cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; +#endif + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef VERYDEBUG + cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; +#endif + } + + //reset mask and exit loop + pthread_mutex_lock(&status_mutex); + listeningthreads_mask^=(1< 1) + cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; +#endif + while(listeningthreads_mask) + usleep(5000); +#ifdef VERYDEBUG + t = 0; + for(i=0;ipush(wbuffer[i])); +#ifdef VERYDEBUG + cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; +#endif + } + + + + //all threads need to close file, reset mask and exit loop + closeFile(ithread); + pthread_mutex_lock(&status_mutex); + writerthreads_mask^=(1< 0){ + + //for progress and packet loss calculation(new files) + if(myDetectorType == EIGER); + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + if(tempframenum > currframenum) + currframenum = tempframenum; + } +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + + //lock + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + + + //to create new file when max reached + packetsToSave = maxPacketsPerFile - packetsInFile; + if(packetsToSave > numpackets) + packetsToSave = numpackets; +/**next time offset is still plus header length*/ + fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); + packetsInFile += packetsToSave; + packetsCaught += packetsToSave; + totalPacketsCaught += packetsToSave; + + + //new file + if(packetsInFile >= maxPacketsPerFile){ + //for packet loss + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); + if(myDetectorType == EIGER); + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + if(tempframenum > currframenum) + currframenum = tempframenum; + } +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + //create + createNewFile(); + } + + //unlock + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); + + + offset += (packetsToSave * onePacketSize); + numpackets -= packetsToSave; + } + + } + else{ + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + packetsInFile += numpackets; + packetsCaught += numpackets; + totalPacketsCaught += numpackets; + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); + } +} + + + + + + + + + + + + + + +void UDPRESTImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ + +#if defined(MYROOT1) && defined(ALLFILE_DEBUG) + writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); +#endif + + eventType thisEvent = PEDESTAL; + int ndata; + char* buff = 0; + data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; + int remainingsize = npackets * onePacketSize; + int np; + int once = 0; + double tot, tl, tr, bl, br; + int xmin = 1, ymin = 1, ix, iy; + + + while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ + np = ndata/onePacketSize; + + //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); + + //only for moench + if(commonModeSubtractionEnable){ + for(ix = xmin - 1; ix < xmax+1; ix++){ + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); + } + } + } + + + for(ix = xmin - 1; ix < xmax+1; ix++) + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); + if (nf>1000) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + if (thisEvent==PHOTON_MAX) { + receiverdata[ithread]->getFrameNumber(buff); + //iFrame=receiverdata[ithread]->getFrameNumber(buff); +#ifdef MYROOT1 + myTree[ithread]->Fill(); + //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; +#else + pthread_mutex_lock(&write_mutex); + if((enableFileWrite) && (sfilefd)) + singlePhotonDet[ithread]->writeCluster(sfilefd); + pthread_mutex_unlock(&write_mutex); +#endif + } + } + } + + nf++; +#ifndef ALLFILE + pthread_mutex_lock(&progress_mutex); + packetsInFile += packetsPerFrame; + packetsCaught += packetsPerFrame; + totalPacketsCaught += packetsPerFrame; + if(packetsInFile >= maxPacketsPerFile) + createNewFile(); + pthread_mutex_unlock(&progress_mutex); + +#endif + if(!once){ + copyFrameToGui(NULL,-1,buff); + once = 1; + } + } + + remainingsize -= ((buff + ndata) - data); + data = buff + ndata; + if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) + cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuffer[0]<= 0){ + + tengigaEnable = enable; + + if(myDetectorType == EIGER){ + + if(!tengigaEnable){ + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + }else{ + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; + } + frameSize = onePacketSize * packetsPerFrame; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) + //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + + + cout<<"packetsPerFrame:"< +#include +#endif + +#include "RestHelper.h" + + +#include +#include +#include +#include + +/** + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + */ + +class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImplementation { + + public: + /** + * Constructor + */ + UDPRESTImplementation(); + + /** + * Destructor + */ + virtual ~UDPRESTImplementation(); + + + + /** + * delete and free member parameters + */ + void deleteMembers(); + + /** + * initialize member parameters + */ + void initializeMembers(); + + /** + * Set receiver type + * @param det detector type + * Returns success or FAIL + */ + int setDetectorType(detectorType det); + + + //Frame indices and numbers caught + /** + * Returns current Frame Index Caught for an entire acquisition (including all scans) + */ + uint32_t getAcquisitionIndex(); + + /** + * Returns if acquisition started + */ + bool getAcquistionStarted(); + + /** + * Returns Frames Caught for each real time acquisition (eg. for each scan) + */ + int getFramesCaught(); + + /** + * Returns Total Frames Caught for an entire acquisition (including all scans) + */ + int getTotalFramesCaught(); + + /** + * Returns the frame index at start of each real time acquisition (eg. for each scan) + */ + uint32_t getStartFrameIndex(); + + /** + * Returns current Frame Index for each real time acquisition (eg. for each scan) + */ + uint32_t getFrameIndex(); + + /** + * Returns if measurement started + */ + bool getMeasurementStarted(); + + /** + * Resets the Total Frames Caught + * This is how the receiver differentiates between entire acquisitions + * Returns 0 + */ + void resetTotalFramesCaught(); + + + + + //file parameters + /** + * Returns File Path + */ + //char* getFilePath() const; + + /** + * Set File Path + * @param c file path + */ + //char* setFilePath(const char c[]); + + /** + * Returns File Name + */ + //char* getFileName() const; + + /** + * Set File Name (without frame index, file index and extension) + * @param c file name + */ + //char* setFileName(const char c[]); + + /** + * Returns File Index + */ + int getFileIndex(); + + /** + * Set File Index + * @param i file index + */ + int setFileIndex(int i); + + /** + * Set Frame Index Needed + * @param i frame index needed + */ + int setFrameIndexNeeded(int i); + + /** + * Set enable file write + * @param i file write enable + * Returns file write enable + */ + //int setEnableFileWrite(int i); + + /** + * Enable/disable overwrite + * @param i enable + * Returns enable over write + */ + //int setEnableOverwrite(int i); + + /** + * Returns file write enable + * 1: YES 0: NO + */ + //int getEnableFileWrite() const; + + /** + * Returns file over write enable + * 1: YES 0: NO + */ + //int getEnableOverwrite() const; + +//other parameters + + /** + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + void abort() {}; + + /** + * Returns status of receiver: idle, running or error + */ + runStatus getStatus() const; + + /** + * Set detector hostname + * @param c hostname + */ + void initialize(const char *detectorHostName); + + /* Returns detector hostname + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ + //char *getDetectorHostname() const; + + /** + * Set Ethernet Interface or IP to listen to + */ + void setEthernetInterface(char* c); + + /** + * Set UDP Port Number + */ + void setUDPPortNo(int p); + + /* + * Returns number of frames to receive + * This is the number of frames to expect to receiver from the detector. + * The data receiver will change from running to idle when it got this number of frames + */ + + //int getNumberOfFrames() const; + + /** + * set frame number if a positive number + */ + //int32_t setNumberOfFrames(int32_t fnum); + + + /** + * Returns scan tag + */ + //int getScanTag() const; + + /** + * set scan tag if its is a positive number + */ + //int32_t setScanTag(int32_t stag); + + /** + * Returns the number of bits per pixel + */ + //int getDynamicRange() const; + + /** + * set dynamic range if its is a positive number + */ + int32_t setDynamicRange(int32_t dr); + + /** + * Set short frame + * @param i if shortframe i=1 + */ + int setShortFrame(int i); + + /** + * Set the variable to send every nth frame to gui + * or if 0,send frame only upon gui request + */ + int setNFrameToGui(int i); + + /** set acquisition period if a positive number + */ + int64_t setAcquisitionPeriod(int64_t index); + + /** get data compression, by saving only hits + */ + bool getDataCompression(); + + /** enabl data compression, by saving only hits + /returns if failed + */ + int enableDataCompression(bool enable); + + /** + * enable 10Gbe + @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out + \returns enable for 10Gbe + */ + int enableTenGiga(int enable = -1); + + + +//other functions + + /** + * Returns the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param fnum frame number for eiger as it is not in the packet + */ + void readFrame(char* c,char** raw, uint32_t &fnum); + + /** + * Closes all files + * @param ithr thread index + */ + void closeFile(int ithr = -1); + + /** + * Starts Receiver - starts to listen for packets + * @param message is the error message if there is an error + * Returns success + */ + int startReceiver(char message[]); + + /** + * Stops Receiver - stops listening for packets + * Returns success + */ + int stopReceiver(); + + /** set status to transmitting and + * when fifo is empty later, sets status to run_finished + */ + void startReadout(); + + /** + * shuts down the udp sockets + * \returns if success or fail + */ + int shutDownUDPSockets(); + +private: + + /* + void not_implemented(string method_name){ + std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; + }; + */ + /** + * Deletes all the filter objects for single photon data + */ + void deleteFilter(); + + /** + * Constructs the filter for single photon data + */ + void setupFilter(); + + /** + * set up fifo according to the new numjobsperthread + */ + void setupFifoStructure (); + + /** + * Copy frames to gui + * uses semaphore for nth frame mode + */ + void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); + + /** + * creates udp sockets + * \returns if success or fail + */ + int createUDPSockets(); + + /** + * create listening thread + * @param destroy is true to kill all threads and start again + */ + int createListeningThreads(bool destroy = false); + + /** + * create writer threads + * @param destroy is true to kill all threads and start again + */ + int createWriterThreads(bool destroy = false); + + /** + * set thread priorities + */ + void setThreadPriorities(); + + /** + * initializes variables and creates the first file + * also does the startAcquisitionCallBack + * \returns FAIL or OK + */ + int setupWriter(); + + /** + * Creates new tree and file for compression + * @param ithr thread number + * @param iframe frame number + *\returns OK for succces or FAIL for failure + */ + int createCompressionFile(int ithr, int iframe); + + /** + * Creates new file + *\returns OK for succces or FAIL for failure + */ + int createNewFile(); + + /** + * Static function - Thread started which listens to packets. + * Called by startReceiver() + * @param this_pointer pointer to this object + */ + static void* startListeningThread(void *this_pointer); + + /** + * Static function - Thread started which writes packets to file. + * Called by startReceiver() + * @param this_pointer pointer to this object + */ + static void* startWritingThread(void *this_pointer); + + /** + * Thread started which listens to packets. + * Called by startReceiver() + * + */ + int startListening(); + + /** + * Thread started which writes packets to file. + * Called by startReceiver() + * + */ + int startWriting(); + + /** + * Writing to file without compression + * @param buf is the address of buffer popped out of fifo + * @param numpackets is the number of packets + * @param framenum current frame number + */ + void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); + + /** + * Its called for the first packet of a scan or acquistion + * Sets the startframeindices and the variables to know if acquisition started + * @param ithread listening thread number + */ + void startFrameIndices(int ithread); + + /** + * This is called when udp socket is shut down + * It pops ffff instead of packet number into fifo + * to inform writers about the end of listening session + * @param ithread listening thread number + * @param rc number of bytes received + * @param pc packet count + * @param t total packets listened to + */ + void stopListening(int ithread, int rc, int &pc, int &t); + + /** + * When acquisition is over, this is called + * @param ithread listening thread number + * @param wbuffer writer buffer + */ + void stopWriting(int ithread, char* wbuffer[]); + + + /** + * data compression for each fifo output + * @param ithread listening thread number + * @param wbuffer writer buffer + * @param npackets number of packets from the fifo + * @param data pointer to the next packet start + * @param xmax max pixels in x direction + * @param ymax max pixels in y direction + * @param nf nf + */ + void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); + + + /** structure of an eiger image header*/ + typedef struct + { + unsigned char header_before[20]; + unsigned char fnum[4]; + unsigned char header_after[24]; + } eiger_image_header; + + + /** structure of an eiger image header*/ + typedef struct + { + unsigned char num1[4]; + unsigned char num2[4]; + } eiger_packet_header; + + /** max number of listening threads */ + const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; + + /** max number of writer threads */ + const static int MAX_NUM_WRITER_THREADS = 15; + + /** detector type */ + detectorType myDetectorType; + + /** detector hostname */ + char detHostname[MAX_STR_LENGTH]; + + /** status of receiver */ + runStatus status; + + /** UDP Socket between Receiver and Detector */ + genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; + + /** Server UDP Port*/ + int server_port[MAX_NUM_LISTENING_THREADS]; + + /** ethernet interface or IP to listen to */ + char *eth; + + /** max packets per file **/ + int maxPacketsPerFile; + + /** File write enable */ + int enableFileWrite; + + /** File over write enable */ + int overwrite; + + /** Complete File name */ + char savefilename[MAX_STR_LENGTH]; + + /** File Name without frame index, file index and extension*/ + char fileName[MAX_STR_LENGTH]; + + /** File Path */ + char filePath[MAX_STR_LENGTH]; + + /** File Index */ + int fileIndex; + + /** scan tag */ + int scanTag; + + /** if frame index required in file name */ + int frameIndexNeeded; + + /* Acquisition started */ + bool acqStarted; + + /* Measurement started */ + bool measurementStarted; + + /** Frame index at start of each real time acquisition (eg. for each scan) */ + uint32_t startFrameIndex; + + /** Actual current frame index of each time acquisition (eg. for each scan) */ + uint32_t frameIndex; + + /** Frames Caught for each real time acquisition (eg. for each scan) */ + int packetsCaught; + + /** Total packets caught for an entire acquisition (including all scans) */ + int totalPacketsCaught; + + /** Pckets currently in current file, starts new file when it reaches max */ + int packetsInFile; + + /** Frame index at start of an entire acquisition (including all scans) */ + uint32_t startAcquisitionIndex; + + /** Actual current frame index of an entire acquisition (including all scans) */ + uint32_t acquisitionIndex; + + /** number of packets per frame*/ + int packetsPerFrame; + + /** frame index mask */ + uint32_t frameIndexMask; + + /** packet index mask */ + uint32_t packetIndexMask; + + /** frame index offset */ + int frameIndexOffset; + + /** acquisition period */ + int64_t acquisitionPeriod; + + /** frame number */ + int32_t numberOfFrames; + + /** dynamic range */ + int dynamicRange; + + /** short frames */ + int shortFrame; + + /** current frame number */ + uint32_t currframenum; + + /** Previous Frame number from buffer */ + uint32_t prevframenum; + + /** size of one frame */ + int frameSize; + + /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ + int bufferSize; + + /** oen buffer size */ + int onePacketSize; + + /** latest data */ + char* latestData; + + /** gui data ready */ + int guiDataReady; + + /** points to the data to send to gui */ + char* guiData; + + /** points to the filename to send to gui */ + char* guiFileName; + + /** temporary number for eiger frame number as its not included in the packet */ + uint32_t guiFrameNumber; + + /** send every nth frame to gui or only upon gui request*/ + int nFrameToGui; + + /** fifo size */ + unsigned int fifosize; + + /** number of jobs per thread for data compression */ + int numJobsPerThread; + + /** datacompression - save only hits */ + bool dataCompression; + + /** memory allocated for the buffer */ + char *mem0[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data read */ + CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data already written and ready to be resued*/ + CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; + + /** Receiver buffer */ + char *buffer[MAX_NUM_LISTENING_THREADS]; + + /** number of writer threads */ + int numListeningThreads; + + /** number of writer threads */ + int numWriterThreads; + + /** to know if listening and writer threads created properly */ + int thread_started; + + /** current listening thread index*/ + int currentListeningThreadIndex; + + /** current writer thread index*/ + int currentWriterThreadIndex; + + /** thread listening to packets */ + pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; + + /** thread writing packets */ + pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; + + /** total frame count the listening thread has listened to */ + int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; + + /** mask showing which listening threads are running */ + volatile uint32_t listeningthreads_mask; + + /** mask showing which writer threads are running */ + volatile uint32_t writerthreads_mask; + + /** mask showing which threads have created files*/ + volatile uint32_t createfile_mask; + + /** OK if file created was successful */ + int ret_createfile; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllListeningThreads; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllWritingThreads; + + /** 10Gbe enable*/ + int tengigaEnable; + + + + +//semaphores + /** semaphore to synchronize writer and guireader threads */ + sem_t smp; + /** semaphore to synchronize listener threads */ + sem_t listensmp[MAX_NUM_LISTENING_THREADS]; + /** semaphore to synchronize writer threads */ + sem_t writersmp[MAX_NUM_WRITER_THREADS]; + + +//mutex + /** guiDataReady mutex */ + pthread_mutex_t dataReadyMutex; + + /** mutex for status */ + pthread_mutex_t status_mutex; + + /** mutex for progress variable currframenum */ + pthread_mutex_t progress_mutex; + + /** mutex for writing data to file */ + pthread_mutex_t write_mutex; + + /** File Descriptor */ + FILE *sfilefd; + + //filter + singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + moenchCommonMode *cmSub; + bool commonModeSubtractionEnable; + +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUM_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUM_WRITER_THREADS]; +#endif + + + + /** + callback arguments are + filepath + filename + fileindex + data size + + return value is + 0 callback takes care of open,close,write file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + + */ + int (*startAcquisitionCallBack)(char*, char*,int, int, void*); + void *pStartAcquisition; + + /** + args to acquisition finished callback + total frames caught + + */ + void (*acquisitionFinishedCallBack)(int, void*); + void *pAcquisitionFinished; + + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); + void *pRawDataReady; + + /** The action which decides what the user and default responsibilites to save data are + * 0 raw data ready callback takes care of open,close,write file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ + int cbAction; + + +public: + + + /** + callback arguments are + filepath + filename + fileindex + datasize + + return value is + 0 callback takes care of open,close,wrie file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + */ + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; + + /** + callback argument is + toatal frames caught + */ + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; + + + //REST specific + bool isInitialized; + RestHelper * rest ; +}; + + +#endif + +//#endif /*REST*/ diff --git a/slsReceiverSoftware/slsReceiver/UDPStandardImplementation.cpp b/slsReceiverSoftware/slsReceiver/UDPStandardImplementation.cpp new file mode 100644 index 0000000000..1314f2d5cb --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/UDPStandardImplementation.cpp @@ -0,0 +1,2330 @@ +/********************************************//** + * @file UDPStandardImplementation.cpp + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + ***********************************************/ + + +#include "UDPStandardImplementation.h" + +#include "moench02ModuleData.h" +#include "gotthardModuleData.h" +#include "gotthardShortModuleData.h" + + +#include // SIGINT +#include // stat +#include // socket(), bind(), listen(), accept(), shut down +#include // sock_addr_in, htonl, INADDR_ANY +#include // exit() +#include //set precision +#include //munmap + + + +#include +#include + + + +using namespace std; + +void UDPStandardImplementation::initializeMembers(){ + myDetectorType = GENERIC; + maxPacketsPerFile = 0; + enableFileWrite = 1; + overwrite = 1; + fileIndex = 0; + scanTag = 0; + frameIndexNeeded = 0; + acqStarted = false; + measurementStarted = false; + startFrameIndex = 0; + frameIndex = 0; + packetsCaught = 0; + totalPacketsCaught = 0; + packetsInFile = 0; + startAcquisitionIndex = 0; + acquisitionIndex = 0; + packetsPerFrame = 0; + frameIndexMask = 0; + packetIndexMask = 0; + frameIndexOffset = 0; + acquisitionPeriod = SAMPLE_TIME_IN_NS; + numberOfFrames = 0; + dynamicRange = 16; + shortFrame = -1; + currframenum = 0; + prevframenum = 0; + frameSize = 0; + bufferSize = 0; + onePacketSize = 0; + guiDataReady = 0; + nFrameToGui = 0; + fifosize = 0; + numJobsPerThread = -1; + dataCompression = false; + numListeningThreads = 1; + numWriterThreads = 1; + thread_started = 0; + currentListeningThreadIndex = -1; + currentWriterThreadIndex = -1; + for(int i=0;i /proc/sys/net/core/rmem_max")) + cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) + cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + /** permanent setting heiner + net.core.rmem_max = 104857600 # 100MiB + net.core.netdev_max_backlog = 250000 + sysctl -p + // from the manual + sysctl -w net.core.rmem_max=16777216 + sysctl -w net.core.netdev_max_backlog=250000 + */ +} + + + +UDPStandardImplementation::~UDPStandardImplementation(){ + createListeningThreads(true); + createWriterThreads(true); + deleteMembers(); +} + + + + +void UDPStandardImplementation::deleteMembers(){ + //kill threads + if(thread_started){ + createListeningThreads(true); + createWriterThreads(true); + } + + for(int i=0;i=0) + fileIndex = i; + return getFileIndex(); +} +*/ + +/* +int UDPStandardImplementation::setFrameIndexNeeded(int i){ + frameIndexNeeded = i; + return frameIndexNeeded; +} +*/ + +/* +int UDPStandardImplementation::getEnableFileWrite() const{ + return enableFileWrite; +} +*/ + +/* +int UDPStandardImplementation::setEnableFileWrite(int i){ + enableFileWrite=i; + return getEnableFileWrite(); +} +*/ + +/* +int UDPStandardImplementation::getEnableOverwrite() const{ + return overwrite; +} +*/ + +/* +int UDPStandardImplementation::setEnableOverwrite(int i){ + overwrite=i; + return getEnableOverwrite(); +} +*/ + + + + +/*other parameters*/ + +slsReceiverDefs::runStatus UDPStandardImplementation::getStatus() const{ + return status; +} + + +void UDPStandardImplementation::initialize(const char *detectorHostName){ + if(strlen(detectorHostName)) + strcpy(detHostname,detectorHostName); +} + + +char *UDPStandardImplementation::getDetectorHostname() const{ + return (char*)detHostname; +} + +void UDPStandardImplementation::setEthernetInterface(char* c){ + strcpy(eth,c); +} + + +void UDPStandardImplementation::setUDPPortNo(int p){ + for(int i=0;i= 0) + numberOfFrames = fnum; + + return getNumberOfFrames(); +} + +int UDPStandardImplementation::getScanTag() const{ + return scanTag; +} + + +int32_t UDPStandardImplementation::setScanTag(int32_t stag){ + if(stag >= 0) + scanTag = stag; + + return getScanTag(); +} + + +int UDPStandardImplementation::getDynamicRange() const{ + return dynamicRange; +} + +int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ + cout << "Setting Dynamic Range" << endl; + + int olddr = dynamicRange; + if(dr >= 0){ + dynamicRange = dr; + + if(myDetectorType == EIGER){ + + + if(!tengigaEnable) + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + else + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + frameSize = onePacketSize * packetsPerFrame; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + + + + if(olddr != dr){ + + //del + if(thread_started){ + createListeningThreads(true); + createWriterThreads(true); + } + for(int i=0;i=0){ + nFrameToGui = i; + setupFifoStructure(); + } + return nFrameToGui; +} + + + +int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ + + if(index >= 0){ + if(index != acquisitionPeriod){ + acquisitionPeriod = index; + setupFifoStructure(); + } + } + return acquisitionPeriod; +} + + +bool UDPStandardImplementation::getDataCompression(){return dataCompression;} + +int UDPStandardImplementation::enableDataCompression(bool enable){ + cout << "Data compression "; + if(enable) + cout << "enabled" << endl; + else + cout << "disabled" << endl; +#ifdef MYROOT1 + cout << " WITH ROOT" << endl; +#else + cout << " WITHOUT ROOT" << endl; +#endif + //delete filter for the current number of threads + deleteFilter(); + + dataCompression = enable; + pthread_mutex_lock(&status_mutex); + writerthreads_mask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + createWriterThreads(true); + + if(enable) + numWriterThreads = MAX_NUM_WRITER_THREADS; + else + numWriterThreads = 1; + + if(createWriterThreads() == FAIL){ + cout << "ERROR: Could not create writer threads" << endl; + return FAIL; + } + setThreadPriorities(); + + + if(enable) + setupFilter(); + + return OK; +} + + + + + + + + + + + + +/*other functions*/ + + +void UDPStandardImplementation::deleteFilter(){ + int i; + cmSub=NULL; + + for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); + +} + + + +//LEO: it is not clear to me.. +void UDPStandardImplementation::setupFifoStructure(){ + + int64_t i; + int oldn = numJobsPerThread; + + //if every nth frame mode + if(nFrameToGui) + numJobsPerThread = nFrameToGui; + + //random nth frame mode + else{ + if(!acquisitionPeriod) + i = SAMPLE_TIME_IN_NS; + else + i = SAMPLE_TIME_IN_NS/acquisitionPeriod; + if (i > MAX_JOBS_PER_THREAD) + numJobsPerThread = MAX_JOBS_PER_THREAD; + else if (i < 1) + numJobsPerThread = 1; + else + numJobsPerThread = i; + } + + //if same, return + if(oldn == numJobsPerThread) + return; + + if(myDetectorType == EIGER) + numJobsPerThread = 1; + + //otherwise memory too much if numjobsperthread is at max = 1000 + fifosize = GOTTHARD_FIFO_SIZE; + if(myDetectorType == MOENCH) + fifosize = MOENCH_FIFO_SIZE; + else if(myDetectorType == EIGER) + fifosize = EIGER_FIFO_SIZE; + + if(fifosize % numJobsPerThread) + fifosize = (fifosize/numJobsPerThread)+1; + else + fifosize = fifosize/numJobsPerThread; + + + cout << "Number of Frames per buffer:" << numJobsPerThread << endl; + cout << "Fifo Size:" << fifosize << endl; + + /* + //for testing + numJobsPerThread = 3; fifosize = 11; + */ + + for(int i=0;iisEmpty()) + fifoFree[i]->pop(buffer[i]); + delete fifoFree[i]; + } + if(fifo[i]) delete fifo[i]; + if(mem0[i]) free(mem0[i]); + fifoFree[i] = new CircularFifo(fifosize); + fifo[i] = new CircularFifo(fifosize); + + + //allocate memory + mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + /** shud let the client know about this */ + if (mem0[i]==NULL){ + cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + exit(-1); + } + buffer[i]=mem0[i]; + //push the addresses into freed fifoFree and writingFifoFree + while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); + buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + } + } + cout << "Fifo structure(s) reconstructed" << endl; +} + + + + + + + +/** acquisition functions */ + +void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ + //point to gui data + if (guiData == NULL) + guiData = latestData; + + //copy data and filename + strcpy(c,guiFileName); + fnum = guiFrameNumber; + + + //could not get gui data + if(!guiDataReady){ + *raw = NULL; + } + //data ready, set guidata to receive new data + else{ + *raw = guiData; + guiData = NULL; + + pthread_mutex_lock(&dataReadyMutex); + guiDataReady = 0; + pthread_mutex_unlock(&dataReadyMutex); + if((nFrameToGui) && (writerthreads_mask)){ + /*if(nFrameToGui){*/ + //release after getting data + sem_post(&smp); + } + } +} + + + + + +void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ + + //random read when gui not ready + if((!nFrameToGui) && (!guiData)){ + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + pthread_mutex_unlock(&dataReadyMutex); + } + + //random read or nth frame read, gui needs data now + else{ + /* + //nth frame read, block current process if the guireader hasnt read it yet + if(nFrameToGui) + sem_wait(&smp); +*/ + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + //eiger + if(startbuf != NULL){ + int offset = 0; + int size = frameSize/EIGER_MAX_PORTS; + for(int j=0;jgetErrorStatus(); + if(iret){ +#ifdef VERBOSE + cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; +#endif + return FAIL; + } + } + + return OK; +} + + + + + + + +int UDPStandardImplementation::shutDownUDPSockets(){ + for(int i=0;iShutDownSocket(); + delete udpSocket[i]; + udpSocket[i] = NULL; + } + } + return OK; +} + + + + + +int UDPStandardImplementation::createListeningThreads(bool destroy){ + int i; + void* status; + + killAllListeningThreads = 0; + + pthread_mutex_lock(&status_mutex); + listeningthreads_mask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + if(!destroy){ + + //start listening threads + cout << "Creating Listening Threads(s)"; + + currentListeningThreadIndex = -1; + + for(i = 0; i < numListeningThreads; ++i){ + sem_init(&listensmp[i],1,0); + thread_started = 0; + currentListeningThreadIndex = i; + if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ + cout << "Could not create listening thread with index " << i << endl; + return FAIL; + } + while(!thread_started); + cout << "."; + cout << flush; + } +#ifdef VERBOSE + cout << "Listening thread(s) created successfully." << endl; +#else + cout << endl; +#endif + }else{ + cout<<"Destroying Listening Thread(s)"<initEventTree(temp, &iframe); + //resets the pedestalSubtraction array and the commonModeSubtraction + singlePhotonDet[ithr]->newDataSet(); + if(myFile[ithr]==NULL){ + cout<<"file null"<IsOpen()){ + cout<<"file not open"< DO_NOTHING){ + //close + if(sfilefd){ + fclose(sfilefd); + sfilefd = NULL; + } + //open file + if(!overwrite){ + if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ + cout << "Error: Could not create new file " << savefilename << endl; + return FAIL; + } + }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ + cout << "Error: Could not create file " << savefilename << endl; + return FAIL; + } + //setting buffer + setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + + //printing packet losses and file names + if(!packetsCaught) + cout << savefilename << endl; + else{ + cout << savefilename + << "\tpacket loss " + << setw(4)<GetCurrentFile(); + + if(myFile[ithr]->Write()) + //->Write(tall->GetName(),TObject::kOverwrite); + cout << "Thread " << ithr <<": wrote frames to file" << endl; + else + cout << "Thread " << ithr << ": could not write frames to file" << endl; + + }else + cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; + //close file + if(myTree[ithr] && myFile[ithr]) + myFile[ithr] = myTree[ithr]->GetCurrentFile(); + if(myFile[ithr] != NULL) + myFile[ithr]->Close(); + myFile[ithr] = NULL; + myTree[ithr] = NULL; + pthread_mutex_unlock(&write_mutex); + +#endif + } +} + + + + + +int UDPStandardImplementation::startReceiver(char message[]){ + int i; + + +// #ifdef VERBOSE + cout << "Starting Receiver" << endl; +//#endif + + + //reset listening thread variables + measurementStarted = false; + //should be set to zero as its added to get next start frame indices for scans for eiger + if(!acqStarted) currframenum = 0; + startFrameIndex = 0; + + for(int i = 0; i < numListeningThreads; ++i) + totalListeningFrameCount[i] = 0; + + //udp socket + if(createUDPSockets() == FAIL){ + strcpy(message,"Could not create UDP Socket(s).\n"); + cout << endl << message << endl; + return FAIL; + } + cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; + + + if(setupWriter() == FAIL){ + //stop udp socket + shutDownUDPSockets(); + + sprintf(message,"Could not create file %s.\n",savefilename); + return FAIL; + } + cout << "Successfully created file(s)" << endl; + + //done to give the gui some proper name instead of always the last file name + if(dataCompression) + sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + + //initialize semaphore + sem_init(&smp,1,0); + + //status + pthread_mutex_lock(&status_mutex); + status = RUNNING; + for(i=0;istartListening(); + + return this_pointer; +} + + + +void* UDPStandardImplementation::startWritingThread(void* this_pointer){ + ((UDPStandardImplementation*)this_pointer)->startWriting(); + return this_pointer; +} + + + + + + +int UDPStandardImplementation::startListening(){ + int ithread = currentListeningThreadIndex; +#ifdef VERYVERBOSE + cout << "In startListening() " << endl; +#endif + + thread_started = 1; + + int i,total; + int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; + uint32_t lastframeheader;// for moench to check for all the packets in last frame + char* tempchar = NULL; + int imageheader = 0; + if(myDetectorType==EIGER) + imageheader = EIGER_IMAGE_HEADER_SIZE; + + + while(1){ + //variables that need to be checked/set before each acquisition + carryonBufferSize = 0; + //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later + maxBufferSize = bufferSize * numJobsPerThread; +#ifdef VERYDEBUG + cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; +#endif + + if(tempchar) {delete [] tempchar;tempchar = NULL;} + if(myDetectorType != EIGER) + tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size + + + while((1<pop(buffer[ithread]); +#ifdef VERYDEBUG + cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; +#endif + + + //receive + if(udpSocket[ithread] == NULL){ + rc = 0; + cout << ithread << "UDP Socket is NULL" << endl; + } + //normal listening + else if(!carryonBufferSize){ + + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + expected = maxBufferSize; + + } + //the remaining packets from previous buffer + else{ +#ifdef VERYDEBUG + cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; + cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) + & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); + expected = maxBufferSize - carryonBufferSize; + } + +#ifdef VERYDEBUG + cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; +#endif + + + + + //start indices for each start of scan/acquisition - eiger does it before + if((!measurementStarted) && (rc > 0) && (!ithread)) + startFrameIndices(ithread); + + //problem in receiving or end of acquisition + if((rc < expected)||(rc <= 0)){ + stopListening(ithread,rc,packetcount,total); + continue; + } + + + + //reset + packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; + carryonBufferSize = 0; + + + + //check if last packet valid and calculate packet count + switch(myDetectorType){ + + case MOENCH: + lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; + cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; + cout << "last packet offset:" << lastpacketoffset << endl; + cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; + cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + //moench last packet value is 0 + if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ + lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; + carryonBufferSize += onePacketSize; + lastpacketoffset -= onePacketSize; + --packetcount; + while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ + carryonBufferSize += onePacketSize; + lastpacketoffset -= onePacketSize; + --packetcount; + } + memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); +#ifdef VERYDEBUG + cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) + & (frameIndexMask)) >> frameIndexOffset) << endl; + cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) + & (packetIndexMask)) << endl; +#endif + } + break; + + case GOTTHARD: + if(shortFrame == -1){ + lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cout << "last packet offset:" << lastpacketoffset << endl; +#endif + + if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ + memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); +#ifdef VERYDEBUG + cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) + & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + carryonBufferSize = onePacketSize; + --packetcount; + } + } +#ifdef VERYDEBUG + cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset) << endl; +#endif + break; + default: + + break; + + } + + + // cout<<"*********** "<fnum)<push(buffer[ithread])); +#ifdef VERYDEBUG + if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; +#endif + } + + sem_wait(&listensmp[ithread]); + + //make sure its not exiting thread + if(killAllListeningThreads){ + cout << ithread << " good bye listening thread" << endl; + if(tempchar) {delete [] tempchar;tempchar = NULL;} + pthread_exit(NULL); + } + } + + return OK; +} + + + + + + + + + + + + + +int UDPStandardImplementation::startWriting(){ + int ithread = currentWriterThreadIndex; +#ifdef VERYVERBOSE + cout << ithread << "In startWriting()" <pop(wbuf[i]); + numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); +#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << endl; +#endif + } + +#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; + cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; +#endif + + + //last dummy packet + if(numpackets == 0xFFFF){ + stopWriting(ithread,wbuf); + continue; + } + + + + + //for progress + if(myDetectorType == EIGER){ + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 + }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + pthread_mutex_lock(&progress_mutex); + if(tempframenum > currframenum) + currframenum = tempframenum; + pthread_mutex_unlock(&progress_mutex); + } +//#ifdef VERYDEBUG + if(myDetectorType == EIGER) + cout << endl < 0){ + for(i=0;ipush(wbuf[i])); +#ifdef VERYDEBUG + cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; +#endif + } + + + } + else{ + //copy to gui + copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYVERBOSE + cout << ithread << " finished copying" << endl; +#endif + while(!fifoFree[0]->push(wbuf[0])); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuf[0]<fnum); + //gotthard has +1 for frame number and not a short frame + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset); + else + startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) + & (frameIndexMask)) >> frameIndexOffset); + + + //start of acquisition + if(!acqStarted){ + startAcquisitionIndex=startFrameIndex; + currframenum = startAcquisitionIndex; + acqStarted = true; + cout << "startAcquisitionIndex:" << startAcquisitionIndex<push(buffer[ithread]); + exit(-1); + } + //push the last buffer into fifo + if(rc > 0){ + pc = (rc/onePacketSize); +#ifdef VERYDEBUG + cout << ithread << " *** last packetcount:" << pc << endl; +#endif + (*((uint16_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef VERYDEBUG + cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; +#endif + } + + + //push dummy buffer to all writer threads + for(i=0;ipop(buffer[ithread]); + (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; +#ifdef VERYDEBUG + cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; +#endif + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef VERYDEBUG + cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; +#endif + } + + //reset mask and exit loop + pthread_mutex_lock(&status_mutex); + listeningthreads_mask^=(1< 1) + cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; +#endif + while(listeningthreads_mask) + usleep(5000); +#ifdef VERYDEBUG + t = 0; + for(i=0;ipush(wbuffer[i])); +#ifdef VERYDEBUG + cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; +#endif + } + + + + //all threads need to close file, reset mask and exit loop + closeFile(ithread); + pthread_mutex_lock(&status_mutex); + writerthreads_mask^=(1< 0){ + + //for progress and packet loss calculation(new files) + if(myDetectorType == EIGER); + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + if(tempframenum > currframenum) + currframenum = tempframenum; + } +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + + //lock + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + + + //to create new file when max reached + packetsToSave = maxPacketsPerFile - packetsInFile; + if(packetsToSave > numpackets) + packetsToSave = numpackets; +/**next time offset is still plus header length*/ + fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); + packetsInFile += packetsToSave; + packetsCaught += packetsToSave; + totalPacketsCaught += packetsToSave; + + + //new file + if(packetsInFile >= maxPacketsPerFile){ + //for packet loss + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); + if(myDetectorType == EIGER); + else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + if(tempframenum > currframenum) + currframenum = tempframenum; + } +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + //create + createNewFile(); + } + + //unlock + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); + + + offset += (packetsToSave * onePacketSize); + numpackets -= packetsToSave; + } + + } + else{ + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + packetsInFile += numpackets; + packetsCaught += numpackets; + totalPacketsCaught += numpackets; + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); + } +} + + + + + + + + + + + + + + +void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ + +#if defined(MYROOT1) && defined(ALLFILE_DEBUG) + writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); +#endif + + eventType thisEvent = PEDESTAL; + int ndata; + char* buff = 0; + data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; + int remainingsize = npackets * onePacketSize; + int np; + int once = 0; + double tot, tl, tr, bl, br; + int xmin = 1, ymin = 1, ix, iy; + + + while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ + np = ndata/onePacketSize; + + //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); + + //only for moench + if(commonModeSubtractionEnable){ + for(ix = xmin - 1; ix < xmax+1; ix++){ + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); + } + } + } + + + for(ix = xmin - 1; ix < xmax+1; ix++) + for(iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); + if (nf>1000) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + if (thisEvent==PHOTON_MAX) { + receiverdata[ithread]->getFrameNumber(buff); + //iFrame=receiverdata[ithread]->getFrameNumber(buff); +#ifdef MYROOT1 + myTree[ithread]->Fill(); + //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; +#else + pthread_mutex_lock(&write_mutex); + if((enableFileWrite) && (sfilefd)) + singlePhotonDet[ithread]->writeCluster(sfilefd); + pthread_mutex_unlock(&write_mutex); +#endif + } + } + } + + nf++; +#ifndef ALLFILE + pthread_mutex_lock(&progress_mutex); + packetsInFile += packetsPerFrame; + packetsCaught += packetsPerFrame; + totalPacketsCaught += packetsPerFrame; + if(packetsInFile >= maxPacketsPerFile) + createNewFile(); + pthread_mutex_unlock(&progress_mutex); + +#endif + if(!once){ + copyFrameToGui(NULL,-1,buff); + once = 1; + } + } + + remainingsize -= ((buff + ndata) - data); + data = buff + ndata; + if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) + cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); +#ifdef VERYVERBOSE + cout<<"buf freed:"<<(void*)wbuffer[0]<= 0){ + + tengigaEnable = enable; + + if(myDetectorType == EIGER){ + + if(!tengigaEnable){ + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + }else{ + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; + } + frameSize = onePacketSize * packetsPerFrame; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) + //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + + + cout<<"packetsPerFrame:"< +#include +#endif + + +#include +#include +#include +#include + + +/** + * @short does all the functions for a receiver, set/get parameters, start/stop etc. + */ + + +class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBaseImplementation { + public: + /** + * Constructor + */ +UDPStandardImplementation(); + + /** + * Destructor + */ + virtual ~UDPStandardImplementation(); + + + + /** + * delete and free member parameters + */ + void deleteMembers(); + + /** + * initialize member parameters + */ + void initializeMembers(); + + /** + * Set receiver type + * @param det detector type + * Returns success or FAIL + */ + int setDetectorType(detectorType det); + + + //Frame indices and numbers caught + /** + * Returns current Frame Index Caught for an entire acquisition (including all scans) + */ + //uint32_t getAcquisitionIndex(); + + /** + * Returns if acquisition started + */ + //bool getAcquistionStarted(); + + /** + * Returns Frames Caught for each real time acquisition (eg. for each scan) + */ + //int getFramesCaught(); + + /** + * Returns Total Frames Caught for an entire acquisition (including all scans) + */ + //int getTotalFramesCaught(); + + /** + * Returns the frame index at start of each real time acquisition (eg. for each scan) + */ + //uint32_t getStartFrameIndex(); + + /** + * Returns current Frame Index for each real time acquisition (eg. for each scan) + */ + //uint32_t getFrameIndex(); + + /** + * Returns if measurement started + */ + //bool getMeasurementStarted(); + + /** + * Resets the Total Frames Caught + * This is how the receiver differentiates between entire acquisitions + * Returns 0 + */ + //void resetTotalFramesCaught(); + + + //file parameters + /** + * Returns File Path + */ + //char* getFilePath() const; + + /** + * Set File Path + * @param c file path + */ + //char* setFilePath(const char c[]); + + /** + * Returns File Name + */ + //char* getFileName() const; + + /** + * Set File Name (without frame index, file index and extension) + * @param c file name + */ + //char* setFileName(const char c[]); + + /** + * Returns File Index + */ + //int getFileIndex(); + + /** + * Set File Index + * @param i file index + */ + //int setFileIndex(int i); + + /** + * Set Frame Index Needed + * @param i frame index needed + */ + //int setFrameIndexNeeded(int i); + + /** + * Set enable file write + * @param i file write enable + * Returns file write enable + */ + //int setEnableFileWrite(int i); + + /** + * Enable/disable overwrite + * @param i enable + * Returns enable over write + */ + //int setEnableOverwrite(int i); + + /** + * Returns file write enable + * 1: YES 0: NO + */ + //int getEnableFileWrite() const; + + /** + * Returns file over write enable + * 1: YES 0: NO + */ + //int getEnableOverwrite() const; + +//other parameters + + /** + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + void abort() {}; + + /** + * Returns status of receiver: idle, running or error + */ + runStatus getStatus() const; + + /** + * Set detector hostname + * @param c hostname + */ + void initialize(const char *detectorHostName); + + /* Returns detector hostname + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ + char *getDetectorHostname() const; + + /** + * Set Ethernet Interface or IP to listen to + */ + void setEthernetInterface(char* c); + + /** + * Set UDP Port Number + */ + void setUDPPortNo(int p); + + /* + * Returns number of frames to receive + * This is the number of frames to expect to receiver from the detector. + * The data receiver will change from running to idle when it got this number of frames + */ + int getNumberOfFrames() const; + + /** + * set frame number if a positive number + */ + int32_t setNumberOfFrames(int32_t fnum); + + /** + * Returns scan tag + */ + int getScanTag() const; + + /** + * set scan tag if its is a positive number + */ + int32_t setScanTag(int32_t stag); + + /** + * Returns the number of bits per pixel + */ + int getDynamicRange() const; + + /** + * set dynamic range if its is a positive number + */ + int32_t setDynamicRange(int32_t dr); + + /** + * Set short frame + * @param i if shortframe i=1 + */ + int setShortFrame(int i); + + /** + * Set the variable to send every nth frame to gui + * or if 0,send frame only upon gui request + */ + int setNFrameToGui(int i); + + /** set acquisition period if a positive number + */ + int64_t setAcquisitionPeriod(int64_t index); + + /** get data compression, by saving only hits + */ + bool getDataCompression(); + + /** enabl data compression, by saving only hits + /returns if failed + */ + int enableDataCompression(bool enable); + + /** + * enable 10Gbe + @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out + \returns enable for 10Gbe + */ + int enableTenGiga(int enable = -1); + + + +//other functions + + /** + * Returns the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param fnum frame number for eiger as it is not in the packet + */ + void readFrame(char* c,char** raw, uint32_t &fnum); + + /** + * Closes all files + * @param ithr thread index + */ + void closeFile(int ithr = -1); + + /** + * Starts Receiver - starts to listen for packets + * @param message is the error message if there is an error + * Returns success + */ + int startReceiver(char message[]); + + /** + * Stops Receiver - stops listening for packets + * Returns success + */ + int stopReceiver(); + + /** set status to transmitting and + * when fifo is empty later, sets status to run_finished + */ + void startReadout(); + + /** + * shuts down the udp sockets + * \returns if success or fail + */ + int shutDownUDPSockets(); + +private: + + /* + void not_implemented(string method_name){ + std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; + }; + */ + /** + * Deletes all the filter objects for single photon data + */ + void deleteFilter(); + + /** + * Constructs the filter for single photon data + */ + void setupFilter(); + + /** + * set up fifo according to the new numjobsperthread + */ + void setupFifoStructure (); + + /** + * Copy frames to gui + * uses semaphore for nth frame mode + */ + void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); + + /** + * creates udp sockets + * \returns if success or fail + */ + int createUDPSockets(); + + /** + * create listening thread + * @param destroy is true to kill all threads and start again + */ + int createListeningThreads(bool destroy = false); + + /** + * create writer threads + * @param destroy is true to kill all threads and start again + */ + int createWriterThreads(bool destroy = false); + + /** + * set thread priorities + */ + void setThreadPriorities(); + + /** + * initializes variables and creates the first file + * also does the startAcquisitionCallBack + * \returns FAIL or OK + */ + int setupWriter(); + + /** + * Creates new tree and file for compression + * @param ithr thread number + * @param iframe frame number + *\returns OK for succces or FAIL for failure + */ + int createCompressionFile(int ithr, int iframe); + + /** + * Creates new file + *\returns OK for succces or FAIL for failure + */ + int createNewFile(); + + /** + * Static function - Thread started which listens to packets. + * Called by startReceiver() + * @param this_pointer pointer to this object + */ + static void* startListeningThread(void *this_pointer); + + /** + * Static function - Thread started which writes packets to file. + * Called by startReceiver() + * @param this_pointer pointer to this object + */ + static void* startWritingThread(void *this_pointer); + + /** + * Thread started which listens to packets. + * Called by startReceiver() + * + */ + int startListening(); + + /** + * Thread started which writes packets to file. + * Called by startReceiver() + * + */ + int startWriting(); + + /** + * Writing to file without compression + * @param buf is the address of buffer popped out of fifo + * @param numpackets is the number of packets + * @param framenum current frame number + */ + void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); + + /** + * Its called for the first packet of a scan or acquistion + * Sets the startframeindices and the variables to know if acquisition started + * @param ithread listening thread number + */ + void startFrameIndices(int ithread); + + /** + * This is called when udp socket is shut down + * It pops ffff instead of packet number into fifo + * to inform writers about the end of listening session + * @param ithread listening thread number + * @param rc number of bytes received + * @param pc packet count + * @param t total packets listened to + */ + void stopListening(int ithread, int rc, int &pc, int &t); + + /** + * When acquisition is over, this is called + * @param ithread listening thread number + * @param wbuffer writer buffer + */ + void stopWriting(int ithread, char* wbuffer[]); + + + /** + * data compression for each fifo output + * @param ithread listening thread number + * @param wbuffer writer buffer + * @param npackets number of packets from the fifo + * @param data pointer to the next packet start + * @param xmax max pixels in x direction + * @param ymax max pixels in y direction + * @param nf nf + */ + void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); + + + /** structure of an eiger image header*/ + typedef struct + { + unsigned char header_before[20]; + unsigned char fnum[4]; + unsigned char header_after[24]; + } eiger_image_header; + + + /** structure of an eiger image header*/ + typedef struct + { + unsigned char num1[4]; + unsigned char num2[4]; + } eiger_packet_header; + + /** max number of listening threads */ + const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; + + /** max number of writer threads */ + const static int MAX_NUM_WRITER_THREADS = 15; + + /** detector type */ + detectorType myDetectorType; + + /** detector hostname */ + char detHostname[MAX_STR_LENGTH]; + + /** status of receiver */ + runStatus status; + + /** UDP Socket between Receiver and Detector */ + genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; + + /** Server UDP Port*/ + int server_port[MAX_NUM_LISTENING_THREADS]; + + /** ethernet interface or IP to listen to */ + char *eth; + + /** max packets per file **/ + int maxPacketsPerFile; + + /** File write enable */ + int enableFileWrite; + + /** File over write enable */ + int overwrite; + + /** Complete File name */ + char savefilename[MAX_STR_LENGTH]; + + /** File Name without frame index, file index and extension*/ + char fileName[MAX_STR_LENGTH]; + + /** File Path */ + char filePath[MAX_STR_LENGTH]; + + /** File Index */ + int fileIndex; + + /** scan tag */ + int scanTag; + + /** if frame index required in file name */ + int frameIndexNeeded; + + /* Acquisition started */ + bool acqStarted; + + /* Measurement started */ + bool measurementStarted; + + /** Frame index at start of each real time acquisition (eg. for each scan) */ + uint32_t startFrameIndex; + + /** Actual current frame index of each time acquisition (eg. for each scan) */ + uint32_t frameIndex; + + /** Frames Caught for each real time acquisition (eg. for each scan) */ + int packetsCaught; + + /** Total packets caught for an entire acquisition (including all scans) */ + int totalPacketsCaught; + + /** Pckets currently in current file, starts new file when it reaches max */ + int packetsInFile; + + /** Frame index at start of an entire acquisition (including all scans) */ + uint32_t startAcquisitionIndex; + + /** Actual current frame index of an entire acquisition (including all scans) */ + uint32_t acquisitionIndex; + + /** number of packets per frame*/ + int packetsPerFrame; + + /** frame index mask */ + uint32_t frameIndexMask; + + /** packet index mask */ + uint32_t packetIndexMask; + + /** frame index offset */ + int frameIndexOffset; + + /** acquisition period */ + int64_t acquisitionPeriod; + + /** frame number */ + int32_t numberOfFrames; + + /** dynamic range */ + int dynamicRange; + + /** short frames */ + int shortFrame; + + /** current frame number */ + uint32_t currframenum; + + /** Previous Frame number from buffer */ + uint32_t prevframenum; + + /** size of one frame */ + int frameSize; + + /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ + int bufferSize; + + /** oen buffer size */ + int onePacketSize; + + /** latest data */ + char* latestData; + + /** gui data ready */ + int guiDataReady; + + /** points to the data to send to gui */ + char* guiData; + + /** points to the filename to send to gui */ + char* guiFileName; + + /** temporary number for eiger frame number as its not included in the packet */ + uint32_t guiFrameNumber; + + /** send every nth frame to gui or only upon gui request*/ + int nFrameToGui; + + /** fifo size */ + unsigned int fifosize; + + /** number of jobs per thread for data compression */ + int numJobsPerThread; + + /** datacompression - save only hits */ + bool dataCompression; + + /** memory allocated for the buffer */ + char *mem0[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data read */ + CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data already written and ready to be resued*/ + CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; + + /** Receiver buffer */ + char *buffer[MAX_NUM_LISTENING_THREADS]; + + /** number of writer threads */ + int numListeningThreads; + + /** number of writer threads */ + int numWriterThreads; + + /** to know if listening and writer threads created properly */ + int thread_started; + + /** current listening thread index*/ + int currentListeningThreadIndex; + + /** current writer thread index*/ + int currentWriterThreadIndex; + + /** thread listening to packets */ + pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; + + /** thread writing packets */ + pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; + + /** total frame count the listening thread has listened to */ + int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; + + /** mask showing which listening threads are running */ + volatile uint32_t listeningthreads_mask; + + /** mask showing which writer threads are running */ + volatile uint32_t writerthreads_mask; + + /** mask showing which threads have created files*/ + volatile uint32_t createfile_mask; + + /** OK if file created was successful */ + int ret_createfile; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllListeningThreads; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllWritingThreads; + + /** 10Gbe enable*/ + int tengigaEnable; + + + + +//semaphores + /** semaphore to synchronize writer and guireader threads */ + sem_t smp; + /** semaphore to synchronize listener threads */ + sem_t listensmp[MAX_NUM_LISTENING_THREADS]; + /** semaphore to synchronize writer threads */ + sem_t writersmp[MAX_NUM_WRITER_THREADS]; + + +//mutex + /** guiDataReady mutex */ + pthread_mutex_t dataReadyMutex; + + /** mutex for status */ + pthread_mutex_t status_mutex; + + /** mutex for progress variable currframenum */ + pthread_mutex_t progress_mutex; + + /** mutex for writing data to file */ + pthread_mutex_t write_mutex; + + /** File Descriptor */ + FILE *sfilefd; + + //filter + singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + moenchCommonMode *cmSub; + bool commonModeSubtractionEnable; + +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUM_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUM_WRITER_THREADS]; +#endif + + + + /** + callback arguments are + filepath + filename + fileindex + data size + + return value is + 0 callback takes care of open,close,write file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + + */ + int (*startAcquisitionCallBack)(char*, char*,int, int, void*); + void *pStartAcquisition; + + /** + args to acquisition finished callback + total frames caught + + */ + void (*acquisitionFinishedCallBack)(int, void*); + void *pAcquisitionFinished; + + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); + void *pRawDataReady; + + /** The action which decides what the user and default responsibilites to save data are + * 0 raw data ready callback takes care of open,close,write file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ + int cbAction; + + +public: + + + /** + callback arguments are + filepath + filename + fileindex + datasize + + return value is + 0 callback takes care of open,close,wrie file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + */ + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; + + /** + callback argument is + toatal frames caught + */ + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; + + /** + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; +}; + + +#endif + +//#endif From c2b885f2306f368a92c411332607d0fa0253282c Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Tue, 9 Sep 2014 17:01:43 +0200 Subject: [PATCH 026/222] version --- slsReceiverSoftware/gitInfo.txt | 8 ++++---- slsReceiverSoftware/includes/gitInfoReceiver.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index cf5def048f..355fd15244 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repsitory UUID: 1c259aeba8b068b9f6e550d63a9a3a14bd7d3ab7 -Revision: 6 +Repsitory UUID: d2553484f575ec21e35c0a782cc307f9e0115554 +Revision: 16 Branch: master Last Changed Author: Maliakal_Dhanya -Last Changed Rev: 6 -Last Changed Date: 2014-06-03 12:06:57 +0200 +Last Changed Rev: 16 +Last Changed Date: 2014-07-31 12:13:15 +0200 diff --git a/slsReceiverSoftware/includes/gitInfoReceiver.h b/slsReceiverSoftware/includes/gitInfoReceiver.h index 05f3c2ab6e..586f715b08 100644 --- a/slsReceiverSoftware/includes/gitInfoReceiver.h +++ b/slsReceiverSoftware/includes/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "1c259aeba8b068b9f6e550d63a9a3a14bd7d3ab7" -//#define SVNREV 0x6 +#define SVNREPUUID "d2553484f575ec21e35c0a782cc307f9e0115554" +//#define SVNREV 0x16 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Maliakal_Dhanya" -#define SVNREV 0x6 -#define SVNDATE 0x20140603 +#define SVNREV 0x16 +#define SVNDATE 0x20140731 // From 811bac16ecc1a86ba329f6c327d17f04c408d926 Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Tue, 9 Sep 2014 17:16:51 +0200 Subject: [PATCH 027/222] trying to make it work... --- slsReceiverSoftware/includes/logger.h | 56 +++++++++++---------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/slsReceiverSoftware/includes/logger.h b/slsReceiverSoftware/includes/logger.h index a230a52662..be93f9fac8 100644 --- a/slsReceiverSoftware/includes/logger.h +++ b/slsReceiverSoftware/includes/logger.h @@ -10,30 +10,25 @@ inline std::string NowTime(); enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4}; template -class Log -{ -public: - Log(); - virtual ~Log(); - std::ostringstream& Get(TLogLevel level = logINFO); -public: - static TLogLevel& ReportingLevel(); - static std::string ToString(TLogLevel level); - static TLogLevel FromString(const std::string& level); -protected: - std::ostringstream os; -private: - Log(const Log&); - Log& operator =(const Log&); +class Log{ + public: + Log(); + virtual ~Log(); + std::ostringstream& Get(TLogLevel level = logINFO); + public: + static TLogLevel& ReportingLevel(); + static std::string ToString(TLogLevel level); + static TLogLevel FromString(const std::string& level); + protected: + std::ostringstream os; + private: + Log(const Log&); + Log& operator =(const Log&); }; -template -Log::Log() -{ -} +template Log::Log() {} -template -std::ostringstream& Log::Get(TLogLevel level) +template std::ostringstream& Log::Get(TLogLevel level) { os << "- " << NowTime(); os << " " << ToString(level) << ": "; @@ -41,29 +36,25 @@ std::ostringstream& Log::Get(TLogLevel level) return os; } -template -Log::~Log() +template Log::~Log() { os << std::endl; T::Output(os.str()); } -template -TLogLevel& Log::ReportingLevel() +template TLogLevel& Log::ReportingLevel() { static TLogLevel reportingLevel = logDEBUG4; return reportingLevel; } -template -std::string Log::ToString(TLogLevel level) +template std::string Log::ToString(TLogLevel level) { static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"}; return buffer[level]; } -template -TLogLevel Log::FromString(const std::string& level) +template TLogLevel Log::FromString(const std::string& level) { if (level == "DEBUG4") return logDEBUG4; @@ -85,15 +76,13 @@ TLogLevel Log::FromString(const std::string& level) return logINFO; } -class Output2FILE -{ +class Output2FILE { public: static FILE*& Stream(); static void Output(const std::string& msg); }; -inline FILE*& Output2FILE::Stream() -{ +inline FILE*& Output2FILE::Stream() { static FILE* pStream = stderr; return pStream; } @@ -136,6 +125,7 @@ class FILELOG_DECLSPEC FILELog : public Log {}; #include inline std::string NowTime() + { const int MAX_LEN = 200; char buffer[MAX_LEN]; From dc04efbbb1723d618b54540e56607959c3cff2c4 Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Tue, 9 Sep 2014 18:13:31 +0200 Subject: [PATCH 028/222] working logger! --- slsReceiverSoftware/Makefile | 23 ++- slsReceiverSoftware/includes/logger.h | 145 ++++++++++-------- slsReceiverSoftware/includes/utilities.h | 20 +-- .../slsReceiver/UDPInterface.cpp | 7 +- .../slsReceiver/UDPInterface.h | 2 +- slsReceiverSoftware/slsReceiver/main.cpp | 1 + slsReceiverSoftware/slsReceiver/utilities.cpp | 66 ++++++++ 7 files changed, 175 insertions(+), 89 deletions(-) create mode 100644 slsReceiverSoftware/slsReceiver/utilities.cpp diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 07de136724..a9f9f57dc9 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -12,17 +12,25 @@ CFLAGS= -g -DC_ONLY -fPIC DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -I$(ASM) + #-IslsReceiverInterface -SRC_CLNT= MySocketTCP/MySocketTCP.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/UDPStandardImplementation.cpp slsReceiver/UDPRESTImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUsers.cpp includes/utilities.h +SRC_CLNT = MySocketTCP/MySocketTCP.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/UDPStandardImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUsers.cpp slsReceiver/utilities.cpp #slsReceiverInterface/receiverInterface.cpp #slsReceiver/slsReceiverUDPFunctions.cpp - -OBJS = $(SRC_CLNT:.cpp=.o) -OBJS += includes/utilities.h +#slsReceiver/utilities.cpp includes/logger.h +#ifeq ($(REST),yes) +# SRC_CLNT += slsReceiver/UDPRESTImplementation.cpp +# INCLUDES += $(RESTINCLUDE) +#endif + +OBJS=$(SRC_CLNT:.cpp=.o) +#OBJS = $(OBJS1:.h=.o) +#OBJS += slsReceiver/logger.o #OBJS += slsReceiver/eigerReceiver.o + .PHONY: all intdoc package eigerReceiver clean all: package $(SRC_CLNT) @@ -30,19 +38,23 @@ all: package $(SRC_CLNT) intdoc: $(SRC_H) $(SRC_CLNT) doxygen doxy.config - %.o : %.cpp Makefile ifeq ($(ROOTSLS),yes) echo "with root" $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) else echo "without root" + echo $(REST) + echo $(INCLUDES) $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) endif # LEO: not satisfied by eigerReceiver package: $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a +#slsReceiver/logger.o: +# $(CXX) -o $@ -c includes/logger.h $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) + #eigerReceiver: # echo "src client:" $(SRC_CLNT) # cd slsReceiver && make eigerReceiver @@ -57,6 +69,7 @@ $(DESTDIR)/libSlsReceiver.a: $(OBJS) mv libSlsReceiver.a $(DESTDIR) clean: + echo rm -rf $(OBJS) rm -rf $(OBJS) cd slsReceiver && make clean cd diff --git a/slsReceiverSoftware/includes/logger.h b/slsReceiverSoftware/includes/logger.h index be93f9fac8..eda43b0b0a 100644 --- a/slsReceiverSoftware/includes/logger.h +++ b/slsReceiverSoftware/includes/logger.h @@ -1,5 +1,5 @@ -#ifndef __LOG_H__ -#define __LOG_H__ +//#ifndef __LOG_H__ +//#define __LOG_H__ #include #include @@ -9,13 +9,11 @@ inline std::string NowTime(); enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4}; -template -class Log{ +template class Log{ public: Log(); virtual ~Log(); std::ostringstream& Get(TLogLevel level = logINFO); - public: static TLogLevel& ReportingLevel(); static std::string ToString(TLogLevel level); static TLogLevel FromString(const std::string& level); @@ -26,7 +24,80 @@ class Log{ Log& operator =(const Log&); }; -template Log::Log() {} + +class Output2FILE { +public: + static FILE*& Stream(); + static void Output(const std::string& msg); +}; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) +# if defined (BUILDING_FILELOG_DLL) +# define FILELOG_DECLSPEC __declspec (dllexport) +# elif defined (USING_FILELOG_DLL) +# define FILELOG_DECLSPEC __declspec (dllimport) +# else +# define FILELOG_DECLSPEC +# endif // BUILDING_DBSIMPLE_DLL +#else +# define FILELOG_DECLSPEC +#endif // _WIN32 + +class FILELOG_DECLSPEC FILELog : public Log {}; +//typedef Log FILELog; + +#ifndef FILELOG_MAX_LEVEL +#define FILELOG_MAX_LEVEL logDEBUG4 +#endif + +#define FILE_LOG(level) \ + if (level > FILELOG_MAX_LEVEL) ; \ + else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ + else FILELog().Get(level) + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) + +#include + + + +inline std::string NowTime() + +{ + const int MAX_LEN = 200; + char buffer[MAX_LEN]; + if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, + "HH':'mm':'ss", buffer, MAX_LEN) == 0) + return "Error in NowTime()"; + + char result[100] = {0}; + static DWORD first = GetTickCount(); + sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000); + return result; +} + +#else + +#include + +inline std::string NowTime() +{ + char buffer[11]; + time_t t; + time(&t); + tm r = {0}; + strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r)); + struct timeval tv; + gettimeofday(&tv, 0); + char result[100] = {0}; + sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000); + return result; +} + +#endif //WIN32 + + +template Log::Log(){} template std::ostringstream& Log::Get(TLogLevel level) { @@ -54,7 +125,8 @@ template std::string Log::ToString(TLogLevel level) return buffer[level]; } -template TLogLevel Log::FromString(const std::string& level) +template +TLogLevel Log::FromString(const std::string& level) { if (level == "DEBUG4") return logDEBUG4; @@ -76,13 +148,9 @@ template TLogLevel Log::FromString(const std::string& level) return logINFO; } -class Output2FILE { -public: - static FILE*& Stream(); - static void Output(const std::string& msg); -}; -inline FILE*& Output2FILE::Stream() { +inline FILE*& Output2FILE::Stream() +{ static FILE* pStream = stderr; return pStream; } @@ -108,55 +176,6 @@ inline void Output2FILE::Output(const std::string& msg) # define FILELOG_DECLSPEC #endif // _WIN32 -class FILELOG_DECLSPEC FILELog : public Log {}; -//typedef Log FILELog; - -#ifndef FILELOG_MAX_LEVEL -#define FILELOG_MAX_LEVEL logDEBUG4 -#endif - -#define FILE_LOG(level) \ - if (level > FILELOG_MAX_LEVEL) ; \ - else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ - else FILELog().Get(level) - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) - -#include - -inline std::string NowTime() -{ - const int MAX_LEN = 200; - char buffer[MAX_LEN]; - if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, - "HH':'mm':'ss", buffer, MAX_LEN) == 0) - return "Error in NowTime()"; - - char result[100] = {0}; - static DWORD first = GetTickCount(); - sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000); - return result; -} - -#else - -#include - -inline std::string NowTime() -{ - char buffer[11]; - time_t t; - time(&t); - tm r = {0}; - strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r)); - struct timeval tv; - gettimeofday(&tv, 0); - char result[100] = {0}; - sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000); - return result; -} - -#endif //WIN32 -#endif //__LOG_H__ +//#endif //__LOG_H__ diff --git a/slsReceiverSoftware/includes/utilities.h b/slsReceiverSoftware/includes/utilities.h index e55d81598f..78a99bcbca 100644 --- a/slsReceiverSoftware/includes/utilities.h +++ b/slsReceiverSoftware/includes/utilities.h @@ -3,27 +3,11 @@ #include #include using namespace std; +#include "sls_receiver_defs.h" /* uncomment next line to enable debug output */ //#define EIGER_DEBUG -/* macro for debug output http://stackoverflow.com/a/14256296 */ -#ifdef EIGER_DEBUG -#define DEBUG(x) do { std::cerr << x << std::endl; } while (0) -#else -#define DEBUG(x) -#endif -#ifdef VERBOSE -#define VERBOSE_PRINT(x) do { std::cout << "[VERBOSE]" << x << std::endl; } while (0) -#else -#define VERBOSE_PRINT(x) -#endif - - - - - - -inline int read_config_file(string fname, int *tcpip_port_no); +int read_config_file(string fname, int *tcpip_port_no); diff --git a/slsReceiverSoftware/slsReceiver/UDPInterface.cpp b/slsReceiverSoftware/slsReceiver/UDPInterface.cpp index 650166a6e2..a0d7716874 100644 --- a/slsReceiverSoftware/slsReceiver/UDPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/UDPInterface.cpp @@ -34,8 +34,11 @@ UDPInterface * UDPInterface::create(string receiver_type){ cout << "Starting " << receiver_type << endl; return new UDPStandardImplementation(); } - //else if (receiver_type == "REST") - // return new UDPRESTImplementation(); + +#ifdef REST + else if (receiver_type == "REST") + return new UDPRESTImplementation(); +#endif else{ FILE_LOG(logWARNING) << "[ERROR] UDP interface not supported, using standard implementation"; return new UDPBaseImplementation(); diff --git a/slsReceiverSoftware/slsReceiver/UDPInterface.h b/slsReceiverSoftware/slsReceiver/UDPInterface.h index 77cfe3e7e8..5c497167de 100644 --- a/slsReceiverSoftware/slsReceiver/UDPInterface.h +++ b/slsReceiverSoftware/slsReceiver/UDPInterface.h @@ -17,7 +17,7 @@ #include "MySocketTCP.h" #include "utilities.h" - +#include "logger.h" /* void print_not_implemented(string method_name){ diff --git a/slsReceiverSoftware/slsReceiver/main.cpp b/slsReceiverSoftware/slsReceiver/main.cpp index 14fb01d0e4..32adb96be5 100644 --- a/slsReceiverSoftware/slsReceiver/main.cpp +++ b/slsReceiverSoftware/slsReceiver/main.cpp @@ -8,6 +8,7 @@ #include #include "utilities.h" +#include "logger.h" using namespace std; diff --git a/slsReceiverSoftware/slsReceiver/utilities.cpp b/slsReceiverSoftware/slsReceiver/utilities.cpp new file mode 100644 index 0000000000..ae401a5ccd --- /dev/null +++ b/slsReceiverSoftware/slsReceiver/utilities.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include + +#include "utilities.h" + + +using namespace std; + + +int read_config_file(string fname, int *tcpip_port_no){ + + ifstream infile; + string sLine,sargname; + int iline = 0; + int success = slsReceiverDefs::OK; + + infile.open(fname.c_str(), ios_base::in); + if (infile.is_open()) { + while(infile.good()){ + getline(infile,sLine); + iline++; + + //VERBOSE_PRINT(sLine); + + if(sLine.find('#')!=string::npos){ + //VERBOSE_PRINT( "Line is a comment "); + continue; + } + else if(sLine.length()<2){ + //VERBOSE_PRINT("Empty line "); + continue; + } + else{ + istringstream sstr(sLine); + + //parameter name + if(sstr.good()) + sstr >> sargname; + + //tcp port + if(sargname=="rx_tcpport"){ + if(sstr.good()) { + sstr >> sargname; + if(sscanf(sargname.c_str(),"%d",tcpip_port_no)) + cout<<"dataport:"< Date: Wed, 10 Sep 2014 09:19:35 +0200 Subject: [PATCH 029/222] cleaning the project --- slsReceiverSoftware/Makefile | 52 ++++++++---------- slsReceiverSoftware/MySocketTCP/._.DS_Store | Bin 82 -> 0 bytes slsReceiverSoftware/MySocketTCP/Makefile | 23 -------- slsReceiverSoftware/MySocketTCP/MySocketTCP.c | 1 - .../MySocketTCP/MySocketTCP.cpp | 1 - slsReceiverSoftware/MySocketTCP/rec | Bin 14727 -> 0 bytes slsReceiverSoftware/MySocketTCP/send | Bin 14960 -> 0 bytes .../{MySocketTCP => include}/MySocketTCP.h | 0 .../{includes => include}/circularFifo.h | 0 .../{MySocketTCP => include}/genericSocket.h | 0 .../{includes => include}/gitInfoReceiver.h | 0 .../gitInfoReceiverTmp.h | 0 .../{includes => include}/logger.h | 0 .../{includes => include}/receiver_defs.h | 0 .../{includes => include}/sls_receiver_defs.h | 0 .../sls_receiver_funcs.h | 0 .../{includes => include}/utilities.h | 0 .../{slsReceiver => src}/.cproject | 0 .../{slsReceiver => src}/.project | 0 .../{slsReceiver => src}/Makefile | 4 -- .../MySocketTCP.cxx => src/MySocketTCP.cpp} | 0 .../{slsReceiver => src}/RestHelper.h | 0 .../UDPBaseImplementation.cpp | 0 .../UDPBaseImplementation.h | 0 .../{slsReceiver => src}/UDPInterface.cpp | 0 .../{slsReceiver => src}/UDPInterface.h | 0 .../UDPRESTImplementation.cpp | 0 .../UDPRESTImplementation.h | 0 .../UDPStandardImplementation.cpp | 0 .../UDPStandardImplementation.h | 0 .../eigerReceiver/RestHelper.h | 0 .../eigerReceiver/eigerReceiver.cpp | 0 .../eigerReceiver/eigerReceiver.h | 0 .../eigerReceiver/eigerReceiverDummy.cpp | 0 .../eigerReceiver/eigerReceiverTest.cpp | 0 .../{slsReceiver => src}/main.cpp | 0 .../{MySocketTCP => src}/rec.cxx | 0 .../{MySocketTCP => src}/send.cxx | 0 .../{slsReceiver => src}/slsReceiver.cpp | 0 .../{slsReceiver => src}/slsReceiver.h | 0 .../slsReceiverTCPIPInterface.cpp | 0 .../slsReceiverTCPIPInterface.h | 0 .../slsReceiverUDPFunctions.h | 0 .../{slsReceiver => src}/slsReceiverUsers.cpp | 0 .../{slsReceiver => src}/slsReceiverUsers.h | 0 .../{slsReceiver => src}/utilities.cpp | 0 46 files changed, 24 insertions(+), 57 deletions(-) delete mode 100644 slsReceiverSoftware/MySocketTCP/._.DS_Store delete mode 100644 slsReceiverSoftware/MySocketTCP/Makefile delete mode 120000 slsReceiverSoftware/MySocketTCP/MySocketTCP.c delete mode 120000 slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp delete mode 100755 slsReceiverSoftware/MySocketTCP/rec delete mode 100755 slsReceiverSoftware/MySocketTCP/send rename slsReceiverSoftware/{MySocketTCP => include}/MySocketTCP.h (100%) rename slsReceiverSoftware/{includes => include}/circularFifo.h (100%) rename slsReceiverSoftware/{MySocketTCP => include}/genericSocket.h (100%) rename slsReceiverSoftware/{includes => include}/gitInfoReceiver.h (100%) rename slsReceiverSoftware/{includes => include}/gitInfoReceiverTmp.h (100%) rename slsReceiverSoftware/{includes => include}/logger.h (100%) rename slsReceiverSoftware/{includes => include}/receiver_defs.h (100%) rename slsReceiverSoftware/{includes => include}/sls_receiver_defs.h (100%) rename slsReceiverSoftware/{includes => include}/sls_receiver_funcs.h (100%) rename slsReceiverSoftware/{includes => include}/utilities.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/.cproject (100%) rename slsReceiverSoftware/{slsReceiver => src}/.project (100%) rename slsReceiverSoftware/{slsReceiver => src}/Makefile (92%) rename slsReceiverSoftware/{MySocketTCP/MySocketTCP.cxx => src/MySocketTCP.cpp} (100%) rename slsReceiverSoftware/{slsReceiver => src}/RestHelper.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/UDPBaseImplementation.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/UDPBaseImplementation.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/UDPInterface.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/UDPInterface.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/UDPRESTImplementation.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/UDPRESTImplementation.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/UDPStandardImplementation.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/UDPStandardImplementation.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/eigerReceiver/RestHelper.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/eigerReceiver/eigerReceiver.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/eigerReceiver/eigerReceiver.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/eigerReceiver/eigerReceiverDummy.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/eigerReceiver/eigerReceiverTest.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/main.cpp (100%) rename slsReceiverSoftware/{MySocketTCP => src}/rec.cxx (100%) rename slsReceiverSoftware/{MySocketTCP => src}/send.cxx (100%) rename slsReceiverSoftware/{slsReceiver => src}/slsReceiver.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/slsReceiver.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/slsReceiverTCPIPInterface.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/slsReceiverTCPIPInterface.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/slsReceiverUDPFunctions.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/slsReceiverUsers.cpp (100%) rename slsReceiverSoftware/{slsReceiver => src}/slsReceiverUsers.h (100%) rename slsReceiverSoftware/{slsReceiver => src}/utilities.cpp (100%) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index a9f9f57dc9..3b3f6c526c 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -4,6 +4,8 @@ include ../Makefile.include DESTDIR ?= ../bin LIBDIR ?= $(DESTDIR) DOCDIR ?= docs +SRCDIR = src +PROGS = $(DESTDIR)/slsReceiver CFLAGS= -g -DC_ONLY -fPIC @@ -11,53 +13,34 @@ CFLAGS= -g -DC_ONLY -fPIC DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS -INCLUDES?= -I. -Iincludes -IMySocketTCP -IslsReceiver -IslsDetectorCalibration -I$(ASM) +INCLUDES?= -Iinclude -IMySocketTCP -I../slsDetectorCalibration -I$(ASM) -#-IslsReceiverInterface +#-I$(SRCDIR)Interface -SRC_CLNT = MySocketTCP/MySocketTCP.cpp slsReceiver/UDPInterface.cpp slsReceiver/UDPBaseImplementation.cpp slsReceiver/UDPStandardImplementation.cpp slsReceiver/slsReceiverTCPIPInterface.cpp slsReceiver/slsReceiver.cpp slsReceiver/slsReceiverUsers.cpp slsReceiver/utilities.cpp -#slsReceiverInterface/receiverInterface.cpp -#slsReceiver/slsReceiverUDPFunctions.cpp -#slsReceiver/utilities.cpp includes/logger.h -#ifeq ($(REST),yes) -# SRC_CLNT += slsReceiver/UDPRESTImplementation.cpp -# INCLUDES += $(RESTINCLUDE) -#endif +SRC_CLNT = $(SRCDIR)/MySocketTCP.cpp $(SRCDIR)/UDPInterface.cpp $(SRCDIR)/UDPBaseImplementation.cpp $(SRCDIR)/UDPStandardImplementation.cpp $(SRCDIR)/slsReceiverTCPIPInterface.cpp $(SRCDIR)/slsReceiver.cpp $(SRCDIR)/slsReceiverUsers.cpp $(SRCDIR)/utilities.cpp +MAIN_SRC = $(SRCDIR)/main.cpp OBJS=$(SRC_CLNT:.cpp=.o) -#OBJS = $(OBJS1:.h=.o) -#OBJS += slsReceiver/logger.o -#OBJS += slsReceiver/eigerReceiver.o - .PHONY: all intdoc package eigerReceiver clean -all: package $(SRC_CLNT) +all: lib $(SRC_CLNT) receiver intdoc: $(SRC_H) $(SRC_CLNT) doxygen doxy.config %.o : %.cpp Makefile ifeq ($(ROOTSLS),yes) - echo "with root" $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) else - echo "without root" - echo $(REST) - echo $(INCLUDES) $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) endif -# LEO: not satisfied by eigerReceiver -package: $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a +lib: $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a -#slsReceiver/logger.o: -# $(CXX) -o $@ -c includes/logger.h $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) +receiver: $(DESTDIR)/slsReceiver -#eigerReceiver: -# echo "src client:" $(SRC_CLNT) -# cd slsReceiver && make eigerReceiver $(DESTDIR)/libSlsReceiver.so: $(OBJS) $(CXX) -shared -Wl,-soname,libSlsReceiver.so -o libSlsReceiver.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64 -lpthread @@ -68,10 +51,23 @@ $(DESTDIR)/libSlsReceiver.a: $(OBJS) ar rcs libSlsReceiver.a $(OBJS) mv libSlsReceiver.a $(DESTDIR) + +$(DESTDIR)/slsReceiver: lib + $(CXX) -o $@ $(MAIN_SRC) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC +#$(EIGERFLAGS) + + +# Stand-alone Mysocket tests +mysocket_test: + g++ -c $(SRCDIR)/MySocketTCP.cpp -I include + g++ -o rec MySocketTCP.o $(SRCDIR)/rec.cxx -I include + g++ -o send MySocketTCP.o $(SRCDIR)/send.cxx -I include + + clean: - echo rm -rf $(OBJS) rm -rf $(OBJS) - cd slsReceiver && make clean + rm $(PROGS) + rm $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so cd #------------------------------------------------------------------------------- diff --git a/slsReceiverSoftware/MySocketTCP/._.DS_Store b/slsReceiverSoftware/MySocketTCP/._.DS_Store deleted file mode 100644 index c9474ea62235481b7d27ae5a878d2b4070bc6e05..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 82 jcmZQz6=P>$V!#9-F-{;h0%8Rq2JwS{7!DlZEK~*nFE;@e diff --git a/slsReceiverSoftware/MySocketTCP/Makefile b/slsReceiverSoftware/MySocketTCP/Makefile deleted file mode 100644 index 69634f361b..0000000000 --- a/slsReceiverSoftware/MySocketTCP/Makefile +++ /dev/null @@ -1,23 +0,0 @@ - -TOBECLEANED = MySocketTCP.o - -PROGRAMS = rec send - -all: $(PROGRAMS) - -clean: - @rm -f $(TOBECLEANED) $(PROGRAMS) - -rec: MySocketTCP.o rec.cxx - g++ -o $@ $^ - @echo "$@ done" - -send: MySocketTCP.o send.cxx - g++ -o $@ $^ - @echo "$@ done" - -MySocketTCP.o: MySocketTCP.cxx MySocketTCP.h - g++ -c $< - @echo "$@ done" - - diff --git a/slsReceiverSoftware/MySocketTCP/MySocketTCP.c b/slsReceiverSoftware/MySocketTCP/MySocketTCP.c deleted file mode 120000 index a995312db4..0000000000 --- a/slsReceiverSoftware/MySocketTCP/MySocketTCP.c +++ /dev/null @@ -1 +0,0 @@ -MySocketTCP.cxx \ No newline at end of file diff --git a/slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp b/slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp deleted file mode 120000 index a995312db4..0000000000 --- a/slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp +++ /dev/null @@ -1 +0,0 @@ -MySocketTCP.cxx \ No newline at end of file diff --git a/slsReceiverSoftware/MySocketTCP/rec b/slsReceiverSoftware/MySocketTCP/rec deleted file mode 100755 index b652bb8f4795994f4cbe47c47317b9aff8e3a018..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14727 zcmeHOeRNyJl^@x1P+F5XA2Pli-llheo?0Q z{ygrmv6ibSkpxylREWZkac*e3JRPUe}7$TnGo z2(x58FaBWJ#l$c}T!gr|yR`1U8_7d%#4*WYmaw~(9@o@8bO=9!PU!@<1{ z{v;^Fn@A`BQHS4(Yhv1`gC7?xR|h{X{>uTEf>Qop9efCtAb#7?cZb7&z`@r!_%#PV z0ZRG5bMPF8e*%V z-w}r&bFg;%c@9oH{0BiP|J^)&Ne7?h$iL{|FFW!daWL!2{P!aEJnQw{4?0hrFE)e! z%ICa3`q?}&M_dhBi*eQhN_iVmd~-&AKIEIgpMvv{FW`3xyCe9a57FsX3e)WBjz!Ic z9f;eeDa;#s&1S1BoUpBUT_li5SP5Z%EV}hJ{I}TERV|G%FsLSCK@+nJEpn zLgfmxXV|08uB$S7k=_w$BH7rI$F5gwWkS=M=9XBCX|M(Q`ph0H zo`^*Qk+9uw_Exf$x>W<=sw)^Y6GTRFUM?26)iDb7$v7pnA4UK5Tj&RgWCaeyT zhy`!AY=Nc-_VkO89g9Zfe?kOf(Wn))MNiUBAU_&93KN2T0W)A*ePOhbiB^fm%t$O4 zu*0#aXh(qpO$x1+O~tVuTXb1=2rb>-9}U2cU?i5XL?9Tnz%osm<#cIxARHB2<6+wp z*VomVS5{Pty3Lzct!^-@Dy|gQuWwilh~#Q@Z7#3KrsKL24pW3*v7Fa90~JfG(wNSx zlhG`2JW`tTu?N2@_#x*GKVs98{`YcLdk1L@9%$et`7H6rU%wsMN<=ZnFw^X15BXU3 z9AE~@Z*=q#CoT$Odi0759Qm?v_-xv}#E~Dv{5}gBIgUy=VPbrgVB(rW`dKU(>1RRK zONw#gBgFtKB}Kk6QViGyq_AWmDN0;K`X1DY6g4U*Efr!ZDJ-~*6cbk^>0I2)NKv60 zQcM`vkz!ERlH%r8Pr3m29MW@zSWkK$+KcpkLbQ@D6k;>!`9j=6`hFp{kotw_AiY3{ z5b1?Nw55NU8uMj5s9NS;{=J66UOFJAS4^Ph(~BqZkJ^jr#cYWXFHansMp(=i36Xc= zu*7Vc5WC{Ueu>#aAy^_#?3I`;74j4BmY6LTT1q@DFLVWi z6A~7)Cqe_n$0TNtgzhCiEHQf~G)%l-V)jtzG2*=vv!_D4iFZrP9t%B1JS;JLF0_|; zKw|b_XdiKp#O%q?e&Q_>vqwWO5;sZAo(&x)u9cWQ9D0Sg61eL1kEef;IzHai+8ipw zy&>es-;J9>|MFR{FY|Q>Obidh7g|zd-VE}Hn|B#hj znmJTL1)kJF@6ER!*l8~jJD=yW!12pHKFAL4x977R1TJQec*~hKeHeyF-(8qCrqXSb zsqIsqWYv!Clhe~eB$q<$5$Mf)`H$1nBlYFJqo^$??}!4tXYK>|efEK6KEVoXrakl`B|SO}Ga`}=PjF*5X;(QcW#2&vZ^W!vXuQQ85wtu`Ce90dVRSs-CFKVd&@KHP#~&?dWpXIL&nrHqYVEZVkh$ot{dP5zkI`ejea zlx7)YvL$+y`QmX!Gs(-U4I+ zr(}Yz@IqDwmiRD8Z;FKc@^ja&Rp`}sH8|` zyvnPsx%a%v3bjoRc^@s?g{kHkx?vNvWY$9b#E;l~-tsULu42M>RYHsjOPKJqO4!DP zbD6;B0%S=s!OMjER6?2wZ=v|nZD0=*{gNmO^jV^x5^Vwc0?|uE%|QP^^c|vlpl67_ zMzj*>Iie?sI0wE!^l73CfJTT?M5RDKB1!_GLvFf+)pfeY1zqX}G=cZ7Ktc_&!`DCx^DgWyT&U zBQ3gHPEG~1(wE$3c%)Kw*F^maNo`Y`$n$ET*k9bK1n)$}@im5#~J(Jh};Y*P&XU^uo^cFg;SH zlyWKpr)&uKVqXa#u+t;yBU5jEY3{d;u))Br}dPj7aIM`*gWpZZVzOcrYAcO>U`p# zmBF1O1N5dM-Vf*!nFYE*(!+Eo_|X*o=yF{i+|Ti&l6RRHZ$lQfevlL6zqx#VZk|Ok z;GEVQJs(ijh?et#oL1cP=FCd?ud6?9g=Nx@&Y(Z$LDtus=N_r( zn^Jfu)?9daoc_cVpZjjyF*a}j3j$-T38Ztxcysqz@aJ;)Z)O7W>A~UaIP(~9%6o)F zbf&&Aj^#Eh?u0^yBYL;-wEZJoZRBIc=AwM!nOAhl*2^)5(dH z+>)T2Yft1dSe6l}@lDtX!HPrfGlB>s9*@QS;i!LR|JC2pXg1evYHiqHH2O~?)3UKX zPv#o`*03Fds(7yz_p2@2%lyu+Ft&UBajR2qAzNEx$w)^#ZezFmtw0y|ajo`1N2jnT z9B7ZlZEQ4Koq=S;7FIZF$NAqIhzP5@GaRvm6?I5V?ivfLv1wytYfD>GlQ1?mu5Me? zLb}1&K+@7IjHc$s)<%(x-X4u@jry?*9gB;)K-3?N+5R9lpl!>q_O<;p$!a&-Z^yDM zw8n#8--CJahYzT<=Rqxp_ZufIUsmIJkh>i5qC8!i|JOhh?_%4Icj2E&9j-l%j)v3l zsQc$m8-Enn23{|Oqg~hdo8qzdh}8|3#%rFQxW!aIUngAS7w^gTE#Et2dv$iR6|};= zR)_x@;kmH*+85Ey7%!p&+anp!uYz*B<9ncf&?BJNfkrUQ`OeCV*}?|x038N>67*@% zW1xHoHi2<>9P~NNF<3&0`B=s*0<8zF0sS0kE9ewx59lJSbB95%!;*h5=*yTLUk1Ge z4@O=L-X}rJL7xMy2mKLf2dIAv<$_j%z6i=XFnI205}s|o68W;M)a$($wvgvXY{ibE z0V-C_@eLNOKATG@^7sz%bKqfX{v_UJBylH_J3;yRY$P25@6iIhVWizM3-tYDOZ2{hKq&;*B9ws?)7`z3b`F1Ws+VP!U-yyVXKCcG6uMT^CtY<#2 z6}+NPdwt6b@Or?j2CuCE?|$&^E0B+`Y@Pyd47`g#v*j6gd+$LXl20EheYh~6eU$Z2I=Md66Sf(FwJyu=x4Xlr5?7}7awTKUaPyZ;y z--2|m+UO(s{L7FwfXF@kjj+#qbdT3pU+NLFy`D9&K)d4VySynhfslR%>bawtrg|=P z`7mvXU~NOc&9)sbnO=jq1-vk5mRFZ5Q7y~eSkIhg$Y_+jSuAdsw?(-_OTTB`n2p;n zqzr6c9WTWNuleqel<(}YvJsEn`CC7$WPL0pNr25}Q&Ct@$6EEjKbukkO%5s_v7YP_#q?q6P6SyOpcWwn24 zGiKNEdH!GenehFES`V?irf~2I0^}Lhl7xgK{5U+WNAus zdjitISa-J-<*nz8170D^am%qL&tYNway;q4G0pG+L~Q@@wyn-ff#Jus4svb-s6xc; znlAzb$9xEK)wtGtQpRf$IqoUPxnLLM$^bY=;8MzP+qe#qW0`WCJLG+xzzLLPSck}Q zPZr1gQ7BrCYh5nW88;(xp5Qg-3O^>J0bH|OmZRmna6KE5a-3^+Lr&gDfEg&qf!c$p zRxqe*JR?dB#8y`bs$~6TrgD#hyr{(rSZZG5x>qH-I@~ z07lesVsrxAj$sf{>*HL!4`&B>PtZY^JA?$vvA#cn+)pUS262Lxdl*>D$#ZcyWcIQa z0@ZSRTyoEU!Rvb-XBhki^!=ktj<>&~7dvN|9GxtSfp2MeO%?LIALMi$k(4d>Ag;9> zUsQ`rR6kLMLEHBOTx&VLkoG}N^W1WW0oZ3OSDqt;+%a6!Ul^E&e(;}&S|87%j1|yF z*`K@Qc#j*0+%}}?KpDngBWisSyhDt9ps;VJ7$@*mxPu(qtONUpW5caaV8M6~8BuI3AcRd4CFK(XvmA;-VsD}y-B6_!M06 zgFydAD0XIS`mw@XF)4plSgow+mkQ&+5d!^BVKo!c&lKiNr~FA_97J-3VsU}=gD*L2 zl_IS8TvHGH_qWrWW3;^&k^J|g7Jn^ zKT$MaSb4Y?Sog1|=zW6EU2gf^d6;Kn-TZ@j_@}^nP3$Q;R~!S@{^G}-aTJ(=U`AiW?t|ZZKMAaZ z9~a-q!`}zyeU1LbGqv1D(9eU+{|iU{Qt)Zd+rYeE;u835@s7jSXPo`cq^8d#R{?YW zy&v*C!@JhuUnlbm@iAci+{^O%9KJpS{iuUEGqC)x0PAOH${%s~yBz*I4%X$r7ZuZc z1C;jz>t|u&6|6XdJ~Mp>u=|X08d&#d8T#`xj=b)_ryQ*7^Bl0=8=(Hzf%X0aaS=Nb z{;S*Ld|)2pq7Czk=7=TaBV2;W`qlvR2pZGo6`g};Q6YH5EiCz^qRo-lQ(V1_z%&8uMGgY3<)drD7Yf-iM%lJAk=PrH=X7FciT+B;q#)ds`Vh{fpZ8Ab9jN-EmW-y+Xzx7IaP z1pE4gdHwpv)vMNyGuzQVZhGX*S&ou2|r&)<3-NF3QQA?<6`$&E4nSXT*8%+&Q}*OeCevLKmCY3sqG(|GpL*);#@gG|7(v za=NLivcqx7^@o3;d)YuMYC*y}(xn{0Jde zR35*dsb?kh@q-AoWUie08X#9N*P5CZ^i@5&!)WSdt?~}~yR-6}gM>RFzh=u?MPvHyb4K5~mUbHBR4G%@3<>eZUt zIQ8<%opMr})Hts>*v6-9mYm8s6N2-FOP+aVM%$3W%3vMjB;$q6>1uIq9RK+FI9_H#y($tUs8btl_^5hG?LnEib2eRuL^ zIxSVt+2bF3=iK?e&;5Syz2E!2-+SME_uaR{w|=e5PMUvY(^QF7x5>T3c<+yqFC`y z0H64p+r!w03{MsaSugpx6yxBJgU5Ihn2~z14#suJvkrALdVv`=ul`q7+Y9dz;)Tz< zJ&ZpDk5Th)0Uz*;pv%9yGt_!@XWLbsp>VvXG!`jcuJS@P*|r-uHp{%!lX+$#(k2TL z*><*b@%xGw6aO9JBE-wOimIQy`IkeB-yEMce{WHBZ|z-AAvr62fteAQXCC5C8*j1k z$3YohLpu3;YD|4vSMaT{M?%Rgu1Cv5o-+L-NR{@sWz2i>0gLFbBhix%*E zKI`_-&*qBR;yTbOjI%~i%3FwOhx|Oq*MmO^=OJIf?_yS4;EF5gbSs5nbaX|+M$Ga@ zEyEDTOz(*-v?|PSTW4*c(JC(w1pQINiuyxVtTy2D zH6ZPpR(~uMFd{K4YWllsn~bJ1!`HYHg)(a(61Q-*u`$va^M&j*Ga8jwow3^UD>TrA zB3BsoHwR={R%Iv>Gf=NtQ5z0f)#bh|NN?+`C)wDT!>&&v;iCn5dW>!} z8jFPeogu5&*iuF-btwbksv{6EVnpS_Xbx`;h1+1GSiH-mSirVpZ5@o*7782jnAs*` zk-%N1C18p`cdrOqk#MK{kBLAe95w@%=#E=4W1upfE^IwLVt_yYkGEW@B$c9(YfLt(Ks8nR4r zV|BH0O=+2^ZfRM)rq(Dgy++))zIF{Dk}K4;vAi^sj_WcwOaXo~0GO5`{y#DvN5QHY7_6w)t1IcZYJ zj*?=WjFDo1jgunZ1StmWBq=lz$bSKABz>C@9#XWZh_nbglR|^}q?ouCkj}x}O^OD2 zNikuRkYZ3SCB@C{O49kT0qHw&?<2iPh)U9T32_7I0wJnM-z`K9Degh*NWDU=C%qW< zCA~z5=H#yuqn@-2O-t|QUjmgpe^^YdcnK|;y6hzWX}_tvcY=dDv4>~U<+}X#I$s9GqG1Ceil(A6td#RS;^q?fJulGT5?x z@9+5r93=k1L!($AU6sb)GZO^^EmQj~q+fS<%c6mUOITiF$n`}gP0jD8kj>tjK3d2E zT!|y@+ipKRU@Z{?Pjgvd`{n*I$o3Ce^JoWwi&?|&5~fWZgCf#*7bJa?$>xc~_DNT~ zeCPIwsVO1iOCh!m<))u_b82e1ro^)iw?k0g5e0Z(yAQlu!PBL9zQufUp^$z8EzYFt zf}WJZvc{#uzHye5@_ABy3s7YLQ16|?zBIk&beBwBh}7$S#oK3RP|`PgdS=R344U$d zCVdmB4HK#6qLgpk_5Dmi$@L|kWK)Sd=`Km%j0({-v`h5NOZg_3`HJ!H@{K397mFQ# zkBmuQI^|1iO_yd$fjYCaI$MT)lhpOJKcmUH^%_rY7?*lYo<*+!90KYmwoeEPdQC{Z zCS251={1?Hm&c)3&&?8yV*W&5z9Yk7dw+m(PrpYdje*akLr6lxa32$BT?uG$g69v* z-eCC@eo*mKQn-JpXKq$eUAm~V{B{7LJ+0DCJa(+qrk8ey(J(FIvYsji#avwd`UDAS4oUQ|l zX^@nLdGL=4b5X~(KL&ovSA=dkk9u*_$g1}fnR>5b9gjQeeG&D*8MI3-$fI4F~^2q0Kf010}0CRSI5^c|PQ~%JM2O^Yc_U!!rd}INqaGb92 zOhyKpcrZxh0J#a;Bsq4HgRDTx@Iu;f&aM&^#r8bsXwL;X4d?()U;002q)4RQ%B#&e z_rA;qHBY46dk#E`spcfQ;dPXfUI+1!f2H}{C9}XuU(1B=sDwF8Si*!SRl-6hypsuh zEN4AeoCASwb16UBjGx#=M`!tTu2yMJiMWH{&zN3e$@8PchZn z_NRwC^7K~H@Y_&6WTgW?09mGKhkX^88RXc&h3dl7FCV$P;>p6c^Lm&BM0WAg1t;83H_ z+m{z&hUSb8`*84~c{bxXj4Dg>9F--&HjZ-hWJp3cm4Q_}3m3`Cp*3-+v0utajqZ_? zQ=U@kOHMUhvQTx`MEmmONM-5q{wzH>&!+m+$c@vEs=-Cn_~qACcS^Rj;Dj#3=3~MerVs$$Z|!o2KOaIo<)Gj5vILPL4(q;4JH%em9_M z5jE!nIkmX=wds}c-&TLz4$Y(=okxGng{-qbJ_>x+{@68Lu(Llt_uDi4_O1Hkr^s@a z{@4MQQ=^xG&!<2BFy`nFjE%g{J$-!c`3fXaL+*3Wm-)2kca(Cj=N?(mK`A_dH5VQp zr#?E#=e}EZj&42z4;eUgJ@oG9f1=oMM zjx1(QmS=%edt^Op+=(G~O7ONb(7%LtDtIX6+lPIx?z>>vH&%aGuCq!oj?$fAB>RU@ z7lzcUyhq!akUb^SnZ1F_pFNaHHjmR@$8d`p=s(T`3gRIPQWn+`$;0fhVTY>U`VCS) zqSm5+dNsR4XRBs-_F^(QqqvXdE$%KyabL|T?t9=-y8~$18O2?hx44Cl;x^|L*KHT~ zC4Zjc{uAq~GaLIO6rmeCH>bG8c5y#Lr=FqR19^-4xTCo5zmjdcAA?83_a8woB)-Fc z5idJ^Q?macE>oYA|EkZh1~`b^NtGt~>@NX@QhS(@tAyhmT(U6ocCj|;gV0u_V_Em6W?5@u5wP={t~V=iv*nv6dKJnEoD~`vwwkVq+xf8&em{d}GgS zA1g>Tk73i~it?%C(E<5>1#6+iu#0|}wN{+EC~?$%-S)Bg%ZVckZ{zA9wXlRbaGZVn zBz8KmA+ul7i7BfnaoRm~EHxuBF%=(A$So7fIreO<1@L|L_pR8e;VO&!pbWlfG!pfO z!rtlqVQ*ud(NMjqsdj^}&U+4-#*H;OGON5>Lsk$)MYotyui8?+(rfQpV>{X#HQVJD zx4AVE?`&(uZT2p&>F?k^v)SrzYZoSk{jHIxWwr^k-5>9?gc%B3QT}i7cM7wsJ=AFm zGi;NH+|?FlUH!(orpD&_dg0qxx2Ab*Bk2a;29m}G;j3?`YpN6R@Ll1^*02}5Ewyx-Vqxw0D1h1^w$ zi*m}+{J#Yndkfumz6Jk$+Hn0j%BVdDk7fVNw(*B>?ZfMjP`G22w>}za?KHdK(s&Kk z9W|Ni4JFm&~~SIZ%u_(RUhK37|(oxux?nP%r3f zpf`Z-##F)ga$d|o7HA*nAn12Np9Gx*<$Jzj%w4BIIcss~mSR1!5OgzWCFoP2O`r>~ zgzE;a#QJd%v;}MW1E6U<-uw`>2X_TGCV=mPmVh1ytpWXS&^FMQ-ax&eqoB`$vJDKb zyX%E(o2O8|5G-=LcS9HQyogQMHT8jt)w4bQ1#2$kGLbyKC;bd~c>Qn&uLVimZRKuP zZaxc1N5R{Zhc}3{kEGn5Pv_xrgJm4N&3Sn2kEZ+Go)6^VokH5fXW?O@6vx1u51Omz zLZqDsg9^U=n-IpgHUQ3BDfj0`? zBG62IzI)vFq7TWZ4;4LdjdD$8=m*)?|s z4??`?D%@2l-gL>ktJ;aC@3Vc(ighVoB&a|W>v%aXc+Gd5q%(HV}SEyodmjrcm^%-wF! zMTkofS0b)O+=SSUxCQYZ#7`mq1L9MNM-h)B{u=Rh#F^OMz6fy%;!4D|h?@}G5w{@9 zdhy13m3JwQ!YuPv;Jx&6@A9&;%Cc+AD!fY@%r@^jzopWzT2Z!4@cs7xOXt|6G}hZ? z`CCOPP9i88)K}`}DoU|>GD~qF;3~`CAxb;K@zS6_78IpzyBMDAm zfEP78DX%WNvEC~U;W&mU#fb*|w*!C`Y4cltQECQ__9*VjMz9SzHA0a%WnuR41cL!h zu|6yfSdnN93Mg`C0OF{`-xUf#I)Z}nS1M~$CAY>P9f)*wnPJ|3&O6{$xg56~Yx2Aq z#xKW{4jj`A??uEjq+E5&b75e3fpw7c8$dZCZq47bOt5jmDA$GL;|cFq|(P?q6lM2>s1IObnML2GcW>t#A)3nJ$UUURPS zVlwK(HS1+PTD}9<))qALficC~<-lqaA2FhJHj{9_Qi~bU5z| zI_P>+NT3|;VnNP=+#NKC9kkpdz*67Z;=q*JmvkfLyot= zp-Y9(_W>5mx)}I2iq|Yco@<1hZX=R1^&Y{smg5WgG~_Z9xkK&;4mrMfAA_9M9jwgt zF+`RDK=`z5Qa+Kv}f|lbw?gZqvQNRwAVf-&d zE!Tuir>2rK%VU;T5LrL<<148a$X&^dcF=8q4cL(^D7VIupfBk{EK7&aTqeXD8h~m! z(gH{Nx+`!`hOhE$CC4_~!2aRbaF&%#b}QJSeONHvL{3ps}Sga3agojex@*II^|CaV_(P-W{8WWA3Sciw*V_X$JB$q|Lqj#7_F}hr!R5l zCZn$lcbH0Gt*;9!JRdO6(Xi)SIP2L6Do@bZxE1u6qrM*CGOSNQ;D=|{zYFQ7YVPgp?x0#*5ipd0Q@wb56f)+E@1s!Oa2#ub@1ZiYdM(DxV*2?zj$`|N5J}-kokXM z%U=#Y^?4nb_e)#?UnnMRzCO#n*q+q%+3V%NoPY0!JkKiE+WZ@2ew;f4*3Z7Iuh-`5 zv)-SwF=qzW|Bt}>Ihyh>+WbdtKF>5W==zJ$FugxO`NhEcd6;-58;+pQhJOs$d6xP< z=C{XxG5Yhn-2_yVxre;|JpSnoFwyRit+dmh9~fc0Jtu@86`#;Y#xCN3HfI4`n&L14Wn zMEM77zCJ7ec^m8Y9kem;Ow9i*a24i1&Wpqsg5lJEKCttw`wC`6&}Zv6+IR$M%-;^Y zO#631k=PEb_adm@CxE$5Wf}9Z@hG@c=r}Jg0#Pew#oOCUaT?vIZmMfA*4H*R@ff{P zlZ9@o&an72V}#mzN>^Na-8DE3-qqb{Vxyc8$IFejh|$p*Y4vv+^0CM8$9sf&TxyGV zb@l3cd>d?6F$WxZG1U%0lW;f2CoBBJ%0a zFswkkQHE3N;kMlB-1U5OY+ZWE=^$OwFwuS8u4T7JQ7%Xpwyizp6@}m6vDY?Uy0Wq|Ap6cA|Zz z-g&TpTAU~B?L+#3SX}BXbhSC%P+pFM{_C)d&13$)dim8uRzH=OHJVmasLQO2Tl}oT z;htyvoTI(l2yW%~5m^OQFZc2L41PP2(+2tYp67E4er=I0D!((BZf6WVW38 z>>*n)TboMm#n+%aeDzz{s+=zxoLTvCMa-Fy+p^^=bYZK*Z8w`{ceQ#cgpCYUdj2m( zvQ_5y7w4)(e_N7m({gFkM(Z#5z9qYQBm46b%oEeDs@~B#l~ZrQoGEA6q_V*bn4v8u zZG2XZ6ye+SPQZrzY8%^n8v)`FTs0aE@bMYj>BN zkMJc@cFpq3mvdz=U#@$E-1PLuz-*%2{4k z6N=eW2HPMfA^STh{Si`jn{qp=e1)TqOe^>Sk+b2`FMpk>^3x+{!e9O!SB{b Date: Wed, 10 Sep 2014 09:20:49 +0200 Subject: [PATCH 030/222] update gitignore --- slsReceiverSoftware/.gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/.gitignore b/slsReceiverSoftware/.gitignore index ccb33f18f2..b7e550b019 100644 --- a/slsReceiverSoftware/.gitignore +++ b/slsReceiverSoftware/.gitignore @@ -1,2 +1,6 @@ +*~ *.o -slsDetectorCalibration +GPATH +GRTAGS +GSYMS +GTAGS From 59fc6fbaf8ce255eb7fa3fef9166197300909f25 Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Wed, 10 Sep 2014 09:39:11 +0200 Subject: [PATCH 031/222] moved .h into include. Second round of cleaning --- slsReceiverSoftware/.gitignore | 1 + slsReceiverSoftware/Makefile | 38 ++- .../{src => include}/RestHelper.h | 0 .../{src => include}/UDPBaseImplementation.h | 0 .../{src => include}/UDPInterface.h | 0 .../{src => include}/UDPRESTImplementation.h | 0 .../UDPStandardImplementation.h | 0 .../{src => include}/slsReceiver.h | 0 .../slsReceiverTCPIPInterface.h | 0 .../slsReceiverUDPFunctions.h | 0 .../{src => include}/slsReceiverUsers.h | 0 slsReceiverSoftware/src/Makefile | 66 ----- .../src/eigerReceiver/RestHelper.h | 195 -------------- .../src/eigerReceiver/eigerReceiver.cpp | 254 ------------------ .../src/eigerReceiver/eigerReceiver.h | 211 --------------- .../src/eigerReceiver/eigerReceiverDummy.cpp | 99 ------- .../src/eigerReceiver/eigerReceiverTest.cpp | 97 ------- slsReceiverSoftware/{src => test}/rec.cxx | 0 slsReceiverSoftware/{src => test}/send.cxx | 0 19 files changed, 25 insertions(+), 936 deletions(-) rename slsReceiverSoftware/{src => include}/RestHelper.h (100%) rename slsReceiverSoftware/{src => include}/UDPBaseImplementation.h (100%) rename slsReceiverSoftware/{src => include}/UDPInterface.h (100%) rename slsReceiverSoftware/{src => include}/UDPRESTImplementation.h (100%) rename slsReceiverSoftware/{src => include}/UDPStandardImplementation.h (100%) rename slsReceiverSoftware/{src => include}/slsReceiver.h (100%) rename slsReceiverSoftware/{src => include}/slsReceiverTCPIPInterface.h (100%) rename slsReceiverSoftware/{src => include}/slsReceiverUDPFunctions.h (100%) rename slsReceiverSoftware/{src => include}/slsReceiverUsers.h (100%) delete mode 100644 slsReceiverSoftware/src/Makefile delete mode 100644 slsReceiverSoftware/src/eigerReceiver/RestHelper.h delete mode 100644 slsReceiverSoftware/src/eigerReceiver/eigerReceiver.cpp delete mode 100644 slsReceiverSoftware/src/eigerReceiver/eigerReceiver.h delete mode 100644 slsReceiverSoftware/src/eigerReceiver/eigerReceiverDummy.cpp delete mode 100644 slsReceiverSoftware/src/eigerReceiver/eigerReceiverTest.cpp rename slsReceiverSoftware/{src => test}/rec.cxx (100%) rename slsReceiverSoftware/{src => test}/send.cxx (100%) diff --git a/slsReceiverSoftware/.gitignore b/slsReceiverSoftware/.gitignore index b7e550b019..038cff97ea 100644 --- a/slsReceiverSoftware/.gitignore +++ b/slsReceiverSoftware/.gitignore @@ -1,5 +1,6 @@ *~ *.o +build GPATH GRTAGS GSYMS diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 3b3f6c526c..338cc9d9bc 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -5,6 +5,8 @@ DESTDIR ?= ../bin LIBDIR ?= $(DESTDIR) DOCDIR ?= docs SRCDIR = src +TESTDIR = test +BUILDDIR = build PROGS = $(DESTDIR)/slsReceiver @@ -13,24 +15,24 @@ CFLAGS= -g -DC_ONLY -fPIC DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS -INCLUDES?= -Iinclude -IMySocketTCP -I../slsDetectorCalibration -I$(ASM) +INCLUDES?= -Iinclude -I../slsDetectorCalibration -I$(ASM) #-I$(SRCDIR)Interface -SRC_CLNT = $(SRCDIR)/MySocketTCP.cpp $(SRCDIR)/UDPInterface.cpp $(SRCDIR)/UDPBaseImplementation.cpp $(SRCDIR)/UDPStandardImplementation.cpp $(SRCDIR)/slsReceiverTCPIPInterface.cpp $(SRCDIR)/slsReceiver.cpp $(SRCDIR)/slsReceiverUsers.cpp $(SRCDIR)/utilities.cpp -MAIN_SRC = $(SRCDIR)/main.cpp +SRC_CLNT = MySocketTCP.cpp UDPInterface.cpp UDPBaseImplementation.cpp UDPStandardImplementation.cpp slsReceiverTCPIPInterface.cpp slsReceiver.cpp slsReceiverUsers.cpp utilities.cpp +MAIN_SRC = main.cpp -OBJS=$(SRC_CLNT:.cpp=.o) +OBJS=$(SRC_CLNT:%.cpp=$(BUILDDIR)/%.o) .PHONY: all intdoc package eigerReceiver clean -all: lib $(SRC_CLNT) receiver +all: lib receiver intdoc: $(SRC_H) $(SRC_CLNT) doxygen doxy.config -%.o : %.cpp Makefile +$(BUILDDIR)/%.o : $(SRCDIR)/%.cpp Makefile ifeq ($(ROOTSLS),yes) $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) else @@ -53,22 +55,30 @@ $(DESTDIR)/libSlsReceiver.a: $(OBJS) $(DESTDIR)/slsReceiver: lib - $(CXX) -o $@ $(MAIN_SRC) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC + $(CXX) -o $@ $(SRCDIR)/$(MAIN_SRC) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC #$(EIGERFLAGS) # Stand-alone Mysocket tests mysocket_test: - g++ -c $(SRCDIR)/MySocketTCP.cpp -I include - g++ -o rec MySocketTCP.o $(SRCDIR)/rec.cxx -I include - g++ -o send MySocketTCP.o $(SRCDIR)/send.cxx -I include + g++ -o $(TESTDIR)/MySocketTCP.o -c $(SRCDIR)/MySocketTCP.cpp -I include + g++ -o $(TESTDIR)/rec $(TESTDIR)/MySocketTCP.o $(TESTDIR)/rec.cxx -I include + g++ -o $(TESTDIR)/send $(TESTDIR)/MySocketTCP.o $(TESTDIR)/send.cxx -I include -clean: - rm -rf $(OBJS) +clean: buildclean + rm $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so rm $(PROGS) - rm $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so - cd + ifeq (,$(wildcard $(TESTDIR/rec))) + make testclean + endif + +buildclean: + rm -rf $(OBJS) + +testclean: + cd $(TESTDIR) && rm *.o rec send + #------------------------------------------------------------------------------- diff --git a/slsReceiverSoftware/src/RestHelper.h b/slsReceiverSoftware/include/RestHelper.h similarity index 100% rename from slsReceiverSoftware/src/RestHelper.h rename to slsReceiverSoftware/include/RestHelper.h diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h similarity index 100% rename from slsReceiverSoftware/src/UDPBaseImplementation.h rename to slsReceiverSoftware/include/UDPBaseImplementation.h diff --git a/slsReceiverSoftware/src/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h similarity index 100% rename from slsReceiverSoftware/src/UDPInterface.h rename to slsReceiverSoftware/include/UDPInterface.h diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h similarity index 100% rename from slsReceiverSoftware/src/UDPRESTImplementation.h rename to slsReceiverSoftware/include/UDPRESTImplementation.h diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h similarity index 100% rename from slsReceiverSoftware/src/UDPStandardImplementation.h rename to slsReceiverSoftware/include/UDPStandardImplementation.h diff --git a/slsReceiverSoftware/src/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h similarity index 100% rename from slsReceiverSoftware/src/slsReceiver.h rename to slsReceiverSoftware/include/slsReceiver.h diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h similarity index 100% rename from slsReceiverSoftware/src/slsReceiverTCPIPInterface.h rename to slsReceiverSoftware/include/slsReceiverTCPIPInterface.h diff --git a/slsReceiverSoftware/src/slsReceiverUDPFunctions.h b/slsReceiverSoftware/include/slsReceiverUDPFunctions.h similarity index 100% rename from slsReceiverSoftware/src/slsReceiverUDPFunctions.h rename to slsReceiverSoftware/include/slsReceiverUDPFunctions.h diff --git a/slsReceiverSoftware/src/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h similarity index 100% rename from slsReceiverSoftware/src/slsReceiverUsers.h rename to slsReceiverSoftware/include/slsReceiverUsers.h diff --git a/slsReceiverSoftware/src/Makefile b/slsReceiverSoftware/src/Makefile deleted file mode 100644 index 88d8caf2e3..0000000000 --- a/slsReceiverSoftware/src/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -include ../../Makefile.include - -DESTDIR ?= ../../bin -LIBDIR ?= $(DESTDIR) -PROGS = $(DESTDIR)/slsReceiver - - -CFLAGS += -DSLS_RECEIVER_UDP_FUNCTIONS -O3 -CPPFLAGS = ${CFLAGS} # for MAC - - -LDFLAGRXR ?= -L$(LIBDIR) -lSlsReceiver -L/usr/lib64/ -lpthread -LDFLAGRXR += -lm -lstdc++ - - -INCLUDES ?= -I ../MySocketTCP -I ../slsDetectorCalibration -I ../includes/ -I eigerReceiver -I . -SRC_CLNT = main.cpp - - -INSTMODE = 0777 -OBJS = $(SRC_CLNT:.cpp=.o) - - -.PHONY: all receiver clean static_receiver boot eigerReceiver lib - -all: receiver - -receiver: $(DESTDIR)/slsReceiver - -static_receiver: $(DESTDIR)/sslsReceiver - -boot: $(OBJS) - -$(DESTDIR)/sslsReceiver: lib - mkdir -p $(DESTDIR) - $(CXX) -static -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) - - -$(DESTDIR)/slsReceiver: lib - $(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC -#$(EIGERFLAGS) - - -#ifeq ($(EIGERSLS), yes) -#eigerReceiver: -# $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiverTest.o eigerReceiver/eigerReceiverTest.cpp #$(EIGERFLAGS) -# $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiver.cpp $(EIGERFLAGS) -# $(CXX) eigerReceiverTest.o eigerReceiver.o -o eigerReceiver/eigerReceiverTest $(EIGERFLAGS) -# $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiverImplementation.cpp $(EIGERFLAGS) -#else ifeq ($(ROOTSLS), yes) -#eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp -# echo "Compiling with root" -# $(CXX) $(FLAGS) $(CFLAGS) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp $(ROOTFLAGS) -#else -#eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp -# $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp -#endif - -lib: - cd ../ && $(MAKE) DESTDIR=../bin LIBDIR=../bin - -clean: - rm -rf $(PROGS) *.o eigerReceiverTest $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so core - - - diff --git a/slsReceiverSoftware/src/eigerReceiver/RestHelper.h b/slsReceiverSoftware/src/eigerReceiver/RestHelper.h deleted file mode 100644 index 6f423f5e1e..0000000000 --- a/slsReceiverSoftware/src/eigerReceiver/RestHelper.h +++ /dev/null @@ -1,195 +0,0 @@ -/** - * @file RestHelper.h - * @author Leonardo Sala - * @date Tue Mar 25 09:28:19 2014 - * - * @brief - * - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "JsonBox/Value.h" - -#include -#include -#include - -/// HTTP timeout in seconds, default is 8 -#define HTTP_TIMEOUT 10 -/// Number of connection tries -#define N_CONNECTION_TRIES 3 - -using namespace Poco::Net; -using namespace Poco; -using namespace std; - -class RestHelper { - public: - - ~RestHelper(){}; - - void init(string hostname, int port){ - /** Initialize the RestHelper. Hostname and port parameters are not supposed to change. - * - * - * @param hostname FQDN of the host to connect to , e.g. www.iamfake.org, or sodoi.org - * @param port - * - * @return - */ - - full_hostname = "http://"+hostname; - session = new HTTPClientSession(hostname,port ); - session->setKeepAliveTimeout( Timespan( HTTP_TIMEOUT,0) ); - }; - - - int get_json(string request, string* answer){ - /** Retrieves a reply from the RESTful webservice. - * - * - * @param request Request without the hostname, e.g. if the full request would have been http://fake.org/fakemethod, request=fakemethod - * @param answer - * - * @return 0 if successful, -1 if failure happens. - */ - URI * uri = new URI(full_hostname+"/"+request); - string path(uri->getPathAndQuery()); - if (path.empty()) path = "/"; - - // send request - HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1); - req.setContentType("application/json\r\n"); - int code = send_request(session, req, answer); - delete uri; - return code; - }; - - - int get_json(string request, JsonBox::Value* json_value){ - /** - * - * - * @param request - * @param json_value - * - * @return - */ - URI *uri = new URI(full_hostname+"/"+request); - string path(uri->getPathAndQuery()); - if (path.empty()) path = "/"; - // send request - HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1); - req.setContentType("application/json\r\n"); - string answer; - int code = send_request(session, req, &answer); - json_value->loadFromString(answer); - delete uri; - return code; - }; - - - int post_json(string request, string *answer, string request_body=""){ - /** - * - * - * @param request - * @param answer - * @param request_body Eventual arguments to the URL, e.g. action=login&name=mammamia - * - * @return - */ - //from: http://stackoverflow.com/questions/1499086/poco-c-net-ssl-how-to-post-https-request - URI *uri = new URI(full_hostname+"/"+request); - string path(uri->getPathAndQuery()); - if (path.empty()) path = "/"; - HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); - req.setContentType("application/json\r\n"); - req.setContentLength( request.length() ); - int code = send_request(session, req, answer, request_body); - delete uri; - return code; - } - - - int post_json(string request, JsonBox::Value* json_value, string request_body=""){ - /** - * - * - * @param request - * @param json_value - * @param request_body Eventual arguments to the URL, e.g. action=login&name=mammamia - * - * @return - */ - - URI *uri = new URI(full_hostname+"/"+request); - string path(uri->getPathAndQuery()); - if (path.empty()) path = "/"; - HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); - req.setContentType("application/json\r\n"); - req.setContentLength( request.length() ); - string answer; - int code = send_request(session, req, &answer, request_body); - json_value->loadFromString(answer); - delete uri; - return code; - } - - - private: - //URI * uri; - HTTPClientSession *session; - string full_hostname; - - int send_request(HTTPClientSession *session, HTTPRequest &req, string *answer, string request_body=""){ - /** - * - * - * @param session - * @param req - * @param answer - * @param request_body - * - * @return - */ - - int n=0; - int code = -1; - while(nsendRequest( (req) ); - else - session->sendRequest( (req) ) << request_body; - - HTTPResponse res; - istream &is = session->receiveResponse(res); - StreamCopier::copyToString(is, *answer); - code = res.getStatus(); - if (code != 200){ - cout << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() << endl; - code = -1; - } - return code; - } - catch (exception& e){ - cout << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping " << HTTP_TIMEOUT << " seconds\n"; - sleep(HTTP_TIMEOUT); - } - n+=1; - } - - return code; - } - -}; diff --git a/slsReceiverSoftware/src/eigerReceiver/eigerReceiver.cpp b/slsReceiverSoftware/src/eigerReceiver/eigerReceiver.cpp deleted file mode 100644 index fa19895beb..0000000000 --- a/slsReceiverSoftware/src/eigerReceiver/eigerReceiver.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - * eigerReceiver.cpp - * - * Created on: Mar 11, 2014 - * Author: billich - */ - -#include -#include -#include "eigerReceiver.h" - - -/* uncomment next line to enable debug output */ -#define EIGER_DEBUG - -/* macro for debug output http://stackoverflow.com/a/14256296 */ -#ifdef EIGER_DEBUG -#define DEBUG(x) do { std::cerr << x << std::endl; } while (0) -#else -#define DEBUG(x) -#endif - - -using namespace std; - -struct EigerReceiverInitializationConfiguration { - - string detectorHostname; -}; - -struct EigerReceiverScanConfiguration { - - string fileName; - string filePath; - int dynamicRange; - int scanTag; - int numberOfFrames; - bool doFileWrite; - bool doFileOverWrite; - - EigerReceiverScanConfiguration(): - dynamicRange(-1), - scanTag(-1), - numberOfFrames(-1), - doFileWrite(false), - doFileOverWrite(false){}; -}; - -class EigerReceiverImplementation: public EigerReceiver { - -public: - - EigerReceiverImplementation() : isInitialized(false), status(slsReceiverDefs::ERROR) {}; - - void initialize(const char *detectorHostname) { - - string name; - if (detectorHostname != NULL) { - name = detectorHostname; - } - - if (name.empty()) { - DEBUG("initialize(): can't initialize with empty string or NULL for detectorHostname"); - } else if (isInitialized == true) { - DEBUG("initialize(): already initialized, can't initialize several times"); - } else { - DEBUG("initialize(): initialize() with: detectorHostName=" << name << "."); - init_config.detectorHostname = name; - isInitialized = true; - status = slsReceiverDefs::IDLE; - } - -#ifdef SALA - //REST call - hardcoded - RestHelper rest ; - rest.init("localhost",8080); - std::string answer; - std::cout << "---- REST test 1: true, string "<< std::endl; - int code = rest.get_json("status", &answer); - std::cout << "Answer: " << answer << std::endl; - - std::cout << "---- REST test 2: 404, string "<< std::endl; - code = rest.get_json("statuss", &answer); - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; - } - - std::cout << "---- REST test 3: true, json object "<< std::endl; - JsonBox::Value json_value; - code = rest.get_json("status", &json_value); - std::cout << "JSON " << json_value["status"] << std::endl; - - answer = ""; - std::cout << "---- REST test 4: POST, string "<< std::endl; - code = rest.post_json("recipes/cassoela", &answer); - std::cout << "POST answer: " << answer << std::endl; - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; - } - - RestHelper rest2 ; - rest2.init("reallyfake",8080); - std::cout << "---- REST test 4: host not found, json object "<< std::endl; - JsonBox::Value json_value2; - code = rest2.get_json("status", &json_value2); - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; - } - -#endif - } - - - char *getDetectorHostname() const { - string name = init_config.detectorHostname; - if (name.empty()) { - DEBUG("getDetectorHostname(): Return NULL"); - return(NULL); - } - char *c = new char[name.length()+1]; - name.copy(c, name.length()); - c[name.length()] = '\0'; - DEBUG("getDetectorHostname(): Return " << c << "."); - return(c); - } - - char *getFileName() const { - string name = scan_config.fileName; - - char *c = new char[name.length()+1]; - name.copy(c, name.length()); - c[name.length()] = '\0'; - DEBUG("getFileName(): Return " << c); - return(c); - } - - char *getFilePath() const { - string name = scan_config.filePath; - - char *c = new char[name.length()+1]; - name.copy(c, name.length()); - c[name.length()] = '\0'; - DEBUG("getFilePath(): Return " << c); - return(c); - } - - int getDynamicRange() const { - DEBUG("getDynamicRange(): Return " << scan_config.dynamicRange); - return(scan_config.dynamicRange); - } - - int getScanTag() const { - DEBUG("getScanTag(): returns " << scan_config.scanTag); - return(scan_config.scanTag); - } - - int getNumberOfFrames() const { - DEBUG("getNumberOfFrames(): return " << scan_config.numberOfFrames); - return(scan_config.numberOfFrames); - } - - int getEnableFileWrite() const { - DEBUG("getEnableFileWrite() returns " << scan_config.doFileWrite); - return(scan_config.doFileWrite); - } - - int getEnableOverwrite() const { - DEBUG("getEnableOverwrite() returns " << scan_config.doFileOverWrite); - return(scan_config.doFileOverWrite); - } - - slsReceiverDefs::runStatus getStatus() const { - DEBUG("getStatus(): return " <getFileName()); - } - - char *setFilePath(const char c[]) { - DEBUG("setFilePath() called with " << c << "."); - scan_config.filePath = c; - return(this->getFilePath()); - } - - int setDynamicRange (const int dr) { - DEBUG("setDynamicRange() called with " << dr << '.'); - scan_config.dynamicRange = dr; - return(getDynamicRange()); - } - - int setScanTag (const int tag) { - DEBUG("setScanTag() called with " << tag); - scan_config.scanTag = tag; - return(getScanTag()); - } - - int setNumberOfFrames (const int fnum) { - DEBUG("setNumberOfFrames() called with " << fnum); - scan_config.numberOfFrames = fnum; - return(getNumberOfFrames()); - } - - int setEnableFileWrite(const int i) { - DEBUG("enableFileWrite() called with " << i); - scan_config.doFileWrite = i; - return(getEnableFileWrite()); - } - - int setEnableOverwrite(const int i) { - DEBUG("setEnableOverwrite() called with " << i); - scan_config.doFileOverWrite = i; - return(getEnableOverwrite()); - } - - int startReceiver(char message[]) { - DEBUG("startReceiver(): return 0."); - status = slsReceiverDefs::RUNNING; - message = NULL; - return(0); - } - - int stopReceiver() { - DEBUG("stopReceiver(): return 0."); - status = slsReceiverDefs::IDLE; - return(0); - } - - void abort() { - DEBUG("abort(): return 0."); - status = slsReceiverDefs::IDLE; - } - -private: - EigerReceiverScanConfiguration scan_config; - EigerReceiverInitializationConfiguration init_config; - bool isInitialized; - slsReceiverDefs::runStatus status; -}; - -EigerReceiver *EigerReceiver::create(void) { - DEBUG("create(): Return new EigerReceiverImplementation instance."); - return new EigerReceiverImplementation(); -} - - - - diff --git a/slsReceiverSoftware/src/eigerReceiver/eigerReceiver.h b/slsReceiverSoftware/src/eigerReceiver/eigerReceiver.h deleted file mode 100644 index 9d26b185be..0000000000 --- a/slsReceiverSoftware/src/eigerReceiver/eigerReceiver.h +++ /dev/null @@ -1,211 +0,0 @@ -#ifndef EIGERRECEIVER_H -#define EIGERRECEIVER_H -/*********************************************** - * @file eigerReceiver.h - * @short does all the functions for a receiver, set/get parameters, start/stop etc. - ***********************************************/ - -/** - * @short does all the functions for a receiver, set/get parameters, start/stop etc. - */ - -#include "sls_receiver_defs.h" -#ifdef SALA -#include "RestHelper.h" -#endif -class EigerReceiver { - /* abstract class that defines the public interface of an eiger data receiver. - * - * Use the factory method EigerReceiver::create() to get an instance: - * - * EigerReceiver *receiver = EigerReceiver::create() - * - * supported sequence of method-calls: - * - * initialize() : once and only once after create() - * - * get*() : anytime after initialize(), multiples times - * set*() : anytime after initialize(), multiple times - * - * startReceiver(): anytime after initialize(). Will fail if state already is 'running' - * - * abort(), - * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. - * - * getStatus() returns the actual state of the data receiver - running or idle. All other - * get*() and set*() methods access the local cache of configuration values only and *do not* modify the data receiver settings. - * - * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. - * - * get- and set-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: - * - * char *c = receiver->getFileName(); - * .... - * delete[] c; - * - * always: 1:YES 0:NO for int as bool-like arguments - * - */ - -public: - - /** - * factory method to create instances - */ - static EigerReceiver *create(); - - /** - * Destructor - */ - virtual ~EigerReceiver() {}; - - /** - * Initialize the Receiver - @param detectorHostName detector hostname - * you can call this function only once. You must call it before you call startReceiver() for the first time. - */ - virtual void initialize(const char *detectorHostName) = 0; - - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - virtual char *getDetectorHostname() const = 0; - - /** - * Returns status of receiver: idle, running or error - */ - virtual slsReceiverDefs::runStatus getStatus() const = 0; - - /** - * Returns File Name - * caller is responsible to deallocate the returned char array. - */ - virtual char *getFileName() const = 0; - - - /** - * Returns File Path - * caller is responsible to deallocate the returned char array - */ - virtual char *getFilePath() const = 0; //FIXME: Does the caller need to free() the returned pointer? - - - /** - * Returns the number of bits per pixel - */ - virtual int getDynamicRange() const = 0; - - /** - * Returns scan tag - */ - virtual int getScanTag() const = 0; - - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames - */ - virtual int getNumberOfFrames() const = 0; - - /** - * Returns file write enable - * 1: YES 0: NO - */ - virtual int getEnableFileWrite() const = 0; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - virtual int getEnableOverwrite() const = 0; - - /** - * Set File Name (without frame index, file index and extension) - @param c file name - /returns file name - * returns NULL on failure (like bad file name) - * does not check the existence of the file - we don't know which path we'll finally use, so no point to check. - * caller is responsible to deallocate the returned char array. - */ - virtual char* setFileName(const char c[]) = 0; - - /** - * Set File Path - @param c file path - /returns file path - * checks the existence of the directory. returns NULL if directory does not exist or is not readable. - * caller is responsible to deallocate the returned char array. - */ - virtual char* setFilePath(const char c[]) = 0; - - /** - * Returns the number of bits per pixel - @param dr sets dynamic range - /returns dynamic range - * returns -1 on failure - * FIXME: what are the allowd values - should we use an enum as argument? - */ - virtual int setDynamicRange(const int dr) = 0; - - - /** - * Set scan tag - @param tag scan tag - /returns scan tag (always non-negative) - * FIXME: valid range - only positive? 16bit ore 32bit? - * returns -1 on failure - */ - virtual int setScanTag(const int tag) = 0; - - /** - * Sets number of frames - @param fnum number of frames - /returns number of frames - */ - virtual int setNumberOfFrames(const int fnum) = 0; - - /** - * Set enable file write - * @param i file write enable - /returns file write enable - */ - virtual int setEnableFileWrite(const int i) = 0; - - /** - * Set enable file overwrite - * @param i file overwrite enable - /returns file overwrite enable - */ - virtual int setEnableOverwrite(const int i) = 0; - - /** - * Starts Receiver - activate all configuration settings to the eiger receiver and start to listen for packets - @param message is the error message if there is an error - /returns 0 on success or -1 on failure - */ - //FIXME: success == 0 or success == 1? - virtual int startReceiver(char message[]) = 0; //FIXME: who allocates message[]? - - /** - * Stops Receiver - stops listening for packets - /returns success - * same as abort(). Always returns 0. - */ - virtual int stopReceiver() = 0; - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - virtual void abort() = 0; - -protected: - -private: - -}; - -#endif /* #ifndef EIGERRECEIVER_H */ diff --git a/slsReceiverSoftware/src/eigerReceiver/eigerReceiverDummy.cpp b/slsReceiverSoftware/src/eigerReceiver/eigerReceiverDummy.cpp deleted file mode 100644 index f45c7517ee..0000000000 --- a/slsReceiverSoftware/src/eigerReceiver/eigerReceiverDummy.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * eigerReceiver.cpp - * - * Created on: Mar 11, 2014 - * Author: billich - */ - -#include -#include -#include "eigerReceiver.h" - - -using namespace std; - -struct EigerReceiverInitializationConfiguration { - string detectorHostname; -}; - -struct EigerReceiverScanConfiguration { - - string fileName; - string filePath; - int dynamicRange; - int scanTag; - int numberOfFrames; - bool doFileWrite; - bool doFileOverWrite; - - EigerReceiverScanConfiguration(): - dynamicRange(-1), - scanTag(-1), - numberOfFrames(-1), - doFileWrite(false), - doFileOverWrite(false){}; -}; - -class EigerReceiverImplementation: public EigerReceiver { - -public: - - EigerReceiverImplementation(){}; - - ~EigerReceiverImplementation(){}; - - void initialize(const char *detectorHostname) {} - - char *getDetectorHostname() const { return (char*)"";} - - char *getFileName() const {return (char*)"";} - - char *getFilePath() const {return (char*)"";} - - int getDynamicRange() const { return 0;} - - int getScanTag() const {return 0;} - - int getNumberOfFrames() const {return 0;} - - int getEnableFileWrite() const {return 0;} - - int getEnableOverwrite() const {return 0;} - - slsReceiverDefs::runStatus getStatus() const { return slsReceiverDefs::IDLE;} - - char *setFileName(const char c[]) {return (char*)"";} - - char *setFilePath(const char c[]) {return (char*)"";} - - int setDynamicRange (const int dr) {return 0;} - - int setScanTag (const int tag) {return 0;} - - int setNumberOfFrames (const int fnum) {return 0;} - - int setEnableFileWrite(const int i) {return 0;} - - int setEnableOverwrite(const int i) {return 0;} - - int startReceiver(char message[]) {return 0;} - - int stopReceiver() {return 0;} - - void abort() {} - -private: - EigerReceiverScanConfiguration scan_config; - EigerReceiverInitializationConfiguration init_config; - bool isInitialized; - slsReceiverDefs::runStatus status; - -}; - -EigerReceiver *EigerReceiver::create(void) { - return new EigerReceiverImplementation(); -} - - - - diff --git a/slsReceiverSoftware/src/eigerReceiver/eigerReceiverTest.cpp b/slsReceiverSoftware/src/eigerReceiver/eigerReceiverTest.cpp deleted file mode 100644 index bdfcba7a16..0000000000 --- a/slsReceiverSoftware/src/eigerReceiver/eigerReceiverTest.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * eigerReceiverTest.cpp - - * - * Created on: Mar 11, 2014 - * Author: billich - */ - -#include -#include -#include "eigerReceiver.h" - -using namespace std; - -int main(int argc, char *argv[]){ - - const char *name = "detectors_host_name"; - const char *empty = ""; - std::string prefix = "main: "; - cout <getStatus(); - char *c0 = receiver->getDetectorHostname(); - if (c0 == NULL) { - cout <initialize(empty); - status = receiver->getStatus(); - receiver->initialize(name); - status = receiver->getStatus(); - receiver->initialize(name); - status = receiver->getStatus(); - receiver->initialize((char *)NULL); - - cout << endl; - - status = receiver->getStatus(); - char *c6 = receiver->getDetectorHostname(); - cout <getFileName(); - cout <." << endl; - delete[] c1; - - char *c2 = receiver->getFilePath(); - cout <." << endl; - delete[]c2; - - int range = receiver->getDynamicRange(); - cout <getScanTag(); - cout <setFileName( "some_other_name"); - cout < after setting to " << endl << endl; - delete[] c3; - - char *c4 = receiver->setFilePath( "some_other_path"); - cout < after setting to " << endl << endl; - delete[] c4; - - range = receiver->setDynamicRange(8); - cout <setScanTag(99); - cout << "got scan tag " << tag << " after setting to 99." << endl << endl; - - int n = receiver->setNumberOfFrames(11); - cout << "got number of frames " << n << " after setting to 11." << endl << endl; - - int w = receiver->setEnableFileWrite(1); - cout << "got enable file write " << w << " after setting to 1." << endl << endl; - - char *c5; - status = receiver->getStatus(); - receiver->startReceiver(c5); - status = receiver->getStatus(); - receiver->stopReceiver(); - status = receiver->getStatus(); - receiver->abort(); - status = receiver->getStatus(); - -} - - - - diff --git a/slsReceiverSoftware/src/rec.cxx b/slsReceiverSoftware/test/rec.cxx similarity index 100% rename from slsReceiverSoftware/src/rec.cxx rename to slsReceiverSoftware/test/rec.cxx diff --git a/slsReceiverSoftware/src/send.cxx b/slsReceiverSoftware/test/send.cxx similarity index 100% rename from slsReceiverSoftware/src/send.cxx rename to slsReceiverSoftware/test/send.cxx From 3e0f618fbe85b8cd855714ed594a28f5b6cf10b7 Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Wed, 10 Sep 2014 10:09:29 +0200 Subject: [PATCH 032/222] cleaning --- slsReceiverSoftware/slsReceiver/Makefile | 68 ----- .../eigerReceiver/eigerReceiver.cpp | 259 ------------------ .../eigerReceiver/eigerReceiverDummy.cpp | 101 ------- .../eigerReceiver/eigerReceiverTest.cpp | 97 ------- 4 files changed, 525 deletions(-) delete mode 100644 slsReceiverSoftware/slsReceiver/Makefile delete mode 100644 slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp delete mode 100644 slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp delete mode 100644 slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp diff --git a/slsReceiverSoftware/slsReceiver/Makefile b/slsReceiverSoftware/slsReceiver/Makefile deleted file mode 100644 index c94528eeb9..0000000000 --- a/slsReceiverSoftware/slsReceiver/Makefile +++ /dev/null @@ -1,68 +0,0 @@ -include ../../Makefile.include - -DESTDIR ?= ../../bin -LIBDIR ?= $(DESTDIR) -PROGS = $(DESTDIR)/slsReceiver - - -CFLAGS += -DSLS_RECEIVER_UDP_FUNCTIONS -O3 -CPPFLAGS = ${CFLAGS} # for MAC - - -LDFLAGRXR ?= -L$(LIBDIR) -lSlsReceiver -L/usr/lib64/ -lpthread -LDFLAGRXR += -lm -lstdc++ - - -INCLUDES ?= -I ../MySocketTCP -I ../slsDetectorCalibration -I ../includes -I eigerReceiver -I . -I ../slsDetectorSoftware/commonFiles -SRC_CLNT = main.cpp - - -INSTMODE = 0777 -OBJS = $(SRC_CLNT:.cpp=.o) - - -.PHONY: all receiver clean static_receiver boot eigerReceiver lib - -all: receiver - -receiver: $(DESTDIR)/slsReceiver - -static_receiver: $(DESTDIR)/sslsReceiver - -boot: $(OBJS) - -$(DESTDIR)/sslsReceiver: lib - echo $(OBJS) - echo $(LDFLAGRXR) - echo $(LIBS) - mkdir -p $(DESTDIR) - $(CXX) -static -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) - - -$(DESTDIR)/slsReceiver: eigerReceiver lib - $(CXX) -o $@ $(SRC_CLNT) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC -#$(EIGERFLAGS) - - -ifeq ($(EIGERSLS), yes) -eigerReceiver: - $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiverTest.o eigerReceiver/eigerReceiverTest.cpp $(EIGERFLAGS) - $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiver.cpp $(EIGERFLAGS) - $(CXX) eigerReceiverTest.o eigerReceiver.o -o eigerReceiver/eigerReceiverTest $(EIGERFLAGS) -else ifeq ($(ROOTSLS), yes) -eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp - echo "Compiling with root" - $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp $(ROOTFLAGS) -else -eigerReceiver: eigerReceiver/eigerReceiverDummy.cpp - $(CXX) $(FLAGS) $(CFLAGS) $(INCLUDES) -fPIC -c -o eigerReceiver.o eigerReceiver/eigerReceiverDummy.cpp -endif - -lib: - cd ../ && $(MAKE) DESTDIR=../bin LIBDIR=../bin - -clean: - rm -rf $(PROGS) *.o eigerReceiverTest $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so core - - - diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp deleted file mode 100644 index 48024c5d03..0000000000 --- a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiver.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * eigerReceiver.cpp - * - * Created on: Mar 11, 2014 - * Author: billich - */ - -#include -#include -#include "eigerReceiver.h" - - -/* uncomment next line to enable debug output */ -#define EIGER_DEBUG - -/* macro for debug output http://stackoverflow.com/a/14256296 */ -#ifdef EIGER_DEBUG -#define DEBUG(x) do { std::cerr << x << std::endl; } while (0) -#else -#define DEBUG(x) -#endif - - -using namespace std; - -struct EigerReceiverInitializationConfiguration { - - string detectorHostname; -}; - -struct EigerReceiverScanConfiguration { - - string fileName; - string filePath; - int dynamicRange; - int scanTag; - int numberOfFrames; - bool doFileWrite; - bool doFileOverWrite; - - EigerReceiverScanConfiguration(): - dynamicRange(-1), - scanTag(-1), - numberOfFrames(-1), - doFileWrite(false), - doFileOverWrite(false){}; -}; - -class EigerReceiverImplementation: public EigerReceiver { - -public: - - EigerReceiverImplementation() : isInitialized(false), status(slsReceiverDefs::ERROR) {}; - - void initialize(const char *detectorHostname) { - - string name; - if (detectorHostname != NULL) { - name = detectorHostname; - } - - if (name.empty()) { - DEBUG("initialize(): can't initialize with empty string or NULL for detectorHostname"); - } else if (isInitialized == true) { - DEBUG("initialize(): already initialized, can't initialize several times"); - } else { - DEBUG("initialize(): initialize() with: detectorHostName=" << name << "."); - init_config.detectorHostname = name; - isInitialized = true; - status = slsReceiverDefs::IDLE; - } - -#ifdef SALA - //REST call - hardcoded - RestHelper rest ; - rest.init("localhost",8080); - std::string answer; - std::cout << "---- REST test 1: true, string "<< std::endl; - int code = rest.get_json("status", &answer); - std::cout << "Answer: " << answer << std::d::endl; - - std::cout << "---- REST test 2: 404, string "<< std::endl; - code = rest.get_json("statuss", &answer); - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; - } - - std::cout << "---- REST test 3: true, json object "<< std::endl; - JsonBox::Value json_value; - code = rest.get_json("status", &json_value); - std::cout << "JSON " << json_value["status"] << std::endl; - - answer = ""; - std::cout << "---- REST test 4: POST, string "<< std::endl; - code = rest.post_json("recipes/cassoela", &answer); - std::cout << "POST answer: " << answer << std::endl; - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; - } - - RestHelper rest2 ; - rest2.init("reallyfake",8080); - std::cout << "---- REST test 4: host not found, json object "<< std::endl; - JsonBox::Value json_value2; - code = rest2.get_json("status", &json_value2); - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; - } - -#endif - } - - - char *getDetectorHostname() const { - string name = init_config.detectorHostname; - if (name.empty()) { - DEBUG("getDetectorHostname(): Return NULL"); - return(NULL); - } - char *c = new char[name.length()+1]; - name.copy(c, name.length()); - c[name.length()] = '\0'; - DEBUG("getDetectorHostname(): Return " << c << "."); - return(c); - } - - char *getFileName() const { - string name = scan_config.fileName; - - char *c = new char[name.length()+1]; - name.copy(c, name.length()); - c[name.length()] = '\0'; - DEBUG("getFileName(): Return " << c); - return(c); - } - - char *getFilePath() const { - string name = scan_config.filePath; - - char *c = new char[name.length()+1]; - name.copy(c, name.length()); - c[name.length()] = '\0'; - DEBUG("getFilePath(): Return " << c); - return(c); - } - - int getDynamicRange() const { - DEBUG("getDynamicRange(): Return " << scan_config.dynamicRange); - return(scan_config.dynamicRange); - } - - int getScanTag() const { - DEBUG("getScanTag(): returns " << scan_config.scanTag); - return(scan_config.scanTag); - } - - int getNumberOfFrames() const { - DEBUG("getNumberOfFrames(): return " << scan_config.numberOfFrames); - return(scan_config.numberOfFrames); - } - - int getEnableFileWrite() const { - DEBUG("getEnableFileWrite() returns " << scan_config.doFileWrite); - return(scan_config.doFileWrite); - } - - int getEnableOverwrite() const { - DEBUG("getEnableOverwrite() returns " << scan_config.doFileOverWrite); - return(scan_config.doFileOverWrite); - } - - slsReceiverDefs::runStatus getStatus() const { - DEBUG("getStatus(): return " <getFileName()); - } - - char *setFilePath(const char c[]) { - DEBUG("setFilePath() called with " << c << "."); - scan_config.filePath = c; - return(this->getFilePath()); - } - - int setDynamicRange (const int dr) { - DEBUG("setDynamicRange() called with " << dr << '.'); - scan_config.dynamicRange = dr; - return(getDynamicRange()); - } - - int setScanTag (const int tag) { - DEBUG("setScanTag() called with " << tag); - scan_config.scanTag = tag; - return(getScanTag()); - } - - int setNumberOfFrames (const int fnum) { - DEBUG("setNumberOfFrames() called with " << fnum); - scan_config.numberOfFrames = fnum; - return(getNumberOfFrames()); - } - - int setEnableFileWrite(const int i) { - DEBUG("enableFileWrite() called with " << i); - scan_config.doFileWrite = i; - return(getEnableFileWrite()); - } - - int setEnableOverwrite(const int i) { - DEBUG("setEnableOverwrite() called with " << i); - scan_config.doFileOverWrite = i; - return(getEnableOverwrite()); - } - - int startReceiver(char message[]) { - DEBUG("startReceiver(): return 0."); - status = slsReceiverDefs::RUNNING; - message = NULL; - return(0); - } - - int stopReceiver() { - DEBUG("stopReceiver(): return 0."); - status = slsReceiverDefs::IDLE; - return(0); - } - - void abort() { - DEBUG("abort(): return 0."); - status = slsReceiverDefs::IDLE; - } - - // Temporary workaround - int setDetectorType(slsReceiverDefs::detectorType det){ - return 0; - } - -private: - EigerReceiverScanConfiguration scan_config; - EigerReceiverInitializationConfiguration init_config; - bool isInitialized; - slsReceiverDefs::runStatus status; -}; - -EigerReceiver *EigerReceiver::create(void) { - DEBUG("create(): Return new EigerReceiverImplementation instance."); - return new EigerReceiverImplementation(); -} - - - - diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp deleted file mode 100644 index ad8139cd87..0000000000 --- a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverDummy.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * eigerReceiver.cpp - * - * Created on: Mar 11, 2014 - * Author: billich - */ - -#include -#include -#include "eigerReceiver.h" - - -using namespace std; - -struct EigerReceiverInitializationConfiguration { - string detectorHostname; -}; - -struct EigerReceiverScanConfiguration { - - string fileName; - string filePath; - int dynamicRange; - int scanTag; - int numberOfFrames; - bool doFileWrite; - bool doFileOverWrite; - - EigerReceiverScanConfiguration(): - dynamicRange(-1), - scanTag(-1), - numberOfFrames(-1), - doFileWrite(false), - doFileOverWrite(false){}; -}; - -class EigerReceiverImplementation: public EigerReceiver { - -public: - - EigerReceiverImplementation(){}; - - ~EigerReceiverImplementation(){}; - - void initialize(const char *detectorHostname) {} - - char *getDetectorHostname() const { return (char*)"";} - - char *getFileName() const {return (char*)"";} - - char *getFilePath() const {return (char*)"";} - - int getFileIndex() const {return 0;} - - int getDynamicRange() const { return 0;} - - int getScanTag() const {return 0;} - - int getNumberOfFrames() const {return 0;} - - int getEnableFileWrite() const {return 0;} - - int getEnableOverwrite() const {return 0;} - - slsReceiverDefs::runStatus getStatus() const { return slsReceiverDefs::IDLE;} - - char *setFileName(const char c[]) {return (char*)"";} - - char *setFilePath(const char c[]) {return (char*)"";} - - int setDynamicRange (const int dr) {return 0;} - - int setScanTag (const int tag) {return 0;} - - int setNumberOfFrames (const int fnum) {return 0;} - - int setEnableFileWrite(const int i) {return 0;} - - int setEnableOverwrite(const int i) {return 0;} - - int startReceiver(char message[]) {return 0;} - - int stopReceiver() {return 0;} - - void abort() {} - -private: - EigerReceiverScanConfiguration scan_config; - EigerReceiverInitializationConfiguration init_config; - bool isInitialized; - slsReceiverDefs::runStatus status; - -}; - -EigerReceiver *EigerReceiver::create(void) { - return new EigerReceiverImplementation(); -} - - - - diff --git a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp b/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp deleted file mode 100644 index 7eb80f690e..0000000000 --- a/slsReceiverSoftware/slsReceiver/eigerReceiver/eigerReceiverTest.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * eigerReceiverTest.cpp - - * - * Created on: Mar 11, 2014 - * Author: billich - */ - -#include -#include -#include "eigerReceiver.h" - -using namespace std; - -int main(int argc, char *argv[]){ - - const char *name = "detectors_host_name"; - const char *empty = ""; - std::string prefix = "main: "; - cout <getStatus(); - char *c0 = receiver->getDetectorHostname(); - if (c0 == NULL) { - cout <initialize(empty); - status = receiver->getStatus(); - receiver->initialize(name); - status = receiver->getStatus(); - receiver->initialize(name); - status = receiver->getStatus(); - receiver->initialize((char *)NULL); - - cout << endl; - - status = receiver->getStatus(); - char *c6 = receiver->getDetectorHostname(); - cout <getFileName(); - cout <." << endl; - delete[] c1; - - char *c2 = receiver->getFilePath(); - cout <." << endl; - delete[]c2; - - int range = receiver->getDynamicRange(); - cout <getScanTag(); - cout <setFileName( "some_other_name"); - cout < after setting to " << endl << endl; - delete[] c3; - - char *c4 = receiver->setFilePath( "some_other_path"); - cout < after setting to " << endl << endl; - delete[] c4; - - range = receiver->setDynamicRange(8); - cout <setScanTag(99); - cout << "got scan tag " << tag << " after setting to 99." << endl << endl; - - int n = receiver->setNumberOfFrames(11); - cout << "got number of frames " << n << " after setting to 11." << endl << endl; - - int w = receiver->setEnableFileWrite(1); - cout << "got enable file write " << w << " after setting to 1." << endl << endl; - - char *c5; - status = receiver->getStatus(); - receiver->startReceiver(c5); - status = receiver->getStatus(); - receiver->stopReceiver(); - status = receiver->getStatus(); - receiver->abort(); - status = receiver->getStatus(); - -} - - - - From 50d049539e324634977a3665afa95576cd323b1b Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Wed, 10 Sep 2014 10:17:36 +0200 Subject: [PATCH 033/222] minor --- slsReceiverSoftware/include/UDPInterface.h | 31 +++++++++------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 590ee67d8a..aee09d7ff7 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -3,14 +3,14 @@ /*********************************************** * @file UDPInterface.h - * @short base class with all the functions for a receiver, set/get parameters, start/stop etc. + * @short Base class with all the functions for the UDP inteface of the receiver ***********************************************/ /** - * \mainpage Base class with all the functions for a receiver, set/get parameters, start/stop etc. + * \mainpage Base class with all the functions for the UDP inteface of the receiver */ /** - * @short base class with all the functions for a receiver, set/get parameters, start/stop etc. + * @short Base class with all the functions for the UDP inteface of the receiver */ @@ -21,19 +21,14 @@ #include "utilities.h" #include "logger.h" -/* -void print_not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; -} -*/ class UDPInterface { - /* abstract class that defines the public interface of an sls detector data receiver. + /* abstract class that defines the UDP interface of an sls detector data receiver. * - * Use the factory method slsReceiverBase::create() to get an instance: + * Use the factory method UDPInterface::create() to get an instance: * - * slsReceiverBase *receiver = slsReceiverBase::create() + * UDPInterface *udp_interface = UDPInterface::create() * * supported sequence of method-calls: * @@ -80,9 +75,9 @@ class UDPInterface { static UDPInterface *create(string receiver_type = "standard"); -public: + public: + - /** * Initialize the Receiver @@ -383,11 +378,11 @@ class UDPInterface { guidatapointer (NULL, no data required) */ virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg) = 0; - -protected: - -private: + + protected: + + private: }; -#endif /* #ifndef SLSRECEIVERBASE_H */ +#endif /* #ifndef UDPINTERFACE_H */ From eb1f9db9afcf0f25f0fe00f30e1cfa60bc53cd17 Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Fri, 12 Sep 2014 13:24:08 +0200 Subject: [PATCH 034/222] added build dir --- slsReceiverSoftware/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/.gitignore b/slsReceiverSoftware/.gitignore index 038cff97ea..31dd1b8d22 100644 --- a/slsReceiverSoftware/.gitignore +++ b/slsReceiverSoftware/.gitignore @@ -1,6 +1,6 @@ *~ *.o -build +build/* GPATH GRTAGS GSYMS From e0ee1fb386a3c4e8d4d6de8306d183fec4591657 Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Fri, 12 Sep 2014 16:09:43 +0200 Subject: [PATCH 035/222] fixed bug in config reading; added printout in MAkefile --- slsReceiverSoftware/Makefile | 7 +++++++ slsReceiverSoftware/src/slsReceiver.cpp | 26 +++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 7bbc89d5b2..981b44f1f8 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -23,6 +23,13 @@ MAIN_SRC = main.cpp OBJS=$(SRC_CLNT:%.cpp=$(BUILDDIR)/%.o) +$(info ) +$(info #######################################) +$(info # Compiling slsReceiverSoftware #) +$(info #######################################) +$(info ) + + .PHONY: all intdoc package eigerReceiver clean all: lib receiver diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index a59e773deb..f051592ced 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -30,7 +30,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ */ //creating base receiver - int tcpip_port_no = 1984; + int tcpip_port_no = 1954; success=OK; string fname = ""; string udp_interface_type = "standard"; @@ -85,17 +85,19 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ } // if required fname parameter not available, fail - if (fname == "") - success = FAIL; - - if((!fname.empty()) && (success == OK)){ - FILE_LOG(logINFO) << "config file name " << fname; - success = read_config_file(fname, &tcpip_port_no); - //VERBOSE_PRINT("Read configuration file of " + iline + " lines"); - } - else { - FILE_LOG(logERROR) << "Error opening configuration file " << fname ; + //if (fname == "") + // success = FAIL; + + if( !fname.empty() ){ + try{ + FILE_LOG(logINFO) << "config file name " << fname; + success = read_config_file(fname, &tcpip_port_no); + //VERBOSE_PRINT("Read configuration file of " + iline + " lines"); + } + catch(...){ + FILE_LOG(logERROR) << "Error opening configuration file " << fname ; success = FAIL; + } } @@ -104,7 +106,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ } if (success==OK){ - cout << "SLS Receiver starting " << udp_interface_type << endl; + FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << endl; udp_interface = UDPInterface::create(udp_interface_type); tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no); //tcp ip interface From 7986746194d4fa88482d51b2b9afca50a7d6a630 Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Mon, 15 Sep 2014 16:33:57 +0200 Subject: [PATCH 036/222] from private to protected --- slsReceiverSoftware/Makefile | 4 +- .../include/UDPBaseImplementation.h | 9 +- .../include/UDPStandardImplementation.h | 304 +----------------- .../src/UDPBaseImplementation.cpp | 33 +- .../src/UDPStandardImplementation.cpp | 26 +- 5 files changed, 49 insertions(+), 327 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 981b44f1f8..4bc760e825 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -32,7 +32,7 @@ $(info ) .PHONY: all intdoc package eigerReceiver clean -all: lib receiver +all: builddir lib receiver intdoc: $(SRC_H) $(SRC_CLNT) doxygen doxy.config @@ -76,6 +76,8 @@ clean: buildclean rm $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so rm $(PROGS) +builddir: + if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi buildclean: rm -rf $(OBJS) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 7b9068a63d..5528e34f0e 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -319,7 +319,7 @@ class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterfa */ int shutDownUDPSockets(); -private: +protected: /* void not_implemented(string method_name){ @@ -466,6 +466,10 @@ class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterfa void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); + + //// Could be done more fine-grained... TODO + // private: + protected: /** structure of an eiger image header*/ typedef struct { @@ -683,6 +687,9 @@ class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterfa /** 10Gbe enable*/ int tengigaEnable; + // TODO: not properly sure where to put these... + /** structure of an eiger image header*/ + diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index e161c8d81d..b6c25a144a 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -40,7 +40,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** * Constructor */ -UDPStandardImplementation(); + UDPStandardImplementation(); /** * Destructor @@ -466,308 +466,6 @@ UDPStandardImplementation(); void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); - /** structure of an eiger image header*/ - typedef struct - { - unsigned char header_before[20]; - unsigned char fnum[4]; - unsigned char header_after[24]; - } eiger_image_header; - - - /** structure of an eiger image header*/ - typedef struct - { - unsigned char num1[4]; - unsigned char num2[4]; - } eiger_packet_header; - - /** max number of listening threads */ - const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; - - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; - - /** detector type */ - detectorType myDetectorType; - - /** detector hostname */ - char detHostname[MAX_STR_LENGTH]; - - /** status of receiver */ - runStatus status; - - /** UDP Socket between Receiver and Detector */ - genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; - - /** Server UDP Port*/ - int server_port[MAX_NUM_LISTENING_THREADS]; - - /** ethernet interface or IP to listen to */ - char *eth; - - /** max packets per file **/ - int maxPacketsPerFile; - - /** File write enable */ - int enableFileWrite; - - /** File over write enable */ - int overwrite; - - /** Complete File name */ - char savefilename[MAX_STR_LENGTH]; - - /** File Name without frame index, file index and extension*/ - char fileName[MAX_STR_LENGTH]; - - /** File Path */ - char filePath[MAX_STR_LENGTH]; - - /** File Index */ - int fileIndex; - - /** scan tag */ - int scanTag; - - /** if frame index required in file name */ - int frameIndexNeeded; - - /* Acquisition started */ - bool acqStarted; - - /* Measurement started */ - bool measurementStarted; - - /** Frame index at start of each real time acquisition (eg. for each scan) */ - uint32_t startFrameIndex; - - /** Actual current frame index of each time acquisition (eg. for each scan) */ - uint32_t frameIndex; - - /** Frames Caught for each real time acquisition (eg. for each scan) */ - int packetsCaught; - - /** Total packets caught for an entire acquisition (including all scans) */ - int totalPacketsCaught; - - /** Pckets currently in current file, starts new file when it reaches max */ - int packetsInFile; - - /** Frame index at start of an entire acquisition (including all scans) */ - uint32_t startAcquisitionIndex; - - /** Actual current frame index of an entire acquisition (including all scans) */ - uint32_t acquisitionIndex; - - /** number of packets per frame*/ - int packetsPerFrame; - - /** frame index mask */ - uint32_t frameIndexMask; - - /** packet index mask */ - uint32_t packetIndexMask; - - /** frame index offset */ - int frameIndexOffset; - - /** acquisition period */ - int64_t acquisitionPeriod; - - /** frame number */ - int32_t numberOfFrames; - - /** dynamic range */ - int dynamicRange; - - /** short frames */ - int shortFrame; - - /** current frame number */ - uint32_t currframenum; - - /** Previous Frame number from buffer */ - uint32_t prevframenum; - - /** size of one frame */ - int frameSize; - - /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - int bufferSize; - - /** oen buffer size */ - int onePacketSize; - - /** latest data */ - char* latestData; - - /** gui data ready */ - int guiDataReady; - - /** points to the data to send to gui */ - char* guiData; - - /** points to the filename to send to gui */ - char* guiFileName; - - /** temporary number for eiger frame number as its not included in the packet */ - uint32_t guiFrameNumber; - - /** send every nth frame to gui or only upon gui request*/ - int nFrameToGui; - - /** fifo size */ - unsigned int fifosize; - - /** number of jobs per thread for data compression */ - int numJobsPerThread; - - /** datacompression - save only hits */ - bool dataCompression; - - /** memory allocated for the buffer */ - char *mem0[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data read */ - CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data already written and ready to be resued*/ - CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; - - /** Receiver buffer */ - char *buffer[MAX_NUM_LISTENING_THREADS]; - - /** number of writer threads */ - int numListeningThreads; - - /** number of writer threads */ - int numWriterThreads; - - /** to know if listening and writer threads created properly */ - int thread_started; - - /** current listening thread index*/ - int currentListeningThreadIndex; - - /** current writer thread index*/ - int currentWriterThreadIndex; - - /** thread listening to packets */ - pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; - - /** thread writing packets */ - pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; - - /** total frame count the listening thread has listened to */ - int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - - /** mask showing which listening threads are running */ - volatile uint32_t listeningthreads_mask; - - /** mask showing which writer threads are running */ - volatile uint32_t writerthreads_mask; - - /** mask showing which threads have created files*/ - volatile uint32_t createfile_mask; - - /** OK if file created was successful */ - int ret_createfile; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllListeningThreads; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllWritingThreads; - - /** 10Gbe enable*/ - int tengigaEnable; - - - - -//semaphores - /** semaphore to synchronize writer and guireader threads */ - sem_t smp; - /** semaphore to synchronize listener threads */ - sem_t listensmp[MAX_NUM_LISTENING_THREADS]; - /** semaphore to synchronize writer threads */ - sem_t writersmp[MAX_NUM_WRITER_THREADS]; - - -//mutex - /** guiDataReady mutex */ - pthread_mutex_t dataReadyMutex; - - /** mutex for status */ - pthread_mutex_t status_mutex; - - /** mutex for progress variable currframenum */ - pthread_mutex_t progress_mutex; - - /** mutex for writing data to file */ - pthread_mutex_t write_mutex; - - /** File Descriptor */ - FILE *sfilefd; - - //filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - moenchCommonMode *cmSub; - bool commonModeSubtractionEnable; - -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif - - - - /** - callback arguments are - filepath - filename - fileindex - data size - - return value is - 0 callback takes care of open,close,write file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - - */ - int (*startAcquisitionCallBack)(char*, char*,int, int, void*); - void *pStartAcquisition; - - /** - args to acquisition finished callback - total frames caught - - */ - void (*acquisitionFinishedCallBack)(int, void*); - void *pAcquisitionFinished; - - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); - void *pRawDataReady; - - /** The action which decides what the user and default responsibilites to save data are - * 0 raw data ready callback takes care of open,close,write file - * 1 callback writes file, we have to open, close it - * 2 we open, close, write file, callback does not do anything */ - int cbAction; public: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 14207ce658..247c2b329c 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -94,11 +94,12 @@ void UDPBaseImplementation::resetTotalFramesCaught(){ /*file parameters*/ char* UDPBaseImplementation::getFilePath() const{ - FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; + //FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; return (char*)filePath; } -char* UDPBaseImplementation::setFilePath(const char c[]){ +inline char* UDPBaseImplementation::setFilePath(const char c[]){ + cout << "SET FILE PATH " << c << endl; if(strlen(c)){ //check if filepath exists struct stat st; @@ -109,6 +110,7 @@ char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logWARNING) << "FilePath does not exist:" << filePath; } } + cout << getFilePath() << " " << filePath << endl; return getFilePath(); } @@ -117,7 +119,7 @@ char* UDPBaseImplementation::getFileName() const{ return (char*)fileName; } -char* UDPBaseImplementation::setFileName(const char c[]){ +inline char* UDPBaseImplementation::setFileName(const char c[]){ //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; if(strlen(c)) @@ -132,17 +134,15 @@ int UDPBaseImplementation::getFileIndex(){ } int UDPBaseImplementation::setFileIndex(int i){ - cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; - /* + //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; if(i>=0) fileIndex = i; - */ return getFileIndex(); } int UDPBaseImplementation::setFrameIndexNeeded(int i){ - cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; + //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; frameIndexNeeded = i; return frameIndexNeeded; } @@ -871,8 +871,10 @@ int UDPBaseImplementation::setupWriter(){ //acquisition start call back returns enable write - if (startAcquisitionCallBack) + if (startAcquisitionCallBack){ + cout << filePath << " - " << fileName << endl; cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); + } if(cbAction < DO_EVERYTHING) cout << endl << "Note: Call back activated. Data saving must be taken care of by user in call back." << endl; @@ -952,14 +954,21 @@ int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){ int UDPBaseImplementation::createNewFile(){ - int gt = getFrameIndex(); - if(gt==-1) gt=0; + + cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; + + + /* + int gt = getFrameIndex(); + if(gt==-1) gt=0; //create file name if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex); + cout << filePath << " + " << fileName << endl; + //if filewrite and we are allowed to write if(enableFileWrite && cbAction > DO_NOTHING){ //close @@ -974,7 +983,7 @@ int UDPBaseImplementation::createNewFile(){ return FAIL; } }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not create file " << savefilename << endl; + cout << "Error: Could not creat dsdasdserwe file " << savefilename << endl; return FAIL; } //setting buffer @@ -1001,7 +1010,7 @@ int UDPBaseImplementation::createNewFile(){ prevframenum = currframenum; packetsInFile = 0; } - + */ return OK; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 1314f2d5cb..19ea6ccedc 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -110,8 +110,11 @@ void UDPStandardImplementation::initializeMembers(){ strcpy(detHostname,""); strcpy(guiFileName,""); strcpy(savefilename,""); - strcpy(filePath,""); - strcpy(fileName,"run"); + + setFileName("run"); + setFilePath(""); + //strcpy(filePath,""); + //strcpy(fileName,"run"); //status @@ -122,16 +125,17 @@ void UDPStandardImplementation::initializeMembers(){ } -UDPStandardImplementation::UDPStandardImplementation(): - thread_started(0), - eth(NULL), - latestData(NULL), - guiFileName(NULL), - guiFrameNumber(0), - tengigaEnable(0){ +UDPStandardImplementation::UDPStandardImplementation(){ cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa" << endl; + thread_started = 0; + eth = NULL; + latestData = NULL; + guiFileName = NULL; + guiFrameNumber = 0; + tengigaEnable = 0; + for(int i=0;i DO_NOTHING){ //close From cfacc6ad6ed831548a42c7288d01d82431bb9757 Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Mon, 15 Sep 2014 16:52:53 +0200 Subject: [PATCH 037/222] modified to support REST receiver, still not properly working --- slsReceiverSoftware/Makefile | 9 ++++++++- slsReceiverSoftware/src/UDPInterface.cpp | 8 +++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 4bc760e825..b245a634f0 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -15,9 +15,16 @@ CFLAGS= -g -DC_ONLY -fPIC DFLAGS= -g -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS -INCLUDES?= -Iinclude -I../slsDetectorCalibration -I$(ASM) +INCLUDES?= $(INCLUDESRXR) -I include/ -I ../slsDetectorCalibration + +#-Iinclude -I../slsDetectorCalibration -I$(ASM) SRC_CLNT = MySocketTCP.cpp UDPInterface.cpp UDPBaseImplementation.cpp UDPStandardImplementation.cpp slsReceiverTCPIPInterface.cpp slsReceiver.cpp slsReceiverUsers.cpp utilities.cpp + +ifeq ($(REST), yes) + SRC_CLNT += UDPRESTImplementation.cpp +endif + MAIN_SRC = main.cpp OBJS=$(SRC_CLNT:%.cpp=$(BUILDDIR)/%.o) diff --git a/slsReceiverSoftware/src/UDPInterface.cpp b/slsReceiverSoftware/src/UDPInterface.cpp index a0d7716874..0d7d0503c3 100644 --- a/slsReceiverSoftware/src/UDPInterface.cpp +++ b/slsReceiverSoftware/src/UDPInterface.cpp @@ -23,6 +23,7 @@ using namespace std; #include "UDPInterface.h" #include "UDPBaseImplementation.h" #include "UDPStandardImplementation.h" +#include "UDPRESTImplementation.h" @@ -35,10 +36,11 @@ UDPInterface * UDPInterface::create(string receiver_type){ return new UDPStandardImplementation(); } -#ifdef REST - else if (receiver_type == "REST") + //#ifdef REST + else if (receiver_type == "REST"){ return new UDPRESTImplementation(); -#endif + } + //#endif else{ FILE_LOG(logWARNING) << "[ERROR] UDP interface not supported, using standard implementation"; return new UDPBaseImplementation(); From 5cfe7b433832f1510eb6776a172b77caeb2d87bc Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Tue, 16 Sep 2014 16:29:36 +0200 Subject: [PATCH 038/222] 32 bit image, and 32 bit mode frame number for eiger fixed, startframeindex included in readframe for all det in tcpip class --- .../MySocketTCP/genericSocket.h | 12 +++++++++ .../slsReceiver/slsReceiverBase.h | 3 ++- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 27 ++++++++++--------- .../slsReceiver/slsReceiverUDPFunctions.cpp | 27 ++++++++++++++----- .../slsReceiver/slsReceiverUDPFunctions.h | 4 +-- 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/slsReceiverSoftware/MySocketTCP/genericSocket.h b/slsReceiverSoftware/MySocketTCP/genericSocket.h index bb899f35b6..a798a0feff 100644 --- a/slsReceiverSoftware/MySocketTCP/genericSocket.h +++ b/slsReceiverSoftware/MySocketTCP/genericSocket.h @@ -61,6 +61,8 @@ class sockaddr_in; #endif +#include /******exit */ + #include #include #include @@ -558,6 +560,16 @@ enum communicationProtocol{ break; case UDP: if (socketDescriptor<0) return -1; + +/* + cout <<"******listening inside genericsocket"<0){ diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverBase.h b/slsReceiverSoftware/slsReceiver/slsReceiverBase.h index 007bf4a970..97d21bec45 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverBase.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverBase.h @@ -273,8 +273,9 @@ class slsReceiverBase { * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui * @param fnum frame number for eiger as it is not in the packet + * @param fstartind is the start index of the acquisition */ - virtual void readFrame(char* c,char** raw, uint32_t &fnum) = 0; + virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind ) = 0; /** set status to transmitting and * when fifo is empty later, sets status to run_finished diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index cc143efc45..2ebfd38264 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -1000,8 +1000,8 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ else{ ret = OK; - startIndex=receiverBase->getStartFrameIndex(); - receiverBase->readFrame(fName,&raw,index); + /*startIndex=receiverBase->getStartFrameIndex();*/ + receiverBase->readFrame(fName,&raw,index,startIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1170,8 +1170,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ cout<<"haven't caught any frame yet"<getStartFrameIndex(); - receiverBase->readFrame(fName,&raw,index); + /*startIndex=receiverBase->getStartFrameIndex();*/ + receiverBase->readFrame(fName,&raw,index,startIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1302,13 +1302,9 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ char* raw = new char[frameSize]; char* origVal = new char[frameSize]; char* retval = new char[dataSize]; - + uint32_t startIndex=0; strcpy(mess,"Could not read frame\n"); -/* typedef struct{ - unsigned char num1[4]; - unsigned char num2[4]; - } eiger_packet_header;*/ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS @@ -1326,7 +1322,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ else{ ret = OK; /** read a frame */ - receiverBase->readFrame(fName,&raw, index); + receiverBase->readFrame(fName,&raw,index,startIndex); #ifdef VERBOSE cout << "index:" << dec << index << endl; #endif @@ -1373,16 +1369,21 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport); retindex += numbytesperlineperport; c1 += numbytesperlineperport; + if(repeat == 2) c1 += 16; } for(irepeat=0;irepeat using namespace std; +#define EIGER_32BIT_INITIAL_CONSTANT 0x17c + @@ -785,7 +787,7 @@ void slsReceiverUDPFunctions::setupFifoStructure(){ /** acquisition functions */ -void slsReceiverUDPFunctions::readFrame(char* c,char** raw, uint32_t &fnum){ +void slsReceiverUDPFunctions::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){ //point to gui data if (guiData == NULL) guiData = latestData; @@ -793,7 +795,7 @@ void slsReceiverUDPFunctions::readFrame(char* c,char** raw, uint32_t &fnum){ //copy data and filename strcpy(c,guiFileName); fnum = guiFrameNumber; - + fstartind = getStartFrameIndex(); //could not get gui data if(!guiDataReady){ @@ -1506,9 +1508,13 @@ int slsReceiverUDPFunctions::startListening(){ //normal listening else if(!carryonBufferSize){ + /* if(!ithread){*/ rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); expected = maxBufferSize; - + /*}else{ + while(1) usleep(100000000); + } +*/ } //the remaining packets from previous buffer else{ @@ -1726,7 +1732,10 @@ int loop; //for progress if(myDetectorType == EIGER){ tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 + if(dynamicRange != 32) + tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 + else + tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else @@ -1751,6 +1760,7 @@ int loop; if (cbAction < DO_EVERYTHING){ for(i=0;i 0){ for(i=0;i Date: Wed, 17 Sep 2014 15:56:27 +0200 Subject: [PATCH 039/222] able to send data to eigerbe tweaks on logging added configuration_map, to flexibly pass options to the different receivers some more fixes to method overloads still very preliminary --- slsReceiverSoftware/include/RestHelper.h | 31 +-- .../include/UDPBaseImplementation.h | 5 +- slsReceiverSoftware/include/UDPInterface.h | 7 +- .../include/UDPRESTImplementation.h | 40 ++-- slsReceiverSoftware/include/logger.h | 15 +- slsReceiverSoftware/include/utilities.h | 4 +- .../src/UDPBaseImplementation.cpp | 116 +++++++++-- .../src/UDPRESTImplementation.cpp | 187 +++++++++++++----- .../src/UDPStandardImplementation.cpp | 8 +- slsReceiverSoftware/src/slsReceiver.cpp | 17 +- .../src/slsReceiverTCPIPInterface.cpp | 9 +- slsReceiverSoftware/src/utilities.cpp | 26 ++- 12 files changed, 350 insertions(+), 115 deletions(-) diff --git a/slsReceiverSoftware/include/RestHelper.h b/slsReceiverSoftware/include/RestHelper.h index fc4056c43d..5c10d0ff9d 100644 --- a/slsReceiverSoftware/include/RestHelper.h +++ b/slsReceiverSoftware/include/RestHelper.h @@ -19,17 +19,13 @@ #include "JsonBox/Value.h" +//#include "logger.h" + #include #include #include #include -#define EIGER_DEBUG -#ifdef EIGER_DEBUG -#define DEBUG(x) do { std::cerr << "[DEBUG] " << x << std::endl; } while (0) -#else -#define DEBUG(x) -#endif using namespace Poco::Net; @@ -39,7 +35,7 @@ using namespace std; class RestHelper { public: - RestHelper(int timeout=10, int n_tries=3){ + RestHelper(int timeout=10, int n_tries=10){ /** * * @@ -78,18 +74,22 @@ class RestHelper { */ //Check for http:// string + FILE_LOG(logDEBUG) << __func__ << " starting"; string proto_str = "http://"; + if( size_t found = hostname.find(proto_str) != string::npos ){ + cout << hostname << endl; + char c1[hostname.size()-found-1]; + cout << c1 << endl; size_t length1 = hostname.copy(c1, hostname.size()-found-1, proto_str.size()); c1[length1]='\0'; hostname = c1; } full_hostname = "http://"+hostname; - session = new HTTPClientSession(hostname,port ); + session = new HTTPClientSession(hostname, port ); session->setKeepAliveTimeout( Timespan( http_timeout,0) ); - }; @@ -168,7 +168,7 @@ class RestHelper { string answer; int code = send_request(session, req, &answer); if(code == 0 ) { - DEBUG("ANSWER " << answer ); + FILE_LOG(logDEBUG) << "ANSWER " << answer; json_value->loadFromString(answer); } delete uri; @@ -176,7 +176,7 @@ class RestHelper { }; - int post_json(string request, string *answer, string request_body=""){ + int post_json(string request, string *answer, string request_body="{}"){ /** * * @@ -192,15 +192,16 @@ class RestHelper { if (path.empty()) path = "/"; HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); req.setContentType("application/json\r\n"); - req.setContentLength( request.length() ); - + cout << "REQUEST BODY " << request_body << endl; + req.setContentLength( request_body.length() ); int code = send_request(session, req, answer, request_body); + delete uri; return code; } - int post_json(string request, JsonBox::Value* json_value, string request_body=""){ + int post_json(string request, JsonBox::Value* json_value, string request_body="{}"){ /** * * @@ -283,7 +284,7 @@ class RestHelper { return code; } catch (exception& e){ - cout << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"< config_map); + /** * delete and free member parameters diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 590ee67d8a..e2454e09be 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -13,6 +13,7 @@ * @short base class with all the functions for a receiver, set/get parameters, start/stop etc. */ +#include #include "sls_receiver_defs.h" #include "receiver_defs.h" @@ -20,7 +21,6 @@ #include "utilities.h" #include "logger.h" - /* void print_not_implemented(string method_name){ std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; @@ -78,9 +78,10 @@ class UDPInterface { * Factory create method */ static UDPInterface *create(string receiver_type = "standard"); - -public: + virtual void configure(map config_map) = 0; + + public: diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index 32c55e4fff..30cd782ede 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -34,7 +34,7 @@ * @short does all the functions for a receiver, set/get parameters, start/stop etc. */ -class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImplementation { +class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseImplementation { public: /** @@ -47,7 +47,10 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp */ virtual ~UDPRESTImplementation(); - + + void initialize_REST(); + + void configure(map config_map); /** * delete and free member parameters @@ -57,14 +60,28 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp /** * initialize member parameters */ - void initializeMembers(); + //void initializeMembers(); + + /** + * Set detector hostname + * @param c hostname + */ + //void initialize(const char *detectorHostName); + + /* Returns detector hostname + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ + //char *getDetectorHostname() const; + /** * Set receiver type * @param det detector type * Returns success or FAIL */ - int setDetectorType(detectorType det); + //int setDetectorType(detectorType det); //Frame indices and numbers caught @@ -192,18 +209,6 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp */ runStatus getStatus() const; - /** - * Set detector hostname - * @param c hostname - */ - void initialize(const char *detectorHostName); - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - //char *getDetectorHostname() const; /** * Set Ethernet Interface or IP to listen to @@ -811,6 +816,9 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp //REST specific bool isInitialized; RestHelper * rest ; + int rest_port; // receiver backend port + string rest_hostname; // receiver hostname + }; diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index eda43b0b0a..3d6d5703ee 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -5,6 +5,19 @@ #include #include +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +#define MYCONCAT(x,y) +#define __AT__ string(__FILE__) + string("::") + string(__func__) + string("(): ") + +//":" TOSTRING(__LINE__) + +/* +void error(const char *location, const char *msg){ + printf("Error at %s: %s\n", location, msg); +} +*/ + inline std::string NowTime(); enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4}; @@ -110,7 +123,7 @@ template std::ostringstream& Log::Get(TLogLevel level) template Log::~Log() { os << std::endl; - T::Output(os.str()); + T::Output( os.str()); } template TLogLevel& Log::ReportingLevel() diff --git a/slsReceiverSoftware/include/utilities.h b/slsReceiverSoftware/include/utilities.h index 78a99bcbca..b28d4f32c4 100644 --- a/slsReceiverSoftware/include/utilities.h +++ b/slsReceiverSoftware/include/utilities.h @@ -2,6 +2,8 @@ #include #include #include +#include + using namespace std; #include "sls_receiver_defs.h" @@ -9,5 +11,5 @@ using namespace std; //#define EIGER_DEBUG -int read_config_file(string fname, int *tcpip_port_no); +int read_config_file(string fname, int *tcpip_port_no, map * configuration_map); diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 247c2b329c..c831621ee5 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -35,6 +35,11 @@ UDPBaseImplementation::UDPBaseImplementation(){} UDPBaseImplementation::~UDPBaseImplementation(){} +void UDPBaseImplementation::configure(map config_map){ + FILE_LOG(logWARNING) << __AT__ << "doing nothing..."; +}; + + void UDPBaseImplementation::deleteMembers(){ FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; } @@ -47,6 +52,92 @@ void UDPBaseImplementation::initializeMembers(){ int UDPBaseImplementation::setDetectorType(detectorType det){ cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; + + cout << "Setting Receiver Type " << endl; + + deleteMembers(); + initializeMembers(); + + myDetectorType = det; + + switch(myDetectorType){ + case GOTTHARD: + cout << endl << "***** This is a GOTTHARD Receiver *****" << endl << endl; + break; + case MOENCH: + cout << endl << "***** This is a MOENCH Receiver *****" << endl << endl; + break; + case EIGER: + cout << endl << "***** This is a EIGER Receiver *****" << endl << endl; + break; + default: + cout << endl << "***** Unknown Receiver *****" << endl << endl; + return FAIL; + break; + } + + //moench variables + if(myDetectorType == GOTTHARD){ + fifosize = GOTTHARD_FIFO_SIZE; + packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; + onePacketSize = GOTTHARD_ONE_PACKET_SIZE; + frameSize = GOTTHARD_BUFFER_SIZE; + bufferSize = GOTTHARD_BUFFER_SIZE; + maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; + frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; + frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; + packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; + }else if(myDetectorType == MOENCH){ + fifosize = MOENCH_FIFO_SIZE; + packetsPerFrame = MOENCH_PACKETS_PER_FRAME; + onePacketSize = MOENCH_ONE_PACKET_SIZE; + frameSize = MOENCH_BUFFER_SIZE; + bufferSize = MOENCH_BUFFER_SIZE; + maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; + frameIndexMask = MOENCH_FRAME_INDEX_MASK; + frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; + packetIndexMask = MOENCH_PACKET_INDEX_MASK; + } + else if(myDetectorType == EIGER){ + fifosize = EIGER_FIFO_SIZE; + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + frameSize = onePacketSize * packetsPerFrame; + bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + frameIndexMask = EIGER_FRAME_INDEX_MASK; + frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; + packetIndexMask = EIGER_PACKET_INDEX_MASK; + + pthread_mutex_lock(&status_mutex); + listeningthreads_mask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + if(thread_started) + createListeningThreads(true); + + numListeningThreads = MAX_NUM_LISTENING_THREADS; + } + latestData = new char[frameSize]; + + + setupFifoStructure(); + + if(createListeningThreads() == FAIL){ + cout << "ERROR: Could not create listening thread" << endl; + exit (-1); + } + + if(createWriterThreads() == FAIL){ + cout << "ERROR: Could not create writer threads" << endl; + exit (-1); + } + + setThreadPriorities(); + + cout << "Ready..." << endl; + + return OK; + return OK; } @@ -94,12 +185,11 @@ void UDPBaseImplementation::resetTotalFramesCaught(){ /*file parameters*/ char* UDPBaseImplementation::getFilePath() const{ - //FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; return (char*)filePath; } inline char* UDPBaseImplementation::setFilePath(const char c[]){ - cout << "SET FILE PATH " << c << endl; + FILE_LOG(logDEBUG) << __AT__ << "called"; if(strlen(c)){ //check if filepath exists struct stat st; @@ -110,6 +200,7 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logWARNING) << "FilePath does not exist:" << filePath; } } + FILE_LOG(logDEBUG) << __AT__ << getFilePath(); cout << getFilePath() << " " << filePath << endl; return getFilePath(); } @@ -628,6 +719,7 @@ void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char int UDPBaseImplementation::createUDPSockets(){ + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; //if eth is mistaken with ip address @@ -1015,17 +1107,12 @@ int UDPBaseImplementation::createNewFile(){ } - - - - - - -void UDPBaseImplementation::closeFile(int ithr){ -#ifdef VERBOSE - cout << "In closeFile for thread " << ithr << endl; -#endif - +// This is actually called on CTRL-C +void UDPBaseImplementation::closeFile(int ithr) +{ + + FILE_LOG(logDEBUG) << __AT__ << "called"; + if(!dataCompression){ if(sfilefd){ #ifdef VERBOSE @@ -1072,6 +1159,9 @@ void UDPBaseImplementation::closeFile(int ithr){ #endif } + + FILE_LOG(logDEBUG) << __AT__ << "exited"; + } diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index 3dc6b210a3..8f40e95524 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -16,55 +16,113 @@ #include // stat #include // socket(), bind(), listen(), accept(), shut down #include // sock_addr_in, htonl, INADDR_ANY -#include // exit() -#include //set precision -#include //munmap +#include // exit() +#include // set precision +#include // munmap #include #include +#include //#include "utilities.h" using namespace std; +/* + TODO + + filePath != getFilePath +*/ -UDPRESTImplementation::UDPRESTImplementation() : isInitialized(false), status(slsReceiverDefs::ERROR) {} + +UDPRESTImplementation::UDPRESTImplementation(){ + + rest_hostname = "localhost"; + rest_port = 8081; +} UDPRESTImplementation::~UDPRESTImplementation(){} -void UDPRESTImplementation::initialize(const char *detectorHostName){ +void UDPRESTImplementation::configure(map config_map){ + FILE_LOG(logWARNING) << __AT__ << " called"; + + map::const_iterator pos; + + pos = config_map.find("rest_hostname"); + if (pos != config_map.end() ){ + string host_port_str = pos->second; + std::size_t pos = host_port_str.find(":"); // position of "live" in str + if(pos != string::npos){ + istringstream (host_port_str.substr (pos)) >> rest_port; + rest_hostname = host_port_str.substr(0, pos); + cout << rest_hostname << " " << rest_port << endl; + } + } + + for(map::const_iterator i=config_map.begin(); i != config_map.end(); i++){ + std::cout << i->first << " " << i->second<< std::endl; + } + + +}; + - string name; - if (detectorHostName != NULL) - name = detectorHostName; - if (name.empty()) { - FILE_LOG(logDEBUG) << "initialize(): can't initialize with empty string or NULL for detectorHostname"; - } else if (isInitialized == true) { - FILE_LOG(logDEBUG) << "initialize(): already initialized, can't initialize several times"; - } else { - FILE_LOG(logDEBUG) << "initialize(): initialize() with: detectorHostName=" << name; - strcpy(detHostname,detectorHostName); - //init_config.detectorHostname = name; +void UDPRESTImplementation::initialize_REST(){ + + if (rest_hostname.empty()) { + FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; + } + else if (isInitialized == true) { + FILE_LOG(logDEBUG) << __AT__ << "already initialized, can't initialize several times"; + } + else { + FILE_LOG(logDEBUG) << __AT__ << "with receiverHostName=" << rest_hostname << ":" << rest_port; - //REST call - hardcoded - //RestHelper rest ; - rest->init(detHostname, 8080); + rest = new RestHelper() ; std::string answer; - int code = rest->get_json("status", &answer); - if (code != 0){ - //throw -1; - std::cout << "I SHOULD THROW AN EXCEPTION!!!" << std::endl; + int code; + try{ + rest->init(rest_hostname, rest_port); + code = rest->get_json("state", &answer); + + if (code != 0){ + throw answer; + } + else{ + isInitialized = true; + status = slsReceiverDefs::IDLE; + } + FILE_LOG(logDEBUG) << __func__ << "Answer: " << answer; } - else{ - isInitialized = true; - status = slsReceiverDefs::IDLE; + catch(std::string e){ + FILE_LOG(logERROR) << __func__ << ": " << e; + throw; } - std::cout << "Answer: " << answer << std::endl; + //JsonBox::Object json_object; + //json_object["configfile"] = JsonBox::Value("FILENAME"); + JsonBox::Value json_request; + //json_request["configfile"] = "config.py"; + json_request["path"] = filePath; + + stringstream ss; + string test; + std::cout << "GetSTring: " << json_request << std::endl; + json_request.writeToStream(ss, false); + //ss << json_request; + ss >> test; + + + cout << "aaaa" <post_json("state/initialize", &answer, test); + FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; + code = rest->get_json("state", &answer); + FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer; + /* std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl; @@ -73,14 +131,18 @@ void UDPRESTImplementation::initialize(const char *detectorHostName){ std::cout << "JSON " << json_value["status"] << std::endl; */ } + + FILE_LOG(logDEBUG) << __func__ << ": initialize() done"; + } +/* int UDPRESTImplementation::setDetectorType(detectorType det){ cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; return OK; } - +*/ /*Frame indices and numbers caught*/ @@ -180,7 +242,9 @@ char *UDPRESTImplementation::getDetectorHostname() const{ */ void UDPRESTImplementation::setEthernetInterface(char* c){ - strcpy(eth,c); + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + //strcpy(eth,c); + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; } @@ -219,14 +283,17 @@ int32_t UDPRESTImplementation::setScanTag(int32_t stag){ */ int32_t UDPRESTImplementation::setDynamicRange(int32_t dr){ - cout << "Setting Dynamic Range" << endl; + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; int olddr = dynamicRange; if(dr >= 0){ dynamicRange = dr; } + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << getDynamicRange(); return getDynamicRange(); + + } @@ -571,6 +638,8 @@ void UDPRESTImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char int UDPRESTImplementation::createUDPSockets(){ + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + std::cout << "AAAAAAAAAAAa" << std::endl; //if eth is mistaken with ip address if (strchr(eth,'.')!=NULL) @@ -615,13 +684,24 @@ int UDPRESTImplementation::createUDPSockets(){ int UDPRESTImplementation::shutDownUDPSockets(){ + + FILE_LOG(logDEBUG) << __AT__ << "called"; + FILE_LOG(logDEBUG) << __AT__ << "doing nothing"; + + + /* for(int i=0;iShutDownSocket(); delete udpSocket[i]; udpSocket[i] = NULL; } } + */ + + FILE_LOG(logDEBUG) << __AT__ << "finished"; + return OK; } @@ -955,9 +1035,7 @@ int UDPRESTImplementation::createNewFile(){ void UDPRESTImplementation::closeFile(int ithr){ -#ifdef VERBOSE - cout << "In closeFile for thread " << ithr << endl; -#endif + FILE_LOG(logDEBUG) << __AT__ << "called for thread " << ithr; if(!dataCompression){ if(sfilefd){ @@ -1005,6 +1083,8 @@ void UDPRESTImplementation::closeFile(int ithr){ #endif } + + FILE_LOG(logDEBUG) << __AT__ << "exited for thread " << ithr; } @@ -1014,13 +1094,32 @@ void UDPRESTImplementation::closeFile(int ithr){ int UDPRESTImplementation::startReceiver(char message[]){ int i; + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + initialize_REST(); + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " initialized"; // #ifdef VERBOSE cout << "Starting Receiver" << endl; //#endif + std::string answer; + int code; + + + //test = "{\"configfile\":\"config.pu\", \"path\":\"patto\"}"; + code = rest->post_json("state/configure", &answer); + std::cout << answer << std::endl; + code = rest->get_json("state", &answer); + std::cout << answer << std::endl; + + code = rest->post_json("state/open", &answer); + std::cout << answer << std::endl; + code = rest->get_json("state", &answer); + std::cout << answer << std::endl; + //reset listening thread variables + /* measurementStarted = false; //should be set to zero as its added to get next start frame indices for scans for eiger if(!acqStarted) currframenum = 0; @@ -1028,8 +1127,9 @@ int UDPRESTImplementation::startReceiver(char message[]){ for(int i = 0; i < numListeningThreads; ++i) totalListeningFrameCount[i] = 0; - + */ //udp socket + /* if(createUDPSockets() == FAIL){ strcpy(message,"Could not create UDP Socket(s).\n"); cout << endl << message << endl; @@ -1037,7 +1137,8 @@ int UDPRESTImplementation::startReceiver(char message[]){ } cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; - + */ + /* if(setupWriter() == FAIL){ //stop udp socket shutDownUDPSockets(); @@ -1069,7 +1170,7 @@ int UDPRESTImplementation::startReceiver(char message[]){ sem_post(&listensmp[i]); for(i=0; i < numWriterThreads; ++i) sem_post(&writersmp[i]); - + */ cout << "Receiver Started.\nStatus:" << status << endl; @@ -1081,10 +1182,7 @@ int UDPRESTImplementation::startReceiver(char message[]){ int UDPRESTImplementation::stopReceiver(){ - -//#ifdef VERBOSE - cout << "Stopping Receiver" << endl; -//#endif + FILE_LOG(logDEBUG) << __AT__ << "called"; if(status == RUNNING) startReadout(); @@ -1101,7 +1199,8 @@ int UDPRESTImplementation::stopReceiver(){ status = IDLE; pthread_mutex_unlock(&(status_mutex)); - cout << "Receiver Stopped.\nStatus:" << status << endl << endl; + FILE_LOG(logDEBUG) << __AT__ << "exited, status " << endl; + return OK; } @@ -1110,10 +1209,7 @@ int UDPRESTImplementation::stopReceiver(){ void UDPRESTImplementation::startReadout(){ - - //#ifdef VERBOSE - cout << "Start Receiver Readout" << endl; - //#endif + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; //wait so that all packets which take time has arrived usleep(50000); @@ -1127,6 +1223,7 @@ void UDPRESTImplementation::startReadout(){ //kill udp socket to tell the listening thread to push last packet shutDownUDPSockets(); + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 19ea6ccedc..6f2f7eb695 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -127,8 +127,8 @@ void UDPStandardImplementation::initializeMembers(){ UDPStandardImplementation::UDPStandardImplementation(){ - cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa" << endl; - + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting" ; + thread_started = 0; eth = NULL; latestData = NULL; @@ -963,7 +963,7 @@ int UDPStandardImplementation::shutDownUDPSockets(){ - +// TODO: add a destroyListeningThreads int UDPStandardImplementation::createListeningThreads(bool destroy){ int i; void* status; @@ -974,6 +974,8 @@ int UDPStandardImplementation::createListeningThreads(bool destroy){ listeningthreads_mask = 0x0; pthread_mutex_unlock(&(status_mutex)); + FILE_LOG(logDEBUG) << "Starting " << __func__ << endl; + if(!destroy){ //start listening threads diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index f051592ced..fcb0bb1010 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -8,7 +8,7 @@ #include #include #include - +#include #include #include "slsReceiver.h" @@ -30,10 +30,12 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ */ //creating base receiver + map configuration_map; int tcpip_port_no = 1954; success=OK; string fname = ""; string udp_interface_type = "standard"; + string rest_hostname = "localhost:8081"; //parse command line for config static struct option long_options[] = { @@ -44,6 +46,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ {"type", required_argument, 0, 't'}, {"config", required_argument, 0, 'f'}, {"rx_tcpport", required_argument, 0, 'b'}, + {"rest_hostname", required_argument, 0, 'r'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; @@ -52,7 +55,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ int c; while ( c != -1 ){ - c = getopt_long (argc, argv, "bfht", long_options, &option_index); + c = getopt_long (argc, argv, "bfhtr", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) @@ -72,12 +75,19 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ udp_interface_type = optarg; break; + case 'r': + rest_hostname = optarg; + break; + case 'h': string help_message = """\nSLS Receiver Server\n\n"""; help_message += """usage: slsReceiver --config config_fname [--rx_tcpport port]\n\n"""; help_message += """\t--config:\t configuration filename for SLS Detector receiver\n"""; help_message += """\t--rx_tcpport:\t TCP Communication Port with the client. Default: 1954.\n\n"""; + help_message += """\t--rest_hostname:\t Receiver hostname:port. It applies only to REST receivers, and indicates the hostname of the REST backend. Default: localhost:8081.\n\n"""; + help_message += """\t--type:\t Type of the receiver. Possible arguments are: standard, REST. Default: standard.\n\n"""; + cout << help_message << endl; break; @@ -91,7 +101,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ if( !fname.empty() ){ try{ FILE_LOG(logINFO) << "config file name " << fname; - success = read_config_file(fname, &tcpip_port_no); + success = read_config_file(fname, &tcpip_port_no, &configuration_map); //VERBOSE_PRINT("Read configuration file of " + iline + " lines"); } catch(...){ @@ -108,6 +118,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ if (success==OK){ FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << endl; udp_interface = UDPInterface::create(udp_interface_type); + udp_interface->configure(configuration_map); tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no); //tcp ip interface } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index ea59d4bce1..275a6c9326 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -69,14 +69,13 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* //Catch signal SIGINT to close files properly signal(SIGINT,staticCloseFile); - } } } int slsReceiverTCPIPInterface::setPortNumber(int pn){ - int p_number; + int p_number; MySocketTCP *oldsocket=NULL;; int sd=0; @@ -144,10 +143,12 @@ void slsReceiverTCPIPInterface::stop(){ cout<<"Shutting down TCP Socket and TCP thread"<ShutDownSocket(); + cout<<"Socket closed"<setEthernetInterface(eth); //get mac address from ethernet interface diff --git a/slsReceiverSoftware/src/utilities.cpp b/slsReceiverSoftware/src/utilities.cpp index ae401a5ccd..afb5a6c655 100644 --- a/slsReceiverSoftware/src/utilities.cpp +++ b/slsReceiverSoftware/src/utilities.cpp @@ -5,19 +5,23 @@ #include #include +#include + #include "utilities.h" using namespace std; -int read_config_file(string fname, int *tcpip_port_no){ +int read_config_file(string fname, int *tcpip_port_no, map * configuration_map ){ ifstream infile; - string sLine,sargname; + string sLine,sargname, sargvalue; int iline = 0; int success = slsReceiverDefs::OK; + + infile.open(fname.c_str(), ios_base::in); if (infile.is_open()) { while(infile.good()){ @@ -26,21 +30,25 @@ int read_config_file(string fname, int *tcpip_port_no){ //VERBOSE_PRINT(sLine); - if(sLine.find('#')!=string::npos){ - //VERBOSE_PRINT( "Line is a comment "); + if(sLine.find('#') != string::npos) continue; - } - else if(sLine.length()<2){ - //VERBOSE_PRINT("Empty line "); + + else if(sLine.length()<2) continue; - } + else{ istringstream sstr(sLine); //parameter name - if(sstr.good()) + if(sstr.good()){ sstr >> sargname; + if (! sstr.good()) + continue; + + sstr >> sargvalue; + (*configuration_map)[sargname] = sargvalue; + } //tcp port if(sargname=="rx_tcpport"){ if(sstr.good()) { From e5864d4343a0df9c2a8eed524a793c4a828a4728 Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Mon, 22 Sep 2014 11:45:01 +0200 Subject: [PATCH 040/222] Added status resetting for REST --- slsReceiverSoftware/include/UDPInterface.h | 26 +--- .../include/UDPRESTImplementation.h | 2 + .../src/UDPBaseImplementation.cpp | 20 ++- slsReceiverSoftware/src/UDPInterface.cpp | 11 -- .../src/UDPRESTImplementation.cpp | 137 ++++++++++++++---- .../src/slsReceiverTCPIPInterface.cpp | 47 +++--- 6 files changed, 157 insertions(+), 86 deletions(-) diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index e2454e09be..60d9cc75b3 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -21,19 +21,15 @@ #include "utilities.h" #include "logger.h" -/* -void print_not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; -} -*/ + class UDPInterface { - /* abstract class that defines the public interface of an sls detector data receiver. + /* abstract class that defines the public interface of an sls detector data receiver UDP part. * * Use the factory method slsReceiverBase::create() to get an instance: * - * slsReceiverBase *receiver = slsReceiverBase::create() + * UDPInterface *receiver = UDPInterface::create() * * supported sequence of method-calls: * @@ -64,11 +60,6 @@ class UDPInterface { public: - /** - * constructor - */ - //UDPInterface(){}; - /** * Destructor */ @@ -80,11 +71,10 @@ class UDPInterface { static UDPInterface *create(string receiver_type = "standard"); virtual void configure(map config_map) = 0; + public: - - /** * Initialize the Receiver @param detectorHostName detector hostname @@ -94,10 +84,10 @@ class UDPInterface { /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ virtual char *getDetectorHostname() const = 0; /** diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index 30cd782ede..32213f50c7 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -48,8 +48,10 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI virtual ~UDPRESTImplementation(); + protected: void initialize_REST(); + public: void configure(map config_map); /** diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index c831621ee5..58d0f2395d 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -2121,12 +2121,24 @@ int UDPBaseImplementation::enableTenGiga(int enable){ createWriterThreads(true); } for(int i=0;i // SIGINT -#include // stat -#include // socket(), bind(), listen(), accept(), shut down -#include // sock_addr_in, htonl, INADDR_ANY -#include // exit() -#include //set precision -#include //munmap -*/ - #include #include using namespace std; @@ -35,7 +25,6 @@ UDPInterface * UDPInterface::create(string receiver_type){ cout << "Starting " << receiver_type << endl; return new UDPStandardImplementation(); } - //#ifdef REST else if (receiver_type == "REST"){ return new UDPRESTImplementation(); diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index 8f40e95524..5ae3e670c5 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -31,12 +31,14 @@ using namespace std; /* TODO + filePath != getFilePath - + + better state handling. Now it is only IDLE - RUNNING - IDLE */ UDPRESTImplementation::UDPRESTImplementation(){ - + FILE_LOG(logDEBUG) << __AT__ << " called"; + + // Default values rest_hostname = "localhost"; rest_port = 8081; } @@ -57,20 +59,21 @@ void UDPRESTImplementation::configure(map config_map){ if(pos != string::npos){ istringstream (host_port_str.substr (pos)) >> rest_port; rest_hostname = host_port_str.substr(0, pos); - cout << rest_hostname << " " << rest_port << endl; } } - + + /* for(map::const_iterator i=config_map.begin(); i != config_map.end(); i++){ std::cout << i->first << " " << i->second<< std::endl; } - + */ }; void UDPRESTImplementation::initialize_REST(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; if (rest_hostname.empty()) { FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; @@ -116,7 +119,6 @@ void UDPRESTImplementation::initialize_REST(){ ss >> test; - cout << "aaaa" <post_json("state/initialize", &answer, test); FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; @@ -147,17 +149,34 @@ int UDPRESTImplementation::setDetectorType(detectorType det){ /*Frame indices and numbers caught*/ -bool UDPRESTImplementation::getAcquistionStarted(){return acqStarted;}; +bool UDPRESTImplementation::getAcquistionStarted(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return acqStarted; +}; -bool UDPRESTImplementation::getMeasurementStarted(){return measurementStarted;}; +bool UDPRESTImplementation::getMeasurementStarted(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return measurementStarted; +}; -int UDPRESTImplementation::getFramesCaught(){return (packetsCaught/packetsPerFrame);} +int UDPRESTImplementation::getFramesCaught(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return (packetsCaught/packetsPerFrame); +} -int UDPRESTImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);} +int UDPRESTImplementation::getTotalFramesCaught(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return (totalPacketsCaught/packetsPerFrame); +} -uint32_t UDPRESTImplementation::getStartFrameIndex(){return startFrameIndex;} +uint32_t UDPRESTImplementation::getStartFrameIndex(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return startFrameIndex; +} uint32_t UDPRESTImplementation::getFrameIndex(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + if(!packetsCaught) frameIndex=-1; else @@ -167,15 +186,22 @@ uint32_t UDPRESTImplementation::getFrameIndex(){ uint32_t UDPRESTImplementation::getAcquisitionIndex(){ + //FILE_LOG(logDEBUG) << __AT__ << " called, idx: " << acquisitionIndex; if(!totalPacketsCaught) - acquisitionIndex=-1; + acquisitionIndex = -1; else acquisitionIndex = currframenum - startAcquisitionIndex; + + //FILE_LOG(logDEBUG) << __AT__ << " idx: " << acquisitionIndex + // << " currframenum: " << currframenum + // << " startAcqIdx: " << startAcquisitionIndex; + return acquisitionIndex; } void UDPRESTImplementation::resetTotalFramesCaught(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; acqStarted = false; startAcquisitionIndex = 0; totalPacketsCaught = 0; @@ -184,21 +210,23 @@ void UDPRESTImplementation::resetTotalFramesCaught(){ /*file parameters*/ int UDPRESTImplementation::getFileIndex(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; return fileIndex; } int UDPRESTImplementation::setFileIndex(int i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; - /* + if(i>=0) fileIndex = i; - */ + return getFileIndex(); } int UDPRESTImplementation::setFrameIndexNeeded(int i){ - cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; + FILE_LOG(logDEBUG) << __AT__ << " called"; frameIndexNeeded = i; return frameIndexNeeded; } @@ -230,6 +258,7 @@ int UDPRESTImplementation::setEnableOverwrite(int i){ /*other parameters*/ slsReceiverDefs::runStatus UDPRESTImplementation::getStatus() const{ + FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status; return status; } @@ -243,12 +272,15 @@ char *UDPRESTImplementation::getDetectorHostname() const{ void UDPRESTImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + + // TODO: this segfaults //strcpy(eth,c); - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; + //FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; } void UDPRESTImplementation::setUDPPortNo(int p){ + FILE_LOG(logDEBUG) << __AT__ << " called"; for(int i=0;i=0){ nFrameToGui = i; setupFifoStructure(); @@ -339,7 +373,7 @@ int UDPRESTImplementation::setNFrameToGui(int i){ int64_t UDPRESTImplementation::setAcquisitionPeriod(int64_t index){ - + FILE_LOG(logDEBUG) << __AT__ << " called"; if(index >= 0){ if(index != acquisitionPeriod){ acquisitionPeriod = index; @@ -350,9 +384,13 @@ int64_t UDPRESTImplementation::setAcquisitionPeriod(int64_t index){ } -bool UDPRESTImplementation::getDataCompression(){return dataCompression;} +bool UDPRESTImplementation::getDataCompression(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return dataCompression; +} int UDPRESTImplementation::enableDataCompression(bool enable){ + FILE_LOG(logDEBUG) << __AT__ << " called"; cout << "Data compression "; if(enable) cout << "enabled" << endl; @@ -406,6 +444,7 @@ int UDPRESTImplementation::enableDataCompression(bool enable){ void UDPRESTImplementation::deleteFilter(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int i; cmSub=NULL; @@ -423,6 +462,7 @@ void UDPRESTImplementation::deleteFilter(){ void UDPRESTImplementation::setupFilter(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; double hc = 0; double sigma = 5; int sign = 1; @@ -459,6 +499,11 @@ void UDPRESTImplementation::setupFilter(){ //LEO: it is not clear to me.. void UDPRESTImplementation::setupFifoStructure(){ + FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; +} +/* +void UDPRESTImplementation::setupFifoStructure(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int64_t i; int oldn = numJobsPerThread; @@ -504,10 +549,6 @@ void UDPRESTImplementation::setupFifoStructure(){ cout << "Number of Frames per buffer:" << numJobsPerThread << endl; cout << "Fifo Size:" << fifosize << endl; - /* - //for testing - numJobsPerThread = 3; fifosize = 11; - */ for(int i=0;iget_json("state", &answer); + std::cout << answer << std::endl; + + code = rest->post_json("state/close", &answer); + std::cout << answer << std::endl; + code = rest->post_json("state/reset", &answer); + std::cout << answer << std::endl; + + code = rest->get_json("state", &answer); + std::cout << answer << std::endl; + + status = slsReceiverDefs::IDLE; + + /* for(int i=0;iget_json("state", &answer); std::cout << answer << std::endl; + status = slsReceiverDefs::RUNNING; //reset listening thread variables /* @@ -1172,8 +1237,6 @@ int UDPRESTImplementation::startReceiver(char message[]){ sem_post(&writersmp[i]); */ - cout << "Receiver Started.\nStatus:" << status << endl; - return OK; } @@ -1230,6 +1293,8 @@ void UDPRESTImplementation::startReadout(){ void* UDPRESTImplementation::startListeningThread(void* this_pointer){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + ((UDPRESTImplementation*)this_pointer)->startListening(); return this_pointer; @@ -1238,6 +1303,7 @@ void* UDPRESTImplementation::startListeningThread(void* this_pointer){ void* UDPRESTImplementation::startWritingThread(void* this_pointer){ + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPRESTImplementation*)this_pointer)->startWriting(); return this_pointer; } @@ -1248,6 +1314,8 @@ void* UDPRESTImplementation::startWritingThread(void* this_pointer){ int UDPRESTImplementation::startListening(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int ithread = currentListeningThreadIndex; #ifdef VERYVERBOSE cout << "In startListening() " << endl; @@ -1449,6 +1517,7 @@ int UDPRESTImplementation::startListening(){ int UDPRESTImplementation::startWriting(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE cout << ithread << "In startWriting()" <0) - port_no = pn; - - success=OK; - + myDetectorType(GOTTHARD), + receiverBase(rbase), + ret(OK), + lockStatus(0), + shortFrame(-1), + packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), + dynamicrange(16), + socket(NULL), + killTCPServerThread(0), + tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2){ + + int port_no=portNumber; + + + if (pn>0) + port_no = pn; + + success=OK; + //create socket if(success == OK){ socket = new MySocketTCP(port_no); @@ -56,24 +56,25 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* delete socket; socket=NULL; } else { - portNumber=port_no; + portNumber=port_no; //initialize variables strcpy(socket->lastClientIP,"none"); strcpy(socket->thisClientIP,"none1"); strcpy(mess,"dummy message"); - + function_table(); #ifdef VERBOSE cout << "Function table assigned." << endl; #endif - + //Catch signal SIGINT to close files properly signal(SIGINT,staticCloseFile); } } - + } + int slsReceiverTCPIPInterface::setPortNumber(int pn){ int p_number; MySocketTCP *oldsocket=NULL;; From f05248cd3202613e989dbd9215fc2e71b5ff65d4 Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Mon, 22 Sep 2014 14:09:31 +0200 Subject: [PATCH 041/222] fixes --- .../src/UDPRESTImplementation.cpp | 190 +++++++----------- .../src/UDPStandardImplementation.cpp | 90 +++++++-- 2 files changed, 153 insertions(+), 127 deletions(-) diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index 5ae3e670c5..c3f6bf836d 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -44,7 +44,9 @@ UDPRESTImplementation::UDPRESTImplementation(){ } -UDPRESTImplementation::~UDPRESTImplementation(){} +UDPRESTImplementation::~UDPRESTImplementation(){ + delete rest; +} void UDPRESTImplementation::configure(map config_map){ @@ -74,67 +76,67 @@ void UDPRESTImplementation::configure(map config_map){ void UDPRESTImplementation::initialize_REST(){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - if (rest_hostname.empty()) { - FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; - } - else if (isInitialized == true) { - FILE_LOG(logDEBUG) << __AT__ << "already initialized, can't initialize several times"; - } - else { - FILE_LOG(logDEBUG) << __AT__ << "with receiverHostName=" << rest_hostname << ":" << rest_port; - - rest = new RestHelper() ; - std::string answer; - int code; - try{ - rest->init(rest_hostname, rest_port); - code = rest->get_json("state", &answer); - - if (code != 0){ - throw answer; - } - else{ - isInitialized = true; - status = slsReceiverDefs::IDLE; - } - FILE_LOG(logDEBUG) << __func__ << "Answer: " << answer; - } - catch(std::string e){ - FILE_LOG(logERROR) << __func__ << ": " << e; - throw; - } - - //JsonBox::Object json_object; - //json_object["configfile"] = JsonBox::Value("FILENAME"); - JsonBox::Value json_request; - //json_request["configfile"] = "config.py"; - json_request["path"] = filePath; - - stringstream ss; - string test; - std::cout << "GetSTring: " << json_request << std::endl; - json_request.writeToStream(ss, false); - //ss << json_request; - ss >> test; - - - test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; - code = rest->post_json("state/initialize", &answer, test); - FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; - code = rest->get_json("state", &answer); - FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer; - - - /* - std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl; - JsonBox::Value json_value; - code = rest.get_json("status", &json_value); - std::cout << "JSON " << json_value["status"] << std::endl; + + if (rest_hostname.empty()) { + FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; + } + else if (isInitialized == true) { + FILE_LOG(logDEBUG) << __AT__ << "already initialized, can't initialize several times"; + } + else { + FILE_LOG(logDEBUG) << __AT__ << "with receiverHostName=" << rest_hostname << ":" << rest_port; + + rest = new RestHelper() ; + std::string answer; + int code; + try{ + rest->init(rest_hostname, rest_port); + code = rest->get_json("state", &answer); + + if (code != 0){ + throw answer; + } + else{ + isInitialized = true; + status = slsReceiverDefs::IDLE; + } + FILE_LOG(logDEBUG) << __func__ << "Answer: " << answer; + } + catch(std::string e){ + FILE_LOG(logERROR) << __func__ << ": " << e; + throw; + } + + //JsonBox::Object json_object; + //json_object["configfile"] = JsonBox::Value("FILENAME"); + JsonBox::Value json_request; + //json_request["configfile"] = "config.py"; + json_request["path"] = filePath; + + stringstream ss; + string test; + std::cout << "GetSTring: " << json_request << std::endl; + json_request.writeToStream(ss, false); + //ss << json_request; + ss >> test; + + + test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; + code = rest->post_json("state/initialize", &answer, test); + FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; + code = rest->get_json("state", &answer); + FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer; + + + /* + std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl; + JsonBox::Value json_value; + code = rest.get_json("status", &json_value); + std::cout << "JSON " << json_value["status"] << std::endl; */ - } - - FILE_LOG(logDEBUG) << __func__ << ": initialize() done"; + } + + FILE_LOG(logDEBUG) << __func__ << ": initialize() done"; } @@ -166,6 +168,10 @@ int UDPRESTImplementation::getFramesCaught(){ int UDPRESTImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if (packetsPerFrame == 0){ + FILE_LOG(logWARNING) << __AT__ << " packetsPerFrame is 0!!!"; + return 0; + } return (totalPacketsCaught/packetsPerFrame); } @@ -216,7 +222,6 @@ int UDPRESTImplementation::getFileIndex(){ int UDPRESTImplementation::setFileIndex(int i){ FILE_LOG(logDEBUG) << __AT__ << " called"; - cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; if(i>=0) fileIndex = i; @@ -390,56 +395,12 @@ bool UDPRESTImplementation::getDataCompression(){ } int UDPRESTImplementation::enableDataCompression(bool enable){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - cout << "Data compression "; - if(enable) - cout << "enabled" << endl; - else - cout << "disabled" << endl; -#ifdef MYROOT1 - cout << " WITH ROOT" << endl; -#else - cout << " WITHOUT ROOT" << endl; -#endif - //delete filter for the current number of threads - deleteFilter(); - - dataCompression = enable; - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - createWriterThreads(true); - - if(enable) - numWriterThreads = MAX_NUM_WRITER_THREADS; - else - numWriterThreads = 1; - - if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; - return FAIL; - } - setThreadPriorities(); - - - if(enable) - setupFilter(); - + FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; return OK; } - - - - - - - - - /*other functions*/ @@ -462,6 +423,8 @@ void UDPRESTImplementation::deleteFilter(){ void UDPRESTImplementation::setupFilter(){ + //LEO: check + FILE_LOG(logDEBUG) << __AT__ << " called"; double hc = 0; double sigma = 5; @@ -698,7 +661,7 @@ int UDPRESTImplementation::createUDPSockets(){ } //normal socket else{ - cout<<"eth:"<get_json("state", &answer); @@ -742,7 +704,7 @@ int UDPRESTImplementation::shutDownUDPSockets(){ code = rest->get_json("state", &answer); std::cout << answer << std::endl; - status = slsReceiverDefs::IDLE; + status = slsReceiverDefs::RUN_FINISHED; @@ -1744,7 +1706,11 @@ void UDPRESTImplementation::startFrameIndices(int ithread){ } +void UDPRESTImplementation::stopListening(int ithread, int rc, int &pc, int &t){ + FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; +}; +/* void UDPRESTImplementation::stopListening(int ithread, int rc, int &pc, int &t){ FILE_LOG(logDEBUG) << __AT__ << " called"; @@ -1754,7 +1720,7 @@ int i; cerr << ithread << " recvfrom() failed:"<push(buffer[ithread]); exit(-1); } @@ -1815,7 +1781,7 @@ int i; } } - +*/ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 6f2f7eb695..b3e8aa0980 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -125,7 +125,8 @@ void UDPStandardImplementation::initializeMembers(){ } -UDPStandardImplementation::UDPStandardImplementation(){ +UDPStandardImplementation::UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting" ; @@ -182,7 +183,8 @@ UDPStandardImplementation::UDPStandardImplementation(){ -UDPStandardImplementation::~UDPStandardImplementation(){ +UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + createListeningThreads(true); createWriterThreads(true); deleteMembers(); @@ -191,7 +193,8 @@ UDPStandardImplementation::~UDPStandardImplementation(){ -void UDPStandardImplementation::deleteMembers(){ +void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + //kill threads if(thread_started){ createListeningThreads(true); @@ -224,7 +227,8 @@ void UDPStandardImplementation::deleteMembers(){ -int UDPStandardImplementation::setDetectorType(detectorType det){ +int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logDEBUG) << __AT__ << " called"; + cout << "Setting Receiver Type " << endl; deleteMembers(); @@ -451,6 +455,9 @@ int UDPStandardImplementation::setEnableOverwrite(int i){ /*other parameters*/ slsReceiverDefs::runStatus UDPStandardImplementation::getStatus() const{ + FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status; + + return status; } @@ -465,12 +472,14 @@ char *UDPStandardImplementation::getDetectorHostname() const{ return (char*)detHostname; } -void UDPStandardImplementation::setEthernetInterface(char* c){ +void UDPStandardImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " called"; + strcpy(eth,c); } -void UDPStandardImplementation::setUDPPortNo(int p){ +void UDPStandardImplementation::setUDPPortNo(int p){ FILE_LOG(logDEBUG) << __AT__ << " called"; + for(int i=0;i= 0) numberOfFrames = fnum; @@ -494,7 +504,8 @@ int UDPStandardImplementation::getScanTag() const{ } -int32_t UDPStandardImplementation::setScanTag(int32_t stag){ +int32_t UDPStandardImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if(stag >= 0) scanTag = stag; @@ -506,7 +517,8 @@ int UDPStandardImplementation::getDynamicRange() const{ return dynamicRange; } -int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ +int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " called"; + cout << "Setting Dynamic Range" << endl; int olddr = dynamicRange; @@ -566,7 +578,8 @@ int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ -int UDPStandardImplementation::setShortFrame(int i){ +int UDPStandardImplementation::setShortFrame(int i){ FILE_LOG(logDEBUG) << __AT__ << " called"; + shortFrame=i; if(shortFrame!=-1){ @@ -596,7 +609,8 @@ int UDPStandardImplementation::setShortFrame(int i){ } -int UDPStandardImplementation::setNFrameToGui(int i){ +int UDPStandardImplementation::setNFrameToGui(int i){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if(i>=0){ nFrameToGui = i; setupFifoStructure(); @@ -606,7 +620,8 @@ int UDPStandardImplementation::setNFrameToGui(int i){ -int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ +int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if(index >= 0){ if(index != acquisitionPeriod){ @@ -618,9 +633,11 @@ int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ } -bool UDPStandardImplementation::getDataCompression(){return dataCompression;} +bool UDPStandardImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " called"; +return dataCompression;} + +int UDPStandardImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " called"; -int UDPStandardImplementation::enableDataCompression(bool enable){ cout << "Data compression "; if(enable) cout << "enabled" << endl; @@ -673,7 +690,8 @@ int UDPStandardImplementation::enableDataCompression(bool enable){ /*other functions*/ -void UDPStandardImplementation::deleteFilter(){ +void UDPStandardImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; cmSub=NULL; @@ -691,6 +709,8 @@ void UDPStandardImplementation::deleteFilter(){ void UDPStandardImplementation::setupFilter(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + double hc = 0; double sigma = 5; int sign = 1; @@ -727,6 +747,7 @@ void UDPStandardImplementation::setupFilter(){ //LEO: it is not clear to me.. void UDPStandardImplementation::setupFifoStructure(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int64_t i; int oldn = numJobsPerThread; @@ -816,6 +837,8 @@ void UDPStandardImplementation::setupFifoStructure(){ /** acquisition functions */ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + //point to gui data if (guiData == NULL) guiData = latestData; @@ -850,6 +873,8 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + //random read when gui not ready if((!nFrameToGui) && (!guiData)){ @@ -905,6 +930,7 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, int UDPStandardImplementation::createUDPSockets(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; //if eth is mistaken with ip address @@ -950,6 +976,8 @@ int UDPStandardImplementation::createUDPSockets(){ int UDPStandardImplementation::shutDownUDPSockets(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + for(int i=0;iShutDownSocket(); @@ -965,6 +993,8 @@ int UDPStandardImplementation::shutDownUDPSockets(){ // TODO: add a destroyListeningThreads int UDPStandardImplementation::createListeningThreads(bool destroy){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; void* status; @@ -1022,6 +1052,8 @@ int UDPStandardImplementation::createListeningThreads(bool destroy){ int UDPStandardImplementation::createWriterThreads(bool destroy){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; void* status; @@ -1083,6 +1115,8 @@ int UDPStandardImplementation::createWriterThreads(bool destroy){ void UDPStandardImplementation::setThreadPriorities(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; //assign priorities struct sched_param tcp_param, listen_param, write_param; @@ -1120,6 +1154,7 @@ void UDPStandardImplementation::setThreadPriorities(){ int UDPStandardImplementation::setupWriter(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; //reset writing thread variables packetsInFile=0; @@ -1203,6 +1238,8 @@ int UDPStandardImplementation::setupWriter(){ int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + #ifdef MYROOT1 char temp[MAX_STR_LENGTH]; //create file name for gui purposes, and set up acquistion parameters @@ -1231,6 +1268,8 @@ int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){ int UDPStandardImplementation::createNewFile(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int gt = getFrameIndex(); if(gt==-1) gt=0; //create file name @@ -1295,6 +1334,8 @@ int UDPStandardImplementation::createNewFile(){ void UDPStandardImplementation::closeFile(int ithr){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + #ifdef VERBOSE cout << "In closeFile for thread " << ithr << endl; #endif @@ -1352,6 +1393,8 @@ void UDPStandardImplementation::closeFile(int ithr){ int UDPStandardImplementation::startReceiver(char message[]){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; @@ -1420,6 +1463,7 @@ int UDPStandardImplementation::startReceiver(char message[]){ int UDPStandardImplementation::stopReceiver(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; //#ifdef VERBOSE @@ -1450,6 +1494,7 @@ int UDPStandardImplementation::stopReceiver(){ void UDPStandardImplementation::startReadout(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; //#ifdef VERBOSE cout << "Start Receiver Readout" << endl; @@ -1473,6 +1518,7 @@ void UDPStandardImplementation::startReadout(){ void* UDPStandardImplementation::startListeningThread(void* this_pointer){ + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startListening(); return this_pointer; @@ -1481,6 +1527,7 @@ void* UDPStandardImplementation::startListeningThread(void* this_pointer){ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startWriting(); return this_pointer; } @@ -1491,6 +1538,7 @@ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ int UDPStandardImplementation::startListening(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int ithread = currentListeningThreadIndex; #ifdef VERYVERBOSE cout << "In startListening() " << endl; @@ -1692,6 +1740,8 @@ int UDPStandardImplementation::startListening(){ int UDPStandardImplementation::startWriting(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE cout << ithread << "In startWriting()" < Date: Fri, 26 Sep 2014 11:19:26 +0200 Subject: [PATCH 042/222] udpport2 module --- .../slsReceiver/slsReceiverBase.h | 5 +++++ .../slsReceiver/slsReceiverTCPIPInterface.cpp | 7 ++++--- .../slsReceiver/slsReceiverUDPFunctions.cpp | 17 +++++++++++++---- .../slsReceiver/slsReceiverUDPFunctions.h | 5 +++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverBase.h b/slsReceiverSoftware/slsReceiver/slsReceiverBase.h index 97d21bec45..41408f7e78 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverBase.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverBase.h @@ -232,6 +232,11 @@ class slsReceiverBase { */ virtual void setUDPPortNo(int p) = 0; + /** + * Set UDP Port Number + */ + virtual void setUDPPortNo2(int p) = 0; + /** * Set Ethernet Interface or IP to listen to */ diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp index 2ebfd38264..ef854bc59d 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.cpp @@ -613,10 +613,10 @@ int slsReceiverTCPIPInterface::setup_udp(){ ret=OK; strcpy(mess,"could not set up udp connection"); char retval[MAX_STR_LENGTH]=""; - char args[2][MAX_STR_LENGTH]; + char args[3][MAX_STR_LENGTH]; string temp; - int udpport; + int udpport,udpport2; char eth[MAX_STR_LENGTH]; @@ -641,8 +641,9 @@ int slsReceiverTCPIPInterface::setup_udp(){ else{ //set up udp port sscanf(args[1],"%d",&udpport); + sscanf(args[2],"%d",&udpport2); receiverBase->setUDPPortNo(udpport); - + receiverBase->setUDPPortNo2(udpport2); //setup udpip //get ethernet interface or IP to listen to temp = genericSocket::ipToName(args[0]); diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index ac73e78c0c..388272b6ba 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -443,9 +443,16 @@ void slsReceiverUDPFunctions::setEthernetInterface(char* c){ void slsReceiverUDPFunctions::setUDPPortNo(int p){ - for(int i=0;igetErrorStatus(); - if(iret){ + if(!iret) + cout << "UDP port opened at port " << server_port[i] << endl; + else{ #ifdef VERBOSE cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; #endif diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h index c955ee1c43..20c5d76338 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h @@ -213,6 +213,11 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public slsRecei */ void setUDPPortNo(int p); + /** + * Set UDP Port Number2 + */ + void setUDPPortNo2(int p); + /* * Returns number of frames to receive * This is the number of frames to expect to receiver from the detector. From e94e678f7ddf5cd4eb8d38c0818bca585148e1de Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Tue, 14 Oct 2014 15:42:32 +0200 Subject: [PATCH 043/222] receiver bottom module included, and image reconstruction works for all bit modes, receiver still for a half module each, although two of them combined to make one module image --- .../slsReceiver/slsReceiver.cpp | 32 ++++- .../slsReceiver/slsReceiverTCPIPInterface.cpp | 118 +++++++++++++----- .../slsReceiver/slsReceiverTCPIPInterface.h | 6 +- .../slsReceiver/slsReceiverUDPFunctions.cpp | 40 +++--- .../slsReceiver/slsReceiverUDPFunctions.h | 5 +- 5 files changed, 146 insertions(+), 55 deletions(-) diff --git a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp index cd5ab551d1..f044f7b7fd 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiver.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiver.cpp @@ -18,9 +18,8 @@ using namespace std; slsReceiver::slsReceiver(int argc, char *argv[], int &success){ //creating base receiver cout << "SLS Receiver" << endl; - receiverBase = new slsReceiverUDPFunctions(); int tcpip_port_no=-1; - + bool bottom = false; ifstream infile; @@ -116,6 +115,31 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ } } } + + //mode top:bottom + else if(!strcasecmp(argv[iarg],"-mode")){ + if(iarg+1==argc){ + cout << "no mode given after -mode in command line. Exiting." << endl; + success=FAIL; + }else{ + if(!strcasecmp(argv[iarg+1],"bottom")){ + cout<<"mode: bottom"< #include #include +#include //linux5 +#define be64toh(x) __bswap_64 (x) //linux5 +//#include //linux6 using namespace std; @@ -28,7 +31,7 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { } -slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn): +slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn, bool bot): myDetectorType(GOTTHARD), receiverBase(rbase), ret(OK), @@ -38,7 +41,8 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, slsReceiverBa dynamicrange(16), socket(NULL), killTCPServerThread(0), - tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2){ + tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2), + bottom(bot){ int port_no=portNumber; @@ -1336,7 +1340,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ } /**proper frame*/ - else{ + else{//cout<<"**** got proper frame ******"<> 8) & 0x00FF00FF00FF00FFULL ); temp = ((temp << 16) & 0xFFFF0000FFFF0000ULL ) | ((temp >> 16) & 0x0000FFFF0000FFFFULL ); temp = (temp << 32) | ((temp >> 32) & 0xFFFFFFFFULL); (*(((uint64_t*)retval)+i)) = temp; + */ } -/* - ( (((val) >> 56) & 0x00000000000000FF) | (((val) >> 40) & 0x000000000000FF00) | \ - (((val) >> 24) & 0x0000000000FF0000) | (((val) >> 8) & 0x00000000FF000000) | \ - (((val) << 8) & 0x000000FF00000000) | (((val) << 24) & 0x0000FF0000000000) | \ - (((val) << 40) & 0x00FF000000000000) | (((val) << 56) & 0xFF00000000000000) ) - */ - /* - for(i=0;i<(1024*(16*dynamicrange)*2)/4;i++) - (*(((uint32_t*)retval)+i)) = htonl((uint32_t)(*(((uint32_t*)retval)+i))); - */ arg = index-startIndex; } } diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h index 423d0949ab..ccd27c2554 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverTCPIPInterface.h @@ -26,8 +26,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { * @param succecc socket creation was successfull * @param rbase pointer to the receiver base * @param pn port number (defaults to default port number) + * @param bot mode is bottom if true, else its a top half module */ - slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn=-1); + slsReceiverTCPIPInterface(int &success, slsReceiverBase* rbase, int pn=-1, bool bot=false); /** * Sets the port number to listen to. @@ -272,6 +273,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** port number */ int portNumber; + /** true if bottom half module for eiger */ + bool bottom; + protected: /** Socket */ diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index 388272b6ba..aa9458377a 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -31,13 +31,14 @@ using namespace std; -slsReceiverUDPFunctions::slsReceiverUDPFunctions(): +slsReceiverUDPFunctions::slsReceiverUDPFunctions(bool bot): thread_started(0), eth(NULL), latestData(NULL), guiFileName(NULL), guiFrameNumber(0), - tengigaEnable(0){ + tengigaEnable(0), + bottom(bot){ for(int i=0;igetErrorStatus(); if(!iret) - cout << "UDP port opened at port " << server_port[i] << endl; + cout << "UDP port opened at port " << port[i] << endl; else{ #ifdef VERBOSE - cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; + cout << "Could not create UDP socket on port " << port[i] << " error:" << iret << endl; #endif return FAIL; } @@ -1351,7 +1357,7 @@ int slsReceiverUDPFunctions::startReceiver(char message[]){ cout << endl << message << endl; return FAIL; } - cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; + cout << "UDP socket(s) created successfully." << endl; if(setupWriter() == FAIL){ @@ -1540,9 +1546,9 @@ int slsReceiverUDPFunctions::startListening(){ expected = maxBufferSize - carryonBufferSize; } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif +//#endif @@ -1954,9 +1960,9 @@ int i; #endif pthread_mutex_unlock(&(status_mutex)); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << ": Frames listened to " << dec << ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame) << endl; -#endif +//#endif //waiting for all listening threads to be done, to print final count of frames listened to if(ithread == 0){ diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h index 20c5d76338..d0efecfc3c 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.h @@ -40,7 +40,7 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public slsRecei /** * Constructor */ - slsReceiverUDPFunctions(); + slsReceiverUDPFunctions(bool bot); /** * Destructor @@ -768,6 +768,9 @@ class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public slsRecei * 2 we open, close, write file, callback does not do anything */ int cbAction; + /** true if bottom half module for eiger */ + bool bottom; + public: From f2dddd88cd1973d9d8e29921153d9c7be2e3d173 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Wed, 15 Oct 2014 09:22:17 +0200 Subject: [PATCH 044/222] JUNGFRAU detector type added --- slsReceiverSoftware/includes/sls_receiver_defs.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/includes/sls_receiver_defs.h b/slsReceiverSoftware/includes/sls_receiver_defs.h index 70fc6ece87..2381621c04 100755 --- a/slsReceiverSoftware/includes/sls_receiver_defs.h +++ b/slsReceiverSoftware/includes/sls_receiver_defs.h @@ -55,7 +55,9 @@ class slsReceiverDefs { GOTTHARD, /**< gotthard */ PICASSO, /**< picasso */ AGIPD, /**< agipd */ - MOENCH /**< moench */ + MOENCH, /**< moench */ + JUNGFRAU, /**< jungfrau */ + JUNGFRAUCTB /**< jungfrauCTBversion */ }; From b85490b528faa7e0f1db0a1b7a3936c26c254b12 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Thu, 16 Oct 2014 14:14:20 +0200 Subject: [PATCH 045/222] the version given to esrf --- slsReceiverSoftware/gitInfo.txt | 10 +++++----- slsReceiverSoftware/includes/gitInfoReceiver.h | 10 +++++----- .../slsReceiver/slsReceiverUDPFunctions.cpp | 14 ++++++++------ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 355fd15244..410c414c31 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repsitory UUID: d2553484f575ec21e35c0a782cc307f9e0115554 -Revision: 16 +Repsitory UUID: e019a6ce7d96d4ac9cb5762b7137245aedb4d5b8 +Revision: 22 Branch: master -Last Changed Author: Maliakal_Dhanya -Last Changed Rev: 16 -Last Changed Date: 2014-07-31 12:13:15 +0200 +Last Changed Author: Anna_Bergamaschi +Last Changed Rev: 22 +Last Changed Date: 2014-10-15 09:22:40 +0200 diff --git a/slsReceiverSoftware/includes/gitInfoReceiver.h b/slsReceiverSoftware/includes/gitInfoReceiver.h index 586f715b08..967f26e159 100644 --- a/slsReceiverSoftware/includes/gitInfoReceiver.h +++ b/slsReceiverSoftware/includes/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "d2553484f575ec21e35c0a782cc307f9e0115554" -//#define SVNREV 0x16 +#define SVNREPUUID "e019a6ce7d96d4ac9cb5762b7137245aedb4d5b8" +//#define SVNREV 0x22 //#define SVNKIND "" //#define SVNSCHED "" -#define SVNAUTH "Maliakal_Dhanya" -#define SVNREV 0x16 -#define SVNDATE 0x20140731 +#define SVNAUTH "Anna_Bergamaschi" +#define SVNREV 0x22 +#define SVNDATE 0x20141015 // diff --git a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp index aa9458377a..4be1529b41 100644 --- a/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp +++ b/slsReceiverSoftware/slsReceiver/slsReceiverUDPFunctions.cpp @@ -1551,19 +1551,21 @@ int slsReceiverUDPFunctions::startListening(){ //#endif - - //start indices for each start of scan/acquisition - eiger does it before - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); + if((!measurementStarted) && (rc > 0) && (!ithread)) + startFrameIndices(ithread); + //problem in receiving or end of acquisition if((rc < expected)||(rc <= 0)){ stopListening(ithread,rc,packetcount,total); continue; } - - +/* + //start indices for each start of scan/acquisition - eiger does it before + if((!measurementStarted) && (rc > 0) && (!ithread)) + startFrameIndices(ithread); +*/ //reset packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; From 72ba2ae90151d7315314e11dc376c66c8818c68a Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Mon, 27 Oct 2014 12:01:29 +0100 Subject: [PATCH 046/222] offset added to receiver funcs --- slsReceiverSoftware/includes/sls_receiver_defs.h | 4 +++- slsReceiverSoftware/includes/sls_receiver_funcs.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/includes/sls_receiver_defs.h b/slsReceiverSoftware/includes/sls_receiver_defs.h index 2381621c04..f21579ae9a 100755 --- a/slsReceiverSoftware/includes/sls_receiver_defs.h +++ b/slsReceiverSoftware/includes/sls_receiver_defs.h @@ -87,7 +87,9 @@ class slsReceiverDefs { MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */ PROGRESS, /**< fraction of measurement elapsed - only get! */ - MEASUREMENTS_NUMBER + MEASUREMENTS_NUMBER, + FRAMES_FROM_START, + FRAMES_FROM_START_PG }; diff --git a/slsReceiverSoftware/includes/sls_receiver_funcs.h b/slsReceiverSoftware/includes/sls_receiver_funcs.h index bb7655481b..7f3842576e 100644 --- a/slsReceiverSoftware/includes/sls_receiver_funcs.h +++ b/slsReceiverSoftware/includes/sls_receiver_funcs.h @@ -8,7 +8,7 @@ enum { //General functions - F_EXEC_RECEIVER_COMMAND=0, /**< command is executed */ + F_EXEC_RECEIVER_COMMAND=128, /**< command is executed */ F_EXIT_RECEIVER, /**< turn off receiver server */ F_LOCK_RECEIVER, /**< Locks/Unlocks server communication to the given client */ F_GET_LAST_RECEIVER_CLIENT_IP, /**< returns the IP of the client last connected to the receiver */ From 8a63e7e184133b0543c2c3829bef29b8840fc652 Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Wed, 5 Nov 2014 11:43:17 +0100 Subject: [PATCH 047/222] added log printouts. Added hardcoded REST configuration --- slsReceiverSoftware/Makefile | 1 - slsReceiverSoftware/include/RestHelper.h | 15 +-- .../include/UDPRESTImplementation.h | 2 + .../src/UDPBaseImplementation.cpp | 118 ++++++++++-------- .../src/UDPRESTImplementation.cpp | 68 +++++----- 5 files changed, 111 insertions(+), 93 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index b245a634f0..4f90d61077 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -1,4 +1,3 @@ - include ../Makefile.include DESTDIR ?= ../bin diff --git a/slsReceiverSoftware/include/RestHelper.h b/slsReceiverSoftware/include/RestHelper.h index 5c10d0ff9d..93382a6104 100644 --- a/slsReceiverSoftware/include/RestHelper.h +++ b/slsReceiverSoftware/include/RestHelper.h @@ -74,14 +74,11 @@ class RestHelper { */ //Check for http:// string - FILE_LOG(logDEBUG) << __func__ << " starting"; + FILE_LOG(logDEBUG4) << __func__ << " starting"; string proto_str = "http://"; if( size_t found = hostname.find(proto_str) != string::npos ){ - cout << hostname << endl; - char c1[hostname.size()-found-1]; - cout << c1 << endl; size_t length1 = hostname.copy(c1, hostname.size()-found-1, proto_str.size()); c1[length1]='\0'; hostname = c1; @@ -168,7 +165,7 @@ class RestHelper { string answer; int code = send_request(session, req, &answer); if(code == 0 ) { - FILE_LOG(logDEBUG) << "ANSWER " << answer; + FILE_LOG(logDEBUG4) << "REQUEST: " << " ANSWER: " << answer; json_value->loadFromString(answer); } delete uri; @@ -192,7 +189,6 @@ class RestHelper { if (path.empty()) path = "/"; HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); req.setContentType("application/json\r\n"); - cout << "REQUEST BODY " << request_body << endl; req.setContentLength( request_body.length() ); int code = send_request(session, req, answer, request_body); @@ -266,9 +262,8 @@ class RestHelper { if (request_body == "") session->sendRequest( (req) ); else{ - cout << request_body << endl; - ostream &os = session->sendRequest( req ) ; - os << request_body; + ostream &os = session->sendRequest( req ) ; + os << request_body; } HTTPResponse res; @@ -276,7 +271,7 @@ class RestHelper { StreamCopier::copyToString(is, *answer); code = res.getStatus(); if (code != 200){ - cout << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() << endl; + FILE_LOG(logERROR) << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() ; code = -1; } else diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index 32213f50c7..19dd034c20 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -50,6 +50,8 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI protected: void initialize_REST(); + int get_rest_state(RestHelper * rest, string *rest_state); + public: void configure(map config_map); diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 58d0f2395d..42296fda45 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -147,17 +147,17 @@ int UDPBaseImplementation::setDetectorType(detectorType det){ /*Frame indices and numbers caught*/ -bool UDPBaseImplementation::getAcquistionStarted(){return acqStarted;}; +bool UDPBaseImplementation::getAcquistionStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return acqStarted;}; -bool UDPBaseImplementation::getMeasurementStarted(){return measurementStarted;}; +bool UDPBaseImplementation::getMeasurementStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return measurementStarted;}; -int UDPBaseImplementation::getFramesCaught(){return (packetsCaught/packetsPerFrame);} +int UDPBaseImplementation::getFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (packetsCaught/packetsPerFrame);} -int UDPBaseImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);} +int UDPBaseImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (totalPacketsCaught/packetsPerFrame);} -uint32_t UDPBaseImplementation::getStartFrameIndex(){return startFrameIndex;} +uint32_t UDPBaseImplementation::getStartFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startFrameIndex;} -uint32_t UDPBaseImplementation::getFrameIndex(){ +uint32_t UDPBaseImplementation::getFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(!packetsCaught) frameIndex=-1; else @@ -166,7 +166,7 @@ uint32_t UDPBaseImplementation::getFrameIndex(){ } -uint32_t UDPBaseImplementation::getAcquisitionIndex(){ +uint32_t UDPBaseImplementation::getAcquisitionIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(!totalPacketsCaught) acquisitionIndex=-1; else @@ -175,7 +175,7 @@ uint32_t UDPBaseImplementation::getAcquisitionIndex(){ } -void UDPBaseImplementation::resetTotalFramesCaught(){ +void UDPBaseImplementation::resetTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; acqStarted = false; startAcquisitionIndex = 0; totalPacketsCaught = 0; @@ -185,10 +185,12 @@ void UDPBaseImplementation::resetTotalFramesCaught(){ /*file parameters*/ char* UDPBaseImplementation::getFilePath() const{ + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + return (char*)filePath; } -inline char* UDPBaseImplementation::setFilePath(const char c[]){ +inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; FILE_LOG(logDEBUG) << __AT__ << "called"; if(strlen(c)){ //check if filepath exists @@ -207,10 +209,12 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){ char* UDPBaseImplementation::getFileName() const{ + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + return (char*)fileName; } -inline char* UDPBaseImplementation::setFileName(const char c[]){ +inline char* UDPBaseImplementation::setFileName(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; if(strlen(c)) @@ -220,11 +224,11 @@ inline char* UDPBaseImplementation::setFileName(const char c[]){ } -int UDPBaseImplementation::getFileIndex(){ +int UDPBaseImplementation::getFileIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex; } -int UDPBaseImplementation::setFileIndex(int i){ +int UDPBaseImplementation::setFileIndex(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; if(i>=0) fileIndex = i; @@ -232,7 +236,7 @@ int UDPBaseImplementation::setFileIndex(int i){ } -int UDPBaseImplementation::setFrameIndexNeeded(int i){ +int UDPBaseImplementation::setFrameIndexNeeded(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; frameIndexNeeded = i; return frameIndexNeeded; @@ -240,19 +244,23 @@ int UDPBaseImplementation::setFrameIndexNeeded(int i){ int UDPBaseImplementation::getEnableFileWrite() const{ - return enableFileWrite; + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + +return enableFileWrite; } -int UDPBaseImplementation::setEnableFileWrite(int i){ +int UDPBaseImplementation::setEnableFileWrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; enableFileWrite=i; return getEnableFileWrite(); } int UDPBaseImplementation::getEnableOverwrite() const{ + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + return overwrite; } -int UDPBaseImplementation::setEnableOverwrite(int i){ +int UDPBaseImplementation::setEnableOverwrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; overwrite=i; return getEnableOverwrite(); } @@ -268,7 +276,7 @@ slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ } -void UDPBaseImplementation::initialize(const char *detectorHostName){ +void UDPBaseImplementation::initialize(const char *detectorHostName){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(strlen(detectorHostName)) strcpy(detHostname,detectorHostName); } @@ -278,12 +286,12 @@ char *UDPBaseImplementation::getDetectorHostname() const{ return (char*)detHostname; } -void UDPBaseImplementation::setEthernetInterface(char* c){ +void UDPBaseImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " starting"; strcpy(eth,c); } -void UDPBaseImplementation::setUDPPortNo(int p){ +void UDPBaseImplementation::setUDPPortNo(int p){ FILE_LOG(logDEBUG) << __AT__ << " starting"; for(int i=0;i= 0) numberOfFrames = fnum; @@ -308,7 +316,7 @@ int UDPBaseImplementation::getScanTag() const{ } -int32_t UDPBaseImplementation::setScanTag(int32_t stag){ +int32_t UDPBaseImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(stag >= 0) scanTag = stag; @@ -320,7 +328,7 @@ int UDPBaseImplementation::getDynamicRange() const{ return dynamicRange; } -int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ +int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "Setting Dynamic Range" << endl; int olddr = dynamicRange; @@ -380,7 +388,7 @@ int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ -int UDPBaseImplementation::setShortFrame(int i){ +int UDPBaseImplementation::setShortFrame(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; shortFrame=i; if(shortFrame!=-1){ @@ -410,7 +418,7 @@ int UDPBaseImplementation::setShortFrame(int i){ } -int UDPBaseImplementation::setNFrameToGui(int i){ +int UDPBaseImplementation::setNFrameToGui(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(i>=0){ nFrameToGui = i; setupFifoStructure(); @@ -420,7 +428,7 @@ int UDPBaseImplementation::setNFrameToGui(int i){ -int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ +int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(index >= 0){ if(index != acquisitionPeriod){ @@ -432,9 +440,9 @@ int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ } -bool UDPBaseImplementation::getDataCompression(){return dataCompression;} +bool UDPBaseImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return dataCompression;} -int UDPBaseImplementation::enableDataCompression(bool enable){ +int UDPBaseImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "Data compression "; if(enable) cout << "enabled" << endl; @@ -487,7 +495,7 @@ int UDPBaseImplementation::enableDataCompression(bool enable){ /*other functions*/ -void UDPBaseImplementation::deleteFilter(){ +void UDPBaseImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; cmSub=NULL; @@ -504,7 +512,7 @@ void UDPBaseImplementation::deleteFilter(){ } -void UDPBaseImplementation::setupFilter(){ +void UDPBaseImplementation::setupFilter(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; double hc = 0; double sigma = 5; int sign = 1; @@ -540,7 +548,7 @@ void UDPBaseImplementation::setupFilter(){ //LEO: it is not clear to me.. -void UDPBaseImplementation::setupFifoStructure(){ +void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int64_t i; int oldn = numJobsPerThread; @@ -629,7 +637,7 @@ void UDPBaseImplementation::setupFifoStructure(){ /** acquisition functions */ -void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ +void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //point to gui data if (guiData == NULL) guiData = latestData; @@ -663,7 +671,7 @@ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ -void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ +void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //random read when gui not ready if((!nFrameToGui) && (!guiData)){ @@ -718,9 +726,7 @@ void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char -int UDPBaseImplementation::createUDPSockets(){ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - +int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //if eth is mistaken with ip address if (strchr(eth,'.')!=NULL) @@ -764,7 +770,7 @@ int UDPBaseImplementation::createUDPSockets(){ -int UDPBaseImplementation::shutDownUDPSockets(){ +int UDPBaseImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; for(int i=0;iShutDownSocket(); @@ -779,7 +785,7 @@ int UDPBaseImplementation::shutDownUDPSockets(){ -int UDPBaseImplementation::createListeningThreads(bool destroy){ +int UDPBaseImplementation::createListeningThreads(bool destroy){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; void* status; @@ -834,7 +840,7 @@ int UDPBaseImplementation::createListeningThreads(bool destroy){ -int UDPBaseImplementation::createWriterThreads(bool destroy){ +int UDPBaseImplementation::createWriterThreads(bool destroy){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; void* status; @@ -895,7 +901,7 @@ int UDPBaseImplementation::createWriterThreads(bool destroy){ -void UDPBaseImplementation::setThreadPriorities(){ +void UDPBaseImplementation::setThreadPriorities(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; //assign priorities struct sched_param tcp_param, listen_param, write_param; @@ -932,7 +938,7 @@ void UDPBaseImplementation::setThreadPriorities(){ -int UDPBaseImplementation::setupWriter(){ +int UDPBaseImplementation::setupWriter(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //reset writing thread variables packetsInFile=0; @@ -1017,7 +1023,7 @@ int UDPBaseImplementation::setupWriter(){ -int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){ +int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){ FILE_LOG(logDEBUG) << __AT__ << " starting"; #ifdef MYROOT1 char temp[MAX_STR_LENGTH]; //create file name for gui purposes, and set up acquistion parameters @@ -1045,7 +1051,7 @@ int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){ -int UDPBaseImplementation::createNewFile(){ +int UDPBaseImplementation::createNewFile(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; @@ -1168,7 +1174,7 @@ void UDPBaseImplementation::closeFile(int ithr) -int UDPBaseImplementation::startReceiver(char message[]){ +int UDPBaseImplementation::startReceiver(char message[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; @@ -1236,7 +1242,7 @@ int UDPBaseImplementation::startReceiver(char message[]){ -int UDPBaseImplementation::stopReceiver(){ +int UDPBaseImplementation::stopReceiver(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //#ifdef VERBOSE @@ -1266,7 +1272,7 @@ int UDPBaseImplementation::stopReceiver(){ -void UDPBaseImplementation::startReadout(){ +void UDPBaseImplementation::startReadout(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //#ifdef VERBOSE cout << "Start Receiver Readout" << endl; @@ -1289,7 +1295,7 @@ void UDPBaseImplementation::startReadout(){ -void* UDPBaseImplementation::startListeningThread(void* this_pointer){ +void* UDPBaseImplementation::startListeningThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " starting"; ((UDPBaseImplementation*)this_pointer)->startListening(); return this_pointer; @@ -1297,7 +1303,7 @@ void* UDPBaseImplementation::startListeningThread(void* this_pointer){ -void* UDPBaseImplementation::startWritingThread(void* this_pointer){ +void* UDPBaseImplementation::startWritingThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " starting"; ((UDPBaseImplementation*)this_pointer)->startWriting(); return this_pointer; } @@ -1307,7 +1313,7 @@ void* UDPBaseImplementation::startWritingThread(void* this_pointer){ -int UDPBaseImplementation::startListening(){ +int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int ithread = currentListeningThreadIndex; #ifdef VERYVERBOSE cout << "In startListening() " << endl; @@ -1508,7 +1514,7 @@ int UDPBaseImplementation::startListening(){ -int UDPBaseImplementation::startWriting(){ +int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE cout << ithread << "In startWriting()" < config_map){ }; +int UDPRESTImplementation::get_rest_state(RestHelper * rest, string *rest_state){ + + JsonBox::Value answer; + //string rest_state = ""; + int code = rest->get_json("state", &answer); + if ( code != -1 ){ + (*rest_state) = answer["state"].getString(); + } + + return code; +}; void UDPRESTImplementation::initialize_REST(){ FILE_LOG(logDEBUG) << __AT__ << " called"; @@ -91,7 +102,7 @@ void UDPRESTImplementation::initialize_REST(){ int code; try{ rest->init(rest_hostname, rest_port); - code = rest->get_json("state", &answer); + code = get_rest_state(rest, &answer); if (code != 0){ throw answer; @@ -115,7 +126,7 @@ void UDPRESTImplementation::initialize_REST(){ stringstream ss; string test; - std::cout << "GetSTring: " << json_request << std::endl; + //std::cout << "GetSTring: " << json_request << std::endl; json_request.writeToStream(ss, false); //ss << json_request; ss >> test; @@ -125,7 +136,7 @@ void UDPRESTImplementation::initialize_REST(){ code = rest->post_json("state/initialize", &answer, test); FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; code = rest->get_json("state", &answer); - FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer; + FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer << "\n"; /* @@ -692,33 +703,29 @@ int UDPRESTImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << "called"; - std::string answer; - int code = rest->get_json("state", &answer); - std::cout << answer << std::endl; + JsonBox::Value answer; + int code; + string be_state = ""; + // LEO: this is probably wrong + if (be_state == "OPEN"){ + while (be_state != "TRANSIENT"){ + code = rest->get_json("state", &answer); + be_state = answer["state"].getString(); + cout << be_state << endl; + usleep(10000); + } + } code = rest->post_json("state/close", &answer); - std::cout << answer << std::endl; + std::cout <post_json("state/reset", &answer); - std::cout << answer << std::endl; + std::cout << code << " " << answer << std::endl; code = rest->get_json("state", &answer); - std::cout << answer << std::endl; + std::cout << code << " " << answer << std::endl; status = slsReceiverDefs::RUN_FINISHED; - - - /* - for(int i=0;iShutDownSocket(); - delete udpSocket[i]; - udpSocket[i] = NULL; - } - } - */ - FILE_LOG(logDEBUG) << __AT__ << "finished"; return OK; @@ -1131,17 +1138,14 @@ int UDPRESTImplementation::startReceiver(char message[]){ std::string answer; int code; - - //test = "{\"configfile\":\"config.pu\", \"path\":\"patto\"}"; - code = rest->post_json("state/configure", &answer); - std::cout << answer << std::endl; + // TODO: remove hardcode!!! + std::string request_body = "{\"settings\": {\"bit_depth\": 16, \"nimages\": 1}}"; //"{\"nimages\":\"1\", \"bit_depth\":\"16\"}"; + FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body; + code = rest->post_json("state/configure", &answer, request_body); code = rest->get_json("state", &answer); - std::cout << answer << std::endl; code = rest->post_json("state/open", &answer); - std::cout << answer << std::endl; code = rest->get_json("state", &answer); - std::cout << answer << std::endl; status = slsReceiverDefs::RUNNING; @@ -1234,17 +1238,21 @@ int UDPRESTImplementation::stopReceiver(){ void UDPRESTImplementation::startReadout(){ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; //wait so that all packets which take time has arrived usleep(50000); + status = TRANSMITTING; + /********************************************/ + /* usleep(2000000); pthread_mutex_lock(&status_mutex); status = TRANSMITTING; pthread_mutex_unlock(&status_mutex); cout << "Status: Transmitting" << endl; + */ //kill udp socket to tell the listening thread to push last packet shutDownUDPSockets(); From 9ec5541b582332d11be2d4f3fc9e969530f1a80d Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Fri, 7 Nov 2014 14:42:56 +0100 Subject: [PATCH 048/222] removed hardcoded DR and nframes --- slsReceiverSoftware/src/UDPRESTImplementation.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index 42118de14d..dcb57a3e9f 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -1137,9 +1137,17 @@ int UDPRESTImplementation::startReceiver(char message[]){ std::string answer; int code; - + //char *intStr = itoa(a); + //string str = string(intStr); // TODO: remove hardcode!!! - std::string request_body = "{\"settings\": {\"bit_depth\": 16, \"nimages\": 1}}"; //"{\"nimages\":\"1\", \"bit_depth\":\"16\"}"; + stringstream ss; + ss << getDynamicRange(); + string str_dr = ss.str(); + ss << getNumberOfFrames(); + string str_n = ss.str(); + + std::string request_body = "{\"settings\": {\"bit_depth\": " + str_dr + ", \"nimages\": " + str_n + "}}"; + //"{\"nimages\":\"1\", \"bit_depth\":\"16\"}"; FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body; code = rest->post_json("state/configure", &answer, request_body); code = rest->get_json("state", &answer); From 3a07f0d785a2091b8bd8f96a9a4bbb5c5cdd547e Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Fri, 7 Nov 2014 15:49:01 +0100 Subject: [PATCH 049/222] fixed dr bug --- .../include/UDPRESTImplementation.h | 2 +- .../src/UDPRESTImplementation.cpp | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index 19dd034c20..6ee2be4b93 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -592,7 +592,7 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI int32_t numberOfFrames; /** dynamic range */ - int dynamicRange; + //int dynamicRange; /** short frames */ int shortFrame; diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index dcb57a3e9f..291e021f85 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -344,7 +344,13 @@ int32_t UDPRESTImplementation::setDynamicRange(int32_t dr){ } +/* +int32_t UDPRESTImplementation::getDynamicRange() const{ + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + return dynamicRange; +} +*/ int UDPRESTImplementation::setShortFrame(int i){ FILE_LOG(logDEBUG) << __AT__ << " called"; @@ -708,14 +714,15 @@ int UDPRESTImplementation::shutDownUDPSockets(){ string be_state = ""; // LEO: this is probably wrong - if (be_state == "OPEN"){ + cout << "AAAAAAAAAAAAA " << be_state << " " << status << endl; + //if (be_state == "OPEN"){ while (be_state != "TRANSIENT"){ - code = rest->get_json("state", &answer); - be_state = answer["state"].getString(); - cout << be_state << endl; - usleep(10000); + code = rest->get_json("state", &answer); + be_state = answer["state"].getString(); + cout << "be_State: " << be_state << endl; + usleep(10000); } - } + //} code = rest->post_json("state/close", &answer); std::cout <post_json("state/reset", &answer); @@ -1143,11 +1150,12 @@ int UDPRESTImplementation::startReceiver(char message[]){ stringstream ss; ss << getDynamicRange(); string str_dr = ss.str(); - ss << getNumberOfFrames(); - string str_n = ss.str(); + stringstream ss2; + ss2 << getNumberOfFrames(); + string str_n = ss2.str(); std::string request_body = "{\"settings\": {\"bit_depth\": " + str_dr + ", \"nimages\": " + str_n + "}}"; - //"{\"nimages\":\"1\", \"bit_depth\":\"16\"}"; + //std::string request_body = "{\"settings\": {\"nimages\":1, \"scanid\":999, \"bit_depth\":16}}"; FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body; code = rest->post_json("state/configure", &answer, request_body); code = rest->get_json("state", &answer); From eb0ca1c9446ae12595f704aff154e3cc1ea08dce Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Fri, 7 Nov 2014 16:02:24 +0100 Subject: [PATCH 050/222] commented overloaded data members --- .../include/UDPRESTImplementation.h | 152 +++++++++--------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index 6ee2be4b93..7cfe2b23d1 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -502,233 +502,233 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI const static int MAX_NUM_WRITER_THREADS = 15; /** detector type */ - detectorType myDetectorType; + //detectorType myDetectorType; /** detector hostname */ - char detHostname[MAX_STR_LENGTH]; + //char detHostname[MAX_STR_LENGTH]; /** status of receiver */ - runStatus status; + //runStatus status; /** UDP Socket between Receiver and Detector */ - genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; + //genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; /** Server UDP Port*/ - int server_port[MAX_NUM_LISTENING_THREADS]; + //int server_port[MAX_NUM_LISTENING_THREADS]; /** ethernet interface or IP to listen to */ - char *eth; + //char *eth; /** max packets per file **/ - int maxPacketsPerFile; + //int maxPacketsPerFile; /** File write enable */ - int enableFileWrite; + //int enableFileWrite; /** File over write enable */ - int overwrite; + //int overwrite; /** Complete File name */ - char savefilename[MAX_STR_LENGTH]; + //char savefilename[MAX_STR_LENGTH]; /** File Name without frame index, file index and extension*/ - char fileName[MAX_STR_LENGTH]; + //char fileName[MAX_STR_LENGTH]; /** File Path */ - char filePath[MAX_STR_LENGTH]; + //char filePath[MAX_STR_LENGTH]; /** File Index */ - int fileIndex; + //int fileIndex; /** scan tag */ - int scanTag; + //int scanTag; /** if frame index required in file name */ - int frameIndexNeeded; + //int frameIndexNeeded; /* Acquisition started */ - bool acqStarted; + //bool acqStarted; /* Measurement started */ - bool measurementStarted; + //bool measurementStarted; /** Frame index at start of each real time acquisition (eg. for each scan) */ - uint32_t startFrameIndex; + //uint32_t startFrameIndex; /** Actual current frame index of each time acquisition (eg. for each scan) */ - uint32_t frameIndex; + //uint32_t frameIndex; /** Frames Caught for each real time acquisition (eg. for each scan) */ - int packetsCaught; + //int packetsCaught; /** Total packets caught for an entire acquisition (including all scans) */ - int totalPacketsCaught; + //int totalPacketsCaught; /** Pckets currently in current file, starts new file when it reaches max */ - int packetsInFile; + //int packetsInFile; /** Frame index at start of an entire acquisition (including all scans) */ - uint32_t startAcquisitionIndex; + //uint32_t startAcquisitionIndex; /** Actual current frame index of an entire acquisition (including all scans) */ - uint32_t acquisitionIndex; + //uint32_t acquisitionIndex; /** number of packets per frame*/ - int packetsPerFrame; + //int packetsPerFrame; /** frame index mask */ - uint32_t frameIndexMask; + //uint32_t frameIndexMask; /** packet index mask */ - uint32_t packetIndexMask; + //uint32_t packetIndexMask; /** frame index offset */ - int frameIndexOffset; + //int frameIndexOffset; /** acquisition period */ - int64_t acquisitionPeriod; + //int64_t acquisitionPeriod; /** frame number */ - int32_t numberOfFrames; + //int32_t numberOfFrames; /** dynamic range */ //int dynamicRange; /** short frames */ - int shortFrame; + //int shortFrame; /** current frame number */ - uint32_t currframenum; + //uint32_t currframenum; /** Previous Frame number from buffer */ - uint32_t prevframenum; + //uint32_t prevframenum; /** size of one frame */ - int frameSize; + //int frameSize; /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - int bufferSize; + //int bufferSize; /** oen buffer size */ - int onePacketSize; + //int onePacketSize; /** latest data */ - char* latestData; + //char* latestData; /** gui data ready */ - int guiDataReady; + //int guiDataReady; /** points to the data to send to gui */ - char* guiData; + //char* guiData; /** points to the filename to send to gui */ - char* guiFileName; + //char* guiFileName; /** temporary number for eiger frame number as its not included in the packet */ - uint32_t guiFrameNumber; + //uint32_t guiFrameNumber; /** send every nth frame to gui or only upon gui request*/ - int nFrameToGui; + //int nFrameToGui; /** fifo size */ - unsigned int fifosize; + //unsigned int fifosize; /** number of jobs per thread for data compression */ - int numJobsPerThread; + //int numJobsPerThread; /** datacompression - save only hits */ - bool dataCompression; + //bool dataCompression; /** memory allocated for the buffer */ - char *mem0[MAX_NUM_LISTENING_THREADS]; + //char *mem0[MAX_NUM_LISTENING_THREADS]; /** circular fifo to store addresses of data read */ - CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; + //CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; /** circular fifo to store addresses of data already written and ready to be resued*/ - CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; + //CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; /** Receiver buffer */ - char *buffer[MAX_NUM_LISTENING_THREADS]; + //char *buffer[MAX_NUM_LISTENING_THREADS]; /** number of writer threads */ - int numListeningThreads; + //intt numListeningThreads; /** number of writer threads */ - int numWriterThreads; + //int numWriterThreads; /** to know if listening and writer threads created properly */ - int thread_started; + //int thread_started; /** current listening thread index*/ - int currentListeningThreadIndex; + //int currentListeningThreadIndex; /** current writer thread index*/ - int currentWriterThreadIndex; + //int currentWriterThreadIndex; /** thread listening to packets */ - pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; + //pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; /** thread writing packets */ - pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; + //pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; /** total frame count the listening thread has listened to */ - int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; + //int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; /** mask showing which listening threads are running */ - volatile uint32_t listeningthreads_mask; + //volatile uint32_t listeningthreads_mask; /** mask showing which writer threads are running */ - volatile uint32_t writerthreads_mask; + //volatile uint32_t writerthreads_mask; /** mask showing which threads have created files*/ - volatile uint32_t createfile_mask; + //volatile uint32_t createfile_mask; /** OK if file created was successful */ - int ret_createfile; + //int ret_createfile; /** variable used to self terminate threads waiting for semaphores */ - int killAllListeningThreads; + //int killAllListeningThreads; /** variable used to self terminate threads waiting for semaphores */ - int killAllWritingThreads; + //int killAllWritingThreads; /** 10Gbe enable*/ - int tengigaEnable; + //int tengigaEnable; //semaphores /** semaphore to synchronize writer and guireader threads */ - sem_t smp; + //sem_t smp; /** semaphore to synchronize listener threads */ - sem_t listensmp[MAX_NUM_LISTENING_THREADS]; + //sem_t listensmp[MAX_NUM_LISTENING_THREADS]; /** semaphore to synchronize writer threads */ - sem_t writersmp[MAX_NUM_WRITER_THREADS]; + //sem_t writersmp[MAX_NUM_WRITER_THREADS]; //mutex /** guiDataReady mutex */ - pthread_mutex_t dataReadyMutex; + //pthread_mutex_t dataReadyMutex; /** mutex for status */ - pthread_mutex_t status_mutex; + //pthread_mutex_t status_mutex; /** mutex for progress variable currframenum */ - pthread_mutex_t progress_mutex; + //pthread_mutex_t progress_mutex; /** mutex for writing data to file */ - pthread_mutex_t write_mutex; + //pthread_mutex_t write_mutex; /** File Descriptor */ - FILE *sfilefd; + //FILE *sfilefd; //filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - moenchCommonMode *cmSub; - bool commonModeSubtractionEnable; + //singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + //slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + //moenchCommonMode *cmSub; + //bool commonModeSubtractionEnable; #ifdef MYROOT1 /** Tree where the hits are stored */ From 72bf64ff57ea94bebfd7418d926aabd357bae225 Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Tue, 11 Nov 2014 17:01:55 +0100 Subject: [PATCH 051/222] cleaning --- .../include/slsReceiverUDPFunctions.h | 815 ------------------ 1 file changed, 815 deletions(-) delete mode 100644 slsReceiverSoftware/include/slsReceiverUDPFunctions.h diff --git a/slsReceiverSoftware/include/slsReceiverUDPFunctions.h b/slsReceiverSoftware/include/slsReceiverUDPFunctions.h deleted file mode 100644 index e9ff00590a..0000000000 --- a/slsReceiverSoftware/include/slsReceiverUDPFunctions.h +++ /dev/null @@ -1,815 +0,0 @@ -#ifdef SLS_RECEIVER_UDP_FUNCTIONS -#ifndef SLS_RECEIVER_UDP_FUNCTIONS_H -#define SLS_RECEIVER_UDP_FUNCTIONS_H -/********************************************//** - * @file slsReceiverUDPFunctions.h - * @short does all the functions for a receiver, set/get parameters, start/stop etc. - ***********************************************/ - - -//#include "sls_receiver_defs.h" -//#include "receiver_defs.h" -//#include "genericSocket.h" -#include "circularFifo.h" -#include "singlePhotonDetector.h" -#include "slsReceiverData.h" -#include "moenchCommonMode.h" - - -#include "UDPInterface.h" -#include "UDPBaseImplementation.h" - - -#ifdef MYROOT1 -#include -#include -#endif - - -#include -#include -#include -#include - - -/** - * @short does all the functions for a receiver, set/get parameters, start/stop etc. - */ - - -class slsReceiverUDPFunctions : private virtual slsReceiverDefs, public UDPInterface { - - public: - /** - * Constructor - */ - slsReceiverUDPFunctions(bool bot); - - /** - * Destructor - */ - virtual ~slsReceiverUDPFunctions(); - - /** - * delete and free member parameters - */ - void deleteMembers(); - - /** - * initialize member parameters - */ - void initializeMembers(); - - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - int setDetectorType(detectorType det); - - - //Frame indices and numbers caught - /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) - */ - uint32_t getAcquisitionIndex(); - - /** - * Returns if acquisition started - */ - bool getAcquistionStarted(); - - /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) - */ - int getFramesCaught(); - - /** - * Returns Total Frames Caught for an entire acquisition (including all scans) - */ - int getTotalFramesCaught(); - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - uint32_t getStartFrameIndex(); - - /** - * Returns current Frame Index for each real time acquisition (eg. for each scan) - */ - uint32_t getFrameIndex(); - - /** - * Returns if measurement started - */ - bool getMeasurementStarted(); - - /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 - */ - void resetTotalFramesCaught(); - - - - - //file parameters - /** - * Returns File Path - */ - char* getFilePath() const; - - /** - * Set File Path - * @param c file path - */ - char* setFilePath(const char c[]); - - /** - * Returns File Name - */ - char* getFileName() const; - - /** - * Set File Name (without frame index, file index and extension) - * @param c file name - */ - char* setFileName(const char c[]); - - /** - * Returns File Index - */ - int getFileIndex(); - - /** - * Set File Index - * @param i file index - */ - int setFileIndex(int i); - - /** - * Set Frame Index Needed - * @param i frame index needed - */ - int setFrameIndexNeeded(int i); - - /** - * Set enable file write - * @param i file write enable - * Returns file write enable - */ - int setEnableFileWrite(int i); - - /** - * Enable/disable overwrite - * @param i enable - * Returns enable over write - */ - int setEnableOverwrite(int i); - - /** - * Returns file write enable - * 1: YES 0: NO - */ - int getEnableFileWrite() const; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - int getEnableOverwrite() const; - -//other parameters - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - void abort() {}; - - /** - * Returns status of receiver: idle, running or error - */ - runStatus getStatus() const; - - /** - * Set detector hostname - * @param c hostname - */ - void initialize(const char *detectorHostName); - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - char *getDetectorHostname() const; - - /** - * Set Ethernet Interface or IP to listen to - */ - void setEthernetInterface(char* c); - - /** - * Set UDP Port Number - */ - void setUDPPortNo(int p); - - /** - * Set UDP Port Number2 - */ - void setUDPPortNo2(int p); - - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames - */ - int getNumberOfFrames() const; - - /** - * set frame number if a positive number - */ - int32_t setNumberOfFrames(int32_t fnum); - - /** - * Returns scan tag - */ - int getScanTag() const; - - /** - * set scan tag if its is a positive number - */ - int32_t setScanTag(int32_t stag); - - /** - * Returns the number of bits per pixel - */ - int getDynamicRange() const; - - /** - * set dynamic range if its is a positive number - */ - int32_t setDynamicRange(int32_t dr); - - /** - * Set short frame - * @param i if shortframe i=1 - */ - int setShortFrame(int i); - - /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request - */ - int setNFrameToGui(int i); - - /** set acquisition period if a positive number - */ - int64_t setAcquisitionPeriod(int64_t index); - - /** get data compression, by saving only hits - */ - bool getDataCompression(); - - /** enabl data compression, by saving only hits - /returns if failed - */ - int enableDataCompression(bool enable); - - /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe - */ - int enableTenGiga(int enable = -1); - - - -//other functions - - /** - * Returns the buffer-current frame read by receiver - * @param c pointer to current file name - * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet - * @param fstartind is the start index of the acquisition - */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind); - - /** - * Closes all files - * @param ithr thread index - */ - void closeFile(int ithr = -1); - - /** - * Starts Receiver - starts to listen for packets - * @param message is the error message if there is an error - * Returns success - */ - int startReceiver(char message[]); - - /** - * Stops Receiver - stops listening for packets - * Returns success - */ - int stopReceiver(); - - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished - */ - void startReadout(); - - /** - * shuts down the udp sockets - * \returns if success or fail - */ - int shutDownUDPSockets(); - -private: - /** - * Deletes all the filter objects for single photon data - */ - void deleteFilter(); - - /** - * Constructs the filter for single photon data - */ - void setupFilter(); - - /** - * set up fifo according to the new numjobsperthread - */ - void setupFifoStructure (); - - /** - * Copy frames to gui - * uses semaphore for nth frame mode - */ - void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); - - /** - * creates udp sockets - * \returns if success or fail - */ - int createUDPSockets(); - - /** - * create listening thread - * @param destroy is true to kill all threads and start again - */ - int createListeningThreads(bool destroy = false); - - /** - * create writer threads - * @param destroy is true to kill all threads and start again - */ - int createWriterThreads(bool destroy = false); - - /** - * set thread priorities - */ - void setThreadPriorities(); - - /** - * initializes variables and creates the first file - * also does the startAcquisitionCallBack - * \returns FAIL or OK - */ - int setupWriter(); - - /** - * Creates new tree and file for compression - * @param ithr thread number - * @param iframe frame number - *\returns OK for succces or FAIL for failure - */ - int createCompressionFile(int ithr, int iframe); - - /** - * Creates new file - *\returns OK for succces or FAIL for failure - */ - int createNewFile(); - - /** - * Static function - Thread started which listens to packets. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startListeningThread(void *this_pointer); - - /** - * Static function - Thread started which writes packets to file. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startWritingThread(void *this_pointer); - - /** - * Thread started which listens to packets. - * Called by startReceiver() - * - */ - int startListening(); - - /** - * Thread started which writes packets to file. - * Called by startReceiver() - * - */ - int startWriting(); - - /** - * Writing to file without compression - * @param buf is the address of buffer popped out of fifo - * @param numpackets is the number of packets - * @param framenum current frame number - */ - void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); - - /** - * Its called for the first packet of a scan or acquistion - * Sets the startframeindices and the variables to know if acquisition started - * @param ithread listening thread number - */ - void startFrameIndices(int ithread); - - /** - * This is called when udp socket is shut down - * It pops ffff instead of packet number into fifo - * to inform writers about the end of listening session - * @param ithread listening thread number - * @param rc number of bytes received - * @param pc packet count - * @param t total packets listened to - */ - void stopListening(int ithread, int rc, int &pc, int &t); - - /** - * When acquisition is over, this is called - * @param ithread listening thread number - * @param wbuffer writer buffer - */ - void stopWriting(int ithread, char* wbuffer[]); - - - /** - * data compression for each fifo output - * @param ithread listening thread number - * @param wbuffer writer buffer - * @param npackets number of packets from the fifo - * @param data pointer to the next packet start - * @param xmax max pixels in x direction - * @param ymax max pixels in y direction - * @param nf nf - */ - void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); - - - /** structure of an eiger image header*/ - typedef struct - { - unsigned char header_before[20]; - unsigned char fnum[4]; - unsigned char header_after[24]; - } eiger_image_header; - - /** structure of an eiger image header*/ - typedef struct - { - unsigned char num1[4]; - unsigned char num2[4]; - } eiger_packet_header; - - /** max number of listening threads */ - const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; - - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; - - /** detector type */ - detectorType myDetectorType; - - /** detector hostname */ - char detHostname[MAX_STR_LENGTH]; - - /** status of receiver */ - runStatus status; - - /** UDP Socket between Receiver and Detector */ - genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; - - /** Server UDP Port*/ - int server_port[MAX_NUM_LISTENING_THREADS]; - - /** ethernet interface or IP to listen to */ - char *eth; - - /** max packets per file **/ - int maxPacketsPerFile; - - /** File write enable */ - int enableFileWrite; - - /** File over write enable */ - int overwrite; - - /** Complete File name */ - char savefilename[MAX_STR_LENGTH]; - - /** File Name without frame index, file index and extension*/ - char fileName[MAX_STR_LENGTH]; - - /** File Path */ - char filePath[MAX_STR_LENGTH]; - - /** File Index */ - int fileIndex; - - /** scan tag */ - int scanTag; - - /** if frame index required in file name */ - int frameIndexNeeded; - - /* Acquisition started */ - bool acqStarted; - - /* Measurement started */ - bool measurementStarted; - - /** Frame index at start of each real time acquisition (eg. for each scan) */ - uint32_t startFrameIndex; - - /** Actual current frame index of each time acquisition (eg. for each scan) */ - uint32_t frameIndex; - - /** Frames Caught for each real time acquisition (eg. for each scan) */ - int packetsCaught; - - /** Total packets caught for an entire acquisition (including all scans) */ - int totalPacketsCaught; - - /** Pckets currently in current file, starts new file when it reaches max */ - int packetsInFile; - - /** Frame index at start of an entire acquisition (including all scans) */ - uint32_t startAcquisitionIndex; - - /** Actual current frame index of an entire acquisition (including all scans) */ - uint32_t acquisitionIndex; - - /** number of packets per frame*/ - int packetsPerFrame; - - /** frame index mask */ - uint32_t frameIndexMask; - - /** packet index mask */ - uint32_t packetIndexMask; - - /** frame index offset */ - int frameIndexOffset; - - /** acquisition period */ - int64_t acquisitionPeriod; - - /** frame number */ - int32_t numberOfFrames; - - /** dynamic range */ - int dynamicRange; - - /** short frames */ - int shortFrame; - - /** current frame number */ - uint32_t currframenum; - - /** Previous Frame number from buffer */ - uint32_t prevframenum; - - /** size of one frame */ - int frameSize; - - /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - int bufferSize; - - /** oen buffer size */ - int onePacketSize; - - /** latest data */ - char* latestData; - - /** gui data ready */ - int guiDataReady; - - /** points to the data to send to gui */ - char* guiData; - - /** points to the filename to send to gui */ - char* guiFileName; - - /** temporary number for eiger frame number as its not included in the packet */ - uint32_t guiFrameNumber; - - /** send every nth frame to gui or only upon gui request*/ - int nFrameToGui; - - /** fifo size */ - unsigned int fifosize; - - /** number of jobs per thread for data compression */ - int numJobsPerThread; - - /** datacompression - save only hits */ - bool dataCompression; - - /** memory allocated for the buffer */ - char *mem0[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data read */ - CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data already written and ready to be resued*/ - CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; - - /** Receiver buffer */ - char *buffer[MAX_NUM_LISTENING_THREADS]; - - /** number of writer threads */ - int numListeningThreads; - - /** number of writer threads */ - int numWriterThreads; - - /** to know if listening and writer threads created properly */ - int thread_started; - - /** current listening thread index*/ - int currentListeningThreadIndex; - - /** current writer thread index*/ - int currentWriterThreadIndex; - - /** thread listening to packets */ - pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; - - /** thread writing packets */ - pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; - - /** total frame count the listening thread has listened to */ - int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - - /** mask showing which listening threads are running */ - volatile uint32_t listeningthreads_mask; - - /** mask showing which writer threads are running */ - volatile uint32_t writerthreads_mask; - - /** mask showing which threads have created files*/ - volatile uint32_t createfile_mask; - - /** OK if file created was successful */ - int ret_createfile; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllListeningThreads; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllWritingThreads; - - /** 10Gbe enable*/ - int tengigaEnable; - - - - -//semaphores - /** semaphore to synchronize writer and guireader threads */ - sem_t smp; - /** semaphore to synchronize listener threads */ - sem_t listensmp[MAX_NUM_LISTENING_THREADS]; - /** semaphore to synchronize writer threads */ - sem_t writersmp[MAX_NUM_WRITER_THREADS]; - - -//mutex - /** guiDataReady mutex */ - pthread_mutex_t dataReadyMutex; - - /** mutex for status */ - pthread_mutex_t status_mutex; - - /** mutex for progress variable currframenum */ - pthread_mutex_t progress_mutex; - - /** mutex for writing data to file */ - pthread_mutex_t write_mutex; - - /** File Descriptor */ - FILE *sfilefd; - - //filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - moenchCommonMode *cmSub; - bool commonModeSubtractionEnable; - -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif - - - - /** - callback arguments are - filepath - filename - fileindex - data size - - return value is - 0 callback takes care of open,close,write file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - - */ - int (*startAcquisitionCallBack)(char*, char*,int, int, void*); - void *pStartAcquisition; - - /** - args to acquisition finished callback - total frames caught - - */ - void (*acquisitionFinishedCallBack)(int, void*); - void *pAcquisitionFinished; - - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); - void *pRawDataReady; - - /** The action which decides what the user and default responsibilites to save data are - * 0 raw data ready callback takes care of open,close,write file - * 1 callback writes file, we have to open, close it - * 2 we open, close, write file, callback does not do anything */ - int cbAction; - - /** true if bottom half module for eiger */ - bool bottom; - - -public: - - - /** - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; - - /** - callback argument is - toatal frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; -}; - - -#endif - -#endif From 3324667d05092fe6cc88ebfde6d67cf1148d8bad Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Wed, 12 Nov 2014 11:54:12 +0100 Subject: [PATCH 052/222] proper thread handling for the REST receiver --- slsReceiverSoftware/include/RestHelper.h | 15 +++-- slsReceiverSoftware/include/logger.h | 3 +- .../src/UDPBaseImplementation.cpp | 11 ++- .../src/UDPRESTImplementation.cpp | 67 +++++++++++++------ 4 files changed, 64 insertions(+), 32 deletions(-) diff --git a/slsReceiverSoftware/include/RestHelper.h b/slsReceiverSoftware/include/RestHelper.h index 93382a6104..b3d679b26e 100644 --- a/slsReceiverSoftware/include/RestHelper.h +++ b/slsReceiverSoftware/include/RestHelper.h @@ -25,6 +25,7 @@ #include #include #include +#include @@ -35,19 +36,21 @@ using namespace std; class RestHelper { public: - RestHelper(int timeout=10, int n_tries=10){ + RestHelper(int timeout=10, int n_tries=1){ /** * * * @param timeout default=10 - * @param n_tries default=3 + * @param n_tries default=1 */ http_timeout = timeout; n_connection_tries = n_tries; } - ~RestHelper(){}; + ~RestHelper(){ + delete session; + }; void set_connection_params(int timeout, int n_tries){ @@ -74,7 +77,6 @@ class RestHelper { */ //Check for http:// string - FILE_LOG(logDEBUG4) << __func__ << " starting"; string proto_str = "http://"; if( size_t found = hostname.find(proto_str) != string::npos ){ @@ -165,7 +167,7 @@ class RestHelper { string answer; int code = send_request(session, req, &answer); if(code == 0 ) { - FILE_LOG(logDEBUG4) << "REQUEST: " << " ANSWER: " << answer; + FILE_LOG(logDEBUG) << __AT__ << " REQUEST: " << " ANSWER: " << answer; json_value->loadFromString(answer); } delete uri; @@ -285,7 +287,8 @@ class RestHelper { n+=1; } - return code; + throw std::string("Cannot connect to the REST server! Please check..."); + //return code; } }; diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index 3d6d5703ee..74f5c9a126 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -4,11 +4,12 @@ #include #include #include +#include #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define MYCONCAT(x,y) -#define __AT__ string(__FILE__) + string("::") + string(__func__) + string("(): ") +#define __AT__ string(__FILE__) + string("::") + string(__func__) + string("(): ") //":" TOSTRING(__LINE__) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 351255df3f..de09ae6947 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -53,8 +53,7 @@ void UDPBaseImplementation::initializeMembers(){ int UDPBaseImplementation::setDetectorType(detectorType det){ cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; - - cout << "Setting Receiver Type " << endl; + cout << "Setting Receiver Type " << endl; deleteMembers(); initializeMembers(); @@ -76,7 +75,7 @@ int UDPBaseImplementation::setDetectorType(detectorType det){ return FAIL; break; } - + /* //moench variables if(myDetectorType == GOTTHARD){ fifosize = GOTTHARD_FIFO_SIZE; @@ -138,7 +137,7 @@ int UDPBaseImplementation::setDetectorType(detectorType det){ cout << "Ready..." << endl; return OK; - + */ return OK; } @@ -1124,7 +1123,7 @@ void UDPBaseImplementation::closeFile(int ithr) { FILE_LOG(logDEBUG) << __AT__ << "called"; - + /* if(!dataCompression){ if(sfilefd){ #ifdef VERBOSE @@ -1171,7 +1170,7 @@ void UDPBaseImplementation::closeFile(int ithr) #endif } - + */ FILE_LOG(logDEBUG) << __AT__ << "exited"; } diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index fe66960581..be929dd0d0 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -36,7 +36,7 @@ using namespace std; UDPRESTImplementation::UDPRESTImplementation(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG) << "PID: " << getpid() << __AT__ << " called"; //TODO I do not really know what to do with bottom... // Default values @@ -718,32 +718,54 @@ int UDPRESTImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << "called"; + // this is just to be sure, it could be removed + for(int i=0;iShutDownSocket(); + delete udpSocket[i]; + udpSocket[i] = NULL; + } + } + JsonBox::Value answer; int code; string be_state = ""; + FILE_LOG(logDEBUG) << __AT__ << " numListeningThreads=" << numListeningThreads; + if (rest == NULL){ + FILE_LOG(logWARNING) << __AT__ << "No REST object initialized, closing..."; + return OK; + } + + // getting the state + FILE_LOG(logWARNING) << "PLEASE WAIT WHILE CHECKING AND SHUTTING DOWN ALL CONNECTIONS!"; + code = rest->get_json("state", &answer); + be_state = answer["state"].getString(); + // LEO: this is probably wrong - cout << "AAAAAAAAAAAAA " << be_state << " " << status << endl; - //if (be_state == "OPEN"){ + if (be_state == "OPEN"){ while (be_state != "TRANSIENT"){ code = rest->get_json("state", &answer); be_state = answer["state"].getString(); cout << "be_State: " << be_state << endl; usleep(10000); } - //} - code = rest->post_json("state/close", &answer); - std::cout <post_json("state/reset", &answer); - std::cout << code << " " << answer << std::endl; - - code = rest->get_json("state", &answer); - std::cout << code << " " << answer << std::endl; + + code = rest->post_json("state/close", &answer); + std::cout <post_json("state/reset", &answer); + std::cout << code << " " << answer << std::endl; + code = rest->get_json("state", &answer); + std::cout << code << " " << answer << std::endl; + } status = slsReceiverDefs::RUN_FINISHED; - FILE_LOG(logDEBUG) << __AT__ << "finished"; + //LEO: not sure it's needed + delete rest; + FILE_LOG(logDEBUG) << __AT__ << "finished"; return OK; } @@ -1289,8 +1311,9 @@ void UDPRESTImplementation::startReadout(){ void* UDPRESTImplementation::startListeningThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; - ((UDPRESTImplementation*)this_pointer)->startListening(); + //((UDPRESTImplementation*)this_pointer)->startListening(); return this_pointer; } @@ -1299,7 +1322,9 @@ void* UDPRESTImplementation::startListeningThread(void* this_pointer){ void* UDPRESTImplementation::startWritingThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " called"; - ((UDPRESTImplementation*)this_pointer)->startWriting(); + FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; + + //((UDPRESTImplementation*)this_pointer)->startWriting(); return this_pointer; } @@ -1310,7 +1335,9 @@ void* UDPRESTImplementation::startWritingThread(void* this_pointer){ int UDPRESTImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; + /* int ithread = currentListeningThreadIndex; #ifdef VERYVERBOSE cout << "In startListening() " << endl; @@ -1495,7 +1522,7 @@ int UDPRESTImplementation::startListening(){ pthread_exit(NULL); } } - + */ return OK; } @@ -1513,6 +1540,8 @@ int UDPRESTImplementation::startListening(){ int UDPRESTImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; + /* int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE cout << ithread << "In startWriting()" < Date: Mon, 17 Nov 2014 17:06:50 +0100 Subject: [PATCH 053/222] fixed non-rest compilation --- slsReceiverSoftware/Makefile | 4 ++-- slsReceiverSoftware/src/UDPInterface.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 4f90d61077..c16db2438a 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -45,9 +45,9 @@ intdoc: $(SRC_H) $(SRC_CLNT) $(BUILDDIR)/%.o : $(SRCDIR)/%.cpp Makefile ifeq ($(ROOTSLS),yes) - $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ #$(FLAGS) + $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) $(LDFLAGRXR) -L/usr/lib64/ #$(FLAGS) else - $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) -lpthread #$(FLAGS) + $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) $(LDFLAGRXR) -lpthread #$(FLAGS) endif lib: $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a diff --git a/slsReceiverSoftware/src/UDPInterface.cpp b/slsReceiverSoftware/src/UDPInterface.cpp index 3d8ffb767c..a0b3d13716 100644 --- a/slsReceiverSoftware/src/UDPInterface.cpp +++ b/slsReceiverSoftware/src/UDPInterface.cpp @@ -13,8 +13,9 @@ using namespace std; #include "UDPInterface.h" #include "UDPBaseImplementation.h" #include "UDPStandardImplementation.h" +#ifdef REST #include "UDPRESTImplementation.h" - +#endif using namespace std; @@ -26,11 +27,11 @@ UDPInterface * UDPInterface::create(string receiver_type){ cout << "Starting " << receiver_type << endl; return new UDPStandardImplementation(); } - //#ifdef REST +#ifdef REST else if (receiver_type == "REST"){ return new UDPRESTImplementation(); } - //#endif +#endif else{ FILE_LOG(logWARNING) << "[ERROR] UDP interface not supported, using standard implementation"; return new UDPBaseImplementation(); From 2eaefaba3adc33050dca46f6d42d5ca9fc92d28b Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Tue, 18 Nov 2014 10:51:52 +0100 Subject: [PATCH 054/222] added log level control --- slsReceiverSoftware/Makefile | 4 ++-- slsReceiverSoftware/include/logger.h | 17 +++++++++++++---- slsReceiverSoftware/src/main.cpp | 4 ---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index c16db2438a..2a6303f93c 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -45,9 +45,9 @@ intdoc: $(SRC_H) $(SRC_CLNT) $(BUILDDIR)/%.o : $(SRCDIR)/%.cpp Makefile ifeq ($(ROOTSLS),yes) - $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) $(LDFLAGRXR) -L/usr/lib64/ #$(FLAGS) + $(CXX) -DROOTSLS -o $@ -c $< $(INCLUDES) $(DFLAGS) $(ROOTFLAGS) -fPIC $(EPICSFLAGS) $(LDFLAGRXR) -L/usr/lib64/ $(FLAGS) else - $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) $(LDFLAGRXR) -lpthread #$(FLAGS) + $(CXX) -o $@ -c $< $(INCLUDES) $(DFLAGS) -fPIC $(EPICSFLAGS) $(LDFLAGRXR) -lpthread $(FLAGS) endif lib: $(OBJS) $(DESTDIR)/libSlsReceiver.so $(DESTDIR)/libSlsReceiver.a diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index 74f5c9a126..cba284fb19 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -6,6 +6,19 @@ #include #include +#ifdef VERBOSE +#define FILELOG_MAX_LEVEL logDEBUG +#endif + +#ifdef VERYVERBOSE +#define FILELOG_MAX_LEVEL logDEBUG4 +#endif + +#ifndef FILELOG_MAX_LEVEL +#define FILELOG_MAX_LEVEL logINFO +#endif + + #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define MYCONCAT(x,y) @@ -60,10 +73,6 @@ class Output2FILE { class FILELOG_DECLSPEC FILELog : public Log {}; //typedef Log FILELog; -#ifndef FILELOG_MAX_LEVEL -#define FILELOG_MAX_LEVEL logDEBUG4 -#endif - #define FILE_LOG(level) \ if (level > FILELOG_MAX_LEVEL) ; \ else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ diff --git a/slsReceiverSoftware/src/main.cpp b/slsReceiverSoftware/src/main.cpp index 32adb96be5..c2dde5fc4e 100644 --- a/slsReceiverSoftware/src/main.cpp +++ b/slsReceiverSoftware/src/main.cpp @@ -13,10 +13,6 @@ using namespace std; - - - - int main(int argc, char *argv[]) { int ret = slsReceiverDefs::OK; From 4770d74c121ae4ad68568d9c8ecdeb234fedc774 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Tue, 18 Nov 2014 17:29:12 +0100 Subject: [PATCH 055/222] return even if eiger got only 16 bytes of a packet --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3b6f4a654b..6c92bf98e1 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2019,7 +2019,7 @@ int i; exit(-1); } //push the last buffer into fifo - if(rc > 0){ + if((myDetectorType != EIGER) && (rc > 0)){ //for eiger throw away incomplete frames pc = (rc/onePacketSize); #ifdef VERYDEBUG cout << ithread << " *** last packetcount:" << pc << endl; @@ -2030,7 +2030,8 @@ int i; #ifdef VERYDEBUG cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; #endif - } + }else + fifoFree[ithread]->push(buffer[ithread]);//for all detectors too. why was this not there? for rc=0? //push dummy buffer to all writer threads From 1d5580b0d4cbdf7102100f698ba6b96b0bebf0b8 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 25 Nov 2014 11:54:54 +0100 Subject: [PATCH 056/222] JMCB max frames --- slsReceiverSoftware/include/sls_receiver_defs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index f21579ae9a..7f39ff05d6 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -20,6 +20,7 @@ typedef int int32_t; #define SHORT_MAX_FRAMES_PER_FILE 100000 #define MOENCH_MAX_FRAMES_PER_FILE 1000 #define EIGER_MAX_FRAMES_PER_FILE 20000 +#define JFCTB_MAX_FRAMES_PER_FILE 100000 /** From 5b2a896ed3b815162f4a54f9bd1b81f582e42064 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Fri, 28 Nov 2014 14:28:56 +0100 Subject: [PATCH 057/222] to return if it catches only 16 bytes or less than expected, but compensates for first frame being only 266240 for eiger --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 6c92bf98e1..5822a11ca1 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1647,6 +1647,7 @@ int UDPStandardImplementation::startListening(){ stopListening(ithread,rc,packetcount,total); continue; } + /* //start indices for each start of scan/acquisition - eiger does it before if((!measurementStarted) && (rc > 0) && (!ithread)) @@ -2004,7 +2005,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ -void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){ +void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){cout << "Stop Listening" << endl; FILE_LOG(logDEBUG) << __AT__ << " called"; @@ -2019,7 +2020,9 @@ int i; exit(-1); } //push the last buffer into fifo - if((myDetectorType != EIGER) && (rc > 0)){ //for eiger throw away incomplete frames + if((myDetectorType == EIGER) && (rc < 266240) )//for eiger throw away incomplete frames + fifoFree[ithread]->push(buffer[ithread]); + else if(rc > 0){cout<< ithread << " last rc:"<push(buffer[ithread]);//for all detectors too. why was this not there? for rc=0? + } //push dummy buffer to all writer threads From 6787c2e1e0f9c3ced0adc8e7ce731d51cc29f195 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Mon, 1 Dec 2014 17:18:26 +0100 Subject: [PATCH 058/222] got rid of unnecessary usleep before transmitting in receiver --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 5822a11ca1..0ac51c321b 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1521,10 +1521,10 @@ void UDPStandardImplementation::startReadout(){ //#endif //wait so that all packets which take time has arrived - usleep(50000); + usleep(5000); /********************************************/ - usleep(2000000); + //usleep(2000000); pthread_mutex_lock(&status_mutex); status = TRANSMITTING; pthread_mutex_unlock(&status_mutex); From 52d3140a3aa19b68ea6e9560f8848090d0164f03 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Tue, 2 Dec 2014 10:12:00 +0100 Subject: [PATCH 059/222] a version of receiver for gemma with bottom --- .../include/UDPStandardImplementation.h | 2 +- .../src/UDPStandardImplementation.cpp | 20 +++++++++++++++++-- slsReceiverSoftware/src/slsReceiver.cpp | 13 +++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 6b5c0c0c45..dca52e6a45 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -47,7 +47,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ virtual ~UDPStandardImplementation(); - + void configure(map config_map); /** * delete and free member parameters diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0ac51c321b..cb8d66c25d 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -91,6 +91,22 @@ UDPStandardImplementation::UDPStandardImplementation() } +void UDPStandardImplementation::configure(map config_map){ + FILE_LOG(logWARNING) << __AT__ << " called"; + + map::const_iterator pos; + pos = config_map.find("mode"); + if (pos != config_map.end() ){ + int b; + if(!sscanf(pos->second.c_str(), "%d", &b)){ + cout << "Warning: Could not parse mode. Assuming top mode." << endl; + b = 0; + } + bottom = b!= 0; + cout << "bottom:"<< bottom << endl; + } +}; + void UDPStandardImplementation::initializeMembers(){ myDetectorType = GENERIC; maxPacketsPerFile = 0; @@ -945,12 +961,12 @@ int UDPStandardImplementation::createUDPSockets(){ port[1] = server_port[1]; /** eiger specific */ - /* + if(bottom){ port[0] = server_port[1]; port[1] = server_port[0]; } - */ + //if eth is mistaken with ip address if (strchr(eth,'.')!=NULL) strcpy(eth,""); diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 595a39868b..6ffc2fdf98 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -65,6 +65,13 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ switch(c){ + case 'm': + int b; + sscanf(optarg, "%d", &b); + bottom = b != 0; + configuration_map["mode"] = optarg; + break; + case 'f': fname = optarg; //cout << long_options[option_index].name << " " << optarg << endl; @@ -86,7 +93,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ string help_message = """\nSLS Receiver Server\n\n"""; help_message += """usage: slsReceiver --config config_fname [--rx_tcpport port]\n\n"""; help_message += """\t--config:\t configuration filename for SLS Detector receiver\n"""; - help_message += """\t--mode:\t ???\n"""; + help_message += """\t--mode:\t 1 for bottom and 0 for top\n"""; help_message += """\t--rx_tcpport:\t TCP Communication Port with the client. Default: 1954.\n\n"""; help_message += """\t--rest_hostname:\t Receiver hostname:port. It applies only to REST receivers, and indicates the hostname of the REST backend. Default: localhost:8081.\n\n"""; @@ -120,10 +127,10 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ } if (success==OK){ - FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << endl; + FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << " with mode " << bottom << endl; udp_interface = UDPInterface::create(udp_interface_type); udp_interface->configure(configuration_map); - tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no); + tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no, bottom); //tcp ip interface } } From dc4e74087dea563df969849754d820cd6bba2b9c Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Mon, 8 Dec 2014 09:16:19 +0100 Subject: [PATCH 060/222] makefile crash if files dont exist in make clean, fixed --- slsReceiverSoftware/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 2a6303f93c..c445eaa8cf 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -79,8 +79,9 @@ mysocket_test: clean: buildclean make testclean - rm $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so - rm $(PROGS) + if test -e $(DESTDIR)/libSlsReceiver.a; then rm $(DESTDIR)/libSlsReceiver.a;fi + if test -e $(DESTDIR)/libSlsReceiver.so; then rm $(DESTDIR)/libSlsReceiver.so;fi + if test -e $(PROGS); then rm $(PROGS);fi builddir: if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi From f79f3cf0217417819b8e7a9293375f16da76d7a6 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Mon, 8 Dec 2014 09:17:56 +0100 Subject: [PATCH 061/222] makefile crash if files dont exist in make clean, fixed --- slsReceiverSoftware/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index 2a6303f93c..c445eaa8cf 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -79,8 +79,9 @@ mysocket_test: clean: buildclean make testclean - rm $(DESTDIR)/libSlsReceiver.a $(DESTDIR)/libSlsReceiver.so - rm $(PROGS) + if test -e $(DESTDIR)/libSlsReceiver.a; then rm $(DESTDIR)/libSlsReceiver.a;fi + if test -e $(DESTDIR)/libSlsReceiver.so; then rm $(DESTDIR)/libSlsReceiver.so;fi + if test -e $(PROGS); then rm $(PROGS);fi builddir: if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi From 169c0a43cef9bcf1176315f475cf6eee6d363f92 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Mon, 8 Dec 2014 10:25:42 +0100 Subject: [PATCH 062/222] updating version numbers --- slsReceiverSoftware/gitInfo.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 410c414c31..d680dad1d7 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repsitory UUID: e019a6ce7d96d4ac9cb5762b7137245aedb4d5b8 -Revision: 22 -Branch: master -Last Changed Author: Anna_Bergamaschi -Last Changed Rev: 22 -Last Changed Date: 2014-10-15 09:22:40 +0200 +Repsitory UUID: 879c5e2ee129acfd70aba4ae6fab829cc5409350 +Revision: 67 +Branch: gemma +Last Changed Author: Maliakal_Dhanya +Last Changed Rev: 67 +Last Changed Date: 2014-12-08 09:17:56 +0100 From 76c9d2c61bd839d5126ac2400a2463a73ef760d5 Mon Sep 17 00:00:00 2001 From: Maliakal Dhanya Date: Wed, 14 Jan 2015 10:48:36 +0100 Subject: [PATCH 063/222] lot of couts and some pre and post --- .../src/UDPStandardImplementation.cpp | 118 ++++++++++-------- 1 file changed, 69 insertions(+), 49 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index cb8d66c25d..ca8715eda0 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -864,8 +864,10 @@ void UDPStandardImplementation::setupFifoStructure(){ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){ FILE_LOG(logDEBUG) << __AT__ << " called"; //point to gui data - if (guiData == NULL) + if (guiData == NULL){ guiData = latestData; + cout <<"gui data not null anymore" << endl; + } //copy data and filename strcpy(c,guiFileName); @@ -873,22 +875,22 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui fstartind = getStartFrameIndex(); //could not get gui data - if(!guiDataReady){ + if(!guiDataReady){cout<<"gui data not ready"<ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + cout<<"value:"<fnum)<pop(wbuf[i]); numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; -#endif +//#ifdef VERYDEBUG + cout << ithread << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; +//#endif } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << " numpackets:" << dec << numpackets << endl; cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -#endif +//#endif //last dummy packet @@ -1890,8 +1910,8 @@ int loop; } - if(myDetectorType == EIGER) { - copyFrameToGui(wbuf,currframenum); + if(myDetectorType == EIGER) {cout<<"gonna copy frame"<push(wbuf[i])); #ifdef VERYDEBUG @@ -2001,7 +2021,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ startAcquisitionIndex=startFrameIndex; currframenum = startAcquisitionIndex; acqStarted = true; - cout << "startAcquisitionIndex:" << startAcquisitionIndex<push(buffer[ithread])); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -#endif +//#endif } //reset mask and exit loop @@ -2108,9 +2128,9 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; int i,j; -#ifdef VERYDEBUG - cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl; -#endif +//#ifdef VERYDEBUG + cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[0] << endl; +//#endif //free fifo for(i=0;i Date: Fri, 30 Jan 2015 10:58:30 +0100 Subject: [PATCH 064/222] unnecessary long wait in receiver --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index ca8715eda0..145ad5ca0c 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1495,7 +1495,7 @@ int UDPStandardImplementation::startReceiver(char message[]){ for(i=0; i < numWriterThreads; ++i) sem_post(&writersmp[i]); - usleep(5000000); + //usleep(5000000); cout << "Receiver Started.\nStatus:" << status << endl; return OK; From f30833a4608e69e542b0a60e1213b1e331338e35 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 30 Jan 2015 15:03:35 +0100 Subject: [PATCH 065/222] got rid of unnecessary printouts in receiver --- slsReceiverSoftware/src/UDPBaseImplementation.cpp | 2 ++ slsReceiverSoftware/src/UDPStandardImplementation.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index de09ae6947..1c6b1a9768 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -203,7 +203,9 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEB } } FILE_LOG(logDEBUG) << __AT__ << getFilePath(); +#ifdef VERBOSE cout << getFilePath() << " " << filePath << endl; +#endif return getFilePath(); } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0ac51c321b..16b9de1f42 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1298,8 +1298,9 @@ int UDPStandardImplementation::createNewFile(){ else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex); - +#ifdef VERBOSE cout << filePath << " + " << fileName << endl; +#endif //if filewrite and we are allowed to write if(enableFileWrite && cbAction > DO_NOTHING){ @@ -1632,9 +1633,9 @@ int UDPStandardImplementation::startListening(){ expected = maxBufferSize - carryonBufferSize; } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -//#endif +#endif //start indices for each start of scan/acquisition - eiger does it before From 7fd12f97b4b08b3192ecd4b8436a23d8360d76e7 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 30 Jan 2015 16:49:30 +0100 Subject: [PATCH 066/222] some unnecessary printouts --- .../src/UDPBaseImplementation.cpp | 2 + .../src/UDPStandardImplementation.cpp | 48 +++++++++++-------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index de09ae6947..1c6b1a9768 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -203,7 +203,9 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEB } } FILE_LOG(logDEBUG) << __AT__ << getFilePath(); +#ifdef VERBOSE cout << getFilePath() << " " << filePath << endl; +#endif return getFilePath(); } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 145ad5ca0c..29843ff947 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -866,7 +866,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //point to gui data if (guiData == NULL){ guiData = latestData; - cout <<"gui data not null anymore" << endl; + //cout <<"gui data not null anymore" << endl; } //copy data and filename @@ -875,22 +875,26 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui fstartind = getStartFrameIndex(); //could not get gui data - if(!guiDataReady){cout<<"gui data not ready"< DO_NOTHING){ @@ -1645,7 +1653,7 @@ int UDPStandardImplementation::startListening(){ /* if(!ithread){*/ rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - cout<<"value:"<fnum)<fnum)<pop(wbuf[i]); numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); //#ifdef VERYDEBUG @@ -1855,11 +1863,11 @@ int loop; //#endif } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " numpackets:" << dec << numpackets << endl; cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -//#endif +#endif //last dummy packet @@ -1910,8 +1918,10 @@ int loop; } - if(myDetectorType == EIGER) {cout<<"gonna copy frame"<push(wbuf[i])); #ifdef VERYDEBUG @@ -2080,9 +2090,9 @@ int i; cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; #endif while(!fifo[ithread]->push(buffer[ithread])); -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -//#endif +#endif } //reset mask and exit loop @@ -2128,9 +2138,9 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; int i,j; -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[0] << endl; -//#endif +#endif //free fifo for(i=0;i Date: Wed, 4 Feb 2015 16:11:13 +0100 Subject: [PATCH 067/222] some code refraction to get rid of memeory leakage --- slsReceiverSoftware/include/genericSocket.h | 1 - .../src/UDPBaseImplementation.cpp | 7 ++-- .../src/UDPStandardImplementation.cpp | 40 +++++++++++-------- slsReceiverSoftware/src/main.cpp | 1 + .../src/slsReceiverTCPIPInterface.cpp | 11 ++--- 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index a798a0feff..bbe119439e 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -103,7 +103,6 @@ enum communicationProtocol{ nsent(0), total_sent(0)// sender (client): where to? ip { - // strcpy(hostname,host_ip_or_name); struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 1c6b1a9768..7641a5a1e5 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1328,8 +1328,8 @@ int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " s thread_started = 1; - int i,total; - int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; + int total; + int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; uint32_t lastframeheader;// for moench to check for all the packets in last frame char* tempchar = NULL; int imageheader = 0; @@ -1534,9 +1534,8 @@ int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " sta char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; - int ret,i,j; + int ret,i; int packetsPerThread = packetsPerFrame/numListeningThreads; -int loop; while(1){ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 16b9de1f42..a2ddd6e390 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -67,7 +67,6 @@ UDPStandardImplementation::UDPStandardImplementation() rawDataReadyCallBack = NULL; pRawDataReady = NULL; - initializeMembers(); //mutex pthread_mutex_init(&dataReadyMutex,NULL); @@ -75,6 +74,8 @@ UDPStandardImplementation::UDPStandardImplementation() pthread_mutex_init(&progress_mutex,NULL); pthread_mutex_init(&write_mutex,NULL); + initializeMembers(); + //to increase socket receiver buffer size and max length of input queue by changing kernel settings if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; @@ -1567,8 +1568,8 @@ int UDPStandardImplementation::startListening(){ thread_started = 1; - int i,total; - int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; + int total; + int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; uint32_t lastframeheader;// for moench to check for all the packets in last frame char* tempchar = NULL; int imageheader = 0; @@ -1750,6 +1751,8 @@ int UDPStandardImplementation::startListening(){ if(tempchar) {delete [] tempchar;tempchar = NULL;} pthread_exit(NULL); } + + if(tempchar) {delete [] tempchar;tempchar = NULL;} } return OK; @@ -1782,9 +1785,8 @@ int UDPStandardImplementation::startWriting(){ char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; - int ret,i,j; + int ret,i; int packetsPerThread = packetsPerFrame/numListeningThreads; -int loop; while(1){ @@ -1792,17 +1794,17 @@ int loop; nf = 0; packetsPerThread = packetsPerFrame/numListeningThreads; if(myDetectorType == MOENCH){ - xmax = MOENCH_PIXELS_IN_ONE_ROW-1; - ymax = MOENCH_PIXELS_IN_ONE_ROW-1; - }else{ - if(shortFrame == -1){ + xmax = MOENCH_PIXELS_IN_ONE_ROW-1; + ymax = MOENCH_PIXELS_IN_ONE_ROW-1; + }else{ + if(shortFrame == -1){ xmax = GOTTHARD_PIXELS_IN_ROW-1; ymax = GOTTHARD_PIXELS_IN_COL-1; - }else{ - xmax = GOTTHARD_SHORT_PIXELS_IN_ROW-1; - ymax = GOTTHARD_SHORT_PIXELS_IN_COL-1; - } + }else{ + xmax = GOTTHARD_SHORT_PIXELS_IN_ROW-1; + ymax = GOTTHARD_SHORT_PIXELS_IN_COL-1; } + } @@ -1880,7 +1882,7 @@ int loop; for(i=0;ipush(wbuf[i])); #ifdef VERYDEBUG - cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; + cout << ithread << ":" << i << " fifo freed:" << (void*)wbuf[i] << endl; #endif } @@ -1888,10 +1890,12 @@ int loop; } else{ //copy to gui - copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); + if((packetsPerFrame * numpackets) == bufferSize){ + copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; + cout << ithread << " finished copying" << endl; #endif + }//else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuf[0])); #ifdef VERYVERBOSE cout<<"buf freed:"<<(void*)wbuf[0]<push(buffer[ithread]); - else if(rc > 0){cout<< ithread << " last rc:"< 0){ pc = (rc/onePacketSize); #ifdef VERYDEBUG + cout << ithread << " last rc:"<stop(); } + delete user; cout << "Goodbye!" << endl; return 0; } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 20c95a0513..b1fe40acac 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -26,7 +26,8 @@ using namespace std; slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { - if(socket) delete socket; + if(socket) {delete socket; socket=NULL;} + if(receiverBase) {delete receiverBase; receiverBase=NULL;} closeFile(0); } @@ -1221,8 +1222,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ } //all adc else{ - //ignore if half frame is missing - if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){ + /*//ignore if half frame is missing + if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){*/ //should be same frame if (index == index2){ @@ -1239,11 +1240,11 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ } }else cout << "different frames caught. frame1:"<< hex << index << ":"< Date: Tue, 10 Feb 2015 12:21:31 +0100 Subject: [PATCH 068/222] initializing variables and copying ot gui only full frames --- slsReceiverSoftware/include/genericSocket.h | 9 ++++++++- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index bbe119439e..d6a102201d 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -103,6 +103,10 @@ enum communicationProtocol{ nsent(0), total_sent(0)// sender (client): where to? ip { + memset(&serverAddress, 0, sizeof(sockaddr_in)); + memset(&clientAddress, 0, sizeof(sockaddr_in)); + // serverAddress = {0}; + // clientAddress = {0}; // strcpy(hostname,host_ip_or_name); struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ @@ -158,7 +162,10 @@ enum communicationProtocol{ nsent(0), total_sent(0) { - + memset(&serverAddress, 0, sizeof(sockaddr_in)); + memset(&clientAddress, 0, sizeof(sockaddr_in)); + // serverAddress = {0}; + // clientAddress = {0}; /* // you can specify an IP address: */ /* */ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index a2ddd6e390..d97adf49a6 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1890,7 +1890,7 @@ int UDPStandardImplementation::startWriting(){ } else{ //copy to gui - if((packetsPerFrame * numpackets) == bufferSize){ + if(numpackets == packetsPerFrame * numJobsPerThread){ //only full frames copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYVERBOSE cout << ithread << " finished copying" << endl; From 1e55577fc2125a2a53f61625d862bdf04c0fa750 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 10 Feb 2015 16:54:39 +0100 Subject: [PATCH 069/222] no change --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b74f9c6cf4..9f1b765fde 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1676,9 +1676,9 @@ int UDPStandardImplementation::startListening(){ expected = maxBufferSize - carryonBufferSize; } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif +//#endif //start indices for each start of scan/acquisition - eiger does it before From 6d8fcaa4230594f096985e3153008bf0dcc058e3 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 13 Feb 2015 11:58:36 +0100 Subject: [PATCH 070/222] debugging output change --- slsReceiverSoftware/include/genericSocket.h | 8 ++++---- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index d6a102201d..a10e07649d 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -103,8 +103,8 @@ enum communicationProtocol{ nsent(0), total_sent(0)// sender (client): where to? ip { - memset(&serverAddress, 0, sizeof(sockaddr_in)); - memset(&clientAddress, 0, sizeof(sockaddr_in)); + //memset(&serverAddress, 0, sizeof(sockaddr_in)); + //memset(&clientAddress, 0, sizeof(sockaddr_in)); // serverAddress = {0}; // clientAddress = {0}; // strcpy(hostname,host_ip_or_name); @@ -162,8 +162,8 @@ enum communicationProtocol{ nsent(0), total_sent(0) { - memset(&serverAddress, 0, sizeof(sockaddr_in)); - memset(&clientAddress, 0, sizeof(sockaddr_in)); + //memset(&serverAddress, 0, sizeof(sockaddr_in)); + // memset(&clientAddress, 0, sizeof(sockaddr_in)); // serverAddress = {0}; // clientAddress = {0}; /* // you can specify an IP address: */ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 9f1b765fde..e7ee3fe22a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1564,7 +1564,7 @@ void UDPStandardImplementation::startReadout(){ //wait so that all packets which take time has arrived usleep(5000); /********************************************/ - //usleep(10000000); + //usleep(1000000); //usleep(2000000); pthread_mutex_lock(&status_mutex); @@ -1860,9 +1860,9 @@ int UDPStandardImplementation::startWriting(){ //cout<<"writer gonna pop from fifo:"<pop(wbuf[i]); numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; -//#endif +#endif } #ifdef VERYDEBUG @@ -2109,9 +2109,9 @@ int i; #endif pthread_mutex_unlock(&(status_mutex)); -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cout << ithread << ": Frames listened to " << dec << ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame) << endl; -//#endif +#endif //waiting for all listening threads to be done, to print final count of frames listened to if(ithread == 0){ From 651a13f811fd7c814bdc46918e409be7464f7f1d Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 23 Feb 2015 15:25:06 +0100 Subject: [PATCH 071/222] so that gui can reread the same frame from receiver, guidataready is set to zero only once --- .../src/UDPStandardImplementation.cpp | 63 +++++++++++++------ .../src/slsReceiverTCPIPInterface.cpp | 18 +++--- 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index e7ee3fe22a..05e1952086 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -867,7 +867,9 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //point to gui data if (guiData == NULL){ guiData = latestData; - //cout <<"gui data not null anymore" << endl; +#ifdef VERY_VERY_DEBUG + cout <<"gui data not null anymore" << endl; +#endif } //copy data and filename @@ -877,25 +879,33 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //could not get gui data if(!guiDataReady){ - //cout<<"gui data not ready"<pop(wbuf[i]); numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); #ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; + cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; #endif } @@ -1874,10 +1887,15 @@ int UDPStandardImplementation::startWriting(){ //last dummy packet if(numpackets == 0xFFFF){ +#ifdef VERYDEBUG + cout << "LAST dummy packet" << endl; +#endif stopWriting(ithread,wbuf); continue; } - +#ifdef VERYDEBUG + else cout <<"NOT a dummy packet"< 0){ for(i=0;ipush(wbuf[i])); #ifdef VERYDEBUG @@ -2056,7 +2081,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ -void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){cout << "Stop Listening" << endl; +void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){ FILE_LOG(logDEBUG) << __AT__ << " called"; diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index b1fe40acac..d98a7ddd70 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1336,9 +1336,9 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**send garbage with -1 index to try again*/ if (raw == NULL){ arg = -1; -#ifdef VERBOSE +//#ifdef VERBOSE cout<<"data not ready for gui yet"< Date: Tue, 24 Feb 2015 16:19:33 +0100 Subject: [PATCH 072/222] moved start of frame to after stoplistening, for eiger to ignore incomplete frames --- .../src/UDPBaseImplementation.cpp | 1 + .../src/UDPStandardImplementation.cpp | 61 ++++++++++++------- .../src/slsReceiverTCPIPInterface.cpp | 12 ++-- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 7641a5a1e5..9c6c26460d 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -171,6 +171,7 @@ uint32_t UDPBaseImplementation::getAcquisitionIndex(){ FILE_LOG(logDEBUG) << __A acquisitionIndex=-1; else acquisitionIndex = currframenum - startAcquisitionIndex; + //cout<<"acquisitionIndex:"< 0) && (!ithread)) startFrameIndices(ithread); - +*/ //problem in receiving or end of acquisition if((rc < expected)||(rc <= 0)){ @@ -1703,11 +1703,11 @@ int UDPStandardImplementation::startListening(){ continue; } -/* - //start indices for each start of scan/acquisition - eiger does it before +///* + //start indices for each start of scan/acquisition - this should be done after to ignore first incomplete frames if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); -*/ +//*/ //reset packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; @@ -1884,17 +1884,16 @@ int UDPStandardImplementation::startWriting(){ cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; #endif - //last dummy packet if(numpackets == 0xFFFF){ #ifdef VERYDEBUG - cout << "LAST dummy packet" << endl; + cout << "**LAST dummy packet" << endl; #endif stopWriting(ithread,wbuf); continue; } #ifdef VERYDEBUG - else cout <<"NOT a dummy packet"<push(buffer[ithread]); exit(-1); } + //push the last buffer into fifo - if((myDetectorType == EIGER) && (rc < 266240) )//for eiger throw away incomplete frames - fifoFree[ithread]->push(buffer[ithread]); - else if(rc > 0){ - pc = (rc/onePacketSize); + if(rc > 0){ + //eiger (incomplete frames) - throw away + if((myDetectorType == EIGER) && (rc < (bufferSize * numJobsPerThread)) ){ + if(rc == 266240) + cout << ithread << " Start of detector: Received test frame of 266240 bytes." << endl; + cout << ithread << "Discarding incomplete frame" << endl; + fifoFree[ithread]->push(buffer[ithread]); + } + //eiger (complete frames) + other detectors + else{ + pc = (rc/onePacketSize); #ifdef VERYDEBUG - cout << ithread << " last rc:"<push(buffer[ithread])); + (*((uint16_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); #ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; + cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; #endif + } + } + //free buffer + else{ + cout << ithread << "Discarding empty frame" << endl; + fifoFree[ithread]->push(buffer[ithread]); } + //push dummy buffer to all writer threads for(i=0;ipop(buffer[ithread]); @@ -2279,8 +2293,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num packetsInFile += packetsToSave; packetsCaught += packetsToSave; totalPacketsCaught += packetsToSave; - - +#ifdef VERYDEBUG + cout << "/totalPacketsCaught:" << dec << totalPacketsCaught <= maxPacketsPerFile){ //for packet loss diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index d98a7ddd70..8b0d52195a 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1336,9 +1336,9 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**send garbage with -1 index to try again*/ if (raw == NULL){ arg = -1; -//#ifdef VERBOSE +#ifdef VERBOSE cout<<"data not ready for gui yet"< Date: Wed, 25 Feb 2015 10:34:57 +0100 Subject: [PATCH 073/222] moved startframeindice to before stop listening for gotthard --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3fbba8a7ef..7f8429d2f6 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1699,12 +1699,17 @@ int UDPStandardImplementation::startListening(){ //problem in receiving or end of acquisition if((rc < expected)||(rc <= 0)){ + if(myDetectorType != EIGER){ + //start indices for each start of scan/acquisition - this should be done earlier for normal detectors + if((!measurementStarted) && (rc > 0) && (!ithread)) + startFrameIndices(ithread); + } stopListening(ithread,rc,packetcount,total); continue; } ///* - //start indices for each start of scan/acquisition - this should be done after to ignore first incomplete frames + //eiger - start indices for each start of scan/acquisition - this should be done after to ignore first incomplete frames if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); //*/ From 2f824695313242f29d40f6d89f4f8eaeab7685c2 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 5 Mar 2015 15:21:12 +0100 Subject: [PATCH 074/222] fifo debug with color done --- slsReceiverSoftware/include/ansi.h | 59 ++++++++++ .../include/sls_receiver_defs.h | 2 +- .../src/UDPBaseImplementation.cpp | 8 +- .../src/UDPStandardImplementation.cpp | 103 ++++++++++-------- 4 files changed, 124 insertions(+), 48 deletions(-) create mode 100644 slsReceiverSoftware/include/ansi.h diff --git a/slsReceiverSoftware/include/ansi.h b/slsReceiverSoftware/include/ansi.h new file mode 100644 index 0000000000..1a24d403e4 --- /dev/null +++ b/slsReceiverSoftware/include/ansi.h @@ -0,0 +1,59 @@ +#define RED "\x1b[31m" +#define GREEN "\x1b[32m" +#define YELLOW "\x1b[33m" +#define BLUE "\x1b[34m" +#define MAGENTA "\x1b[35m" +#define CYAN "\x1b[36m" +#define BG_RED "\x1b[41m" +#define BG_GREEN "\x1b[42m" +#define BG_YELLOW "\x1b[43m" +#define BG_BLUE "\x1b[44m" +#define BG_MAGENTA "\x1b[45m" +#define BG_CYAN "\x1b[46m" +#define RESET "\x1b[0m" +#define BOLD "\x1b[1m" + +#define cprintf(code, format, ...) printf(code format RESET, ##__VA_ARGS__) + +/* + +Code examples + +example 1 (a snippet): + + +#ifdef MARTIN + cprintf(BLUE, "LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base); + for (i=0; i < buffer_len/4; i++) + cprintf(BLUE, "%.8X ",*(((unsigned *) buffer)+i)); + printf("\n"); +#endif + +#ifdef MARTIN + cprintf(CYAN, "LL Read - If: %X - Data: ",ll->ll_fifo_base); +#endif + + + +example 2: + +int main() +{ + int i=1; + printf("Normal %i\n", i); + cprintf(RED, "Red\n"); + cprintf(GREEN, "Green\n"); + cprintf(YELLOW, "Yellow\n"); + cprintf(BLUE, "Blue\n"); + cprintf(MAGENTA, "Mangenta %i\n", i); + cprintf(CYAN, "Cyan %i\n", i); + cprintf(BOLD, "White %i\n", i); + cprintf(RED BOLD, "Red %i\n", i); + cprintf(GREEN BOLD, "Green\n"); + cprintf(YELLOW BOLD, "Yellow\n"); + cprintf(BLUE BOLD, "Blue\n"); + cprintf(MAGENTA BOLD, "Mangenta %i\n", i); + cprintf(CYAN BOLD, "Cyan %i\n", i); +} + +*/ diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 7f39ff05d6..7e3af64c2b 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -8,7 +8,7 @@ #endif #include - +#include "ansi.h" typedef double double32_t; typedef float float32_t; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 9c6c26460d..f12890aa28 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -374,12 +374,12 @@ int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) < setupFifoStructure(); if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; + cprintf(BG_RED,"ERROR: Could not create listening thread\n"); exit (-1); } if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); exit (-1); } @@ -475,7 +475,7 @@ int UDPBaseImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG numWriterThreads = 1; if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); return FAIL; } setThreadPriorities(); @@ -763,7 +763,7 @@ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " iret = udpSocket[i]->getErrorStatus(); if(iret){ #ifdef VERBOSE - cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; + cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n",server_port[i], iret); #endif return FAIL; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 7f8429d2f6..6f454ab570 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -322,12 +322,12 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD setupFifoStructure(); if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; + cprintf(BG_RED,"ERROR: Could not create listening thread\n"); exit (-1); } if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); exit (-1); } @@ -585,12 +585,12 @@ int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEB setupFifoStructure(); if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; + cprintf(BG_RED,"ERROR: Could not create listening thread\n"); exit (-1); } if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); exit (-1); } @@ -691,7 +691,7 @@ int UDPStandardImplementation::enableDataCompression(bool enable){ FILE_LOG(log numWriterThreads = 1; if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; + cprintf(BG_RED,"ERROR: Could not create writer threads\n"); return FAIL; } setThreadPriorities(); @@ -830,6 +830,9 @@ void UDPStandardImplementation::setupFifoStructure(){ if(fifoFree[i]){ while(!fifoFree[i]->isEmpty()) fifoFree[i]->pop(buffer[i]); +#ifdef FIFO_DEBUG + //cprintf(GREEN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); +#endif delete fifoFree[i]; } if(fifo[i]) delete fifo[i]; @@ -849,6 +852,9 @@ void UDPStandardImplementation::setupFifoStructure(){ //push the addresses into freed fifoFree and writingFifoFree while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { fifoFree[i]->push(buffer[i]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); +#endif buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); } } @@ -1017,7 +1023,7 @@ int UDPStandardImplementation::createUDPSockets(){ cout << "UDP port opened at port " << port[i] << endl; else{ #ifdef VERBOSE - cout << "Could not create UDP socket on port " << port[i] << " error:" << iret << endl; + cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); #endif return FAIL; } @@ -1349,11 +1355,11 @@ int UDPStandardImplementation::createNewFile(){ //open file if(!overwrite){ if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cout << "Error: Could not create new file " << savefilename << endl; + cprintf(BG_RED,"Error: Could not create new file %s\n",savefilename); return FAIL; } }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not create file " << savefilename << endl; + cprintf(BG_RED,"Error: Could not create file %s\n",savefilename); return FAIL; } //setting buffer @@ -1650,8 +1656,8 @@ int UDPStandardImplementation::startListening(){ #endif //pop fifoFree[ithread]->pop(buffer[ithread]); -#ifdef VERYDEBUG - cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); #endif @@ -1687,9 +1693,9 @@ int UDPStandardImplementation::startListening(){ expected = maxBufferSize - carryonBufferSize; } -#ifdef VERYDEBUG +//#ifdef VERDEBUG cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif +//#endif /* //start indices for each start of scan/acquisition - eiger does it before @@ -1796,8 +1802,9 @@ int UDPStandardImplementation::startListening(){ cout<push(buffer[ithread])); -#ifdef VERYDEBUG - if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; +#ifdef FIFO_DEBUG + //if(!ithread) + cprintf(RED, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif } @@ -1877,29 +1884,27 @@ int UDPStandardImplementation::startWriting(){ cout << "writer gonna pop from fifo:" << i << endl; #endif fifo[i]->pop(wbuf[i]); +#ifdef FIFO_DEBUG + cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); +#endif numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); #ifdef VERYDEBUG cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; #endif } -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -#endif //last dummy packet if(numpackets == 0xFFFF){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << "**LAST dummy packet" << endl; -#endif +//#endif stopWriting(ithread,wbuf); continue; } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG else cout <<"**NOT a dummy packet"<push(wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i << " fifo freed:" << (void*)wbuf[i] << endl; +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuf[i]),i); #endif } @@ -1971,8 +1976,8 @@ int UDPStandardImplementation::startWriting(){ #endif }//else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuf[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]<push(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener not txm free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); +#endif exit(-1); } @@ -2108,6 +2116,9 @@ int i; cout << ithread << " Start of detector: Received test frame of 266240 bytes." << endl; cout << ithread << "Discarding incomplete frame" << endl; fifoFree[ithread]->push(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener last buffer free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); +#endif } //eiger (complete frames) + other detectors else{ @@ -2119,8 +2130,8 @@ int i; (*((uint16_t*)(buffer[ithread]))) = pc; totalListeningFrameCount[ithread] += pc; while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; +#ifdef FIFO_DEBUG + cprintf(RED,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif } } @@ -2128,6 +2139,9 @@ int i; else{ cout << ithread << "Discarding empty frame" << endl; fifoFree[ithread]->push(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); +#endif } @@ -2135,13 +2149,16 @@ int i; //push dummy buffer to all writer threads for(i=0;ipop(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); +#endif (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; #ifdef VERYDEBUG - cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; + cout << ithread << " dummy buffer num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; #endif while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; +#ifdef FIFO_DEBUG + cprintf(RED,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif } @@ -2195,8 +2212,8 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //free fifo for(i=0;ipush(wbuffer[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); #endif } @@ -2233,9 +2250,10 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ status = RUN_FINISHED; pthread_mutex_unlock(&(status_mutex)); //report - cout << "Status: Run Finished" << endl; - cout << "Total Packets Caught:" << dec << totalPacketsCaught << endl; - cout << "Total Frames Caught:"<< dec << (totalPacketsCaught/packetsPerFrame) << endl; + + cprintf(GREEN, "Status: Run Finished\n"); + cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught); + cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); //acquisition end if (acquisitionFinishedCallBack) acquisitionFinishedCallBack((totalPacketsCaught/packetsPerFrame), pAcquisitionFinished); @@ -2442,16 +2460,15 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer remainingsize -= ((buff + ndata) - data); data = buff + ndata; if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) - cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuffer[0]< Date: Fri, 6 Mar 2015 10:43:05 +0100 Subject: [PATCH 075/222] Some changes for the JCTB software --- slsReceiverSoftware/include/sls_receiver_defs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 7f39ff05d6..ee104c6323 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -90,7 +90,8 @@ class slsReceiverDefs { PROGRESS, /**< fraction of measurement elapsed - only get! */ MEASUREMENTS_NUMBER, FRAMES_FROM_START, - FRAMES_FROM_START_PG + FRAMES_FROM_START_PG, + SAMPLES_JCTB }; From 6063c712f734a93a08a1e90765e187de2e0690ec Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 10 Mar 2015 15:04:50 +0100 Subject: [PATCH 076/222] copy first frame to latest data no matter what and also copy only if more than packets per frame --- .../src/UDPBaseImplementation.cpp | 2 +- .../src/UDPStandardImplementation.cpp | 75 +++++++++++-------- .../src/slsReceiverTCPIPInterface.cpp | 4 +- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index f12890aa28..8b2cdb598f 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -688,7 +688,7 @@ void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char pthread_mutex_unlock(&dataReadyMutex); } - //random read or nth frame read, gui needs data now + //random read or nth frame read, gui needs data now or it is the first frame else{ /* //nth frame read, block current process if the guireader hasnt read it yet diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 6f454ab570..55e8775f7d 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -874,7 +874,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui if (guiData == NULL){ guiData = latestData; #ifdef VERY_VERY_DEBUG - cout <<"gui data not null anymore" << endl; + cout << "gui data not null anymore" << endl; #endif } @@ -886,14 +886,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //could not get gui data if(!guiDataReady){ #ifdef VERY_VERY_DEBUG - cout<<"gui data not ready"<= packetsPerFrame){//min 1 frame, but neednt be + //if(numpackets == packetsPerFrame * numJobsPerThread){ //only full frames copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYVERBOSE cout << ithread << " finished copying" << endl; @@ -2108,8 +2117,16 @@ int i; exit(-1); } + //free buffer + if(rc <= 0){ + cout << ithread << "Discarding empty frame" << endl; + fifoFree[ithread]->push(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); +#endif + } //push the last buffer into fifo - if(rc > 0){ + else{ //eiger (incomplete frames) - throw away if((myDetectorType == EIGER) && (rc < (bufferSize * numJobsPerThread)) ){ if(rc == 266240) @@ -2135,14 +2152,6 @@ int i; #endif } } - //free buffer - else{ - cout << ithread << "Discarding empty frame" << endl; - fifoFree[ithread]->push(buffer[ithread]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); -#endif - } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 8b0d52195a..8c3815c19f 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1252,10 +1252,10 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ } #ifdef VERBOSE - if(arg!=-1){ + //if(arg!=-1){ cout << "fName:" << fName << endl; cout << "findex:" << arg << endl; - } + //} #endif From 89ad2112c6b397a340635b5573e2ef645321aa0b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 12 Mar 2015 12:25:23 +0100 Subject: [PATCH 077/222] difference between acquisition index and frame index --- .../include/UDPBaseImplementation.h | 18 ++- slsReceiverSoftware/include/UDPInterface.h | 10 +- .../include/UDPRESTImplementation.h | 9 +- .../include/UDPStandardImplementation.h | 10 +- .../src/UDPBaseImplementation.cpp | 59 +++++---- .../src/UDPRESTImplementation.cpp | 19 +-- .../src/UDPStandardImplementation.cpp | 36 ++++-- .../src/slsReceiverTCPIPInterface.cpp | 117 +++++++++++++----- 8 files changed, 190 insertions(+), 88 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 90aaf52b9e..6450f85f0a 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -67,6 +67,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter //Frame indices and numbers caught + /** + * Returns the frame index at start of entire acquisition (including all scans) + */ + uint32_t getStartAcquisitionIndex(); + /** * Returns current Frame Index Caught for an entire acquisition (including all scans) */ @@ -288,9 +293,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui * @param fnum frame number for eiger as it is not in the packet - * @param fstartind is the start index of the acquisition + * @param startAcquisitionIndex is the start index of the acquisition + * @param startFrameIndex is the start index of the scan */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind); + void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + /** * Closes all files * @param ithr thread index @@ -479,6 +486,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter unsigned char fnum[4]; unsigned char header_after[24]; } eiger_image_header; + /** structure of an eiger image header*/ + typedef struct + { + unsigned char header_before[35]; + unsigned char fnum[4]; + unsigned char header_after[9]; + } eiger_image_header32; /** structure of an eiger image header*/ diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 831b9bb62b..8f3ce3f41c 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -240,6 +240,11 @@ class UDPInterface { */ virtual int getFramesCaught() = 0; + /** + * Returns the frame index at start of entire acquisition (including all scans) + */ + virtual uint32_t getStartAcquisitionIndex()=0; + /** * Returns current Frame Index Caught for an entire acquisition (including all scans) */ @@ -328,9 +333,10 @@ class UDPInterface { * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui * @param fnum frame number for eiger as it is not in the packet - * @param fstartind is the start index of the acquisition + * @param startAcquisitionIndex is the start index of the acquisition + * @param startFrameIndex is the start index of the scan */ - virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind ) = 0; + virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0; /** set status to transmitting and * when fifo is empty later, sets status to run_finished diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index 6f59c30c2b..f335ba9d2d 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -89,6 +89,11 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI //Frame indices and numbers caught + /** + * Returns the frame index at start of entire acquisition (including all scans) + */ + uint32_t getStartAcquisitionIndex(); + /** * Returns current Frame Index Caught for an entire acquisition (including all scans) */ @@ -300,8 +305,10 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui * @param fnum frame number for eiger as it is not in the packet + * @param startAcquisitionIndex is the start index of the acquisition + * @param startFrameIndex is the start index of the scan */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind); + void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); /** * Closes all files diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index dca52e6a45..bad7f7a2e3 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -68,6 +68,11 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase //Frame indices and numbers caught + /** + * Returns the frame index at start of entire acquisition (including all scans) + */ + //uint32_t getStartAcquisitionIndex(); + /** * Returns current Frame Index Caught for an entire acquisition (including all scans) */ @@ -290,8 +295,11 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui * @param fnum frame number for eiger as it is not in the packet + * @param startAcquisitionIndex is the start index of the acquisition + * @param startFrameIndex is the start index of the scan */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind); + void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + /** * Closes all files * @param ithr thread index diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 8b2cdb598f..c70be5b7da 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -155,6 +155,8 @@ int UDPBaseImplementation::getFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " int UDPBaseImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (totalPacketsCaught/packetsPerFrame);} +uint32_t UDPBaseImplementation::getStartAcquisitionIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startAcquisitionIndex;} + uint32_t UDPBaseImplementation::getStartFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startFrameIndex;} uint32_t UDPBaseImplementation::getFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; @@ -642,36 +644,33 @@ void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ < /** acquisition functions */ -void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t& fstartind){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; - - //point to gui data - if (guiData == NULL) - guiData = latestData; - - //copy data and filename - strcpy(c,guiFileName); - fnum = guiFrameNumber; - fstartind = getStartFrameIndex(); - - //could not get gui data - if(!guiDataReady){ - *raw = NULL; - } - //data ready, set guidata to receive new data - else{ - *raw = guiData; - guiData = NULL; - - pthread_mutex_lock(&dataReadyMutex); - guiDataReady = 0; - pthread_mutex_unlock(&dataReadyMutex); - if((nFrameToGui) && (writerthreads_mask)){ - /*if(nFrameToGui){*/ - //release after getting data - sem_post(&smp); - } - } +void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + //point to gui data + if (guiData == NULL){ + guiData = latestData; + } + + //copy data and filename + strcpy(c,guiFileName); + fnum = guiFrameNumber; + startAcquisitionIndex = getStartAcquisitionIndex(); + startFrameIndex = getStartFrameIndex(); + + + //could not get gui data + if(!guiDataReady){ + *raw = NULL; + } + //data ready, set guidata to receive new data + else{ + *raw = guiData; + guiData = NULL; + if((nFrameToGui) && (writerthreads_mask)){ + //release after getting data + sem_post(&smp); + } + } } diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index be929dd0d0..b03f92a18b 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -187,6 +187,11 @@ int UDPRESTImplementation::getTotalFramesCaught(){ return (totalPacketsCaught/packetsPerFrame); } +uint32_t UDPRESTImplementation::getStartAcquisitionIndex(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return startAcquisitionIndex; +} + uint32_t UDPRESTImplementation::getStartFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " called"; return startFrameIndex; @@ -577,16 +582,19 @@ void UDPRESTImplementation::setupFifoStructure(){ /** acquisition functions */ -void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){ +void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ FILE_LOG(logDEBUG) << __AT__ << " called"; //point to gui data - if (guiData == NULL) + if (guiData == NULL){ guiData = latestData; + } //copy data and filename strcpy(c,guiFileName); fnum = guiFrameNumber; - fstartind = getStartFrameIndex(); + startAcquisitionIndex = getStartAcquisitionIndex(); + startFrameIndex = getStartFrameIndex(); + //could not get gui data if(!guiDataReady){ @@ -596,12 +604,7 @@ void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32 else{ *raw = guiData; guiData = NULL; - - pthread_mutex_lock(&dataReadyMutex); - guiDataReady = 0; - pthread_mutex_unlock(&dataReadyMutex); if((nFrameToGui) && (writerthreads_mask)){ - /*if(nFrameToGui){*/ //release after getting data sem_post(&smp); } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 55e8775f7d..f44ed60177 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -352,6 +352,8 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD //int UDPStandardImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);} +//uint32_t UDPStandardImplementation::getStartAcquisitionIndex(){return startAcquisitionIndex;} + //uint32_t UDPStandardImplementation::getStartFrameIndex(){return startFrameIndex;} /* @@ -868,7 +870,7 @@ void UDPStandardImplementation::setupFifoStructure(){ /** acquisition functions */ -void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &fstartind){ +void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ FILE_LOG(logDEBUG) << __AT__ << " called"; //point to gui data if (guiData == NULL){ @@ -881,7 +883,9 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //copy data and filename strcpy(c,guiFileName); fnum = guiFrameNumber; - fstartind = getStartFrameIndex(); + startAcquisitionIndex = getStartAcquisitionIndex(); + startFrameIndex = getStartFrameIndex(); + //could not get gui data if(!guiDataReady){ @@ -975,9 +979,13 @@ cout << "copyframe" << endl; #endif //nth frame read, block current process if the guireader hasnt read it yet if(nFrameToGui){ - //cout<<"waiting after copying"<fnum); if(dynamicRange != 32) tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - else + else{ + cout << " 32 bit eiger could be "<< dec << htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) << endl; + cout << " 32 bit eiger32 could be "<< dec << htonl(*(unsigned int*)((eiger_image_header32 *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) << endl; tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans + } }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else @@ -1936,10 +1947,10 @@ int UDPStandardImplementation::startWriting(){ currframenum = tempframenum; pthread_mutex_unlock(&progress_mutex); } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG if(myDetectorType == EIGER) cout << endl <push(buffer[ithread]); #ifdef FIFO_DEBUG @@ -2261,8 +2272,13 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //report cprintf(GREEN, "Status: Run Finished\n"); - cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught); - cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); + if(!totalPacketsCaught){ + cprintf(RED, "Total Packets Caught:%d\n", totalPacketsCaught); + cprintf(RED, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); + }else{ + cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught); + cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); + } //acquisition end if (acquisitionFinishedCallBack) acquisitionFinishedCallBack((totalPacketsCaught/packetsPerFrame), pAcquisitionFinished); diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 8c3815c19f..23d1d01471 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -977,7 +977,9 @@ int slsReceiverTCPIPInterface::read_frame(){ int slsReceiverTCPIPInterface::moench_read_frame(){ ret=OK; char fName[MAX_STR_LENGTH]=""; - int arg = -1,i; + int acquisitionIndex = -1; + int frameIndex= -1; + int i; int bufferSize = MOENCH_BUFFER_SIZE; @@ -990,7 +992,8 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ char* raw = new char[bufferSize]; - uint32_t startIndex=0; + uint32_t startAcquisitionIndex=0; + uint32_t startFrameIndex=0; uint32_t index = 0,bindex = 0, offset=0; strcpy(mess,"Could not read frame\n"); @@ -1001,18 +1004,18 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ /**send garbage with -1 index to try again*/ if(!receiverBase->getFramesCaught()){ - arg = -1; + startAcquisitionIndex = -1; cout<<"haven't caught any frame yet"<getStartFrameIndex();*/ - receiverBase->readFrame(fName,&raw,index,startIndex); + receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ - arg = -1; + startAcquisitionIndex = -1; #ifdef VERBOSE cout<<"data not ready for gui yet"<SendDataOnly(fName,MAX_STR_LENGTH); - socket->SendDataOnly(&arg,sizeof(arg)); + socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); + socket->SendDataOnly(&frameIndex,sizeof(frameIndex)); socket->SendDataOnly(retval,MOENCH_DATA_BYTES); } //return ok/fail @@ -1135,7 +1151,9 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ int slsReceiverTCPIPInterface::gotthard_read_frame(){ ret=OK; char fName[MAX_STR_LENGTH]=""; - int arg = -1,i; + int acquisitionIndex = -1; + int frameIndex= -1; + int i; //retval is a full frame @@ -1161,7 +1179,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ uint32_t index=0,index2=0; uint32_t pindex=0,pindex2=0; uint32_t bindex=0,bindex2=0; - uint32_t startIndex=0; + uint32_t startAcquisitionIndex=0; + uint32_t startFrameIndex=0; strcpy(mess,"Could not read frame\n"); @@ -1173,16 +1192,16 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ /**send garbage with -1 index to try again*/ if(!receiverBase->getFramesCaught()){ - arg=-1; + startAcquisitionIndex=-1; cout<<"haven't caught any frame yet"<getStartFrameIndex();*/ - receiverBase->readFrame(fName,&raw,index,startIndex); + receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ - arg = -1; + startAcquisitionIndex = -1; #ifdef VERBOSE cout<<"data not ready for gui yet"<SendDataOnly(fName,MAX_STR_LENGTH); - socket->SendDataOnly(&arg,sizeof(arg)); + socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); + socket->SendDataOnly(&frameIndex,sizeof(frameIndex)); socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES); } @@ -1297,7 +1332,9 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ int slsReceiverTCPIPInterface::eiger_read_frame(){ ret=OK; char fName[MAX_STR_LENGTH]=""; - int arg = -1,i; + int acquisitionIndex = -1; + int frameIndex= -1; + int i; uint32_t index=0; int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame; @@ -1309,7 +1346,8 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ char* raw = new char[frameSize]; char* origVal = new char[frameSize]; char* retval = new char[dataSize]; - uint32_t startIndex=0; + uint32_t startAcquisitionIndex=0; + uint32_t startFrameIndex=0; strcpy(mess,"Could not read frame\n"); @@ -1320,7 +1358,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**send garbage with -1 index to try again*/ if(!receiverBase->getFramesCaught()){ - arg=-1; + startAcquisitionIndex=-1; #ifdef VERBOSE cout<<"haven't caught any frame yet"<readFrame(fName,&raw,index,startIndex); + receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); #ifdef VERBOSE cout << "index:" << dec << index << endl; #endif /**send garbage with -1 index to try again*/ if (raw == NULL){ - arg = -1; + startAcquisitionIndex = -1; #ifdef VERBOSE cout<<"data not ready for gui yet"<SendDataOnly(fName,MAX_STR_LENGTH); - socket->SendDataOnly(&arg,sizeof(arg)); + socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); + socket->SendDataOnly(&frameIndex,sizeof(frameIndex)); socket->SendDataOnly(retval,dataSize); } From 9e78bae6148c9b2f9c107de614289596faf1291f Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Mon, 23 Mar 2015 11:18:05 +0100 Subject: [PATCH 078/222] solved bad_alloc --- .../src/UDPRESTImplementation.cpp | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index be929dd0d0..e1b3a11149 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -87,7 +87,9 @@ int UDPRESTImplementation::get_rest_state(RestHelper * rest, string *rest_state) }; void UDPRESTImplementation::initialize_REST(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " REST status is initialized: " << isInitialized; if (rest_hostname.empty()) { FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; @@ -104,7 +106,9 @@ void UDPRESTImplementation::initialize_REST(){ try{ rest->init(rest_hostname, rest_port); code = get_rest_state(rest, &answer); + std::cout << "AAAAAAAa " << answer << std::endl; + if (code != 0){ throw answer; } @@ -133,11 +137,19 @@ void UDPRESTImplementation::initialize_REST(){ ss >> test; - test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; - code = rest->post_json("state/initialize", &answer, test); - FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; code = rest->get_json("state", &answer); - FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer << "\n"; + FILE_LOG(logDEBUG) << __AT__ << " state got " << code << " " << answer << "\n"; + if (answer != "INITIALIZED"){ + test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; + code = rest->post_json("state/initialize", &answer, test); + } + else{ + test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; + code = rest->post_json("state/configure", &answer, test); + } + FILE_LOG(logDEBUG) << __AT__ << " state/configure got " << code; + code = rest->get_json("state", &answer); + FILE_LOG(logDEBUG) << __AT__ << " state got " << code << " " << answer << "\n"; /* @@ -1169,10 +1181,8 @@ int UDPRESTImplementation::startReceiver(char message[]){ initialize_REST(); FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " initialized"; -// #ifdef VERBOSE cout << "Starting Receiver" << endl; -//#endif - + std::string answer; int code; //char *intStr = itoa(a); @@ -1184,17 +1194,21 @@ int UDPRESTImplementation::startReceiver(char message[]){ stringstream ss2; ss2 << getNumberOfFrames(); string str_n = ss2.str(); + + cout << "Starting Receiver" << endl; + std::string request_body = "{\"settings\": {\"bit_depth\": " + str_dr + ", \"nimages\": " + str_n + "}}"; //std::string request_body = "{\"settings\": {\"nimages\":1, \"scanid\":999, \"bit_depth\":16}}"; FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body; code = rest->post_json("state/configure", &answer, request_body); - code = rest->get_json("state", &answer); + //code = rest->get_json("state", &answer); + //FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer; - code = rest->post_json("state/open", &answer); - code = rest->get_json("state", &answer); + //code = rest->post_json("state/open", &answer); + //code = rest->get_json("state", &answer); - status = slsReceiverDefs::RUNNING; + status = RUNNING; //reset listening thread variables /* From 1df89d4ce20357c7815acd56686d3c58054c0eb8 Mon Sep 17 00:00:00 2001 From: Leonardo Sala Date: Mon, 23 Mar 2015 11:41:19 +0100 Subject: [PATCH 079/222] test --- slsReceiverSoftware/include/RestHelper.h | 76 ++++++++++--------- .../src/UDPRESTImplementation.cpp | 7 +- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/slsReceiverSoftware/include/RestHelper.h b/slsReceiverSoftware/include/RestHelper.h index b3d679b26e..92846750d6 100644 --- a/slsReceiverSoftware/include/RestHelper.h +++ b/slsReceiverSoftware/include/RestHelper.h @@ -249,45 +249,47 @@ class RestHelper { * @return */ - int n=0; + int n = 0; int code = -1; - while(nsendRequest( (req) ); - else{ - ostream &os = session->sendRequest( req ) ; - os << request_body; - } - - HTTPResponse res; - istream &is = session->receiveResponse(res); - StreamCopier::copyToString(is, *answer); - code = res.getStatus(); - if (code != 200){ - FILE_LOG(logERROR) << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() ; - code = -1; - } - else - code = 0; - return code; - } - catch (exception& e){ - FILE_LOG(logERROR) << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"<sendRequest( (req) ); + else{ + ostream &os = session->sendRequest( req ) ; + os << request_body; + } + + HTTPResponse res; + istream &is = session->receiveResponse(res); + StreamCopier::copyToString(is, *answer); + code = res.getStatus(); + if (code != 200){ + FILE_LOG(logERROR) << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() ; + code = -1; + } + else + code = 0; + return code; + } + catch (exception& e){ + FILE_LOG(logERROR) << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"<post_json("state/configure", &answer, request_body); - //code = rest->get_json("state", &answer); - //FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer; + code = rest->get_json("state", &answer); + FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer; //code = rest->post_json("state/open", &answer); //code = rest->get_json("state", &answer); From e35867227f7fed34610dbfe70c8f517e0d57289d Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 30 Mar 2015 17:16:31 +0200 Subject: [PATCH 080/222] writing frame number to the file for eiger --- slsReceiverSoftware/include/UDPBaseImplementation.h | 3 ++- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 6450f85f0a..7798277780 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -499,7 +499,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter typedef struct { unsigned char num1[4]; - unsigned char num2[4]; + unsigned char num2[3]; + unsigned char num3[1]; } eiger_packet_header; /** max number of listening threads */ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index f44ed60177..012d675a53 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2306,8 +2306,13 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if((enableFileWrite) && (sfilefd)){ offset = HEADER_SIZE_NUM_TOT_PACKETS; - if(myDetectorType == EIGER) + if(myDetectorType == EIGER){ offset += EIGER_HEADER_LENGTH; + (*(uint32_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num1)) = framenum; + //cprintf(RED, "framenum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset)))->num1))); + //cprintf(RED, "2packetnumber:0x%x\n", (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num3))); + //cprintf(RED, "22packetnumber:0x%x\n",(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num3))); + } while(numpackets > 0){ //for progress and packet loss calculation(new files) From b5e8c104dbb6b0048dc9094bbfba8a4ac2753397 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 31 Mar 2015 14:45:41 +0200 Subject: [PATCH 081/222] printouts for eigermapping --- .../src/UDPStandardImplementation.cpp | 6 ++-- .../src/slsReceiverTCPIPInterface.cpp | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 012d675a53..0e5adf38e2 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2309,9 +2309,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(myDetectorType == EIGER){ offset += EIGER_HEADER_LENGTH; (*(uint32_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num1)) = framenum; - //cprintf(RED, "framenum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset)))->num1))); - //cprintf(RED, "2packetnumber:0x%x\n", (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num3))); - //cprintf(RED, "22packetnumber:0x%x\n",(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num3))); + cprintf(RED, "framenum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset)))->num1))); + cprintf(RED, "2packetnumber:0x%x\n", (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num3))); + cprintf(RED, "22packetnumber:0x%x\n",(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num3))); } while(numpackets > 0){ diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 23d1d01471..1daf40ae0b 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1489,6 +1489,19 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ } + /*int inum = 0; + //dr = 16, hence uint16_t + for(inum = 0; inum < 2; inum++) + cprintf(YELLOW,"before htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); + for(inum = 254; inum < 258; inum++) + cprintf(YELLOW,"before htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); + for(inum = 0; inum < 2; inum++) + cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); + for(inum = 254; inum < 258; inum++) + cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); + + */ + //64 bit htonl cuz of endianness for(i=0;i<(1024*(16*dynamicrange)*2)/8;i++){ (*(((uint64_t*)retval)+i)) = be64toh(((uint64_t)(*(((uint64_t*)retval)+i)))); @@ -1501,6 +1514,21 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ (*(((uint64_t*)retval)+i)) = temp; */ } + + /* + //dr = 16, hence uint16_t + for(inum = 0; inum < 2; inum++) + cprintf(MAGENTA,"after htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); + for(inum = 254; inum < 258; inum++) + cprintf(MAGENTA,"after htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); + for(inum = 0; inum < 2; inum++) + cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); + for(inum = 254; inum < 258; inum++) + cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); + */ + + + acquisitionIndex = index-startAcquisitionIndex; if(acquisitionIndex == -1) startFrameIndex = -1; From 6cd28165ca79c4ea9eb5043ce2acdc2ccec75de7 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 10 Apr 2015 17:11:26 +0200 Subject: [PATCH 082/222] top image reconstruct works with make flga --- .../include/UDPBaseImplementation.h | 4 ++-- .../src/UDPStandardImplementation.cpp | 20 +++++++++++++++---- .../src/slsReceiverTCPIPInterface.cpp | 10 +++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 7798277780..eac9fd0da7 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -498,8 +498,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** structure of an eiger image header*/ typedef struct { - unsigned char num1[4]; - unsigned char num2[3]; + unsigned char num1[6]; + unsigned char num2[1]; unsigned char num3[1]; } eiger_packet_header; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0e5adf38e2..4a337fce2e 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1963,6 +1963,7 @@ int UDPStandardImplementation::startWriting(){ }else if (numpackets > 0){ for(i=0;inum1)) = framenum; - cprintf(RED, "framenum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset)))->num1))); - cprintf(RED, "2packetnumber:0x%x\n", (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num3))); - cprintf(RED, "22packetnumber:0x%x\n",(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num3))); +#ifdef WRITE_HEADERS + for (int i = 0; i < packetsPerFrame; i++) + (*(uint32_t*)(((eiger_packet_header *)((char*)(buf + offset + 1040*i)))->num1)) = framenum; + + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset)))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num2))); + cprintf(RED, "p1 num:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num3))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num2))); + cprintf(RED, "p2 num:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num3))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + 2080)))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +2080)))->num2))); + cprintf(RED, "p3 num:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +2080)))->num3))); + +#endif } while(numpackets > 0){ diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 1daf40ae0b..97b87e68b9 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1488,8 +1488,8 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ } } - - /*int inum = 0; +/* + int inum = 0; //dr = 16, hence uint16_t for(inum = 0; inum < 2; inum++) cprintf(YELLOW,"before htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); @@ -1499,8 +1499,8 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); for(inum = 254; inum < 258; inum++) cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); +*/ - */ //64 bit htonl cuz of endianness for(i=0;i<(1024*(16*dynamicrange)*2)/8;i++){ @@ -1515,7 +1515,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ */ } - /* +/* //dr = 16, hence uint16_t for(inum = 0; inum < 2; inum++) cprintf(MAGENTA,"after htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); @@ -1525,7 +1525,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); for(inum = 254; inum < 258; inum++) cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); - */ +*/ From 15bbb099d378500ac369f35b030ff0ee0cba0cb0 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 14 Apr 2015 17:11:56 +0200 Subject: [PATCH 083/222] for mapping 32 bit eiger --- .../include/UDPBaseImplementation.h | 9 +- .../src/UDPStandardImplementation.cpp | 131 ++++++++++++++---- .../src/slsReceiverTCPIPInterface.cpp | 16 +-- 3 files changed, 118 insertions(+), 38 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index eac9fd0da7..4801c751e9 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -489,18 +489,19 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** structure of an eiger image header*/ typedef struct { - unsigned char header_before[35]; + unsigned char header_before[19]; unsigned char fnum[4]; - unsigned char header_after[9]; + unsigned char header_after[25]; } eiger_image_header32; /** structure of an eiger image header*/ typedef struct { - unsigned char num1[6]; - unsigned char num2[1]; + unsigned char num1[4]; + unsigned char num2[2]; unsigned char num3[1]; + unsigned char num4[1]; } eiger_packet_header; /** max number of listening threads */ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 4a337fce2e..93ad2c8d19 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1860,12 +1860,13 @@ int UDPStandardImplementation::startWriting(){ thread_started = 1; + int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; int numpackets, nf; uint32_t tempframenum; char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; - int ret,i; + int ret,i,j; int packetsPerThread = packetsPerFrame/numListeningThreads; while(1){ @@ -1926,14 +1927,16 @@ int UDPStandardImplementation::startWriting(){ //for progress if(myDetectorType == EIGER){ - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + if(dynamicRange != 32) - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - else{ - cout << " 32 bit eiger could be "<< dec << htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) << endl; - cout << " 32 bit eiger32 could be "<< dec << htonl(*(unsigned int*)((eiger_image_header32 *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) << endl; - tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans - } + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + else + tempframenum = htonl(*(unsigned int*)((eiger_image_header32 *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + + + tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 + //tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans + }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else @@ -1961,9 +1964,53 @@ int UDPStandardImplementation::startWriting(){ /* for eiger 32 bit mode, currframenum like gotthard, does not start from 0 or 1 */ rawDataReadyCallBack(currframenum, wbuf[i], numpackets * onePacketSize, sfilefd, guiData,pRawDataReady); }else if (numpackets > 0){ - for(i=0;inum1)) = currframenum; + + //for 32 bit,port number needs to be changed and packet number reconstructed + if(dynamicRange == 32){ + for (i = 0; i < packetsPerFrame/4; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); + + //new port number as its the same everywhere for 32 bit!! + if(!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = 0x00; + +#ifdef VERYDEBUG + cprintf(RED, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); +#endif + } + for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))+(packetsPerFrame/4)); + + //new port number as its the same everywhere for 32 bit!! + if(!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = 0x00; + + +#ifdef VERYDEBUG + cprintf(RED, "%d -0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); +#endif + } + } + } +#endif + + writeToFile_withoutCompression(wbuf[j], numpackets,currframenum); + } #ifdef VERYDEBUG cout << "written everyting" << endl; #endif @@ -2074,9 +2121,13 @@ int UDPStandardImplementation::startWriting(){ void UDPStandardImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " called"; - if (myDetectorType == EIGER) + if (myDetectorType == EIGER){ //add currframenum later in this method for scans - startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + if(dynamicRange == 32) + startFrameIndex = htonl(*(unsigned int*)((eiger_image_header32 *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + else + startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + } //gotthard has +1 for frame number and not a short frame else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) @@ -2131,7 +2182,7 @@ int i; //free buffer if(rc <= 0){ - cout << ithread << "Discarding empty frame" << endl; + cout << ithread << "Discarding empty frame/ End of acquisition" << endl; fifoFree[ithread]->push(buffer[ithread]); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); @@ -2310,19 +2361,47 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(myDetectorType == EIGER){ offset += EIGER_HEADER_LENGTH; #ifdef WRITE_HEADERS - for (int i = 0; i < packetsPerFrame; i++) - (*(uint32_t*)(((eiger_packet_header *)((char*)(buf + offset + 1040*i)))->num1)) = framenum; - - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num2))); - cprintf(RED, "p1 num:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset)))->num3))); - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num2))); - cprintf(RED, "p2 num:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +1040)))->num3))); - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + 2080)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +2080)))->num2))); - cprintf(RED, "p3 num:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +2080)))->num3))); - +#ifdef VERY_DEBUG + int k = 0; + if(dynamicRange != 32){ + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); + k = 1; + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + k = 2; + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + }else{ + k = 0; + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); + k = 1; + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + k = 2; + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + k = 256; + cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + k = 512; + cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + k = 768; + cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + } +#endif #endif } while(numpackets > 0){ diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 97b87e68b9..240784ea56 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1492,13 +1492,13 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ int inum = 0; //dr = 16, hence uint16_t for(inum = 0; inum < 2; inum++) - cprintf(YELLOW,"before htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); + cprintf(YELLOW,"before htonl %d,0 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); for(inum = 254; inum < 258; inum++) - cprintf(YELLOW,"before htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); + cprintf(YELLOW,"before htonl %d,0 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); for(inum = 0; inum < 2; inum++) - cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); + cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); for(inum = 254; inum < 258; inum++) - cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); + cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); */ @@ -1518,13 +1518,13 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /* //dr = 16, hence uint16_t for(inum = 0; inum < 2; inum++) - cprintf(MAGENTA,"after htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); + cprintf(MAGENTA,"after htonl %d,0 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); for(inum = 254; inum < 258; inum++) - cprintf(MAGENTA,"after htonl %d,0 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); + cprintf(MAGENTA,"after htonl %d,0 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); for(inum = 0; inum < 2; inum++) - cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); + cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); for(inum = 254; inum < 258; inum++) - cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint16_t)(*((uint16_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); + cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); */ From 992a298abc9be2ceb9e8be5e16912b3537350f6b Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 21 Apr 2015 15:09:50 +0200 Subject: [PATCH 084/222] added dunny implementation as an example to combine TCPIP interface and custom UDP reciever --- slsReceiverSoftware/Makefile | 9 + .../include/dummyUDPInterface.h | 419 ++++++++++++++++++ slsReceiverSoftware/include/receiver_defs.h | 17 + .../src/UDPStandardImplementation.cpp | 16 + slsReceiverSoftware/src/dummyMain.cpp | 46 ++ .../src/slsReceiverTCPIPInterface.cpp | 7 +- 6 files changed, 512 insertions(+), 2 deletions(-) create mode 100644 slsReceiverSoftware/include/dummyUDPInterface.h create mode 100644 slsReceiverSoftware/src/dummyMain.cpp diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index c445eaa8cf..b7d1c10a95 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -26,6 +26,8 @@ endif MAIN_SRC = main.cpp +DUMMY_MAIN_SRC = dummyMain.cpp + OBJS=$(SRC_CLNT:%.cpp=$(BUILDDIR)/%.o) @@ -40,6 +42,8 @@ $(info ) all: builddir lib receiver +dummy: $(DESTDIR)/dummyReceiver + intdoc: $(SRC_H) $(SRC_CLNT) doxygen doxy.config @@ -70,6 +74,11 @@ $(DESTDIR)/slsReceiver: lib #$(EIGERFLAGS) +$(DESTDIR)/dummyReceiver: lib + $(CXX) -o $@ $(SRCDIR)/$(DUMMY_MAIN_SRC) $(FLAGS) $(INCLUDES) $(CLAGS) $(LIBS) $(LDFLAGRXR) -fPIC +#$(EIGERFLAGS) + + # Stand-alone Mysocket tests mysocket_test: g++ -o $(TESTDIR)/MySocketTCP.o -c $(SRCDIR)/MySocketTCP.cpp -I include diff --git a/slsReceiverSoftware/include/dummyUDPInterface.h b/slsReceiverSoftware/include/dummyUDPInterface.h new file mode 100644 index 0000000000..479de45846 --- /dev/null +++ b/slsReceiverSoftware/include/dummyUDPInterface.h @@ -0,0 +1,419 @@ +#ifndef DUMMYUDPINTERFACE_H +#define DUMMYUDPINTERFACE_H + +/*********************************************** + * @file UDPInterface.h + * @short Base class with all the functions for the UDP inteface of the receiver + ***********************************************/ +/** + * \mainpage Base class with all the functions for the UDP inteface of the receiver + */ + +/** + * @short Base class with all the functions for the UDP inteface of the receiver + */ + +#include "UDPInterface.h" +#include "sls_receiver_defs.h" + + +class dummyUDPInterface : public UDPInterface { + + + /* abstract class that defines the UDP interface of an sls detector data receiver. + * + * Use the factory method UDPInterface::create() to get an instance: + * + * UDPInterface *udp_interface = UDPInterface::create() + * + * supported sequence of method-calls: + * + * initialize() : once and only once after create() + * + * get*() : anytime after initialize(), multiples times + * set*() : anytime after initialize(), multiple times + * + * startReceiver(): anytime after initialize(). Will fail if state already is 'running' + * + * abort(), + * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. + * + * getStatus() returns the actual state of the data receiver - running or idle. All other + * get*() and set*() methods access the local cache of configuration values only and *do not* modify the data receiver settings. + * + * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. + * + * get- and set-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: + * + * char *c = receiver->getFileName(); + * .... + * delete[] c; + * + * always: 1:YES 0:NO for int as bool-like arguments + * + */ + + public: + + /** + * Destructor + */ + dummyUDPInterface() : UDPInterface(), dynamicRange(16), scanTag(1000), nFrames(100), fWrite(1), fOverwrite(1), fIndex(0), fCaught(0), totfCaught(0), startAcqIndex(0), startFrameIndex(0), acqIndex(0), dataCompression(false), period(0), type(slsReceiverDefs::GENERIC), framesNeeded(100), udpPort1(1900), udpPort2(1901), shortFrame(0), nFramesToGui(0), e10G(0) {strcpy(detHostname,"none"); strcpy(fName,"run"); strcpy(fPath,"/scratch/"); strcpy(eth,"eth0"); cout << "New dummy UDP Interface" << endl;}; + + ~dummyUDPInterface() {cout << "Destroying dummy UDP Interface" << endl;}; + + + void del(){cout << "Destroying dummy UDP Interface" << endl;}; + + virtual void configure(map config_map) {}; + /** + * Initialize the Receiver + @param detectorHostName detector hostname + * you can call this function only once. You must call it before you call startReceiver() for the first time. + */ + virtual void initialize(const char *detectorHostName){ cout << "set detector hostname to" << detHostname << endl; strcpy(detHostname,detectorHostName);}; + + + /* Returns detector hostname + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ + virtual char *getDetectorHostname() const { cout << "get detector hostname " << detHostname << endl; return (char*) detHostname;}; + + /** + * Returns status of receiver: idle, running or error + */ + virtual slsReceiverDefs::runStatus getStatus() const { cout << "get dsummy status IDLE " << endl; return slsReceiverDefs::IDLE;};; + + /** + * Returns File Name + * caller is responsible to deallocate the returned char array. + */ + virtual char *getFileName() const { cout << "get file name " << fName << endl; return (char*) fName;}; + + + /** + * Returns File Path + * caller is responsible to deallocate the returned char array + */ + virtual char *getFilePath() const { cout << "get file path " << fPath << endl; return (char*) fPath;};; + + + /** + * Returns the number of bits per pixel + */ + virtual int getDynamicRange() const { cout << "get dynamic range " << dynamicRange << endl; return dynamicRange;};; + + /** + * Returns scan tag + */ + virtual int getScanTag() const { cout << "get scan tag " << scanTag << endl; return scanTag;}; + + /* + * Returns number of frames to receive + * This is the number of frames to expect to receiver from the detector. + * The data receiver will change from running to idle when it got this number of frames + */ + virtual int getNumberOfFrames() const { cout << "get number of frames " << nFrames << endl; return nFrames;}; + + /** + * Returns file write enable + * 1: YES 0: NO + */ + virtual int getEnableFileWrite() const { cout << "get enable file write " << fWrite << endl; return fWrite;}; + + /** + * Returns file over write enable + * 1: YES 0: NO + */ + virtual int getEnableOverwrite() const { cout << "get enable file overwrite " << fOverwrite << endl; return fOverwrite;}; + + /** + * Set File Name (without frame index, file index and extension) + @param c file name + /returns file name + * returns NULL on failure (like bad file name) + * does not check the existence of the file - we don't know which path we'll finally use, so no point to check. + * caller is responsible to deallocate the returned char array. + */ + virtual char* setFileName(const char c[]) { strcpy(fName,c); cout << "set file name " << fName << endl; return fName; }; + + /** + * Set File Path + @param c file path + /returns file path + * checks the existence of the directory. returns NULL if directory does not exist or is not readable. + * caller is responsible to deallocate the returned char array. + */ + virtual char* setFilePath(const char c[]) { strcpy(fPath,c); cout << "set file path " << fPath << endl; return fPath; }; + + /** + * Returns the number of bits per pixel + @param dr sets dynamic range + /returns dynamic range + * returns -1 on failure + * FIXME: what are the allowd values - should we use an enum as argument? + */ + virtual int setDynamicRange(const int dr) {dynamicRange=dr; cout << "set dynamic range " << dynamicRange << endl; return dynamicRange; }; + + + /** + * Set scan tag + @param tag scan tag + /returns scan tag (always non-negative) + * FIXME: valid range - only positive? 16bit ore 32bit? + * returns -1 on failure + */ + virtual int setScanTag(const int tag) {scanTag=tag; cout << "set scan tag " << scanTag << endl; return scanTag; }; + + + /** + * Sets number of frames + @param fnum number of frames + /returns number of frames + */ + virtual int setNumberOfFrames(const int fnum) {nFrames=fnum; cout << "set number of frames " << nFrames << endl; return nFrames; }; + + + /** + * Set enable file write + * @param i file write enable + /returns file write enable + */ + virtual int setEnableFileWrite(const int i) {fWrite=i; cout << "set enable file write " << fWrite << endl; return fWrite; }; + + + /** + * Set enable file overwrite + * @param i file overwrite enable + /returns file overwrite enable + */ + virtual int setEnableOverwrite(const int i) {fOverwrite=i; cout << "set enable file overwrite " << fOverwrite << endl; return fOverwrite; }; + + + /** + * Starts Receiver - activate all configuration settings to the eiger receiver and start to listen for packets + @param message is the error message if there is an error + /returns 0 on success or -1 on failure + */ + //FIXME: success == 0 or success == 1? + virtual int startReceiver(char *message=NULL) {cout << "dummy start receiver" << endl; return 0;}; + + /** + * Stops Receiver - stops listening for packets + /returns success + * same as abort(). Always returns 0. + */ + virtual int stopReceiver() {cout << "dummy stop receiver" << endl; return 0;}; + + /** + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + virtual void abort() {cout << "Aborting receiver" << endl; }; + + + +/******************************************************************************************************************* + **************************************** Added by Dhanya ********************************************************* + *******************************************************************************************************************/ + + /** + * Returns File Index + */ + virtual int getFileIndex() {cout << "get file index " << fIndex << endl; return fIndex;}; + + /** + * Returns Total Frames Caught for an entire acquisition (including all scans) + */ + virtual int getTotalFramesCaught() {cout << "get total frames caught " << totfCaught << endl ; return totfCaught;}; + + /** + * Returns Frames Caught for each real time acquisition (eg. for each scan) + */ + virtual int getFramesCaught() {cout << "get frames caught " << fCaught << endl; return fCaught;}; + + + /** + * Returns the frame index at start of entire acquisition (including all scans) + */ + virtual uint32_t getStartAcquisitionIndex(){ cout << "get start acquisition index " << startAcqIndex << endl; return startAcqIndex; }; + + /** + * Returns current Frame Index Caught for an entire acquisition (including all scans) + */ + virtual uint32_t getAcquisitionIndex(){ cout << "get acquisition index " << acqIndex << endl; return acqIndex; }; + + + /** + * Returns the frame index at start of each real time acquisition (eg. for each scan) + */ + virtual uint32_t getStartFrameIndex() { cout << "get start frame index " << startFrameIndex << endl; return startFrameIndex; }; + + + /** get data compression, by saving only hits + */ + virtual bool getDataCompression() { cout << "get data compression " << dataCompression << endl; return dataCompression;}; + + /** + * Set receiver type + * @param det detector type + * Returns success or FAIL + */ + virtual int setDetectorType(slsReceiverDefs::detectorType det) {type=det; cout << "set detector type " << det << endl; return slsReceiverDefs::OK;}; + + /** + * Set File Index + * @param i file index + */ + virtual int setFileIndex(int i) {fIndex=i; cout << "get file index " << fIndex << endl; return fIndex;}; + + /** set acquisition period if a positive number + */ + virtual int64_t setAcquisitionPeriod(int64_t index) {if (index>=0) {period=index; cout << "set period " << period << endl;} else { cout << "get period " << period << endl;} return period;}; + + /** + * Set Frame Index Needed + * @param i frame index needed + */ + virtual int setFrameIndexNeeded(int i) {framesNeeded=i; cout << "set frame index needed " << period << endl; return framesNeeded;}; + + /** + * Set UDP Port Number + */ + virtual void setUDPPortNo(int p){udpPort1=p; cout << "set UDP port 1 " << udpPort1 << endl; }; + + + /** + * Set UDP Port Number + */ + virtual void setUDPPortNo2(int p) {udpPort2=p; cout << "set UDP port 2 " << udpPort2 << endl; }; + + /** + * Set Ethernet Interface or IP to listen to + */ + virtual void setEthernetInterface(char* c){strcpy(eth,c); cout << "set eth " << c;}; + + /** + * Set short frame + * @param i if shortframe i=1 + */ + virtual int setShortFrame(int i){shortFrame=i; cout << " set short frame" << shortFrame << endl; return shortFrame;}; + + /** + * Set the variable to send every nth frame to gui + * or if 0,send frame only upon gui request + */ + virtual int setNFrameToGui(int i) {nFramesToGui=i; cout << "set nframes to gui " << nFramesToGui << endl; return nFramesToGui;}; + + /** + * Resets the Total Frames Caught + * This is how the receiver differentiates between entire acquisitions + * Returns 0 + */ + virtual void resetTotalFramesCaught() {totfCaught=0; cout << "total frames caugh reset " << totfCaught << endl;}; + + /** enabl data compression, by saving only hits + /returns if failed + */ + virtual int enableDataCompression(bool enable) {dataCompression=enable; cout << "set data compression " << dataCompression<< endl; return dataCompression;}; + + /** + * enable 10Gbe + @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out + \returns enable for 10Gbe + */ + virtual int enableTenGiga(int enable = -1) {if (enable>=0) {e10G=enable; cout << "set 10Gb "<< e10G << endl;} else cout << "get 10Gb "<< e10G << endl; return e10G;}; + + /** + * Returns the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param fnum frame number for eiger as it is not in the packet + * @param startAcquisitionIndex is the start index of the acquisition + * @param startFrameIndex is the start index of the scan + */ + virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){cout << "dummy read frame" << endl; }; + + /** set status to transmitting and + * when fifo is empty later, sets status to run_finished + */ + virtual void startReadout(){cout << "dummy start readout" << endl; }; + + /** + * shuts down the udp sockets + * \returns if success or fail + */ + virtual int shutDownUDPSockets(){cout << "dummy shut down udp sockets" << endl; return slsReceiverDefs::OK;}; + + /** + * Closes all files + * @param ithr thread index, -1 for all threads + */ + virtual void closeFile(int ithr = -1){cout << "dummy close file" << ithr << endl; }; + + /** + * Call back for start acquisition + callback arguments are + filepath + filename + fileindex + datasize + + return value is + 0 callback takes care of open,close,wrie file + 1 callback writes file, we have to open, close it + 2 we open, close, write file, callback does not do anything + */ + virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){cout << "dummy register callback start acquisition" << endl; }; + + /** + * Call back for acquisition finished + callback argument is + total frames caught + */ + virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){cout << "dummy register callback acquisition finished" << endl; }; + + /** + * Call back for raw data + args to raw data ready callback are + framenum + datapointer + datasize in bytes + file descriptor + guidatapointer (NULL, no data required) + */ +virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){cout << "dummy register callback get raw data" << endl; }; + + protected: + + private: + char detHostname[1000]; + char fName[10000]; + char fPath[10000]; + int dynamicRange; + int scanTag; + int nFrames; + int fWrite; + int fOverwrite; + + int fIndex; + int fCaught; +int totfCaught; +int startAcqIndex; +int startFrameIndex; +int acqIndex; +bool dataCompression; + int64_t period; + slsReceiverDefs::detectorType type; + int framesNeeded; + int udpPort1; + int udpPort2; + char eth[1000]; + int shortFrame; + int nFramesToGui; + int e10G; +}; + +#endif /* #ifndef DUMMYUDPINTERFACE_H */ diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 4b0d10161b..6f3b1acd35 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -68,6 +68,23 @@ +#define JCTB_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 +/*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ +#define JCTB_PACKETS_PER_FRAME 50 +#define JCTB_ONE_PACKET_SIZE 8214 +#define JCTB_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) +#define JCTB_DATA_BYTES (JCTB_BUFFER_PER_FRAME) + +#define JCTB_FRAME_INDEX_MASK 0xFFFFFF00 +#define JCTB_FRAME_INDEX_OFFSET 8 +#define JCTB_PACKET_INDEX_MASK 0xFF + +#define JCTB_BYTES_PER_ADC (2) +#define JCTB_PIXELS_IN_ONE_ROW 32 +#define JCTB_BYTES_IN_ONE_ROW (JCTB_PIXELS_IN_ONE_ROW*2) + + + #define EIGER_MAX_PORTS 2 #define EIGER_HEADER_LENGTH 48 diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 93ad2c8d19..3b3a30b020 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -269,6 +269,12 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD case EIGER: cout << endl << "***** This is a EIGER Receiver *****" << endl << endl; break; + case JUNGFRAUCTB: + cout << endl << "***** This is a JUNGFRAUCTB Receiver *****" << endl << endl; + break; + case JUNGFRAU: + cout << endl << "***** This is a JUNGFRAU Receiver *****" << endl << endl; + break; default: cout << endl << "***** Unknown Receiver *****" << endl << endl; return FAIL; @@ -315,6 +321,16 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD createListeningThreads(true); numListeningThreads = MAX_NUM_LISTENING_THREADS; + } else if(myDetectorType == JUNGFRAUCTB || myDetectorType == JUNGFRAU ){ + fifosize = JCTB_FIFO_SIZE; + packetsPerFrame = JCTB_PACKETS_PER_FRAME; + onePacketSize = JCTB_ONE_PACKET_SIZE; + frameSize = JCTB_BUFFER_SIZE; + bufferSize = JCTB_BUFFER_SIZE; + maxPacketsPerFile = JFCTB_MAX_FRAMES_PER_FILE * JCTB_PACKETS_PER_FRAME; + frameIndexMask = JCTB_FRAME_INDEX_MASK; + frameIndexOffset = JCTB_FRAME_INDEX_OFFSET; + packetIndexMask = JCTB_PACKET_INDEX_MASK; } latestData = new char[frameSize]; diff --git a/slsReceiverSoftware/src/dummyMain.cpp b/slsReceiverSoftware/src/dummyMain.cpp new file mode 100644 index 0000000000..41494fd99f --- /dev/null +++ b/slsReceiverSoftware/src/dummyMain.cpp @@ -0,0 +1,46 @@ +/* A simple server in the internet domain using TCP + The port number is passed as an argument */ + +#include "sls_receiver_defs.h" +#include "dummyUDPInterface.h" +#include "slsReceiverTCPIPInterface.h" + +#include +#include + + +using namespace std; + + +int main(int argc, char *argv[]) { + int success; + int tcpip_port_no; + bool bottom = false; + cout << "CCCCCC" << endl; + dummyUDPInterface *udp=new dummyUDPInterface(); + slsReceiverTCPIPInterface *tcpipInterface = new slsReceiverTCPIPInterface(success, udp, tcpip_port_no, bottom); + + + + + if(tcpipInterface->start() == slsReceiverDefs::OK){ + cout << "DONE!" << endl; + string str; + cin>>str; + //wait and look for an exit keyword + while(str.find("exit") == string::npos) + cin>>str; + //stop tcp server thread, stop udp socket + tcpipInterface->stop(); + } + + if (tcpipInterface) + delete tcpipInterface; + if(udp) + delete udp; + return 0; + + + +} + diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 240784ea56..54a52cc903 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -26,9 +26,9 @@ using namespace std; slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { + closeFile(0); if(socket) {delete socket; socket=NULL;} if(receiverBase) {delete receiverBase; receiverBase=NULL;} - closeFile(0); } slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn, bool bot): @@ -652,7 +652,9 @@ int slsReceiverTCPIPInterface::setup_udp(){ receiverBase->setUDPPortNo2(udpport2); //setup udpip //get ethernet interface or IP to listen to + cout << "Ethernet interface is " << args[0] << endl; temp = genericSocket::ipToName(args[0]); + cout << temp << endl; if(temp=="none"){ ret = FAIL; strcpy(mess, "failed to get ethernet interface or IP to listen to\n"); @@ -666,10 +668,11 @@ int slsReceiverTCPIPInterface::setup_udp(){ FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; receiverBase->setEthernetInterface(eth); + cout << eth << endl; //get mac address from ethernet interface if (ret != FAIL) temp = genericSocket::nameToMac(eth); - + if ((temp=="00:00:00:00:00:00") || (ret == FAIL)){ ret = FAIL; From d9809925af3efb2e164ecfdde98934f7fb13478b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 12 May 2015 14:28:13 +0200 Subject: [PATCH 085/222] debugging statements --- slsReceiverSoftware/include/genericSocket.h | 32 +++++++++++++++++++ .../src/UDPStandardImplementation.cpp | 5 ++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index a10e07649d..63de4b5def 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -92,6 +92,13 @@ enum communicationProtocol{ UDP /**< UDP */ }; +typedef struct +{ + unsigned char header_before[20]; + unsigned char fnum[4]; + unsigned char header_after[24]; +} eiger_image_header; + genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : // portno(port_number), protocol(p), @@ -578,8 +585,33 @@ enum communicationProtocol{ //if length given, listens to length, else listens for packetsize till length is reached if(length){ + +/*int k =0;*/ while(length>0){ nsending = (length>packet_size) ? packet_size:length; + +/* + //created for debugging on 11.05.2015 + nsending=5000; + + nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); + + if(nsent <1000){ + if(nsent < 48){ + cout << " "<fnum)<< "\t"; + + cout << k <<" packets" << endl; + k = 0; + } + } + else + k++; +*/ + + nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); if(!nsent) break; length-=nsent; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 93ad2c8d19..1b9a97c7f7 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1950,9 +1950,8 @@ int UDPStandardImplementation::startWriting(){ currframenum = tempframenum; pthread_mutex_unlock(&progress_mutex); } -#ifdef VERYDEBUG - if(myDetectorType == EIGER) - cout << endl < Date: Wed, 13 May 2015 10:30:39 +0200 Subject: [PATCH 086/222] not significant --- slsReceiverSoftware/include/genericSocket.h | 22 +-------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 63de4b5def..519fd52e55 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -586,30 +586,10 @@ typedef struct //if length given, listens to length, else listens for packetsize till length is reached if(length){ -/*int k =0;*/ + while(length>0){ nsending = (length>packet_size) ? packet_size:length; -/* - //created for debugging on 11.05.2015 - nsending=5000; - - nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); - - if(nsent <1000){ - if(nsent < 48){ - cout << " "<fnum)<< "\t"; - - cout << k <<" packets" << endl; - k = 0; - } - } - else - k++; -*/ nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); From 92dfb366f6962b5b814895392df6d077842cb604 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 19 May 2015 10:12:09 +0200 Subject: [PATCH 087/222] gemma offline reading works --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 1cc19d7bb6..29de72adac 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1994,7 +1994,7 @@ int UDPStandardImplementation::startWriting(){ = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); //new port number as its the same everywhere for 32 bit!! - if(!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = 0x00; + if((!j)&& (!bottom)) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = 0x00; #ifdef VERYDEBUG From c8403051891445ab4d0870f658d840d10ee3171b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 21 May 2015 17:39:17 +0200 Subject: [PATCH 088/222] starting receiver only at set detector type works --- slsReceiverSoftware/include/UDPBaseImplementation.h | 5 +++++ slsReceiverSoftware/include/UDPInterface.h | 6 ++++++ slsReceiverSoftware/src/UDPBaseImplementation.cpp | 2 +- slsReceiverSoftware/src/slsReceiver.cpp | 4 +++- .../src/slsReceiverTCPIPInterface.cpp | 13 +++++++++---- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 4801c751e9..ed7889ae82 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -65,6 +65,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ int setDetectorType(detectorType det); + /** + * Set bottom to bot + * @param bot = 1 if bottom + */ + void setBottom(int bot); //Frame indices and numbers caught /** diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 8f3ce3f41c..8952396f3f 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -225,6 +225,12 @@ class UDPInterface { **************************************** Added by Dhanya ********************************************************* *******************************************************************************************************************/ + /** + * Set bottom to bot + * @param bot = 1 if bottom + */ + virtual void setBottom(int bot)= 0; + /** * Returns File Index */ diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index c70be5b7da..bbb8b331d7 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -143,7 +143,7 @@ int UDPBaseImplementation::setDetectorType(detectorType det){ - +void UDPBaseImplementation::setBottom(int bot){bottom=bot;}; /*Frame indices and numbers caught*/ diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 6ffc2fdf98..e43820613d 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -36,6 +36,7 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ string fname = ""; string udp_interface_type = "standard"; string rest_hostname = "localhost:8081"; + udp_interface = NULL; bool bottom = false; //TODO: properly set new parameter -> mode? //parse command line for config @@ -128,10 +129,11 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ if (success==OK){ FILE_LOG(logINFO) << "SLS Receiver starting " << udp_interface_type << " on port " << tcpip_port_no << " with mode " << bottom << endl; +#ifdef REST udp_interface = UDPInterface::create(udp_interface_type); udp_interface->configure(configuration_map); +#endif tcpipInterface = new slsReceiverTCPIPInterface(success, udp_interface, tcpip_port_no, bottom); - //tcp ip interface } } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 54a52cc903..c12e82ff29 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -45,7 +45,7 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* bottom(bot){ int port_no=portNumber; - + if(receiverBase == NULL) receiverBase = 0; if (pn>0) port_no = pn; @@ -198,11 +198,12 @@ void slsReceiverTCPIPInterface::startTCPServer(){ //if tcp command was to exit server if(v==GOODBYE){ cout << "Shutting down UDP Socket" << endl; - if(receiverBase) + if(receiverBase){ receiverBase->shutDownUDPSockets(); - cout << "Closing Files... " << endl; - receiverBase->closeFile(); + cout << "Closing Files... " << endl; + receiverBase->closeFile(); + } pthread_exit(NULL); } @@ -364,6 +365,10 @@ int slsReceiverTCPIPInterface::set_detector_type(){ } else{ myDetectorType = dr; +#ifndef REST + receiverBase = UDPInterface::create("standard"); + receiverBase->setBottom(bottom); +#endif ret=receiverBase->setDetectorType(dr); retval = myDetectorType; } From 99196aa272231ff3deafb3a6f6f95a8969686999 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 26 May 2015 12:08:21 +0200 Subject: [PATCH 089/222] ignore 16 byte messages --- slsReceiverSoftware/include/genericSocket.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 519fd52e55..58c9bb5a44 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -589,11 +589,12 @@ typedef struct while(length>0){ nsending = (length>packet_size) ? packet_size:length; - - - nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); if(!nsent) break; + if(nsent == 16) { + //cout << "."; + continue; + } length-=nsent; total_sent+=nsent; } From 4f88e831c40b2e0319c638564ae20b66802539f5 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 26 May 2015 17:01:42 +0200 Subject: [PATCH 090/222] checks if receiver udp object was created before executing functions and hence always returns a ret --- .../src/slsReceiverTCPIPInterface.cpp | 174 +++++++++++++++--- 1 file changed, 144 insertions(+), 30 deletions(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index c12e82ff29..720784b14a 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -421,6 +421,10 @@ int slsReceiverTCPIPInterface::set_file_name() { if (lockStatus==1 && socket->differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; + } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; } else strcpy(retval,receiverBase->setFileName(fName)); @@ -476,6 +480,10 @@ int slsReceiverTCPIPInterface::set_file_dir() { strcpy(mess,"Can not set file path while receiver running\n"); ret = FAIL; }*/ + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else{ strcpy(retval,receiverBase->setFilePath(fPath)); // if file path doesnt exist @@ -535,6 +543,10 @@ int slsReceiverTCPIPInterface::set_file_index() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else retval=receiverBase->setFileIndex(index); } @@ -588,6 +600,10 @@ int slsReceiverTCPIPInterface::set_frame_index() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else retval=receiverBase->setFrameIndexNeeded(index); } @@ -645,6 +661,10 @@ int slsReceiverTCPIPInterface::setup_udp(){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else if(receiverBase->getStatus()==RUNNING){ ret = FAIL; strcpy(mess,"cannot set up udp when receiver is running\n"); @@ -732,6 +752,10 @@ int slsReceiverTCPIPInterface::start_receiver(){ ret = FAIL; } */ + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else { s = receiverBase->getStatus(); switch (s) { @@ -780,6 +804,10 @@ int slsReceiverTCPIPInterface::stop_receiver(){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else if(receiverBase->getStatus()!=IDLE) ret=receiverBase->stopReceiver(); #endif @@ -802,20 +830,25 @@ int slsReceiverTCPIPInterface::stop_receiver(){ int slsReceiverTCPIPInterface::get_status(){ ret=OK; - enum runStatus retval; + enum runStatus retval = ERROR; // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - retval=receiverBase->getStatus(); + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else retval=receiverBase->getStatus(); #endif - if(socket->differentClients){ + if(ret==OK && socket->differentClients){ cout << "Force update" << endl; ret=FORCE_UPDATE; } // send answer socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -830,15 +863,20 @@ int slsReceiverTCPIPInterface::get_frames_caught(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - retval=receiverBase->getTotalFramesCaught(); + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else retval=receiverBase->getTotalFramesCaught(); #endif - if(socket->differentClients){ + if(ret==OK && socket->differentClients){ cout << "Force update" << endl; ret=FORCE_UPDATE; } // send answer socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -853,16 +891,22 @@ int slsReceiverTCPIPInterface::get_frame_index(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - retval=receiverBase->getAcquisitionIndex(); + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else + retval=receiverBase->getAcquisitionIndex(); #endif - if(socket->differentClients){ + if(ret==OK && socket->differentClients){ cout << "Force update" << endl; ret=FORCE_UPDATE; } // send answer socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -884,6 +928,10 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else receiverBase->resetTotalFramesCaught(); } @@ -936,6 +984,10 @@ int slsReceiverTCPIPInterface::set_short_frame() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else if(receiverBase->getStatus()==RUNNING){ strcpy(mess,"Cannot set short frame while status is running\n"); ret=FAIL; @@ -1009,9 +1061,12 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } /**send garbage with -1 index to try again*/ - if(!receiverBase->getFramesCaught()){ + else if(!receiverBase->getFramesCaught()){ startAcquisitionIndex = -1; cout<<"haven't caught any frame yet"<getFramesCaught()){ + else if(!receiverBase->getFramesCaught()){ startAcquisitionIndex=-1; cout<<"haven't caught any frame yet"<getFramesCaught()){ + else if(!receiverBase->getFramesCaught()){ startAcquisitionIndex=-1; #ifdef VERBOSE cout<<"haven't caught any frame yet"<differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; - }/* + } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } + /* else if((receiverBase->getStatus()==RUNNING) && (index >= 0)){ ret = FAIL; strcpy(mess,"cannot set up receiver mode when receiver is running\n"); @@ -1667,6 +1733,10 @@ int slsReceiverTCPIPInterface::enable_file_write(){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else{ if(enable >= 0) receiverBase->setEnableFileWrite(enable); @@ -1733,21 +1803,28 @@ int slsReceiverTCPIPInterface::start_readout(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS - receiverBase->startReadout(); - retval = receiverBase->getStatus(); - if((retval == TRANSMITTING) || (retval == RUN_FINISHED) || (retval == IDLE)) - ret = OK; - else - ret = FAIL; + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else{ + receiverBase->startReadout(); + retval = receiverBase->getStatus(); + if((retval == TRANSMITTING) || (retval == RUN_FINISHED) || (retval == IDLE)) + ret = OK; + else + ret = FAIL; + } #endif - if(socket->differentClients){ + if(ret==OK && socket->differentClients){ cout << "Force update" << endl; ret=FORCE_UPDATE; } // send answer socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -1779,6 +1856,10 @@ int slsReceiverTCPIPInterface::set_timer() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else{ if(index[0] == slsReceiverDefs::FRAME_PERIOD) retval=receiverBase->setAcquisitionPeriod(index[1]); @@ -1838,6 +1919,10 @@ int slsReceiverTCPIPInterface::enable_compression() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else if(receiverBase->getStatus()==RUNNING){ strcpy(mess,"Cannot enable/disable compression while status is running\n"); ret=FAIL; @@ -1846,7 +1931,11 @@ int slsReceiverTCPIPInterface::enable_compression() { ret = receiverBase->enableDataCompression(enable); } - retval=receiverBase->getDataCompression(); + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else + retval=receiverBase->getDataCompression(); } #endif @@ -1887,6 +1976,10 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { if (lockStatus==1 && socket->differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; + } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; } else{ receiverBase->initialize(hostname); @@ -1955,14 +2048,19 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } } if(ret!=FAIL){ - retval=receiverBase->setDynamicRange(dr); - dynamicrange = dr; - if(myDetectorType == EIGER){ - if(!tenGigaEnable) - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; - else - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; - } + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else{ + retval=receiverBase->setDynamicRange(dr); + dynamicrange = dr; + if(myDetectorType == EIGER){ + if(!tenGigaEnable) + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + else + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + } + } } } #ifdef VERBOSE @@ -2014,6 +2112,10 @@ int slsReceiverTCPIPInterface::enable_overwrite() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else{ if(index >= 0) receiverBase->setEnableOverwrite(index); @@ -2069,6 +2171,10 @@ int slsReceiverTCPIPInterface::enable_tengiga() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } else{ retval=receiverBase->enableTenGiga(val); if((val!=-1) && (val != retval)) @@ -2313,7 +2419,15 @@ int slsReceiverTCPIPInterface::send_update() { int slsReceiverTCPIPInterface::update_client() { ret=OK; + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } socket->SendDataOnly(&ret,sizeof(ret)); + if(ret == FAIL){ + socket->SendDataOnly(mess,sizeof(mess)); + return ret; + } return send_update(); } From 849d0de5cbc2fb2047f494fa453c1580f04e47da Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 10 Jun 2015 12:23:38 +0200 Subject: [PATCH 091/222] not much valuable change --- .../include/UDPBaseImplementation.h | 8 ----- slsReceiverSoftware/include/genericSocket.h | 31 ++++++++++++++++++- .../src/UDPStandardImplementation.cpp | 2 -- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index ed7889ae82..cb5c081959 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -491,14 +491,6 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter unsigned char fnum[4]; unsigned char header_after[24]; } eiger_image_header; - /** structure of an eiger image header*/ - typedef struct - { - unsigned char header_before[19]; - unsigned char fnum[4]; - unsigned char header_after[25]; - } eiger_image_header32; - /** structure of an eiger image header*/ typedef struct diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 58c9bb5a44..0ccc80adfc 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -99,6 +99,13 @@ typedef struct unsigned char header_after[24]; } eiger_image_header; +typedef struct +{ + unsigned char header_before[19]; + unsigned char fnum[4]; + unsigned char header_after[25]; +} eiger_image_header32; + genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : // portno(port_number), protocol(p), @@ -585,10 +592,32 @@ typedef struct //if length given, listens to length, else listens for packetsize till length is reached if(length){ - +/*int k = 0;*/ while(length>0){ nsending = (length>packet_size) ? packet_size:length; + + /* + + //created for debugging on 11.05.2015 + nsending=5000; + nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); + if(nsent <1000){ + if(nsent < 48){ + cout << " "<fnum)<< "\t"; + cout << k <<" packets" << endl; + k = 0; + } + } + else + k++; + */ + + + nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); if(!nsent) break; if(nsent == 16) { diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 29de72adac..f6fe25fcbd 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -26,8 +26,6 @@ using namespace std; -#define EIGER_32BIT_INITIAL_CONSTANT 0x17c - From fdaca8822583fced5db1d0fc231bd23046ec11e2 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 10 Jun 2015 13:26:51 +0200 Subject: [PATCH 092/222] includes 32 bit subframes --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index f6fe25fcbd..d6e85c5c7a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1945,7 +1945,7 @@ int UDPStandardImplementation::startWriting(){ if(dynamicRange != 32) tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); else - tempframenum = htonl(*(unsigned int*)((eiger_image_header32 *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 @@ -2136,9 +2136,9 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ if (myDetectorType == EIGER){ //add currframenum later in this method for scans - if(dynamicRange == 32) + /*if(dynamicRange == 32) startFrameIndex = htonl(*(unsigned int*)((eiger_image_header32 *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - else + else*/ startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); } //gotthard has +1 for frame number and not a short frame From 28ed7d6b2d4e492c196e45fcc449d105e3f10e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Br=C3=BCckner?= Date: Thu, 11 Jun 2015 11:25:49 +0200 Subject: [PATCH 093/222] Solved merge conflicts --- slsReceiverSoftware/include/genericSocket.h | 35 ++------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 0ccc80adfc..e113f24b85 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -99,13 +99,6 @@ typedef struct unsigned char header_after[24]; } eiger_image_header; -typedef struct -{ - unsigned char header_before[19]; - unsigned char fnum[4]; - unsigned char header_after[25]; -} eiger_image_header32; - genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : // portno(port_number), protocol(p), @@ -592,38 +585,16 @@ typedef struct //if length given, listens to length, else listens for packetsize till length is reached if(length){ -/*int k = 0;*/ + while(length>0){ nsending = (length>packet_size) ? packet_size:length; - /* - - //created for debugging on 11.05.2015 - nsending=5000; - nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); - if(nsent <1000){ - if(nsent < 48){ - cout << " "<fnum)<< "\t"; - cout << k <<" packets" << endl; - k = 0; - } - } - else - k++; - */ - - + nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); if(!nsent) break; - if(nsent == 16) { - //cout << "."; - continue; - } + if (nsent == 16) continue; length-=nsent; total_sent+=nsent; } From b27f691d036a7171db732ff1c4e16a15f92164fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Br=C3=BCckner?= Date: Thu, 11 Jun 2015 11:30:40 +0200 Subject: [PATCH 094/222] Revert "Solved merge conflicts" This reverts commit c222221d18bd5db7d9a8c86071fe2fbdc0ce25ac. --- slsReceiverSoftware/include/genericSocket.h | 35 +++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index e113f24b85..0ccc80adfc 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -99,6 +99,13 @@ typedef struct unsigned char header_after[24]; } eiger_image_header; +typedef struct +{ + unsigned char header_before[19]; + unsigned char fnum[4]; + unsigned char header_after[25]; +} eiger_image_header32; + genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : // portno(port_number), protocol(p), @@ -585,16 +592,38 @@ typedef struct //if length given, listens to length, else listens for packetsize till length is reached if(length){ - +/*int k = 0;*/ while(length>0){ nsending = (length>packet_size) ? packet_size:length; - + /* + + //created for debugging on 11.05.2015 + nsending=5000; + nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); + if(nsent <1000){ + if(nsent < 48){ + cout << " "<fnum)<< "\t"; + cout << k <<" packets" << endl; + k = 0; + } + } + else + k++; + */ + + nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); if(!nsent) break; - if (nsent == 16) continue; + if(nsent == 16) { + //cout << "."; + continue; + } length-=nsent; total_sent+=nsent; } From bcf8d40fd2f7349fb7bb8651d4749ed8cf8dd4c5 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 12 Jun 2015 17:46:50 +0200 Subject: [PATCH 095/222] minor changes, but posted semaphore in stop receiver so rxr not waiting forever for gui when it will never come --- .../src/UDPStandardImplementation.cpp | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index d6e85c5c7a..bd2e7560a6 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -890,7 +890,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui if (guiData == NULL){ guiData = latestData; #ifdef VERY_VERY_DEBUG - cout << "gui data not null anymore" << endl; + cprintf(CYAN,"gui data not null anymore\n"); #endif } @@ -904,14 +904,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //could not get gui data if(!guiDataReady){ #ifdef VERY_VERY_DEBUG - cout << "gui data not ready" << endl; + cprintf(CYAN,"gui data not ready\n"); #endif *raw = NULL; } //data ready, set guidata to receive new data else{ #ifdef VERY_VERY_DEBUG - cout << "gui data ready" << endl; + cprintf(CYAN,"gui data ready\n"); #endif *raw = guiData; guiData = NULL; @@ -921,14 +921,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui pthread_mutex_unlock(&dataReadyMutex);*/ if((nFrameToGui) && (writerthreads_mask)){ #ifdef VERY_VERY_DEBUG - cout << "gonna post" << endl; + cprintf(CYAN,"gonna post\n"); #endif /*if(nFrameToGui){*/ //release after getting data sem_post(&smp); } #ifdef VERY_VERY_DEBUG - cout << "done post" << endl; + cprintf(CYAN,"done post\n"); #endif } } @@ -947,7 +947,7 @@ cout << "copyframe" << endl; //else guidata always null as guidataready is always 1 after 1st frame, and seccond data never gets copied if((!nFrameToGui) && (!guiData)){ #ifdef VERY_VERY_DEBUG - cout << "doing nothing" << endl; + cprintf(GREEN,"doing nothing\n"); #endif pthread_mutex_lock(&dataReadyMutex); guiDataReady=0; @@ -957,12 +957,12 @@ cout << "copyframe" << endl; //random read or nth frame read, gui needs data now or it is the first frame else{ #ifdef VERY_VERY_DEBUG - cout << "gui needs data now or 1st frame" << endl; + cprintf(GREEN,"gui needs data now or 1st frame\n"); #endif pthread_mutex_lock(&dataReadyMutex); guiDataReady=0; #ifdef VERY_VERY_DEBUG - cout << "guidataready is 0, copying data" << endl; + cprintf(GREEN,"guidataready is 0, copying data\n"); #endif //eiger if(startbuf != NULL){ @@ -989,16 +989,16 @@ cout << "copyframe" << endl; guiDataReady=1; pthread_mutex_unlock(&dataReadyMutex); #ifdef VERY_VERY_DEBUG - cout << "guidataready = 1" << endl; + cprintf(GREEN,"guidataready = 1\n"); #endif //nth frame read, block current process if the guireader hasnt read it yet if(nFrameToGui){ #ifdef VERY_VERY_DEBUG - cout<<"waiting after copying"<push(buffer[ithread])); #ifdef FIFO_DEBUG //if(!ithread) - cprintf(RED, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); + cprintf(MAGENTA, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif } @@ -1934,7 +1939,7 @@ int UDPStandardImplementation::startWriting(){ continue; } #ifdef VERYDEBUG - else cout <<"**NOT a dummy packet"<push(wbuf[i])); @@ -2196,7 +2201,7 @@ int i; //free buffer if(rc <= 0){ cout << ithread << "Discarding empty frame/ End of acquisition" << endl; - fifoFree[ithread]->push(buffer[ithread]); + fifoFree[ithread]->push(buffer[ithread]);/** why not while(!)*/ #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); #endif @@ -2208,7 +2213,7 @@ int i; if(rc == 266240) cprintf(GREEN, "%d Start of detector: Received test frame of 266240 bytes.\n",ithread); cout << ithread << "Discarding incomplete frame" << endl; - fifoFree[ithread]->push(buffer[ithread]); + fifoFree[ithread]->push(buffer[ithread]);/** why not while(!)*/ #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener last buffer free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); #endif From 9a61841ac769d8d46e07fa95ab1047be14f816b5 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 16 Jun 2015 12:00:02 +0200 Subject: [PATCH 096/222] git version update --- slsReceiverSoftware/gitInfo.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index d680dad1d7..a8b18fa13e 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware -URL: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repsitory UUID: 879c5e2ee129acfd70aba4ae6fab829cc5409350 -Revision: 67 -Branch: gemma -Last Changed Author: Maliakal_Dhanya -Last Changed Rev: 67 -Last Changed Date: 2014-12-08 09:17:56 +0100 +URL: origin maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git +Repository Root: origin maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git +Repsitory UUID: 44d2a6ae0422ef1d792890a409d202d3cec5b7f7 +Revision: 108 +Branch: master +Last Changed Author: Dhanya_Maliakal +Last Changed Rev: 108 +Last Changed Date: 2015-06-12 17:46:50 +0200 From 8b282e3bbe4d9a15ae2de2157498aba31270dc6e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 16 Jun 2015 16:28:24 +0200 Subject: [PATCH 097/222] write headers is compulsory for eiger --- .../src/UDPStandardImplementation.cpp | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index bd2e7560a6..e6722aeda9 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -27,6 +27,7 @@ using namespace std; +#define WRITE_HEADERS UDPStandardImplementation::UDPStandardImplementation() @@ -2380,44 +2381,46 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num offset += EIGER_HEADER_LENGTH; #ifdef WRITE_HEADERS #ifdef VERY_DEBUG - int k = 0; - if(dynamicRange != 32){ - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); - k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); - k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); - }else{ - k = 0; - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); - k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); - k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); - k = 256; - cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); - k = 512; - cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); - k = 768; - cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + if(myDetectorType == EIGER){ + int k = 0; + if(dynamicRange != 32){ + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); + k = 1; + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + k = 2; + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + }else{ + k = 0; + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); + k = 1; + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + k = 2; + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + k = 256; + cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + k = 512; + cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + k = 768; + cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + } } #endif #endif From 237c5286cad8988da0d94dc1158498cdecd19bdf Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 26 Jun 2015 11:49:26 +0200 Subject: [PATCH 098/222] includes dynamic range in offline headers for eiger --- slsReceiverSoftware/gitInfo.txt | 8 +++--- slsReceiverSoftware/include/gitInfoReceiver.h | 12 ++++---- .../src/UDPStandardImplementation.cpp | 28 +++++++++++-------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index a8b18fa13e..787a95474c 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git Repository Root: origin maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repsitory UUID: 44d2a6ae0422ef1d792890a409d202d3cec5b7f7 -Revision: 108 +Repsitory UUID: 2afc468d30f3078b2bb8637584ae3a88f476f20b +Revision: 110 Branch: master Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 108 -Last Changed Date: 2015-06-12 17:46:50 +0200 +Last Changed Rev: 110 +Last Changed Date: 2015-06-16 16:28:24 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 967f26e159..59e2a1dfff 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" -#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git" +#define SVNURL "maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "e019a6ce7d96d4ac9cb5762b7137245aedb4d5b8" -//#define SVNREV 0x22 +#define SVNREPUUID "2afc468d30f3078b2bb8637584ae3a88f476f20b" +//#define SVNREV 0x110 //#define SVNKIND "" //#define SVNSCHED "" -#define SVNAUTH "Anna_Bergamaschi" -#define SVNREV 0x22 -#define SVNDATE 0x20141015 +#define SVNAUTH "Dhanya_Maliakal" +#define SVNREV 0x110 +#define SVNDATE 0x20150616 // diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index e6722aeda9..7c6f9ee4e1 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1982,13 +1982,27 @@ int UDPStandardImplementation::startWriting(){ for(i=0;i 0){ + } + + else if (numpackets > 0){ for(j=0;jnum1)) = currframenum; + //overwriting port number and dynamic range + if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = (dynamicRange<<2); + else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + +#ifdef VERYDEBUG + cprintf(RED, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4))); +#endif + + } //for 32 bit,port number needs to be changed and packet number reconstructed if(dynamicRange == 32){ @@ -1997,10 +2011,6 @@ int UDPStandardImplementation::startWriting(){ (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); - //new port number as its the same everywhere for 32 bit!! - if((!j)&& (!bottom)) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = 0x00; - - #ifdef VERYDEBUG cprintf(RED, "%d - 0x%x - %d - %d\n", i, (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), @@ -2013,10 +2023,6 @@ int UDPStandardImplementation::startWriting(){ (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))+(packetsPerFrame/4)); - //new port number as its the same everywhere for 32 bit!! - if(!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = 0x00; - - #ifdef VERYDEBUG cprintf(RED, "%d -0x%x - %d - %d\n", i, (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), From 7e02a9d3d18c8d4d4c220c5d535fc7a8144baae1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 26 Jun 2015 15:57:28 +0200 Subject: [PATCH 099/222] resolved flip bytes in eiger --- .../src/slsReceiverTCPIPInterface.cpp | 39 ------------------- 1 file changed, 39 deletions(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 720784b14a..5fc7ced7d2 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1557,45 +1557,6 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ } } -/* - int inum = 0; - //dr = 16, hence uint16_t - for(inum = 0; inum < 2; inum++) - cprintf(YELLOW,"before htonl %d,0 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); - for(inum = 254; inum < 258; inum++) - cprintf(YELLOW,"before htonl %d,0 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); - for(inum = 0; inum < 2; inum++) - cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); - for(inum = 254; inum < 258; inum++) - cprintf(YELLOW,"before htonl %d,2 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); -*/ - - - //64 bit htonl cuz of endianness - for(i=0;i<(1024*(16*dynamicrange)*2)/8;i++){ - (*(((uint64_t*)retval)+i)) = be64toh(((uint64_t)(*(((uint64_t*)retval)+i)))); - /* - int64_t temp; - temp = ((uint64_t)(*(((uint64_t*)retval)+i))); - temp = ((temp << 8) & 0xFF00FF00FF00FF00ULL ) | ((temp >> 8) & 0x00FF00FF00FF00FFULL ); - temp = ((temp << 16) & 0xFFFF0000FFFF0000ULL ) | ((temp >> 16) & 0x0000FFFF0000FFFFULL ); - temp = (temp << 32) | ((temp >> 32) & 0xFFFFFFFFULL); - (*(((uint64_t*)retval)+i)) = temp; - */ - } - -/* - //dr = 16, hence uint16_t - for(inum = 0; inum < 2; inum++) - cprintf(MAGENTA,"after htonl %d,0 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); - for(inum = 254; inum < 258; inum++) - cprintf(MAGENTA,"after htonl %d,0 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+(inum*(dynamicrange/8)))))))); - for(inum = 0; inum < 2; inum++) - cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); - for(inum = 254; inum < 258; inum++) - cprintf(MAGENTA,"after htonl %d,2 :%d\n",inum,((uint8_t)(*((uint8_t*)((char*)(retval+((2048+inum)*(dynamicrange/8)))))))); -*/ - acquisitionIndex = index-startAcquisitionIndex; From 3600fb6304554178923167b6d50412a693100944 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 29 Jun 2015 16:57:16 +0200 Subject: [PATCH 100/222] git rev in --- slsReceiverSoftware/gitInfo.txt | 8 ++++---- slsReceiverSoftware/include/gitInfoReceiver.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 787a95474c..71d112f950 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git Repository Root: origin maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repsitory UUID: 2afc468d30f3078b2bb8637584ae3a88f476f20b -Revision: 110 +Repsitory UUID: 750a0a06945a748a18d0b8b19b7cf94ecf2fec23 +Revision: 112 Branch: master Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 110 -Last Changed Date: 2015-06-16 16:28:24 +0200 +Last Changed Rev: 112 +Last Changed Date: 2015-06-26 15:57:28 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 59e2a1dfff..19ffa6835c 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "2afc468d30f3078b2bb8637584ae3a88f476f20b" -//#define SVNREV 0x110 +#define SVNREPUUID "750a0a06945a748a18d0b8b19b7cf94ecf2fec23" +//#define SVNREV 0x112 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x110 -#define SVNDATE 0x20150616 +#define SVNREV 0x112 +#define SVNDATE 0x20150626 // From 88e96d45e7da69dea0f98eb6f6001d41a6abf3cb Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 30 Jun 2015 17:21:45 +0200 Subject: [PATCH 101/222] getting dr from rxr fixed --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 8 +++++--- slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 7c6f9ee4e1..0b22d88884 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -563,10 +563,11 @@ int UDPStandardImplementation::getDynamicRange() const{ int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " called"; - cout << "Setting Dynamic Range" << endl; - int olddr = dynamicRange; + if(dr >= 0){ + cout << "Setting Dynamic Range to " << dr << endl; + dynamicRange = dr; if(myDetectorType == EIGER){ @@ -615,7 +616,8 @@ int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEB } } - } + }else cout << "Getting Dynamic Range " << endl; + return getDynamicRange(); } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 5fc7ced7d2..2c882b1390 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1996,7 +1996,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else if(myDetectorType == EIGER){ + else if ((dr>0) && (myDetectorType == EIGER)){ switch(dr){ case 4: case 8: @@ -2004,6 +2004,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { case 32:break; default: sprintf(mess,"This dynamic range does not exist for eiger: %d\n",dr); + cprintf(RED,"%s", mess); ret=FAIL; break; } @@ -2013,8 +2014,9 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; }else{ - retval=receiverBase->setDynamicRange(dr); - dynamicrange = dr; + if(dr > 0) receiverBase->setDynamicRange(dr); + retval = receiverBase->getDynamicRange(); + dynamicrange = retval; if(myDetectorType == EIGER){ if(!tenGigaEnable) packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; From fbfafb98fd0686471ddb64e66309160c5ba3c5e1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 3 Jul 2015 16:10:04 +0200 Subject: [PATCH 102/222] small change --- .../include/UDPStandardImplementation.h | 11 +- .../src/UDPBaseImplementation.cpp | 2 +- .../src/UDPStandardImplementation.cpp | 173 +++++++++++++----- 3 files changed, 140 insertions(+), 46 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index bad7f7a2e3..99c159bcb9 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -463,10 +463,19 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void stopWriting(int ithread, char* wbuffer[]); + /** + * updates parameters and writes to file when not a dummy frame + * Also calls writeToFile_withoutCompression or handleDataCompression + * Called by startWriting() + * @param ithread writing thread number + * @param wbuffer writer buffer + * @param npackets number of packets from the fifo + */ + int handleWithoutDataCompression(int ithread, char* wbuffer[], int &npackets); /** * data compression for each fifo output - * @param ithread listening thread number + * @param ithread writing thread number * @param wbuffer writer buffer * @param npackets number of packets from the fifo * @param data pointer to the next packet start diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index bbb8b331d7..98adfb6e70 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1826,7 +1826,7 @@ int i; void UDPBaseImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i,j; + int i; #ifdef VERYDEBUG cout << ithread << " **********************popped last dummy frame:" << (void*)wbuffer[wIndex] << endl; #endif diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0b22d88884..c93b52f9a9 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1734,19 +1734,19 @@ int UDPStandardImplementation::startListening(){ cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; #endif -/* + //start indices for each start of scan/acquisition - eiger does it before if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); -*/ + //problem in receiving or end of acquisition if((rc < expected)||(rc <= 0)){ - if(myDetectorType != EIGER){ + /*if(myDetectorType != EIGER){ //start indices for each start of scan/acquisition - this should be done earlier for normal detectors if((!measurementStarted) && (rc > 0) && (!ithread)) startFrameIndices(ithread); - } + }*/ stopListening(ithread,rc,packetcount,total); continue; } @@ -1882,13 +1882,12 @@ int UDPStandardImplementation::startWriting(){ thread_started = 1; - int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; int numpackets, nf; uint32_t tempframenum; char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; - int ret,i,j; + int ret,i; int packetsPerThread = packetsPerFrame/numListeningThreads; while(1){ @@ -1927,9 +1926,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); #endif numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; -#endif +//#endif } @@ -1947,7 +1946,7 @@ int UDPStandardImplementation::startWriting(){ - //for progress + //update current frame number for progress if(myDetectorType == EIGER){ if(dynamicRange != 32) @@ -1977,12 +1976,12 @@ int UDPStandardImplementation::startWriting(){ #endif - //without datacompression: write datacall back, or write data, free fifo + /* //without datacompression: write datacall back, or write data, free fifo if(!dataCompression){ if (cbAction < DO_EVERYTHING){ for(i=0;ifnum); - else*/ - startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); } //gotthard has +1 for frame number and not a short frame else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) @@ -2169,19 +2167,19 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ startAcquisitionIndex=startFrameIndex; currframenum = startAcquisitionIndex; acqStarted = true; - cout << "startAcquisitionIndex:" << hex << startAcquisitionIndex<push(buffer[ithread]);/** why not while(!)*/ -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener last buffer free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); -#endif - } //eiger (complete frames) + other detectors - else{ - pc = (rc/onePacketSize); + pc = (rc/onePacketSize); #ifdef VERYDEBUG - cout << ithread << " last rc:"<push(buffer[ithread])); + (*((uint16_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG - cprintf(RED,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); + cprintf(RED,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif - } + } @@ -2269,9 +2256,9 @@ int i; #endif pthread_mutex_unlock(&(status_mutex)); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cout << ithread << ": Frames listened to " << dec << ((totalListeningFrameCount[ithread]*numListeningThreads)/packetsPerFrame) << endl; -#endif +//#endif //waiting for all listening threads to be done, to print final count of frames listened to if(ithread == 0){ @@ -2281,12 +2268,12 @@ int i; #endif while(listeningthreads_mask) usleep(5000); -#ifdef VERYDEBUG +//#ifdef VERYDEBUG t = 0; for(i=0;i 0){ + for(j=0;jnum1)) = currframenum; + //overwriting port number and dynamic range + if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = (dynamicRange<<2); + else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + +#ifdef VERYDEBUG + cprintf(RED, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4))); +#endif + } + + //for 32 bit,port number needs to be changed and packet number reconstructed + if(dynamicRange == 32){ + for (i = 0; i < packetsPerFrame/4; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); + +#ifdef VERYDEBUG + cprintf(RED, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); +#endif + } + for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))+(packetsPerFrame/4)); + +#ifdef VERYDEBUG + cprintf(RED, "%d -0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); +#endif + } + } + } +#endif + + writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); + } +#ifdef VERYDEBUG + cprintf(BLUE,"written everyting\n"); +#endif + } + + + if(myDetectorType == EIGER) { +#ifdef VERYDEBUG + cprintf(BLUE,"gonna copy frame\n"); +#endif + copyFrameToGui(wbuffer,currframenum); +#ifdef VERYDEBUG + cprintf(BLUE,"copied frame\n"); +#endif + for(i=0;ipush(wbuffer[i])); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]),i); +#endif + } + + + } + else{ + //copy to gui + if(npackets >= packetsPerFrame){//min 1 frame, but neednt be + //if(npackets == packetsPerFrame * numJobsPerThread){ //only full frames + copyFrameToGui(NULL,-1,wbuffer[0]+HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYVERBOSE + cout << ithread << " finished copying" << endl; +#endif + }//else cout << "unfinished buffersize" << endl; + while(!fifoFree[0]->push(wbuffer[0])); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); +#endif + } +} From 476d1b452f61a1212c8eaf39d90fd28bd5ab89e1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 10 Jul 2015 16:04:29 +0200 Subject: [PATCH 103/222] some changes --- .../include/UDPBaseImplementation.h | 3 +- .../include/UDPStandardImplementation.h | 11 +- .../include/sls_receiver_defs.h | 2 +- .../src/UDPBaseImplementation.cpp | 5 +- .../src/UDPStandardImplementation.cpp | 577 +++++++++--------- slsReceiverSoftware/src/slsReceiver.cpp | 2 +- .../src/slsReceiverTCPIPInterface.cpp | 269 ++++---- slsReceiverSoftware/src/slsReceiverUsers.cpp | 2 +- 8 files changed, 445 insertions(+), 426 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index cb5c081959..6a8c53bd36 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -471,13 +471,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * data compression for each fifo output * @param ithread listening thread number * @param wbuffer writer buffer - * @param npackets number of packets from the fifo * @param data pointer to the next packet start * @param xmax max pixels in x direction * @param ymax max pixels in y direction * @param nf nf */ - void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); + void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 99c159bcb9..4c04265d44 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -459,9 +459,8 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** * When acquisition is over, this is called * @param ithread listening thread number - * @param wbuffer writer buffer */ - void stopWriting(int ithread, char* wbuffer[]); + void stopWriting(int ithread); /** * updates parameters and writes to file when not a dummy frame @@ -469,21 +468,21 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Called by startWriting() * @param ithread writing thread number * @param wbuffer writer buffer - * @param npackets number of packets from the fifo + * @param partialframe is 1 if both ports of eiger dont have same frame + * @param smaller is which port is the smaller frame number if only partial frame received */ - int handleWithoutDataCompression(int ithread, char* wbuffer[], int &npackets); + void handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe = 0, int smaller = 0); /** * data compression for each fifo output * @param ithread writing thread number * @param wbuffer writer buffer - * @param npackets number of packets from the fifo * @param data pointer to the next packet start * @param xmax max pixels in x direction * @param ymax max pixels in y direction * @param nf nf */ - void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); + void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 025e3b9cf8..7ed6e08378 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -19,7 +19,7 @@ typedef int int32_t; #define MAX_FRAMES_PER_FILE 20000 #define SHORT_MAX_FRAMES_PER_FILE 100000 #define MOENCH_MAX_FRAMES_PER_FILE 1000 -#define EIGER_MAX_FRAMES_PER_FILE 20000 +#define EIGER_MAX_FRAMES_PER_FILE 20 #define JFCTB_MAX_FRAMES_PER_FILE 100000 diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 98adfb6e70..b279147ae2 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1647,7 +1647,7 @@ int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " sta } //data compression else - handleDataCompression(ithread,wbuf,numpackets,d, xmax, ymax, nf); + handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); @@ -1998,7 +1998,7 @@ void UDPBaseImplementation::writeToFile_withoutCompression(char* buf,int numpack -void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ +void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; @@ -2009,6 +2009,7 @@ void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], eventType thisEvent = PEDESTAL; int ndata; char* buff = 0; + int npackets = (uint16_t)(*((uint16_t*)wbuffer[0])); data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; int remainingsize = npackets * onePacketSize; int np; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index c93b52f9a9..cd4963e4b4 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1,6 +1,10 @@ /********************************************//** * @file UDPStandardImplementation.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. + * update: 08 July 2015 + * startwriting assumes that for eiger numberoflisteningthreads is limited to 2. + * Otherwise logic to compare n number of frame numbers and store previous frames + * is more complicated compared to just 2 threads. ***********************************************/ @@ -850,7 +854,7 @@ void UDPStandardImplementation::setupFifoStructure(){ while(!fifoFree[i]->isEmpty()) fifoFree[i]->pop(buffer[i]); #ifdef FIFO_DEBUG - //cprintf(GREEN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); + cprintf(CYAN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); #endif delete fifoFree[i]; } @@ -872,7 +876,7 @@ void UDPStandardImplementation::setupFifoStructure(){ while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { fifoFree[i]->push(buffer[i]); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); + cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); #endif buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); } @@ -893,7 +897,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui if (guiData == NULL){ guiData = latestData; #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gui data not null anymore\n"); + cprintf(MAGENTA,"gui data not null anymore\n"); #endif } @@ -907,14 +911,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //could not get gui data if(!guiDataReady){ #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gui data not ready\n"); + cprintf(MAGENTA,"gui data not ready\n"); #endif *raw = NULL; } //data ready, set guidata to receive new data else{ #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gui data ready\n"); + cprintf(MAGENTA,"gui data ready\n"); #endif *raw = guiData; guiData = NULL; @@ -924,14 +928,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui pthread_mutex_unlock(&dataReadyMutex);*/ if((nFrameToGui) && (writerthreads_mask)){ #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gonna post\n"); + cprintf(MAGENTA,"gonna post\n"); #endif /*if(nFrameToGui){*/ //release after getting data sem_post(&smp); } #ifdef VERY_VERY_DEBUG - cprintf(CYAN,"done post\n"); + cprintf(MAGENTA,"done post\n"); #endif } } @@ -1367,6 +1371,9 @@ int UDPStandardImplementation::createNewFile(){ int gt = getFrameIndex(); if(gt==-1) gt=0; + //just because currframenum will start from 1, while getframeindex will start from 0 + else if(myDetectorType == EIGER) + gt++; //create file name if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); @@ -1401,6 +1408,8 @@ int UDPStandardImplementation::createNewFile(){ if(!packetsCaught) cout << savefilename << endl; else{ + + cout << savefilename << "\tpacket loss " << setw(4)<pop(buffer[ithread]); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); + cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); #endif @@ -1706,14 +1721,17 @@ int UDPStandardImplementation::startListening(){ //normal listening else if(!carryonBufferSize){ - /* if(!ithread){*/ +#ifdef SOCKET_DEBUG + if(!ithread){ +#endif rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); //cout<<"value:"<fnum)< 0) && (!ithread)) startFrameIndices(ithread); -//*/ +*/ //reset packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; carryonBufferSize = 0; - //check if last packet valid and calculate packet count switch(myDetectorType){ @@ -1818,30 +1835,72 @@ int UDPStandardImplementation::startListening(){ & (frameIndexMask)) >> frameIndexOffset) << endl; #endif break; - default: + + case EIGER: + lastpacketoffset = (((numJobsPerThread * packetsPerFrame/numListeningThreads - 1) * onePacketSize) + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef VERYDEBUG + cprintf(BLUE,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); + cprintf(BLUE,"%d 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(BLUE,"%d last packet offset: %d\n",ithread,lastpacketoffset); + cprintf(BLUE,"%d last pnum: 0x%x\n", ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); +/*for 32 bit try to print 64 bit value of packet header to rule out no other byte changes value other than num4 */ +#endif + //if eiger last packet value is NOT as expected according to bit mode + cprintf(BLUE,"%d lastpacket value: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); + cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + + if( ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) != last_packet_value){ +//#ifdef VERYDEBUG + cprintf(RED,"NOT full frame\n"); +//#endif + lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); + carryonBufferSize += onePacketSize; + cprintf(BLUE,"%d lastpacket value: %d packet count: %d\n",ithread,lastpacketheader,packetcount); + lastpacketoffset -= onePacketSize; + --packetcount; + + cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + + //while last packet value is greater than current offset packet value (till we reach ff) + while (lastpacketheader > ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) ){ + lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); + carryonBufferSize += onePacketSize; + cprintf(BLUE,"%d check value: %d lastpacket value: %d packet count: %d\n",ithread,lastpacketheader,packetcount); + lastpacketoffset -= onePacketSize; + --packetcount; + cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + + } + memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); +//#ifdef VERYDEBUG + cprintf(BLUE,"%d tempchar 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempchar)))->num4)))); +//#endif + + } break; - } + default: + break; - // cout<<"*********** "<fnum)<push(buffer[ithread])); #ifdef FIFO_DEBUG //if(!ithread) - cprintf(MAGENTA, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); + cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif } @@ -1877,18 +1936,20 @@ int UDPStandardImplementation::startWriting(){ int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE - cout << ithread << "In startWriting()" <pop(wbuf[i]); + //if previous popped out frame was last dummy frame, dont pop out or you're stuck + //also check if there is a previous frame, then also dont pop out or you miss one frame + if(!previousframe[i]){ +//#ifdef VERYDEBUG + cprintf(GREEN,"%d writer gonna pop from fifo: %d\n",ithread,i); +//#endif + fifo[i]->pop(wbuf[i]); #ifdef FIFO_DEBUG - cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); + cprintf(GREEN,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); #endif - numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); + numpackets[i] = (uint16_t)(*((uint16_t*)wbuf[i])); //#ifdef VERYDEBUG - cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; + cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); //#endif + + + //if last dummy packet, free it + if(numpackets[i] == 0xFFFF){ +//#ifdef VERYDEBUG + cprintf(GREEN, "%d popped last dummy frame:0x%x for listen thread %d\n", ithread, (void*)wbuf[i], i); +//#endif + while(!fifoFree[i]->push(wbuf[i])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuf[i]),i); +#endif + + }else allDummyFramesPopped = 0; + } } - //last dummy packet - if(numpackets == 0xFFFF){ + + //if all last dummy frames popped + if(allDummyFramesPopped){ #ifdef VERYDEBUG - cout << "**LAST dummy packet" << endl; + cprintf(GREEN,"%d all dummy frames popped\n", ithread); #endif - stopWriting(ithread,wbuf); + stopWriting(ithread); continue; } #ifdef VERYDEBUG - else cout <<"**NOT a dummy packet"<< dec << numpackets<< endl; + else cprintf(GREEN,"%d NOT all dummy frames popped\n", ,ithread); #endif @@ -1949,14 +2036,42 @@ int UDPStandardImplementation::startWriting(){ //update current frame number for progress if(myDetectorType == EIGER){ - if(dynamicRange != 32) - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + /* Assuming there are only 2 listening threads of eiger, + * else logic is more complex to find smallest frame number + * and store n number of previous frames for n number of threads */ + + if (numpackets[0] == 0xFFFF) + tempframenum = 0xFFFF; else - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[0] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + if (numpackets[1] == 0xFFFF) + tempframenum2 = 0xFFFF; + else + tempframenum2 = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[1] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + + + //check if one of them is less than the other (both dummies wouldnt reach here) + if(tempframenum!=tempframenum2){ + //frame number of the smaller one + onlyoneport = 1; + smaller = (tempframenum > tempframenum2); + //dummy frame will always be bigger fnum,previousframe = 1 means dont pop out that fifo next time + previousframe[!smaller] = 1; + previousframe[smaller] = 0; + + //update only the smaller number + if (smaller) + tempframenum = tempframenum2; + tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 + } + //no leftover frames left when you write both + else{ + onlyoneport = 0; + previousframe[0] = 0; + previousframe[1] = 0; + } - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - //tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); @@ -1972,122 +2087,18 @@ int UDPStandardImplementation::startWriting(){ pthread_mutex_unlock(&progress_mutex); } #ifdef EIGER_DEBUG2 - cout << endl < 0){ - for(j=0;jnum1)) = currframenum; - //overwriting port number and dynamic range - if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = (dynamicRange<<2); - else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = ((dynamicRange<<2)|(0x1)); - -#ifdef VERYDEBUG - cprintf(RED, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4))); -#endif - - } - - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame/4; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); - -#ifdef VERYDEBUG - cprintf(RED, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); -#endif - } - for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))+(packetsPerFrame/4)); - -#ifdef VERYDEBUG - cprintf(RED, "%d -0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); -#endif - } - } - } -#endif - - writeToFile_withoutCompression(wbuf[j], numpackets,currframenum); - } -#ifdef VERYDEBUG - cprintf(BLUE,"written everyting\n"); -#endif - } - - - if(myDetectorType == EIGER) { -#ifdef VERYDEBUG - cprintf(BLUE,"gonna copy frame\n"); + cprintf(GREEN,"%d tempframenum:%d curframenum:%d\n",ithread, tempframenum, currframenum); #endif - copyFrameToGui(wbuf,currframenum); -#ifdef VERYDEBUG - cprintf(BLUE,"copied frame\n"); -#endif - for(i=0;ipush(wbuf[i])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuf[i]),i); -#endif - } - - } - else{ - //copy to gui - if(numpackets >= packetsPerFrame){//min 1 frame, but neednt be - //if(numpackets == packetsPerFrame * numJobsPerThread){ //only full frames - copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; -#endif - }//else cout << "unfinished buffersize" << endl; - while(!fifoFree[0]->push(wbuf[0])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuf[0])); -#endif - } - } - */ //without datacompression: write datacall back, or write data, free fifo - if(!dataCompression) handleWithoutDataCompression(ithread,wbuf,numpackets); + if(!dataCompression) handleWithoutDataCompression(ithread,wbuf,onlyoneport,smaller); //data compression - else handleDataCompression(ithread,wbuf,numpackets,d, xmax, ymax, nf); - - - + else handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); } #ifdef VERYVERBOSE - cout << ithread << " gonna wait for 1st sem" << endl; + cprintf(GREEN,"%d gonna wait for 1st sem\n", ithread); #endif //wait sem_wait(&writersmp[ithread]); @@ -2097,7 +2108,7 @@ int UDPStandardImplementation::startWriting(){ pthread_exit(NULL); } #ifdef VERYVERBOSE - cout << ithread << " got 1st post" << endl; + cprintf(GREEN,"%d got 1st post\n", ithread); #endif @@ -2124,7 +2135,7 @@ int UDPStandardImplementation::startWriting(){ #ifdef VERYVERBOSE - cout << ithread << " gonna wait for 2nd sem" << endl; + cprintf(GREEN,"%d gonna wait for 2nd sem\n", ithread); #endif //wait sem_wait(&writersmp[ithread]); @@ -2134,7 +2145,7 @@ int UDPStandardImplementation::startWriting(){ pthread_exit(NULL); } #ifdef VERYVERBOSE - cout << ithread << " got 2nd post" << endl; + cprintf(GREEN,"%d got 2nd post\n", ithread); #endif } @@ -2167,7 +2178,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ startAcquisitionIndex=startFrameIndex; currframenum = startAcquisitionIndex; acqStarted = true; - cout << "startAcquisitionIndex:" << dec << startAcquisitionIndex<push(buffer[ithread]); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener not txm free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); @@ -2207,7 +2218,7 @@ int i; //free buffer if(rc <= 0){ - cout << ithread << "Discarding empty frame/ End of acquisition" << endl; + cprintf(BLUE,"%d End of acquisition\n", ithread); fifoFree[ithread]->push(buffer[ithread]);/** why not while(!)*/ #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); @@ -2215,17 +2226,20 @@ int i; } //push the last buffer into fifo else{ + + if (rc < (bufferSize * numJobsPerThread)) + cprintf(RED,"%d Pushing Incomplete frame into fifo\n", ithread); //eiger (complete frames) + other detectors pc = (rc/onePacketSize); -#ifdef VERYDEBUG - cout << ithread << " last rc:"<push(buffer[ithread])); #ifdef FIFO_DEBUG - cprintf(RED,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif } @@ -2236,15 +2250,15 @@ int i; for(i=0;ipop(buffer[ithread]); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); #endif (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; #ifdef VERYDEBUG - cout << ithread << " dummy buffer num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; + cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); #endif while(!fifo[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG - cprintf(RED,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif } @@ -2252,19 +2266,19 @@ int i; pthread_mutex_lock(&status_mutex); listeningthreads_mask^=(1< 1) - cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; + cprintf(BLUE,"%d Waiting for listening to be done.. current mask:0x%x\n", ithread, listeningthreads_mask); #endif while(listeningthreads_mask) usleep(5000); @@ -2272,7 +2286,7 @@ int i; t = 0; for(i=0;ipush(wbuffer[i])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -#endif - } - - - //all threads need to close file, reset mask and exit loop closeFile(ithread); pthread_mutex_lock(&status_mutex); writerthreads_mask^=(1<num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); + cprintf(GREEN, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(GREEN, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(GREEN, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(GREEN, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(GREEN, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(GREEN, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); }else{ k = 0; - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); + cprintf(GREEN, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(GREEN, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(GREEN, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(GREEN, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 256; - cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 512; - cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 768; - cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(GREEN, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(GREEN, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(GREEN, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); } } #endif @@ -2435,9 +2434,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(tempframenum > currframenum) currframenum = tempframenum; } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif +//#ifdef VERYDEBUG + cprintf(GREEN,"tempframenum: %d curframenum: %d\n",tempframenum,currframenum); +//#endif //lock if(numWriterThreads > 1) @@ -2454,7 +2453,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num packetsCaught += packetsToSave; totalPacketsCaught += packetsToSave; #ifdef VERYDEBUG - cout << "/totalPacketsCaught:" << dec << totalPacketsCaught <= maxPacketsPerFile){ @@ -2472,9 +2471,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(tempframenum > currframenum) currframenum = tempframenum; } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif +//#ifdef VERYDEBUG + cprintf(GREEN,"tempframenum: %d curframenum: %d\n", tempframenum ,currframenum); +//#endif //create createNewFile(); } @@ -2503,87 +2502,102 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num -int UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[], int &npackets){ +void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe, int smaller){ int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; - int i,j; + int i,j,npackets; if (cbAction < DO_EVERYTHING){ - for(i=0;i 0){ + else { for(j=0;j 0){ + #ifdef WRITE_HEADERS - if (myDetectorType == EIGER){ + if (myDetectorType == EIGER){ - for (i = 0; i < packetsPerFrame/2; i++){ - //overwriting frame number in header - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num1)) = currframenum; - //overwriting port number and dynamic range - if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = (dynamicRange<<2); - else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + for (i = 0; i < packetsPerFrame/2; i++){ + //overwriting frame number in header + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num1)) = currframenum; + //overwriting port number and dynamic range + if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num3)) = (dynamicRange<<2); + else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); #ifdef VERYDEBUG - cprintf(RED, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4))); + cprintf(GREEN, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4))); #endif - } + } - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame/4; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); + //for 32 bit,port number needs to be changed and packet number reconstructed + if(dynamicRange == 32){ + for (i = 0; i < packetsPerFrame/4; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num4))); #ifdef VERYDEBUG - cprintf(RED, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num2))); #endif - } - for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))+(packetsPerFrame/4)); + } + for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num4))+(packetsPerFrame/4)); #ifdef VERYDEBUG - cprintf(RED, "%d -0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); + cprintf(GREEN, "%d -0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num2))); #endif + } } } - } #endif - writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); + writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); + } } #ifdef VERYDEBUG - cprintf(BLUE,"written everyting\n"); + cprintf(GREEN,"written everyting\n"); #endif } if(myDetectorType == EIGER) { + if(!partialframe){ #ifdef VERYDEBUG - cprintf(BLUE,"gonna copy frame\n"); -#endif - copyFrameToGui(wbuffer,currframenum); -#ifdef VERYDEBUG - cprintf(BLUE,"copied frame\n"); + cprintf(GREEN,"gonna copy frame\n"); #endif + copyFrameToGui(wbuffer,currframenum); +//#ifdef VERYDEBUG + cprintf(GREEN,"copied frame\n"); +//#endif + } for(i=0;ipush(wbuffer[i])); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]),i); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]),i); #endif } @@ -2600,7 +2614,7 @@ int UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* w }//else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuffer[0])); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); #endif } } @@ -2611,7 +2625,7 @@ int UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* w -void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ +void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ FILE_LOG(logDEBUG) << __AT__ << " called"; #if defined(MYROOT1) && defined(ALLFILE_DEBUG) @@ -2621,6 +2635,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer eventType thisEvent = PEDESTAL; int ndata; char* buff = 0; + int npackets = (uint16_t)(*((uint16_t*)wbuffer[0])); data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; int remainingsize = npackets * onePacketSize; int np; @@ -2701,7 +2716,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer while(!fifoFree[0]->push(wbuffer[0])); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); + cprintf(GREEN,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); #endif } diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index e43820613d..5783e601c7 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -162,7 +162,7 @@ void slsReceiver::closeFile(int p) { int64_t slsReceiver::getReceiverVersion(){ - tcpipInterface->getReceiverVersion(); + return tcpipInterface->getReceiverVersion(); } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 2c882b1390..bcefc85d88 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -32,25 +32,25 @@ slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { } slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn, bool bot): - myDetectorType(GOTTHARD), - receiverBase(rbase), - ret(OK), - lockStatus(0), - shortFrame(-1), - packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), - dynamicrange(16), - socket(NULL), - killTCPServerThread(0), - tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2), - bottom(bot){ - - int port_no=portNumber; - if(receiverBase == NULL) receiverBase = 0; - - if (pn>0) - port_no = pn; - - success=OK; + myDetectorType(GOTTHARD), + receiverBase(rbase), + ret(OK), + lockStatus(0), + shortFrame(-1), + packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), + dynamicrange(16), + socket(NULL), + killTCPServerThread(0), + tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2), + bottom(bot){ + + int port_no=portNumber; + if(receiverBase == NULL) receiverBase = 0; + + if (pn>0) + port_no = pn; + + success=OK; //create socket if(success == OK){ @@ -65,58 +65,60 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* strcpy(socket->lastClientIP,"none"); strcpy(socket->thisClientIP,"none1"); strcpy(mess,"dummy message"); - + function_table(); #ifdef VERBOSE cout << "Function table assigned." << endl; #endif - + //Catch signal SIGINT to close files properly signal(SIGINT,staticCloseFile); } } - + } int slsReceiverTCPIPInterface::setPortNumber(int pn){ int p_number; - MySocketTCP *oldsocket=NULL;; - int sd=0; - - if (pn>0) { - p_number = pn; - - if (p_number<1024) { - sprintf(mess,"Too low port number %d\n", p_number); - cout << mess << endl; - } else { - - oldsocket=socket; - socket = new MySocketTCP(p_number); - if(socket){ - sd = socket->getErrorStatus(); - if (!sd){ - portNumber=p_number; - delete oldsocket; - } else { - cout << "Could not bind port " << p_number << endl; - if (sd==-10) { - - cout << "Port "<< p_number << " already set" << endl; - } else { - delete socket; - socket=oldsocket; - } - } - - } else { - socket=oldsocket; - } - } - } - - return portNumber; + + MySocketTCP *oldsocket=NULL;; + int sd=0; + + if (pn>0) { + p_number = pn; + + if (p_number<1024) { + sprintf(mess,"Too low port number %d\n", p_number); + cout << mess << endl; + } else { + + oldsocket=socket; + socket = new MySocketTCP(p_number); + if(socket){ + sd = socket->getErrorStatus(); + if (!sd){ + portNumber=p_number; + strcpy(socket->lastClientIP,oldsocket->lastClientIP); + delete oldsocket; + } else { + cout << "Could not bind port " << p_number << endl; + if (sd==-10) { + + cout << "Port "<< p_number << " already set" << endl; + } else { + delete socket; + socket=oldsocket; + } + } + + } else { + socket=oldsocket; + } + } + } + + return portNumber; } @@ -142,7 +144,7 @@ void slsReceiverTCPIPInterface::stop(){ receiverBase->shutDownUDPSockets(); cout << "Closing Files... " << endl; - receiverBase->closeFile(); + receiverBase->closeFile(); cout<<"Shutting down TCP Socket and TCP thread"<differentClients){ @@ -426,7 +428,7 @@ int slsReceiverTCPIPInterface::set_file_name() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else + else strcpy(retval,receiverBase->setFileName(fName)); } #ifdef VERBOSE @@ -671,44 +673,44 @@ int slsReceiverTCPIPInterface::setup_udp(){ } else{ //set up udp port - sscanf(args[1],"%d",&udpport); - sscanf(args[2],"%d",&udpport2); - receiverBase->setUDPPortNo(udpport); - receiverBase->setUDPPortNo2(udpport2); - //setup udpip - //get ethernet interface or IP to listen to - cout << "Ethernet interface is " << args[0] << endl; - temp = genericSocket::ipToName(args[0]); - cout << temp << endl; - if(temp=="none"){ - ret = FAIL; - strcpy(mess, "failed to get ethernet interface or IP to listen to\n"); - } - else{ - strcpy(eth,temp.c_str()); - if (strchr(eth,'.')!=NULL) { - strcpy(eth,""); - ret = FAIL; - } - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; - receiverBase->setEthernetInterface(eth); - - cout << eth << endl; - //get mac address from ethernet interface - if (ret != FAIL) + sscanf(args[1],"%d",&udpport); + sscanf(args[2],"%d",&udpport2); + receiverBase->setUDPPortNo(udpport); + receiverBase->setUDPPortNo2(udpport2); + //setup udpip + //get ethernet interface or IP to listen to + cout << "Ethernet interface is " << args[0] << endl; + temp = genericSocket::ipToName(args[0]); + cout << temp << endl; + if(temp=="none"){ + ret = FAIL; + strcpy(mess, "failed to get ethernet interface or IP to listen to\n"); + } + else{ + strcpy(eth,temp.c_str()); + if (strchr(eth,'.')!=NULL) { + strcpy(eth,""); + ret = FAIL; + } + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; + receiverBase->setEthernetInterface(eth); + + cout << eth << endl; + //get mac address from ethernet interface + if (ret != FAIL) temp = genericSocket::nameToMac(eth); - - - if ((temp=="00:00:00:00:00:00") || (ret == FAIL)){ - ret = FAIL; - strcpy(mess,"failed to get mac adddress to listen to\n"); - cout << "mess:" << mess << endl; - } - else{ - strcpy(retval,temp.c_str()); - cout<<"mac:"<> GOTTHARD_FRAME_INDEX_OFFSET); #ifdef VERBOSE - cout << "index1:" << hex << index << endl; - cout << "index2:" << hex << index << endl; + cout << "index1:" << hex << index << endl; + cout << "index2:" << hex << index << endl; #endif } @@ -1310,21 +1312,21 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ /*//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 << ":"<initialize(hostname); + else{ + receiverBase->initialize(hostname); strcpy(retval,receiverBase->getDetectorHostname()); - } + } } #ifdef VERBOSE if(ret!=FAIL) @@ -1998,15 +2000,15 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } else if ((dr>0) && (myDetectorType == EIGER)){ switch(dr){ - case 4: - case 8: - case 16: - case 32:break; - default: - sprintf(mess,"This dynamic range does not exist for eiger: %d\n",dr); - cprintf(RED,"%s", mess); - ret=FAIL; - break; + case 4: + case 8: + case 16: + case 32:break; + default: + sprintf(mess,"This dynamic range does not exist for eiger: %d\n",dr); + cprintf(RED,"%s", mess); + ret=FAIL; + break; } } if(ret!=FAIL){ @@ -2247,6 +2249,7 @@ int slsReceiverTCPIPInterface::lock_receiver() { int slsReceiverTCPIPInterface::set_port() { ret=OK; MySocketTCP* mySocket=NULL; + char oldLastClientIP[INET_ADDRSTRLEN]; int sd=-1; enum runStatus p_type; /* just to get the input */ int p_number; @@ -2277,12 +2280,14 @@ int slsReceiverTCPIPInterface::set_port() { ret=FAIL; } cout << "set port " << p_type << " to " << p_number <lastClientIP); mySocket = new MySocketTCP(p_number); } if(mySocket){ sd = mySocket->getErrorStatus(); if (!sd){ ret=OK; + strcpy(socket->lastClientIP,oldLastClientIP); if (mySocket->differentClients) ret=FORCE_UPDATE; } else { diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index 9b1f147dad..c27f1efc2a 100644 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -25,7 +25,7 @@ void slsReceiverUsers::closeFile(int p) { } int64_t slsReceiverUsers::getReceiverVersion(){ - slsReceiverUsers::receiver->getReceiverVersion(); + return slsReceiverUsers::receiver->getReceiverVersion(); } From ca9f195f0bd0de0d45e021e2d6cd3866efd53a3a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 16 Jul 2015 13:33:34 +0200 Subject: [PATCH 104/222] starting of a new change --- .../include/UDPBaseImplementation.h | 5 +- slsReceiverSoftware/include/genericSocket.h | 27 +- .../src/UDPBaseImplementation.cpp | 4 +- .../src/UDPStandardImplementation.cpp | 231 +++++++++++++----- 4 files changed, 184 insertions(+), 83 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 6a8c53bd36..3ece433dd7 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -486,7 +486,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** structure of an eiger image header*/ typedef struct { - unsigned char header_before[20]; + //unsigned char header_before1[5]; + //unsigned char header_confirm[1]; + //unsigned char header_before2[14]; + unsigned char header_before[20]; unsigned char fnum[4]; unsigned char header_after[24]; } eiger_image_header; diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 0ccc80adfc..ed5d386a11 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -94,18 +94,11 @@ enum communicationProtocol{ typedef struct { - unsigned char header_before[20]; + unsigned char header_before[20]; unsigned char fnum[4]; unsigned char header_after[24]; } eiger_image_header; -typedef struct -{ - unsigned char header_before[19]; - unsigned char fnum[4]; - unsigned char header_after[25]; -} eiger_image_header32; - genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : // portno(port_number), protocol(p), @@ -581,24 +574,13 @@ typedef struct case UDP: if (socketDescriptor<0) return -1; -/* - cout <<"******listening inside genericsocket"<0){ nsending = (length>packet_size) ? packet_size:length; - - /* - +/* //created for debugging on 11.05.2015 nsending=5000; nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); @@ -616,14 +598,9 @@ typedef struct k++; */ - nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); if(!nsent) break; - if(nsent == 16) { - //cout << "."; - continue; - } length-=nsent; total_sent+=nsent; } diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index b279147ae2..e1a6301033 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -624,7 +624,7 @@ void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ < mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); /** shud let the client know about this */ if (mem0[i]==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); exit(-1); } buffer[i]=mem0[i]; @@ -1754,7 +1754,7 @@ int i; cerr << ithread << " recvfrom() failed:"<push(buffer[ithread]); exit(-1); } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index cd4963e4b4..5b6ca4bdff 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -839,14 +839,13 @@ void UDPStandardImplementation::setupFifoStructure(){ else fifosize = fifosize/numJobsPerThread; + //one packet per buffer + if(myDetectorType == EIGER) + fifosize *= (packetsPerFrame/(numListeningThreads)); cout << "Number of Frames per buffer:" << numJobsPerThread << endl; cout << "Fifo Size:" << fifosize << endl; - /* - //for testing - numJobsPerThread = 3; fifosize = 11; - */ for(int i=0;i(fifosize); fifo[i] = new CircularFifo(fifosize); //allocate memory - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + //if eiger, allocate only one packet size per buffer + if(myDetectorType == EIGER) + mem0[i]=(char*)malloc((onePacketSize * numJobsPerThread)*fifosize); + else + mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + /** shud let the client know about this */ if (mem0[i]==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); exit(-1); } buffer[i]=mem0[i]; + + //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); + if(myDetectorType == EIGER){ + while (buffer[i]<(mem0[i]+(onePacketSize * numJobsPerThread)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); #ifdef FIFO_DEBUG - cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); + cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); #endif - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + buffer[i]+=(onePacketSize * numJobsPerThread); + } } + else{ + while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); +#ifdef FIFO_DEBUG + cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); +#endif + buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + } + } + } cout << "Fifo structure(s) reconstructed" << endl; } @@ -1674,17 +1693,8 @@ int UDPStandardImplementation::startListening(){ int total; int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader, lastpacketheader;// for moench to check for all the packets in last frame + uint32_t lastframeheader = 0, lastpacketheader = -1, tempframenum = 0;// for moench to check for all the packets in last frame char* tempchar = NULL; - int last_packet_value = 0xff; - if(myDetectorType == EIGER){ - switch(dynamicRange){ - case 4: last_packet_value = 0x40; break; - case 8: last_packet_value = 0x80; break; - case 16: last_packet_value = 0xff; break; - default: last_packet_value = 0xff; break; // 32 bit mode currently gives pnum only upto 0xff and then resets - } - } while(1){ @@ -1692,10 +1702,12 @@ int UDPStandardImplementation::startListening(){ carryonBufferSize = 0; //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later maxBufferSize = bufferSize * numJobsPerThread; + #ifdef VERYDEBUG - cprintf(BLUE, "%d maxBufferSize:%d carryonBufferSize:%d\n", ithread, maxBufferSize,carryonBufferSize); + cprintf(BLUE, "%d listenTo:%d maxBufferSize:%d carryonBufferSize:%d\n", ithread,listenTo,maxBufferSize,carryonBufferSize); #endif + //temporary buffer to copy initial packets for next frames if(tempchar) {delete [] tempchar;tempchar = NULL;} if(myDetectorType != EIGER) tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size @@ -1724,9 +1736,32 @@ int UDPStandardImplementation::startListening(){ #ifdef SOCKET_DEBUG if(!ithread){ #endif - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - //cout<<"value:"<fnum)<ReceiveDataOnly(buffer[ithread]); + //headers or crazy byte size + while (rc != onePacketSize){ + //end of acquisition + if((rc == 0) && (status == TRANSMITTING)){ + stopListening(ithread,rc,packetcount,total); + continue; + } + //16 byte or crazy packet size + if(rc != EIGER_HEADER_LENGTH) + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); + //header + else{ + tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread])))->fnum); + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); + } + } + } + //other detectors + else{ + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + //cout<<"value:"<fnum)< 0) && (!ithread)) + + if( (!measurementStarted) && (myDetectorType != EIGER) && (rc > 0) && (!ithread)) startFrameIndices(ithread); //problem in receiving or end of acquisition - if((rc < expected)||(rc <= 0)){ + //if(((rc < expected) && (status == TRANSMITTING)) || (rc<0)){ + if((status == TRANSMITTING)&& (myDetectorType != EIGER)) { /*if(myDetectorType != EIGER){ //start indices for each start of scan/acquisition - this should be done earlier for normal detectors if((!measurementStarted) && (rc > 0) && (!ithread)) @@ -1776,8 +1813,10 @@ int UDPStandardImplementation::startListening(){ */ //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; + if (myDetectorType != EIGER){ + packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; + carryonBufferSize = 0; + } //check if last packet valid and calculate packet count @@ -1838,46 +1877,126 @@ int UDPStandardImplementation::startListening(){ case EIGER: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame/numListeningThreads - 1) * onePacketSize) + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS); + + + //push missing packet if any by looking at last packetheader values + + + //packetnumber is smaller = different frame + if(lastpacketheader >= ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4)))) + tempframenum++; + + + + + //tag framenumber to the packet + (*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num1)) = tempframenum; + //remember last packet value + lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4))); + + + + + + + + + + //literally end of buffer + lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS; + + //extra header + //or less than 1 frame caught(end of acquisition) + if(rc < expected){ + cprintf(RED,"%d rc:%d expectted:%d\n", ithread, rc, expected); + //extra header, looking at last byte of buffer + if ((*((uint8_t*)((char*)buffer[ithread]+lastpacketoffset-1))) == 0x1){ + cprintf(RED,"%d extra header\n", ithread); + //copy extra header + lastpacketoffset-= EIGER_HEADER_LENGTH; + carryonBufferSize += EIGER_HEADER_LENGTH; + memcpy(tempchar, buffer[ithread]+(lastpacketoffset-EIGER_HEADER_LENGTH), EIGER_HEADER_LENGTH); + cprintf(RED,"%d lastpacketoffset:%d\n",ithread, lastpacketoffset); + } + + //less than 1 frame caught + else cprintf(RED,"%d less than 1 frame \n", ithread); + + //find number of packets from last packet number + lastpacketoffset -= onePacketSize; + cprintf(RED,"%d lastpacketoffset:%d\n",ithread, lastpacketoffset); + + for (k=0;k*1040num4)))); + } + + packetcount = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))+1; + cprintf(RED,"%d num packets caught:%d\n",ithread, packetcount); + + + + cout <<"EXITING"<< endl; + exit(-1); + + } + //more than 1 frame caught but missed the frame header packet + //or exactly 1 frame caught + else { + //points to last packet + lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS - onePacketSize; + lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); #ifdef VERYDEBUG - cprintf(BLUE,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); - cprintf(BLUE,"%d 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - cprintf(BLUE,"%d last packet offset: %d\n",ithread,lastpacketoffset); - cprintf(BLUE,"%d last pnum: 0x%x\n", ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); -/*for 32 bit try to print 64 bit value of packet header to rule out no other byte changes value other than num4 */ + cprintf(BLUE,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); + cprintf(BLUE,"%d 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(BLUE,"%d last packet offset: %d\n",ithread,lastpacketoffset); + cprintf(BLUE,"%d last pnum: 0x%x\n", ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); + //for 32 bit try to print 64 bit value of packet header to rule out no other byte changes value other than num4 #endif - //if eiger last packet value is NOT as expected according to bit mode - cprintf(BLUE,"%d lastpacket value: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); - cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); - if( ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) != last_packet_value){ -//#ifdef VERYDEBUG - cprintf(RED,"NOT full frame\n"); -//#endif - lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); + //proper 1 frame + if((rc == expected) && (lastpacketheader == last_packet_value)){ + break; + } + + //incomplete frame, more than 1 frame caught, but missed header packet + cprintf(RED,"%d INCOMPLETE frame, rc:%d, expected:%d\n", ithread, rc, expected); + cprintf(RED,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); + + //if eiger last packet value is NOT as expected according to bit mode carryonBufferSize += onePacketSize; - cprintf(BLUE,"%d lastpacket value: %d packet count: %d\n",ithread,lastpacketheader,packetcount); lastpacketoffset -= onePacketSize; --packetcount; - cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))), packetcount); //while last packet value is greater than current offset packet value (till we reach ff) while (lastpacketheader > ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) ){ + lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); carryonBufferSize += onePacketSize; - cprintf(BLUE,"%d check value: %d lastpacket value: %d packet count: %d\n",ithread,lastpacketheader,packetcount); lastpacketoffset -= onePacketSize; --packetcount; - cprintf(BLUE,"%d lastpacket value -1: %d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset - onePacketSize)))->num4)))); + + cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))), packetcount); } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -//#ifdef VERYDEBUG - cprintf(BLUE,"%d tempchar 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempchar)))->num4)))); -//#endif + + cprintf(RED,"%d to copy: %d\n", ithread, carryonBufferSize); + cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset+onePacketSize)))->num4))), packetcount); + + memcpy(tempchar , buffer[ithread]+(HEADER_SIZE_NUM_TOT_PACKETS), EIGER_HEADER_LENGTH); + memcpy((char*)(tempchar + EIGER_HEADER_LENGTH), buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); + (*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) = htonl(lastframeheader+1); + cprintf(RED,"%d copied\n", ithread); + //#ifdef VERYDEBUG + cprintf(RED,"%d tempchar 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempchar+EIGER_HEADER_LENGTH)))->num4)))); + //#endif + } + //when we lose frame header packet + lastframeheader = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + cprintf(RED,"%d lastframeheader : %d\n", ithread, lastframeheader); break; @@ -2208,7 +2327,7 @@ int i; cprintf(BLUE, "%d recvfrom() failed\n", ithread); #endif if(status != TRANSMITTING){ - cprintf(BLUE,"%d *** should never be here********* status not transmitting***********************\n", ithread);/**/ + cprintf(BG_RED,"%d *** should never be here********* status not transmitting***********************\n", ithread);/**/ fifoFree[ithread]->push(buffer[ithread]); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener not txm free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); @@ -2257,9 +2376,9 @@ int i; cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); #endif while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG +//#ifdef FIFO_DEBUG cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); -#endif +//#endif } //reset mask and exit loop @@ -2504,7 +2623,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe, int smaller){ int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; - int i,j,npackets; + int i,j,npackets, ntotpackets=0; if (cbAction < DO_EVERYTHING){ @@ -2513,6 +2632,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if(partialframe && (i!=smaller) ) continue; //for eiger 32 bit mode, currframenum like gotthard, does not start from 0 or 1 npackets = (uint16_t)(*((uint16_t*)wbuffer[i])); + ntotpackets += npackets; rawDataReadyCallBack(currframenum, wbuffer[i], npackets * onePacketSize, sfilefd, guiData,pRawDataReady); } } @@ -2523,6 +2643,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if(partialframe && (j!=smaller) ) continue; npackets = (uint16_t)(*((uint16_t*)wbuffer[j])); + ntotpackets += npackets; if (npackets > 0){ #ifdef WRITE_HEADERS @@ -2583,7 +2704,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if(myDetectorType == EIGER) { - if(!partialframe){ + if(ntotpackets >= packetsPerFrame ) { #ifdef VERYDEBUG cprintf(GREEN,"gonna copy frame\n"); #endif From 26a42d8f67d5714b74689a1c0d3e06c8d64e2691 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 17 Jul 2015 13:29:23 +0200 Subject: [PATCH 105/222] new way --- .../include/UDPBaseImplementation.h | 3 + .../src/UDPStandardImplementation.cpp | 130 +++++++++++++----- 2 files changed, 95 insertions(+), 38 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 3ece433dd7..9daf2ab797 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -659,6 +659,9 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** Receiver buffer */ char *buffer[MAX_NUM_LISTENING_THREADS]; + /** Missing Packet */ + char *missingPacket; + /** number of writer threads */ int numListeningThreads; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 5b6ca4bdff..004ba1fb13 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -54,6 +54,7 @@ UDPStandardImplementation::UDPStandardImplementation() udpSocket[i] = NULL; server_port[i] = DEFAULT_UDP_PORTNO+i; mem0[i] = NULL; + missingPacket[i] = NULL; fifo[i] = NULL; fifoFree[i] = NULL; } @@ -163,6 +164,7 @@ void UDPStandardImplementation::initializeMembers(){ for(int i=0;inum4))); + numberofmissingpackets = 0; - //push missing packet if any by looking at last packetheader values - - - //packetnumber is smaller = different frame - if(lastpacketheader >= ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4)))) + //update tempframenumber if header packet missed out, ie. if packetnumber is smaller = different frame + if(lastpacketheader >= currentpacketheader){ tempframenum++; + //add missing packets for previous frame + numberofmissingpackets += (LAST_PACKET_VALUE - lastpacketheader); + //add for missing frames + numberofmissingpackets += ((tempframenum-lastframeheader -1) * (packetsPerFrame/numListeningThreads)); + //add missing packets for current frame + numberofmissingpackets += (currentpacketheader); + } - //tag framenumber to the packet - (*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num1)) = tempframenum; //remember last packet value lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4))); + lastframeheader = tempframenum; + //temporarily store current buffer if there are missing packets + if(numberofmissingpackets) + tempchar = buffer[ithread]; + for(i=0;inum1)) = tempframenum; +#ifdef VERYDEBUG + cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); +#endif + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFO_DEBUG + //if(!ithread) + cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); +#endif +#ifdef VERYDEBUG + cprintf(BLUE, "%d waiting to pop out of listeningfifo\n",ithread); +#endif + //pop + fifoFree[ithread]->pop(buffer[ithread]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); +#endif + } + buffer[ithread] = tempchar; + //tag framenumber to the packet + (*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num1)) = tempframenum; + packetcount = 1; - +/* //literally end of buffer lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS; @@ -1997,6 +2068,8 @@ int UDPStandardImplementation::startListening(){ //when we lose frame header packet lastframeheader = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); cprintf(RED,"%d lastframeheader : %d\n", ithread, lastframeheader); + + */ break; @@ -2007,11 +2080,14 @@ int UDPStandardImplementation::startListening(){ + + //#ifdef VERYDEBUG cprintf(BLUE, "%d packetcount:%d carryonbuffer:%d\n", ithread, packetcount, carryonBufferSize); //#endif //write packet count and push - (*((uint16_t*)(buffer[ithread]))) = packetcount; + if(myDetectorType != EIGER) + (*((uint16_t*)(buffer[ithread]))) = packetcount; totalListeningFrameCount[ithread] += packetcount; #ifdef VERYDEBUG cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); @@ -2067,8 +2143,7 @@ int UDPStandardImplementation::startWriting(){ int xmax=0,ymax=0; int ret,i; int packetsPerThread = packetsPerFrame/numListeningThreads; - int allDummyFramesPopped; - int smaller, onlyoneport=0; + while(1){ @@ -2099,16 +2174,10 @@ int UDPStandardImplementation::startWriting(){ while((1<push(wbuf[i])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuf[i]),i); -#endif - - }else allDummyFramesPopped = 0; - } } - //if all last dummy frames popped - if(allDummyFramesPopped){ + if(numpackets[i] == 0xFFFF){ #ifdef VERYDEBUG cprintf(GREEN,"%d all dummy frames popped\n", ithread); #endif From 878c12d43ed874a217f448a64fc342f05d6bab27 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 21 Jul 2015 13:36:14 +0200 Subject: [PATCH 106/222] still long way to go --- .../include/UDPBaseImplementation.h | 11 +- .../include/UDPStandardImplementation.h | 4 +- slsReceiverSoftware/include/receiver_defs.h | 2 +- .../src/UDPStandardImplementation.cpp | 994 +++++++++--------- 4 files changed, 496 insertions(+), 515 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 9daf2ab797..8db022a697 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -486,10 +486,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** structure of an eiger image header*/ typedef struct { - //unsigned char header_before1[5]; - //unsigned char header_confirm[1]; - //unsigned char header_before2[14]; - unsigned char header_before[20]; + unsigned char header_before1[5]; + unsigned char header_confirm[1]; + unsigned char header_before2[14]; + //unsigned char header_before[20]; unsigned char fnum[4]; unsigned char header_after[24]; } eiger_image_header; @@ -659,9 +659,6 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** Receiver buffer */ char *buffer[MAX_NUM_LISTENING_THREADS]; - /** Missing Packet */ - char *missingPacket; - /** number of writer threads */ int numListeningThreads; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 4c04265d44..42650e9bbd 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -468,10 +468,8 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Called by startWriting() * @param ithread writing thread number * @param wbuffer writer buffer - * @param partialframe is 1 if both ports of eiger dont have same frame - * @param smaller is which port is the smaller frame number if only partial frame received */ - void handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe = 0, int smaller = 0); + void handleWithoutDataCompression(int ithread, char* wbuffer[]); /** * data compression for each fifo output diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 6f3b1acd35..6a28654b31 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -14,7 +14,7 @@ #define BUF_SIZE (16*1024*1024) //16mb #define SAMPLE_TIME_IN_NS 100000000//100ms #define MAX_JOBS_PER_THREAD 1000 -#define HEADER_SIZE_NUM_TOT_PACKETS 2 +#define HEADER_SIZE_NUM_TOT_PACKETS 4 #define HEADER_SIZE_NUM_FRAMES 2 #define HEADER_SIZE_NUM_PACKETS 1 diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 004ba1fb13..84d1adcbcb 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1,10 +1,6 @@ /********************************************//** * @file UDPStandardImplementation.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. - * update: 08 July 2015 - * startwriting assumes that for eiger numberoflisteningthreads is limited to 2. - * Otherwise logic to compare n number of frame numbers and store previous frames - * is more complicated compared to just 2 threads. ***********************************************/ @@ -54,7 +50,6 @@ UDPStandardImplementation::UDPStandardImplementation() udpSocket[i] = NULL; server_port[i] = DEFAULT_UDP_PORTNO+i; mem0[i] = NULL; - missingPacket[i] = NULL; fifo[i] = NULL; fifoFree[i] = NULL; } @@ -164,7 +159,6 @@ void UDPStandardImplementation::initializeMembers(){ for(int i=0;iisEmpty()) fifoFree[i]->pop(buffer[i]); #ifdef FIFO_DEBUG - cprintf(CYAN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); + //cprintf(GREEN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); #endif delete fifoFree[i]; } if(fifo[i]) delete fifo[i]; if(mem0[i]) free(mem0[i]); - fifoFree[i] = new CircularFifo(fifosize); fifo[i] = new CircularFifo(fifosize); //allocate memory - //if eiger, allocate only one packet size per buffer - if(myDetectorType == EIGER) - mem0[i]=(char*)malloc((onePacketSize * numJobsPerThread)*fifosize); - else - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - + mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); /** shud let the client know about this */ if (mem0[i]==NULL){ - cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); + cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; exit(-1); } buffer[i]=mem0[i]; - - //push the addresses into freed fifoFree and writingFifoFree - if(myDetectorType == EIGER){ - while (buffer[i]<(mem0[i]+(onePacketSize * numJobsPerThread)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); + while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + fifoFree[i]->push(buffer[i]); #ifdef FIFO_DEBUG - cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); + cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); #endif - buffer[i]+=(onePacketSize * numJobsPerThread); - } + buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); } - else{ - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); -#ifdef FIFO_DEBUG - cprintf(CYAN,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); -#endif - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); - } - } - } cout << "Fifo structure(s) reconstructed" << endl; - - - //missing packet - if(myDetectorType == EIGER){ - - if (missingPacket) - free(missingPacket); - - missingPacket=(char*)malloc(onePacketSize); - if (missingPacket==NULL){ - cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR missing packet !!!!!!!+++++++++++++++++++++\n"); - exit(-1); - } - //fill missing packet - else{ - - for(int j = 0; j < onePacketSize/4; j++) - (*((uint32_t*)(missingPacket + j))) = 0xffffffff; - - //to check - for(int j = 0; j < onePacketSize/4; j++) - cout << i << ":"<< (*((uint32_t*)(missingPacket + j))) << endl; - } - } } @@ -945,7 +893,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui if (guiData == NULL){ guiData = latestData; #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"gui data not null anymore\n"); + cprintf(CYAN,"gui data not null anymore\n"); #endif } @@ -959,14 +907,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui //could not get gui data if(!guiDataReady){ #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"gui data not ready\n"); + cprintf(CYAN,"gui data not ready\n"); #endif *raw = NULL; } //data ready, set guidata to receive new data else{ #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"gui data ready\n"); + cprintf(CYAN,"gui data ready\n"); #endif *raw = guiData; guiData = NULL; @@ -976,14 +924,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui pthread_mutex_unlock(&dataReadyMutex);*/ if((nFrameToGui) && (writerthreads_mask)){ #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"gonna post\n"); + cprintf(CYAN,"gonna post\n"); #endif /*if(nFrameToGui){*/ //release after getting data sem_post(&smp); } #ifdef VERY_VERY_DEBUG - cprintf(MAGENTA,"done post\n"); + cprintf(CYAN,"done post\n"); #endif } } @@ -1419,9 +1367,6 @@ int UDPStandardImplementation::createNewFile(){ int gt = getFrameIndex(); if(gt==-1) gt=0; - //just because currframenum will start from 1, while getframeindex will start from 0 - else if(myDetectorType == EIGER) - gt++; //create file name if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); @@ -1456,8 +1401,6 @@ int UDPStandardImplementation::createNewFile(){ if(!packetsCaught) cout << savefilename << endl; else{ - - cout << savefilename << "\tpacket loss " << setw(4)<pop(buffer[ithread]); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); #endif - //receive + + //ensure udpsocket exists if(udpSocket[ithread] == NULL){ rc = 0; - cout << ithread << "UDP Socket is NULL" << endl; + cprintf(BLUE, "%d UDP Socket is NULL\n",ithread); } + + //normal listening else if(!carryonBufferSize){ - #ifdef SOCKET_DEBUG - if(!ithread){ -#endif - if(myDetectorType == EIGER){ - //listen to only 1 packet at a time - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); - //headers or crazy byte size - while (rc != onePacketSize){ - //end of acquisition - if((rc == 0) && (status == TRANSMITTING)){ - stopListening(ithread,rc,packetcount,total); - continue; - } - //16 byte or crazy packet size - if(rc != EIGER_HEADER_LENGTH) - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); - //header - else{ - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread])))->fnum); - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread]); - } - } - } - //other detectors - else{ + if(!ithread){ +#endif rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - //cout<<"value:"<fnum)<> frameIndexOffset)<> frameIndexOffset)); + cprintf(BLUE, "%d tempchar packet:%d\n", ((((uint32_t)(*((uint32_t*)(tempchar))))) + & (packetIndexMask))); #endif - //if there is a packet from previous buffer, copy it and listen to n less frame memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, tempchar, carryonBufferSize); rc = udpSocket[ithread]->ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); expected = maxBufferSize - carryonBufferSize; } + #ifdef EIGER_DEBUG cprintf(BLUE, "%d rc: %d. expected: %d\n", ithread, rc, expected); #endif - //start indices for each start of scan/acquisition - eiger does it before - - if( (!measurementStarted) && (myDetectorType != EIGER) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); + //start indices for each start of scan/acquisition + if((!measurementStarted) && (rc > 0)){ + pthread_mutex_lock(&progress_mutex); + startFrameIndices(ithread); + pthread_mutex_unlock(&progress_mutex); + } //problem in receiving or end of acquisition - //if(((rc < expected) && (status == TRANSMITTING)) || (rc<0)){ - if((status == TRANSMITTING)&& (myDetectorType != EIGER)) { - /*if(myDetectorType != EIGER){ - //start indices for each start of scan/acquisition - this should be done earlier for normal detectors - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); - }*/ + if (status == TRANSMITTING){ stopListening(ithread,rc,packetcount,total); continue; } -/* other detectors do after - //eiger - start indices for each start of scan/acquisition - this should be done after to ignore first incomplete frames - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); -*/ //reset - if (myDetectorType != EIGER){ - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - } + packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; + carryonBufferSize = 0; + //check if last packet valid and calculate packet count switch(myDetectorType){ - case MOENCH: lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYDEBUG @@ -1887,216 +1794,62 @@ int UDPStandardImplementation::startListening(){ cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) & (packetIndexMask)) << endl; #endif - } + } break; case GOTTHARD: if(shortFrame == -1){ lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYDEBUG - cout << "last packet offset:" << lastpacketoffset << endl; + cprintf(BLUE, "%d last packet offset:%d\n",ithread, lastpacketoffset); #endif - + //if not last packet if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); #ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; + cprintf(BLUE, "%d tempchar header:%d\n",ithread,(((((uint32_t)(*((uint32_t*)(tempchar))))+1) + & (frameIndexMask)) >> frameIndexOffset)); #endif carryonBufferSize = onePacketSize; --packetcount; } } #ifdef VERYDEBUG - cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; + cprintf(BLUE, "%d header:%d\n", (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset)); #endif break; - case EIGER: - - currentpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4))); - numberofmissingpackets = 0; - - //update tempframenumber if header packet missed out, ie. if packetnumber is smaller = different frame - if(lastpacketheader >= currentpacketheader){ - tempframenum++; - - //add missing packets for previous frame - numberofmissingpackets += (LAST_PACKET_VALUE - lastpacketheader); - - //add for missing frames - numberofmissingpackets += ((tempframenum-lastframeheader -1) * (packetsPerFrame/numListeningThreads)); - - //add missing packets for current frame - numberofmissingpackets += (currentpacketheader); - } - //remember last packet value - lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num4))); - lastframeheader = tempframenum; - - //temporarily store current buffer if there are missing packets - if(numberofmissingpackets) - tempchar = buffer[ithread]; - - for(i=0;inum1)) = tempframenum; -#ifdef VERYDEBUG - cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - //if(!ithread) - cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); -#endif -#ifdef VERYDEBUG - cprintf(BLUE, "%d waiting to pop out of listeningfifo\n",ithread); -#endif - //pop - fifoFree[ithread]->pop(buffer[ithread]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); -#endif - } - - buffer[ithread] = tempchar; - //tag framenumber to the packet - (*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread])))->num1)) = tempframenum; - packetcount = 1; - - - - -/* - - //literally end of buffer - lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS; - - //extra header - //or less than 1 frame caught(end of acquisition) - if(rc < expected){ - cprintf(RED,"%d rc:%d expectted:%d\n", ithread, rc, expected); - //extra header, looking at last byte of buffer - if ((*((uint8_t*)((char*)buffer[ithread]+lastpacketoffset-1))) == 0x1){ - cprintf(RED,"%d extra header\n", ithread); - //copy extra header - lastpacketoffset-= EIGER_HEADER_LENGTH; - carryonBufferSize += EIGER_HEADER_LENGTH; - memcpy(tempchar, buffer[ithread]+(lastpacketoffset-EIGER_HEADER_LENGTH), EIGER_HEADER_LENGTH); - cprintf(RED,"%d lastpacketoffset:%d\n",ithread, lastpacketoffset); - } - - //less than 1 frame caught - else cprintf(RED,"%d less than 1 frame \n", ithread); - - //find number of packets from last packet number - lastpacketoffset -= onePacketSize; - cprintf(RED,"%d lastpacketoffset:%d\n",ithread, lastpacketoffset); - - for (k=0;k*1040num4)))); - } - - packetcount = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))+1; - cprintf(RED,"%d num packets caught:%d\n",ithread, packetcount); - - - - cout <<"EXITING"<< endl; - exit(-1); - - } - //more than 1 frame caught but missed the frame header packet - //or exactly 1 frame caught - else { - //points to last packet - lastpacketoffset = rc + HEADER_SIZE_NUM_TOT_PACKETS - onePacketSize; - lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); -#ifdef VERYDEBUG - cprintf(BLUE,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); - cprintf(BLUE,"%d 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + EIGER_HEADER_LENGTH + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - cprintf(BLUE,"%d last packet offset: %d\n",ithread,lastpacketoffset); - cprintf(BLUE,"%d last pnum: 0x%x\n", ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4)))); - //for 32 bit try to print 64 bit value of packet header to rule out no other byte changes value other than num4 -#endif - - //proper 1 frame - if((rc == expected) && (lastpacketheader == last_packet_value)){ - break; - } - - //incomplete frame, more than 1 frame caught, but missed header packet - cprintf(RED,"%d INCOMPLETE frame, rc:%d, expected:%d\n", ithread, rc, expected); - cprintf(RED,"%d fnum: 0x%x\n", ithread, htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); - - //if eiger last packet value is NOT as expected according to bit mode - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - - cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))), packetcount); - - //while last packet value is greater than current offset packet value (till we reach ff) - while (lastpacketheader > ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))) ){ - - lastpacketheader = ((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))); - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - - cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset)))->num4))), packetcount); - - } - - cprintf(RED,"%d to copy: %d\n", ithread, carryonBufferSize); - cprintf(RED,"%d lastpacketheader:%d last packet value:%d packetcount: %d\n",ithread,lastpacketheader,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + lastpacketoffset+onePacketSize)))->num4))), packetcount); - - memcpy(tempchar , buffer[ithread]+(HEADER_SIZE_NUM_TOT_PACKETS), EIGER_HEADER_LENGTH); - memcpy((char*)(tempchar + EIGER_HEADER_LENGTH), buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); - (*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum) = htonl(lastframeheader+1); - cprintf(RED,"%d copied\n", ithread); - //#ifdef VERYDEBUG - cprintf(RED,"%d tempchar 1st pnum: 0x%x\n", ithread, ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempchar+EIGER_HEADER_LENGTH)))->num4)))); - //#endif - - - } - //when we lose frame header packet - lastframeheader = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - cprintf(RED,"%d lastframeheader : %d\n", ithread, lastframeheader); - - */ + case EIGER: + //because even headers might be included, so not packet count + (*((uint32_t*)(buffer[ithread]))) = rc; break; - default: break; - } - - -//#ifdef VERYDEBUG - cprintf(BLUE, "%d packetcount:%d carryonbuffer:%d\n", ithread, packetcount, carryonBufferSize); -//#endif //write packet count and push +#ifdef VERYDEBUG + cprintf(BLUE, "%d packetcount:%d carryonbuffer:%d\n", ithread, packetcount, carryonBufferSize); +#endif if(myDetectorType != EIGER) - (*((uint16_t*)(buffer[ithread]))) = packetcount; + (*((uint32_t*)(buffer[ithread]))) = packetcount; totalListeningFrameCount[ithread] += packetcount; #ifdef VERYDEBUG cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); #endif while(!fifo[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG - //if(!ithread) cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif + + + } sem_wait(&listensmp[ithread]); @@ -2136,20 +1889,29 @@ int UDPStandardImplementation::startWriting(){ thread_started = 1; - int numpackets[numListeningThreads],previousframe[numListeningThreads] ,nf; - uint32_t tempframenum, tempframenum2; + int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; + int numpackets[numListeningThreads], popready[numListeningThreads], woffset[numListeningThreads], nf; + bool endofacquisition, startheader[numListeningThreads]; + uint32_t tempframenum[numListeningThreads]; + + uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; + int numberofmissingpackets[numListeningThreads]; + char* tempbuffer[numListeningThreads] = NULL; + int tempoffset[numListeningThreads]; + int LAST_PACKET_VALUE; + bool fullframe; + + char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; - int ret,i; - int packetsPerThread = packetsPerFrame/numListeningThreads; + int ret,i,j; while(1){ nf = 0; - packetsPerThread = packetsPerFrame/numListeningThreads; if(myDetectorType == MOENCH){ xmax = MOENCH_PIXELS_IN_ONE_ROW-1; ymax = MOENCH_PIXELS_IN_ONE_ROW-1; @@ -2162,113 +1924,323 @@ int UDPStandardImplementation::startWriting(){ ymax = GOTTHARD_SHORT_PIXELS_IN_COL-1; } } - //checking for previous numpackets of that thread should be correct - for(i=0;ipop(wbuf[i]); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); + cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); #endif - numpackets[i] = (uint16_t)(*((uint16_t*)wbuf[i])); -//#ifdef VERYDEBUG - cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); -//#endif + numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); +#ifdef VERYDEBUG + cout << i << " numpackets:" << dec << numpackets[i] << "for fifo :"<< i << endl; +#endif + //dont pop until ready + popready[i] = 0; + //reset offset + woffset[i] = 0; + } } - //if all last dummy frames popped - if(numpackets[i] == 0xFFFF){ + + //check for end of acquisition + endofacquisition = true; + for(i=0;ifnum); + for(i=0;ifnum); - - - //check if one of them is less than the other (both dummies wouldnt reach here) - if(tempframenum!=tempframenum2){ - //frame number of the smaller one - onlyoneport = 1; - smaller = (tempframenum > tempframenum2); - //dummy frame will always be bigger fnum,previousframe = 1 means dont pop out that fifo next time - previousframe[!smaller] = 1; - previousframe[smaller] = 0; - - //update only the smaller number - if (smaller) - tempframenum = tempframenum2; - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 + //makes sure it doesnt add the finished thread packet all over again + if(tempframenum == currframenum) + while(woffset[i] <= numpackets[i]){ + + + //offset outside boundaries to even check for header + if((woffset[i] + EIGER_HEADER_LENGTH)>= numpackets[i]){ + popready[i] = 1; + fullframe = false; + break; + } + + //check if header + if( 0x01 == (*(uint16_t*)(((eiger_image_header *)((char*)(wbuf[i] + woffset[i])))->header_confirm))){ + //expected frame header -eiger frame numbers start at 1, so need to -1 + if(tempframenum[i] == (htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + woffset[i])))->fnum)+(startFrameIndex-1))){ + woffset[i] += EIGER_HEADER_LENGTH; + startheader[i] = true; + numberofmissingpackets[i] = 0; + lastpacketheader[i] = -1; + tempoffset[i] = 0; + } + //wrong header - leave + else{ + numberofmissingpackets[i] += (LAST_PACKET_VALUE - lastpacketheader[i]); + tempframenum[i]++; + //add missing packets + for(j=0;jnum4))); + //last packet - leave + if(currentpacketheader[i] == LAST_PACKET_VALUE){ + //fill buffer + tempbuffer[i][tempoffset[i]] = wbuf[i] + woffset[i]; + woffset[i] += onePacketSize; + //reset + startheader[i] = false; + lastpacketheader[i] = -1; + tempoffset[i] = 0; + break; + } + //same frame packet + if(currentpacketheader[i] > lastpacketheader[i]){ + + if(!startheader[i]){ + tempframenum[i]++; + } + else + startheader[i] = false; + lastpacketheader[i] = -1; + numberofmissingpackets[i] = 0; + numberofmissingpackets[i] += (currentpacketheader[i] - lastpacketheader[i] -1); + //add missing packets + for(j=0;jnum1)) = currframenum; + //overwriting port number and dynamic range + if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num3)) = (dynamicRange<<2); + else (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + + #ifdef VERYDEBUG + cprintf(GREEN, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4))); + #endif + + } + + //for 32 bit,port number needs to be changed and packet number reconstructed + if(dynamicRange == 32){ + for (i = 0; i < packetsPerFrame/4; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num4))); + + #ifdef VERYDEBUG + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num2))); + #endif + } + for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ + //new packet number that has space for 16 bit + (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num4))+(packetsPerFrame/4)); + + #ifdef VERYDEBUG + cprintf(GREEN, "%d -0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num2))); + #endif + } + } + + +#endif + + + + //writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); + + + + + } } - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); +#ifdef VERYDEBUG + cprintf(GREEN,"gonna copy frame\n"); +#endif + copyFrameToGui(wbuffer,currframenum); +//#ifdef VERYDEBUG + cprintf(GREEN,"copied frame\n"); +//#endif - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - pthread_mutex_lock(&progress_mutex); - if(tempframenum > currframenum) - currframenum = tempframenum; - pthread_mutex_unlock(&progress_mutex); + for(i=0;ipush(tempoffset[i])); + #ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tempoffset[i]),i); + #endif } + + #ifdef EIGER_DEBUG2 - cprintf(GREEN,"%d tempframenum:%d curframenum:%d\n",ithread, tempframenum, currframenum); + cout << endl <> frameIndexOffset); + else + tempframenum[0] = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum[0]; + else{ + pthread_mutex_lock(&progress_mutex); + if(tempframenum[0] > currframenum) + currframenum = tempframenum[0]; + pthread_mutex_unlock(&progress_mutex); + } + + + //without datacompression: write datacall back, or write data, free fifo + if(!dataCompression) handleWithoutDataCompression(ithread,wbuf); + //data compression + else handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); + + } + } #ifdef VERYVERBOSE cprintf(GREEN,"%d gonna wait for 1st sem\n", ithread); @@ -2276,7 +2248,7 @@ int UDPStandardImplementation::startWriting(){ //wait sem_wait(&writersmp[ithread]); if(killAllWritingThreads){ - cout << ithread << " good bye writing thread" << endl; + cprintf(GREEN,"%d good bye writing thread\n", ithread); closeFile(ithread); pthread_exit(NULL); } @@ -2313,7 +2285,7 @@ int UDPStandardImplementation::startWriting(){ //wait sem_wait(&writersmp[ithread]); if(killAllWritingThreads){ - cout << ithread << " Goodbye thread" << endl; + cprintf(GREEN,"%d Goodbye thread\n", ithread); closeFile(ithread); pthread_exit(NULL); } @@ -2355,11 +2327,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ } //for scans, cuz currfraenum resets else if (myDetectorType == EIGER){ - /*if(dynamicRange == 32) - startFrameIndex = (currframenum + 1);// to be added later for scans - else*/ - startFrameIndex += currframenum; - + startFrameIndex += currframenum; } @@ -2375,93 +2343,95 @@ void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int FILE_LOG(logDEBUG) << __AT__ << " called"; -int i; + int i; #ifdef VERYVERBOSE - cprintf(BLUE, "%d recvfrom() failed\n", ithread); -#endif - if(status != TRANSMITTING){ - cprintf(BG_RED,"%d *** should never be here********* status not transmitting***********************\n", ithread);/**/ - fifoFree[ithread]->push(buffer[ithread]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener not txm free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE, "%d Stop Listening\n", ithread); #endif - exit(-1); - } - //free buffer - if(rc <= 0){ - cprintf(BLUE,"%d End of acquisition\n", ithread); - fifoFree[ithread]->push(buffer[ithread]);/** why not while(!)*/ + + if(status != TRANSMITTING){ + cprintf(BG_RED,"%d *** udp socket not shut down from client ***********************\n", ithread); + while(!fifoFree[ithread]->push(buffer[ithread])); + exit(-1); + } + + + //free buffer + if(rc <= 0){ + cprintf(BLUE,"%d End of acquisition\n", ithread); + while(!fifoFree[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); + cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); #endif - } - //push the last buffer into fifo - else{ + } - if (rc < (bufferSize * numJobsPerThread)) - cprintf(RED,"%d Pushing Incomplete frame into fifo\n", ithread); - //eiger (complete frames) + other detectors - pc = (rc/onePacketSize); -//#ifdef VERYDEBUG - cprintf(BLUE,"%d last rc:%d\n",ithread, rc); - cprintf(BLUE,"%d last packetcount:%d\n", ithread, pc); -//#endif - (*((uint16_t*)(buffer[ithread]))) = pc; - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); + + //push the last buffer into fifo + else{ + pc = (rc/onePacketSize); +#ifdef VERYDEBUG + cprintf(BLUE,"%d last rc:%d\n",ithread, rc); + cprintf(BLUE,"%d last packetcount:%d\n", ithread, pc); +#endif + (*((uint32_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; + while(!fifo[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); #endif + } - } - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); + //push dummy buffer to all writer threads + for(i=0;ipop(buffer[ithread]); #ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); + cprintf(BLUE,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); #endif - (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; + (*((uint32_t*)(buffer[ithread]))) = 0x0; #ifdef VERYDEBUG - cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); + cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); #endif - while(!fifo[ithread]->push(buffer[ithread])); -//#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); -//#endif - } + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); +#endif + } + + - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1< 1) - cprintf(BLUE,"%d Waiting for listening to be done.. current mask:0x%x\n", ithread, listeningthreads_mask); + if(numListeningThreads > 1) + cprintf(BLUE,"%d Waiting for listening to be done.. current mask:0x%x\n", ithread, listeningthreads_mask); #endif - while(listeningthreads_mask) - usleep(5000); -//#ifdef VERYDEBUG - t = 0; - for(i=0;ipush(wbuffer[i])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); +#endif + } + + + //all threads need to close file, reset mask and exit loop closeFile(ithread); pthread_mutex_lock(&status_mutex); @@ -2551,42 +2536,42 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(myDetectorType == EIGER){ int k = 0; if(dynamicRange != 32){ - cprintf(GREEN, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(GREEN, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(GREEN, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); k = 1; - cprintf(GREEN, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(GREEN, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); k = 2; - cprintf(GREEN, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); }else{ k = 0; - cprintf(GREEN, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(GREEN, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(GREEN, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); k = 1; - cprintf(GREEN, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(GREEN, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 2; - cprintf(GREEN, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 256; - cprintf(GREEN, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 512; - cprintf(GREEN, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); k = 768; - cprintf(GREEN, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(GREEN, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(GREEN, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); + cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); + cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); } } #endif @@ -2607,9 +2592,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(tempframenum > currframenum) currframenum = tempframenum; } -//#ifdef VERYDEBUG - cprintf(GREEN,"tempframenum: %d curframenum: %d\n",tempframenum,currframenum); -//#endif +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif //lock if(numWriterThreads > 1) @@ -2626,7 +2611,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num packetsCaught += packetsToSave; totalPacketsCaught += packetsToSave; #ifdef VERYDEBUG - cprintf(GREEN,"%d totalPacketsCaught: %d\n", ithread, totalPacketsCaught); + cout << "/totalPacketsCaught:" << dec << totalPacketsCaught <= maxPacketsPerFile){ @@ -2644,9 +2629,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(tempframenum > currframenum) currframenum = tempframenum; } -//#ifdef VERYDEBUG - cprintf(GREEN,"tempframenum: %d curframenum: %d\n", tempframenum ,currframenum); -//#endif +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif //create createNewFile(); } @@ -2675,16 +2660,17 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num -void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[], int partialframe, int smaller){ + + + + +void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[]){ int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; int i,j,npackets, ntotpackets=0; if (cbAction < DO_EVERYTHING){ for(i=0;ipush(wbuffer[0])); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); + cprintf(BLUE,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); #endif } From 4e5209699152d8a6f83754c8ff34fc2f6803838c Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 21 Jul 2015 16:25:56 +0200 Subject: [PATCH 107/222] included propix receiver --- slsReceiverSoftware/include/receiver_defs.h | 38 ++++- .../include/slsReceiverTCPIPInterface.h | 3 + .../include/sls_receiver_defs.h | 3 +- .../src/UDPStandardImplementation.cpp | 26 ++- .../src/slsReceiverTCPIPInterface.cpp | 158 ++++++++++++++++++ 5 files changed, 213 insertions(+), 15 deletions(-) diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 6f3b1acd35..6466a45b50 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -51,6 +51,26 @@ + +#define PROPIX_PIXELS_IN_ROW 22 +#define PROPIX_PIXELS_IN_COL 22 +#define PROPIX_DATABYTES_PER_PIXEL 2 + +#define PROPIX_FIFO_SIZE 25000 //cannot be less than max jobs per thread = 1000 +#define PROPIX_PACKETS_PER_FRAME 2 +#define PROPIX_ONE_PACKET_SIZE 1286 +#define PROPIX_BUFFER_SIZE (PROPIX_ONE_PACKET_SIZE*PROPIX_PACKETS_PER_FRAME) //1286*2 +//#define PROPIX_DATA_BYTES (1280*PROPIX_PACKETS_PER_FRAME) //1280*2 +#define PROPIX_DATA_BYTES (PROPIX_PIXELS_IN_ROW * PROPIX_PIXELS_IN_COL * PROPIX_DATABYTES_PER_PIXEL) //22 * 22 * 2 + +#define PROPIX_FRAME_INDEX_MASK 0xFFFFFFFE +#define PROPIX_FRAME_INDEX_OFFSET 1 +#define PROPIX_PACKET_INDEX_MASK 0x1 + + + + + #define MOENCH_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 /*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ #define MOENCH_PACKETS_PER_FRAME 40 @@ -68,19 +88,19 @@ -#define JCTB_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 +#define JCTB_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 /*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ -#define JCTB_PACKETS_PER_FRAME 50 +#define JCTB_PACKETS_PER_FRAME 50 #define JCTB_ONE_PACKET_SIZE 8214 -#define JCTB_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) -#define JCTB_DATA_BYTES (JCTB_BUFFER_PER_FRAME) +#define JCTB_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) +#define JCTB_DATA_BYTES (JCTB_BUFFER_PER_FRAME) -#define JCTB_FRAME_INDEX_MASK 0xFFFFFF00 -#define JCTB_FRAME_INDEX_OFFSET 8 -#define JCTB_PACKET_INDEX_MASK 0xFF +#define JCTB_FRAME_INDEX_MASK 0xFFFFFF00 +#define JCTB_FRAME_INDEX_OFFSET 8 +#define JCTB_PACKET_INDEX_MASK 0xFF -#define JCTB_BYTES_PER_ADC (2) -#define JCTB_PIXELS_IN_ONE_ROW 32 +#define JCTB_BYTES_PER_ADC (2) +#define JCTB_PIXELS_IN_ONE_ROW 32 #define JCTB_BYTES_IN_ONE_ROW (JCTB_PIXELS_IN_ONE_ROW*2) diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index ea0e1a3d01..83d9416aac 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -170,6 +170,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** gotthard specific read frame */ int gotthard_read_frame(); + /** propix specific read frame */ + int propix_read_frame(); + /** moench specific read frame */ int moench_read_frame(); diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 025e3b9cf8..6abb308870 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -58,7 +58,8 @@ class slsReceiverDefs { AGIPD, /**< agipd */ MOENCH, /**< moench */ JUNGFRAU, /**< jungfrau */ - JUNGFRAUCTB /**< jungfrauCTBversion */ + JUNGFRAUCTB, /**< jungfrauCTBversion */ + PROPIX /**< propix */ }; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0b22d88884..12edd0720c 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -262,6 +262,9 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD case GOTTHARD: cout << endl << "***** This is a GOTTHARD Receiver *****" << endl << endl; break; + case PROPIX: + cout << endl << "***** This is a PROPIX Receiver *****" << endl << endl; + break; case MOENCH: cout << endl << "***** This is a MOENCH Receiver *****" << endl << endl; break; @@ -280,7 +283,7 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD break; } - //moench variables + //detector specific variables if(myDetectorType == GOTTHARD){ fifosize = GOTTHARD_FIFO_SIZE; packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; @@ -291,6 +294,16 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; + }else if(myDetectorType == PROPIX){ + fifosize = PROPIX_FIFO_SIZE; + packetsPerFrame = PROPIX_PACKETS_PER_FRAME; + onePacketSize = PROPIX_ONE_PACKET_SIZE; + frameSize = PROPIX_BUFFER_SIZE; + bufferSize = PROPIX_BUFFER_SIZE; + maxPacketsPerFile = MAX_FRAMES_PER_FILE * PROPIX_PACKETS_PER_FRAME; + frameIndexMask = PROPIX_FRAME_INDEX_MASK; + frameIndexOffset = PROPIX_FRAME_INDEX_OFFSET; + packetIndexMask = PROPIX_PACKET_INDEX_MASK; }else if(myDetectorType == MOENCH){ fifosize = MOENCH_FIFO_SIZE; packetsPerFrame = MOENCH_PACKETS_PER_FRAME; @@ -827,6 +840,8 @@ void UDPStandardImplementation::setupFifoStructure(){ fifosize = GOTTHARD_FIFO_SIZE; if(myDetectorType == MOENCH) fifosize = MOENCH_FIFO_SIZE; + if(myDetectorType == PROPIX) + fifosize = PROPIX_FIFO_SIZE; else if(myDetectorType == EIGER) fifosize = EIGER_FIFO_SIZE; @@ -1797,6 +1812,7 @@ int UDPStandardImplementation::startListening(){ break; case GOTTHARD: + case PROPIX: if(shortFrame == -1){ lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYDEBUG @@ -1959,7 +1975,7 @@ int UDPStandardImplementation::startWriting(){ tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 //tempframenum = ((tempframenum / EIGER_32BIT_INITIAL_CONSTANT) + startFrameIndex)-1;//eiger 32 bit mode is a multiple of 17c. +startframeindex for scans - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + }else if ((myDetectorType == PROPIX) || ((myDetectorType == GOTTHARD) && (shortFrame == -1))) tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); @@ -2156,7 +2172,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); } //gotthard has +1 for frame number and not a short frame - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + else if ((myDetectorType == PROPIX) || ((myDetectorType == GOTTHARD) && (shortFrame == -1))) startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) & (frameIndexMask)) >> frameIndexOffset); else @@ -2437,7 +2453,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num //for progress and packet loss calculation(new files) if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); @@ -2474,7 +2490,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num //for packet loss lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); else tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 2c882b1390..631df46d12 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1027,6 +1027,8 @@ int slsReceiverTCPIPInterface::read_frame(){ return moench_read_frame(); case EIGER: return eiger_read_frame(); + case PROPIX: + return propix_read_frame(); default: return gotthard_read_frame(); } @@ -1393,6 +1395,162 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ +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 = new char[bufferSize]; + int rnel = bufferSize/(sizeof(int)); + int* retval = new int[rnel]; + int* origVal = new int[rnel]; + //all initialized to 0 + for(i=0;igetFramesCaught()){ + startAcquisitionIndex=-1; + cout<<"haven't caught any frame yet"<getStartFrameIndex();*/ + receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); + + /**send garbage with -1 index to try again*/ + if (raw == NULL){ + startAcquisitionIndex = -1; +#ifdef VERBOSE + cout<<"data not ready for gui yet"<> 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 VERBOSE + cout << "index1:" << hex << index << endl; + cout << "index2:" << hex << index << endl; +#endif + + memcpy(origVal,raw,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 << ":"<differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL){ + cout << "mess:" << mess << endl; + socket->SendDataOnly(mess,sizeof(mess)); + } + else{ + socket->SendDataOnly(fName,MAX_STR_LENGTH); + socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); + socket->SendDataOnly(&frameIndex,sizeof(frameIndex)); + socket->SendDataOnly(retval,PROPIX_DATA_BYTES); + } + + delete [] retval; + delete [] origVal; + delete [] raw; + + return ret; +} + + + + + + + + int slsReceiverTCPIPInterface::eiger_read_frame(){ From f970baf1b827031ca32861a0f330594c4d60267a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 27 Jul 2015 12:36:45 +0200 Subject: [PATCH 108/222] write and copy to gui left --- .../include/UDPStandardImplementation.h | 3 +- .../src/UDPStandardImplementation.cpp | 356 +++++++----------- 2 files changed, 137 insertions(+), 222 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 42650e9bbd..3462ded226 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -442,8 +442,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Its called for the first packet of a scan or acquistion * Sets the startframeindices and the variables to know if acquisition started * @param ithread listening thread number + * @param numbytes number of bytes it listened to */ - void startFrameIndices(int ithread); + void startFrameIndices(int ithread, int numbytes); /** * This is called when udp socket is shut down diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 84d1adcbcb..ed0df1b47a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -828,15 +828,17 @@ void UDPStandardImplementation::setupFifoStructure(){ if(myDetectorType == MOENCH) fifosize = MOENCH_FIFO_SIZE; else if(myDetectorType == EIGER) - fifosize = EIGER_FIFO_SIZE; + fifosize = EIGER_FIFO_SIZE * packetsPerFrame; if(fifosize % numJobsPerThread) fifosize = (fifosize/numJobsPerThread)+1; else fifosize = fifosize/numJobsPerThread; - - cout << "Number of Frames per buffer:" << numJobsPerThread << endl; + if(myDetectorType == EIGER) + cout << "1 packet per buffer" << endl; + else + cout << "Number of Frames per buffer:" << numJobsPerThread << endl; cout << "Fifo Size:" << fifosize << endl; /* @@ -854,27 +856,32 @@ void UDPStandardImplementation::setupFifoStructure(){ #endif delete fifoFree[i]; } - if(fifo[i]) delete fifo[i]; + if(fifo[i]) delete fifo[i]; if(mem0[i]) free(mem0[i]); fifoFree[i] = new CircularFifo(fifosize); fifo[i] = new CircularFifo(fifosize); + int whatperbuffer = bufferSize; + if(myDetectorType == EIGER) + whatperbuffer = onePacketSize; + //allocate memory - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); + mem0[i]=(char*)malloc((whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); /** shud let the client know about this */ if (mem0[i]==NULL){ cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; exit(-1); } + buffer[i]=mem0[i]; //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { + while (buffer[i]<(mem0[i]+(whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { fifoFree[i]->push(buffer[i]); #ifdef FIFO_DEBUG cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); #endif - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + buffer[i]+=(whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); } } cout << "Fifo structure(s) reconstructed" << endl; @@ -1683,7 +1690,8 @@ int UDPStandardImplementation::startListening(){ if(tempchar) {delete [] tempchar;tempchar = NULL;} if(myDetectorType != EIGER) tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - + else + maxBufferSize = 0; @@ -1747,7 +1755,7 @@ int UDPStandardImplementation::startListening(){ //start indices for each start of scan/acquisition if((!measurementStarted) && (rc > 0)){ pthread_mutex_lock(&progress_mutex); - startFrameIndices(ithread); + startFrameIndices(ithread, rc); pthread_mutex_unlock(&progress_mutex); } @@ -1825,6 +1833,7 @@ int UDPStandardImplementation::startListening(){ case EIGER: //because even headers might be included, so not packet count (*((uint32_t*)(buffer[ithread]))) = rc; + packetcount = 1; break; default: @@ -1890,16 +1899,16 @@ int UDPStandardImplementation::startWriting(){ thread_started = 1; int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; - int numpackets[numListeningThreads], popready[numListeningThreads], woffset[numListeningThreads], nf; - bool endofacquisition, startheader[numListeningThreads]; + int numpackets[numListeningThreads], popready[numListeningThreads], nf; + bool startdatapacket[numListeningThreads],fullframe[numListeningThreads]; uint32_t tempframenum[numListeningThreads]; uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; - char* tempbuffer[numListeningThreads] = NULL; + char* tempbuffer = NULL; int tempoffset[numListeningThreads]; int LAST_PACKET_VALUE; - bool fullframe; + char* wbuf[numListeningThreads];//interleaved @@ -1930,31 +1939,33 @@ int UDPStandardImplementation::startWriting(){ //allow them all to be popped initially for(i=0;ipop(wbuf[i]); #ifdef FIFO_DEBUG @@ -1977,27 +1985,18 @@ int UDPStandardImplementation::startWriting(){ #endif numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); #ifdef VERYDEBUG - cout << i << " numpackets:" << dec << numpackets[i] << "for fifo :"<< i << endl; + cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); #endif - //dont pop until ready - popready[i] = 0; - //reset offset - woffset[i] = 0; + //dont pop again if dummy packet + if(!numpackets[i]) + popready[i] = 0; } } - //check for end of acquisition - endofacquisition = true; - for(i=0;i= numpackets[i]){ - popready[i] = 1; - fullframe = false; - break; - } + //header packet + if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i])))->header_confirm))){ - //check if header - if( 0x01 == (*(uint16_t*)(((eiger_image_header *)((char*)(wbuf[i] + woffset[i])))->header_confirm))){ - //expected frame header -eiger frame numbers start at 1, so need to -1 - if(tempframenum[i] == (htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + woffset[i])))->fnum)+(startFrameIndex-1))){ - woffset[i] += EIGER_HEADER_LENGTH; - startheader[i] = true; - numberofmissingpackets[i] = 0; - lastpacketheader[i] = -1; - tempoffset[i] = 0; - } - //wrong header - leave - else{ - numberofmissingpackets[i] += (LAST_PACKET_VALUE - lastpacketheader[i]); - tempframenum[i]++; - //add missing packets - for(j=0;jfnum)+(startFrameIndex-1); + //next frame, leave + else{ + //add missing packets + numberofmissingpackets += (LAST_PACKET_VALUE = lastpacketheader[i]); + for(j=0;jnum4))); - //last packet - leave + } + //data packet + else{ + //update current packet + currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + woffset[i])))->num4))); + //same frame packet - continue building frame + if(currentpacketheader[i] > lastpacketheader[i]){ + //add missing packets + numberofmissingpackets[i] += (currentpacketheader[i] - lastpacketheader[i] -1); + for(j=0;j lastpacketheader[i]){ - - if(!startheader[i]){ - tempframenum[i]++; - } - else - startheader[i] = false; - lastpacketheader[i] = -1; - numberofmissingpackets[i] = 0; - numberofmissingpackets[i] += (currentpacketheader[i] - lastpacketheader[i] -1); - //add missing packets - for(j=0;jnum1)) = currframenum; - //overwriting port number and dynamic range - if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num3)) = (dynamicRange<<2); - else (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); - - #ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4))); - #endif - - } - - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame/4; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num4))); - - #ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num2))); - #endif - } - for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + onePacketSize*i)))->num4))+(packetsPerFrame/4)); - - #ifdef VERYDEBUG - cprintf(GREEN, "%d -0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(tempoffset[j] + i*onePacketSize)))->num2))); - #endif - } - } - - -#endif - - - - //writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); - - + if(tempframenum[0] != tempframenum[1]) + cprintf(RED,"Frame numbers mismatch!!! %d %d\n",tempframenum[0],tempframenum[1]); + currentpacketheader = tempframenum[0]; + //write - } + //copy } -#ifdef VERYDEBUG - cprintf(GREEN,"gonna copy frame\n"); -#endif - copyFrameToGui(wbuffer,currframenum); -//#ifdef VERYDEBUG - cprintf(GREEN,"copied frame\n"); -//#endif - - for(i=0;ipush(tempoffset[i])); - #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tempoffset[i]),i); - #endif - } #ifdef EIGER_DEBUG2 @@ -2302,12 +2205,17 @@ int UDPStandardImplementation::startWriting(){ -void UDPStandardImplementation::startFrameIndices(int ithread){ +void UDPStandardImplementation::startFrameIndices(int ithread, int numbytes){ FILE_LOG(logDEBUG) << __AT__ << " called"; + //add currframenum later in this method for scans if (myDetectorType == EIGER){ - //add currframenum later in this method for scans - startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + //check if its a header + if(EIGER_HEADER_LENGTH == numbytes) + startFrameIndex = (htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum))-1; + //missed header packet, so default value + else + startFrameIndex = 0; } //gotthard has +1 for frame number and not a short frame else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) @@ -2321,13 +2229,13 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ //start of acquisition if(!acqStarted){ startAcquisitionIndex=startFrameIndex; - currframenum = startAcquisitionIndex; + //currframenum = startAcquisitionIndex; acqStarted = true; cprintf(BLUE,"%d startAcquisitionIndex:%d\n", ithread, startAcquisitionIndex); } //for scans, cuz currfraenum resets else if (myDetectorType == EIGER){ - startFrameIndex += currframenum; + startFrameIndex += (currframenum+1); } @@ -2369,12 +2277,18 @@ void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int //push the last buffer into fifo else{ - pc = (rc/onePacketSize); + if(myDetectorType == EIGER){ + (*((uint32_t*)(buffer[ithread]))) = rc; + pc = 1; + }else{ + pc = (rc/onePacketSize); + (*((uint32_t*)(buffer[ithread]))) = pc; + } #ifdef VERYDEBUG cprintf(BLUE,"%d last rc:%d\n",ithread, rc); cprintf(BLUE,"%d last packetcount:%d\n", ithread, pc); #endif - (*((uint32_t*)(buffer[ithread]))) = pc; + totalListeningFrameCount[ithread] += pc; while(!fifo[ithread]->push(buffer[ithread])); #ifdef FIFO_DEBUG From fa156f337ec3b51c9c4d78d03bc4359e2dca228e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 28 Jul 2015 18:15:09 +0200 Subject: [PATCH 109/222] sorta done without missing packet identifiers --- .../include/UDPBaseImplementation.h | 3 + .../include/UDPStandardImplementation.h | 4 +- .../include/sls_receiver_defs.h | 4 +- .../src/UDPStandardImplementation.cpp | 261 ++++++++++-------- 4 files changed, 153 insertions(+), 119 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 8db022a697..1e1c7bdf94 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -575,6 +575,9 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** Pckets currently in current file, starts new file when it reaches max */ int packetsInFile; + /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ + int numTotMissingPacketsInFile; + /** Frame index at start of an entire acquisition (including all scans) */ uint32_t startAcquisitionIndex; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 3462ded226..40c3ab54c5 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -461,7 +461,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * When acquisition is over, this is called * @param ithread listening thread number */ - void stopWriting(int ithread); + void stopWriting(int ithread, char* wbuffer[]); /** * updates parameters and writes to file when not a dummy frame @@ -470,7 +470,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param ithread writing thread number * @param wbuffer writer buffer */ - void handleWithoutDataCompression(int ithread, char* wbuffer[]); + void handleWithoutDataCompression(int ithread, char* wbuffer); /** * data compression for each fifo output diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 7ed6e08378..a9f6d30c21 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -19,8 +19,8 @@ typedef int int32_t; #define MAX_FRAMES_PER_FILE 20000 #define SHORT_MAX_FRAMES_PER_FILE 100000 #define MOENCH_MAX_FRAMES_PER_FILE 1000 -#define EIGER_MAX_FRAMES_PER_FILE 20 -#define JFCTB_MAX_FRAMES_PER_FILE 100000 +#define EIGER_MAX_FRAMES_PER_FILE 2000 +#define JFCTB_MAX_FRAMES_PER_FILE 100000 /** diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index ed0df1b47a..48d53098e9 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -122,6 +122,7 @@ void UDPStandardImplementation::initializeMembers(){ packetsCaught = 0; totalPacketsCaught = 0; packetsInFile = 0; + numTotMissingPacketsInFile = 0; startAcquisitionIndex = 0; acquisitionIndex = 0; packetsPerFrame = 0; @@ -1260,6 +1261,7 @@ int UDPStandardImplementation::setupWriter(){ //reset writing thread variables packetsInFile=0; + numTotMissingPacketsInFile = 0; packetsCaught=0; frameIndex=0; if(sfilefd) sfilefd=NULL; @@ -1377,6 +1379,8 @@ int UDPStandardImplementation::createNewFile(){ //create file name if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); + else if (myDetectorType == EIGER) + sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,currframenum,fileIndex); else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex); @@ -1411,11 +1415,11 @@ int UDPStandardImplementation::createNewFile(){ cout << savefilename << "\tpacket loss " << setw(4)<header_confirm))){ + if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->header_confirm))){ //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans if(!startdatapacket[i]) - tempframenum[i] = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + woffset[i])))->fnum)+(startFrameIndex-1); + tempframenum[i] = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)+(startFrameIndex-1); //next frame, leave else{ //add missing packets - numberofmissingpackets += (LAST_PACKET_VALUE = lastpacketheader[i]); + numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); + //to decrement from packetsInFile to calculate packet loss + numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jnum4))); + currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); //same frame packet - continue building frame if(currentpacketheader[i] > lastpacketheader[i]){ //add missing packets - numberofmissingpackets[i] += (currentpacketheader[i] - lastpacketheader[i] -1); + numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); + //to decrement from packetsInFile to calculate packet loss + numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jpush(wbuffer[i])); + if(myDetectorType == EIGER) { + //push every packet + for(j=0;jpush(wbuffer[i]+j*onePacketSize)); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]+j*onePacketSize)); #endif + } + }else{ + while(!fifoFree[i]->push(wbuffer[i])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); +#endif + } } @@ -2444,7 +2490,6 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num offset = HEADER_SIZE_NUM_TOT_PACKETS; if(myDetectorType == EIGER){ - offset += EIGER_HEADER_LENGTH; #ifdef WRITE_HEADERS #ifdef VERY_DEBUG if(myDetectorType == EIGER){ @@ -2531,7 +2576,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(packetsInFile >= maxPacketsPerFile){ //for packet loss lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER); + if(myDetectorType == EIGER);//because currframenum is the latest one for eiger else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); else @@ -2578,79 +2623,67 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num -void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[]){ - int totalheader = HEADER_SIZE_NUM_TOT_PACKETS + EIGER_HEADER_LENGTH; - int i,j,npackets, ntotpackets=0; +void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer){ + int i,npackets; if (cbAction < DO_EVERYTHING){ - for(i=0;i 0){ + npackets = (uint32_t)(*((uint32_t*)wbuffer)); + if (npackets > 0){ #ifdef WRITE_HEADERS - if (myDetectorType == EIGER){ + if (myDetectorType == EIGER){ - for (i = 0; i < packetsPerFrame/2; i++){ - //overwriting frame number in header - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num1)) = currframenum; - //overwriting port number and dynamic range - if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num3)) = (dynamicRange<<2); - else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + for (i = 0; i < packetsPerFrame; i++){ + //overwriting frame number in header + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num1)) = currframenum; + //overwriting port number and dynamic range + if (i<(packetsPerFrame/2)) + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = (dynamicRange<<2); + else + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); #ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4))); + cprintf(GREEN, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4))); #endif - } + } - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame/4; i++){ + //for 32 bit,port number needs to be changed and packet number reconstructed + if(dynamicRange == 32){ + for (i = 0; i < packetsPerFrame; i++){ + if( (i < (packetsPerFrame/4)) || ((i > (packetsPerFrame/2)) && (i < (3*packetsPerFrame/4))) ){ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num4))); - -#ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num2))); -#endif - } - for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))); + }else{ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader + onePacketSize*i)))->num4))+(packetsPerFrame/4)); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))+(packetsPerFrame/4)); + } #ifdef VERYDEBUG - cprintf(GREEN, "%d -0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[j] + totalheader +i*onePacketSize)))->num2))); + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num2))); #endif - } + } } + } #endif - writeToFile_withoutCompression(wbuffer[j], npackets,currframenum); - } + writeToFile_withoutCompression(wbuffer, npackets,currframenum); } + #ifdef VERYDEBUG cprintf(GREEN,"written everyting\n"); #endif @@ -2658,25 +2691,23 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if(myDetectorType == EIGER) { - if(ntotpackets >= packetsPerFrame ) { + #ifdef VERYDEBUG - cprintf(GREEN,"gonna copy frame\n"); + cprintf(GREEN,"gonna copy frame\n"); #endif - copyFrameToGui(wbuffer,currframenum); -//#ifdef VERYDEBUG - cprintf(GREEN,"copied frame\n"); -//#endif - } - for(i=0;ipush(wbuffer[i])); + copyFrameToGui(wbuffer,currframenum); + //#ifdef VERYDEBUG + cprintf(GREEN,"copied frame\n"); + //#endif + + for(i=0;inum3)) != 0xFF) + while(!fifoFree[i]->push(wbuffer+i*onePacketSize)); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]),i); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer+i*onePacketSize)); #endif } - - } else{ //copy to gui From d49da66daefca78bcfc6459b335abfc0a22138d3 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 30 Jul 2015 10:42:10 +0200 Subject: [PATCH 110/222] almost done with changes --- .../include/UDPStandardImplementation.h | 5 +- .../src/UDPStandardImplementation.cpp | 278 +++++++++--------- 2 files changed, 148 insertions(+), 135 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 40c3ab54c5..67443f21c1 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -436,7 +436,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param numpackets is the number of packets * @param framenum current frame number */ - void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); + void writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum); /** * Its called for the first packet of a scan or acquistion @@ -469,8 +469,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Called by startWriting() * @param ithread writing thread number * @param wbuffer writer buffer + * @param npackets number of packets */ - void handleWithoutDataCompression(int ithread, char* wbuffer); + void handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets); /** * data compression for each fifo output diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3f18ddea9c..8e8c930b6c 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -992,12 +992,8 @@ cout << "copyframe" << endl; #endif //eiger if(startbuf != NULL){ - int offset = 0; - int size = frameSize/EIGER_MAX_PORTS; - for(int j=0;jpop(wbuf[i]); #ifdef FIFO_DEBUG - cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); + cprintf(GREEN,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); #endif numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); #ifdef VERYDEBUG @@ -2070,18 +2071,23 @@ int UDPStandardImplementation::startWriting(){ if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->header_confirm))){ //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans - if(!startdatapacket[i]) + if(!startdatapacket[i]){ + tempframenum[i] = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)+(startFrameIndex-1); - //next frame, leave +//#ifdef VERYVERBOSE + cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); +//#endif + }//next frame, leave else{ + cprintf(RED,"**missing packets and got header\n"); //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); //to decrement from packetsInFile to calculate packet loss numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jnum4))); +#ifdef VERYVERBOSE + cprintf(GREEN,"** got current packet header of %d: %d lastpacketheader %d\n",i,currentpacketheader[i],lastpacketheader[i]); +#endif //same frame packet - continue building frame if(currentpacketheader[i] > lastpacketheader[i]){ //add missing packets @@ -2100,30 +2109,31 @@ int UDPStandardImplementation::startWriting(){ numTotMissingPacketsInFile += numberofmissingpackets[i]; for(j=0;jpush(buffer[ithread])); #ifdef FIFO_DEBUG cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); @@ -2415,27 +2429,15 @@ void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; - int i,j; -#ifdef VERBOSE - cprintf(GREEN,"%d End of Acquisition\n",ithread); -#endif + cprintf(GREEN,"%d End of Acquisition for Writing Thread\n",ithread); + int i,j; //free fifo for(i=0;ipush(wbuffer[i]+j*onePacketSize)); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[i]+j*onePacketSize)); -#endif - } - }else{ - while(!fifoFree[i]->push(wbuffer[i])); + while(!fifoFree[i]->push(wbuffer[i])); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); + cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); #endif - } } @@ -2497,10 +2499,10 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ -void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum){ +void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum){ FILE_LOG(logDEBUG) << __AT__ << " called"; - int packetsToSave, offset,lastpacket; + int packetsToSave, offset,lastpacket,i; uint32_t tempframenum = framenum; //file write @@ -2513,42 +2515,42 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(myDetectorType == EIGER){ int k = 0; if(dynamicRange != 32){ - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num4))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num4))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); }else{ k = 0; - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset+k*1040)))->num2))); + cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 256; - cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 512; - cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); k = 768; - cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf + offset + k*1040)))->num1))); - cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num3))); - cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf + offset +k*1040)))->num2))); + cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); + cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); + cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); } } #endif @@ -2559,9 +2561,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num //for progress and packet loss calculation(new files) if(myDetectorType == EIGER); else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); if(numWriterThreads == 1) currframenum = tempframenum; @@ -2583,7 +2585,12 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(packetsToSave > numpackets) packetsToSave = numpackets; /**next time offset is still plus header length*/ - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); + if(myDetectorType == EIGER) + for(i=0;i= maxPacketsPerFile){ - //for packet loss - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER);//because currframenum is the latest one for eiger - else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) + //for packet loss, because currframenum is the latest one for eiger + if(myDetectorType != EIGER){ + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + } if(numWriterThreads == 1) currframenum = tempframenum; else{ @@ -2619,8 +2627,8 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num if(numWriterThreads > 1) pthread_mutex_unlock(&write_mutex); - - offset += (packetsToSave * onePacketSize); + if(myDetectorType != EIGER) + offset += (packetsToSave * onePacketSize); numpackets -= packetsToSave; } @@ -2643,17 +2651,19 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf,int num -void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer){ - int i,npackets; +void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets){ + int i,j; if (cbAction < DO_EVERYTHING){ - npackets = (uint32_t)(*((uint32_t*)wbuffer)); - rawDataReadyCallBack(currframenum, wbuffer + HEADER_SIZE_NUM_TOT_PACKETS, npackets * onePacketSize, sfilefd, guiData,pRawDataReady); + if (myDetectorType == EIGER){ + for(i=0;i 0){ #ifdef WRITE_HEADERS @@ -2661,17 +2671,17 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* for (i = 0; i < packetsPerFrame; i++){ //overwriting frame number in header - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num1)) = currframenum; + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; //overwriting port number and dynamic range if (i<(packetsPerFrame/2)) - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = (dynamicRange<<2); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = (dynamicRange<<2); else - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = ((dynamicRange<<2)|(0x1)); #ifdef VERYDEBUG cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); #endif } @@ -2681,19 +2691,19 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* for (i = 0; i < packetsPerFrame; i++){ if( (i < (packetsPerFrame/4)) || ((i > (packetsPerFrame/2)) && (i < (3*packetsPerFrame/4))) ){ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); }else{ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS + onePacketSize*i)))->num4))+(packetsPerFrame/4)); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+(packetsPerFrame/4)); } #ifdef VERYDEBUG cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer + HEADER_SIZE_NUM_TOT_PACKETS +i*onePacketSize)))->num2))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); #endif } @@ -2720,13 +2730,15 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(GREEN,"copied frame\n"); //#endif - for(i=0;inum3)) != 0xFF) - while(!fifoFree[i]->push(wbuffer+i*onePacketSize)); + for(i=0;inum3)) != 0xFF) + while(!fifoFree[i]->push(wbuffer[j+i*(packetsPerFrame/2)])); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer+i*onePacketSize)); + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[j+i*(packetsPerFrame/2)])); #endif + } } } else{ @@ -2752,13 +2764,13 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* -void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ +void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ FILE_LOG(logDEBUG) << __AT__ << " called"; #if defined(MYROOT1) && defined(ALLFILE_DEBUG) writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); #endif - + int npackets = (uint32_t)(*((uint32_t*)wbuffer[0])); eventType thisEvent = PEDESTAL; int ndata; char* buff = 0; From c0f2e5c6c2ce4475f4d56dd465f55255f7e24a04 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 30 Jul 2015 11:00:36 +0200 Subject: [PATCH 111/222] onepacketsize not consistent for 10g bug fix --- .../src/UDPStandardImplementation.cpp | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 12edd0720c..03bada0660 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -586,10 +586,15 @@ int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEB if(myDetectorType == EIGER){ - if(!tengigaEnable) + if(!tengigaEnable){ packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - else + onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + + }else{ packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; + onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; + } + frameSize = onePacketSize * packetsPerFrame; bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; @@ -2009,15 +2014,15 @@ int UDPStandardImplementation::startWriting(){ for (i = 0; i < packetsPerFrame/2; i++){ //overwriting frame number in header - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num1)) = currframenum; + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + onePacketSize*i)))->num1)) = currframenum; //overwriting port number and dynamic range - if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = (dynamicRange<<2); - else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num3)) = ((dynamicRange<<2)|(0x1)); + if (!j) (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + onePacketSize*i)))->num3)) = (dynamicRange<<2); + else (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + onePacketSize*i)))->num3)) = ((dynamicRange<<2)|(0x1)); #ifdef VERYDEBUG cprintf(RED, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*onePacketSize)))->num4))); #endif } @@ -2026,26 +2031,26 @@ int UDPStandardImplementation::startWriting(){ if(dynamicRange == 32){ for (i = 0; i < packetsPerFrame/4; i++){ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + onePacketSize*i)))->num4))); #ifdef VERYDEBUG cprintf(RED, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*onePacketSize)))->num2))); #endif } for (i = packetsPerFrame/4; i < packetsPerFrame/2; i++){ //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + EIGER_ONE_GIGA_ONE_PACKET_SIZE*i)))->num4))+(packetsPerFrame/4)); + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + onePacketSize*i)))->num2)) + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader + onePacketSize*i)))->num4))+(packetsPerFrame/4)); #ifdef VERYDEBUG cprintf(RED, "%d -0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*EIGER_ONE_GIGA_ONE_PACKET_SIZE)))->num2))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*onePacketSize)))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*onePacketSize)))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuf[j] + totalheader +i*onePacketSize)))->num2))); #endif } } @@ -2656,20 +2661,18 @@ int UDPStandardImplementation::enableTenGiga(int enable){ if(!tengigaEnable){ packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; }else{ packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; } frameSize = onePacketSize * packetsPerFrame; bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; cout<<"packetsPerFrame:"< Date: Mon, 3 Aug 2015 16:29:59 +0200 Subject: [PATCH 112/222] almost done --- .../include/UDPBaseImplementation.h | 11 +- .../src/UDPStandardImplementation.cpp | 362 +++++++++++------- 2 files changed, 233 insertions(+), 140 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 1e1c7bdf94..4e29e0bc69 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -567,16 +567,19 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter uint32_t frameIndex; /** Frames Caught for each real time acquisition (eg. for each scan) */ - int packetsCaught; + uint32_t packetsCaught; /** Total packets caught for an entire acquisition (including all scans) */ - int totalPacketsCaught; + uint32_t totalPacketsCaught; /** Pckets currently in current file, starts new file when it reaches max */ - int packetsInFile; + uint32_t packetsInFile; /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ - int numTotMissingPacketsInFile; + uint32_t numTotMissingPacketsInFile; + + /** Number of missing packets in an acquisition(sometimes packetsinFile is incorrect due to padded packets for eiger)*/ + uint32_t numMissingPackets; /** Frame index at start of an entire acquisition (including all scans) */ uint32_t startAcquisitionIndex; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index f538976253..3cd559b529 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -123,6 +123,7 @@ void UDPStandardImplementation::initializeMembers(){ totalPacketsCaught = 0; packetsInFile = 0; numTotMissingPacketsInFile = 0; + numMissingPackets = 0; startAcquisitionIndex = 0; acquisitionIndex = 0; packetsPerFrame = 0; @@ -1278,6 +1279,7 @@ int UDPStandardImplementation::setupWriter(){ //reset writing thread variables packetsInFile=0; numTotMissingPacketsInFile = 0; + numMissingPackets = 0; packetsCaught=0; frameIndex=0; if(sfilefd) sfilefd=NULL; @@ -1936,16 +1938,37 @@ int UDPStandardImplementation::startWriting(){ int ret,i,j; + char* tofree[packetsPerFrame] ; + int tofreeoffset[packetsPerFrame]; char* tempbuffer[packetsPerFrame]; char* blankframe[packetsPerFrame]; int blankoffset; int tempoffset[numListeningThreads]; - if(myDetectorType == EIGER) + if(myDetectorType == EIGER){ for(i=0;inum3)) != 0xFF) + cprintf(RED,"blank frame header is not FF\n"); + + cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); + } + + //last packet numbers for different dynamic ranges + switch(dynamicRange){ + case 4: LAST_PACKET_VALUE = 0x40; break; + case 8: LAST_PACKET_VALUE = 0x80; break; + case 16: LAST_PACKET_VALUE = 0xff; break; + case 32: LAST_PACKET_VALUE = 0xff; break; + default: break; } + } + while(1){ @@ -1972,6 +1995,7 @@ int UDPStandardImplementation::startWriting(){ popready[i] = true; startdatapacket[i] = false; tempoffset[i] = (i*packetsPerFrame/numListeningThreads); + tofreeoffset[i] = (i*packetsPerFrame/numListeningThreads); blankoffset = 0; lastpacketheader[i] = -1; currentpacketheader[i] = -1; @@ -1983,34 +2007,6 @@ int UDPStandardImplementation::startWriting(){ - if(myDetectorType == EIGER){ - - for(i=0;ipop(wbuf[i]); #ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i])); + cprintf(GREEN,"%d writer poped 0x%x from fifo %d\n", ithread, (void*)(wbuf[i]), i); #endif numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); #ifdef VERYDEBUG cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); #endif //dont pop again if dummy packet - if(!numpackets[i]) + if(!numpackets[i]){ popready[i] = false; + cprintf(RED,"%d dummy frame popped out of fifo %d",ithread, i); + }else{ + tofree[tofreeoffset[i]] = wbuf[i]; + tofreeoffset[i]++; + } + } } @@ -2040,11 +2042,31 @@ int UDPStandardImplementation::startWriting(){ //end of acquisition if((!numpackets[0])&& (!numpackets[1])){ -#ifdef VERYDEBUG - cprintf(GREEN,"%d End of Acquisition in Writing Thread\n", ithread); -#endif - stopWriting(ithread,wbuf); - continue; +//#ifdef VERYDEBUG + cprintf(GREEN,"%d Both dummy frames\n", ithread); +//#endif + //remaning packets to be written + if((myDetectorType == EIGER) && + ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))){ + cprintf(RED,"**missing packets and end of acquisition\n"); + for(i=0;iheader_confirm))){ - - //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans - if(!startdatapacket[i]){ - tempframenum[i] = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)+(startFrameIndex-1); -//#ifdef VERYVERBOSE - cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); + if(numpackets[i]){ + while(!fifoFree[i]->push((wbuf[i]))); +//#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed unknown length pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuf[i]),i); //#endif - }//next frame, leave - else{ - cprintf(RED,"**missing packets and got header\n"); - //add missing packets - numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); - //to decrement from packetsInFile to calculate packet loss - numTotMissingPacketsInFile += numberofmissingpackets[i]; - for(j=0;jnum4))); -#ifdef VERYVERBOSE - cprintf(GREEN,"** got current packet header of %d: %d lastpacketheader %d\n",i,currentpacketheader[i],lastpacketheader[i]); -#endif - //same frame packet - continue building frame - if(currentpacketheader[i] > lastpacketheader[i]){ - //add missing packets - numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); - //to decrement from packetsInFile to calculate packet loss - numTotMissingPacketsInFile += numberofmissingpackets[i]; - for(j=0;jheader_confirm))){ + + //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans + if(!startdatapacket[i]){ + tempframenum[i] = (htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); + if(!tempframenum[i]) + cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); + tempframenum[i] += (startFrameIndex-1); + //#ifdef VERYVERBOSE + cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); + //#endif + }//next frame, leave + else{ + cprintf(RED,"**missing packets and got header\n"); + //add missing packets + numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); + //to decrement from packetsInFile to calculate packet loss + for(j=0;jnum4))); +#ifdef VERYVERBOSE + cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d\n",i,currentpacketheader[i],lastpacketheader[i]); +#endif + //same frame packet - continue building frame + if(currentpacketheader[i] > lastpacketheader[i]){ + //add missing packets + numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); + //to decrement from packetsInFile to calculate packet loss + for(j=0;jpush(tofree[j])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),0); +#endif + } + for(j=(packetsPerFrame/numListeningThreads);jpush(tofree[j])); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); +#endif + } + + + +//#ifdef VERYDEBUG + cprintf(GREEN,"finished freeing\n"); +//#endif //reset a few stuff for(int i=0;ipush(wbuffer[i])); -#ifdef FIFO_DEBUG +//#ifdef FIFO_DEBUG cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -#endif +//#endif } @@ -2480,8 +2559,8 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ cprintf(GREEN, "Status: Run Finished\n"); if(!totalPacketsCaught){ - cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught); - cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); + cprintf(RED, "Total Packets Caught: 0\n"); + cprintf(RED, "Total Frames Caught: 0\n"); }else{ cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught); cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame)); @@ -2505,7 +2584,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum){ FILE_LOG(logDEBUG) << __AT__ << " called"; - +cout<<"in write to file numpackets:"< numpackets) packetsToSave = numpackets; /**next time offset is still plus header length*/ - if(myDetectorType == EIGER) - for(i=0;i= maxPacketsPerFile){ @@ -2641,8 +2724,9 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n if(numWriterThreads > 1) pthread_mutex_lock(&write_mutex); packetsInFile += numpackets; - packetsCaught += numpackets; - totalPacketsCaught += numpackets; + packetsCaught += (numpackets - numMissingPackets); + totalPacketsCaught += (numpackets - numMissingPackets); + numMissingPackets = 0; if(numWriterThreads > 1) pthread_mutex_unlock(&write_mutex); } @@ -2734,16 +2818,22 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(GREEN,"copied frame\n"); //#endif - for(i=0;inum3)) != 0xFF) - while(!fifoFree[i]->push(wbuffer[j+i*(packetsPerFrame/2)])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[j+i*(packetsPerFrame/2)])); -#endif - } +/* + for(j=0;jnum3)) != 0xFF){ + + while(!fifoFree[(j/(packetsPerFrame/2))]->push(&(wbuffer[j] - HEADER_SIZE_NUM_TOT_PACKETS))); + + //#ifdef FIFO_DEBUG + cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[j]- HEADER_SIZE_NUM_TOT_PACKETS),(j/(packetsPerFrame/2))); + //#endif + }else cprintf(GREEN,"blank frame 0x%x\n",(void*)(wbuffer[j])); } + + //#ifdef VERYDEBUG + cprintf(GREEN,"finished freeing\n"); + //#endif + */ } else{ //copy to gui From 4fbfe186ef636f06bd9f17d651cc78da00bc6ade Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 4 Aug 2015 15:20:00 +0200 Subject: [PATCH 113/222] done --- .../src/UDPStandardImplementation.cpp | 221 +++++++++--------- 1 file changed, 117 insertions(+), 104 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3cd559b529..9f365d4b04 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1922,43 +1922,34 @@ int UDPStandardImplementation::startWriting(){ thread_started = 1; - int numpackets[numListeningThreads], nf; - bool startdatapacket[numListeningThreads],fullframe[numListeningThreads],popready[numListeningThreads]; - uint32_t tempframenum[numListeningThreads]; - - int lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; - int numberofmissingpackets[numListeningThreads]; - int LAST_PACKET_VALUE; - - - char* wbuf[numListeningThreads];//interleaved char *d=new char[bufferSize*numListeningThreads]; int xmax=0,ymax=0; int ret,i,j; + int numpackets[numListeningThreads], nf; + bool startdatapacket[numListeningThreads],fullframe[numListeningThreads],popready[numListeningThreads]; + uint32_t tempframenum[numListeningThreads]; + int lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; + int numberofmissingpackets[numListeningThreads]; - char* tofree[packetsPerFrame] ; - int tofreeoffset[packetsPerFrame]; - char* tempbuffer[packetsPerFrame]; - char* blankframe[packetsPerFrame]; - int blankoffset; + int MAX_VALUE = 1024; + char* tofree[MAX_VALUE]; + char* tempbuffer[MAX_VALUE]; + char* blankframe[MAX_VALUE]; + int tofreeoffset[numListeningThreads]; int tempoffset[numListeningThreads]; - if(myDetectorType == EIGER){ - for(i=0;inum3)) != 0xFF) - cprintf(RED,"blank frame header is not FF\n"); + int blankoffset; + for(i=0;ipush((wbuf[i]))); -//#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed unknown length pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuf[i]),i); -//#endif - } continue; } //not dummy buffer and not after getting a full frame if(numpackets[i] && (!fullframe[i])){ - //header packet + //IMAGE HEADER PACKET if( 0x01 == (*(uint8_t*)(((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->header_confirm))){ //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans @@ -2114,12 +2115,37 @@ int UDPStandardImplementation::startWriting(){ if(!tempframenum[i]) cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); tempframenum[i] += (startFrameIndex-1); - //#ifdef VERYVERBOSE - cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); - //#endif - }//next frame, leave + + //normal frame packet (also exception of tempnum 0 and currfnum 0) + if((tempframenum[i] == (currframenum+1))||(!tempframenum[i] && !currframenum)){ +#ifdef EIGER_DEBUG3 + cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); +#endif + } + //frame too far ahead + else{ +#ifdef EIGER_DEBUG3 + cprintf(RED,"frame number too far ahead, missing packets\n"); +#endif + tempframenum[i] = currframenum + 1; + //add missing packets + numberofmissingpackets[i] = (LAST_PACKET_VALUE); + //to decrement from packetsInFile to calculate packet loss + for(j=0;jpush(wbuffer[i])); -//#ifdef FIFO_DEBUG +#ifdef FIFO_DEBUG cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -//#endif +#endif } @@ -2584,7 +2610,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum){ FILE_LOG(logDEBUG) << __AT__ << " called"; -cout<<"in write to file numpackets:"<= maxPacketsPerFile){ @@ -2814,28 +2842,10 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(GREEN,"gonna copy frame\n"); #endif copyFrameToGui(wbuffer,currframenum); - //#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"copied frame\n"); - //#endif - -/* - for(j=0;jnum3)) != 0xFF){ - - while(!fifoFree[(j/(packetsPerFrame/2))]->push(&(wbuffer[j] - HEADER_SIZE_NUM_TOT_PACKETS))); - - //#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuffer[j]- HEADER_SIZE_NUM_TOT_PACKETS),(j/(packetsPerFrame/2))); - //#endif - }else cprintf(GREEN,"blank frame 0x%x\n",(void*)(wbuffer[j])); - } - - //#ifdef VERYDEBUG - cprintf(GREEN,"finished freeing\n"); - //#endif - */ - } - else{ +#endif + }else{ //copy to gui if(npackets >= packetsPerFrame){//min 1 frame, but neednt be //if(npackets == packetsPerFrame * numJobsPerThread){ //only full frames @@ -2843,11 +2853,14 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* #ifdef VERYVERBOSE cout << ithread << " finished copying" << endl; #endif - }//else cout << "unfinished buffersize" << endl; + } + /* freeing now done at function call + //else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuffer[0])); #ifdef FIFO_DEBUG cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); #endif + */ } } From a26cbced57b022050ebd3ad66de7cee903303be4 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 5 Aug 2015 09:11:50 +0200 Subject: [PATCH 114/222] corrected 10g mapping for gui --- .../src/slsReceiverTCPIPInterface.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 631df46d12..5cb2f0fb5c 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1616,13 +1616,13 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ int c2=(frameSize/2) + 8; //second port int retindex=0; int irow,ibytesperpacket; - int linesperpacket = (16/dynamicrange)* 1;// 16:1 line, 8:2 lines, 4:4 lines, 32: 0.5 + 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 = 1040*(16*dynamicrange)*2; if(tenGigaEnable){ - linesperpacket = (16/dynamicrange)* 4;// 16:4 line, 8:8 lines, 4:16 lines, 32: 2 + linesperpacket = (16*4/dynamicrange);// 16:4 line, 8:8 lines, 4:16 lines, 32: 2 datapacketlength = EIGER_TEN_GIGA_ONE_DATA_SIZE; } //if 1GbE, one line is split into two packets for 32 bit mode, so its special @@ -1640,7 +1640,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport); retindex += numbytesperlineperport; c1 += numbytesperlineperport; - if(dynamicrange == 32){ + if(dynamicrange == 32 && !tenGigaEnable){ c1 += 16; memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport); retindex += numbytesperlineperport; @@ -1651,7 +1651,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport); retindex += numbytesperlineperport; c2 += numbytesperlineperport; - if(dynamicrange == 32){ + if(dynamicrange == 32 && !tenGigaEnable){ c2 += 16; memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport); retindex += numbytesperlineperport; @@ -1660,7 +1660,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ } ibytesperpacket += numbytesperlineperport; } - if(dynamicrange != 32) { + if(dynamicrange != 32 || tenGigaEnable) { c1 += 16; c2 += 16; } @@ -1677,7 +1677,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ for(irow=0;irow Date: Wed, 5 Aug 2015 12:08:28 +0200 Subject: [PATCH 115/222] proper freeng after udpsocket shutdown --- slsReceiverSoftware/include/genericSocket.h | 2 ++ slsReceiverSoftware/src/UDPStandardImplementation.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 0ccc80adfc..216a9fa11b 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -443,6 +443,8 @@ typedef struct void ShutDownSocket(){ while(!shutdown(socketDescriptor, SHUT_RDWR)); + close(socketDescriptor); + socketDescriptor = -1; }; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 03bada0660..0104f9b47d 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1077,6 +1077,7 @@ int UDPStandardImplementation::createUDPSockets(){ #ifdef VERBOSE cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); #endif + shutDownUDPSockets(); return FAIL; } } From d2f53aaf64f6f603307debf3d8145bc86e21aece Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 7 Aug 2015 12:06:10 +0200 Subject: [PATCH 116/222] bugs --- .../src/UDPStandardImplementation.cpp | 206 ++++++++++++------ 1 file changed, 137 insertions(+), 69 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index ff275d8056..0f05e06781 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1987,8 +1987,14 @@ int UDPStandardImplementation::startWriting(){ for(i=0;inum3)) = 0xFE; + + for(j=0;j<(onePacketSize-16);++j) + (*((uint8_t*)((char*)(blankframe[i])+8+j))) = 0xFF; + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) != 0xFE){ + cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); + exit(-1); + } #ifdef FIFO_DEBUG cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); #endif @@ -2036,12 +2042,14 @@ int UDPStandardImplementation::startWriting(){ //dont pop again if dummy packet if(!numpackets[i]){ popready[i] = false; -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED,"%d Dummy frame popped out of fifo %d",ithread, i); -#endif +//#endif }else{ - tofree[tofreeoffset[i]] = wbuf[i]; - tofreeoffset[i]++; + if(myDetectorType == EIGER){ + tofree[tofreeoffset[i]] = wbuf[i]; + tofreeoffset[i]++; + } } } @@ -2051,21 +2059,24 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if((!numpackets[0])&& (!numpackets[1])){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif +//#endif //remaning packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED,"**End of Acquisition but didnt get last packet\n"); -#endif +//#endif for(i=0;inum3)) == 0xFE) + cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "1 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; } @@ -2097,10 +2108,10 @@ int UDPStandardImplementation::startWriting(){ if((numpackets[i] != EIGER_HEADER_LENGTH) && (numpackets[i] != onePacketSize)){ if(numpackets[i]) cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); -#ifdef VERBOSE +//#ifdef VERBOSE else cprintf(RED, "WARNING: Dummy packet: %d from fifo %d\n", numpackets[i],i); -#endif +//#endif continue; } @@ -2119,23 +2130,29 @@ int UDPStandardImplementation::startWriting(){ //normal frame packet (also exception of tempnum 0 and currfnum 0) if((tempframenum[i] == (currframenum+1))||(!tempframenum[i] && !currframenum)){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); -#endif +//#endif } //frame too far ahead else{ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED,"frame number too far ahead, missing packets\n"); -#endif +//#endif tempframenum[i] = currframenum + 1; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE); + if(numberofmissingpackets[i]>0) + cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + cprintf(RED,"2 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "2 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; + } //set fullframe and dont let fifo pop over it until written fullframe[i] = true; @@ -2144,14 +2161,19 @@ int UDPStandardImplementation::startWriting(){ } }//two image headers at a time = next frame, leave else{ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED,"received frame header twice, missing packets\n"); -#endif +//#endif //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); + if(numberofmissingpackets[i]>0) + cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + cprintf(RED,"3 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "3 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; } @@ -2165,16 +2187,21 @@ int UDPStandardImplementation::startWriting(){ startdatapacket[i] = true; //update current packet currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); -#ifdef VERYVERBOSE - cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d\n",i,currentpacketheader[i],lastpacketheader[i]); -#endif +//#ifdef VERYVERBOSE + cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); +//#endif //same frame packet - continue building frame if(currentpacketheader[i] > lastpacketheader[i]){ //add missing packets numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); + if(numberofmissingpackets[i]>0) + cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; } @@ -2185,24 +2212,29 @@ int UDPStandardImplementation::startWriting(){ lastpacketheader[i] = currentpacketheader[i]; //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver if(currentpacketheader[i] == LAST_PACKET_VALUE){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN, "Got last packet\n"); -#endif +//#endif fullframe[i] = true; popready[i] = false; } } //next frame packet - leave else{ -#ifdef EIGER_DEBUG3 - cprintf(RED,"packet from next frame, missing packets"<0) + cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d\n",i,lastpacketheader[i],currentpacketheader[i]); //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); tempoffset[i] ++; blankoffset ++; } @@ -2231,17 +2263,22 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; -#ifdef EIGER_DEBUG2 - cprintf(GREEN,"%d **fnum:%d**\n",currframenum); -#endif -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG2 + cprintf(GREEN,"**fnum:%d**\n",currframenum); +//#endif +//#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) - cprintf(RED, "fifo 0 missing packets:%d\n",numberofmissingpackets[0]); + cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) - cprintf(RED, "fifo 1 missing packets:%d\n",numberofmissingpackets[1]); - if(numMissingPackets) - cprintf(RED, "numMissingPackets:%d\n",numMissingPackets); -#endif + cprintf(RED, "fifo 1 missing packets:%d fnum:%d\n",numberofmissingpackets[1],currframenum); + if(numMissingPackets){ + cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); + + for (j=0;jnum3)) == 0xFE) + cprintf(RED,"found the missing packet at pnum:%d\n",j); + } +//#endif //write and copy to gui @@ -2264,9 +2301,9 @@ int UDPStandardImplementation::startWriting(){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -#endif +//#endif //reset a few stuff for(int i=0;inum1)) = currframenum; - //overwriting port number and dynamic range - if (i<(packetsPerFrame/2)) - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = (dynamicRange<<2); - else - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = ((dynamicRange<<2)|(0x1)); -#ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); -#endif - - } + //which port + if (i ==(packetsPerFrame/2)) + port = 1; + //missing packet + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFE){ + missingpacket = 1; + //add packet numbers + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); + }else{ + missingpacket = 0; - //for 32 bit,port number needs to be changed and packet number reconstructed - if(dynamicRange == 32){ - for (i = 0; i < packetsPerFrame; i++){ - if( (i < (packetsPerFrame/4)) || ((i > (packetsPerFrame/2)) && (i < (3*packetsPerFrame/4))) ){ - //new packet number that has space for 16 bit - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))); - }else{ - //new packet number that has space for 16 bit + if(dynamicRange != 32){ + //move packet numbers to num2, and compensate for port1 starting pnum from 0 + if(!port) + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = + ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+1); + else + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = + ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+(packetsPerFrame/2) +1); + } + //dr == 32 + else{ + if(i == 0) + pnuminc = 0; + else if(i == (packetsPerFrame/4)) + pnuminc = (packetsPerFrame/4); + else if(i == (packetsPerFrame/2)) + pnuminc = (packetsPerFrame/2); + else if(i == (3*packetsPerFrame/4)) + pnuminc = (3*packetsPerFrame/4); (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+(packetsPerFrame/4)); + = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+pnuminc+1); } + } + + + if((*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) != (i+1)){ + cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFE) + cprintf(BG_RED,"missing packet though\n"); + exit(-1); + } + + //overwriting port number and dynamic range + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = + ((dynamicRange<<2)|(missingpacket<<1)|(port)); + + //frame number + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; + #ifdef VERYDEBUG - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); + if((i==0)||(i==1)){ + cprintf(GREEN, "%d packet header:0x%016llx num3:0x%x\n",i, + ((uint64_t)(*((uint64_t*)(wbuffer[i])))), + (uint8_t)(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))); + } + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); #endif - } + + } } #endif @@ -2855,13 +2923,13 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cout << ithread << " finished copying" << endl; #endif } - /* freeing now done at function call + //else cout << "unfinished buffersize" << endl; while(!fifoFree[0]->push(wbuffer[0])); #ifdef FIFO_DEBUG cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); #endif - */ + } } From 52f83b9249bc9a32300053de62ba7adb46533725 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 10 Aug 2015 13:44:57 +0200 Subject: [PATCH 117/222] do not push, debug commands involved --- slsReceiverSoftware/include/genericSocket.h | 50 ++++++++++++++++--- .../src/UDPBaseImplementation.cpp | 8 ++- .../src/UDPStandardImplementation.cpp | 41 ++++++++++----- .../src/slsReceiverTCPIPInterface.cpp | 1 - 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 216a9fa11b..3bb4adcff4 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -60,7 +60,7 @@ class sockaddr_in; #include #endif - +#include "ansi.h" #include /******exit */ #include @@ -71,6 +71,8 @@ class sockaddr_in; #include #include +#include //SIGINT + using namespace std; #define DEFAULT_PACKET_SIZE 1286 @@ -125,6 +127,7 @@ typedef struct struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n"; + cprintf(RED,"Exiting: Problem interpreting host:%s\n",host_ip_or_name); } else { // Set some fields in the serverAddress structure. serverAddress.sin_family = hostInfo->h_addrtype; @@ -134,6 +137,7 @@ typedef struct socketDescriptor=0; //You can use send and recv, //would it work????? } clientAddress_length=sizeof(clientAddress); + cprintf(MAGENTA, "client socket created %d \n",socketDescriptor,protocol); } @@ -176,6 +180,7 @@ typedef struct nsent(0), total_sent(0) { + signal(SIGCHLD,SIG_IGN); //memset(&serverAddress, 0, sizeof(sockaddr_in)); // memset(&clientAddress, 0, sizeof(sockaddr_in)); // serverAddress = {0}; @@ -205,9 +210,12 @@ typedef struct socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp + cprintf(MAGENTA, "socket created %d protocol:%d\n",socketDescriptor,protocol); + if (socketDescriptor < 0) { cerr << "Can not create socket "<0) { if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) { cerr << "Error: with server accept, connection refused"<=0){ + close(file_des); + file_des=-1; + } + } +*/ + + if(file_des>=0){ //then was open if(is_a_server){ - close(file_des); + // cprintf(MAGENTA, "file_des disconnected %d \n",file_des); + if(close(file_des)) + cprintf(RED,"file_des not disconnected %d\n", file_des); + // cprintf(MAGENTA, "file_des disconnected %d \n",file_des); } else { - close(socketDescriptor); + //cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor); + if(close(socketDescriptor)) + cprintf(RED,"socketDescriptor not disconnected %d\n", file_des); + // cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor); socketDescriptor=-1; } file_des=-1; } + + + } }; void ShutDownSocket(){ - while(!shutdown(socketDescriptor, SHUT_RDWR)); - close(socketDescriptor); - socketDescriptor = -1; + while(!shutdown(socketDescriptor, SHUT_RDWR)); + Disconnect(); }; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index bbb8b331d7..80ce6b2c72 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -745,15 +745,19 @@ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " if(!strlen(eth)){ cout<<"warning:eth is empty.listening to all"< /proc/sys/net/core/netdev_max_backlog")) cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + /** permanent setting heiner net.core.rmem_max = 104857600 # 100MiB net.core.netdev_max_backlog = 250000 @@ -1056,24 +1057,29 @@ int UDPStandardImplementation::createUDPSockets(){ if(!strlen(eth)){ cout<<"warning:eth is empty.listening to all"<getErrorStatus(); - if(!iret) + if(!iret){ cout << "UDP port opened at port " << port[i] << endl; - else{ + cprintf(YELLOW, "socket of port %d descriptor:%d\n",i,udpSocket[i]->getsocketDescriptor()); + }else{ #ifdef VERBOSE cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); #endif @@ -1082,6 +1088,8 @@ int UDPStandardImplementation::createUDPSockets(){ } } + + return OK; } @@ -1276,7 +1284,7 @@ int UDPStandardImplementation::setupWriter(){ packetsInFile=0; packetsCaught=0; frameIndex=0; - if(sfilefd) sfilefd=NULL; + if(sfilefd) {cprintf(RED,"**FILE not closed!\n");fclose(sfilefd);sfilefd=NULL;} guiData = NULL; guiDataReady=0; strcpy(guiFileName,""); @@ -1402,9 +1410,13 @@ int UDPStandardImplementation::createNewFile(){ if(enableFileWrite && cbAction > DO_NOTHING){ //close if(sfilefd){ - fclose(sfilefd); + if(fclose(sfilefd)){ + cprintf(YELLOW, "file clsoe problem %d\n",fileno(sfilefd)); + fclose(sfilefd); + } sfilefd = NULL; } + //open file if(!overwrite){ if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ @@ -1418,6 +1430,9 @@ int UDPStandardImplementation::createNewFile(){ //setting buffer setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + cprintf(YELLOW, "file value:%d\n",fileno(sfilefd)); + + //cprintf(YELLOW, "file valuex:%d",(int)sfilefd); //printing packet losses and file names if(!packetsCaught) cout << savefilename << endl; @@ -1459,10 +1474,12 @@ void UDPStandardImplementation::closeFile(int ithr){ if(!dataCompression){ if(sfilefd){ -#ifdef VERBOSE - cout << "sfield:" << (int)sfilefd << endl; -#endif - fclose(sfilefd); +//#ifdef VERBOSE + cprintf(YELLOW, "gonna close file:%d\n",fileno(sfilefd)); +//#endif + if(fclose(sfilefd)) + perror("close ERRROR"); + cprintf(YELLOW, "check close file:%d\n",fileno(sfilefd)); sfilefd = NULL; } } @@ -1473,7 +1490,8 @@ void UDPStandardImplementation::closeFile(int ithr){ #ifdef VERBOSE cout << "sfield:" << (int)sfilefd << endl; #endif - fclose(sfilefd); + if(fclose(sfilefd)) + perror("close ERRROR"); sfilefd = NULL; } #endif @@ -1612,7 +1630,6 @@ int UDPStandardImplementation::stopReceiver(){ }else cout <<" Not idle to stop receiver" << endl; - //sem_post(&smp); return OK; diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 5cb2f0fb5c..dfa01e6e37 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -65,7 +65,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* strcpy(socket->lastClientIP,"none"); strcpy(socket->thisClientIP,"none1"); strcpy(mess,"dummy message"); - function_table(); #ifdef VERBOSE cout << "Function table assigned." << endl; From 0a24778ff8f4629bb6dd564e13006989dc573d93 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 10 Aug 2015 14:45:43 +0200 Subject: [PATCH 118/222] missing packets should work now --- .../include/UDPBaseImplementation.h | 5 +- .../src/UDPStandardImplementation.cpp | 89 ++++++++++++------- 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 4e29e0bc69..05b9929754 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -575,10 +575,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** Pckets currently in current file, starts new file when it reaches max */ uint32_t packetsInFile; + /** Number of missing packets in acquisition*/ + uint32_t numTotMissingPackets; + /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ uint32_t numTotMissingPacketsInFile; - /** Number of missing packets in an acquisition(sometimes packetsinFile is incorrect due to padded packets for eiger)*/ + /** Number of missing packets per buffer*/ uint32_t numMissingPackets; /** Frame index at start of an entire acquisition (including all scans) */ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0f05e06781..87fc042e0e 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -122,6 +122,7 @@ void UDPStandardImplementation::initializeMembers(){ packetsCaught = 0; totalPacketsCaught = 0; packetsInFile = 0; + numTotMissingPackets = 0; numTotMissingPacketsInFile = 0; numMissingPackets = 0; startAcquisitionIndex = 0; @@ -861,8 +862,9 @@ void UDPStandardImplementation::setupFifoStructure(){ cout << "1 packet per buffer" << endl; else cout << "Number of Frames per buffer:" << numJobsPerThread << endl; +#ifdef VERBOSE cout << "Fifo Size:" << fifosize << endl; - +#endif /* //for testing numJobsPerThread = 3; fifosize = 11; @@ -1279,6 +1281,7 @@ int UDPStandardImplementation::setupWriter(){ //reset writing thread variables packetsInFile=0; + numTotMissingPackets = 0; numTotMissingPacketsInFile = 0; numMissingPackets = 0; packetsCaught=0; @@ -2042,9 +2045,9 @@ int UDPStandardImplementation::startWriting(){ //dont pop again if dummy packet if(!numpackets[i]){ popready[i] = false; -//#ifdef EIGER_DEBUG3 - cprintf(RED,"%d Dummy frame popped out of fifo %d",ithread, i); -//#endif +#ifdef EIGER_DEBUG3 + cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); +#endif }else{ if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; @@ -2059,24 +2062,26 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if((!numpackets[0])&& (!numpackets[1])){ -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -//#endif +#endif //remaning packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED,"**End of Acquisition but didnt get last packet\n"); -//#endif +#endif for(i=0;inum3)) == 0xFE) cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "1 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; } @@ -2106,12 +2111,12 @@ int UDPStandardImplementation::startWriting(){ //offset outside boundaries, also eliminates dummy packet if((numpackets[i] != EIGER_HEADER_LENGTH) && (numpackets[i] != onePacketSize)){ +#ifdef EIGER_DEBUG3 if(numpackets[i]) cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); -//#ifdef VERBOSE else cprintf(RED, "WARNING: Dummy packet: %d from fifo %d\n", numpackets[i],i); -//#endif +#endif continue; } @@ -2130,26 +2135,30 @@ int UDPStandardImplementation::startWriting(){ //normal frame packet (also exception of tempnum 0 and currfnum 0) if((tempframenum[i] == (currframenum+1))||(!tempframenum[i] && !currframenum)){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); -//#endif +#endif } //frame too far ahead else{ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED,"frame number too far ahead, missing packets\n"); -//#endif +#endif tempframenum[i] = currframenum + 1; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE); +#ifdef VERYDEBUG if(numberofmissingpackets[i]>0) cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); +#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) cprintf(RED,"2 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "2 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; @@ -2161,19 +2170,23 @@ int UDPStandardImplementation::startWriting(){ } }//two image headers at a time = next frame, leave else{ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED,"received frame header twice, missing packets\n"); -//#endif +#endif //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); +#ifdef VERYDEBUG if(numberofmissingpackets[i]>0) cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); +#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) cprintf(RED,"3 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "3 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; } @@ -2187,21 +2200,25 @@ int UDPStandardImplementation::startWriting(){ startdatapacket[i] = true; //update current packet currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); -//#ifdef VERYVERBOSE +#ifdef VERYVERBOSE cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); -//#endif +#endif //same frame packet - continue building frame if(currentpacketheader[i] > lastpacketheader[i]){ //add missing packets numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); +#ifdef VERYDEBUG if(numberofmissingpackets[i]>0) cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); +#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; } @@ -2212,29 +2229,33 @@ int UDPStandardImplementation::startWriting(){ lastpacketheader[i] = currentpacketheader[i]; //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver if(currentpacketheader[i] == LAST_PACKET_VALUE){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN, "Got last packet\n"); -//#endif +#endif fullframe[i] = true; popready[i] = false; } } //next frame packet - leave else{ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED,"packet from next frame, missing packets\n"); -//#endif +#endif //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); +#ifdef VERYDEBUG if(numberofmissingpackets[i]>0) cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d\n",i,lastpacketheader[i],currentpacketheader[i]); +#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif tempoffset[i] ++; blankoffset ++; } @@ -2262,11 +2283,11 @@ int UDPStandardImplementation::startWriting(){ tempframenum[1]++; numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; - -//#ifdef EIGER_DEBUG2 + numTotMissingPackets += numMissingPackets; +#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -//#endif -//#ifdef EIGER_DEBUG3 +#endif +#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2278,7 +2299,7 @@ int UDPStandardImplementation::startWriting(){ if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[j])))->num3)) == 0xFE) cprintf(RED,"found the missing packet at pnum:%d\n",j); } -//#endif +#endif //write and copy to gui @@ -2301,9 +2322,9 @@ int UDPStandardImplementation::startWriting(){ -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -//#endif +#endif //reset a few stuff for(int i=0;i= 0){ @@ -3062,13 +3085,13 @@ int UDPStandardImplementation::enableTenGiga(int enable){ bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - +#ifdef VERBOSE cout<<"packetsPerFrame:"< Date: Thu, 13 Aug 2015 14:46:57 +0200 Subject: [PATCH 119/222] need to chek --- .../src/UDPStandardImplementation.cpp | 379 +++++++++--------- 1 file changed, 199 insertions(+), 180 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 87fc042e0e..374322684a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1702,7 +1702,7 @@ int UDPStandardImplementation::startListening(){ uint32_t lastframeheader;// for moench to check for all the packets in last frame char* tempchar = NULL; - + uint32_t prenum=0; while(1){ @@ -1720,7 +1720,7 @@ int UDPStandardImplementation::startListening(){ else maxBufferSize = 0; - + prenum=0; while((1<ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); + if(rc == 1040){ + cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + + if(((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))< prenum){ + cprintf(BG_RED, "framenumber weird:previous:%d\n",prenum); + exit(-1); + } + prenum = ((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + + } expected = maxBufferSize; #ifdef SOCKET_DEBUG }else{ @@ -1782,7 +1793,8 @@ int UDPStandardImplementation::startListening(){ //start indices for each start of scan/acquisition if((!measurementStarted) && (rc > 0)){ pthread_mutex_lock(&progress_mutex); - startFrameIndices(ithread, rc); + if(!measurementStarted) + startFrameIndices(ithread, rc); pthread_mutex_unlock(&progress_mutex); } @@ -1931,8 +1943,9 @@ int UDPStandardImplementation::startWriting(){ int xmax=0,ymax=0; int ret,i,j; + bool endofacquisition; int numpackets[numListeningThreads], nf; - bool startdatapacket[numListeningThreads],fullframe[numListeningThreads],popready[numListeningThreads]; + bool fullframe[numListeningThreads],popready[numListeningThreads]; uint32_t tempframenum[numListeningThreads]; int lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; @@ -1990,11 +2003,11 @@ int UDPStandardImplementation::startWriting(){ for(i=0;inum3)) = 0xFE; + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) = 0xFF; for(j=0;j<(onePacketSize-16);++j) (*((uint8_t*)((char*)(blankframe[i])+8+j))) = 0xFF; - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) != 0xFE){ + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) != 0xFF){ cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); exit(-1); } @@ -2009,7 +2022,6 @@ int UDPStandardImplementation::startWriting(){ for(i=0;inum1)))); + cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + + + }if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; } @@ -2061,36 +2080,15 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION - if((!numpackets[0])&& (!numpackets[1])){ -#ifdef VERYDEBUG + if(endofacquisition){ +//#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif - //remaning packets to be written +//#endif + //remaining packets to be written if((myDetectorType == EIGER) && - ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))){ -#ifdef EIGER_DEBUG3 - cprintf(RED,"**End of Acquisition but didnt get last packet\n"); -#endif - for(i=0;inum3)) == 0xFE) - cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); -#endif - tempoffset[i] ++; - blankoffset ++; - } - //set fullframe and dont let fifo pop over it until written - fullframe[i] = true; - popready[i] = false; + ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); + else{ - } - }else{ stopWriting(ithread,wbuf); continue; } @@ -2098,95 +2096,48 @@ int UDPStandardImplementation::startWriting(){ - - if(myDetectorType == EIGER){ - //trying to find a full frame + //NOT FULL FRAME if(!fullframe[0] || !fullframe[1]){ - - for(i=0;iheader_confirm))){ - //new frame (no datapacket received yet), update frame num and corrected for fnum reset for scans - if(!startdatapacket[i]){ - tempframenum[i] = (htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)); - if(!tempframenum[i]) - cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); - tempframenum[i] += (startFrameIndex-1); - - //normal frame packet (also exception of tempnum 0 and currfnum 0) - if((tempframenum[i] == (currframenum+1))||(!tempframenum[i] && !currframenum)){ -#ifdef EIGER_DEBUG3 - cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); -#endif - } - //frame too far ahead - else{ -#ifdef EIGER_DEBUG3 - cprintf(RED,"frame number too far ahead, missing packets\n"); -#endif - tempframenum[i] = currframenum + 1; - //add missing packets - numberofmissingpackets[i] = (LAST_PACKET_VALUE); -#ifdef VERYDEBUG - if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); -#endif - //to decrement from packetsInFile to calculate packet loss - for(j=0;jnum3)) == 0xFE) - cprintf(RED,"2 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "2 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); -#endif - tempoffset[i] ++; - blankoffset ++; - - } - //set fullframe and dont let fifo pop over it until written - fullframe[i] = true; - popready[i] = false; - - } - }//two image headers at a time = next frame, leave - else{ -#ifdef EIGER_DEBUG3 - cprintf(RED,"received frame header twice, missing packets\n"); -#endif + //anything that is not a data packet of right size + if(numpackets[i] != onePacketSize){ + //header packet + if(numpackets[i] == EIGER_HEADER_LENGTH) continue; + //dummy packet + else if(!numpackets[i]){ +//#ifdef VERYDEBUG + cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); +//#endif + cout<<"tempoffset["<0) - cprintf(BG_RED,"fifo:%d missing packet from: %d\n",i,lastpacketheader[i]); -#endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) - cprintf(RED,"3 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "3 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); -#endif + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) == 0xFF) + cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); +#endif + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ + cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + exit(-1); + }else + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + tempoffset[i] ++; blankoffset ++; } @@ -2195,83 +2146,142 @@ int UDPStandardImplementation::startWriting(){ popready[i] = false; } } - //DATA PACKET +//#ifdef EIGER_DEBUG3 else{ - startdatapacket[i] = true; - //update current packet - currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); -#ifdef VERYVERBOSE - cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); -#endif - //same frame packet - continue building frame - if(currentpacketheader[i] > lastpacketheader[i]){ - //add missing packets - numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); -#ifdef VERYDEBUG - if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); -#endif - //to decrement from packetsInFile to calculate packet loss - for(j=0;jnum3)) == 0xFE) - cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); -#endif - tempoffset[i] ++; - blankoffset ++; - } - //add current packet - tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; - tempoffset[i] ++; - //update last packet - lastpacketheader[i] = currentpacketheader[i]; - //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver - if(currentpacketheader[i] == LAST_PACKET_VALUE){ -#ifdef EIGER_DEBUG3 - cprintf(GREEN, "Got last packet\n"); -#endif - fullframe[i] = true; - popready[i] = false; - } - } - //next frame packet - leave - else{ -#ifdef EIGER_DEBUG3 - cprintf(RED,"packet from next frame, missing packets\n"); -#endif + cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); + continue; + } +//#endif + } + + + + + + //not a full frame + if(!fullframe[i]){ + + //update frame number + //tempframenum[i] = (htonl(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + tempframenum[i] = ((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + + if(!tempframenum[i]) + cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); + tempframenum[i] += (startFrameIndex-1); + + + //WRONG FRAME - leave (also includes exception of tempnum 0 and currfnum 0) + if((tempframenum[i] != (currframenum+1))&&(tempframenum[i] || currframenum)){cout<<"wrong packet"<num1))), + ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); +//#endif + tempframenum[i] = currframenum+1; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); #ifdef VERYDEBUG if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d\n",i,lastpacketheader[i],currentpacketheader[i]); + cprintf(BG_RED,"fifo:%d missing packet from: %d now\n",i,lastpacketheader[i]); #endif //to decrement from packetsInFile to calculate packet loss for(j=0;jnum3)) == 0xFE) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) == 0xFF) cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ + cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + exit(-1); + }else + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + tempoffset[i] ++; blankoffset ++; } //set fullframe and dont let fifo pop over it until written fullframe[i] = true; popready[i] = false; + } + + + //CORRECT FRAME - continue building frame + else {cout<<"correct packet"<num4))); +//#ifdef VERYVERBOSE + cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); +//#endif + //add missing packets + numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); +#ifdef VERYDEBUG + if(numberofmissingpackets[i]>0) + cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); +#endif + //to decrement from packetsInFile to calculate packet loss + for(j=0;jnum3)) == 0xFF) + cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); + else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); +#endif + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ + cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + exit(-1); + }else + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + tempoffset[i] ++; + blankoffset ++; + } + //add current packet + + if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ + cprintf(BG_RED, "pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d\n",i,tempoffset[i],currentpacketheader[i],tempframenum[i]); + exit(-1); + } + tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; +#ifdef EIGER_DEBUG3 + cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempoffset[i]); +#endif + if((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ + cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempframenum[i]); + exit(-1); + } + cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + tempoffset[i] ++; + //update last packet + lastpacketheader[i] = currentpacketheader[i]; + popready[i] = true; + //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver + if(currentpacketheader[i] == LAST_PACKET_VALUE){ +#ifdef EIGER_DEBUG3 + cprintf(GREEN, "Got last packet\n"); +#endif + fullframe[i] = true; + popready[i] = false; } } } - } } - //check if a full frame received + //FULL FRAME if(fullframe[0] && fullframe[1]){ //determine frame number @@ -2284,9 +2294,9 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -#ifdef EIGER_DEBUG2 - cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif +//#ifdef EIGER_DEBUG2 + cprintf(GREEN,"**fnum:%d**\n",currframenum); +//#endif #ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); @@ -2296,7 +2306,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); for (j=0;jnum3)) == 0xFE) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[j])))->num3)) == 0xFF) cprintf(RED,"found the missing packet at pnum:%d\n",j); } #endif @@ -2319,12 +2329,10 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); #endif } - - - -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -#endif +//#endif + //reset a few stuff for(int i=0;ifnum))-1; //missed header packet, so default value else - startFrameIndex = 0; + startFrameIndex = ((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))-1); + cout<<"startFrameIndex["<push(wbuffer[i])); @@ -2853,14 +2862,23 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //which port if (i ==(packetsPerFrame/2)) port = 1; + + + //missing packet - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFE){ + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF){ missingpacket = 1; //add packet numbers (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); }else{ missingpacket = 0; + if((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)) != (i-(port*packetsPerFrame/numListeningThreads))){ + cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)),currframenum); + exit(-1); + } + + if(dynamicRange != 32){ //move packet numbers to num2, and compensate for port1 starting pnum from 0 if(!port) @@ -2889,7 +2907,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if((*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) != (i+1)){ cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFE) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF) cprintf(BG_RED,"missing packet though\n"); exit(-1); } @@ -2898,8 +2916,9 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = ((dynamicRange<<2)|(missingpacket<<1)|(port)); + //frame number - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; + //(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; #ifdef VERYDEBUG if((i==0)||(i==1)){ From 80f33997d41d76652a8fbe2bcf56ddfa34562600 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 17 Aug 2015 15:37:28 +0200 Subject: [PATCH 120/222] almost works test stage still --- .../src/UDPStandardImplementation.cpp | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 374322684a..3d3c1f4c9a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -894,7 +894,7 @@ void UDPStandardImplementation::setupFifoStructure(){ mem0[i]=(char*)malloc((whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); /** shud let the client know about this */ if (mem0[i]==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); exit(-1); } @@ -1720,8 +1720,6 @@ int UDPStandardImplementation::startListening(){ else maxBufferSize = 0; - prenum=0; - while((1<ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - if(rc == 1040){ - cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - - if(((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))< prenum){ - cprintf(BG_RED, "framenumber weird:previous:%d\n",prenum); - exit(-1); - } - prenum = ((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); - + if(rc == EIGER_HEADER_LENGTH && myDetectorType == EIGER) { + while(rc == EIGER_HEADER_LENGTH) + rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); } expected = maxBufferSize; #ifdef SOCKET_DEBUG @@ -1947,7 +1938,8 @@ int UDPStandardImplementation::startWriting(){ int numpackets[numListeningThreads], nf; bool fullframe[numListeningThreads],popready[numListeningThreads]; uint32_t tempframenum[numListeningThreads]; - int lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; + uint32_t presentframenum; + uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; int MAX_VALUE = 1024; @@ -2033,7 +2025,7 @@ int UDPStandardImplementation::startWriting(){ tempframenum[i] = 0; } endofacquisition = false; - + presentframenum = 0; while((1<pop(wbuf[i]); #ifdef FIFO_DEBUG cprintf(GREEN,"%d writer poped 0x%x from fifo %d\n", ithread, (void*)(wbuf[i]), i); @@ -2055,8 +2044,12 @@ int UDPStandardImplementation::startWriting(){ #ifdef VERYDEBUG cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); #endif + if(numpackets < 0){ + cprintf(BG_RED,"negative numpackets[%d]%d\n",i,numpackets[i]); + exit(-1); + } //dont pop again if dummy packet - if(!numpackets[i]){ + else if(numpackets[i] == 0){ popready[i] = false; //#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); @@ -2066,9 +2059,12 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == 1040){ cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + }else if(numpackets[i] == EIGER_HEADER_LENGTH){ + cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); + exit(-1); + } - - }if(myDetectorType == EIGER){ + if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; } @@ -2107,7 +2103,7 @@ int UDPStandardImplementation::startWriting(){ //anything that is not a data packet of right size if(numpackets[i] != onePacketSize){ //header packet - if(numpackets[i] == EIGER_HEADER_LENGTH) continue; + if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ //#ifdef VERYDEBUG @@ -2130,7 +2126,7 @@ int UDPStandardImplementation::startWriting(){ else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); #endif if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); @@ -2171,15 +2167,15 @@ int UDPStandardImplementation::startWriting(){ tempframenum[i] += (startFrameIndex-1); - //WRONG FRAME - leave (also includes exception of tempnum 0 and currfnum 0) - if((tempframenum[i] != (currframenum+1))&&(tempframenum[i] || currframenum)){cout<<"wrong packet"<num1))), ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); //#endif - tempframenum[i] = currframenum+1; + tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); #ifdef VERYDEBUG @@ -2195,7 +2191,7 @@ int UDPStandardImplementation::startWriting(){ else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + cprintf(BG_RED, "wrong blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); @@ -2237,7 +2233,7 @@ int UDPStandardImplementation::startWriting(){ else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "pnum mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + cprintf(BG_RED, "correct blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); @@ -2250,7 +2246,7 @@ int UDPStandardImplementation::startWriting(){ //add current packet if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d\n",i,tempoffset[i],currentpacketheader[i],tempframenum[i]); + cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n",i,tempoffset[i],currentpacketheader[i],tempframenum[i],(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i])))->num1))); exit(-1); } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; @@ -2288,9 +2284,9 @@ int UDPStandardImplementation::startWriting(){ if(tempframenum[0] != tempframenum[1]) cprintf(RED,"Frame numbers mismatch!!! %d %d\n",tempframenum[0],tempframenum[1]); currframenum = tempframenum[0]; - //to resolve for missing frame packets + /*//to resolve for missing frame packets tempframenum[0]++; - tempframenum[1]++; + tempframenum[1]++;*/ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; @@ -2335,10 +2331,11 @@ int UDPStandardImplementation::startWriting(){ //reset a few stuff + presentframenum = tempframenum[0]+1; for(int i=0;inum4)) != (i-(port*packetsPerFrame/numListeningThreads))){ cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)),currframenum); - exit(-1); + /* exit(-1);*/ } @@ -2909,7 +2906,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF) cprintf(BG_RED,"missing packet though\n"); - exit(-1); + /*exit(-1);*/ } //overwriting port number and dynamic range From e8a5f8108347081449eaf3231a7cba73ccd685ec Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 19 Aug 2015 14:32:08 +0200 Subject: [PATCH 121/222] moving to fix another branch --- .../src/UDPStandardImplementation.cpp | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3d3c1f4c9a..0d4eab84b3 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1751,7 +1751,11 @@ int UDPStandardImplementation::startListening(){ if(rc == EIGER_HEADER_LENGTH && myDetectorType == EIGER) { while(rc == EIGER_HEADER_LENGTH) rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - } + }/* + if(rc == 1040){ + cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + }*/ expected = maxBufferSize; #ifdef SOCKET_DEBUG }else{ @@ -2768,17 +2772,17 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n }else fwrite(buf[0]+offset, 1, packetsToSave * onePacketSize, sfilefd); packetsInFile += packetsToSave; -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"packetscaught earlier:%d packetstosave:%d numMissingPackets:%d addingon:%d\n", packetsCaught,packetsToSave,numMissingPackets,(packetsToSave - numMissingPackets)); -#endif +//#endif packetsCaught += (packetsToSave - numMissingPackets); totalPacketsCaught += (packetsToSave - numMissingPackets); numMissingPackets = 0; -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"packetscaught:%d\n", packetsCaught); cprintf(GREEN,"totalPacketsCaught:%d\n", totalPacketsCaught); -#endif +//#endif //new file if(packetsInFile >= maxPacketsPerFile){ @@ -2867,12 +2871,13 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* missingpacket = 1; //add packet numbers (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; }else{ missingpacket = 0; if((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)) != (i-(port*packetsPerFrame/numListeningThreads))){ cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)),currframenum); - /* exit(-1);*/ + exit(-1); } @@ -2906,7 +2911,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF) cprintf(BG_RED,"missing packet though\n"); - /*exit(-1);*/ + exit(-1); } //overwriting port number and dynamic range @@ -2938,9 +2943,9 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* writeToFile_withoutCompression(wbuffer, npackets,currframenum); } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"written everyting\n"); -#endif +//#endif } From 5dd5c250f3c30593706dd67f3ed8c80a6440443d Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 19 Aug 2015 14:55:15 +0200 Subject: [PATCH 122/222] removing unnecessary prints --- slsReceiverSoftware/include/genericSocket.h | 30 +++---------------- .../src/UDPBaseImplementation.cpp | 2 -- .../src/UDPStandardImplementation.cpp | 19 ++++++------ 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 3bb4adcff4..aa79f3233c 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -60,7 +60,6 @@ class sockaddr_in; #include #endif -#include "ansi.h" #include /******exit */ #include @@ -71,7 +70,6 @@ class sockaddr_in; #include #include -#include //SIGINT using namespace std; @@ -127,7 +125,6 @@ typedef struct struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n"; - cprintf(RED,"Exiting: Problem interpreting host:%s\n",host_ip_or_name); } else { // Set some fields in the serverAddress structure. serverAddress.sin_family = hostInfo->h_addrtype; @@ -137,7 +134,6 @@ typedef struct socketDescriptor=0; //You can use send and recv, //would it work????? } clientAddress_length=sizeof(clientAddress); - cprintf(MAGENTA, "client socket created %d \n",socketDescriptor,protocol); } @@ -180,7 +176,6 @@ typedef struct nsent(0), total_sent(0) { - signal(SIGCHLD,SIG_IGN); //memset(&serverAddress, 0, sizeof(sockaddr_in)); // memset(&clientAddress, 0, sizeof(sockaddr_in)); // serverAddress = {0}; @@ -210,12 +205,10 @@ typedef struct socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp - cprintf(MAGENTA, "socket created %d protocol:%d\n",socketDescriptor,protocol); if (socketDescriptor < 0) { cerr << "Can not create socket "<0) { if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) { cerr << "Error: with server accept, connection refused"<=0){ @@ -459,16 +443,10 @@ typedef struct if(file_des>=0){ //then was open if(is_a_server){ - // cprintf(MAGENTA, "file_des disconnected %d \n",file_des); - if(close(file_des)) - cprintf(RED,"file_des not disconnected %d\n", file_des); - // cprintf(MAGENTA, "file_des disconnected %d \n",file_des); + close(file_des); } else { - //cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor); - if(close(socketDescriptor)) - cprintf(RED,"socketDescriptor not disconnected %d\n", file_des); - // cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor); + close(socketDescriptor); socketDescriptor=-1; } file_des=-1; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 80ce6b2c72..670805a462 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -746,7 +746,6 @@ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " cout<<"warning:eth is empty.listening to all"<getErrorStatus(); if(!iret){ cout << "UDP port opened at port " << port[i] << endl; - cprintf(YELLOW, "socket of port %d descriptor:%d\n",i,udpSocket[i]->getsocketDescriptor()); + //cprintf(YELLOW, "socket of port %d descriptor:%d\n",i,udpSocket[i]->getsocketDescriptor()); }else{ #ifdef VERBOSE cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); @@ -1411,7 +1411,7 @@ int UDPStandardImplementation::createNewFile(){ //close if(sfilefd){ if(fclose(sfilefd)){ - cprintf(YELLOW, "file clsoe problem %d\n",fileno(sfilefd)); + cprintf(RED, "file close problem %d\n",fileno(sfilefd)); fclose(sfilefd); } sfilefd = NULL; @@ -1430,9 +1430,8 @@ int UDPStandardImplementation::createNewFile(){ //setting buffer setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - cprintf(YELLOW, "file value:%d\n",fileno(sfilefd)); + //cprintf(YELLOW, "file value:%d\n",fileno(sfilefd)); - //cprintf(YELLOW, "file valuex:%d",(int)sfilefd); //printing packet losses and file names if(!packetsCaught) cout << savefilename << endl; @@ -1474,12 +1473,12 @@ void UDPStandardImplementation::closeFile(int ithr){ if(!dataCompression){ if(sfilefd){ -//#ifdef VERBOSE +#ifdef VERBOSE cprintf(YELLOW, "gonna close file:%d\n",fileno(sfilefd)); -//#endif +#endif if(fclose(sfilefd)) - perror("close ERRROR"); - cprintf(YELLOW, "check close file:%d\n",fileno(sfilefd)); + perror("file close ERROR"); + //cprintf(YELLOW, "check close file:%d\n",fileno(sfilefd)); sfilefd = NULL; } } From 587d357f3ee94ae5c75c0577b8f6826b2805d286 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 19 Aug 2015 15:47:24 +0200 Subject: [PATCH 123/222] resetting frame index for scans for eiger --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index bb72416654..bebb7ad5e9 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2187,11 +2187,8 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " called"; if (myDetectorType == EIGER){ - //add currframenum later in this method for scans - /*if(dynamicRange == 32) - startFrameIndex = htonl(*(unsigned int*)((eiger_image_header32 *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - else*/ - startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + startFrameIndex = 0; + /*startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum);*/ } //gotthard has +1 for frame number and not a short frame else if ((myDetectorType == PROPIX) || ((myDetectorType == GOTTHARD) && (shortFrame == -1))) @@ -2209,6 +2206,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ acqStarted = true; cout << "startAcquisitionIndex:" << hex << startAcquisitionIndex< Date: Thu, 20 Aug 2015 10:17:36 +0200 Subject: [PATCH 124/222] changed startframeindex to 1 as thats whats written to file in eiger --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index bebb7ad5e9..683b6a9f98 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2187,7 +2187,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " called"; if (myDetectorType == EIGER){ - startFrameIndex = 0; + startFrameIndex = 1; /*startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum);*/ } //gotthard has +1 for frame number and not a short frame From a29da27a42e83bb98090f5ada84cebc2d13812c7 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 20 Aug 2015 17:36:41 +0200 Subject: [PATCH 125/222] works without problems except bottom doesnt get much for acquire --- .../include/UDPBaseImplementation.h | 2 +- .../src/UDPStandardImplementation.cpp | 129 +++++++++++------- 2 files changed, 82 insertions(+), 49 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 05b9929754..38adefe902 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -618,7 +618,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter uint32_t currframenum; /** Previous Frame number from buffer */ - uint32_t prevframenum; + int prevframenum; /** size of one frame */ int frameSize; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0d4eab84b3..5f68876a98 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1749,12 +1749,16 @@ int UDPStandardImplementation::startListening(){ #endif rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); if(rc == EIGER_HEADER_LENGTH && myDetectorType == EIGER) { - while(rc == EIGER_HEADER_LENGTH) + while(rc == EIGER_HEADER_LENGTH){ rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - }/* - if(rc == 1040){ - cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + /*cprintf(MAGENTA,"%d got a header*****************************\n",ithread); + cprintf(MAGENTA,"tempframenum[%d]:%d\n",ithread,(htonl(*(uint32_t*)(((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)))); + */} + } + /* if(rc == 1040){ + cprintf(CYAN,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(CYAN,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(CYAN,"add[%d]:0x%x\n",ithread,(void*)(buffer[ithread])); }*/ expected = maxBufferSize; #ifdef SOCKET_DEBUG @@ -1888,6 +1892,9 @@ int UDPStandardImplementation::startListening(){ cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); #endif while(!fifo[ithread]->push(buffer[ithread])); + /*cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(YELLOW,"add[%d]:0x%x\n",ithread,(void*)(buffer[ithread]));*/ #ifdef FIFO_DEBUG cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif @@ -2007,9 +2014,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); exit(-1); } - #ifdef FIFO_DEBUG + //#ifdef FIFO_DEBUG cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); - #endif + //#endif } } @@ -2061,9 +2068,9 @@ int UDPStandardImplementation::startWriting(){ }else{ endofacquisition = false; if(numpackets[i] == 1040){ - cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + /* cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - }else if(numpackets[i] == EIGER_HEADER_LENGTH){ + */}else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); } @@ -2125,19 +2132,19 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2) cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); #endif - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ + if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); exit(-1); }else - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); - + /*cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); +*/ tempoffset[i] ++; blankoffset ++; } @@ -2172,13 +2179,13 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave - if(tempframenum[i] != presentframenum){cout<<"wrong packet"<num1))), ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); -//#endif +#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2190,18 +2197,23 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2) cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "wrong blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ + cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " + "i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3)), + (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + /*cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (void*)(tempbuffer[tempoffset[i]]));*/ tempoffset[i] ++; blankoffset ++; @@ -2213,15 +2225,15 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame - else {cout<<"correct packet"<num4))); -//#ifdef VERYVERBOSE +#ifdef VERYVERBOSE cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); -//#endif +#endif //add missing packets numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); #ifdef VERYDEBUG @@ -2232,25 +2244,32 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2) cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)) != 0xFF){ - cprintf(BG_RED, "correct blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ + cprintf(BG_RED, "correct blank mismatch num4 earlier2! " + "i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3)), + (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + /* cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (void*)(tempbuffer[tempoffset[i]]));*/ tempoffset[i] ++; blankoffset ++; } //add current packet if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n",i,tempoffset[i],currentpacketheader[i],tempframenum[i],(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i])))->num1))); + cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", + i,tempoffset[i],currentpacketheader[i], + tempframenum[i],(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i]+ HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); exit(-1); } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; @@ -2258,10 +2277,15 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempoffset[i]); #endif if((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempframenum[i]); + cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d add:0x%x\n", + i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)), + tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } - cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + /*cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + i,tempoffset[i],tempframenum[i], + (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (void*)(tempbuffer[tempoffset[i]]));*/ tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; @@ -2306,7 +2330,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); for (j=0;jnum3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[j])))->num3))&0x2) cprintf(RED,"found the missing packet at pnum:%d\n",j); } #endif @@ -2329,9 +2353,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); #endif } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -//#endif +#endif //reset a few stuff @@ -2341,6 +2365,7 @@ int UDPStandardImplementation::startWriting(){ //no dummy packet and is the last packet (if not last packet, next frame, dont pop over it) if((numpackets[i]) && (currentpacketheader[i] == LAST_PACKET_VALUE)) popready[i] = true; + /*cprintf(GREEN,"popready[%d]:%d\n",i,popready[i]);*/ tempoffset[i] = (i*packetsPerFrame/numListeningThreads); tofreeoffset[i] = (i*packetsPerFrame/numListeningThreads); blankoffset = 0; @@ -2350,6 +2375,11 @@ int UDPStandardImplementation::startWriting(){ } } + /* for(int i=0;inum1)))); + cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + }*/ } @@ -2772,17 +2802,17 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n }else fwrite(buf[0]+offset, 1, packetsToSave * onePacketSize, sfilefd); packetsInFile += packetsToSave; -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"packetscaught earlier:%d packetstosave:%d numMissingPackets:%d addingon:%d\n", packetsCaught,packetsToSave,numMissingPackets,(packetsToSave - numMissingPackets)); -//#endif +#endif packetsCaught += (packetsToSave - numMissingPackets); totalPacketsCaught += (packetsToSave - numMissingPackets); numMissingPackets = 0; -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"packetscaught:%d\n", packetsCaught); cprintf(GREEN,"totalPacketsCaught:%d\n", totalPacketsCaught); -//#endif +#endif //new file if(packetsInFile >= maxPacketsPerFile){ @@ -2867,11 +2897,11 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //missing packet - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF){ + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))&0x2){ missingpacket = 1; //add packet numbers (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; + (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum+1; }else{ missingpacket = 0; @@ -2909,7 +2939,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if((*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) != (i+1)){ cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) == 0xFF) + if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))&0x2) cprintf(BG_RED,"missing packet though\n"); exit(-1); } @@ -2933,8 +2963,11 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); #endif - - +/* + cprintf(GREEN,"at writing, fnum:%d, pnum:%d,num3:0x%x add:0x%x\n", + currframenum, i, (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (void*)(wbuffer[i])); +*/ } } @@ -2943,9 +2976,9 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* writeToFile_withoutCompression(wbuffer, npackets,currframenum); } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"written everyting\n"); -//#endif +#endif } From 4813d7b59830393b0e713ad695706009c508c025 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 21 Aug 2015 10:04:55 +0200 Subject: [PATCH 126/222] should work properly --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 5f68876a98..7692697215 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1654,7 +1654,12 @@ void UDPStandardImplementation::startReadout(){ /********************************************/ //usleep(10000000); //usleep(2000000); - + int prev = totalPacketsCaught; + usleep(50000); + while(prev!=totalPacketsCaught){ + prev=totalPacketsCaught; + usleep(50000); + } pthread_mutex_lock(&status_mutex); status = TRANSMITTING; pthread_mutex_unlock(&status_mutex); @@ -2014,9 +2019,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); exit(-1); } - //#ifdef FIFO_DEBUG +#ifdef FIFO_DEBUG cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); - //#endif +#endif } } From 8f6b8a847404262ab58f7cee2a3625f55188c818 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 21 Aug 2015 10:54:14 +0200 Subject: [PATCH 127/222] forgot to commit earlier --- .../src/UDPStandardImplementation.cpp | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 7692697215..de95765a26 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2067,9 +2067,9 @@ int UDPStandardImplementation::startWriting(){ //dont pop again if dummy packet else if(numpackets[i] == 0){ popready[i] = false; -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); -//#endif +#endif }else{ endofacquisition = false; if(numpackets[i] == 1040){ @@ -2093,9 +2093,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -//#endif +#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2122,15 +2122,15 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); -//#endif +#endif cout<<"tempoffset["<num3))); */ - tempoffset[i] ++; - blankoffset ++; + tempoffset[i]++; + blankoffset++; } //set fullframe and dont let fifo pop over it until written fullframe[i] = true; popready[i] = false; } } -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 else{ cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); continue; } -//#endif +#endif } @@ -2317,15 +2317,12 @@ int UDPStandardImplementation::startWriting(){ if(tempframenum[0] != tempframenum[1]) cprintf(RED,"Frame numbers mismatch!!! %d %d\n",tempframenum[0],tempframenum[1]); currframenum = tempframenum[0]; - /*//to resolve for missing frame packets - tempframenum[0]++; - tempframenum[1]++;*/ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -//#ifdef EIGER_DEBUG2 +#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -//#endif +#endif #ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); From 0a0dfb2dc6765e0a8c3931ec92b47bfd78fc2939 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 21 Aug 2015 14:11:38 +0200 Subject: [PATCH 128/222] fixed problem with increasing file descriptor when connecting to receiver --- slsReceiverSoftware/include/genericSocket.h | 40 ++++++++++--------- .../src/slsReceiverTCPIPInterface.cpp | 11 +++++ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index aa79f3233c..fe49df0d21 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -71,6 +71,7 @@ class sockaddr_in; #include + using namespace std; #define DEFAULT_PACKET_SIZE 1286 @@ -206,7 +207,6 @@ typedef struct socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp - if (socketDescriptor < 0) { cerr << "Can not create socket "<= 0){ \ close(socketDescriptor); \ } \ - file_des=-1; \ + if(is_a_server and getProtocol() == TCP){\ + if(file_des>0)\ + close(file_des);\ + } + file_des=-1; \ serverAddress.sin_port=-1; \ }; @@ -401,7 +405,6 @@ typedef struct cerr << "Can not create socket "<=0){ + close(socketDescriptor); + socketDescriptor = -1; + } + } + } + /** @short free connection */ void Disconnect(){ if (protocol==UDP){ @@ -429,18 +442,6 @@ typedef struct socketDescriptor=-1; } else{ - - /* close(socketDescriptor); - socketDescriptor=-1; - if(is_a_server){ - if(file_des>=0){ - close(file_des); - file_des=-1; - } - } -*/ - - if(file_des>=0){ //then was open if(is_a_server){ close(file_des); @@ -451,9 +452,6 @@ typedef struct } file_des=-1; } - - - } }; @@ -536,6 +534,9 @@ typedef struct } mac[sizeof(mac)-1]='\0'; + if(sock!=1){ + close(sock); + } return string(mac); }; @@ -557,6 +558,9 @@ typedef struct strncpy(addr,p,sizeof(addr)-1); addr[sizeof(addr)-1]='\0'; + if(sock!=1){ + close(sock); + } return string(addr); }; diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index dfa01e6e37..65dbd890ce 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -145,8 +145,18 @@ void slsReceiverTCPIPInterface::stop(){ cout<<"Shutting down TCP Socket and TCP thread"<shutDownUDPSockets(); + + cout << "Closing Files... " << endl; + receiverBase->closeFile(); + } + + killTCPServerThread = 1; socket->ShutDownSocket(); + socket->exitServer(); cout<<"Socket closed"<closeFile(); } + socket->exitServer(); pthread_exit(NULL); } From 41a4a9b611f45198f227d1158e69e1e11680d534 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 26 Aug 2015 10:28:39 +0200 Subject: [PATCH 129/222] some changes for 8 and 16 bit --- .../src/UDPStandardImplementation.cpp | 99 +++++++++++-------- 1 file changed, 59 insertions(+), 40 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 7b56daa046..b654be3315 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1987,8 +1987,8 @@ int UDPStandardImplementation::startWriting(){ //last packet numbers for different dynamic ranges if(myDetectorType == EIGER){ switch(dynamicRange){ - case 4: LAST_PACKET_VALUE = 0x40; break; - case 8: LAST_PACKET_VALUE = 0x80; break; + case 4: LAST_PACKET_VALUE = 0x3f; break; + case 8: LAST_PACKET_VALUE = 0x7f; break; case 16: LAST_PACKET_VALUE = 0xff; break; case 32: LAST_PACKET_VALUE = 0xff; break; default: break; @@ -2084,11 +2084,14 @@ int UDPStandardImplementation::startWriting(){ }else{ endofacquisition = false; if(numpackets[i] == 1040){ - /* cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); + cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - */}else if(numpackets[i] == EIGER_HEADER_LENGTH){ + }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); + }else { + cprintf(BG_RED, "got weird in writer, weirdd packetsize:%d\n",numpackets[i]); + } if(myDetectorType == EIGER){ @@ -2104,9 +2107,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif +//#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2133,15 +2136,15 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); -#endif - cout<<"tempoffset["<num3))); exit(-1); }else - /*cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); -*/ +//#ifdef PADDING + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); +//#endif tempoffset[i]++; blankoffset++; } @@ -2169,12 +2173,12 @@ int UDPStandardImplementation::startWriting(){ popready[i] = false; } } -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 else{ cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); continue; } -#endif +//#endif } @@ -2195,13 +2199,17 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave - if(tempframenum[i] != presentframenum){/*cout<<"wrong packet"<num1))), ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); -#endif +//#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2226,11 +2234,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else - /*cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", +//#ifdef PADDING + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (void*)(tempbuffer[tempoffset[i]]));*/ - + (void*)(tempbuffer[tempoffset[i]])); +//#endif tempoffset[i] ++; blankoffset ++; } @@ -2241,10 +2250,13 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame - else {/*cout<<"correct packet"<num4))); #ifdef VERYVERBOSE @@ -2273,10 +2285,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else - /* cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", +//#ifdef PADDING + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (void*)(tempbuffer[tempoffset[i]]));*/ + (void*)(tempbuffer[tempoffset[i]])); +//#endif tempoffset[i] ++; blankoffset ++; } @@ -2298,10 +2312,12 @@ int UDPStandardImplementation::startWriting(){ tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } - /*cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", +//#ifdef PADDING + cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (void*)(tempbuffer[tempoffset[i]]));*/ + (void*)(tempbuffer[tempoffset[i]])); +//#endif tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; @@ -2331,10 +2347,10 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -#ifdef EIGER_DEBUG2 +//#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif -#ifdef EIGER_DEBUG3 +//#endif +//#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2346,7 +2362,7 @@ int UDPStandardImplementation::startWriting(){ if ((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[j])))->num3))&0x2) cprintf(RED,"found the missing packet at pnum:%d\n",j); } -#endif +//#endif //write and copy to gui @@ -2366,9 +2382,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); #endif } -#ifdef VERYDEBUG +//#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -#endif +//#endif //reset a few stuff @@ -2388,11 +2404,13 @@ int UDPStandardImplementation::startWriting(){ } } - /* for(int i=0;inum1)))); cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - }*/ + } +//#endif } @@ -2955,11 +2973,12 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* cprintf(GREEN, "%d packet header:0x%016llx num3:0x%x\n",i, ((uint64_t)(*((uint64_t*)(wbuffer[i])))), (uint8_t)(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))); + + cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), + (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); } - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); #endif /* cprintf(GREEN,"at writing, fnum:%d, pnum:%d,num3:0x%x add:0x%x\n", From ed1dc77bb31178074fcfaf53d4370701557d31e5 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Fri, 28 Aug 2015 10:56:24 +0200 Subject: [PATCH 130/222] some changes to receiver defs --- .../include/dummyUDPInterface.h | 21 +++++++++++-- slsReceiverSoftware/include/receiver_defs.h | 16 +++++----- slsReceiverSoftware/src/dummyMain.cpp | 30 ++++++++++--------- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/slsReceiverSoftware/include/dummyUDPInterface.h b/slsReceiverSoftware/include/dummyUDPInterface.h index 479de45846..5cba675cc0 100644 --- a/slsReceiverSoftware/include/dummyUDPInterface.h +++ b/slsReceiverSoftware/include/dummyUDPInterface.h @@ -15,6 +15,7 @@ #include "UDPInterface.h" #include "sls_receiver_defs.h" +#include "genericSocket.h" class dummyUDPInterface : public UDPInterface { @@ -58,7 +59,12 @@ class dummyUDPInterface : public UDPInterface { /** * Destructor */ - dummyUDPInterface() : UDPInterface(), dynamicRange(16), scanTag(1000), nFrames(100), fWrite(1), fOverwrite(1), fIndex(0), fCaught(0), totfCaught(0), startAcqIndex(0), startFrameIndex(0), acqIndex(0), dataCompression(false), period(0), type(slsReceiverDefs::GENERIC), framesNeeded(100), udpPort1(1900), udpPort2(1901), shortFrame(0), nFramesToGui(0), e10G(0) {strcpy(detHostname,"none"); strcpy(fName,"run"); strcpy(fPath,"/scratch/"); strcpy(eth,"eth0"); cout << "New dummy UDP Interface" << endl;}; + dummyUDPInterface() : UDPInterface(), dynamicRange(16), scanTag(1000), nFrames(100), fWrite(1), fOverwrite(1), fIndex(0), fCaught(0), totfCaught(0), startAcqIndex(0), startFrameIndex(0), acqIndex(0), dataCompression(false), period(0), type(slsReceiverDefs::GENERIC), framesNeeded(100), udpPort1(1900), udpPort2(1901), shortFrame(0), nFramesToGui(0), e10G(0) {strcpy(detHostname,"none"); strcpy(fName,"run"); strcpy(fPath,"/scratch/"); strcpy(eth,"eth0"); cout << "New dummy UDP Interface" << endl; + + + + +}; ~dummyUDPInterface() {cout << "Destroying dummy UDP Interface" << endl;}; @@ -198,7 +204,18 @@ class dummyUDPInterface : public UDPInterface { /returns 0 on success or -1 on failure */ //FIXME: success == 0 or success == 1? - virtual int startReceiver(char *message=NULL) {cout << "dummy start receiver" << endl; return 0;}; + virtual int startReceiver(char *message=NULL) {cout << "dummy start receiver" << endl; + char buff[8225]; + buff[8224]='\0'; + int ip=0; + int ib; + genericSocket *udpSocket= new genericSocket(50004,genericSocket::UDP,8224); + while((ib=udpSocket->ReceiveDataOnly(buff,8224))>0) { + cout << "*** "<< ib <<" ************************** " << ip++ << endl; + cout << buff << endl; + cout << "*****************************" << endl << endl<< endl ; + } +return 0;}; /** * Stops Receiver - stops listening for packets diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 6f3b1acd35..f208d93c7c 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -70,14 +70,14 @@ #define JCTB_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 /*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ -#define JCTB_PACKETS_PER_FRAME 50 -#define JCTB_ONE_PACKET_SIZE 8214 -#define JCTB_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) -#define JCTB_DATA_BYTES (JCTB_BUFFER_PER_FRAME) - -#define JCTB_FRAME_INDEX_MASK 0xFFFFFF00 -#define JCTB_FRAME_INDEX_OFFSET 8 -#define JCTB_PACKET_INDEX_MASK 0xFF +#define JCTB_PACKETS_PER_FRAME 1 +#define JCTB_ONE_PACKET_SIZE 8224 +#define JCTB_BUFFER_SIZE (JCTB_ONE_PACKET_SIZE*40) +#define JCTB_DATA_BYTES (8192*JCTB_PACKETS_PER_FRAME) + +#define JCTB_FRAME_INDEX_MASK 0xFFFFFFFF +#define JCTB_FRAME_INDEX_OFFSET 6+8 +#define JCTB_PACKET_INDEX_MASK 0xFFFFFFFF #define JCTB_BYTES_PER_ADC (2) #define JCTB_PIXELS_IN_ONE_ROW 32 diff --git a/slsReceiverSoftware/src/dummyMain.cpp b/slsReceiverSoftware/src/dummyMain.cpp index 41494fd99f..3f4e9bb2d3 100644 --- a/slsReceiverSoftware/src/dummyMain.cpp +++ b/slsReceiverSoftware/src/dummyMain.cpp @@ -18,24 +18,26 @@ int main(int argc, char *argv[]) { bool bottom = false; cout << "CCCCCC" << endl; dummyUDPInterface *udp=new dummyUDPInterface(); - slsReceiverTCPIPInterface *tcpipInterface = new slsReceiverTCPIPInterface(success, udp, tcpip_port_no, bottom); +// slsReceiverTCPIPInterface *tcpipInterface = new slsReceiverTCPIPInterface(success, udp, tcpip_port_no, bottom); - if(tcpipInterface->start() == slsReceiverDefs::OK){ - cout << "DONE!" << endl; - string str; - cin>>str; - //wait and look for an exit keyword - while(str.find("exit") == string::npos) - cin>>str; - //stop tcp server thread, stop udp socket - tcpipInterface->stop(); - } - - if (tcpipInterface) - delete tcpipInterface; +// if(tcpipInterface->start() == slsReceiverDefs::OK){ +// cout << "DONE!" << endl; +// string str; +// cin>>str; +// //wait and look for an exit keyword +// while(str.find("exit") == string::npos) +// cin>>str; +// //stop tcp server thread, stop udp socket +// tcpipInterface->stop(); +// } + +// if (tcpipInterface) +// delete tcpipInterface; + + udp->startReceiver(); if(udp) delete udp; return 0; From 74366b3cfe326684a88dce83f3df813153838878 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 3 Sep 2015 12:00:37 +0200 Subject: [PATCH 131/222] halfway into new server --- .../include/UDPBaseImplementation.h | 33 +-- .../include/UDPStandardImplementation.h | 2 - .../src/UDPBaseImplementation.cpp | 91 ------- .../src/UDPStandardImplementation.cpp | 225 +++++++----------- .../src/slsReceiverTCPIPInterface.cpp | 1 - 5 files changed, 105 insertions(+), 247 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 38adefe902..3dd655f541 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -483,25 +483,25 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter //// Could be done more fine-grained... TODO // private: protected: - /** structure of an eiger image header*/ + /** structure of an eiger packet*/ typedef struct { - unsigned char header_before1[5]; - unsigned char header_confirm[1]; - unsigned char header_before2[14]; - //unsigned char header_before[20]; - unsigned char fnum[4]; - unsigned char header_after[24]; - } eiger_image_header; + unsigned char subframenum[4]; + unsigned char missingpacket[2]; + unsigned char portnum[1]; + unsigned char dynamicrange[1]; + } eiger_packet_header_t; - /** structure of an eiger image header*/ typedef struct { - unsigned char num1[4]; - unsigned char num2[2]; - unsigned char num3[1]; - unsigned char num4[1]; - } eiger_packet_header; + unsigned char framenum[6]; + unsigned char packetnum[2]; + } eiger_packet_footer_t; + + eiger_packet_header_t* eiger_packet_header; + unsigned char* eiger_packet_data; + eiger_packet_footer_t* eiger_packet_footer; + /** max number of listening threads */ const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; @@ -626,9 +626,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ int bufferSize; - /** oen buffer size */ + /** one buffer size */ int onePacketSize; + /** one buffer size */ + int oneDataSize; + /** latest data */ char* latestData; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 67443f21c1..92092bead2 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -485,8 +485,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); - - public: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 40152f5816..c59932b9d8 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1561,97 +1561,6 @@ int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " sta while((1<pop(wbuf[i]); - numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; -#endif - } - -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -#endif - - - //last dummy packet - if(numpackets == 0xFFFF){ - stopWriting(ithread,wbuf); - continue; - } - - - - - //for progress - if(myDetectorType == EIGER){ - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - pthread_mutex_lock(&progress_mutex); - if(tempframenum > currframenum) - currframenum = tempframenum; - pthread_mutex_unlock(&progress_mutex); - } -//#ifdef VERYDEBUG - if(myDetectorType == EIGER) - cout << endl < 0){ - for(i=0;ipush(wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; -#endif - } - - - } - else{ - //copy to gui - copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; -#endif - while(!fifoFree[0]->push(wbuf[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]< #include - +#include using namespace std; @@ -39,7 +39,6 @@ UDPStandardImplementation::UDPStandardImplementation() //guiFrameNumber(0), //tengigaEnable(0) { - thread_started = 0; eth = NULL; latestData = NULL; @@ -141,6 +140,7 @@ void UDPStandardImplementation::initializeMembers(){ frameSize = 0; bufferSize = 0; onePacketSize = 0; + oneDataSize = 0; guiDataReady = 0; nFrameToGui = 0; fifosize = 0; @@ -200,6 +200,7 @@ void UDPStandardImplementation::initializeMembers(){ //strcpy(fileName,"run"); + //status pthread_mutex_lock(&status_mutex); status = IDLE; @@ -246,6 +247,7 @@ void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG) << __AT__ < if(fifo[i]) {delete fifo[i]; fifo[i] = NULL;} if(fifoFree[i]) {delete fifoFree[i]; fifoFree[i] = NULL;} } + } @@ -323,6 +325,7 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD fifosize = EIGER_FIFO_SIZE; packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; frameSize = onePacketSize * packetsPerFrame; bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; @@ -337,6 +340,8 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD createListeningThreads(true); numListeningThreads = MAX_NUM_LISTENING_THREADS; + + } else if(myDetectorType == JUNGFRAUCTB || myDetectorType == JUNGFRAU ){ fifosize = JCTB_FIFO_SIZE; packetsPerFrame = JCTB_PACKETS_PER_FRAME; @@ -1004,13 +1009,6 @@ cout << "copyframe" << endl; for(int j=0;jReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - /*cprintf(MAGENTA,"%d got a header*****************************\n",ithread); - cprintf(MAGENTA,"tempframenum[%d]:%d\n",ithread,(htonl(*(uint32_t*)(((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum)))); - */} + } } - /* if(rc == 1040){ - cprintf(CYAN,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(CYAN,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - cprintf(CYAN,"add[%d]:0x%x\n",ithread,(void*)(buffer[ithread])); - }*/ expected = maxBufferSize; #ifdef SOCKET_DEBUG }else{ @@ -1908,9 +1899,6 @@ int UDPStandardImplementation::startListening(){ cprintf(BLUE,"%d listener going to push fifo: 0x%x\n", ithread,(void*)(buffer[ithread])); #endif while(!fifo[ithread]->push(buffer[ithread])); - /*cprintf(YELLOW,"tempframenum[%d]:%d\n",ithread,((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(YELLOW,"packetnum[%d]:%d\n",ithread,((*(uint8_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); - cprintf(YELLOW,"add[%d]:0x%x\n",ithread,(void*)(buffer[ithread]));*/ #ifdef FIFO_DEBUG cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); #endif @@ -2019,15 +2007,24 @@ int UDPStandardImplementation::startWriting(){ //blank frame if(myDetectorType == EIGER){ + for(i=0;inum3)) = 0xFF; - for(j=0;j<(onePacketSize-16);++j) - (*((uint8_t*)((char*)(blankframe[i])+8+j))) = 0xFF; - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) != 0xFF){ - cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[i])))->num3)) ); + //blank frame for each packet + blankframe[i] = new char[onePacketSize]; + eiger_packet_header = (eiger_packet_header_t*) blankframe[i]; + //set missing packet to 0xff + *( (uint16_t*) eiger_packet_header->missingpacket) = 0xFF; + + //set each value inside blank frame to 0xff + for(j=0;j<(oneDataSize);++j){ + eiger_packet_data = blankframe[i] + sizeof(eiger_packet_header_t) + j; + *(eiger_packet_data) = 0xFF; + } + //verify + if (*( (uint16_t*) eiger_packet_header->missingpacket) != 0xFF){ + cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,*( (uint16_t*) eiger_packet_header->missingpacket) ); exit(-1); } #ifdef FIFO_DEBUG @@ -2084,8 +2081,8 @@ int UDPStandardImplementation::startWriting(){ }else{ endofacquisition = false; if(numpackets[i] == 1040){ - cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1)))); - cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum)))); + cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); @@ -2151,19 +2148,19 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3))&0x2) + if (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)) cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); #endif - if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ - cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x\n", + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ + cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3))); + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket))); exit(-1); }else //#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))); + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))); //#endif tempoffset[i]++; blankoffset++; @@ -2189,8 +2186,7 @@ int UDPStandardImplementation::startWriting(){ if(!fullframe[i]){ //update frame number - //tempframenum[i] = (htonl(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); - tempframenum[i] = ((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + tempframenum[i] = ((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))); if(!tempframenum[i]) @@ -2207,8 +2203,8 @@ int UDPStandardImplementation::startWriting(){ //#ifdef EIGER_DEBUG3 cprintf(RED,"fifo:%d packet from next frame %d, add missing packets to the right one %d\n",i,tempframenum[i],presentframenum ); cprintf(RED,"current wrong frame:%d wrong frame packet number:%d\n", - ((*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))), - ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + ((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))), + ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); //#endif tempframenum[i] = presentframenum; //add missing packets @@ -2221,23 +2217,23 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3))&0x2) + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))== 0xFF) cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif - if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x add:0x%x\n", + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else //#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); //#endif tempoffset[i] ++; @@ -2258,7 +2254,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"**tempfraemnum of %d: %d\n",i,tempframenum[i]); //#endif //update current packet - currentpacketheader[i] = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4))); + currentpacketheader[i] = ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum))); #ifdef VERYVERBOSE cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); #endif @@ -2272,23 +2268,23 @@ int UDPStandardImplementation::startWriting(){ for(j=0;jnum3))&0x2) + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)) ==0xFF) cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); #endif - if (!((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3))&0x2)){ + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ cprintf(BG_RED, "correct blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d num3:0x%x actual num3:0x%x add:0x%x\n", + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(blankframe[blankoffset])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else //#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); //#endif tempoffset[i] ++; @@ -2299,23 +2295,23 @@ int UDPStandardImplementation::startWriting(){ if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", i,tempoffset[i],currentpacketheader[i], - tempframenum[i],(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuf[i]+ HEADER_SIZE_NUM_TOT_PACKETS)))->num1))); + tempframenum[i],(*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i]+ HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))); exit(-1); } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; #ifdef EIGER_DEBUG3 - cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)),tempoffset[i]); + cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)),tempoffset[i]); #endif - if((*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ + if((*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d add:0x%x\n", - i,(*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num4)), + i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } //#ifdef PADDING - cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d num3:0x%x add:0x%x\n", + cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_header *)((char*)(tempbuffer[tempoffset[i]])))->num3)), + (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), (void*)(tempbuffer[tempoffset[i]])); //#endif tempoffset[i] ++; @@ -2359,7 +2355,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); for (j=0;jnum3))&0x2) + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[j])))->missingpacket))==0xFF) cprintf(RED,"found the missing packet at pnum:%d\n",j); } //#endif @@ -2407,8 +2403,8 @@ int UDPStandardImplementation::startWriting(){ //#ifdef VERYDEBUG for(int i=0;inum1)))); - cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->num4)))); + cprintf(GREEN,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum)))); + cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); } //#endif } @@ -2735,53 +2731,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n if((enableFileWrite) && (sfilefd)){ offset = HEADER_SIZE_NUM_TOT_PACKETS; - if(myDetectorType == EIGER){ -#ifdef WRITE_HEADERS -#ifdef VERY_DEBUG - if(myDetectorType == EIGER){ - int k = 0; - if(dynamicRange != 32){ - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); - k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); - k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k,(*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num4))); - }else{ - k = 0; - cprintf(RED, "\np1 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p1:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p0 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 1; - cprintf(RED, "p2 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p2:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p1 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 2; - cprintf(RED, "p3 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p3:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p2 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 256; - cprintf(RED, "p257 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p257:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p256 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 512; - cprintf(RED, "p513 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p513:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p512 num:%d - %d\n", k, (*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - k = 768; - cprintf(RED, "p769 fnum:0x%x\n", (*(unsigned int*)(((eiger_packet_header *)((char*)(buf[k])))->num1))); - cprintf(RED, "p769:0x%x\n", (*(uint8_t*)(((eiger_packet_header *)((char*)(buf[k])))->num3))); - cprintf(RED, "p768 num:%d - %d\n", k,(*(uint16_t*)(((eiger_packet_header *)((char*)(buf[k])))->num2))); - } - } -#endif -#endif - } + while(numpackets > 0){ //for progress and packet loss calculation(new files) @@ -2913,29 +2863,29 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //missing packet - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))&0x2){ + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))==0xFF){ missingpacket = 1; //add packet numbers - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = (i+1); - (*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum+1; + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = (i+1); + (*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->framenum)) = currframenum+1; }else{ missingpacket = 0; - if((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)) != (i-(port*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)),currframenum); + if((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) != (i-(port*packetsPerFrame/numListeningThreads))){ + cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)),currframenum); exit(-1); } - if(dynamicRange != 32){ + /* if(dynamicRange != 32){*/ //move packet numbers to num2, and compensate for port1 starting pnum from 0 if(!port) - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = - ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+1); + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = + ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))+1); else - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) = - ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+(packetsPerFrame/2) +1); - } + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = + ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))+(packetsPerFrame/2) +1); + /*} //dr == 32 else{ if(i == 0) @@ -2946,43 +2896,42 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* pnuminc = (packetsPerFrame/2); else if(i == (3*packetsPerFrame/4)) pnuminc = (3*packetsPerFrame/4); - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) - = ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4))+pnuminc+1); + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) + = ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum,))+pnuminc+1); - } + }*/ } - if((*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)) != (i+1)){ - cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2)),currframenum); - if ((*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))&0x2) + if((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) != (i+1)){ + cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)),currframenum); + if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))==0xFF) cprintf(BG_RED,"missing packet though\n"); exit(-1); } //overwriting port number and dynamic range - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)) = + (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)) = ((dynamicRange<<2)|(missingpacket<<1)|(port)); //frame number - //(*(uint32_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num1)) = currframenum; + //(*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->framenum)) = currframenum; #ifdef VERYDEBUG if((i==0)||(i==1)){ - cprintf(GREEN, "%d packet header:0x%016llx num3:0x%x\n",i, + cprintf(GREEN, "%d packet header:0x%016llx missingpacket:0x%x\n",i, ((uint64_t)(*((uint64_t*)(wbuffer[i])))), - (uint8_t)(*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3))); + (uint8_t)(*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))); - cprintf(GREEN, "%d - 0x%x - %d - %d\n", i, - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), - (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num4)), - (*(uint16_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num2))); + cprintf(GREEN, "%d - 0x%x - %d\n", i, + (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)), + (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))); } #endif /* - cprintf(GREEN,"at writing, fnum:%d, pnum:%d,num3:0x%x add:0x%x\n", - currframenum, i, (*(uint8_t*)(((eiger_packet_header *)((char*)(wbuffer[i])))->num3)), + cprintf(GREEN,"at writing, fnum:%d, pnum:%d,missingpacket:0x%x add:0x%x\n", + currframenum, i, (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)), (void*)(wbuffer[i])); */ @@ -3148,9 +3097,11 @@ int UDPStandardImplementation::enableTenGiga(int enable){ if(!tengigaEnable){ packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; + oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; }else{ packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; + oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE; } frameSize = onePacketSize * packetsPerFrame; bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) @@ -3202,5 +3153,3 @@ int UDPStandardImplementation::enableTenGiga(int enable){ return tengigaEnable; } - - diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 3d16a3c4fa..ea0336895c 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1570,7 +1570,6 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ char fName[MAX_STR_LENGTH]=""; int acquisitionIndex = -1; int frameIndex= -1; - int i; uint32_t index=0; int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame; From 04578f7c69217b9d4d159732554acf17775f19fe Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 3 Sep 2015 15:17:31 +0200 Subject: [PATCH 132/222] added subframe exposure time settable --- slsReceiverSoftware/include/sls_receiver_defs.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 6abb308870..49cc8fb644 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -92,7 +92,9 @@ class slsReceiverDefs { MEASUREMENTS_NUMBER, FRAMES_FROM_START, FRAMES_FROM_START_PG, - SAMPLES_JCTB + SAMPLES_JCTB, + SUBFRAME_ACQUISITION_TIME, /**< subframe exposure time */ + MAX_TIMERS }; From 572b6fe29f9422bbd46ecab4bd37c6539f216520 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 10 Sep 2015 14:05:10 +0200 Subject: [PATCH 133/222] f --- slsReceiverSoftware/include/UDPBaseImplementation.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 3dd655f541..d68f1c6d43 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -498,10 +498,6 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter unsigned char packetnum[2]; } eiger_packet_footer_t; - eiger_packet_header_t* eiger_packet_header; - unsigned char* eiger_packet_data; - eiger_packet_footer_t* eiger_packet_footer; - /** max number of listening threads */ const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; From fe76ce96504d31f03ba89c5b9465ffdd338c65c6 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 15 Sep 2015 15:31:29 +0200 Subject: [PATCH 134/222] seems to run fine, only 16gb checked for fimware v 10 and software version v1.10.2 --- .../include/UDPBaseImplementation.h | 6 + slsReceiverSoftware/include/receiver_defs.h | 3 +- .../src/UDPBaseImplementation.cpp | 190 ----------- .../src/UDPStandardImplementation.cpp | 311 +++++++++--------- 4 files changed, 170 insertions(+), 340 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index d68f1c6d43..d69e00b932 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -505,6 +505,9 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** max number of writer threads */ const static int MAX_NUM_WRITER_THREADS = 15; + /** missing packet identifier value */ + const static uint16_t missingPacketValue = 0xFFFF; + /** detector type */ detectorType myDetectorType; @@ -712,6 +715,9 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** 10Gbe enable*/ int tengigaEnable; + /** footer offset is different for 1g and 10g*/ + int footer_offset; + // TODO: not properly sure where to put these... /** structure of an eiger image header*/ diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 701b4e3826..206c8b92b4 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -118,10 +118,11 @@ #define EIGER_ONE_GIGA_ONE_DATA_SIZE 1024 #define EIGER_TEN_GIGA_ONE_PACKET_SIZE 4112 #define EIGER_TEN_GIGA_ONE_DATA_SIZE 4096 +#define EIGER_PACKET_HEADER_SIZE 8 //#define EIGER_BUFFER_SIZE_CONSTANT (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT)//1040*16*2//*bit mode //#define EIGER_DATA_BYTES_CONSTANT (EIGER_ONE_DATA_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT) //1024*16*2//*bit mode -#define EIGER_FRAME_INDEX_MASK 0xFFFF +#define EIGER_FRAME_INDEX_MASK 0xFFFFFFFF //32 bit for now #define EIGER_FRAME_INDEX_OFFSET 0 #define EIGER_PACKET_INDEX_MASK 0x0 diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index c59932b9d8..fb10ae1066 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -558,83 +558,6 @@ void UDPBaseImplementation::setupFilter(){ FILE_LOG(logDEBUG) << __AT__ << " sta //LEO: it is not clear to me.. void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int64_t i; - int oldn = numJobsPerThread; - - //if every nth frame mode - if(nFrameToGui) - numJobsPerThread = nFrameToGui; - - //random nth frame mode - else{ - if(!acquisitionPeriod) - i = SAMPLE_TIME_IN_NS; - else - i = SAMPLE_TIME_IN_NS/acquisitionPeriod; - if (i > MAX_JOBS_PER_THREAD) - numJobsPerThread = MAX_JOBS_PER_THREAD; - else if (i < 1) - numJobsPerThread = 1; - else - numJobsPerThread = i; - } - - //if same, return - if(oldn == numJobsPerThread) - return; - - if(myDetectorType == EIGER) - numJobsPerThread = 1; - - //otherwise memory too much if numjobsperthread is at max = 1000 - fifosize = GOTTHARD_FIFO_SIZE; - if(myDetectorType == MOENCH) - fifosize = MOENCH_FIFO_SIZE; - else if(myDetectorType == EIGER) - fifosize = EIGER_FIFO_SIZE; - - if(fifosize % numJobsPerThread) - fifosize = (fifosize/numJobsPerThread)+1; - else - fifosize = fifosize/numJobsPerThread; - - - cout << "Number of Frames per buffer:" << numJobsPerThread << endl; - cout << "Fifo Size:" << fifosize << endl; - - /* - //for testing - numJobsPerThread = 3; fifosize = 11; - */ - - for(int i=0;iisEmpty()) - fifoFree[i]->pop(buffer[i]); - delete fifoFree[i]; - } - if(fifo[i]) delete fifo[i]; - if(mem0[i]) free(mem0[i]); - fifoFree[i] = new CircularFifo(fifosize); - fifo[i] = new CircularFifo(fifosize); - - - //allocate memory - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - /** shud let the client know about this */ - if (mem0[i]==NULL){ - cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); - exit(-1); - } - buffer[i]=mem0[i]; - //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); - } - } - cout << "Fifo structure(s) reconstructed" << endl; } @@ -1529,93 +1452,6 @@ int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " sta cout << ithread << "In startWriting()" <fnum); - //gotthard has +1 for frame number and not a short frame - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset); - else - startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) - & (frameIndexMask)) >> frameIndexOffset); - - - //start of acquisition - if(!acqStarted){ - startAcquisitionIndex=startFrameIndex; - currframenum = startAcquisitionIndex; - acqStarted = true; - cout << "startAcquisitionIndex:" << startAcquisitionIndex<missingpacket) = 0xFF; + *( (uint16_t*) blankframe_header->missingpacket) = missingPacketValue; //set each value inside blank frame to 0xff for(j=0;j<(oneDataSize);++j){ - eiger_packet_data = blankframe[i] + sizeof(eiger_packet_header_t) + j; - *(eiger_packet_data) = 0xFF; + blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; + *(blankframe_data) = 0xFF; } //verify - if (*( (uint16_t*) eiger_packet_header->missingpacket) != 0xFF){ - cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,*( (uint16_t*) eiger_packet_header->missingpacket) ); + if (*( (uint16_t*) blankframe_header->missingpacket) != missingPacketValue){ + cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,*( (uint16_t*) blankframe_header->missingpacket) ); exit(-1); } #ifdef FIFO_DEBUG @@ -2041,8 +2057,8 @@ int UDPStandardImplementation::startWriting(){ tempoffset[i] = (i*packetsPerFrame/numListeningThreads); tofreeoffset[i] = (i*packetsPerFrame/numListeningThreads); blankoffset = 0; - lastpacketheader[i] = -1; - currentpacketheader[i] = -1; + lastpacketheader[i] = 0; + currentpacketheader[i] = 0; numberofmissingpackets[i] = 0; numpackets[i] = 0; @@ -2065,6 +2081,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer poped 0x%x from fifo %d\n", ithread, (void*)(wbuf[i]), i); #endif numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); + #ifdef VERYDEBUG cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); #endif @@ -2080,17 +2097,22 @@ int UDPStandardImplementation::startWriting(){ #endif }else{ endofacquisition = false; - if(numpackets[i] == 1040){ - cprintf(BLUE,"tempframenum[%d]:%d\n",i,((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum)))); - cprintf(BLUE,"packetnum[%d]:%d\n",i,((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); + if(numpackets[i] == 1040){; +#ifdef EIGER_DEBUG3 + wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); + //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BLUE,"tempframenum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BLUE,"packetnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetnum)); +#endif }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); - }else { + } +//#ifdef EIGER_DEBUG3 + else { cprintf(BG_RED, "got weird in writer, weirdd packetsize:%d\n",numpackets[i]); - } - +//#endif if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; @@ -2104,9 +2126,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -//#ifdef VERYDEBUG +#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Both dummy frames\n", ithread); -//#endif +#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2121,6 +2143,8 @@ int UDPStandardImplementation::startWriting(){ if(myDetectorType == EIGER){ + + //NOT FULL FRAME if(!fullframe[0] || !fullframe[1]){ for(i=0;imissingpacket)) - cprintf(RED,"1 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "1 fifo:%d Weird at pnum:%d\n",i,tempoffset[i]); -#endif - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ - cprintf(BG_RED, "dummy blank mismatch num4 earlier2! i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x\n", + + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; + blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + if (*( (uint16_t*) tempframe_header->missingpacket)!= missingPacketValue){ + cprintf(BG_RED, "dummy blank mismatch num4 earlier2! " + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), - (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket))); + *( (uint16_t*) tempframe_header->missingpacket), + *( (uint16_t*) blankframe_header->missingpacket)); exit(-1); }else -//#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i,tempoffset[i],tempframenum[i],(*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))); -//#endif +#ifdef PADDING + cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i, + tempoffset[i],tempframenum[i],*( (uint16_t*) tempframe_header->missingpacket)); +#endif tempoffset[i]++; blankoffset++; } @@ -2184,9 +2208,12 @@ int UDPStandardImplementation::startWriting(){ //not a full frame if(!fullframe[i]){ - + wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef EIGER_DEBUG3 + cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); +#endif //update frame number - tempframenum[i] = ((*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))); + tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); if(!tempframenum[i]) @@ -2196,16 +2223,18 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave if(tempframenum[i] != presentframenum){ -//#ifdef PADDING +#ifdef PADDING cout<<"wrong packet"<framenum))), - ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); -//#endif + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_footer->packetnum)); + +#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2216,26 +2245,24 @@ int UDPStandardImplementation::startWriting(){ //to decrement from packetsInFile to calculate packet loss for(j=0;jmissingpacket))== 0xFF) - cprintf(RED,"5 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "5 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); -#endif - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ + + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; + blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + if (*( (uint16_t*) tempframe_header->missingpacket)!= missingPacketValue){ cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), - (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket)), + *( (uint16_t*) tempframe_header->missingpacket), + *( (uint16_t*) blankframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; blankoffset ++; } @@ -2247,73 +2274,75 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame else { -//#ifdef PADDING +#ifdef PADDING cout<<"correct packet"<packetnum))); + currentpacketheader[i] = *( (uint16_t*) wbuf_footer->packetnum); #ifdef VERYVERBOSE - cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n",i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); + cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n", + i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); #endif //add missing packets numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); #ifdef VERYDEBUG if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n",i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); + cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n", + i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); #endif //to decrement from packetsInFile to calculate packet loss for(j=0;jmissingpacket)) ==0xFF) - cprintf(RED,"4 fifo:%d missing packet added at pnum:%d\n",i,tempoffset[i]); - else cprintf(RED, "4 fifo:%d WEird at pnum:%d\n",i,tempoffset[i]); -#endif - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket))!= 0xFF){ + + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; + blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + if (*( (uint16_t*) tempframe_header->missingpacket)!= missingPacketValue){ cprintf(BG_RED, "correct blank mismatch num4 earlier2! " "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), - (*(uint8_t*)(((eiger_packet_1g *)((char*)(blankframe[blankoffset])))->missingpacket)), + *( (uint16_t*) tempframe_header->missingpacket), + *( (uint16_t*) blankframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; blankoffset ++; } //add current packet - - if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ + if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", i,tempoffset[i],currentpacketheader[i], - tempframenum[i],(*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuf[i]+ HEADER_SIZE_NUM_TOT_PACKETS)))->framenum))); + tempframenum[i],(uint32_t)(*( (uint64_t*) wbuf_footer))); exit(-1); } + tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; + tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); #ifdef EIGER_DEBUG3 - cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)),tempoffset[i]); + cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n", + i,*( (uint16_t*) tempframe_footer->packetnum),tempoffset[i]); #endif - if((*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)) != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d fnum:%d add:0x%x\n", - i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->packetnum)), + if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ + cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%x\n", + i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - (*(uint8_t*)(((eiger_packet_1g *)((char*)(tempbuffer[tempoffset[i]])))->missingpacket)), + *( (uint16_t*) tempframe_footer->packetnum), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; @@ -2343,10 +2372,10 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -//#ifdef EIGER_DEBUG2 +#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -//#endif -//#ifdef EIGER_DEBUG3 +#endif +#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2354,11 +2383,13 @@ int UDPStandardImplementation::startWriting(){ if(numMissingPackets){ cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); - for (j=0;jmissingpacket))==0xFF) + for (j=0;jmissingpacket)==missingPacketValue) cprintf(RED,"found the missing packet at pnum:%d\n",j); + } } -//#endif +#endif //write and copy to gui @@ -2378,9 +2409,9 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); #endif } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG cprintf(GREEN,"finished freeing\n"); -//#endif +#endif //reset a few stuff @@ -2394,19 +2425,20 @@ int UDPStandardImplementation::startWriting(){ tempoffset[i] = (i*packetsPerFrame/numListeningThreads); tofreeoffset[i] = (i*packetsPerFrame/numListeningThreads); blankoffset = 0; - lastpacketheader[i] = -1; - currentpacketheader[i] = -1; + lastpacketheader[i] = 0; + currentpacketheader[i] = 0; numberofmissingpackets[i] = 0; } } -//#ifdef VERYDEBUG +#ifdef VERYDEBUG for(int i=0;iframenum)))); - cprintf(GREEN,"packetnum[%d]:%d\n",i,((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS)))->packetnum)))); + cprintf(GREEN,"tempframenum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + cprintf(GREEN,"packetnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetnum)); } -//#endif +#endif } @@ -2838,8 +2870,6 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* int i,j, missingpacket,port = 0, pnuminc; - - if (cbAction < DO_EVERYTHING){ if (myDetectorType == EIGER){ for(i=0;ipacketnum)); +#endif //which port if (i ==(packetsPerFrame/2)) port = 1; @@ -2863,77 +2902,51 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //missing packet - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))==0xFF){ + if (*( (uint16_t*) wbuf_header->missingpacket)== missingPacketValue){ +#ifdef VERY_VERBOSE + cprintf(GREEN,"missing packet at %d\n", i+1); +#endif missingpacket = 1; - //add packet numbers - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = (i+1); - (*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->framenum)) = currframenum+1; + //add frame and packet numbers + *( (uint64_t*) wbuf_footer) = (uint64_t)((currframenum+1)); + *( (uint16_t*) wbuf_footer->packetnum) = (i+1); }else{ missingpacket = 0; - if((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) != (i-(port*packetsPerFrame/numListeningThreads))){ - cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)),currframenum); + if(*( (uint16_t*) wbuf_footer->packetnum)!= (i-(port*packetsPerFrame/numListeningThreads))+1){ + cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n", + i,*( (uint16_t*) wbuf_footer->packetnum),currframenum); exit(-1); } - - /* if(dynamicRange != 32){*/ //move packet numbers to num2, and compensate for port1 starting pnum from 0 - if(!port) - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = - ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))+1); - else - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) = - ((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))+(packetsPerFrame/2) +1); - /*} - //dr == 32 - else{ - if(i == 0) - pnuminc = 0; - else if(i == (packetsPerFrame/4)) - pnuminc = (packetsPerFrame/4); - else if(i == (packetsPerFrame/2)) - pnuminc = (packetsPerFrame/2); - else if(i == (3*packetsPerFrame/4)) - pnuminc = (3*packetsPerFrame/4); - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) - = ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum,))+pnuminc+1); - - }*/ + if(port) + *( (uint16_t*) wbuf_footer->packetnum) = (*( (uint16_t*) wbuf_footer->packetnum))+(packetsPerFrame/2); } - - if((*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)) != (i+1)){ - cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n",i,(*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum)),currframenum); - if ((*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))==0xFF) + if(*( (uint16_t*) wbuf_footer->packetnum) != (i+1)){ + cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n", + i,*( (uint16_t*) wbuf_footer->packetnum),currframenum); + if (*( (uint16_t*) wbuf_header->missingpacket) == missingPacketValue) cprintf(BG_RED,"missing packet though\n"); exit(-1); } //overwriting port number and dynamic range - (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)) = - ((dynamicRange<<2)|(missingpacket<<1)|(port)); + *( (uint8_t*) wbuf_header->portnum) = port; + *( (uint8_t*) wbuf_header->dynamicrange) = dynamicRange; - //frame number - //(*(uint32_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->framenum)) = currframenum; #ifdef VERYDEBUG if((i==0)||(i==1)){ cprintf(GREEN, "%d packet header:0x%016llx missingpacket:0x%x\n",i, - ((uint64_t)(*((uint64_t*)(wbuffer[i])))), - (uint8_t)(*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket))); + (uint64_t)()*( (uint64_t*) wbuf_header)), *( (uint16_t*) wbuf_header->missingpacket)); cprintf(GREEN, "%d - 0x%x - %d\n", i, - (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)), - (*(uint16_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->packetnum))); + *( (uint16_t*) wbuf_header->missingpacket), *( (uint16_t*) wbuf_footer->packetnum)); } #endif -/* - cprintf(GREEN,"at writing, fnum:%d, pnum:%d,missingpacket:0x%x add:0x%x\n", - currframenum, i, (*(uint8_t*)(((eiger_packet_1g *)((char*)(wbuffer[i])))->missingpacket)), - (void*)(wbuffer[i])); -*/ } } From 5368103efa36c625ea36b81a6af41389bb07dc46 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 15 Sep 2015 15:40:54 +0200 Subject: [PATCH 135/222] 10g gui bottom offset bug fix --- slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 65dbd890ce..aa799d380e 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1629,11 +1629,12 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ 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 = 1040*(16*dynamicrange)*2; + 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){ From c7017eef5b720f67723c00cfa6308f19a88b35d5 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 15 Sep 2015 15:41:58 +0200 Subject: [PATCH 136/222] 10g gui bottom offset bug fix --- slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index ea0336895c..17ff75764e 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1630,11 +1630,12 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ 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 = 1040*(16*dynamicrange)*2; + 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){ From 1b471bc6759d6e9c49a32e627dbf843d7b5a7ee6 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 17 Sep 2015 09:14:00 +0200 Subject: [PATCH 137/222] partial_frames for 10g bug fixed specifzing literal 1024 for allowed packet size in startwritign --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index d55a1f1fcd..8c68403b69 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1962,7 +1962,7 @@ int UDPStandardImplementation::startWriting(){ uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; - int MAX_VALUE = 1024; + int MAX_VALUE = 1024;//32 bit number of packets char* tofree[MAX_VALUE]; char* tempbuffer[MAX_VALUE]; char* blankframe[MAX_VALUE]; @@ -2097,7 +2097,7 @@ int UDPStandardImplementation::startWriting(){ #endif }else{ endofacquisition = false; - if(numpackets[i] == 1040){; + if(numpackets[i] == bufferSize){; #ifdef EIGER_DEBUG3 wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); From b3012acea2a1e26d23ae9a32cc0833f844fbc907 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 17 Sep 2015 12:03:11 +0200 Subject: [PATCH 138/222] bug fixxed for 10g writing filter, still debug mode --- .../src/UDPStandardImplementation.cpp | 81 ++++++++++--------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 8c68403b69..10ed494638 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2092,18 +2092,18 @@ int UDPStandardImplementation::startWriting(){ //dont pop again if dummy packet else if(numpackets[i] == 0){ popready[i] = false; -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); -#endif +//#endif }else{ endofacquisition = false; - if(numpackets[i] == bufferSize){; -#ifdef EIGER_DEBUG3 + if(numpackets[i] == onePacketSize){; +//#ifdef EIGER_DEBUG3 wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"tempframenum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"packetnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetnum)); -#endif +//#endif }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); @@ -2126,9 +2126,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif +//#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2157,15 +2157,15 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); -#endif +//#endif cout<<"tempoffset["<missingpacket)); exit(-1); }else -#ifdef PADDING +//#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i, tempoffset[i],tempframenum[i],*( (uint16_t*) tempframe_header->missingpacket)); -#endif +//#endif tempoffset[i]++; blankoffset++; } @@ -2209,9 +2209,9 @@ int UDPStandardImplementation::startWriting(){ //not a full frame if(!fullframe[i]){ wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); -#endif +//#endif //update frame number tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); @@ -2223,18 +2223,18 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave if(tempframenum[i] != presentframenum){ -#ifdef PADDING +//#ifdef PADDING cout<<"wrong packet"<packetnum)); -#endif +//#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2257,12 +2257,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -#ifdef PADDING +//#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -#endif +//#endif tempoffset[i] ++; blankoffset ++; } @@ -2274,12 +2274,12 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame else { -#ifdef PADDING +//#ifdef PADDING cout<<"correct packet"<packetnum); #ifdef VERYVERBOSE @@ -2308,12 +2308,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -#ifdef PADDING +//#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -#endif +//#endif tempoffset[i] ++; blankoffset ++; } @@ -2326,32 +2326,33 @@ int UDPStandardImplementation::startWriting(){ } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n", i,*( (uint16_t*) tempframe_footer->packetnum),tempoffset[i]); -#endif +//#endif if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%x\n", i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } -#ifdef PADDING +//#ifdef PADDING cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_footer->packetnum), + *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -#endif +//#endif tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; popready[i] = true; //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver if(currentpacketheader[i] == LAST_PACKET_VALUE){ -#ifdef EIGER_DEBUG3 +//#ifdef EIGER_DEBUG3 cprintf(GREEN, "Got last packet\n"); -#endif +//#endif fullframe[i] = true; popready[i] = false; } @@ -2372,10 +2373,10 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -#ifdef EIGER_DEBUG2 +//#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif -#ifdef EIGER_DEBUG3 +//#endif +//#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2389,7 +2390,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED,"found the missing packet at pnum:%d\n",j); } } -#endif +//#endif //write and copy to gui @@ -2431,14 +2432,14 @@ int UDPStandardImplementation::startWriting(){ } } -#ifdef VERYDEBUG +//#ifdef EIGER_DEBUG3 for(int i=0;ipacketnum)); } -#endif +//#endif } From 5a4dfd128d9dbe58c106fc39d4ddf8cd3dda03d0 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 17 Sep 2015 12:29:16 +0200 Subject: [PATCH 139/222] 10g partial_frames should also work now --- .../src/UDPStandardImplementation.cpp | 97 +++++++++++-------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 10ed494638..b0a24ebc00 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2047,9 +2047,21 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); #endif } + + if(tengigaEnable){ + switch(dynamicRange){ + case 4: LAST_PACKET_VALUE = 0x10; break; + case 8: LAST_PACKET_VALUE = 0x20; break; + case 16: LAST_PACKET_VALUE = 0x40; break; + case 32: LAST_PACKET_VALUE = 0x80; break; + default: break; + } + } } + + //allow them all to be popped initially for(i=0;ipacketnum)); -//#endif +#endif }else if(numpackets[i] == EIGER_HEADER_LENGTH){ cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); exit(-1); } -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 else { cprintf(BG_RED, "got weird in writer, weirdd packetsize:%d\n",numpackets[i]); } -//#endif +#endif if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; @@ -2126,9 +2138,9 @@ int UDPStandardImplementation::startWriting(){ //END OF ACQUISITION if(endofacquisition){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"%d Both dummy frames\n", ithread); -//#endif +#endif //remaining packets to be written if((myDetectorType == EIGER) && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); @@ -2157,15 +2169,16 @@ int UDPStandardImplementation::startWriting(){ if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); -//#endif +#endif + cout<<"packetsperframe:"<missingpacket)); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i, tempoffset[i],tempframenum[i],*( (uint16_t*) tempframe_header->missingpacket)); -//#endif +#endif tempoffset[i]++; blankoffset++; } @@ -2194,12 +2207,12 @@ int UDPStandardImplementation::startWriting(){ popready[i] = false; } } -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 else{ cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); continue; } -//#endif +#endif } @@ -2209,9 +2222,9 @@ int UDPStandardImplementation::startWriting(){ //not a full frame if(!fullframe[i]){ wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); -//#endif +#endif //update frame number tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); @@ -2223,18 +2236,18 @@ int UDPStandardImplementation::startWriting(){ //WRONG FRAME - leave if(tempframenum[i] != presentframenum){ -//#ifdef PADDING +#ifdef PADDING cout<<"wrong packet"<packetnum)); -//#endif +#endif tempframenum[i] = presentframenum; //add missing packets numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); @@ -2257,12 +2270,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; blankoffset ++; } @@ -2274,12 +2287,12 @@ int UDPStandardImplementation::startWriting(){ //CORRECT FRAME - continue building frame else { -//#ifdef PADDING +#ifdef PADDING cout<<"correct packet"<packetnum); #ifdef VERYVERBOSE @@ -2308,12 +2321,12 @@ int UDPStandardImplementation::startWriting(){ (void*)(tempbuffer[tempoffset[i]])); exit(-1); }else -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; blankoffset ++; } @@ -2328,31 +2341,31 @@ int UDPStandardImplementation::startWriting(){ tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN,"**fifo:%d currentpacketheader: %d tempoffset:%d\n", i,*( (uint16_t*) tempframe_footer->packetnum),tempoffset[i]); -//#endif +#endif if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%x\n", i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); } -//#ifdef PADDING +#ifdef PADDING cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), (void*)(tempbuffer[tempoffset[i]])); -//#endif +#endif tempoffset[i] ++; //update last packet lastpacketheader[i] = currentpacketheader[i]; popready[i] = true; //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver if(currentpacketheader[i] == LAST_PACKET_VALUE){ -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 cprintf(GREEN, "Got last packet\n"); -//#endif +#endif fullframe[i] = true; popready[i] = false; } @@ -2373,10 +2386,10 @@ int UDPStandardImplementation::startWriting(){ numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -//#ifdef EIGER_DEBUG2 +#ifdef EIGER_DEBUG2 cprintf(GREEN,"**fnum:%d**\n",currframenum); -//#endif -//#ifdef EIGER_DEBUG3 +#endif +#ifdef EIGER_DEBUG3 if(numberofmissingpackets[0]) cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); if(numberofmissingpackets[1]) @@ -2390,7 +2403,7 @@ int UDPStandardImplementation::startWriting(){ cprintf(RED,"found the missing packet at pnum:%d\n",j); } } -//#endif +#endif //write and copy to gui @@ -2432,14 +2445,14 @@ int UDPStandardImplementation::startWriting(){ } } -//#ifdef EIGER_DEBUG3 +#ifdef EIGER_DEBUG3 for(int i=0;ipacketnum)); } -//#endif +#endif } From 30b83861a427b11b89e8008de79e59461d408738 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 17 Sep 2015 12:34:17 +0200 Subject: [PATCH 140/222] 10g partial_frames should also work now --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b0a24ebc00..23bbe0b7a7 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2172,8 +2172,7 @@ int UDPStandardImplementation::startWriting(){ #ifdef EIGER_DEBUG3 cprintf(RED, "Dummy packet: %d from fifo %d\n", numpackets[i],i); #endif - cout<<"packetsperframe:"< Date: Tue, 22 Sep 2015 11:56:37 +0200 Subject: [PATCH 141/222] doesnt crash at frame number 0 --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 23bbe0b7a7..6f86b24162 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2166,7 +2166,7 @@ int UDPStandardImplementation::startWriting(){ //anything that is not a data packet of right size if(numpackets[i] != onePacketSize){ //header packet - if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, frame packet recieved\n"); exit(-1);} + if(numpackets[i] == EIGER_HEADER_LENGTH) {cprintf(BG_RED,"weird, header frame packet recieved. shouldnt\n"); exit(-1);} //dummy packet else if(!numpackets[i]){ #ifdef EIGER_DEBUG3 @@ -2225,11 +2225,11 @@ int UDPStandardImplementation::startWriting(){ cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); #endif //update frame number + if(!((uint32_t)(*( (uint64_t*) wbuf_footer)))){ + cprintf(BG_RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + continue; + } tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); - - - if(!tempframenum[i]) - cprintf(RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,tempframenum[i]); tempframenum[i] += (startFrameIndex-1); From 71cd046bed1ea7b449b17fa673a1acf1c53532b4 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 22 Sep 2015 12:16:42 +0200 Subject: [PATCH 142/222] small change to ensure no crash at wrong frame read --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 6f86b24162..5abb79fccb 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2226,7 +2226,9 @@ int UDPStandardImplementation::startWriting(){ #endif //update frame number if(!((uint32_t)(*( (uint64_t*) wbuf_footer)))){ - cprintf(BG_RED,"**VERY WEIRD frame numbers for fifo %d: %d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BG_RED,"%d VERY WEIRD frame number=%d and popready:%d\n", + i,(uint32_t)(*( (uint64_t*) wbuf_footer)),popready[i]); + popready[i]=true; continue; } tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); From 7c0430572b731e8476f26fab2e7ebbdc2e8fa535 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 22 Sep 2015 16:21:41 +0200 Subject: [PATCH 143/222] included subframe into receiver and sends to gui --- .../include/UDPBaseImplementation.h | 9 +-- slsReceiverSoftware/include/UDPInterface.h | 3 +- .../include/UDPStandardImplementation.h | 5 +- .../src/UDPBaseImplementation.cpp | 56 ++----------------- .../src/UDPStandardImplementation.cpp | 26 +++------ .../src/slsReceiverTCPIPInterface.cpp | 56 +++++++++++++++---- 6 files changed, 63 insertions(+), 92 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index d69e00b932..cbc4f386cf 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -297,11 +297,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Returns the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet * @param startAcquisitionIndex is the start index of the acquisition * @param startFrameIndex is the start index of the scan */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); /** * Closes all files @@ -359,7 +358,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Copy frames to gui * uses semaphore for nth frame mode */ - void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); + void copyFrameToGui(char* startbuf[], char* buf=NULL); /** * creates udp sockets @@ -483,6 +482,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter //// Could be done more fine-grained... TODO // private: protected: + /** structure of an eiger packet*/ typedef struct { @@ -643,9 +643,6 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** points to the filename to send to gui */ char* guiFileName; - /** temporary number for eiger frame number as its not included in the packet */ - uint32_t guiFrameNumber; - /** send every nth frame to gui or only upon gui request*/ int nFrameToGui; diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 8952396f3f..c1d30ec0bb 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -338,11 +338,10 @@ class UDPInterface { * Returns the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet * @param startAcquisitionIndex is the start index of the acquisition * @param startFrameIndex is the start index of the scan */ - virtual void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0; + virtual void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0; /** set status to transmitting and * when fifo is empty later, sets status to run_finished diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 92092bead2..2916ee6b98 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -294,11 +294,10 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Returns the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet * @param startAcquisitionIndex is the start index of the acquisition * @param startFrameIndex is the start index of the scan */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); /** * Closes all files @@ -356,7 +355,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Copy frames to gui * uses semaphore for nth frame mode */ - void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); + void copyFrameToGui(char* startbuf[], char* buf=NULL); /** * creates udp sockets diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index fb10ae1066..20326bafdd 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -567,7 +567,7 @@ void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ < /** acquisition functions */ -void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ +void UDPBaseImplementation::readFrame(char* c,char** raw,uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ FILE_LOG(logDEBUG) << __AT__ << " called"; //point to gui data if (guiData == NULL){ @@ -576,7 +576,6 @@ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32 //copy data and filename strcpy(c,guiFileName); - fnum = guiFrameNumber; startAcquisitionIndex = getStartAcquisitionIndex(); startFrameIndex = getStartFrameIndex(); @@ -601,55 +600,8 @@ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32 -void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; +void UDPBaseImplementation::copyFrameToGui(char* startbuf[], char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - //random read when gui not ready - if((!nFrameToGui) && (!guiData)){ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - pthread_mutex_unlock(&dataReadyMutex); - } - - //random read or nth frame read, gui needs data now or it is the first frame - else{ - /* - //nth frame read, block current process if the guireader hasnt read it yet - if(nFrameToGui) - sem_wait(&smp); -*/ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - //eiger - if(startbuf != NULL){ - int offset = 0; - int size = frameSize/EIGER_MAX_PORTS; - for(int j=0;j= packetsPerFrame){//min 1 frame, but neednt be //if(npackets == packetsPerFrame * numJobsPerThread){ //only full frames - copyFrameToGui(NULL,-1,wbuffer[0]+HEADER_SIZE_NUM_TOT_PACKETS); + copyFrameToGui(NULL,wbuffer[0]+HEADER_SIZE_NUM_TOT_PACKETS); #ifdef VERYVERBOSE cout << ithread << " finished copying" << endl; #endif @@ -3087,7 +3075,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer #endif if(!once){ - copyFrameToGui(NULL,-1,buff); + copyFrameToGui(NULL,buff); once = 1; } } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 17ff75764e..ffa3f5d8cf 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1068,7 +1068,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ uint32_t startAcquisitionIndex=0; uint32_t startFrameIndex=0; - uint32_t index = 0,bindex = 0, offset=0; + uint32_t index = -1,bindex = 0, offset=0; strcpy(mess,"Could not read frame\n"); @@ -1088,7 +1088,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ else{ ret = OK; /*startIndex=receiverBase->getStartFrameIndex();*/ - receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); + receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1253,7 +1253,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ char* raw = new char[bufferSize]; - uint32_t index=0,index2=0; + uint32_t index=-1,index2=0; uint32_t pindex=0,pindex2=0; uint32_t bindex=0,bindex2=0; uint32_t startAcquisitionIndex=0; @@ -1277,7 +1277,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ }else{ ret = OK; /*startIndex=receiverBase->getStartFrameIndex();*/ - receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); + receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1429,7 +1429,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ for(i=0;igetStartFrameIndex();*/ - receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); + receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ if (raw == NULL){ @@ -1567,16 +1567,36 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ int slsReceiverTCPIPInterface::eiger_read_frame(){ ret=OK; + + /** structure of an eiger packet*/ + typedef struct + { + unsigned char subframenum[4]; + unsigned char missingpacket[2]; + unsigned char portnum[1]; + unsigned char dynamicrange[1]; + } eiger_packet_header_t; + + typedef struct + { + unsigned char framenum[6]; + unsigned char packetnum[2]; + } eiger_packet_footer_t; + + char fName[MAX_STR_LENGTH]=""; int acquisitionIndex = -1; int frameIndex= -1; uint32_t index=0; + uint32_t subframenumber=-1; int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame; int dataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE * packetsPerFrame; + int oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; if(tenGigaEnable){ frameSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE * packetsPerFrame; dataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE * packetsPerFrame; + oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE; } char* raw = new char[frameSize]; char* origVal = new char[frameSize]; @@ -1605,10 +1625,8 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ else{ ret = OK; /** read a frame */ - receiverBase->readFrame(fName,&raw,index,startAcquisitionIndex,startFrameIndex); -#ifdef VERBOSE - cout << "index:" << dec << index << endl; -#endif + receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); + /**send garbage with -1 index to try again*/ if (raw == NULL){ startAcquisitionIndex = -1; @@ -1620,6 +1638,21 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**proper frame*/ else{//cout<<"**** got proper frame ******"<subframenum); + } + +#ifdef VERBOSE + cout << "index:" << dec << index << endl; + cout << "subframenumber:" << dec << subframenumber << endl; +#endif + memcpy(origVal,raw,frameSize); raw=NULL; @@ -1740,6 +1773,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ cout << "index:" << index << endl; cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl; cout << "startFrameIndex:" << startFrameIndex << endl; + cout << "subframenumber:" << subframenumber << endl; #endif } } @@ -1751,6 +1785,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ cout << "frameIndex:" << frameIndex << endl; cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl; cout << "startFrameIndex:" << startFrameIndex << endl; + cout << "subframenumber:" << subframenumber << endl; } #endif @@ -1773,6 +1808,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ socket->SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); socket->SendDataOnly(&frameIndex,sizeof(frameIndex)); + socket->SendDataOnly(&subframenumber,sizeof(subframenumber)); socket->SendDataOnly(retval,dataSize); } From 102162ac1a883a4e9d729b6249b066326555555b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 22 Sep 2015 16:41:00 +0200 Subject: [PATCH 144/222] made compatible to subframe in gui for partial_frame --- slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index aa799d380e..8e07ceafee 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1570,7 +1570,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ int frameIndex= -1; int i; uint32_t index=0; - + uint32_t subindex=-1; int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame; int dataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE * packetsPerFrame; if(tenGigaEnable){ @@ -1750,6 +1750,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ cout << "frameIndex:" << frameIndex << endl; cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl; cout << "startFrameIndex:" << startFrameIndex << endl; + } #endif @@ -1772,6 +1773,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ socket->SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); socket->SendDataOnly(&frameIndex,sizeof(frameIndex)); + socket->SendDataOnly(&subindex,sizeof(subindex)); socket->SendDataOnly(retval,dataSize); } From 06b38e591ced7837b36c64b56142781c6a40b573 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 23 Sep 2015 12:34:21 +0200 Subject: [PATCH 145/222] got rid of warnings --- slsReceiverSoftware/include/circularFifo.h | 2 +- .../src/UDPBaseImplementation.cpp | 185 ------------------ .../src/UDPStandardImplementation.cpp | 24 +-- .../src/slsReceiverTCPIPInterface.cpp | 7 +- 4 files changed, 14 insertions(+), 204 deletions(-) diff --git a/slsReceiverSoftware/include/circularFifo.h b/slsReceiverSoftware/include/circularFifo.h index 6f779aafce..1ba584cc4a 100644 --- a/slsReceiverSoftware/include/circularFifo.h +++ b/slsReceiverSoftware/include/circularFifo.h @@ -79,7 +79,7 @@ template bool CircularFifo::push(Element*& item_) { - int nextTail = increment(tail); + unsigned int nextTail = increment(tail); if(nextTail != head) { array[tail] = item_; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 20326bafdd..682c529802 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1399,12 +1399,6 @@ int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " s int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int ithread = currentWriterThreadIndex; -#ifdef VERYVERBOSE - cout << ithread << "In startWriting()" < 0){ - - //for progress and packet loss calculation(new files) - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - //lock - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - - - //to create new file when max reached - packetsToSave = maxPacketsPerFile - packetsInFile; - if(packetsToSave > numpackets) - packetsToSave = numpackets; -/**next time offset is still plus header length*/ - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); - packetsInFile += packetsToSave; - packetsCaught += packetsToSave; - totalPacketsCaught += packetsToSave; - - - //new file - if(packetsInFile >= maxPacketsPerFile){ - //for packet loss - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - //create - createNewFile(); - } - - //unlock - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - - - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; - } - - } - else{ - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - packetsInFile += numpackets; - packetsCaught += numpackets; - totalPacketsCaught += numpackets; - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - } } @@ -1675,97 +1581,6 @@ void UDPBaseImplementation::handleDataCompression(int ithread, char* wbuffer[], FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; -#if defined(MYROOT1) && defined(ALLFILE_DEBUG) - writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); -#endif - - eventType thisEvent = PEDESTAL; - int ndata; - char* buff = 0; - int npackets = (uint16_t)(*((uint16_t*)wbuffer[0])); - data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; - int remainingsize = npackets * onePacketSize; - int np; - int once = 0; - double tot, tl, tr, bl, br; - int xmin = 1, ymin = 1, ix, iy; - - - while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ - np = ndata/onePacketSize; - - //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); - - //only for moench - if(commonModeSubtractionEnable){ - for(ix = xmin - 1; ix < xmax+1; ix++){ - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); - } - } - } - - - for(ix = xmin - 1; ix < xmax+1; ix++) - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); - if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - if (thisEvent==PHOTON_MAX) { - receiverdata[ithread]->getFrameNumber(buff); - //iFrame=receiverdata[ithread]->getFrameNumber(buff); -#ifdef MYROOT1 - myTree[ithread]->Fill(); - //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; -#else - pthread_mutex_lock(&write_mutex); - if((enableFileWrite) && (sfilefd)) - singlePhotonDet[ithread]->writeCluster(sfilefd); - pthread_mutex_unlock(&write_mutex); -#endif - } - } - } - - nf++; -#ifndef ALLFILE - pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; - packetsCaught += packetsPerFrame; - totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= maxPacketsPerFile) - createNewFile(); - pthread_mutex_unlock(&progress_mutex); - -#endif - if(!once){ - copyFrameToGui(NULL,buff); - once = 1; - } - } - - remainingsize -= ((buff + ndata) - data); - data = buff + ndata; - if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) - cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuffer[0]<missingpacket)!= missingPacketValue){ cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%p\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), *( (uint16_t*) blankframe_header->missingpacket), @@ -2303,7 +2297,7 @@ int UDPStandardImplementation::startWriting(){ blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; if (*( (uint16_t*) tempframe_header->missingpacket)!= missingPacketValue){ cprintf(BG_RED, "correct blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%x\n", + "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%p\n", i,tempoffset[i],tempframenum[i], *( (uint16_t*) tempframe_header->missingpacket), *( (uint16_t*) blankframe_header->missingpacket), @@ -2320,7 +2314,7 @@ int UDPStandardImplementation::startWriting(){ blankoffset ++; } //add current packet - if(currentpacketheader[i] != (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ + if(currentpacketheader[i] != (uint32_t)(tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", i,tempoffset[i],currentpacketheader[i], tempframenum[i],(uint32_t)(*( (uint64_t*) wbuf_footer))); @@ -2335,7 +2329,7 @@ int UDPStandardImplementation::startWriting(){ i,*( (uint16_t*) tempframe_footer->packetnum),tempoffset[i]); #endif if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ - cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%x\n", + cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%p\n", i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); exit(-1); @@ -2815,7 +2809,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n cprintf(GREEN,"totalPacketsCaught:%d\n", totalPacketsCaught); #endif //new file - if(packetsInFile >= maxPacketsPerFile){ + if(packetsInFile >= (uint32_t)maxPacketsPerFile){ //for packet loss, because currframenum is the latest one for eiger if(myDetectorType != EIGER){ @@ -2870,7 +2864,7 @@ void UDPStandardImplementation::writeToFile_withoutCompression(char* buf[],int n void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets){ - int i,j, missingpacket,port = 0, pnuminc; + int i, missingpacket,port = 0; if (cbAction < DO_EVERYTHING){ @@ -3069,7 +3063,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer packetsInFile += packetsPerFrame; packetsCaught += packetsPerFrame; totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= maxPacketsPerFile) + if(packetsInFile >= (uint32_t)maxPacketsPerFile) createNewFile(); pthread_mutex_unlock(&progress_mutex); diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index ffa3f5d8cf..24e475c501 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -39,10 +39,11 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* shortFrame(-1), packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), dynamicrange(16), - socket(NULL), killTCPServerThread(0), - tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2), - bottom(bot){ + tenGigaEnable(0), + portNumber(DEFAULT_PORTNO+2), + bottom(bot), + socket(NULL){ int port_no=portNumber; if(receiverBase == NULL) receiverBase = 0; From c392348def93499c7b67cd040343c9c3c0e5799e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 30 Sep 2015 11:40:39 +0200 Subject: [PATCH 146/222] big change half done --- .../include/UDPBaseImplementation.h | 905 +++------ slsReceiverSoftware/include/UDPInterface.h | 490 +++-- .../include/UDPStandardImplementation.h | 221 ++- .../src/UDPBaseImplementation.cpp | 1767 +++-------------- slsReceiverSoftware/src/UDPInterface.cpp | 1 - .../src/UDPStandardImplementation.cpp | 4 +- .../src/slsReceiverTCPIPInterface.cpp | 360 ++-- 7 files changed, 1337 insertions(+), 2411 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index cbc4f386cf..29d9dd009a 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -8,25 +8,9 @@ #include "sls_receiver_defs.h" -#include "receiver_defs.h" -#include "genericSocket.h" -#include "circularFifo.h" -#include "singlePhotonDetector.h" -#include "slsReceiverData.h" -#include "moenchCommonMode.h" - #include "UDPInterface.h" - -#ifdef MYROOT1 -#include -#include -#endif - - #include -#include #include -#include /** * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -35,6 +19,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInterface { public: + + /************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ /** * Constructor */ @@ -45,800 +34,538 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ virtual ~UDPBaseImplementation(); - void configure(map config_map); + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ - /** - * delete and free member parameters + //**initial parameters*** + /* + * Get detector hostname + * @return NULL or hostname or NULL if uninitialized (max of 1000 characters) */ - void deleteMembers(); + char *getDetectorHostname() const; + + //***file parameters*** /** - * initialize member parameters + * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * @return NULL or file name prefix (max of 1000 characters) */ - void initializeMembers(); + char *getFileName() const; /** - * Set receiver type - * @param det detector type - * Returns success or FAIL + * Get File Path + * @return NULL or file path (max of 1000 characters) */ - int setDetectorType(detectorType det); - - /** - * Set bottom to bot - * @param bot = 1 if bottom - */ - void setBottom(int bot); + char *getFilePath() const; - //Frame indices and numbers caught /** - * Returns the frame index at start of entire acquisition (including all scans) + * Get File Index + * @return file index of acquisition */ - uint32_t getStartAcquisitionIndex(); + uint64_t getFileIndex() const; /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) + * Get Scan Tag + * @return scan tag //FIXME: needed? (unsigned integer?) */ - uint32_t getAcquisitionIndex(); + int getScanTag() const; /** - * Returns if acquisition started + * Get if Frame Index is enabled (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @return true if frame index needed, else false */ - bool getAcquistionStarted(); + bool getFrameIndexEnable() const; /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) + * Get File Write Enable + * @return true if file write enabled, else false */ - int getFramesCaught(); + bool getFileWriteEnable() const; /** - * Returns Total Frames Caught for an entire acquisition (including all scans) + * Get File Over Write Enable + * @return true if file over write enabled, else false */ - int getTotalFramesCaught(); + bool getOverwriteEnable() const; /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) + * Get data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @return true if data compression enabled, else false */ - uint32_t getStartFrameIndex(); + bool getDataCompressionEnable() const; + + //***acquisition count parameters*** /** - * Returns current Frame Index for each real time acquisition (eg. for each scan) + * Get Total Frames Caught for an entire acquisition (including all scans) + * @return total number of frames caught for entire acquisition */ - uint32_t getFrameIndex(); + uint64_t getTotalFramesCaught() const; /** - * Returns if measurement started + * Get Frames Caught for each real time acquisition (eg. for each scan) + * @return number of frames caught for each scan */ - bool getMeasurementStarted(); + uint64_t getFramesCaught() const; /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 + * Get Current Frame Index Caught for an entire acquisition (including all scans) + * @return current frame index (represents all scans too) */ - void resetTotalFramesCaught(); - + int64_t getAcquisitionIndex() const; - - //file parameters + //***connection parameters*** /** - * Returns File Path + * Get UDP Port Number + * @return udp port number */ - char* getFilePath() const; + uint32_t getUDPPortNo() const; /** - * Set File Path - * @param c file path + * Get Second UDP Port Number (eiger specific) + * @return second udp port number */ - char* setFilePath(const char c[]); + uint32_t getUDPPortNo2() const; /** - * Returns File Name + * Get Ehernet Interface + * @ethernet interface. eg. eth0 or "" if listening to all (max of 1000 characters) */ - char* getFileName() const; + char *getEthernetInterface() const; + + //***acquisition parameters*** /** - * Set File Name (without frame index, file index and extension) - * @param c file name + * Get Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @return index of adc enabled, else -1 if all enabled */ - char* setFileName(const char c[]); + int getShortFrameEnable() const; /** - * Returns File Index + * Get the Frequency of Frames Sent to GUI + * @return 0 for random frame requests, n for nth frame frequency */ - int getFileIndex(); + uint32_t getFrameToGuiFrequency() const; /** - * Set File Index - * @param i file index + * Get Acquisition Period + * @return acquisition period */ - int setFileIndex(int i); + uint64_t getAcquisitionPeriod() const; - /** - * Set Frame Index Needed - * @param i frame index needed + /* + * Get Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @return number of frames expected */ - int setFrameIndexNeeded(int i); + uint64_t getNumberOfFrames() const; /** - * Set enable file write - * @param i file write enable - * Returns file write enable + * Get Dynamic Range or Number of Bits Per Pixel + * @return dynamic range that is 4, 8, 16 or 32 */ - int setEnableFileWrite(int i); + uint32_t getDynamicRange() const; /** - * Enable/disable overwrite - * @param i enable - * Returns enable over write + * Get Ten Giga Enable + * @return true if 10Giga enabled, else false (1G enabled) */ - int setEnableOverwrite(int i); + bool getTenGigaEnable() const; + //***receiver status*** /** - * Returns file write enable - * 1: YES 0: NO - */ - int getEnableFileWrite() const; + * Get Listening Status of Receiver + * @return can be idle, listening or error depending on if the receiver is listening or not + */ + slsReceiverDefs::runStatus getStatus() const; - /** - * Returns file over write enable - * 1: YES 0: NO - */ - int getEnableOverwrite() const; -//other parameters - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - void abort() {}; + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + + //**initial parameters*** /** - * Returns status of receiver: idle, running or error + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments */ - runStatus getStatus() const; + void configure(map config_map); /** - * Set detector hostname - * @param c hostname + * Set Bottom Enable (eiger specific, should be moved to configure, and later from client via TCPIP) + * @param b is true for bottom enabled or false for bottom disabled */ - void initialize(const char *detectorHostName); + void setBottomEnable(const bool b); - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - char *getDetectorHostname() const; + //***file parameters*** /** - * Set Ethernet Interface or IP to listen to + * Set File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * Does not check for file existence since it is created only at startReceiver + * @param c file name (max of 1000 characters) */ - void setEthernetInterface(char* c); + void setFileName(const char c[]); /** - * Set UDP Port Number - */ - void setUDPPortNo(int p); - void setUDPPortNo2(int p); - - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames + * Set File Path + * Checks for file directory existence before setting file path, + * If it doesn't exist, it will set it blank + * @param c file path (max of 1000 characters) */ - int getNumberOfFrames() const; + void setFilePath(const char c[]); /** - * set frame number if a positive number + * Set File Index of acquisition + * @param i file index of acquisition */ - int32_t setNumberOfFrames(int32_t fnum); + void setFileIndex(const uint64_t i); /** - * Returns scan tag + * Set Scan Tag + * @param i scan tag //FIXME: needed? (unsigned integer?) */ - int getScanTag() const; + void setScanTag(const int i); /** - * set scan tag if its is a positive number + * Set Frame Index Enable (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @param b true for frame index enable, else false */ - int32_t setScanTag(int32_t stag); + void setFrameIndexEnable(const bool b); /** - * Returns the number of bits per pixel + * Set File Write Enable + * @param b true for file write enable, else false */ - int getDynamicRange() const; + void setFileWriteEnable(const bool b); /** - * set dynamic range if its is a positive number + * Set File Overwrite Enable + * @param b true for file overwrite enable, else false */ - int32_t setDynamicRange(int32_t dr); + void setOverwriteEnable(const bool b); /** - * Set short frame - * @param i if shortframe i=1 + * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @param b true for data compression enable, else false */ - int setShortFrame(int i); + void setDataCompressionEnable(const bool b); - /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request - */ - int setNFrameToGui(int i); - /** set acquisition period if a positive number - */ - int64_t setAcquisitionPeriod(int64_t index); - /** get data compression, by saving only hits + //***connection parameters*** + /** + * Set UDP Port Number + * @param i udp port number */ - bool getDataCompression(); + void setUDPPortNo(const uint32_t i); - /** enabl data compression, by saving only hits - /returns if failed + /** + * Set Second UDP Port Number (eiger specific) + * @return second udp port number */ - int enableDataCompression(bool enable); + void setUDPPortNo2(const uint32_t i); /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe + * Set Ethernet Interface to listen to + * @param c ethernet inerface eg. eth0 (max of 1000 characters) */ - int enableTenGiga(int enable = -1); - - + void setEthernetInterface(const char* c); -//other functions + //***connection parameters*** /** - * Returns the buffer-current frame read by receiver - * @param c pointer to current file name - * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan + * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @param i index of adc enabled, else -1 if all enabled */ - void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + void setShortFrameEnable(const int i); /** - * Closes all files - * @param ithr thread index + * Set the Frequency of Frames Sent to GUI + * @param i 0 for random frame requests, n for nth frame frequency */ - void closeFile(int ithr = -1); + void setFrameToGuiFrequency(const uint32_t i); /** - * Starts Receiver - starts to listen for packets - * @param message is the error message if there is an error - * Returns success + * Set Acquisition Period + * @param i acquisition period */ - int startReceiver(char message[]); + void setAcquisitionPeriod(const uint64_t i); /** - * Stops Receiver - stops listening for packets - * Returns success - */ - int stopReceiver(); - - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished + * Set Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @param i number of frames expected */ - void startReadout(); + void setNumberOfFrames(const uint64_t i); /** - * shuts down the udp sockets - * \returns if success or fail + * Set Dynamic Range or Number of Bits Per Pixel + * @param i dynamic range that is 4, 8, 16 or 32 */ - int shutDownUDPSockets(); + void setDynamicRange(const uint32_t i); -protected: - - /* - void not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; - }; - */ /** - * Deletes all the filter objects for single photon data + * Set Ten Giga Enable + * @param b true if 10Giga enabled, else false (1G enabled) */ - void deleteFilter(); + void setTenGigaEnable(const bool b); - /** - * Constructs the filter for single photon data - */ - void setupFilter(); - /** - * set up fifo according to the new numjobsperthread - */ - void setupFifoStructure (); - /** - * Copy frames to gui - * uses semaphore for nth frame mode - */ - void copyFrameToGui(char* startbuf[], char* buf=NULL); + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + //***initial functions*** /** - * creates udp sockets - * \returns if success or fail + * Set receiver type (and corresponding detector variables in derived STANDARD class) + * It is the first function called by the client when connecting to receiver + * @param d detector type + * @return OK or FAIL */ - int createUDPSockets(); + int setDetectorType(const slsReceiverDefs::detectorType d); /** - * create listening thread - * @param destroy is true to kill all threads and start again + * Sets detector hostname (and corresponding detector variables in derived REST class) + * It is second function called by the client when connecting to receiver. + * you can call this function only once. //FIXME: is this still valid, this implemented in derived REST class? + * @param c detector hostname */ - int createListeningThreads(bool destroy = false); + void initialize(const char *c); - /** - * create writer threads - * @param destroy is true to kill all threads and start again - */ - int createWriterThreads(bool destroy = false); + //***acquisition functions*** /** - * set thread priorities + * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) */ - void setThreadPriorities(); + void resetAcquisitionCount(); /** - * initializes variables and creates the first file - * also does the startAcquisitionCallBack - * \returns FAIL or OK + * Start Listening for Packets by activating all configuration settings to receiver + * @param c error message if FAIL + * @return OK or FAIL */ - int setupWriter(); + int startReceiver(char *c=NULL); /** - * Creates new tree and file for compression - * @param ithr thread number - * @param iframe frame number - *\returns OK for succces or FAIL for failure + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer,it returns with the status Run_Finished */ - int createCompressionFile(int ithr, int iframe); + void stopReceiver(); /** - * Creates new file - *\returns OK for succces or FAIL for failure + * Stop Listening to Packets + * and sets status to Transmitting */ - int createNewFile(); + void startReadout(); /** - * Static function - Thread started which listens to packets. - * Called by startReceiver() - * @param this_pointer pointer to this object + * shuts down the udp sockets + * \returns OK or FAIL */ - static void* startListeningThread(void *this_pointer); + int shutDownUDPSockets(); /** - * Static function - Thread started which writes packets to file. - * Called by startReceiver() - * @param this_pointer pointer to this object + * Get the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param startAcquisitionIndex start index of the acquisition + * @param startFrameIndex start index of the scan */ - static void* startWritingThread(void *this_pointer); + void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex); /** - * Thread started which listens to packets. - * Called by startReceiver() - * + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' */ - int startListening(); + void abort(); //FIXME: needed, isnt stopReceiver enough? /** - * Thread started which writes packets to file. - * Called by startReceiver() - * + * Closes all files + * @param i thread index, -1 for all threads */ - int startWriting(); + void closeFile(int i = -1); - /** - * Writing to file without compression - * @param buf is the address of buffer popped out of fifo - * @param numpackets is the number of packets - * @param framenum current frame number - */ - void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); + //***callback functions*** /** - * Its called for the first packet of a scan or acquistion - * Sets the startframeindices and the variables to know if acquisition started - * @param ithread listening thread number + * Call back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is the action which decides what the user and default responsibilities to save data are + * 0 callback takes care of open,close,wrie file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ - void startFrameIndices(int ithread); + void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg); /** - * This is called when udp socket is shut down - * It pops ffff instead of packet number into fifo - * to inform writers about the end of listening session - * @param ithread listening thread number - * @param rc number of bytes received - * @param pc packet count - * @param t total packets listened to + * Call back for acquisition finished + * callback argument is + * total frames caught */ - void stopListening(int ithread, int rc, int &pc, int &t); + void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); /** - * When acquisition is over, this is called - * @param ithread listening thread number - * @param wbuffer writer buffer + * Call back for raw data + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) */ - void stopWriting(int ithread, char* wbuffer[]); - + void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg); - /** - * data compression for each fifo output - * @param ithread listening thread number - * @param wbuffer writer buffer - * @param data pointer to the next packet start - * @param xmax max pixels in x direction - * @param ymax max pixels in y direction - * @param nf nf - */ - void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); - //// Could be done more fine-grained... TODO - // private: protected: - /** structure of an eiger packet*/ - typedef struct - { + //**detector parameters*** + /** + * structure of an eiger packet header + * subframenum subframe number for 32 bit mode (already written by firmware) + * missingpacket explicitly put to 0xFF to recognize it in file read (written by software) + * portnum 0 for the first port and 1 for the second port (written by software to file) + * dynamicrange dynamic range or bits per pixel (written by software to file) + */ + typedef struct { unsigned char subframenum[4]; unsigned char missingpacket[2]; unsigned char portnum[1]; unsigned char dynamicrange[1]; } eiger_packet_header_t; - - typedef struct - { + /** + * structure of an eiger packet footer + * framenum 48 bit frame number (already written by firmware) + * packetnum packet number (already written by firmware) + */ + typedef struct { unsigned char framenum[6]; unsigned char packetnum[2]; } eiger_packet_footer_t; - /** max number of listening threads */ - const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; - - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; - - /** missing packet identifier value */ - const static uint16_t missingPacketValue = 0xFFFF; - /** detector type */ detectorType myDetectorType; - /** detector hostname */ char detHostname[MAX_STR_LENGTH]; - - /** status of receiver */ + /** Number of Packets per Frame*/ + uint64_t packetsPerFrame; + /** Acquisition Period */ + int64_t acquisitionPeriod; + /** Frame Number */ + int64_t numberOfFrames; + /** Dynamic Range */ + uint32_t dynamicRange; + /** Ten Giga Enable*/ + bool tengigaEnable; + /** Bottom Half Module Enable */ + bool bottomEnable; + + //***receiver parameters*** + /** Maximum Number of Listening Threads/ UDP Ports */ + const static int MAX_NUM_LISTENING_THREADS = 2; + /** Receiver Status */ runStatus status; - /** UDP Socket between Receiver and Detector */ - genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; - - /** Server UDP Port*/ - int server_port[MAX_NUM_LISTENING_THREADS]; - - /** ethernet interface or IP to listen to */ - char *eth; + //***connection parameters*** + /** Ethernet Interface */ + char eth[MAX_STR_LENGTH]; + /** Server UDP Port Number*/ + uint32_t udpPortNum[MAX_NUM_LISTENING_THREADS]; - /** max packets per file **/ - int maxPacketsPerFile; - - /** File write enable */ - int enableFileWrite; - - /** File over write enable */ - int overwrite; - - /** Complete File name */ - char savefilename[MAX_STR_LENGTH]; - - /** File Name without frame index, file index and extension*/ + //***file parameters*** + /** File Name without frame index, file index and extension (_d0_f000000000000_8.raw)*/ char fileName[MAX_STR_LENGTH]; - /** File Path */ char filePath[MAX_STR_LENGTH]; - /** File Index */ - int fileIndex; - - /** scan tag */ + uint64_t fileIndex; + /** Scan Tag */ int scanTag; - - /** if frame index required in file name */ - int frameIndexNeeded; - - /* Acquisition started */ - bool acqStarted; - - /* Measurement started */ - bool measurementStarted; - - /** Frame index at start of each real time acquisition (eg. for each scan) */ - uint32_t startFrameIndex; - - /** Actual current frame index of each time acquisition (eg. for each scan) */ - uint32_t frameIndex; - - /** Frames Caught for each real time acquisition (eg. for each scan) */ - uint32_t packetsCaught; - + /** Frame Index Enable */ + bool frameIndexEnable; + /** File Write enable */ + bool fileWriteEnable; + /** Overwrite enable */ + bool overwriteEnable; + /** Data Compression Enable - save only hits */ + bool dataCompressionEnable; + + //***acquisition count parameters*** /** Total packets caught for an entire acquisition (including all scans) */ - uint32_t totalPacketsCaught; - - /** Pckets currently in current file, starts new file when it reaches max */ - uint32_t packetsInFile; - - /** Number of missing packets in acquisition*/ - uint32_t numTotMissingPackets; - - /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ - uint32_t numTotMissingPacketsInFile; - - /** Number of missing packets per buffer*/ - uint32_t numMissingPackets; - - /** Frame index at start of an entire acquisition (including all scans) */ - uint32_t startAcquisitionIndex; + uint64_t totalPacketsCaught; + /** Frames Caught for each real time acquisition (eg. for each scan) */ + uint64_t packetsCaught; + //***acquisition indices parameters*** /** Actual current frame index of an entire acquisition (including all scans) */ - uint32_t acquisitionIndex; - - /** number of packets per frame*/ - int packetsPerFrame; - - /** frame index mask */ - uint32_t frameIndexMask; - - /** packet index mask */ - uint32_t packetIndexMask; - - /** frame index offset */ - int frameIndexOffset; - - /** acquisition period */ - int64_t acquisitionPeriod; - - /** frame number */ - int32_t numberOfFrames; - - /** dynamic range */ - int dynamicRange; - - /** short frames */ - int shortFrame; - - /** current frame number */ - uint32_t currframenum; - - /** Previous Frame number from buffer */ - int prevframenum; - - /** size of one frame */ - int frameSize; - - /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - int bufferSize; - - /** one buffer size */ - int onePacketSize; - - /** one buffer size */ - int oneDataSize; - - /** latest data */ - char* latestData; - - /** gui data ready */ - int guiDataReady; - - /** points to the data to send to gui */ - char* guiData; - - /** points to the filename to send to gui */ - char* guiFileName; - - /** send every nth frame to gui or only upon gui request*/ - int nFrameToGui; - - /** fifo size */ - unsigned int fifosize; - - /** number of jobs per thread for data compression */ - int numJobsPerThread; - - /** datacompression - save only hits */ - bool dataCompression; - - /** memory allocated for the buffer */ - char *mem0[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data read */ - CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; + uint64_t acquisitionIndex; - /** circular fifo to store addresses of data already written and ready to be resued*/ - CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; - - /** Receiver buffer */ - char *buffer[MAX_NUM_LISTENING_THREADS]; - - /** number of writer threads */ - int numListeningThreads; - - /** number of writer threads */ - int numWriterThreads; - - /** to know if listening and writer threads created properly */ - int thread_started; - - /** current listening thread index*/ - int currentListeningThreadIndex; - - /** current writer thread index*/ - int currentWriterThreadIndex; - - /** thread listening to packets */ - pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; - - /** thread writing packets */ - pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; - - /** total frame count the listening thread has listened to */ - int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - - /** mask showing which listening threads are running */ - volatile uint32_t listeningthreads_mask; - - /** mask showing which writer threads are running */ - volatile uint32_t writerthreads_mask; - - /** mask showing which threads have created files*/ - volatile uint32_t createfile_mask; - - /** OK if file created was successful */ - int ret_createfile; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllListeningThreads; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllWritingThreads; - - /** 10Gbe enable*/ - int tengigaEnable; - - /** footer offset is different for 1g and 10g*/ - int footer_offset; - - // TODO: not properly sure where to put these... - /** structure of an eiger image header*/ - - - - -//semaphores - /** semaphore to synchronize writer and guireader threads */ - sem_t smp; - /** semaphore to synchronize listener threads */ - sem_t listensmp[MAX_NUM_LISTENING_THREADS]; - /** semaphore to synchronize writer threads */ - sem_t writersmp[MAX_NUM_WRITER_THREADS]; - - -//mutex - /** guiDataReady mutex */ - pthread_mutex_t dataReadyMutex; - - /** mutex for status */ - pthread_mutex_t status_mutex; - - /** mutex for progress variable currframenum */ - pthread_mutex_t progress_mutex; - - /** mutex for writing data to file */ - pthread_mutex_t write_mutex; - - /** File Descriptor */ - FILE *sfilefd; - - //filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - moenchCommonMode *cmSub; - bool commonModeSubtractionEnable; - -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif + //***acquisition parameters*** + /* Short Frame Enable or index of adc enabled, else -1 if all enabled (gotthard specific) TODO: move to setROI */ + int shortFrameEnable; + /** Frequency of Frames sent to GUI */ + uint32_t FrameToGuiFrequency; + //***callback parameters*** /** - callback arguments are - filepath - filename - fileindex - data size - - return value is - 0 callback takes care of open,close,write file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - - */ + * function being called back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is + * 0 callback takes care of open,close,wrie file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything + */ int (*startAcquisitionCallBack)(char*, char*,int, int, void*); void *pStartAcquisition; /** - args to acquisition finished callback - total frames caught - - */ + * function being called back for acquisition finished + * callback argument is + * total frames caught + */ void (*acquisitionFinishedCallBack)(int, void*); void *pAcquisitionFinished; /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ + * function being called back for raw data + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) + */ void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); void *pRawDataReady; - /** The action which decides what the user and default responsibilites to save data are - * 0 raw data ready callback takes care of open,close,write file - * 1 callback writes file, we have to open, close it - * 2 we open, close, write file, callback does not do anything */ - int cbAction; - - /** true if bottom half module for eiger */ - bool bottom; - -public: +private: - /** - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; - - /** - callback argument is - toatal frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; }; diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index c1d30ec0bb..2e89b59bef 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -26,375 +26,471 @@ class UDPInterface { - /* abstract class that defines the UDP interface of an sls detector data receiver. + /* abstract class that defines the UDP interface of an sls detector data receiver. * - * Use the factory method UDPInterface::create() to get an instance: + * Use the factory method UDPInterface::create() to get an instance: + * + * UDPInterface *udp_interface = UDPInterface::create() * - * UDPInterface *udp_interface = UDPInterface::create() * * supported sequence of method-calls: * - * initialize() : once and only once after create() + * initialize() : once and only once after create() //FIXME: only once functionality implemented in the derived REST class, so not mention here? + * + * get*() : anytime after initialize(), multiples times * - * get*() : anytime after initialize(), multiples times * set*() : anytime after initialize(), multiple times * - * startReceiver(): anytime after initialize(). Will fail if state already is 'running' + * startReceiver(): anytime after initialize(). Will fail if state already is 'running': + * + * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. + * + * abort(), //FIXME: needed? * - * abort(), * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. * - * getStatus() returns the actual state of the data receiver - running or idle. All other + * getStatus() returns the actual state of the data receiver - idle, running or error, enum defined in include/sls_receiver_defs.h + * + * + * * get*() and set*() methods access the local cache of configuration values only and *do not* modify the data receiver settings. * - * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. + * set methods return nothing, use get methods to validate a set method success * - * get- and set-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: + * get-methods that return a char array (char *) allocate a new array at each call. The caller is responsible to free the allocated space: * * char *c = receiver->getFileName(); - * .... + * Or + * FIXME: so that the pointers are not shared external to the class, do the following way in the calling method? + * char *c = new char[MAX_STR_LENGTH]; + * strcpy(c,receiver->getFileName()); + * .... + * * delete[] c; * - * always: 1:YES 0:NO for int as bool-like arguments + * All pointers passed in externally will be allocated and freed by the calling function + * + * OK and FAIL are defined in include/sls_receiver_defs.h for functions implementing behavior * */ public: + /************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + /** + * Constructor + * Only non virtual function implemented in this class + * Factory create method to create a standard or REST object + * @param [in] receiver_type type can be standard or REST + * @return a UDPInterface reference to object depending on receiver type + */ + static UDPInterface *create(string receiver_type = "standard"); + /** * Destructor */ virtual ~UDPInterface() {}; - /** - * Factory create method + + + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + + //**initial parameters*** + /* + * Get detector hostname + * @return hostname or NULL if uninitialized, must be released by calling function (max of 1000 characters) */ - static UDPInterface *create(string receiver_type = "standard"); + virtual char *getDetectorHostname() const = 0; - virtual void configure(map config_map) = 0; - - public: - + //***file parameters*** /** - * Initialize the Receiver - @param detectorHostName detector hostname - * you can call this function only once. You must call it before you call startReceiver() for the first time. + * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * @return NULL or pointer to file name prefix, must be released by calling function (max of 1000 characters) */ - virtual void initialize(const char *detectorHostName) = 0; - - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - virtual char *getDetectorHostname() const = 0; + virtual char *getFileName() const = 0; /** - * Returns status of receiver: idle, running or error + * Get File Path + * @return NULL or pointer to file path, must be released by calling function (max of 1000 characters) */ - virtual slsReceiverDefs::runStatus getStatus() const = 0; + virtual char *getFilePath() const = 0; /** - * Returns File Name - * caller is responsible to deallocate the returned char array. + * Get File Index + * @return NULL or file index of acquisition */ - virtual char *getFileName() const = 0; + virtual uint64_t getFileIndex() const = 0; + /** + * Get Scan Tag + * @return scan tag //FIXME: needed? (unsigned integer?) + */ + virtual int getScanTag() const = 0; /** - * Returns File Path - * caller is responsible to deallocate the returned char array + * Get if Frame Index is enabled (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @return true if frame index needed, else false */ - virtual char *getFilePath() const = 0; //FIXME: Does the caller need to free() the returned pointer? + virtual bool getFrameIndexEnable() const = 0; + /** + * Get File Write Enable + * @return true if file write enabled, else false + */ + virtual bool getFileWriteEnable() const = 0; /** - * Returns the number of bits per pixel + * Get File Over Write Enable + * @return true if file over write enabled, else false */ - virtual int getDynamicRange() const = 0; + virtual bool getOverwriteEnable() const = 0; /** - * Returns scan tag + * Get data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @return true if data compression enabled, else false */ - virtual int getScanTag() const = 0; + virtual bool getDataCompressionEnable() const = 0; - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames + + //***acquisition count parameters*** + /** + * Get Total Frames Caught for an entire acquisition (including all scans) + * @return total number of frames caught for entire acquisition */ - virtual int getNumberOfFrames() const = 0; + virtual uint64_t getTotalFramesCaught() const = 0; /** - * Returns file write enable - * 1: YES 0: NO - */ - virtual int getEnableFileWrite() const = 0; + * Get Frames Caught for each real time acquisition (eg. for each scan) + * @return number of frames caught for each scan + */ + virtual uint64_t getFramesCaught() const = 0; /** - * Returns file over write enable - * 1: YES 0: NO - */ - virtual int getEnableOverwrite() const = 0; + * Get Current Frame Index Caught for an entire acquisition (including all scans) + * @return current frame index (represents all scans too) or -1 if no packets caught + */ + virtual int64_t getAcquisitionIndex() const = 0; + + //***connection parameters*** /** - * Set File Name (without frame index, file index and extension) - @param c file name - /returns file name - * returns NULL on failure (like bad file name) - * does not check the existence of the file - we don't know which path we'll finally use, so no point to check. - * caller is responsible to deallocate the returned char array. + * Get UDP Port Number + * @return udp port number */ - virtual char* setFileName(const char c[]) = 0; + virtual uint32_t getUDPPortNo() const = 0; /** - * Set File Path - @param c file path - /returns file path - * checks the existence of the directory. returns NULL if directory does not exist or is not readable. - * caller is responsible to deallocate the returned char array. + * Get Second UDP Port Number (eiger specific) + * @return second udp port number */ - virtual char* setFilePath(const char c[]) = 0; + virtual uint32_t getUDPPortNo2() const = 0; /** - * Returns the number of bits per pixel - @param dr sets dynamic range - /returns dynamic range - * returns -1 on failure - * FIXME: what are the allowd values - should we use an enum as argument? + * Get Ehernet Interface + * @return ethernet interface. eg. eth0 (max of 1000 characters) */ - virtual int setDynamicRange(const int dr) = 0; + virtual char *getEthernetInterface() const = 0; + //***acquisition parameters*** /** - * Set scan tag - @param tag scan tag - /returns scan tag (always non-negative) - * FIXME: valid range - only positive? 16bit ore 32bit? - * returns -1 on failure + * Get Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @return index of adc enabled, else -1 if all enabled */ - virtual int setScanTag(const int tag) = 0; + virtual int getShortFrameEnable() const = 0; /** - * Sets number of frames - @param fnum number of frames - /returns number of frames + * Get the Frequency of Frames Sent to GUI + * @return 0 for random frame requests, n for nth frame frequency */ - virtual int setNumberOfFrames(const int fnum) = 0; + virtual uint32_t getFrameToGuiFrequency() const = 0; /** - * Set enable file write - * @param i file write enable - /returns file write enable + * Get Acquisition Period + * @return acquisition period */ - virtual int setEnableFileWrite(const int i) = 0; + virtual uint64_t getAcquisitionPeriod() const = 0; + + /* + * Get Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @return number of frames expected + */ + virtual uint64_t getNumberOfFrames() const = 0; /** - * Set enable file overwrite - * @param i file overwrite enable - /returns file overwrite enable + * Get Dynamic Range or Number of Bits Per Pixel + * @return dynamic range that is 4, 8, 16 or 32 */ - virtual int setEnableOverwrite(const int i) = 0; + virtual uint32_t getDynamicRange() const = 0; /** - * Starts Receiver - activate all configuration settings to the eiger receiver and start to listen for packets - @param message is the error message if there is an error - /returns 0 on success or -1 on failure + * Get Ten Giga Enable + * @return true if 10Giga enabled, else false (1G enabled) */ - //FIXME: success == 0 or success == 1? - virtual int startReceiver(char *message=NULL) = 0; //FIXME: who allocates message[]? + virtual bool getTenGigaEnable() const = 0; + //***receiver status*** /** - * Stops Receiver - stops listening for packets - /returns success - * same as abort(). Always returns 0. + * Get Listening Status of Receiver + * @return can be idle, listening or error depending on if the receiver is listening or not */ - virtual int stopReceiver() = 0; + virtual slsReceiverDefs::runStatus getStatus() const = 0; + + + + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + + //**initial parameters*** /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments */ - virtual void abort() = 0; + virtual void configure(map config_map) = 0; + /** + * Set Bottom Enable (eiger specific, should be moved to configure, and later from client via TCPIP) + * @param b is true for bottom enabled or false for bottom disabled + */ + virtual void setBottomEnable(const bool b)= 0; -/******************************************************************************************************************* - **************************************** Added by Dhanya ********************************************************* - *******************************************************************************************************************/ + //***file parameters*** + /** + * Set File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) + * Does not check for file existence since it is created only at startReceiver + * @param c file name (max of 1000 characters) + */ + virtual void setFileName(const char c[]) = 0; /** - * Set bottom to bot - * @param bot = 1 if bottom + * Set File Path + * Checks for file directory existence before setting file path + * @param c file path (max of 1000 characters) */ - virtual void setBottom(int bot)= 0; + virtual void setFilePath(const char c[]) = 0; /** - * Returns File Index + * Set File Index of acquisition + * @param i file index of acquisition */ - virtual int getFileIndex() = 0; + virtual void setFileIndex(const uint64_t i) = 0; /** - * Returns Total Frames Caught for an entire acquisition (including all scans) + * Set Scan Tag + * @param i scan tag //FIXME: needed? (unsigned integer?) */ - virtual int getTotalFramesCaught() = 0; + virtual void setScanTag(const int i) = 0; /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) + * Set Frame Index Enable (acquisition of more than 1 frame adds '_f000000000000' to file name ) + * @param b true for frame index enable, else false */ - virtual int getFramesCaught() = 0; + virtual void setFrameIndexEnable(const bool b) = 0; /** - * Returns the frame index at start of entire acquisition (including all scans) + * Set File Write Enable + * @param b true for file write enable, else false */ - virtual uint32_t getStartAcquisitionIndex()=0; + virtual void setFileWriteEnable(const bool b) = 0; /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) + * Set File Overwrite Enable + * @param b true for file overwrite enable, else false */ - virtual uint32_t getAcquisitionIndex() = 0; + virtual void setOverwriteEnable(const bool b) = 0; /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) + * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @param b true for data compression enable, else false */ - virtual uint32_t getStartFrameIndex() = 0; + virtual void setDataCompressionEnable(const bool b) = 0; - /** get data compression, by saving only hits + + //***connection parameters*** + /** + * Set UDP Port Number + * @param i udp port number */ - virtual bool getDataCompression() = 0; + virtual void setUDPPortNo(const uint32_t i) = 0; /** - * Set receiver type - * @param det detector type - * Returns success or FAIL + * Set Second UDP Port Number (eiger specific) + * @return second udp port number */ - virtual int setDetectorType(slsReceiverDefs::detectorType det) = 0; + virtual void setUDPPortNo2(const uint32_t i) = 0; /** - * Set File Index - * @param i file index + * Set Ethernet Interface to listen to + * @param c ethernet inerface eg. eth0 (max of 1000 characters) */ - virtual int setFileIndex(int i) = 0; + virtual void setEthernetInterface(const char* c) = 0; - /** set acquisition period if a positive number + + //***connection parameters*** + /** + * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @param i index of adc enabled, else -1 if all enabled */ - virtual int64_t setAcquisitionPeriod(int64_t index) = 0; + virtual void setShortFrameEnable(const int i) = 0; /** - * Set Frame Index Needed - * @param i frame index needed + * Set the Frequency of Frames Sent to GUI + * @param i 0 for random frame requests, n for nth frame frequency */ - virtual int setFrameIndexNeeded(int i) = 0; + virtual void setFrameToGuiFrequency(const uint32_t i) = 0; /** - * Set UDP Port Number + * Set Acquisition Period + * @param i acquisition period */ - virtual void setUDPPortNo(int p) = 0; + virtual void setAcquisitionPeriod(const uint64_t i) = 0; /** - * Set UDP Port Number + * Set Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * @param i number of frames expected */ - virtual void setUDPPortNo2(int p) = 0; + virtual void setNumberOfFrames(const uint64_t i) = 0; /** - * Set Ethernet Interface or IP to listen to + * Set Dynamic Range or Number of Bits Per Pixel + * @param i dynamic range that is 4, 8, 16 or 32 */ - virtual void setEthernetInterface(char* c) = 0; + virtual void setDynamicRange(const uint32_t i) = 0; /** - * Set short frame - * @param i if shortframe i=1 + * Set Ten Giga Enable + * @param b true if 10Giga enabled, else false (1G enabled) */ - virtual int setShortFrame(int i) = 0; + virtual void setTenGigaEnable(const bool b) = 0; + + + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ + + //***initial functions*** /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request + * Set receiver type (and corresponding detector variables in derived STANDARD class) + * It is the first function called by the client when connecting to receiver + * @param d detector type + * @return OK or FAIL */ - virtual int setNFrameToGui(int i) = 0; + virtual int setDetectorType(const slsReceiverDefs::detectorType d) = 0; /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 + * Sets detector hostname (and corresponding detector variables in derived REST class) + * It is second function called by the client when connecting to receiver. + * you can call this function only once. //FIXME: is this still valid, this implemented in derived REST class? + * @param c detector hostname */ - virtual void resetTotalFramesCaught() = 0; + virtual void initialize(const char *c) = 0; + - /** enabl data compression, by saving only hits - /returns if failed + //***acquisition functions*** + /** + * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) */ - virtual int enableDataCompression(bool enable) = 0; + void resetAcquisitionCount(); /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe + * Start Listening for Packets by activating all configuration settings to receiver + * @param c error message if FAIL + * @return OK or FAIL */ - virtual int enableTenGiga(int enable = -1) = 0; + virtual int startReceiver(char *c=NULL) = 0; /** - * Returns the buffer-current frame read by receiver - * @param c pointer to current file name - * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer,it returns with the status Run_Finished */ - virtual void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex)=0; + virtual void stopReceiver() = 0; - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished + /** + * Stop Listening to Packets + * and sets status to Transmitting */ virtual void startReadout() = 0; /** * shuts down the udp sockets - * \returns if success or fail + * \returns OK or FAIL */ virtual int shutDownUDPSockets() = 0; + /** + * Get the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param startAcquisitionIndex start index of the acquisition + * @param startFrameIndex start index of the scan + */ + virtual void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex)=0; + + /** + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' + */ + virtual void abort() = 0; //FIXME: needed, isnt stopReceiver enough? + /** * Closes all files - * @param ithr thread index, -1 for all threads + * @param i thread index, -1 for all threads */ - virtual void closeFile(int ithr = -1) = 0; + virtual void closeFile(int i = -1) = 0; + + //***callback functions*** /** * Call back for start acquisition - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg) = 0; + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is + * 0 callback takes care of open,close,wrie file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything + */ + virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg) = 0; /** * Call back for acquisition finished - callback argument is - total frames caught - */ - virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg) = 0; + * callback argument is + * total frames caught + */ + virtual void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg) = 0; /** * Call back for raw data - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg) = 0; - + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) + */ + virtual void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg) = 0; + + protected: - private: }; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 2916ee6b98..04bd7000e6 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -24,6 +24,7 @@ #endif + #include #include #include @@ -199,7 +200,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Set detector hostname * @param c hostname */ - void initialize(const char *detectorHostName); + void setDetectorHostname(const char *detectorHostName); /* Returns detector hostname /returns hostname @@ -484,6 +485,224 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); + + + + + + + + + + + + + + + + + + + + + + + /** max number of writer threads */ + const static int MAX_NUM_WRITER_THREADS = 15; + + /** missing packet identifier value */ + const static uint16_t missingPacketValue = 0xFFFF; + + + /** UDP Socket between Receiver and Detector */ + genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; + + /** max packets per file **/ + int maxPacketsPerFile; + + /** Frame Index at start of an entire acquisition (including all scans) */ + uint64_t startAcquisitionIndex; + /** Complete File name */ + char savefilename[MAX_STR_LENGTH]; + + /* Measurement started */ + bool measurementStarted; + /* Acquisition started */ + bool acqStarted; + /** Frame index at start of each real time acquisition (eg. for each scan) */ + uint32_t startFrameIndex; + + /** Actual current frame index of each time acquisition (eg. for each scan) */ + uint32_t frameIndex; + + /** Pckets currently in current file, starts new file when it reaches max */ + uint32_t packetsInFile; + + /** Number of missing packets in acquisition*/ + uint32_t numTotMissingPackets; + + /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ + uint32_t numTotMissingPacketsInFile; + + /** Number of missing packets per buffer*/ + uint32_t numMissingPackets; + + /** frame index mask */ + uint32_t frameIndexMask; + + /** packet index mask */ + uint32_t packetIndexMask; + + /** frame index offset */ + int frameIndexOffset; + /** Current Frame Number */ + uint64_t currframenum; + + /** Previous Frame number from buffer */ + int prevframenum; + + /** size of one frame */ + int frameSize; + + /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ + int bufferSize; + + /** one buffer size */ + int onePacketSize; + + /** one buffer size */ + int oneDataSize; + + /** latest data */ + char* latestData; + + /** gui data ready */ + int guiDataReady; + + /** points to the data to send to gui */ + char* guiData; + + /** points to the filename to send to gui */ + char* guiFileName; + + /** fifo size */ + unsigned int fifosize; + + /** number of jobs per thread for data compression */ + int numJobsPerThread; + + /** memory allocated for the buffer */ + char *mem0[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data read */ + CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; + + /** circular fifo to store addresses of data already written and ready to be resued*/ + CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; + + /** Receiver buffer */ + char *buffer[MAX_NUM_LISTENING_THREADS]; + + /** number of writer threads */ + int numListeningThreads; + + /** number of writer threads */ + int numWriterThreads; + + /** to know if listening and writer threads created properly */ + int thread_started; + + /** current listening thread index*/ + int currentListeningThreadIndex; + + /** current writer thread index*/ + int currentWriterThreadIndex; + + /** thread listening to packets */ + pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; + + /** thread writing packets */ + pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; + + /** total frame count the listening thread has listened to */ + int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; + + /** mask showing which listening threads are running */ + volatile uint32_t listeningthreads_mask; + + /** mask showing which writer threads are running */ + volatile uint32_t writerthreads_mask; + + /** mask showing which threads have created files*/ + volatile uint32_t createfile_mask; + + /** OK if file created was successful */ + int ret_createfile; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllListeningThreads; + + /** variable used to self terminate threads waiting for semaphores */ + int killAllWritingThreads; + + + + /** footer offset is different for 1g and 10g*/ + int footer_offset; + + // TODO: not properly sure where to put these... + /** structure of an eiger image header*/ + + + + +//semaphores + /** semaphore to synchronize writer and guireader threads */ + sem_t smp; + /** semaphore to synchronize listener threads */ + sem_t listensmp[MAX_NUM_LISTENING_THREADS]; + /** semaphore to synchronize writer threads */ + sem_t writersmp[MAX_NUM_WRITER_THREADS]; + + +//mutex + /** guiDataReady mutex */ + pthread_mutex_t dataReadyMutex; + + /** mutex for status */ + pthread_mutex_t status_mutex; + + /** mutex for progress variable currframenum */ + pthread_mutex_t progress_mutex; + + /** mutex for writing data to file */ + pthread_mutex_t write_mutex; + + /** File Descriptor */ + FILE *sfilefd; + + //filter + singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + moenchCommonMode *cmSub; + bool commonModeSubtractionEnable; + +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUM_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUM_WRITER_THREADS]; +#endif + + + /** The action which decides what the user and default responsibilites to save data are + * 0 raw data ready callback takes care of open,close,write file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ + int cbAction; + + public: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 682c529802..e160608658 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -1,4 +1,4 @@ -#ifdef SLS_RECEIVER_UDP_FUNCTIONS +//#ifdef SLS_RECEIVER_UDP_FUNCTIONS /********************************************//** * @file UDPBaseImplementation.cpp * @short does all the functions for a receiver, set/get parameters, start/stop etc. @@ -23,1665 +23,416 @@ #include #include -//#include "utilities.h" - using namespace std; +/************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ UDPBaseImplementation::UDPBaseImplementation(){ -} - - -UDPBaseImplementation::~UDPBaseImplementation(){} - - -void UDPBaseImplementation::configure(map config_map){ - FILE_LOG(logWARNING) << __AT__ << "doing nothing..."; -}; - - -void UDPBaseImplementation::deleteMembers(){ - FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; -} - - -void UDPBaseImplementation::initializeMembers(){ - FILE_LOG(logWARNING) << "[WARNING] This is a base implementation, " << __func__ << " could have no effects."; -} - - -int UDPBaseImplementation::setDetectorType(detectorType det){ - cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; - cout << "Setting Receiver Type " << endl; - - deleteMembers(); - initializeMembers(); - - myDetectorType = det; - - switch(myDetectorType){ - case GOTTHARD: - cout << endl << "***** This is a GOTTHARD Receiver *****" << endl << endl; - break; - case MOENCH: - cout << endl << "***** This is a MOENCH Receiver *****" << endl << endl; - break; - case EIGER: - cout << endl << "***** This is a EIGER Receiver *****" << endl << endl; - break; - default: - cout << endl << "***** Unknown Receiver *****" << endl << endl; - return FAIL; - break; - } - /* - //moench variables - if(myDetectorType == GOTTHARD){ - fifosize = GOTTHARD_FIFO_SIZE; - packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; - onePacketSize = GOTTHARD_ONE_PACKET_SIZE; - frameSize = GOTTHARD_BUFFER_SIZE; - bufferSize = GOTTHARD_BUFFER_SIZE; - maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; - frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; - packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; - }else if(myDetectorType == MOENCH){ - fifosize = MOENCH_FIFO_SIZE; - packetsPerFrame = MOENCH_PACKETS_PER_FRAME; - onePacketSize = MOENCH_ONE_PACKET_SIZE; - frameSize = MOENCH_BUFFER_SIZE; - bufferSize = MOENCH_BUFFER_SIZE; - maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; - frameIndexMask = MOENCH_FRAME_INDEX_MASK; - frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; - packetIndexMask = MOENCH_PACKET_INDEX_MASK; - } - else if(myDetectorType == EIGER){ - fifosize = EIGER_FIFO_SIZE; - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - frameIndexMask = EIGER_FRAME_INDEX_MASK; - frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; - packetIndexMask = EIGER_PACKET_INDEX_MASK; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - if(thread_started) - createListeningThreads(true); - - numListeningThreads = MAX_NUM_LISTENING_THREADS; - } - latestData = new char[frameSize]; - - - setupFifoStructure(); - - if(createListeningThreads() == FAIL){ - cout << "ERROR: Could not create listening thread" << endl; - exit (-1); - } + //**detector parameters*** + strcpy(detHostname,""); + packetsPerFrame = 0; + acquisitionPeriod = 0; + numberOfFrames = 0; + dynamicRange = 16; + tengigaEnable = false; + bottomEnable = false; + + //***receiver parameters*** + status = IDLE; - if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; - exit (-1); + //***connection parameters*** + strcpy(eth,""); + for(int i=0;i=0) - fileIndex = i; - return getFileIndex(); -} + //not initialized + if(!strlen(fileName)) + return NULL; - -int UDPBaseImplementation::setFrameIndexNeeded(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; - frameIndexNeeded = i; - return frameIndexNeeded; + char* output = new char[MAX_STR_LENGTH]; + strcpy(output,fileName); + //freed by calling function + return output; } +char *UDPBaseImplementation::getFilePath() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; -int UDPBaseImplementation::getEnableFileWrite() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + //not initialized + if(!strlen(filePath)) + return NULL; -return enableFileWrite; + char* output = new char[MAX_STR_LENGTH]; + strcpy(output,filePath); + //freed by calling function + return output; } -int UDPBaseImplementation::setEnableFileWrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - enableFileWrite=i; - return getEnableFileWrite(); -} +uint32_t UDPBaseImplementation::getFileIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex;} -int UDPBaseImplementation::getEnableOverwrite() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; +int UDPBaseImplementation::getScanTag() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return scanTag;} - return overwrite; -} - -int UDPBaseImplementation::setEnableOverwrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - overwrite=i; - return getEnableOverwrite(); -} +bool UDPBaseImplementation::getFrameIndexEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return frameIndexEnable;} +bool UDPBaseImplementation::getFileWriteEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileWriteEnable;} +bool UDPBaseImplementation::getOverwriteEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return overwriteEnable;} +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);} -/*other parameters*/ - -slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ - return status; -} +uint64_t UDPBaseImplementation::getFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return (packetsCaught/packetsPerFrame);} +int64_t UDPBaseImplementation::getAcquisitionIndex() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; -void UDPBaseImplementation::initialize(const char *detectorHostName){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(strlen(detectorHostName)) - strcpy(detHostname,detectorHostName); + if(!totalPacketsCaught) + return -1; + return acquisitionIndex; } -char *UDPBaseImplementation::getDetectorHostname() const{ - return (char*)detHostname; -} +/***connection parameters***/ +uint32_t UDPBaseImplementation::getUDPPortNo() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[0];} -void UDPBaseImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - strcpy(eth,c); -} +uint32_t UDPBaseImplementation::getUDPPortNo2() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[1];} +char *UDPBaseImplementation::getEthernetInterface() const{ + FILE_LOG(logDEBUG) << __AT__ << " starting"; -void UDPBaseImplementation::setUDPPortNo(int p){ - server_port[0] = p; + char* output = new char[MAX_STR_LENGTH]; + strcpy(output,eth); + //freed by calling function + return output; } -void UDPBaseImplementation::setUDPPortNo2(int p){ - server_port[1] = p; -} +/***acquisition parameters***/ +int UDPBaseImplementation::getShortFrameEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return shortFrameEnable;} +uint32_t UDPBaseImplementation::getFrameToGuiFrequency() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return FrameToGuiFrequency;} -int UDPBaseImplementation::getNumberOfFrames() const { - return numberOfFrames; -} +uint64_t UDPBaseImplementation::getAcquisitionPeriod() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return acquisitionPeriod;} +uint64_t UDPBaseImplementation::getNumberOfFrames() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return numberOfFrames;} -int32_t UDPBaseImplementation::setNumberOfFrames(int32_t fnum){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(fnum >= 0) - numberOfFrames = fnum; +uint32_t UDPBaseImplementation::getDynamicRange() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return dynamicRange;} - return getNumberOfFrames(); -} +bool UDPBaseImplementation::getTenGigaEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return tengigaEnable;} +/***receiver status***/ +slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return status;} -int UDPBaseImplementation::getScanTag() const{ - return scanTag; -} -int32_t UDPBaseImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(stag >= 0) - scanTag = stag; - return getScanTag(); -} +/************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ - -int UDPBaseImplementation::getDynamicRange() const{ - return dynamicRange; +/**initial parameters***/ +void UDPBaseImplementation::configure(map config_map){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; } -int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - cout << "Setting Dynamic Range" << endl; - - int olddr = dynamicRange; - if(dr >= 0){ - dynamicRange = dr; - - if(myDetectorType == EIGER){ - - - if(!tengigaEnable) - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - else - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - - if(olddr != dr){ - - //del - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - for(int i=0;i=0){ - nFrameToGui = i; - setupFifoStructure(); - } - return nFrameToGui; + if(strlen(c)) + strcpy(fileName, c); + FILE_LOG(logINFO) << "File name:" << fileName; } +void UDPBaseImplementation::setFilePath(const char c[]){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; - -int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - if(index >= 0){ - if(index != acquisitionPeriod){ - acquisitionPeriod = index; - setupFifoStructure(); + if(strlen(c)){ + //check if filepath exists + struct stat st; + if(stat(c,&st) == 0) + strcpy(filePath,c); + else{ + strcpy(filePath,""); + FILE_LOG(logWARNING) << "FilePath does not exist:" << filePath; } + strcpy(filePath, c); } - return acquisitionPeriod; + FILE_LOG(logINFO) << "File path:" << filePath; } +void UDPBaseImplementation::setFileIndex(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; -bool UDPBaseImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return dataCompression;} - -int UDPBaseImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - cout << "Data compression "; - if(enable) - cout << "enabled" << endl; - else - cout << "disabled" << endl; -#ifdef MYROOT1 - cout << " WITH ROOT" << endl; -#else - cout << " WITHOUT ROOT" << endl; -#endif - //delete filter for the current number of threads - deleteFilter(); - - dataCompression = enable; - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - createWriterThreads(true); - - if(enable) - numWriterThreads = MAX_NUM_WRITER_THREADS; - else - numWriterThreads = 1; - - if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"ERROR: Could not create writer threads\n"); - return FAIL; - } - setThreadPriorities(); - - - if(enable) - setupFilter(); - - return OK; + fileIndex = i; + FILE_LOG(logINFO) << "File Index:" << fileIndex; } +//FIXME: needed? +void UDPBaseImplementation::setScanTag(const int i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + scanTag = i; + FILE_LOG(logINFO) << "Scan Tag:" << scanTag; - - - - - - - - - -/*other functions*/ - - -void UDPBaseImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i; - cmSub=NULL; - - for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); - + frameIndexEnable = b; + FILE_LOG(logINFO) << "Frame Index Enable:" << frameIndexEnable; } +void UDPBaseImplementation::setFileWriteEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; - -//LEO: it is not clear to me.. -void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - + fileWriteEnable = b; + FILE_LOG(logINFO) << "File Write Enable:" << fileWriteEnable; } +void UDPBaseImplementation::setOverwriteEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; - - - - - -/** acquisition functions */ -void UDPBaseImplementation::readFrame(char* c,char** raw,uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - //point to gui data - if (guiData == NULL){ - guiData = latestData; - } - - //copy data and filename - strcpy(c,guiFileName); - startAcquisitionIndex = getStartAcquisitionIndex(); - startFrameIndex = getStartFrameIndex(); - - - //could not get gui data - if(!guiDataReady){ - *raw = NULL; - } - //data ready, set guidata to receive new data - else{ - *raw = guiData; - guiData = NULL; - if((nFrameToGui) && (writerthreads_mask)){ - //release after getting data - sem_post(&smp); - } - } + overwriteEnable = b; + FILE_LOG(logINFO) << "Overwrite Enable:" << overwriteEnable; } +void UDPBaseImplementation::setDataCompressionEnable(const bool b){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; - - - - -void UDPBaseImplementation::copyFrameToGui(char* startbuf[], char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - + dataCompressionEnable = b; + FILE_LOG(logINFO) << "Data Compression Enable:" << dataCompressionEnable; } +/***connection parameters***/ +void UDPBaseImplementation::setUDPPortNo(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; - -int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - //if eth is mistaken with ip address - if (strchr(eth,'.')!=NULL) - strcpy(eth,""); - - shutDownUDPSockets(); - - //if no eth, listen to all - if(!strlen(eth)){ - cout<<"warning:eth is empty.listening to all"<getErrorStatus(); - if(iret){ -#ifdef VERBOSE - cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n",server_port[i], iret); -#endif - return FAIL; - } - } - - return OK; + udpPortNum[0] = i; + FILE_LOG(logINFO) << "udpPortNum[0]:" << udpPortNum[0]; } +void UDPBaseImplementation::setUDPPortNo2(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; - - - - - -int UDPBaseImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - for(int i=0;iShutDownSocket(); - delete udpSocket[i]; - udpSocket[i] = NULL; - } - } - return OK; + udpPortNum[1] = i; + FILE_LOG(logINFO) << "udpPortNum[1]:" << udpPortNum[1]; } +void UDPBaseImplementation::setEthernetInterface(const char* c){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; - - - -int UDPBaseImplementation::createListeningThreads(bool destroy){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i; - void* status; - - killAllListeningThreads = 0; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - if(!destroy){ - - //start listening threads - cout << "Creating Listening Threads(s)"; - - currentListeningThreadIndex = -1; - - for(i = 0; i < numListeningThreads; ++i){ - sem_init(&listensmp[i],1,0); - thread_started = 0; - currentListeningThreadIndex = i; - if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ - cout << "Could not create listening thread with index " << i << endl; - return FAIL; - } - while(!thread_started); - cout << "."; - cout << flush; - } -#ifdef VERBOSE - cout << "Listening thread(s) created successfully." << endl; -#else - cout << endl; -#endif - }else{ - cout<<"Destroying Listening Thread(s)"<initEventTree(temp, &iframe); - //resets the pedestalSubtraction array and the commonModeSubtraction - singlePhotonDet[ithr]->newDataSet(); - if(myFile[ithr]==NULL){ - cout<<"file null"<IsOpen()){ - cout<<"file not open"< DO_NOTHING){ - //close - if(sfilefd){ - fclose(sfilefd); - sfilefd = NULL; - } - //open file - if(!overwrite){ - if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cout << "Error: Could not create new file " << savefilename << endl; - return FAIL; - } - }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not creat dsdasdserwe file " << savefilename << endl; - return FAIL; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - - //printing packet losses and file names - if(!packetsCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)<GetCurrentFile(); - - if(myFile[ithr]->Write()) - //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Thread " << ithr <<": wrote frames to file" << endl; - else - cout << "Thread " << ithr << ": could not write frames to file" << endl; - - }else - cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; - //close file - if(myTree[ithr] && myFile[ithr]) - myFile[ithr] = myTree[ithr]->GetCurrentFile(); - if(myFile[ithr] != NULL) - myFile[ithr]->Close(); - myFile[ithr] = NULL; - myTree[ithr] = NULL; - pthread_mutex_unlock(&write_mutex); - -#endif - } - */ - FILE_LOG(logDEBUG) << __AT__ << "exited"; - + tengigaEnable = b; + FILE_LOG(logINFO) << "Ten Giga Enable:" << tengigaEnable; } +/************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ +/***initial functions***/ +int UDPBaseImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; -int UDPBaseImplementation::startReceiver(char message[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int i; - - -// #ifdef VERBOSE - cout << "Starting Receiver" << endl; -//#endif - - - //reset listening thread variables - measurementStarted = false; - //should be set to zero as its added to get next start frame indices for scans for eiger - if(!acqStarted) currframenum = 0; - startFrameIndex = 0; - - for(int i = 0; i < numListeningThreads; ++i) - totalListeningFrameCount[i] = 0; - - //udp socket - if(createUDPSockets() == FAIL){ - strcpy(message,"Could not create UDP Socket(s).\n"); - cout << endl << message << endl; - return FAIL; - } - cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; - - - if(setupWriter() == FAIL){ - //stop udp socket - shutDownUDPSockets(); - - sprintf(message,"Could not create file %s.\n",savefilename); - return FAIL; - } - cout << "Successfully created file(s)" << endl; - - //done to give the gui some proper name instead of always the last file name - if(dataCompression) - sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); - - //initialize semaphore - sem_init(&smp,1,0); - - //status - pthread_mutex_lock(&status_mutex); - status = RUNNING; - for(i=0;istartListening(); - - return this_pointer; +int UDPBaseImplementation::startReceiver(char *c=NULL){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; + return OK; } - - -void* UDPBaseImplementation::startWritingThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - ((UDPBaseImplementation*)this_pointer)->startWriting(); - return this_pointer; +void UDPBaseImplementation::stopReceiver(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; } - - - - - -int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - int ithread = currentListeningThreadIndex; -#ifdef VERYVERBOSE - cout << "In startListening() " << endl; -#endif - - thread_started = 1; - - int total; - int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader;// for moench to check for all the packets in last frame - char* tempchar = NULL; - int imageheader = 0; - if(myDetectorType==EIGER) - imageheader = EIGER_IMAGE_HEADER_SIZE; - - - while(1){ - //variables that need to be checked/set before each acquisition - carryonBufferSize = 0; - //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later - maxBufferSize = bufferSize * numJobsPerThread; -#ifdef VERYDEBUG - cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; -#endif - - if(tempchar) {delete [] tempchar;tempchar = NULL;} - if(myDetectorType != EIGER) - tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - - - while((1<pop(buffer[ithread]); -#ifdef VERYDEBUG - cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; -#endif - - - //receive - if(udpSocket[ithread] == NULL){ - rc = 0; - cout << ithread << "UDP Socket is NULL" << endl; - } - //normal listening - else if(!carryonBufferSize){ - - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - expected = maxBufferSize; - - } - //the remaining packets from previous buffer - else{ -#ifdef VERYDEBUG - cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; - cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) - & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); - expected = maxBufferSize - carryonBufferSize; - } - -#ifdef VERYDEBUG - cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif - - - - - //start indices for each start of scan/acquisition - eiger does it before - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); - - //problem in receiving or end of acquisition - if((rc < expected)||(rc <= 0)){ - stopListening(ithread,rc,packetcount,total); - continue; - } - - - - //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - - - - //check if last packet valid and calculate packet count - switch(myDetectorType){ - - case MOENCH: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; - cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; - cout << "last packet offset:" << lastpacketoffset << endl; - cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; - cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - //moench last packet value is 0 - if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ - lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) - & (frameIndexMask)) >> frameIndexOffset) << endl; - cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask)) << endl; -#endif - } - break; - - case GOTTHARD: - if(shortFrame == -1){ - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout << "last packet offset:" << lastpacketoffset << endl; -#endif - - if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ - memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - carryonBufferSize = onePacketSize; - --packetcount; - } - } -#ifdef VERYDEBUG - cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - break; - default: - - break; - - } - - - // cout<<"*********** "<fnum)<push(buffer[ithread])); -#ifdef VERYDEBUG - if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; -#endif - } - - sem_wait(&listensmp[ithread]); - - //make sure its not exiting thread - if(killAllListeningThreads){ - cout << ithread << " good bye listening thread" << endl; - if(tempchar) {delete [] tempchar;tempchar = NULL;} - pthread_exit(NULL); - } - } - - return OK; +void UDPBaseImplementation::startReadout(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; } - - - - - - - - - - - - -int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - return OK; +int UDPBaseImplementation::shutDownUDPSockets(){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; } - - - -void UDPBaseImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - - - +void UDPBaseImplementation::readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex){ + FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; + FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; } - - -void UDPBaseImplementation::stopListening(int ithread, int rc, int &pc, int &t){ FILE_LOG(logDEBUG) << __AT__ << " starting"; -int i; - -#ifdef VERYVERBOSE - cerr << ithread << " recvfrom() failed:"<push(buffer[ithread]); - exit(-1); - } - //push the last buffer into fifo - if(rc > 0){ - pc = (rc/onePacketSize); -#ifdef VERYDEBUG - cout << ithread << " *** last packetcount:" << pc << endl; -#endif - (*((uint16_t*)(buffer[ithread]))) = pc; - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; -#endif - } - - - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); - (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; -#ifdef VERYDEBUG - cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -#endif - } - - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1< 1) - cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; -#endif - while(listeningthreads_mask) - usleep(5000); -#ifdef VERYDEBUG - t = 0; - for(i=0;ipush(wbuffer[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; -#endif - } - - - - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&status_mutex); - writerthreads_mask^=(1<= 0){ - - tengigaEnable = enable; - - if(myDetectorType == EIGER){ - - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; - } - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - cout<<"packetsPerFrame:"<*flist[fnum])(); if (ret==FAIL) - cout << "Error executing the function = " << fnum << endl; + cprintf(RED, "Error executing the function = %d\n",fnum); return ret; } @@ -358,7 +358,7 @@ void slsReceiverTCPIPInterface::staticCloseFile(int p){ int slsReceiverTCPIPInterface::set_detector_type(){ ret=OK; - int retval=FAIL; + detectorType retval=GENERIC; detectorType dr; strcpy(mess,"Could not set detector type range\n"); @@ -377,20 +377,35 @@ int slsReceiverTCPIPInterface::set_detector_type(){ ret=FAIL; } else{ - myDetectorType = dr; + + switch(dr){ + case GOTTHARD: + case PROPIX: + case MOENCH: + case EIGER: + case JUNGFRAUCTB: + case JUNGFRAU: + break; + default: + sprintf(mess,"Unknown detector type: %d\n", dr); + ret = FAIL; + break; + if(ret != FAIL){ #ifndef REST - receiverBase = UDPInterface::create("standard"); - receiverBase->setBottom(bottom); + receiverBase = UDPInterface::create("standard"); + receiverBase->setBottomEnable(bottom); #endif - ret=receiverBase->setDetectorType(dr); - retval = myDetectorType; + myDetectorType = dr; + ret=receiverBase->setDetectorType(myDetectorType); + retval = myDetectorType; + } + } } - } //#ifdef VERBOSE if(ret!=FAIL) cout << "detector type" << dr << endl; else - cout << mess << endl; + cprintf(RED, "%s\n", mess); //#endif #endif @@ -417,7 +432,8 @@ int slsReceiverTCPIPInterface::set_detector_type(){ int slsReceiverTCPIPInterface::set_file_name() { ret=OK; - char retval[MAX_STR_LENGTH]=""; + char* retval[MAX_STR_LENGTH] = NULL; + char defaultVal[MAX_STR_LENGTH] = ""; char fName[MAX_STR_LENGTH]; strcpy(mess,"Could not set file name"); @@ -439,8 +455,12 @@ int slsReceiverTCPIPInterface::set_file_name() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else - strcpy(retval,receiverBase->setFileName(fName)); + else{ + receiverBase->setFileName(fName); + retval = receiveBase->getFileName(); + if(retval == NULL) + ret = FAIL; + } } #ifdef VERBOSE if(ret!=FAIL) @@ -457,9 +477,15 @@ int slsReceiverTCPIPInterface::set_file_name() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); - socket->SendDataOnly(retval,MAX_STR_LENGTH); + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + }else + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //free + if(retval != NULL) delete[] retval; //return ok/fail return ret; @@ -472,7 +498,8 @@ int slsReceiverTCPIPInterface::set_file_name() { int slsReceiverTCPIPInterface::set_file_dir() { ret=OK; - char retval[MAX_STR_LENGTH]=""; + char* retval=NULL; + char defaultVal[MAX_STR_LENGTH] = ""; char fPath[MAX_STR_LENGTH]; strcpy(mess,"Could not set file path\n"); @@ -498,13 +525,12 @@ int slsReceiverTCPIPInterface::set_file_dir() { ret=FAIL; } else{ - strcpy(retval,receiverBase->setFilePath(fPath)); - // if file path doesnt exist - if(strlen(fPath)) - if (strcmp(retval,fPath)){ - strcpy(mess,"receiver file path does not exist\n"); - ret=FAIL; - } + receiverBase->setFilePath(fPath); + retval = receiveBase->getFilePath(); + if(reval == NULL){ + ret = FAIL; + strcpy(mess,"receiver file path does not exist\n"); + } } } @@ -523,9 +549,15 @@ int slsReceiverTCPIPInterface::set_file_dir() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); - socket->SendDataOnly(retval,MAX_STR_LENGTH); + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + }else + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //free + if(retval != NULL) delete[] retval; //return ok/fail return ret; @@ -560,8 +592,13 @@ int slsReceiverTCPIPInterface::set_file_index() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else - retval=receiverBase->setFileIndex(index); + else{ + if(index >= 0) + receiverBase->setFileIndex(index); + retval=receiverBase->getFileIndex(); + if(index>=0 && retval!=index) + ret = FAIL; + } } #ifdef VERBOSE if(ret!=FAIL) @@ -578,8 +615,10 @@ int slsReceiverTCPIPInterface::set_file_index() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -617,8 +656,22 @@ int slsReceiverTCPIPInterface::set_frame_index() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else - retval=receiverBase->setFrameIndexNeeded(index); + else{ + //client sets to 0, but for receiver it is just an enable + //client uses this value for other detectors not using receiver, + //so implement the interface here + + switch(index){ + case -1: index=0; break; + default: index=1; break; //value is 0 + } + receiverBase->setFrameIndexEnable(index); + retval=receiverBase->getFrameIndexEnable(); + switch(retval){ + case 0: retval=-1; break; + case 1: retval=0; break; + } + } } #ifdef VERBOSE if(ret!=FAIL) @@ -635,8 +688,10 @@ int slsReceiverTCPIPInterface::set_frame_index() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -652,7 +707,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { int slsReceiverTCPIPInterface::setup_udp(){ ret=OK; strcpy(mess,"could not set up udp connection"); - char retval[MAX_STR_LENGTH]=""; + char retval[MAX_STR_LENGTH] = ""; char args[3][MAX_STR_LENGTH]; string temp; @@ -705,8 +760,8 @@ int slsReceiverTCPIPInterface::setup_udp(){ } FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; receiverBase->setEthernetInterface(eth); - cout << eth << endl; + //get mac address from ethernet interface if (ret != FAIL) temp = genericSocket::nameToMac(eth); @@ -715,7 +770,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ if ((temp=="00:00:00:00:00:00") || (ret == FAIL)){ ret = FAIL; strcpy(mess,"failed to get mac adddress to listen to\n"); - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); } else{ strcpy(retval,temp.c_str()); @@ -733,8 +788,10 @@ int slsReceiverTCPIPInterface::setup_udp(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(retval,MAX_STR_LENGTH); //return ok/fail @@ -749,8 +806,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ int slsReceiverTCPIPInterface::start_receiver(){ ret=OK; ret=OK; - enum runStatus s; - char cstatus[15]; + enum runStatus s = ERROR; strcpy(mess,"Could not start receiver\n"); // execute action if the arguments correctly arrived @@ -771,22 +827,13 @@ int slsReceiverTCPIPInterface::start_receiver(){ } else { s = receiverBase->getStatus(); - switch (s) { - case ERROR: strcpy(cstatus,"error"); break; - case WAITING: strcpy(cstatus,"waiting"); break; - case RUNNING: strcpy(cstatus,"running"); break; - case TRANSMITTING: strcpy(cstatus,"data"); break; - case RUN_FINISHED: strcpy(cstatus,"finished"); break; - default: strcpy(cstatus,"idle"); break; - } if(s == IDLE) ret=receiverBase->startReceiver(mess); else{ - sprintf(mess,"Cannot start Receiver as it is in %s state\n",cstatus); + sprintf(mess,"Cannot start Receiver as it is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); ret=FAIL; } } - #endif if(ret==OK && socket->differentClients){ @@ -797,6 +844,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); } //return ok/fail @@ -808,7 +856,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ int slsReceiverTCPIPInterface::stop_receiver(){ ret=OK; - + enum runStatus s = ERROR; strcpy(mess,"Could not stop receiver\n"); // execute action if the arguments correctly arrived @@ -821,8 +869,17 @@ int slsReceiverTCPIPInterface::stop_receiver(){ strcpy(mess,"Receiver not set up\n"); ret=FAIL; } - else if(receiverBase->getStatus()!=IDLE) - ret=receiverBase->stopReceiver(); + else{ + if(receiverBase->getStatus()!=IDLE) + receiverBase->stopReceiver(); + s = receiverBase->getStatus(); + if(s==IDLE) + ret = OK; + else{ + sprintf(mess,"Could not stop receiver. It is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); + ret = FAIL; + } + } #endif if(ret==OK && socket->differentClients){ @@ -832,8 +889,10 @@ int slsReceiverTCPIPInterface::stop_receiver(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } //return ok/fail return ret; @@ -860,8 +919,10 @@ int slsReceiverTCPIPInterface::get_status(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -888,8 +949,10 @@ int slsReceiverTCPIPInterface::get_frames_caught(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -918,8 +981,10 @@ int slsReceiverTCPIPInterface::get_frame_index(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -946,7 +1011,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ ret=FAIL; } else - receiverBase->resetTotalFramesCaught(); + receiverBase->resetAcquisitionCount(); } #endif @@ -957,9 +1022,10 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); - + } //return ok/fail return ret; @@ -1006,7 +1072,8 @@ int slsReceiverTCPIPInterface::set_short_frame() { ret=FAIL; } else{ - retval=receiverBase->setShortFrame(index); + receiverBase->setShortFrameEnable(index); + retval = receiverBase->getShortFrameEnable(); shortFrame = retval; if(shortFrame==-1) packetsPerFrame=GOTTHARD_PACKETS_PER_FRAME; @@ -1023,8 +1090,10 @@ int slsReceiverTCPIPInterface::set_short_frame() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -1088,7 +1157,6 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ else{ ret = OK; - /*startIndex=receiverBase->getStartFrameIndex();*/ receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ @@ -1203,7 +1271,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1277,7 +1345,6 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ cout<<"haven't caught any frame yet"<getStartFrameIndex();*/ receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ @@ -1385,7 +1452,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1453,7 +1520,6 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ cout<<"haven't caught any frame yet"<getStartFrameIndex();*/ receiverBase->readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); /**send garbage with -1 index to try again*/ @@ -1540,7 +1606,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1802,7 +1868,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cout << "mess:" << mess << endl; + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); } else{ @@ -1855,8 +1921,13 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ ret = FAIL; strcpy(mess,"cannot set up receiver mode when receiver is running\n"); }*/ - else - retval=receiverBase->setNFrameToGui(index); + else{ + if(index >= 0) + receiverBase->setFrameToGuiFrequency(index); + retval=receiverBase->getFrameToGuiFrequency(); + if(index>=0 && retval!=index) + ret = FAIL; + } } #endif @@ -1868,8 +1939,10 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -1907,9 +1980,9 @@ int slsReceiverTCPIPInterface::enable_file_write(){ } else{ if(enable >= 0) - receiverBase->setEnableFileWrite(enable); - retval=receiverBase->getEnableFileWrite(); - if((enable!=-1)&&(enable!=retval)) + receiverBase->setFileWriteEnable(enable); + retval=receiverBase->getFileWriteEnable(); + if(enable>=0 && enable!=retval) ret=FAIL; } } @@ -1922,8 +1995,10 @@ int slsReceiverTCPIPInterface::enable_file_write(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -1991,8 +2066,10 @@ int slsReceiverTCPIPInterface::start_readout(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail return ret; @@ -2029,10 +2106,17 @@ int slsReceiverTCPIPInterface::set_timer() { ret=FAIL; } else{ - if(index[0] == slsReceiverDefs::FRAME_PERIOD) - retval=receiverBase->setAcquisitionPeriod(index[1]); - else - retval=receiverBase->setNumberOfFrames(index[1]); + if(index[0] == slsReceiverDefs::FRAME_PERIOD){ + if(index[1]>=0) + receiverBase->setAcquisitionPeriod(index[1]); + retval=receiverBase->getAcquisitionPeriod(); + }else{ + if(index[1]>=0) + receiverBase->setNumberOfFrames(index[1]); + retval=receiverBase->getNumberOfFrames(); + } + if(index[1]>=0 && retval!=index[1]) + ret = FAIL; } } #ifdef VERBOSE @@ -2053,8 +2137,10 @@ int slsReceiverTCPIPInterface::set_timer() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2095,15 +2181,21 @@ int slsReceiverTCPIPInterface::enable_compression() { strcpy(mess,"Cannot enable/disable compression while status is running\n"); ret=FAIL; } - else - ret = receiverBase->enableDataCompression(enable); + else{ + if(enable >= 0) + receiverBase->setDataCompressionEnable(enable); + } } if (receiverBase == NULL){ strcpy(mess,"Receiver not set up\n"); ret=FAIL; - }else - retval=receiverBase->getDataCompression(); + }else{ + retval = receiverBase->getDataCompressionEnable(); + if(enable >= 0 && retval != enable) + ret = FAIL; + } + } #endif @@ -2114,8 +2206,10 @@ int slsReceiverTCPIPInterface::enable_compression() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2127,7 +2221,8 @@ int slsReceiverTCPIPInterface::enable_compression() { int slsReceiverTCPIPInterface::set_detector_hostname() { ret=OK; - char retval[MAX_STR_LENGTH]=""; + char* retval = NULL; + char defaultVal[MAX_STR_LENGTH] = ""; char hostname[MAX_STR_LENGTH]=""; strcpy(mess,"Could not set detector hostname"); @@ -2151,7 +2246,10 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { } else{ receiverBase->initialize(hostname); - strcpy(retval,receiverBase->getDetectorHostname()); + retval = receiverBase->getDetectorHostname(); + if(retval == NULL){ + ret = FAIL; + } } } #ifdef VERBOSE @@ -2169,9 +2267,14 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); - socket->SendDataOnly(retval,MAX_STR_LENGTH); + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + }else socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //free + if(retval!=NULL) delete[] retval; //return ok/fail return ret; @@ -2203,14 +2306,14 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else if ((dr>0) && (myDetectorType == EIGER)){ + else if (dr>0) { switch(dr){ case 4: case 8: case 16: case 32:break; default: - sprintf(mess,"This dynamic range does not exist for eiger: %d\n",dr); + sprintf(mess,"This dynamic range does not exist: %d\n",dr); cprintf(RED,"%s", mess); ret=FAIL; break; @@ -2221,14 +2324,19 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; }else{ - if(dr > 0) receiverBase->setDynamicRange(dr); + if(dr > 0) + receiverBase->setDynamicRange(dr); retval = receiverBase->getDynamicRange(); - dynamicrange = retval; - if(myDetectorType == EIGER){ - if(!tenGigaEnable) - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; - else - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + if(dr > 0 && retval != dr) + ret = FAIL; + else{ + dynamicrange = retval; + if(myDetectorType == EIGER){ + if(!tenGigaEnable) + packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + else + packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; + } } } } @@ -2248,8 +2356,10 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2288,8 +2398,10 @@ int slsReceiverTCPIPInterface::enable_overwrite() { } else{ if(index >= 0) - receiverBase->setEnableOverwrite(index); - retval=receiverBase->getEnableOverwrite(); + receiverBase->setOverwriteEnable(index); + retval=receiverBase->getOverwriteEnable(); + if(index >=0 && retval != index) + ret = FAIL; } } #ifdef VERBOSE @@ -2307,8 +2419,10 @@ int slsReceiverTCPIPInterface::enable_overwrite() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2346,8 +2460,10 @@ int slsReceiverTCPIPInterface::enable_tengiga() { ret=FAIL; } else{ - retval=receiverBase->enableTenGiga(val); - if((val!=-1) && (val != retval)) + if(val >= 0) + receiverBase->setDataCompressionEnable(val); + retval=receiverBase->getDataCompressionEnable(); + if((val >= 0) && (val != retval)) ret = FAIL; else tenGigaEnable = retval; @@ -2368,8 +2484,10 @@ int slsReceiverTCPIPInterface::enable_tengiga() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if(ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } socket->SendDataOnly(&retval,sizeof(retval)); //return ok/fail @@ -2436,8 +2554,10 @@ int slsReceiverTCPIPInterface::lock_receiver() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); + } else socket->SendDataOnly(&lockStatus,sizeof(lockStatus)); @@ -2509,9 +2629,10 @@ int slsReceiverTCPIPInterface::set_port() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); - } else { + }else { socket->SendDataOnly(&p_number,sizeof(p_number)); if(sd>=0){ socket->Disconnect(); @@ -2550,7 +2671,8 @@ int slsReceiverTCPIPInterface::get_last_client_ip() { int slsReceiverTCPIPInterface::send_update() { ret=OK; int ind; - char path[MAX_STR_LENGTH]; + char defaultVal[MAX_STR_LENGTH]=""; + char* path = NULL; socket->SendDataOnly(socket->lastClientIP,sizeof(socket->lastClientIP)); @@ -2564,17 +2686,26 @@ int slsReceiverTCPIPInterface::send_update() { //filepath #ifdef SLS_RECEIVER_UDP_FUNCTIONS - strcpy(path,receiverBase->getFilePath()); + path = receiverBase->getFilePath(); #endif - socket->SendDataOnly(path,MAX_STR_LENGTH); + if(path == NULL) + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + else{ + socket->SendDataOnly(path,MAX_STR_LENGTH); + delete[] path; + } //filename #ifdef SLS_RECEIVER_UDP_FUNCTIONS - strcpy(path,receiverBase->getFileName()); + path = receiverBase->getFileName(); #endif - socket->SendDataOnly(path,MAX_STR_LENGTH); - + if(path == NULL) + socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); + else{ + socket->SendDataOnly(path,MAX_STR_LENGTH); + delete[] path; + } if (lockStatus==0) { strcpy(socket->lastClientIP,socket->thisClientIP); @@ -2597,7 +2728,8 @@ int slsReceiverTCPIPInterface::update_client() { ret=FAIL; } socket->SendDataOnly(&ret,sizeof(ret)); - if(ret == FAIL){ + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); socket->SendDataOnly(mess,sizeof(mess)); return ret; } @@ -2616,7 +2748,7 @@ int slsReceiverTCPIPInterface::exit_server() { socket->SendDataOnly(&ret,sizeof(ret)); strcpy(mess,"closing server"); socket->SendDataOnly(mess,sizeof(mess)); - cout << mess << endl; + cprintf(RED,"%s\n",mess); return ret; } From 9148f6365ece80e42b83ed66f130686af13883cf Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 2 Oct 2015 12:05:16 +0200 Subject: [PATCH 147/222] changed last packet value literal to expression, not big in functionality --- .../src/UDPStandardImplementation.cpp | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 609f4fea7d..84a5fedbad 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1970,19 +1970,6 @@ int UDPStandardImplementation::startWriting(){ eiger_packet_header_t* blankframe_header=0; unsigned char* blankframe_data=0; - //last packet numbers for different dynamic ranges - if(myDetectorType == EIGER){ - switch(dynamicRange){ - case 4: LAST_PACKET_VALUE = 0x40; break; - case 8: LAST_PACKET_VALUE = 0x80; break; - case 16: LAST_PACKET_VALUE = 0x100; break; - case 32: LAST_PACKET_VALUE = 0x200; break; - default: break; - } - - } - - while(1){ @@ -2030,15 +2017,8 @@ int UDPStandardImplementation::startWriting(){ #endif } - if(tengigaEnable){ - switch(dynamicRange){ - case 4: LAST_PACKET_VALUE = 0x10; break; - case 8: LAST_PACKET_VALUE = 0x20; break; - case 16: LAST_PACKET_VALUE = 0x40; break; - case 32: LAST_PACKET_VALUE = 0x80; break; - default: break; - } - } + //last packet numbers for different dynamic ranges + LAST_PACKET_VALUE = (packetsPerFrame/numListeningThreads); } From a3e88f96d6d1cfd2ad050006dc632c88437c8715 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 8 Oct 2015 12:19:07 +0200 Subject: [PATCH 148/222] some more changes --- .../include/UDPBaseImplementation.h | 67 +- slsReceiverSoftware/include/UDPInterface.h | 30 +- .../include/UDPStandardImplementation.h | 640 +++--- slsReceiverSoftware/include/receiver_defs.h | 8 +- slsReceiverSoftware/include/slsReceiver.h | 1 - .../include/sls_receiver_defs.h | 10 + .../src/UDPBaseImplementation.cpp | 91 +- slsReceiverSoftware/src/UDPInterface.cpp | 4 +- .../src/UDPStandardImplementation.cpp | 1766 ++++++++--------- .../src/slsReceiverTCPIPInterface.cpp | 43 +- 10 files changed, 1373 insertions(+), 1287 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 29d9dd009a..293ac67631 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -7,13 +7,12 @@ ***********************************************/ -#include "sls_receiver_defs.h" +//#include "sls_receiver_defs.h" #include "UDPInterface.h" -#include -#include +//#include /** - * @short does all the functions for a receiver, set/get parameters, start/stop etc. + * @short does all the base functions for a receiver, set/get parameters, start/stop etc. */ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInterface { @@ -123,13 +122,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Get UDP Port Number * @return udp port number */ - uint32_t getUDPPortNo() const; + uint32_t getUDPPortNumber() const; /** * Get Second UDP Port Number (eiger specific) * @return second udp port number */ - uint32_t getUDPPortNo2() const; + uint32_t getUDPPortNumber2() const; /** * Get Ehernet Interface @@ -254,9 +253,9 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) * @param b true for data compression enable, else false + * @return OK or FAIL */ - void setDataCompressionEnable(const bool b); - + int setDataCompressionEnable(const bool b); //***connection parameters*** @@ -264,13 +263,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Set UDP Port Number * @param i udp port number */ - void setUDPPortNo(const uint32_t i); + void setUDPPortNumber(const uint32_t i); /** * Set Second UDP Port Number (eiger specific) * @return second udp port number */ - void setUDPPortNo2(const uint32_t i); + void setUDPPortNumber2(const uint32_t i); /** * Set Ethernet Interface to listen to @@ -279,7 +278,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter void setEthernetInterface(const char* c); - //***connection parameters*** + //***acquisition parameters*** /** * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) * @param i index of adc enabled, else -1 if all enabled @@ -289,14 +288,16 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** * Set the Frequency of Frames Sent to GUI * @param i 0 for random frame requests, n for nth frame frequency + * @return OK or FAIL */ - void setFrameToGuiFrequency(const uint32_t i); + int setFrameToGuiFrequency(const uint32_t i); /** * Set Acquisition Period * @param i acquisition period + * @return OK or FAIL */ - void setAcquisitionPeriod(const uint64_t i); + int setAcquisitionPeriod(const uint64_t i); /** * Set Number of Frames expected by receiver from detector @@ -308,15 +309,16 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** * Set Dynamic Range or Number of Bits Per Pixel * @param i dynamic range that is 4, 8, 16 or 32 + * @return OK or FAIL */ - void setDynamicRange(const uint32_t i); + int setDynamicRange(const uint32_t i); /** * Set Ten Giga Enable * @param b true if 10Giga enabled, else false (1G enabled) + * @return OK or FAIL */ - void setTenGigaEnable(const bool b); - + int setTenGigaEnable(const bool b); /************************************************************************* @@ -324,6 +326,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * They may modify the status of the receiver **************************** *************************************************************************/ + //***initial functions*** /** * Set receiver type (and corresponding detector variables in derived STANDARD class) @@ -387,7 +390,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * abort acquisition with minimum damage: close open files, cleanup. * does nothing if state already is 'idle' */ - void abort(); //FIXME: needed, isnt stopReceiver enough? + void abort(); //FIXME: needed, isn't stopReceiver enough? /** * Closes all files @@ -436,36 +439,12 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter protected: //**detector parameters*** - /** - * structure of an eiger packet header - * subframenum subframe number for 32 bit mode (already written by firmware) - * missingpacket explicitly put to 0xFF to recognize it in file read (written by software) - * portnum 0 for the first port and 1 for the second port (written by software to file) - * dynamicrange dynamic range or bits per pixel (written by software to file) - */ - typedef struct { - unsigned char subframenum[4]; - unsigned char missingpacket[2]; - unsigned char portnum[1]; - unsigned char dynamicrange[1]; - } eiger_packet_header_t; - /** - * structure of an eiger packet footer - * framenum 48 bit frame number (already written by firmware) - * packetnum packet number (already written by firmware) - */ - typedef struct { - unsigned char framenum[6]; - unsigned char packetnum[2]; - } eiger_packet_footer_t; - - /** detector type */ detectorType myDetectorType; /** detector hostname */ char detHostname[MAX_STR_LENGTH]; /** Number of Packets per Frame*/ - uint64_t packetsPerFrame; + uint32_t packetsPerFrame; /** Acquisition Period */ int64_t acquisitionPeriod; /** Frame Number */ @@ -479,7 +458,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter //***receiver parameters*** /** Maximum Number of Listening Threads/ UDP Ports */ - const static int MAX_NUM_LISTENING_THREADS = 2; + const static int MAX_NUMBER_OF_LISTENING_THREADS = 2; /** Receiver Status */ runStatus status; @@ -487,7 +466,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** Ethernet Interface */ char eth[MAX_STR_LENGTH]; /** Server UDP Port Number*/ - uint32_t udpPortNum[MAX_NUM_LISTENING_THREADS]; + uint32_t udpPortNum[MAX_NUMBER_OF_LISTENING_THREADS]; //***file parameters*** /** File Name without frame index, file index and extension (_d0_f000000000000_8.raw)*/ diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 2e89b59bef..65c275a292 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -17,8 +17,6 @@ #include "sls_receiver_defs.h" #include "receiver_defs.h" -#include "MySocketTCP.h" - #include "utilities.h" #include "logger.h" @@ -184,13 +182,13 @@ class UDPInterface { * Get UDP Port Number * @return udp port number */ - virtual uint32_t getUDPPortNo() const = 0; + virtual uint32_t getUDPPortNumber() const = 0; /** * Get Second UDP Port Number (eiger specific) * @return second udp port number */ - virtual uint32_t getUDPPortNo2() const = 0; + virtual uint32_t getUDPPortNumber2() const = 0; /** * Get Ehernet Interface @@ -314,22 +312,22 @@ class UDPInterface { /** * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) * @param b true for data compression enable, else false + * @return OK or FAIL */ - virtual void setDataCompressionEnable(const bool b) = 0; - + virtual int setDataCompressionEnable(const bool b) = 0; //***connection parameters*** /** * Set UDP Port Number * @param i udp port number */ - virtual void setUDPPortNo(const uint32_t i) = 0; + virtual void setUDPPortNumber(const uint32_t i) = 0; /** * Set Second UDP Port Number (eiger specific) * @return second udp port number */ - virtual void setUDPPortNo2(const uint32_t i) = 0; + virtual void setUDPPortNumber2(const uint32_t i) = 0; /** * Set Ethernet Interface to listen to @@ -338,7 +336,7 @@ class UDPInterface { virtual void setEthernetInterface(const char* c) = 0; - //***connection parameters*** + //***acquisition parameters*** /** * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) * @param i index of adc enabled, else -1 if all enabled @@ -348,14 +346,16 @@ class UDPInterface { /** * Set the Frequency of Frames Sent to GUI * @param i 0 for random frame requests, n for nth frame frequency + * @return OK or FAIL */ - virtual void setFrameToGuiFrequency(const uint32_t i) = 0; + virtual int setFrameToGuiFrequency(const uint32_t i) = 0; /** * Set Acquisition Period * @param i acquisition period + * @return OK or FAIL */ - virtual void setAcquisitionPeriod(const uint64_t i) = 0; + virtual int setAcquisitionPeriod(const uint64_t i) = 0; /** * Set Number of Frames expected by receiver from detector @@ -367,15 +367,16 @@ class UDPInterface { /** * Set Dynamic Range or Number of Bits Per Pixel * @param i dynamic range that is 4, 8, 16 or 32 + * @return OK or FAIL */ - virtual void setDynamicRange(const uint32_t i) = 0; + virtual int setDynamicRange(const uint32_t i) = 0; /** * Set Ten Giga Enable * @param b true if 10Giga enabled, else false (1G enabled) + * @return OK or FAIL */ - virtual void setTenGigaEnable(const bool b) = 0; - + virtual int setTenGigaEnable(const bool b) = 0; /************************************************************************* @@ -383,6 +384,7 @@ class UDPInterface { * They may modify the status of the receiver **************************** *************************************************************************/ + //***initial functions*** /** * Set receiver type (and corresponding detector variables in derived STANDARD class) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 04bd7000e6..747eaad346 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -6,25 +6,22 @@ * @short does all the functions for a receiver, set/get parameters, start/stop etc. ***********************************************/ +#include "UDPBaseImplementation.h" -#include "sls_receiver_defs.h" -#include "receiver_defs.h" +//#include "sls_receiver_defs.h" +//#include "receiver_defs.h" #include "genericSocket.h" #include "circularFifo.h" #include "singlePhotonDetector.h" #include "slsReceiverData.h" #include "moenchCommonMode.h" -//#include "UDPInterface.h" -#include "UDPBaseImplementation.h" #ifdef MYROOT1 #include #include #endif - - #include #include #include @@ -38,7 +35,13 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBaseImplementation { public: - /** + + + /************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + /** * Constructor */ UDPStandardImplementation(); @@ -48,237 +51,448 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ virtual ~UDPStandardImplementation(); - void configure(map config_map); - /** - * delete and free member parameters - */ - void deleteMembers(); + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ - /** - * initialize member parameters - */ - void initializeMembers(); + //***acquisition count parameters*** - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - int setDetectorType(detectorType det); + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ - //Frame indices and numbers caught - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - //uint32_t getStartAcquisitionIndex(); + //**initial parameters*** /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) + * Overridden method + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments */ - //uint32_t getAcquisitionIndex(); + void configure(map config_map); + //*** file parameters*** /** - * Returns if acquisition started + * Overridden method + * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) + * @param b true for data compression enable, else false */ - //bool getAcquistionStarted(); + void setDataCompressionEnable(const bool b); + //***acquisition parameters*** /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) + * Overridden method + * Set Short Frame Enabled, later will be moved to getROI (so far only for gotthard) + * @param i index of adc enabled, else -1 if all enabled */ - //int getFramesCaught(); + void setShortFrameEnable(const int i); /** - * Returns Total Frames Caught for an entire acquisition (including all scans) + * Overridden method + * Set the Frequency of Frames Sent to GUI + * @param i 0 for random frame requests, n for nth frame frequency + * @return OK or FAIL */ - //int getTotalFramesCaught(); + int setFrameToGuiFrequency(const uint32_t i); /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) + * Overridden method + * Set Acquisition Period + * @param i acquisition period + * @return OK or FAIL */ - //uint32_t getStartFrameIndex(); + int setAcquisitionPeriod(const uint64_t i); /** - * Returns current Frame Index for each real time acquisition (eg. for each scan) + * Overridden method + * Set Dynamic Range or Number of Bits Per Pixel + * @param i dynamic range that is 4, 8, 16 or 32 + * @return OK or FAIL */ - //uint32_t getFrameIndex(); + int setDynamicRange(const uint32_t i); /** - * Returns if measurement started + * Overridden method + * Set Ten Giga Enable + * @param b true if 10Giga enabled, else false (1G enabled) + * @return OK or FAIL */ - //bool getMeasurementStarted(); + int setTenGigaEnable(const bool b); + - /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 - */ - //void resetTotalFramesCaught(); + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ - //file parameters + //***initial functions*** /** - * Returns File Path + * Overridden method + * Set receiver type (and corresponding detector variables in derived STANDARD class) + * It is the first function called by the client when connecting to receiver + * @param d detector type + * @return OK or FAIL */ - //char* getFilePath() const; + int setDetectorType(const slsReceiverDefs::detectorType d); + //***acquisition functions*** /** - * Set File Path - * @param c file path + * Overridden method + * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) */ - //char* setFilePath(const char c[]); + void resetAcquisitionCount(); /** - * Returns File Name + * Overridden method + * Start Listening for Packets by activating all configuration settings to receiver + * @param c error message if FAIL + * @return OK or FAIL */ - //char* getFileName() const; + int startReceiver(char *c=NULL); + + + +private: + + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ + //**initial parameters*** /** - * Set File Name (without frame index, file index and extension) - * @param c file name + * Delete and free base member parameters */ - //char* setFileName(const char c[]); + void deleteBaseMembers(); - /** - * Returns File Index + /** + * Delete and free member parameters */ - //int getFileIndex(); + void deleteMembers(); /** - * Set File Index - * @param i file index + * Deletes all the filter objects for single photon data + * Deals with data compression */ - //int setFileIndex(int i); + void deleteFilter(); /** - * Set Frame Index Needed - * @param i frame index needed + * Initialize base member parameters */ - //int setFrameIndexNeeded(int i); + void initializeBaseMembers(); /** - * Set enable file write - * @param i file write enable - * Returns file write enable + * Initialize member parameters */ - //int setEnableFileWrite(int i); + void initializeMembers(); /** - * Enable/disable overwrite - * @param i enable - * Returns enable over write + * Sets up all the filter objects for single photon data + * Deals with data compression */ - //int setEnableOverwrite(int i); + void initializeFilter(); /** - * Returns file write enable - * 1: YES 0: NO - */ - //int getEnableFileWrite() const; + * Create Listening Threads + * @param destroy is true to destroy all the threads + */ + int createListeningThreads(bool destroy = false); /** - * Returns file over write enable - * 1: YES 0: NO - */ - //int getEnableOverwrite() const; - -//other parameters + * Create Writer Threads + * @param destroy is true to destroy all the threads + * @return OK or FAIL + */ + int createWriterThreads(bool destroy = false); /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' + * Set Thread Priorities */ - void abort() {}; + void setThreadPriorities(); /** - * Returns status of receiver: idle, running or error + * Set up the Fifo Structure for processing buffers + * between listening and writer threads + * @return OK or FAIL */ - runStatus getStatus() const; + int setupFifoStructure(); /** - * Set detector hostname - * @param c hostname + * Creates UDP Sockets + * @return OK or FAIL */ - void setDetectorHostname(const char *detectorHostName); + int createUDPSockets(); - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - char *getDetectorHostname() const; - /** - * Set Ethernet Interface or IP to listen to - */ - void setEthernetInterface(char* c); + //**detector parameters*** /** - * Set UDP Port Number + * structure of an eiger packet header + * subframenum subframe number for 32 bit mode (already written by firmware) + * missingpacket explicitly put to 0xFF to recognize it in file read (written by software) + * portnum 0 for the first port and 1 for the second port (written by software to file) + * dynamicrange dynamic range or bits per pixel (written by software to file) */ - void setUDPPortNo(int p); + typedef struct { + unsigned char subFameNumber[4]; + unsigned char missingPacket[2]; + unsigned char portIndex[1]; + unsigned char dynamicRange[1]; + } eiger_packet_header_t; /** - * Set UDP Port Number + * structure of an eiger packet footer + * framenum 48 bit frame number (already written by firmware) + * packetnum packet number (already written by firmware) */ - void setUDPPortNo2(int p); + typedef struct { + unsigned char frameNumber[6]; + unsigned char packetNumber[2]; + } eiger_packet_footer_t; + + /** Size of 1 Frame including headers */ + int frameSize; + + /** Size of 1 buffer processed at a time */ + int bufferSize; + + /** One Packet Size including headers */ + int onePacketSize; + + /** One Packet Size without headers */ + int oneDataSize; + + /** Frame Index Mask */ + uint64_t frameIndexMask; + + /** Frame Index Offset */ + int frameIndexOffset; + + /** Packet Index Mask */ + uint64_t packetIndexMask; + + /** Footer offset from start of Packet*/ + int footerOffset; + + //***File parameters*** + /** Maximum Packets Per File **/ + int maxPacketsPerFile; + + + + //***acquisition indices parameters*** + /** Frame Number of First Frame of an Acquisition */ + uint64_t startAcquisitionIndex; + + /** Frame index at start of each real time acquisition (eg. for each scan) */ + uint64_t startFrameIndex; + + /** Current Frame Number */ + uint64_t currentFrameNumber; + + /* Acquisition started */ + bool acqStarted; + + /* Measurement started */ + bool measurementStarted; + + /** Total Frame Count listened to by listening threads */ + int totalListeningFrameCount[MAX_NUMBER_OF_LISTENING_THREADS]; + + + + + //***receiver parameters*** + /** Receiver Buffer */ + char *buffer[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Memory allocated */ + char *mem0[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Circular fifo to point to addresses of data listened to */ + CircularFifo* fifo[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Circular fifo to point to address already written and freed, to be reused */ + CircularFifo* fifoFree[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Number of Jobs Per Buffer */ + int numberofJobsPerBuffer; + + /** Fifo Depth */ + uint32_t fifoSize; + + /** Current Frame copied for Gui */ + char* latestData; + + + + //***general and listening thread parameters*** + /** Ensures if threads created successfully */ + bool threadStarted; + + /** Number of Listening Threads */ + int numberofListeningThreads; + + /** Listening Threads */ + pthread_t listeningThreads[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Semaphores Synchronizing Listening Threads */ + sem_t listenSemaphore[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** Current Listening Thread Index*/ + int currentListeningThreadIndex; + + /** Mask with each bit indicating status of each listening thread */ + volatile uint32_t listeningThreadsMask; + + /** Set to self-terminate listening threads waiting for semaphores */ + bool killAllListeningThreads; + + + + //***writer thread parameters*** + /** Maximum Number of Writer Threads */ + const static int MAX_NUMBER_OF_WRITER_THREADS = 15; + + /** Number of Writer Threads */ + int numberofWriterThreads; + + /** Writer Threads */ + pthread_t writingThreads[MAX_NUMBER_OF_WRITER_THREADS]; + + /** Semaphores Synchronizing Writer Threads */ + sem_t writerSemaphore[MAX_NUMBER_OF_WRITER_THREADS]; + + /** Current Writer Thread Index*/ + int currentWriterThreadIndex; + + /** Mask with each bit indicating status of each writer thread */ + volatile uint32_t writerThreadsMask; + + /** Mask with each bit indicating file created for each writer thread*/ + volatile uint32_t createFileMask; + + /** Set to self-terminate writer threads waiting for semaphores */ + bool killAllWritingThreads; + + + + + + + //***filter parameters*** + /** Common Mode Subtraction Enable FIXME: Always false, only moench uses, Ask Anna */ + bool commonModeSubtractionEnable; + + /** Moench Common Mode Subtraction */ + moenchCommonMode *moenchCommonModeSubtraction; + + /** Single Photon Detector Object for each writer thread */ + singlePhotonDetector *singlePhotonDetectorObject[MAX_NUMBER_OF_WRITER_THREADS]; + + /** Receiver Data Object for each writer thread */ + slsReceiverData *receiverData[MAX_NUMBER_OF_WRITER_THREADS]; + + + + + //***mutex*** + /** mutex for status */ + pthread_mutex_t status_mutex; + + + + + + + + + + + + + + + + + + + + + + + + - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames - */ - int getNumberOfFrames() const; /** - * set frame number if a positive number + * Set receiver type + * @param det detector type + * Returns success or FAIL */ - int32_t setNumberOfFrames(int32_t fnum); + int setDetectorType(detectorType det); + + + //Frame indices and numbers caught + /** + * Returns the frame index at start of entire acquisition (including all scans) + */ + //uint32_t getStartAcquisitionIndex(); /** - * Returns scan tag + * Returns if acquisition started */ - int getScanTag() const; + //bool getAcquistionStarted(); /** - * set scan tag if its is a positive number + * Returns the frame index at start of each real time acquisition (eg. for each scan) */ - int32_t setScanTag(int32_t stag); + //uint32_t getStartFrameIndex(); /** - * Returns the number of bits per pixel + * Returns current Frame Index for each real time acquisition (eg. for each scan) */ - int getDynamicRange() const; + //uint32_t getFrameIndex(); /** - * set dynamic range if its is a positive number + * Returns if measurement started */ - int32_t setDynamicRange(int32_t dr); + //bool getMeasurementStarted(); /** - * Set short frame - * @param i if shortframe i=1 + * Resets the Total Frames Caught + * This is how the receiver differentiates between entire acquisitions + * Returns 0 */ - int setShortFrame(int i); + //void resetTotalFramesCaught(); + + + + + +//other parameters /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request + * abort acquisition with minimum damage: close open files, cleanup. + * does nothing if state already is 'idle' */ - int setNFrameToGui(int i); + void abort() {}; - /** set acquisition period if a positive number + /** + * Returns status of receiver: idle, running or error */ - int64_t setAcquisitionPeriod(int64_t index); + runStatus getStatus() const; - /** get data compression, by saving only hits + /** + * Set detector hostname + * @param c hostname */ - bool getDataCompression(); + void setDetectorHostname(const char *detectorHostName); + - /** enabl data compression, by saving only hits - /returns if failed - */ - int enableDataCompression(bool enable); /** * enable 10Gbe @@ -337,20 +551,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; }; */ - /** - * Deletes all the filter objects for single photon data - */ - void deleteFilter(); - /** - * Constructs the filter for single photon data - */ - void setupFilter(); - /** - * set up fifo according to the new numjobsperthread - */ - void setupFifoStructure (); + /** * Copy frames to gui @@ -358,28 +561,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void copyFrameToGui(char* startbuf[], char* buf=NULL); - /** - * creates udp sockets - * \returns if success or fail - */ - int createUDPSockets(); - - /** - * create listening thread - * @param destroy is true to kill all threads and start again - */ - int createListeningThreads(bool destroy = false); - - /** - * create writer threads - * @param destroy is true to kill all threads and start again - */ - int createWriterThreads(bool destroy = false); - - /** - * set thread priorities - */ - void setThreadPriorities(); /** * initializes variables and creates the first file @@ -507,8 +688,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; + /** missing packet identifier value */ const static uint16_t missingPacketValue = 0xFFFF; @@ -517,21 +697,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** UDP Socket between Receiver and Detector */ genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; - /** max packets per file **/ - int maxPacketsPerFile; - - /** Frame Index at start of an entire acquisition (including all scans) */ - uint64_t startAcquisitionIndex; /** Complete File name */ char savefilename[MAX_STR_LENGTH]; - /* Measurement started */ - bool measurementStarted; - /* Acquisition started */ - bool acqStarted; - /** Frame index at start of each real time acquisition (eg. for each scan) */ - uint32_t startFrameIndex; - /** Actual current frame index of each time acquisition (eg. for each scan) */ uint32_t frameIndex; @@ -547,34 +715,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Number of missing packets per buffer*/ uint32_t numMissingPackets; - /** frame index mask */ - uint32_t frameIndexMask; - - /** packet index mask */ - uint32_t packetIndexMask; - - /** frame index offset */ - int frameIndexOffset; - /** Current Frame Number */ - uint64_t currframenum; - /** Previous Frame number from buffer */ int prevframenum; - /** size of one frame */ - int frameSize; - - /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - int bufferSize; - - /** one buffer size */ - int onePacketSize; - - /** one buffer size */ - int oneDataSize; - - /** latest data */ - char* latestData; /** gui data ready */ int guiDataReady; @@ -585,71 +728,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** points to the filename to send to gui */ char* guiFileName; - /** fifo size */ - unsigned int fifosize; - - /** number of jobs per thread for data compression */ - int numJobsPerThread; - - /** memory allocated for the buffer */ - char *mem0[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data read */ - CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data already written and ready to be resued*/ - CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; - - /** Receiver buffer */ - char *buffer[MAX_NUM_LISTENING_THREADS]; - - /** number of writer threads */ - int numListeningThreads; - - /** number of writer threads */ - int numWriterThreads; - - /** to know if listening and writer threads created properly */ - int thread_started; - - /** current listening thread index*/ - int currentListeningThreadIndex; - - /** current writer thread index*/ - int currentWriterThreadIndex; - - /** thread listening to packets */ - pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; - - /** thread writing packets */ - pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; - - /** total frame count the listening thread has listened to */ - int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - - /** mask showing which listening threads are running */ - volatile uint32_t listeningthreads_mask; - - /** mask showing which writer threads are running */ - volatile uint32_t writerthreads_mask; - - /** mask showing which threads have created files*/ - volatile uint32_t createfile_mask; - - /** OK if file created was successful */ +/** OK if file created was successful */ int ret_createfile; - /** variable used to self terminate threads waiting for semaphores */ - int killAllListeningThreads; - - /** variable used to self terminate threads waiting for semaphores */ - int killAllWritingThreads; - - - - /** footer offset is different for 1g and 10g*/ - int footer_offset; - // TODO: not properly sure where to put these... /** structure of an eiger image header*/ @@ -659,19 +740,11 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase //semaphores /** semaphore to synchronize writer and guireader threads */ sem_t smp; - /** semaphore to synchronize listener threads */ - sem_t listensmp[MAX_NUM_LISTENING_THREADS]; - /** semaphore to synchronize writer threads */ - sem_t writersmp[MAX_NUM_WRITER_THREADS]; - //mutex /** guiDataReady mutex */ pthread_mutex_t dataReadyMutex; - /** mutex for status */ - pthread_mutex_t status_mutex; - /** mutex for progress variable currframenum */ pthread_mutex_t progress_mutex; @@ -682,10 +755,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase FILE *sfilefd; //filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - moenchCommonMode *cmSub; - bool commonModeSubtractionEnable; + #ifdef MYROOT1 /** Tree where the hits are stored */ diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 206c8b92b4..bac0df2d62 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -27,8 +27,9 @@ /*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/ #define GOTTHARD_PACKETS_PER_FRAME 2 #define GOTTHARD_ONE_PACKET_SIZE 1286 +#define GOTTHARD_ONE_DATA_SIZE 1280 #define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2 -#define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME) //1280*2 +#define GOTTHARD_DATA_BYTES (GOTTHARD_ONE_DATA_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1280*2 #define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE #define GOTTHARD_FRAME_INDEX_OFFSET 1 @@ -39,7 +40,7 @@ #define GOTTHARD_SHORT_PACKETS_PER_FRAME 1 -#define GOTTHARD_SHORT_ONE_PACKET_SIZE 518 +#define GOTTHARD_SHORT_ONE_PACKET_SIZE 518 #define GOTTHARD_SHORT_BUFFER_SIZE 518 #define GOTTHARD_SHORT_DATABYTES 512 #define GOTTHARD_SHORT_FRAME_INDEX_MASK 0xFFFFFFFF @@ -75,8 +76,9 @@ /*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ #define MOENCH_PACKETS_PER_FRAME 40 #define MOENCH_ONE_PACKET_SIZE 1286 +#define MOENCH_ONE_DATA_SIZE 1280 #define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40 -#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) //1280*40 +#define MOENCH_DATA_BYTES (MOENCH_ONE_DATA_SIZE*MOENCH_PACKETS_PER_FRAME) //1280*40 #define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00 #define MOENCH_FRAME_INDEX_OFFSET 8 diff --git a/slsReceiverSoftware/include/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h index 4eb0247764..e76ea7d1bf 100644 --- a/slsReceiverSoftware/include/slsReceiver.h +++ b/slsReceiverSoftware/include/slsReceiver.h @@ -8,7 +8,6 @@ #include "slsReceiverTCPIPInterface.h" #include "UDPInterface.h" -//#include "UDPBaseImplementation.h" #include "receiver_defs.h" #include "MySocketTCP.h" diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 11641334aa..04b8b19fbb 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -111,6 +111,16 @@ class slsReceiverDefs { }; + /** returns string from enabled/disabled + \param b true or false + \returns string enabled, disabled + */ + static string stringEnable(bool b){\ + if(b) return string("enabled"); \ + else return string("disabled"); \ + }; + + #ifdef __cplusplus protected: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index e160608658..0c1c302482 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -4,25 +4,12 @@ * @short does all the functions for a receiver, set/get parameters, start/stop etc. ***********************************************/ - #include "UDPBaseImplementation.h" -#include "moench02ModuleData.h" -#include "gotthardModuleData.h" -#include "gotthardShortModuleData.h" - - -#include // SIGINT #include // stat -#include // socket(), bind(), listen(), accept(), shut down -#include // sock_addr_in, htonl, INADDR_ANY -#include // exit() -#include //set precision -#include //munmap -#include #include - +#include using namespace std; @@ -32,7 +19,11 @@ using namespace std; * They access local cache of configuration or detector parameters ******* *************************************************************************/ UDPBaseImplementation::UDPBaseImplementation(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + cout << "Info: Initializing base members" << endl; //**detector parameters*** + myDetectorType = GENERIC; strcpy(detHostname,""); packetsPerFrame = 0; acquisitionPeriod = 0; @@ -51,7 +42,7 @@ UDPBaseImplementation::UDPBaseImplementation(){ } //***file parameters*** - strcpy(fileName,""); + strcpy(fileName,"run"); strcpy(filePath,""); fileIndex = 0; scanTag = 0; @@ -78,9 +69,17 @@ UDPBaseImplementation::UDPBaseImplementation(){ pAcquisitionFinished = NULL; rawDataReadyCallBack = NULL; pRawDataReady = NULL; -}; +} -UDPBaseImplementation::~UDPBaseImplementation(){}; +UDPBaseImplementation::~UDPBaseImplementation(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + cout << "Info: Deleting base member pointers" << endl; + if(detHostname) {delete [] detHostname; detHostname = NULL;} + if(eth) {delete [] eth; eth = NULL;} + if(fileName) {delete [] fileName; fileName = NULL;} + if(filePath) {delete [] filePath; filePath = NULL;} +} /************************************************************************* @@ -157,9 +156,9 @@ int64_t UDPBaseImplementation::getAcquisitionIndex() const{ /***connection parameters***/ -uint32_t UDPBaseImplementation::getUDPPortNo() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[0];} +uint32_t UDPBaseImplementation::getUDPPortNumber() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[0];} -uint32_t UDPBaseImplementation::getUDPPortNo2() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[1];} +uint32_t UDPBaseImplementation::getUDPPortNumber2() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[1];} char *UDPBaseImplementation::getEthernetInterface() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; @@ -205,7 +204,7 @@ void UDPBaseImplementation::setBottomEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; bottomEnable = b; - FILE_LOG(logINFO) << "Bottom Enable:" << bottomEnable; + FILE_LOG(logINFO) << "Bottom Enable: " << stringEnable(bottomEnable); } @@ -255,41 +254,46 @@ void UDPBaseImplementation::setFrameIndexEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; frameIndexEnable = b; - FILE_LOG(logINFO) << "Frame Index Enable:" << frameIndexEnable; + FILE_LOG(logINFO) << "Frame Index Enable: " << stringEnable(frameIndexEnable); } void UDPBaseImplementation::setFileWriteEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; fileWriteEnable = b; - FILE_LOG(logINFO) << "File Write Enable:" << fileWriteEnable; + FILE_LOG(logINFO) << "File Write Enable: " << stringEnable(fileWriteEnable); } void UDPBaseImplementation::setOverwriteEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; overwriteEnable = b; - FILE_LOG(logINFO) << "Overwrite Enable:" << overwriteEnable; + FILE_LOG(logINFO) << "Overwrite Enable: " << stringEnable(overwriteEnable); } -void UDPBaseImplementation::setDataCompressionEnable(const bool b){ +int UDPBaseImplementation::setDataCompressionEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; dataCompressionEnable = b; - FILE_LOG(logINFO) << "Data Compression Enable:" << dataCompressionEnable; -} + FILE_LOG(logINFO) << "Data Compression Enable: " << stringEnable(dataCompressionEnable); + //overridden methods might return FAIL + return OK; +} /***connection parameters***/ -void UDPBaseImplementation::setUDPPortNo(const uint32_t i){ +void UDPBaseImplementation::setUDPPortNumber(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - udpPortNum[0] = i; + if(bottomEnable) + udpPortNum[1] = i; + else + udpPortNum[0] = i; FILE_LOG(logINFO) << "udpPortNum[0]:" << udpPortNum[0]; } -void UDPBaseImplementation::setUDPPortNo2(const uint32_t i){ +void UDPBaseImplementation::setUDPPortNumber2(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; udpPortNum[1] = i; @@ -304,26 +308,32 @@ void UDPBaseImplementation::setEthernetInterface(const char* c){ } -/***connection parameters***/ +/***acquisition parameters***/ void UDPBaseImplementation::setShortFrameEnable(const int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; shortFrameEnable = i; - FILE_LOG(logINFO) << "Short Frame Enable:" << shortFrameEnable; + FILE_LOG(logINFO) << "Short Frame Enable: " << stringEnable(shortFrameEnable); } -void UDPBaseImplementation::setFrameToGuiFrequency(const uint32_t i){ +int UDPBaseImplementation::setFrameToGuiFrequency(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; FrameToGuiFrequency = i; FILE_LOG(logINFO) << "Frame To Gui Frequency:" << FrameToGuiFrequency; + + //overrridden child classes might return FAIL + return OK; } -void UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){ +int UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; acquisitionPeriod = i; FILE_LOG(logINFO) << "Acquisition Period:" << acquisitionPeriod; + + //overrridden child classes might return FAIL + return OK; } void UDPBaseImplementation::setNumberOfFrames(const uint64_t i){ @@ -333,20 +343,25 @@ void UDPBaseImplementation::setNumberOfFrames(const uint64_t i){ FILE_LOG(logINFO) << "Number of Frames:" << numberOfFrames; } -void UDPBaseImplementation::setDynamicRange(const uint32_t i){ +int UDPBaseImplementation::setDynamicRange(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; dynamicRange = i; FILE_LOG(logINFO) << "Dynamic Range:" << dynamicRange; + + //overrridden child classes might return FAIL + return OK; } -void UDPBaseImplementation::setTenGigaEnable(const bool b){ +int UDPBaseImplementation::setTenGigaEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; tengigaEnable = b; - FILE_LOG(logINFO) << "Ten Giga Enable:" << tengigaEnable; -} + FILE_LOG(logINFO) << "Ten Giga Enable: " << stringEnable(tengigaEnable); + //overridden functions might return FAIL + return OK; +} /************************************************************************* @@ -354,11 +369,13 @@ void UDPBaseImplementation::setTenGigaEnable(const bool b){ * They may modify the status of the receiver **************************** *************************************************************************/ + /***initial functions***/ int UDPBaseImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ FILE_LOG(logDEBUG) << __AT__ << " starting"; myDetectorType = d; + //if eiger, set numberofListeningThreads = 2; FILE_LOG(logINFO) << "Detector Type:" << slsDetectorBase::getDetectorType(d); return OK; } diff --git a/slsReceiverSoftware/src/UDPInterface.cpp b/slsReceiverSoftware/src/UDPInterface.cpp index 9520988113..9370358452 100644 --- a/slsReceiverSoftware/src/UDPInterface.cpp +++ b/slsReceiverSoftware/src/UDPInterface.cpp @@ -5,11 +5,11 @@ ***********************************************/ - -#include #include +#include using namespace std; + #include "UDPInterface.h" #include "UDPBaseImplementation.h" #include "UDPStandardImplementation.h" diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index dfbe514936..0f4290c9ca 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -10,81 +10,459 @@ #include "gotthardModuleData.h" #include "gotthardShortModuleData.h" - -#include // SIGINT -#include // stat -#include // socket(), bind(), listen(), accept(), shut down -#include // sock_addr_in, htonl, INADDR_ANY +//#include // socket(), bind(), listen(), accept(), shut down +//#include // sock_addr_in, htonl, INADDR_ANY #include // exit() -#include //set precision -#include //munmap - +#include //set precision for printing parameters for create new file +#include //map +//#include //munmap - -#include #include +#include #include using namespace std; - #define WRITE_HEADERS +/************************************************************************* + * Constructor & Destructor ********************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ UDPStandardImplementation::UDPStandardImplementation(){ - thread_started = 0; - eth = NULL; - latestData = NULL; - guiFileName = NULL; - tengigaEnable = 0; - footer_offset = 0; - for(int i=0;i /proc/sys/net/core/rmem_max")) - cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; - else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) - cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + double hc = 0, sigma = 5; + int sign = 1, csize, i; - /** permanent setting heiner - net.core.rmem_max = 104857600 # 100MiB - net.core.netdev_max_backlog = 250000 - sysctl -p - // from the manual - sysctl -w net.core.rmem_max=16777216 - sysctl -w net.core.netdev_max_backlog=250000 - */ + //common mode initialization + if (commonModeSubtractionEnable){ + if(myDetectorType == MOENCH) + moenchCommonModeSubtraction=new moenchCommonMode(); + else + cout << "Warning: No common mode subtraction for this detector" << endl; + } + + //receiver data initialization + switch(myDetectorType){ + case MOENCH: + csize = 3; + for(i=0; i(receiverData[i], csize, sigma, sign, commonModeSubtractionEnable); +} + + + +int UDPStandardImplementation::createListeningThreads(bool destroy){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + //reset masks + killAllListeningThreads = false; + pthread_mutex_lock(&status_mutex); + listeningThreadsMask = 0x0; + pthread_mutex_unlock(&(status_mutex)); + + //destroy + if(destroy){ + cout << "Info: Destroying Listening Thread(s)" << endl; + + killAllListeningThreads = true; + for(int i = 0; i < numberofListeningThreads; ++i){ + sem_post(&listenSemaphore[i]); + pthread_join(listeningThreads[i],NULL); + cout <<"."< MAX_JOBS_PER_THREAD) + numberofJobsPerBuffer = MAX_JOBS_PER_THREAD; + else if (i < 1) + numberofJobsPerBuffer = 1; + else + numberofJobsPerBuffer = i; + + } + cout << "Info: Number of Frames per buffer:" << numberofJobsPerBuffer << endl; + } + + //set fifo depth + //eiger listens to 1 packet at a time and size changes depending on packets per frame + if(myDetectorType == EIGER) + fifoSize = EIGER_FIFO_SIZE * packetsPerFrame; + else{ + fifoSize = GOTTHARD_FIFO_SIZE; + if(myDetectorType == MOENCH) + fifoSize = MOENCH_FIFO_SIZE; + else if(myDetectorType == PROPIX) + fifoSize = PROPIX_FIFO_SIZE; + //reduce fifo depth if more frames listened to at a time + if(fifoSize % numberofJobsPerBuffer) + fifoSize = (fifoSize/numberofJobsPerBuffer)+1; + else + fifoSize = fifoSize/numberofJobsPerBuffer; + } +#ifdef VERBOSE + cout << "Info: Fifo Depth:" << fifoSize << endl; +#endif + + + //do not rebuild fifo structure if it is the same + if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoSize)) + return OK; + + + //set up fifo structure + for(int i=0;iisEmpty()) + fifoFree[i]->pop(buffer[i]); +#ifdef FIFO_DEBUG + cprintf(GREEN,"%d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); +#endif + delete fifoFree[i]; + } + if(fifo[i]) delete fifo[i]; + if(mem0[i]) free(mem0[i]); + + //creating + fifoFree[i] = new CircularFifo(fifoSize); + fifo[i] = new CircularFifo(fifoSize); + + //allocate memory + mem0[i] = (char*)malloc((bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * fifoSize); + if (mem0[i] == NULL){ + cprintf(BG_RED,"Error: Could not allocate memory for listening \n"); + return FAIL; + } + + //push free address into fifoFree + buffer[i]=mem0[i]; + while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoSize-1))) { + fifoFree[i]->push(buffer[i]); +#ifdef FIFO_DEBUG + cprintf(BLUE,"%d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); +#endif + buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); + } + } + cout << "Info: Fifo structure(s) reconstructed" << endl; +} + + + + +int UDPStandardImplementation::createUDPSockets(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + + + + return OK; +} + + + void UDPStandardImplementation::configure(map config_map){ - FILE_LOG(logWARNING) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; map::const_iterator pos; pos = config_map.find("mode"); @@ -94,678 +472,618 @@ void UDPStandardImplementation::configure(map config_map){ cout << "Warning: Could not parse mode. Assuming top mode." << endl; b = 0; } - bottom = b!= 0; - cout << "bottom:"<< bottom << endl; + bottomEnable = b!= 0; + cout << "Info: Bottom Enable: " << stringEnable(bottomEnable) << endl; } -}; -void UDPStandardImplementation::initializeMembers(){ - myDetectorType = GENERIC; - maxPacketsPerFile = 0; - enableFileWrite = 1; - overwrite = 1; - fileIndex = 0; - scanTag = 0; - frameIndexNeeded = 0; - acqStarted = false; - measurementStarted = false; - startFrameIndex = 0; - frameIndex = 0; - packetsCaught = 0; - totalPacketsCaught = 0; - packetsInFile = 0; - numTotMissingPackets = 0; - numTotMissingPacketsInFile = 0; - numMissingPackets = 0; - startAcquisitionIndex = 0; - acquisitionIndex = 0; - packetsPerFrame = 0; - frameIndexMask = 0; - packetIndexMask = 0; - frameIndexOffset = 0; - acquisitionPeriod = SAMPLE_TIME_IN_NS; - numberOfFrames = 0; - dynamicRange = 16; - shortFrame = -1; - currframenum = 0; - prevframenum = 0; - frameSize = 0; - bufferSize = 0; - onePacketSize = 0; - oneDataSize = 0; - guiDataReady = 0; - nFrameToGui = 0; - fifosize = 0; - numJobsPerThread = -1; - dataCompression = false; - numListeningThreads = 1; - numWriterThreads = 1; - thread_started = 0; - currentListeningThreadIndex = -1; - currentWriterThreadIndex = -1; - for(int i=0;i= 0){ + FrameToGuiFrequency = i; + if(setupFifoStructure() == FAIL) + return FAIL; + } + + cout << "Info: Frame to Gui Frequency set to " << FrameToGuiFrequency << endl; + return OK; } +int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; -UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if(i >= 0){ + acquisitionPeriod = i; + if(setupFifoStructure() == FAIL) + return FAIL; + } - createListeningThreads(true); - createWriterThreads(true); - deleteMembers(); + cout << "Info: Acquisition Period set to " << acquisitionPeriod << endl; + + + return OK; } +int UDPStandardImplementation::setDynamicRange(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int oldDynamicRange = dynamicRange; + cout << "Info: Setting Dynamic Range to " << i << endl; + dynamicRange = i; -void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if(myDetectorType == EIGER){ + + //set parameters depending on new dynamic range. + packetsPerFrame = (tengigaEnable ? EIGER_TEN_GIGA_CONSTANT : EIGER_ONE_GIGA_CONSTANT) + * dynamicRange * EIGER_MAX_PORTS; + frameSize = onePacketSize * packetsPerFrame; + maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + + //new dynamic range, then restart threads and resetup fifo structure + if(oldDynamicRange != dynamicRange){ + + //delete threads + if(threadStarted){ + createListeningThreads(true); + createWriterThreads(true); + } + + //gui buffer + if(latestData){delete[] latestData; latestData = NULL;} + latestData = new char[frameSize]; + + //restructure fifo + if(setupFifoStructure() == FAIL) + return FAIL; + + //create threads + if(createListeningThreads() == FAIL){ + cprintf(BG_RED,"Error: Could not create listening thread\n"); + return FAIL; + } + if(createWriterThreads() == FAIL){ + cprintf(BG_RED,"Error: Could not create writer threads\n"); + return FAIL; + } + setThreadPriorities(); + } - //kill threads - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); } - for(int i=0;i=0) - fileIndex = i; - return getFileIndex(); -} -*/ - -/* -int UDPStandardImplementation::setFrameIndexNeeded(int i){ - frameIndexNeeded = i; - return frameIndexNeeded; -} -*/ - -/* -int UDPStandardImplementation::getEnableFileWrite() const{ - return enableFileWrite; -} -*/ - -/* -int UDPStandardImplementation::setEnableFileWrite(int i){ - enableFileWrite=i; - return getEnableFileWrite(); -} -*/ - -/* -int UDPStandardImplementation::getEnableOverwrite() const{ - return overwrite; -} -*/ -/* -int UDPStandardImplementation::setEnableOverwrite(int i){ - overwrite=i; - return getEnableOverwrite(); + cout << "Info: Acquisition Count has been reset" << endl; } -*/ - +int UDPStandardImplementation::startReceiver(char *c=NULL){ + FILE_LOG(logDEBUG) << __AT__ << " called"; -/*other parameters*/ - -slsReceiverDefs::runStatus UDPStandardImplementation::getStatus() const{ - FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status; - - - return status; -} + cout << "Info: Starting Receiver" << endl; + //reset measurement variables + measurementStarted = false; + startFrameIndex = 0; + if(!acqStarted) + currentFrameNumber = 0; //has to be zero to add to startframeindex for each scan + for(int i = 0; i < numberofListeningThreads; ++i) + totalListeningFrameCount[i] = 0; -void UDPStandardImplementation::setDetectorHostname(const char *detectorHostName){ - if(strlen(detectorHostName)) - strcpy(detHostname,detectorHostName); -} + //create UDP sockets + if(createUDPSockets() == FAIL){ + } -char *UDPStandardImplementation::getDetectorHostname() const{ - if(!strlen(detHostname)) - return NULL; - return (char*)detHostname; + return OK; } -void UDPStandardImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - strcpy(eth,c); -} -void UDPStandardImplementation::setUDPPortNo(int p){ -FILE_LOG(logDEBUG) << __AT__ << " called"; - server_port[0] = p; -} -void UDPStandardImplementation::setUDPPortNo2(int p){ -FILE_LOG(logDEBUG) << __AT__ << " called"; - server_port[1] = p; -} -int UDPStandardImplementation::getNumberOfFrames() const { - return numberOfFrames; -} -int32_t UDPStandardImplementation::setNumberOfFrames(int32_t fnum){ FILE_LOG(logDEBUG) << __AT__ << " called"; - if(fnum >= 0) - numberOfFrames = fnum; - return getNumberOfFrames(); -} -int UDPStandardImplementation::getScanTag() const{ - return scanTag; -} -int32_t UDPStandardImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " called"; - if(stag >= 0) - scanTag = stag; - return getScanTag(); -} -int UDPStandardImplementation::getDynamicRange() const{ - return dynamicRange; -} -int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " called"; - int olddr = dynamicRange; - if(dr >= 0){ - cout << "Setting Dynamic Range to " << dr << endl; - dynamicRange = dr; - if(myDetectorType == EIGER){ - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE; - } - footer_offset = EIGER_PACKET_HEADER_SIZE + oneDataSize; - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - if(olddr != dr){ - //del - if(thread_started){ - createListeningThreads(true); - createWriterThreads(true); - } - for(int i=0;i=0){ - nFrameToGui = i; - setupFifoStructure(); - } - return nFrameToGui; -} + initializeMembers(); + //to increase socket receiver buffer size and max length of input queue by changing kernel settings + if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) + cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) + cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + /** permanent setting heiner + net.core.rmem_max = 104857600 # 100MiB + net.core.netdev_max_backlog = 250000 + sysctl -p + // from the manual + sysctl -w net.core.rmem_max=16777216 + sysctl -w net.core.netdev_max_backlog=250000 + */ + } -int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " called"; - if(index >= 0){ - if(index != acquisitionPeriod){ - acquisitionPeriod = index; - setupFifoStructure(); - } - } - return acquisitionPeriod; -} +void UDPStandardImplementation::initializeMembers(){ + myDetectorType = GENERIC; + enableFileWrite = 1; + overwrite = 1; + fileIndex = 0; + scanTag = 0; + frameIndexNeeded = 0; -bool UDPStandardImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " called"; -return dataCompression;} + frameIndex = 0; + packetsCaught = 0; + totalPacketsCaught = 0; + packetsInFile = 0; + numTotMissingPackets = 0; + numTotMissingPacketsInFile = 0; + numMissingPackets = 0; + startAcquisitionIndex = 0; + acquisitionIndex = 0; -int UDPStandardImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " called"; + frameIndexMask = 0; + packetIndexMask = 0; + frameIndexOffset = 0; + acquisitionPeriod = SAMPLE_TIME_IN_NS; + numberOfFrames = 0; + dynamicRange = 16; + shortFrame = -1; + currframenum = 0; + prevframenum = 0; - cout << "Data compression "; - if(enable) - cout << "enabled" << endl; - else - cout << "disabled" << endl; -#ifdef MYROOT1 - cout << " WITH ROOT" << endl; -#else - cout << " WITHOUT ROOT" << endl; -#endif - //delete filter for the current number of threads - deleteFilter(); + guiDataReady = 0; + nFrameToGui = 0; + dataCompression = false; + numListeningThreads = 1; + numWriterThreads = 1; + thread_started = 0; - dataCompression = enable; - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - createWriterThreads(true); + cbAction = DO_EVERYTHING; + tengigaEnable = 0; - if(enable) - numWriterThreads = MAX_NUM_WRITER_THREADS; - else - numWriterThreads = 1; - if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"ERROR: Could not create writer threads\n"); - return FAIL; + for(int i=0;i(receiverdata[i], csize, sigma, sign, cmSub); +//uint32_t UDPStandardImplementation::getStartFrameIndex(){return startFrameIndex;} +/* +uint32_t UDPStandardImplementation::getFrameIndex(){ + if(!packetsCaught) + frameIndex=-1; + else + frameIndex = currframenum - startFrameIndex; + return frameIndex; } +*/ + -//LEO: it is not clear to me.. -void UDPStandardImplementation::setupFifoStructure(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - int64_t i; - int oldn = numJobsPerThread; - //if every nth frame mode - if(nFrameToGui) - numJobsPerThread = nFrameToGui; - //random nth frame mode - else{ - if(!acquisitionPeriod) - i = SAMPLE_TIME_IN_NS; - else - i = SAMPLE_TIME_IN_NS/acquisitionPeriod; - if (i > MAX_JOBS_PER_THREAD) - numJobsPerThread = MAX_JOBS_PER_THREAD; - else if (i < 1) - numJobsPerThread = 1; - else - numJobsPerThread = i; - } - //if same, return - if(oldn == numJobsPerThread) - return; - if(myDetectorType == EIGER) - numJobsPerThread = 1; - - //otherwise memory too much if numjobsperthread is at max = 1000 - fifosize = GOTTHARD_FIFO_SIZE; - if(myDetectorType == MOENCH) - fifosize = MOENCH_FIFO_SIZE; - if(myDetectorType == PROPIX) - fifosize = PROPIX_FIFO_SIZE; - else if(myDetectorType == EIGER) - fifosize = EIGER_FIFO_SIZE * packetsPerFrame; - - if(fifosize % numJobsPerThread) - fifosize = (fifosize/numJobsPerThread)+1; - else - fifosize = fifosize/numJobsPerThread; - if(myDetectorType == EIGER) - cout << "1 packet per buffer" << endl; - else - cout << "Number of Frames per buffer:" << numJobsPerThread << endl; -#ifdef VERBOSE - cout << "Fifo Size:" << fifosize << endl; -#endif - /* - //for testing - numJobsPerThread = 3; fifosize = 11; - */ - for(int i=0;iisEmpty()) - fifoFree[i]->pop(buffer[i]); -#ifdef FIFO_DEBUG - //cprintf(GREEN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i])); -#endif - delete fifoFree[i]; - } - if(fifo[i]) delete fifo[i]; - if(mem0[i]) free(mem0[i]); - fifoFree[i] = new CircularFifo(fifosize); - fifo[i] = new CircularFifo(fifosize); - int whatperbuffer = bufferSize; - if(myDetectorType == EIGER) - whatperbuffer = onePacketSize; - //allocate memory - mem0[i]=(char*)malloc((whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - /** shud let the client know about this */ - if (mem0[i]==NULL){ - cprintf(BG_RED,"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++\n"); - exit(-1); - } - buffer[i]=mem0[i]; - //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i])); -#endif - buffer[i]+=(whatperbuffer * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); - } - } - cout << "Fifo structure(s) reconstructed" << endl; -} +/*other parameters*/ + @@ -1113,164 +1342,6 @@ int UDPStandardImplementation::shutDownUDPSockets(){ -int UDPStandardImplementation::createListeningThreads(bool destroy){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - int i; - void* status; - - killAllListeningThreads = 0; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - FILE_LOG(logDEBUG) << "Starting " << __func__ << endl; - - if(!destroy){ - - //start listening threads - cout << "Creating Listening Threads(s)"; - - currentListeningThreadIndex = -1; - - for(i = 0; i < numListeningThreads; ++i){ - sem_init(&listensmp[i],1,0); - thread_started = 0; - currentListeningThreadIndex = i; - if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ - cout << "Could not create listening thread with index " << i << endl; - return FAIL; - } - while(!thread_started); - cout << "."; - cout << flush; - } -#ifdef VERBOSE - cout << "Listening thread(s) created successfully." << endl; -#else - cout << endl; -#endif - }else{ - cout<<"Destroying Listening Thread(s)"<= 0){ - - tengigaEnable = enable; - - if(myDetectorType == EIGER){ - - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE; - } - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - -#ifdef VERBOSE - cout<<"packetsPerFrame:"<= 0) - receiverBase->setFrameToGuiFrequency(index); + if(index >= 0){ + ret = receiverBase->setFrameToGuiFrequency(index); + if(ret == FAIL) + strcpy(mess, "Could not allocate memory for listening fifo\n"); + } retval=receiverBase->getFrameToGuiFrequency(); if(index>=0 && retval!=index) ret = FAIL; @@ -2107,8 +2110,11 @@ int slsReceiverTCPIPInterface::set_timer() { } else{ if(index[0] == slsReceiverDefs::FRAME_PERIOD){ - if(index[1]>=0) - receiverBase->setAcquisitionPeriod(index[1]); + if(index[1]>=0){ + ret = receiverBase->setAcquisitionPeriod(index[1]); + if(ret == FAIL) + strcpy(mess,"Could not allocate memory for listening fifo\n") + } retval=receiverBase->getAcquisitionPeriod(); }else{ if(index[1]>=0) @@ -2183,17 +2189,19 @@ int slsReceiverTCPIPInterface::enable_compression() { } else{ if(enable >= 0) - receiverBase->setDataCompressionEnable(enable); + ret = receiverBase->setDataCompressionEnable(enable); } } - if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); - ret=FAIL; - }else{ - retval = receiverBase->getDataCompressionEnable(); - if(enable >= 0 && retval != enable) - ret = FAIL; + if(ret != FAIL){ + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else{ + retval = receiverBase->getDataCompressionEnable(); + if(enable >= 0 && retval != enable) + ret = FAIL; + } } } @@ -2324,8 +2332,11 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { strcpy(mess,"Receiver not set up\n"); ret=FAIL; }else{ - if(dr > 0) - receiverBase->setDynamicRange(dr); + if(dr > 0){ + ret = receiverBase->setDynamicRange(dr); + if(ret == FAIL) + strcpy(mess, "Could not allocate memory for fifo or could not start listening/writing threads\n"); + } retval = receiverBase->getDynamicRange(); if(dr > 0 && retval != dr) ret = FAIL; @@ -2461,8 +2472,8 @@ int slsReceiverTCPIPInterface::enable_tengiga() { } else{ if(val >= 0) - receiverBase->setDataCompressionEnable(val); - retval=receiverBase->getDataCompressionEnable(); + ret = receiverBase->setTenGigaEnable(val); + retval=receiverBase->getTenGigaEnable(); if((val >= 0) && (val != retval)) ret = FAIL; else From e915245c104c9cb66c002ab89cb3fb1de11b0f12 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 8 Oct 2015 17:09:43 +0200 Subject: [PATCH 149/222] additional change --- .../include/UDPBaseImplementation.h | 6 +- slsReceiverSoftware/include/UDPInterface.h | 6 +- .../include/UDPStandardImplementation.h | 220 +++----- .../src/UDPBaseImplementation.cpp | 5 +- .../src/UDPStandardImplementation.cpp | 495 ++++++++---------- 5 files changed, 296 insertions(+), 436 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 293ac67631..c1de8fa6f8 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -111,7 +111,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter uint64_t getFramesCaught() const; /** - * Get Current Frame Index Caught for an entire acquisition (including all scans) + * Get Current Frame Index for an entire acquisition (including all scans) * @return current frame index (represents all scans too) */ int64_t getAcquisitionIndex() const; @@ -372,8 +372,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter void startReadout(); /** - * shuts down the udp sockets - * \returns OK or FAIL + * Shuts down and deletes UDP Sockets + * @return OK or FAIL */ int shutDownUDPSockets(); diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 65c275a292..a3766b8471 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -171,7 +171,7 @@ class UDPInterface { virtual uint64_t getFramesCaught() const = 0; /** - * Get Current Frame Index Caught for an entire acquisition (including all scans) + * Get Current Frame Index for an entire acquisition (including all scans) * @return current frame index (represents all scans too) or -1 if no packets caught */ virtual int64_t getAcquisitionIndex() const = 0; @@ -430,8 +430,8 @@ class UDPInterface { virtual void startReadout() = 0; /** - * shuts down the udp sockets - * \returns OK or FAIL + * Shuts down and deletes UDP Sockets + * @return OK or FAIL */ virtual int shutDownUDPSockets() = 0; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 747eaad346..825806e836 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -57,8 +57,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * They access local cache of configuration or detector parameters ******* *************************************************************************/ - //***acquisition count parameters*** - /************************************************************************* * Setters *************************************************************** @@ -154,14 +152,14 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ int startReceiver(char *c=NULL); - + /** + * Shuts down and deletes UDP Sockets + * @return OK or FAIL + */ + int shutDownUDPSockets(); private: - /************************************************************************* - * Setters *************************************************************** - * They modify the local cache of configuration or detector parameters *** - *************************************************************************/ //**initial parameters*** /** @@ -227,6 +225,13 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ int createUDPSockets(); + /** + * Initializes writer variables and creates the first file + * also does the startAcquisitionCallBack + * @return OK or FAIL + */ + int setupWriter(); + //**detector parameters*** @@ -277,19 +282,27 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Footer offset from start of Packet*/ int footerOffset; + //***File parameters*** /** Maximum Packets Per File **/ int maxPacketsPerFile; + /** If file created successfully for all Writer Threads */ + bool fileCreateSuccess; - //***acquisition indices parameters*** - /** Frame Number of First Frame of an Acquisition */ + + + //***acquisition indices/count parameters*** + /** Frame Number of First Frame of an entire Acquisition (including all scans) */ uint64_t startAcquisitionIndex; /** Frame index at start of each real time acquisition (eg. for each scan) */ uint64_t startFrameIndex; + /** Actual current frame index of each time acquisition (eg. for each scan) */ + uint64_t frameIndex; + /** Current Frame Number */ uint64_t currentFrameNumber; @@ -302,6 +315,19 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Total Frame Count listened to by listening threads */ int totalListeningFrameCount[MAX_NUMBER_OF_LISTENING_THREADS]; + /** Pckets currently in current file, starts new file when it reaches max */ + uint32_t packetsInFile; + + /** Number of Missing Packets per buffer*/ + uint32_t numMissingPackets; + + /** Total Number of Missing Packets in acquisition*/ + uint32_t numTotMissingPackets; + + /** Number of Missing Packets in file */ + uint32_t numTotMissingPacketsInFile; + + @@ -318,15 +344,37 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Circular fifo to point to address already written and freed, to be reused */ CircularFifo* fifoFree[MAX_NUMBER_OF_LISTENING_THREADS]; + /** UDP Sockets - Detector to Receiver */ + genericSocket* udpSocket[MAX_NUMBER_OF_LISTENING_THREADS]; + + /** File Descriptor */ + FILE *sfilefd; + /** Number of Jobs Per Buffer */ int numberofJobsPerBuffer; /** Fifo Depth */ uint32_t fifoSize; - /** Current Frame copied for Gui */ + + //***receiver to GUI parameters*** + /** Current Frame copied for GUI */ char* latestData; + /** If Data to be sent to GUI is ready */ + bool guiDataReady; + + /** Pointer to data to be sent to GUI */ + char* guiData; + + /** Pointer to file name to be sent to GUI */ + char guiFileName[MAX_STR_LENGTH]; + + /** Semaphore to synchronize Writer and GuiReader threads*/ + sem_t writerGuiSemaphore; + + + //***general and listening thread parameters*** @@ -382,7 +430,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase - //***filter parameters*** /** Common Mode Subtraction Enable FIXME: Always false, only moench uses, Ask Anna */ bool commonModeSubtractionEnable; @@ -404,6 +451,12 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase pthread_mutex_t status_mutex; + //***callback*** + /** The action which decides what the user and default responsibilities to save data are + * 0 raw data ready callback takes care of open,close,write file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything */ + int cbAction; @@ -422,89 +475,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase - - - - - - - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - int setDetectorType(detectorType det); - - - //Frame indices and numbers caught - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - //uint32_t getStartAcquisitionIndex(); - - /** - * Returns if acquisition started - */ - //bool getAcquistionStarted(); - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - //uint32_t getStartFrameIndex(); - - /** - * Returns current Frame Index for each real time acquisition (eg. for each scan) - */ - //uint32_t getFrameIndex(); - - /** - * Returns if measurement started - */ - //bool getMeasurementStarted(); - - /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 - */ - //void resetTotalFramesCaught(); - - - - - -//other parameters - - /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' - */ - void abort() {}; - - /** - * Returns status of receiver: idle, running or error - */ - runStatus getStatus() const; - - /** - * Set detector hostname - * @param c hostname - */ - void setDetectorHostname(const char *detectorHostName); - - - - /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe - */ - int enableTenGiga(int enable = -1); - - - -//other functions - /** * Returns the buffer-current frame read by receiver * @param c pointer to current file name @@ -520,12 +490,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void closeFile(int ithr = -1); - /** - * Starts Receiver - starts to listen for packets - * @param message is the error message if there is an error - * Returns success - */ - int startReceiver(char message[]); /** * Stops Receiver - stops listening for packets @@ -538,21 +502,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void startReadout(); - /** - * shuts down the udp sockets - * \returns if success or fail - */ - int shutDownUDPSockets(); - -private: - - /* - void not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; - }; - */ +private: /** @@ -562,12 +514,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase void copyFrameToGui(char* startbuf[], char* buf=NULL); - /** - * initializes variables and creates the first file - * also does the startAcquisitionCallBack - * \returns FAIL or OK - */ - int setupWriter(); /** * Creates new tree and file for compression @@ -694,42 +640,18 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase const static uint16_t missingPacketValue = 0xFFFF; - /** UDP Socket between Receiver and Detector */ - genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; - - /** Complete File name */ +/** Complete File name */ char savefilename[MAX_STR_LENGTH]; - /** Actual current frame index of each time acquisition (eg. for each scan) */ - uint32_t frameIndex; - - /** Pckets currently in current file, starts new file when it reaches max */ - uint32_t packetsInFile; - - /** Number of missing packets in acquisition*/ - uint32_t numTotMissingPackets; - - /** Number of missing packets in file (sometimes packetsinFile is incorrect due to padded packets for eiger)*/ - uint32_t numTotMissingPacketsInFile; - /** Number of missing packets per buffer*/ - uint32_t numMissingPackets; /** Previous Frame number from buffer */ int prevframenum; - /** gui data ready */ - int guiDataReady; - /** points to the data to send to gui */ - char* guiData; - /** points to the filename to send to gui */ - char* guiFileName; -/** OK if file created was successful */ - int ret_createfile; // TODO: not properly sure where to put these... /** structure of an eiger image header*/ @@ -738,8 +660,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase //semaphores - /** semaphore to synchronize writer and guireader threads */ - sem_t smp; + //mutex /** guiDataReady mutex */ @@ -751,8 +672,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** mutex for writing data to file */ pthread_mutex_t write_mutex; - /** File Descriptor */ - FILE *sfilefd; //filter @@ -766,11 +685,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase #endif - /** The action which decides what the user and default responsibilites to save data are - * 0 raw data ready callback takes care of open,close,write file - * 1 callback writes file, we have to open, close it - * 2 we open, close, write file, callback does not do anything */ - int cbAction; public: diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 0c1c302482..ec5c27ad54 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -286,10 +286,7 @@ int UDPBaseImplementation::setDataCompressionEnable(const bool b){ void UDPBaseImplementation::setUDPPortNumber(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - if(bottomEnable) - udpPortNum[1] = i; - else - udpPortNum[0] = i; + udpPortNum[0] = i; FILE_LOG(logINFO) << "udpPortNum[0]:" << udpPortNum[0]; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0f4290c9ca..5901e96a33 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -58,16 +58,22 @@ void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "Info: Deleting member pointers" << endl; + shutDownUDPSockets(); + closeFile(); //filter deleteFilter(); + for(int i=0; igetErrorStatus(); + if(!iret){ + cout << "Info: UDP port opened at port " << port[i] << endl; + }else{ +#ifdef VERBOSE + cprintf(BG_RED,"Error: Could not create UDP socket on port %d error: %d\n", port[i], iret); +#endif + shutDownUDPSockets(); + return FAIL; + } + } + + cout << "Info: UDP socket(s) created successfully." << endl; + cout << "Info: Listener Ready ..." << endl; return OK; } +int UDPStandardImplementation::setupWriter(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + //acquisition start call back returns enable write + cbAction = DO_EVERYTHING; + if (startAcquisitionCallBack) + cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); + + if(cbAction < DO_EVERYTHING){ + cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; + if (rawDataReadyCallBack) + cout << "Info: Data Write has been defined externally" << endl; + }else if(!fileWriteEnable) + cout << "Info: Data will not be saved" << endl; + + + + //creating first file + //setting all value to 1 + pthread_mutex_lock(&status_mutex); + for(int i=0; i config_map){ FILE_LOG(logDEBUG) << __AT__ << " starting"; @@ -869,25 +984,113 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ cout << "Info: Starting Receiver" << endl; + + //RESET //reset measurement variables measurementStarted = false; startFrameIndex = 0; + frameIndex = 0; if(!acqStarted) currentFrameNumber = 0; //has to be zero to add to startframeindex for each scan for(int i = 0; i < numberofListeningThreads; ++i) totalListeningFrameCount[i] = 0; + packetsCaught = 0; + numMissingPackets = 0; + numTotMissingPackets = 0; + numTotMissingPacketsInFile = 0; + //reset file parameters + packetsInFile = 0; + if(sfilefd){ + fclose(sfilefd); + sfilefd = NULL; + } + //reset gui variables + guiData = NULL; + guiDataReady=0; + strcpy(guiFileName,""); + //reset masks + pthread_mutex_lock(&status_mutex); + writerThreadsMask = 0x0; + createFileMask = 0x0; + fileCreateSuccess = false; + pthread_mutex_unlock(&status_mutex); + + + //Print Receiver Configuration + cout << "Info: ***Receiver Configuration***" << endl; + cout << "Info: Max Packets Per File:" << maxPacketsPerFile << endl; + cout << "Info: Data Compression has been " << stringEnable(dataCompressionEnable) << endl; + if(myDetectorType != EIGER) + cout << "Info: Number of Jobs Per Buffer: " << numberofJobsPerBuffer << endl; + if(FrameToGuiFrequency) + cout << "Info: Frequency of frames sent to gui" << FrameToGuiFrequency << endl; + + //create UDP sockets if(createUDPSockets() == FAIL){ + strcpy(c,"Could not create UDP Socket(s).\n"); + cout << endl; + cout << "Error: "<< c << endl; + return FAIL; + } + if(setupWriter() == FAIL){ + //stop udp socket + shutDownUDPSockets(); + sprintf(c,"Could not create file %s.\n",savefilename); + cout << endl; + cout << "Error: "<< c << endl; + return FAIL; } + + //For compression, done to give the gui some proper name instead of always the last file name + if(dataCompressionEnable) + sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + + //initialize semaphore to synchronize between writer and gui reader threads + sem_init(&writerGuiSemaphore,1,0); + + //status and thread masks + pthread_mutex_lock(&status_mutex); + status = RUNNING; + for(int i=0;iShutDownSocket(); + delete udpSocket[i]; + udpSocket[i] = NULL; + } + } + return OK; +} @@ -929,16 +1132,13 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ UDPStandardImplementation::UDPStandardImplementation(){ thread_started = 0; eth = NULL; - latestData = NULL; - guiFileName = NULL; + tengigaEnable = 0; for(int i=0;igetErrorStatus(); - if(!iret){ - cout << "UDP port opened at port " << port[i] << endl; - }else{ -#ifdef VERBOSE - cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); -#endif - shutDownUDPSockets(); - return FAIL; - } - } - - - - return OK; -} - - - - - - - -int UDPStandardImplementation::shutDownUDPSockets(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - for(int i=0;iShutDownSocket(); - delete udpSocket[i]; - udpSocket[i] = NULL; - } - } - return OK; -} - - - - - - - -int UDPStandardImplementation::setupWriter(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - //reset writing thread variables - packetsInFile=0; - numTotMissingPackets = 0; - numTotMissingPacketsInFile = 0; - numMissingPackets = 0; - packetsCaught=0; - frameIndex=0; - if(sfilefd) {cprintf(RED,"**FILE not closed!\n");fclose(sfilefd);sfilefd=NULL;} - guiData = NULL; - guiDataReady=0; - strcpy(guiFileName,""); - cbAction = DO_EVERYTHING; - - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - createfile_mask = 0x0; - ret_createfile = OK; - pthread_mutex_unlock(&status_mutex); - - //printouts - cout << "Max Packets Per File:" << maxPacketsPerFile << endl; - if (rawDataReadyCallBack) - cout << "Note: Data Write has been defined exernally" << endl; - if (dataCompression) - cout << "Data Compression is enabled with " << numJobsPerThread << " number of jobs per thread" << endl; - if(nFrameToGui) - cout << "Sending every " << nFrameToGui << "th frame to gui" << endl; - - - - //acquisition start call back returns enable write - if (startAcquisitionCallBack) - cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); - - if(cbAction < DO_EVERYTHING) - cout << endl << "Note: Call back activated. Data saving must be taken care of by user in call back." << endl; - else if(enableFileWrite==0) - cout << endl << "Note: Data will not be saved" << endl; - - - - //creating first file - - //mask - pthread_mutex_lock(&status_mutex); - for(int i=0;i Date: Tue, 13 Oct 2015 15:22:30 +0200 Subject: [PATCH 150/222] some more --- .../include/UDPBaseImplementation.h | 13 +- slsReceiverSoftware/include/UDPInterface.h | 10 +- .../include/UDPStandardImplementation.h | 371 ++-- slsReceiverSoftware/include/logger.h | 6 + .../src/UDPBaseImplementation.cpp | 2 +- .../src/UDPStandardImplementation.cpp | 1966 ++++++++--------- 6 files changed, 1096 insertions(+), 1272 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index c1de8fa6f8..43f98b5110 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -381,10 +381,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Get the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex start index of the acquisition - * @param startFrameIndex start index of the scan + * @param startAcq start index of the acquisition + * @param startFrame start index of the scan */ - void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex); + void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame); /** * abort acquisition with minimum damage: close open files, cleanup. @@ -393,8 +393,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter void abort(); //FIXME: needed, isn't stopReceiver enough? /** - * Closes all files - * @param i thread index, -1 for all threads + * Closes file / all files(if multiple files) + * @param i thread index (if multiple files used eg. root files) -1 for all threads */ void closeFile(int i = -1); @@ -438,6 +438,9 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter protected: + /************************************************************************* + * Class Members ********************************************************* + *************************************************************************/ //**detector parameters*** /** detector type */ detectorType myDetectorType; diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index a3766b8471..b62ad2eb0c 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -439,10 +439,10 @@ class UDPInterface { * Get the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex start index of the acquisition - * @param startFrameIndex start index of the scan + * @param startAcq start index of the acquisition + * @param startFrame start index of the scan */ - virtual void readFrame(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex)=0; + virtual void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame)=0; /** * abort acquisition with minimum damage: close open files, cleanup. @@ -451,8 +451,8 @@ class UDPInterface { virtual void abort() = 0; //FIXME: needed, isnt stopReceiver enough? /** - * Closes all files - * @param i thread index, -1 for all threads + * Closes file / all files(if multiple files) + * @param i thread index (if multiple files used eg. root files) -1 for all threads */ virtual void closeFile(int i = -1) = 0; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 825806e836..cbd46d433e 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -153,12 +153,63 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase int startReceiver(char *c=NULL); /** + * Overridden method + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer,it returns with the status Run_Finished + * Pre: status is running, semaphores have been instantiated, + * Post: udp sockets shut down, status is idle, semaphores destroyed + */ + void stopReceiver(); + + /** + * Overridden method + * Stop Listening to Packets + * and sets status to Transmitting + * Pre: status is running, udp sockets have been initialized, stop receiver initiated + * Post:udp sockets closed, status is transmitting + */ + void startReadout(); + + /** + * Overridden method * Shuts down and deletes UDP Sockets * @return OK or FAIL */ int shutDownUDPSockets(); + /** + * Overridden method + * Get the buffer-current frame read by receiver + * @param c pointer to current file name + * @param raw address of pointer, pointing to current frame to send to gui + * @param startAcq start index of the acquisition + * @param startFrame start index of the scan + */ + void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame); + + /** + * Overridden method + * Closes file / all files(data compression involves multiple files) + * @param i thread index valid for datacompression using root files, -1 for all threads + */ + void closeFile(int i = -1); + private: + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ + +/* + uint64_t (*getFrameNumber)(); + uint64_t eigerGetFrameNumber(); + uint64_t generalGetFrameNumber(); + getframenumber = &generalgetframenumber; + if(dettpe == eiger) getframenumber = &eigerGerFramenumber; + + call using getframenumber(); +*/ //**initial parameters*** @@ -194,6 +245,19 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void initializeFilter(); + /** + * Set up the Fifo Structure for processing buffers + * between listening and writer threads + * @return OK or FAIL + */ + int setupFifoStructure(); + + + + /************************************************************************* + * Listening and Writing Threads ***************************************** + *************************************************************************/ + /** * Create Listening Threads * @param destroy is true to destroy all the threads @@ -212,13 +276,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void setThreadPriorities(); - /** - * Set up the Fifo Structure for processing buffers - * between listening and writer threads - * @return OK or FAIL - */ - int setupFifoStructure(); - /** * Creates UDP Sockets * @return OK or FAIL @@ -232,7 +289,87 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ int setupWriter(); + /** + * Creates new file + * @return OK or FAIL + */ + int createNewFile(); + + /** + * Static function - Starts Listening Thread of this object + * @param this_pointer pointer to this object + */ + static void* startListeningThread(void *this_pointer); + + /** + * Static function - Starts Writing Thread of this object + * @param this_pointer pointer to this object + */ + static void* startWritingThread(void *this_pointer); + /** + * Thread that listens to packets + * It pops the fifofree for free addresses, listens to packets and pushes them into the fifo + * This is continuously looped for each buffer in a nested loop, which is again looped for each acquisition + * Exits only for changing dynamic range, 10G parameters etc and recreated + * + */ + void startListening(); + + /** + * Thread started which writes packets to file. + * It pops the fifo, processes and writes packets to file and pushes the addresses into the fifoFree + * This is continuously looped for each buffer in a nested loop, which is again looped for each acquisition + * Exits only for changing dynamic range, 10G parameters etc and recreated + * + */ + void startWriting(); + + /** + * Called by startListening + * Listens to buffer, until packet(s) received or shutdownUDPsocket called by client + * Also copies carryovers from previous frame in front of buffer (gotthard and moench) + * For eiger, it ignores packets less than onePacketSize + * @param ithread listening thread index + * @param lSize number of bytes to listen to + * @param cSize number of bytes carried on from previous buffer + * @param temp temporary storage of previous buffer + * @return the number of bytes actually received + */ + int prepareAndListenBuffer(int ithread, int lSize, int cSize, char* temp); + + /** + * Called by startListening + * Its called for the first packet of a scan or acquistion + * Sets the startframeindices and the variables to know if acquisition started + * @param ithread listening thread number + */ + void startFrameIndices(int ithread); + + /** + * Called by prepareAndListenBuffer + * This is called when udp socket is shut down by client + * It pushes ffff instead of packet number into fifo + * to inform writers about the end of listening session + * Then sets the listening mask so that it stops listening and wait for next acquisition trigger + * @param ithread listening thread number + * @param numbytes number of bytes received + */ + void stopListening(int ithread, int numbytes); + + /* + * Called by startListening for gotthard and moench to handle split frames + * It processes listening thread buffers by ensuring split frames are in the same buffer + * @param ithread listening thread index + * @param cSize number of bytes carried over to the next buffer to reunite with split frame + * @param temp temporary buffer to store the split frame + * @return packet count + */ + uint32_t processListeningBuffer(int ithread, int cSize,char* temp); + + /************************************************************************* + * Class Members ********************************************************* + *************************************************************************/ //**detector parameters*** /** @@ -284,7 +421,18 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase //***File parameters*** - /** Maximum Packets Per File **/ +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUMBER_OF_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUMBER_OF_WRITER_THREADS]; +#endif + + /** Complete File name */ + char completeFileName[MAX_STR_LENGTH]; + + /** Maximum Packets Per File **/ int maxPacketsPerFile; /** If file created successfully for all Writer Threads */ @@ -306,6 +454,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Current Frame Number */ uint64_t currentFrameNumber; + /** Previous Frame number from buffer to calculate loss */ + uint64_t previousFrameNumber; + /* Acquisition started */ bool acqStarted; @@ -356,6 +507,11 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Fifo Depth */ uint32_t fifoSize; + /** Missing Packet identifier value */ + const static uint16_t missingPacketValue = 0xFFFF; + + /** Dummy Packet identifier value */ + const static uint32_t dummyPacketValue = 0xFFFFFFFF; //***receiver to GUI parameters*** /** Current Frame copied for GUI */ @@ -381,6 +537,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Ensures if threads created successfully */ bool threadStarted; + /** Current Thread Index*/ + int currentThreadIndex; + /** Number of Listening Threads */ int numberofListeningThreads; @@ -414,9 +573,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Semaphores Synchronizing Writer Threads */ sem_t writerSemaphore[MAX_NUMBER_OF_WRITER_THREADS]; - /** Current Writer Thread Index*/ - int currentWriterThreadIndex; - /** Mask with each bit indicating status of each writer thread */ volatile uint32_t writerThreadsMask; @@ -447,9 +603,17 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase //***mutex*** - /** mutex for status */ - pthread_mutex_t status_mutex; + /** Status mutex */ + pthread_mutex_t statusMutex; + /** Writing mutex */ + pthread_mutex_t writeMutex; + + /** GuiDataReady Mutex */ + pthread_mutex_t dataReadyMutex; + + /** Progress (currentFrameNumber) Mutex */ + pthread_mutex_t progressMutex; //***callback*** /** The action which decides what the user and default responsibilities to save data are @@ -475,32 +639,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase - /** - * Returns the buffer-current frame read by receiver - * @param c pointer to current file name - * @param raw address of pointer, pointing to current frame to send to gui - * @param startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan - */ - void readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); - - /** - * Closes all files - * @param ithr thread index - */ - void closeFile(int ithr = -1); - - - /** - * Stops Receiver - stops listening for packets - * Returns success - */ - int stopReceiver(); - - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished - */ - void startReadout(); @@ -513,8 +651,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void copyFrameToGui(char* startbuf[], char* buf=NULL); - - /** * Creates new tree and file for compression * @param ithr thread number @@ -523,40 +659,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ int createCompressionFile(int ithr, int iframe); - /** - * Creates new file - *\returns OK for succces or FAIL for failure - */ - int createNewFile(); - - /** - * Static function - Thread started which listens to packets. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startListeningThread(void *this_pointer); - - /** - * Static function - Thread started which writes packets to file. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startWritingThread(void *this_pointer); - - /** - * Thread started which listens to packets. - * Called by startReceiver() - * - */ - int startListening(); - - /** - * Thread started which writes packets to file. - * Called by startReceiver() - * - */ - int startWriting(); - /** * Writing to file without compression * @param buf is the address of buffer popped out of fifo @@ -565,25 +667,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum); - /** - * Its called for the first packet of a scan or acquistion - * Sets the startframeindices and the variables to know if acquisition started - * @param ithread listening thread number - * @param numbytes number of bytes it listened to - */ - void startFrameIndices(int ithread, int numbytes); - - /** - * This is called when udp socket is shut down - * It pops ffff instead of packet number into fifo - * to inform writers about the end of listening session - * @param ithread listening thread number - * @param rc number of bytes received - * @param pc packet count - * @param t total packets listened to - */ - void stopListening(int ithread, int rc, int &pc, int &t); - /** * When acquisition is over, this is called * @param ithread listening thread number @@ -615,110 +698,10 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase - - - - - - - - - - - - - - - - - - - - - - /** missing packet identifier value */ - const static uint16_t missingPacketValue = 0xFFFF; - - -/** Complete File name */ - char savefilename[MAX_STR_LENGTH]; - - - - /** Previous Frame number from buffer */ - int prevframenum; - - - - - - - // TODO: not properly sure where to put these... - /** structure of an eiger image header*/ - - - - -//semaphores - - -//mutex - /** guiDataReady mutex */ - pthread_mutex_t dataReadyMutex; - - /** mutex for progress variable currframenum */ - pthread_mutex_t progress_mutex; - - /** mutex for writing data to file */ - pthread_mutex_t write_mutex; - //filter -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif - - - - -public: - - - /** - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; - - /** - callback argument is - toatal frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; }; diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index cba284fb19..5e964da271 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -23,6 +23,12 @@ #define TOSTRING(x) STRINGIFY(x) #define MYCONCAT(x,y) #define __AT__ string(__FILE__) + string("::") + string(__func__) + string("(): ") +#define __SHORT_FORM_OF_FILE__ \ +(strrchr(__FILE__,'/') \ +? strrchr(__FILE__,'/')+1 \ +: __FILE__ \ +) +#define __SHORT_AT__ string(__SHORT_FORM_OF_FILE__) + string("::") + string(__func__) + string("(): ") //":" TOSTRING(__LINE__) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index ec5c27ad54..75f7fa244e 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -37,7 +37,7 @@ UDPBaseImplementation::UDPBaseImplementation(){ //***connection parameters*** strcpy(eth,""); - for(int i=0;i /proc/sys/net/core/rmem_max")) + cout << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) + cout << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + /** permanent setting by heiner + net.core.rmem_max = 104857600 # 100MiB + net.core.netdev_max_backlog = 250000 + sysctl -p + // from the manual + sysctl -w net.core.rmem_max=16777216 + sysctl -w net.core.netdev_max_backlog=250000 + */ } UDPStandardImplementation::~UDPStandardImplementation(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; deleteMembers(); } @@ -49,13 +69,13 @@ UDPStandardImplementation::~UDPStandardImplementation(){ /***initial parameters***/ void UDPStandardImplementation::deleteBaseMembers(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; UDPBaseImplementation::~UDPBaseImplementation(); } void UDPStandardImplementation::deleteMembers(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; cout << "Info: Deleting member pointers" << endl; shutDownUDPSockets(); @@ -77,7 +97,7 @@ void UDPStandardImplementation::deleteMembers(){ } void UDPStandardImplementation::deleteFilter(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; moenchCommonModeSubtraction = NULL; for(int i=0; igetErrorStatus(); - if(!iret){ - cout << "Info: UDP port opened at port " << port[i] << endl; - }else{ -#ifdef VERBOSE - cprintf(BG_RED,"Error: Could not create UDP socket on port %d error: %d\n", port[i], iret); -#endif - shutDownUDPSockets(); - return FAIL; - } - } - - cout << "Info: UDP socket(s) created successfully." << endl; - cout << "Info: Listener Ready ..." << endl; - - return OK; -} - - - -int UDPStandardImplementation::setupWriter(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; - - //acquisition start call back returns enable write - cbAction = DO_EVERYTHING; - if (startAcquisitionCallBack) - cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); - - if(cbAction < DO_EVERYTHING){ - cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; - if (rawDataReadyCallBack) - cout << "Info: Data Write has been defined externally" << endl; - }else if(!fileWriteEnable) - cout << "Info: Data will not be saved" << endl; - - - - //creating first file - //setting all value to 1 - pthread_mutex_lock(&status_mutex); - for(int i=0; i config_map){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; map::const_iterator pos; pos = config_map.find("mode"); @@ -596,7 +376,7 @@ void UDPStandardImplementation::configure(map config_map){ /***file parameters***/ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; cout << "Info: Setting up Data Compression Enable to " << stringEnable(b); #ifdef MYROOT1 @@ -609,9 +389,9 @@ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ dataCompressionEnable = b; //-- create writer threads depending on enable - pthread_mutex_lock(&status_mutex); + pthread_mutex_lock(&statusMutex); writerThreadsMask = 0x0; - pthread_mutex_unlock(&(status_mutex)); + pthread_mutex_unlock(&(statusMutex)); createWriterThreads(true); if(b) @@ -638,7 +418,7 @@ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ /***acquisition parameters***/ void UDPStandardImplementation::setShortFrameEnable(const int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; shortFrameEnable = i; @@ -675,7 +455,7 @@ void UDPStandardImplementation::setShortFrameEnable(const int i){ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; if(i >= 0){ FrameToGuiFrequency = i; @@ -690,7 +470,7 @@ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; if(i >= 0){ acquisitionPeriod = i; @@ -705,7 +485,7 @@ int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ } int UDPStandardImplementation::setDynamicRange(const uint32_t i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; int oldDynamicRange = dynamicRange; @@ -759,7 +539,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ int UDPStandardImplementation::setTenGigaEnable(const bool b){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Info: Setting Ten Giga to " << string(b) << endl; bool oldTenGigaEnable = tengigaEnable; @@ -829,15 +609,19 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ -/************************************************************************* - * Behavioral functions*************************************************** - * They may modify the status of the receiver **************************** + + + + +/************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** *************************************************************************/ /***initial functions***/ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Setting receiver type ..." << endl; @@ -857,7 +641,7 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy cout << "Info: ***** This is a " << slsDetectorBase::getDetectorType(d) << " Receiver *****" << endl; break; default: - cout << "Error: This is an unknown receiver type " << (int)d << endl; + cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); return FAIL; } @@ -934,9 +718,9 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy //delete threads and set number of listening threads if(myDetectorType == EIGER){ - pthread_mutex_lock(&status_mutex); + pthread_mutex_lock(&statusMutex); listeningThreadsMask = 0x0; - pthread_mutex_unlock(&(status_mutex)); + pthread_mutex_unlock(&(statusMutex)); if(threadStarted) createListeningThreads(true); numberofListeningThreads = MAX_NUMBER_OF_LISTENING_THREADS; @@ -949,11 +733,11 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy //create threads if(createListeningThreads() == FAIL){ cprintf(BG_RED,"Error: Could not create listening thread\n"); - exit (-1); + return FAIL; } if(createWriterThreads() == FAIL){ cprintf(BG_RED,"Error: Could not create writer threads\n"); - exit (-1); + return FAIL; } setThreadPriorities(); @@ -969,7 +753,7 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy /***acquisition functions***/ void UDPStandardImplementation::resetAcquisitionCount(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logDEBUG1) << __AT__ << " starting"; totalPacketsCaught = 0; acqStarted = false; @@ -980,7 +764,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c=NULL){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Info: Starting Receiver" << endl; @@ -1009,11 +793,11 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ guiDataReady=0; strcpy(guiFileName,""); //reset masks - pthread_mutex_lock(&status_mutex); + pthread_mutex_lock(&statusMutex); writerThreadsMask = 0x0; createFileMask = 0x0; fileCreateSuccess = false; - pthread_mutex_unlock(&status_mutex); + pthread_mutex_unlock(&statusMutex); //Print Receiver Configuration @@ -1024,6 +808,8 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ cout << "Info: Number of Jobs Per Buffer: " << numberofJobsPerBuffer << endl; if(FrameToGuiFrequency) cout << "Info: Frequency of frames sent to gui" << FrameToGuiFrequency << endl; + else + cout << "Info: Random frames sent to gui" << endl; @@ -1031,54 +817,84 @@ int UDPStandardImplementation::startReceiver(char *c=NULL){ if(createUDPSockets() == FAIL){ strcpy(c,"Could not create UDP Socket(s).\n"); cout << endl; - cout << "Error: "<< c << endl; + cprintf(BG_RED, "Error: %s\n",c); return FAIL; } if(setupWriter() == FAIL){ //stop udp socket shutDownUDPSockets(); - sprintf(c,"Could not create file %s.\n",savefilename); + sprintf(c,"Could not create file %s.\n",completeFileName); cout << endl; - cout << "Error: "<< c << endl; + cprintf(BG_RED, "Error: %s\n",c); return FAIL; } - //For compression, done to give the gui some proper name instead of always the last file name + //For compression, just for gui purposes if(dataCompressionEnable) - sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + sprintf(completeFileName, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); //initialize semaphore to synchronize between writer and gui reader threads sem_init(&writerGuiSemaphore,1,0); //status and thread masks - pthread_mutex_lock(&status_mutex); + pthread_mutex_lock(&statusMutex); status = RUNNING; - for(int i=0;iGetCurrentFile(); + if(myFile[i]->Write()) + //->Write(tall->GetName(),TObject::kOverwrite); + cout << "Info: Thread " << i <<": wrote frames to file" << endl; + else + cout << "Info: Thread " << i << ": could not write frames to file" << endl; + }else + cout << "Info: Thread " << i << ": could not write frames to file: No file or No Tree" << endl; + //close file + if(myTree[i] && myFile[i]) + myFile[i] = myTree[i]->GetCurrentFile(); + if(myFile[i] != NULL) + myFile[i]->Close(); + myFile[i] = NULL; + myTree[i] = NULL; + pthread_mutex_unlock(&writeMutex); +#endif + } +} +/************************************************************************* + * Listening and Writing Threads ***************************************** + *************************************************************************/ +int UDPStandardImplementation::createListeningThreads(bool destroy){ + FILE_LOG(logDEBUG1) << __AT__ << " starting"; + //reset masks + killAllListeningThreads = false; + pthread_mutex_lock(&statusMutex); + listeningThreadsMask = 0x0; + pthread_mutex_unlock(&(statusMutex)); + //destroy + if(destroy){ + cout << "Info: Destroying Listening Thread(s)" << endl; + killAllListeningThreads = true; + for(int i = 0; i < numberofListeningThreads; ++i){ + sem_post(&listenSemaphore[i]); + pthread_join(listeningThreads[i],NULL); + cout <<"."< /proc/sys/net/core/rmem_max")) - cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; - else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) - cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + //destroy threads + if(destroy){ + cout << "Info: Destroying Writer Thread(s)" << endl; - /** permanent setting heiner - net.core.rmem_max = 104857600 # 100MiB - net.core.netdev_max_backlog = 250000 - sysctl -p - // from the manual - sysctl -w net.core.rmem_max=16777216 - sysctl -w net.core.netdev_max_backlog=250000 - */ + killAllWritingThreads = true; + for(int i = 0; i < numberofWriterThreads; ++i){ + sem_post(&writerSemaphore[i]); + pthread_join(writingThreads[i],NULL); + cout <<"."<getErrorStatus(); + if(!iret){ + cout << "Info: UDP port opened at port " << port[i] << endl; + }else{ +#ifdef VERBOSE + cprintf(BG_RED,"Error: Could not create UDP socket on port %d error: %d\n", port[i], iret); +#endif + shutDownUDPSockets(); + return FAIL; + } + } + cout << "Info: UDP socket(s) created successfully." << endl; + cout << "Info: Listener Ready ..." << endl; - strcpy(savefilename,""); - + return OK; +} - //strcpy(filePath,""); - //strcpy(fileName,"run"); +int UDPStandardImplementation::setupWriter(){ + FILE_LOG(logDEBUG1) << __AT__ << " starting"; - //status - pthread_mutex_lock(&status_mutex); - status = IDLE; - pthread_mutex_unlock(&(status_mutex)); + //acquisition start call back returns enable write + cbAction = DO_EVERYTHING; + if (startAcquisitionCallBack) + cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); -} + if(cbAction < DO_EVERYTHING){ + cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; + if (rawDataReadyCallBack) + cout << "Info: Data Write has been defined externally" << endl; + }else if(!fileWriteEnable) + cout << "Info: Data will not be saved" << endl; -UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + //creating first file + //setting all value to 1 + pthread_mutex_lock(&statusMutex); + for(int i=0; i DO_NOTHING){ - for(int i=0;istartListening(); + return this_pointer; +} -//uint32_t UDPStandardImplementation::getStartFrameIndex(){return startFrameIndex;} -/* - acquisitionIndex = currframenum - startAcquisitionIndex - frameIndex = currframenum - startFrameIndex; +void* UDPStandardImplementation::startWritingThread(void* this_pointer){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + ((UDPStandardImplementation*)this_pointer)->startWriting(); + return this_pointer; } -*/ +void UDPStandardImplementation::startListening(){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + //set current thread value index + int ithread = currentThreadIndex; + //let calling function know thread started and obtained current + threadStarted = 1; + //variable definitions + int listenSize = 0; //listen to only 1 packet + uint32_t rc; //size of buffer received in bytes + //split frames + int carryonBufferSize; //from previous buffer to keep frames together in a buffer + char* tempBuffer = NULL; //temporary buffer to store split frames + if(myDetectorType != EIGER){ + listenSize = bufferSize * numberofJobsPerBuffer; //listen to more than 1 packet + tempBuffer = new char[onePacketSize * (packetsPerFrame - 1)]; //store maximum of 1 packets less in a frame + } + /* outer loop - loops once for each acquisition */ + //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) + while(true){ + //reset parameters before acquisition + carryonBufferSize = 0; + /* inner loop - loop for each buffer */ + //until mask unset (udp sockets shut down by client) + while((1 << ithread) & listeningThreadsMask){ + //pop from fifo + fifoFree[ithread]->pop(buffer[ithread]); +#ifdef FIFODEBUG + cprintf(BLUE,"%d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); +#endif + //udpsocket doesnt exist + if(udpSocket[ithread] == NULL){ + cprintf(RED, "Error: Thread %d :UDP Socket not created\n",ithread); + stopListening(ithread,0); + continue; + } + rc = prepareAndListenBuffer(ithread, listenSize, carryonBufferSize, tempBuffer); + //start indices for each start of scan/acquisition + if((!measurementStarted) && (rc > 0)){ + pthread_mutex_lock(&progressMutex); + if(!measurementStarted) + startFrameIndices(ithread); + pthread_mutex_unlock(&progressMutex); + } + //problem in receiving or end of acquisition + if (status == TRANSMITTING){ + stopListening(ithread,rc); + continue; + } + //write packet count to buffer + if(myDetectorType == EIGER) + (*((uint32_t*)(buffer[ithread]))) = 1; + //handling split frames and writing packet Count to buffer + else + (*((uint32_t*)(buffer[ithread]))) = processListeningBuffer(ithread, carryonBufferSize, tempBuffer); + //push buffer to FIFO + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFODEBUG + cprintf(BLUE,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); +#endif + }/*--end of loop for each buffer (inner loop)*/ -/*other parameters*/ + //end of acquisition, wait for next acquisition/change of parameters + sem_wait(&listenSemaphore[ithread]); + //check to exit thread (for change of parameters) - only EXIT possibility + if(killAllListeningThreads){ + cprintf(GREEN,"Listening_Thread %d:Goodbye!\n",ithread); + //free resources at exit + if(tempBuffer) delete[] tempBuffer; + pthread_exit(NULL); + } + }/*--end of loop for each acquisition (outer loop) */ +} -/** acquisition functions */ -void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - //point to gui data - if (guiData == NULL){ - guiData = latestData; -#ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gui data not null anymore\n"); -#endif - } - //copy data and filename - strcpy(c,guiFileName); - startAcquisitionIndex = getStartAcquisitionIndex(); - startFrameIndex = getStartFrameIndex(); - //could not get gui data - if(!guiDataReady){ -#ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gui data not ready\n"); +int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, int cSize, char* temp){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + //listen to UDP packets + memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); + int receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, lSize + cSize); + + //throw away packets that is not one packet size, need to check status if socket is shut down + while(status != TRANSMITTING && myDetectorType == EIGER && receivedSize != onePacketSize) { + if(receivedSize != EIGER_HEADER_LENGTH) + cprintf(RED,"Listening_Thread %d: Listened to a weird packet size %d\n",receivedSize); +#ifdef DEBUG + else + cprintf(BLUE,"Listening_Thread %d: Listened to a header packet\n",ithread); #endif - *raw = NULL; + receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); } - //data ready, set guidata to receive new data - else{ -#ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gui data ready\n"); -#endif - *raw = guiData; - guiData = NULL; - /*pthread_mutex_lock(&dataReadyMutex); WHY WAS THIS HERE IN THE FIRST PLACE - guiDataReady = 0; - pthread_mutex_unlock(&dataReadyMutex);*/ - if((nFrameToGui) && (writerthreads_mask)){ -#ifdef VERY_VERY_DEBUG - cprintf(CYAN,"gonna post\n"); +#ifdef DEBUG + cprintf(BLUE, "Listening_Thread %d : Received bytes: %d. Expected bytes: %d\n", ithread, receivedSize, expected-cSize); #endif - /*if(nFrameToGui){*/ - //release after getting data - sem_post(&smp); + return receivedSize; +} + + +void UDPStandardImplementation::startFrameIndices(int ithread){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + //determine startFrameIndex + switch(myDetectorType){ + case EIGER: + startFrameIndex = 0; //frame number always resets + break; + default: + if(shortFrameEnable < 0){ + startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset); + }else{ + startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) + & (frameIndexMask)) >> frameIndexOffset); } -#ifdef VERY_VERY_DEBUG - cprintf(CYAN,"done post\n"); -#endif + break; + } + + //start of entire acquisition + if(!acqStarted){ + startAcquisitionIndex = startFrameIndex; + acqStarted = true; + cprintf(BLUE,"Info: Thread %d: startAcquisitionIndex:%d\n",ithread,startAcquisitionIndex); } + + //set start of scan/real time measurement + cprintf(BLUE,"Info: Thread %d: startFrameIndex: %d\n", ithread,startFrameIndex); + measurementStarted = true; } -void UDPStandardImplementation::copyFrameToGui(char* startbuf[], char* buf){ - FILE_LOG(logDEBUG) << __AT__ << " called"; -#ifdef VERY_VERY_DEBUG -cout << "copyframe" << endl; -#endif +void UDPStandardImplementation::stopListening(int ithread, int numbytes){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; - //random read when gui not ready , also command line doesnt have nthframetogui - //else guidata always null as guidataready is always 1 after 1st frame, and seccond data never gets copied - if((!nFrameToGui) && (!guiData)){ -#ifdef VERY_VERY_DEBUG - cprintf(GREEN,"doing nothing\n"); + cout << "Info: Stop Listening. Status:" << slsDetectorBase::runStatusType(status) << endl; + + + //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) + if(numbytes < onePacketSize) + numbytes = 0; + + + //free empty buffer + if(numbytes <= 0){ + cprintf(BLUE,"Info: Thread %d :End of Acquisition for Listening Thread\n", ithread); + while(!fifoFree[ithread]->push(buffer[ithread])); +#ifdef FIFODEBUG + cprintf(BLUE,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - pthread_mutex_unlock(&dataReadyMutex); } - //random read or nth frame read, gui needs data now or it is the first frame + + //push last non empty buffer into fifo else{ -#ifdef VERY_VERY_DEBUG - cprintf(GREEN,"gui needs data now or 1st frame\n"); + (*((uint32_t*)(buffer[ithread]))) = numbytes/onePacketSize; + totalListeningFrameCount[ithread] += (numbytes/onePacketSize); +#ifdef DEBUG + cprintf(BLUE,"Listening_Thread %d: Last Buffer numBytes:%d\n",ithread, numbytes); + cprintf(BLUE,"Listening_Thread %d: Last Buffer packet count:%d\n",ithread, numbytes/onePacketSize); #endif - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; -#ifdef VERY_VERY_DEBUG - cprintf(GREEN,"guidataready is 0, copying data\n"); + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFODEBUG + cprintf(BLUE,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); #endif - //eiger - if(startbuf != NULL){ - - for(int j=0;jpop(buffer[ithread]); + //creating dummy-end buffer with pc=0xFFFF + (*((uint32_t*)(buffer[ithread]))) = dummyPacketValue; + while(!fifo[ithread]->push(buffer[ithread])); +#ifdef FIFODEBUG + cprintf(BLUE,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); +#endif + } - strcpy(guiFileName,savefilename); - guiDataReady=1; - pthread_mutex_unlock(&dataReadyMutex); -#ifdef VERY_VERY_DEBUG - cprintf(GREEN,"guidataready = 1\n"); + //reset mask and exit loop + pthread_mutex_lock(&statusMutex); + listeningThreadsMask^=(1< 1) + cprintf(BLUE,"Listening_Thread %d: Waiting for other listening threads to be done.. current mask:0x%x\n", ithread, listeningThreadsMask); #endif - sem_wait(&smp); -#ifdef VERY_VERY_DEBUG - cprintf(GREEN,"done waiting\n"); + while(listeningThreadsMask) + usleep(5000); +#ifdef DEBUG4 + int t=0; + for(i=0;iinitEventTree(temp, &iframe); - //resets the pedestalSubtraction array and the commonModeSubtraction - singlePhotonDet[ithr]->newDataSet(); - if(myFile[ithr]==NULL){ - cout<<"file null"<IsOpen()){ - cout<<"file not open"<> frameIndexOffset)); +#endif + cSize = onePacketSize; + --packetCount; + } } +#ifdef DEBUG4 + cprintf(BLUE, "Listening_Thread %d: First Header:%d\n", (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) + & (frameIndexMask)) >> frameIndexOffset)); #endif - return OK; -} + break; + case MOENCH: + lastPacketOffset = (((numberofJobsPerBuffer * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef DEBUG4 + cprintf(BLUE, "Listening_Thread %d: First Header:%d\t First Packet:%d\t Last Header:%d\t Last Packet:%d\tLast Packet Offset:%d\n", + (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset), + ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)), + (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset), + ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)), + lastPacketOffset); +#endif + //moench last packet value is 0, so find the last packet and store the others in a temp storage + if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastPacketOffset))))) & (packetIndexMask))){ + lastFrameHeader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastPacketOffset))))) + & (frameIndexMask)) >> frameIndexOffset; + cSize += onePacketSize; + lastPacketOffset -= onePacketSize; + --packetCount; + while (lastFrameHeader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastPacketOffset))))) & (frameIndexMask)) >> frameIndexOffset)){ + cSize += onePacketSize; + lastPacketOffset -= onePacketSize; + --packetCount; + } + memcpy(temp, buffer[ithread]+(lastPacketOffset+onePacketSize), cSize); +#ifdef DEBUG4 + cprintf(BLUE, "Listening_Thread %d: temp Header:%d\t temp Packet:%d\n", + (((((uint32_t)(*((uint32_t*)(temp)))))& (frameIndexMask)) >> frameIndexOffset), + ((((uint32_t)(*((uint32_t*)(temp))))) & (packetIndexMask))); +#endif + } + break; + default: + cprintf(RED,"Listening_Thread %d: Error: This detector is not implemented in the receiver" + + slsDetectorBase::getDetectorType(myDetectorType).c_str() + "\n"); + break; + } +#ifdef DEBUG4 + cprintf(BLUE,"Listening_Thread %d: PacketCount:%d CarryonBufferSize:%d\n",ithread, packetCount, cSize); +#endif -int UDPStandardImplementation::createNewFile(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + return packetCount; +} - int gt = getFrameIndex(); - if(gt==-1) gt=0; - //create file name - if(frameIndexNeeded==-1) - sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); - else if (myDetectorType == EIGER) - sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,currframenum,fileIndex); - else - sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex); -#ifdef VERBOSE - cout << filePath << " + " << fileName << endl; -#endif - //if filewrite and we are allowed to write - if(enableFileWrite && cbAction > DO_NOTHING){ - //close - if(sfilefd){ - if(fclose(sfilefd)){ - cprintf(RED, "file close problem %d\n",fileno(sfilefd)); - fclose(sfilefd); - } - sfilefd = NULL; - } - //open file - if(!overwrite){ - if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cprintf(BG_RED,"Error: Could not create new file %s\n",savefilename); - return FAIL; - } - }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cprintf(BG_RED,"Error: Could not create file %s\n",savefilename); - return FAIL; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - //printing packet losses and file names - if(!packetsCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)<GetCurrentFile(); + }/*--end of loop for each acquisition (outer loop) */ + +} + + + + + + + + + + + + + - if(myFile[ithr]->Write()) - //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Thread " << ithr <<": wrote frames to file" << endl; - else - cout << "Thread " << ithr << ": could not write frames to file" << endl; - }else - cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; - //close file - if(myTree[ithr] && myFile[ithr]) - myFile[ithr] = myTree[ithr]->GetCurrentFile(); - if(myFile[ithr] != NULL) - myFile[ithr]->Close(); - myFile[ithr] = NULL; - myTree[ithr] = NULL; - pthread_mutex_unlock(&write_mutex); -#endif - } -} -/** - * Pre: status is running, semaphores have been instantiated, - * Post: udp sockets shut down, status is idle, sempahores destroyed - * */ -int UDPStandardImplementation::stopReceiver(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - if(status != IDLE){ - //#ifdef VERBOSE - cout << "Stopping Receiver" << endl; - //#endif - startReadout(); - while(status == TRANSMITTING){ - sem_post(&smp); - usleep(5000); - } - //semaphore destroy - sem_destroy(&smp); - //change status - pthread_mutex_lock(&status_mutex); - status = IDLE; - pthread_mutex_unlock(&(status_mutex)); - cout << "Receiver Stopped.\nStatus:" << status << endl << endl; - }else cout <<" Not idle to stop receiver" << endl; - //sem_post(&smp); - return OK; -} -/** - * Pre: status is running, udp sockets have been initialized, - * stop receiver initiated - * Post:udp sockets closed, status is transmitting - * */ -void UDPStandardImplementation::startReadout(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - //#ifdef VERBOSE - cout << "Start Receiver Readout" << endl; - //#endif - if(status == RUNNING){ - //wait so that all packets which take time has arrived - usleep(5000); - /********************************************/ - //usleep(10000000); - //usleep(2000000); - uint32_t prev = totalPacketsCaught; - usleep(50000); - while(prev!=totalPacketsCaught){ - prev=totalPacketsCaught; - usleep(50000); - } - pthread_mutex_lock(&status_mutex); - status = TRANSMITTING; - pthread_mutex_unlock(&status_mutex); - cout << "Status: Transmitting" << endl; - } - //kill udp socket to tell the listening thread to push last packet - shutDownUDPSockets(); -} -void* UDPStandardImplementation::startListeningThread(void* this_pointer){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - ((UDPStandardImplementation*)this_pointer)->startListening(); - return this_pointer; -} -void* UDPStandardImplementation::startWritingThread(void* this_pointer){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - ((UDPStandardImplementation*)this_pointer)->startWriting(); - return this_pointer; -} -int UDPStandardImplementation::startListening(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - int ithread = currentListeningThreadIndex; -#ifdef VERYVERBOSE - cprintf(BLUE, "In startListening()\n "); -#endif - thread_started = 1; - int total; - int lastpacketoffset, expected, rc,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader;// for moench to check for all the packets in last frame - char* tempchar = NULL; - while(1){ - //variables that need to be checked/set before each acquisition - carryonBufferSize = 0; - maxBufferSize = bufferSize * numJobsPerThread; -#ifdef VERYDEBUG - cprintf(BLUE, "%d maxBufferSize:%d carryonBufferSize:%d\n", ithread,maxBufferSize,carryonBufferSize); -#endif - //missing packets compensation in listening thread - if(tempchar) {delete [] tempchar;tempchar = NULL;} - if(myDetectorType != EIGER) - tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - else - maxBufferSize = 0; - while((1<pop(buffer[ithread]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread])); -#endif - //ensure udpsocket exists - if(udpSocket[ithread] == NULL){ - rc = 0; - cprintf(BLUE, "%d UDP Socket is NULL\n",ithread); - } - //normal listening - else if(!carryonBufferSize){ -#ifdef SOCKET_DEBUG - if(!ithread){ -#endif - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - if(rc == EIGER_HEADER_LENGTH && myDetectorType == EIGER) { - while(rc == EIGER_HEADER_LENGTH){ - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - } - } - expected = maxBufferSize; -#ifdef SOCKET_DEBUG - }else{ - while(1) usleep(100000000); - } -#endif - } - //the remaining packets from previous buffer, copy it and listen to n less frame - else{ -#ifdef VERYDEBUG - cprintf(BLUE, "%d carry on buffer size:%d\n",ithread,carryonBufferSize); - cprintf(BLUE, "%d framennum in tempchar:%d\n",((((uint32_t)(*((uint32_t*)tempchar))) - & (frameIndexMask)) >> frameIndexOffset)); - cprintf(BLUE, "%d tempchar packet:%d\n", ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask))); -#endif - memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, tempchar, carryonBufferSize); - rc = udpSocket[ithread]->ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); - expected = maxBufferSize - carryonBufferSize; - } -#ifdef EIGER_DEBUG - cprintf(BLUE, "%d rc: %d. expected: %d\n", ithread, rc, expected); -#endif - //start indices for each start of scan/acquisition - if((!measurementStarted) && (rc > 0)){ - pthread_mutex_lock(&progress_mutex); - if(!measurementStarted) - startFrameIndices(ithread, rc); - pthread_mutex_unlock(&progress_mutex); - } - //problem in receiving or end of acquisition - if (status == TRANSMITTING){ - stopListening(ithread,rc,packetcount,total); - continue; - } +/* + acquisitionIndex = currframenum - startAcquisitionIndex + frameIndex = currframenum - startFrameIndex; +} +*/ - //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - //check if last packet valid and calculate packet count - switch(myDetectorType){ - case MOENCH: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; - cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; - cout << "last packet offset:" << lastpacketoffset << endl; - cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; - cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - //moench last packet value is 0 - if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ - lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) - & (frameIndexMask)) >> frameIndexOffset) << endl; - cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask)) << endl; +void UDPStandardImplementation::copyFrameToGui(char* startbuf[], char* buf){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; +#ifdef VERY_VERY_DEBUG +cout << "copyframe" << endl; #endif - } - break; - case GOTTHARD: - case PROPIX: - if(shortFrame == -1){ - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cprintf(BLUE, "%d last packet offset:%d\n",ithread, lastpacketoffset); + //random read when gui not ready , also command line doesnt have nthframetogui + //else guidata always null as guidataready is always 1 after 1st frame, and seccond data never gets copied + if((!nFrameToGui) && (!guiData)){ +#ifdef VERY_VERY_DEBUG + cprintf(GREEN,"doing nothing\n"); #endif - //if not last packet - if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ - memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); -#ifdef VERYDEBUG - cprintf(BLUE, "%d tempchar header:%d\n",ithread,(((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset)); + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + pthread_mutex_unlock(&dataReadyMutex); + } + + //random read or nth frame read, gui needs data now or it is the first frame + else{ +#ifdef VERY_VERY_DEBUG + cprintf(GREEN,"gui needs data now or 1st frame\n"); #endif - carryonBufferSize = onePacketSize; - --packetcount; - } - } -#ifdef VERYDEBUG - cprintf(BLUE, "%d header:%d\n", (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset)); + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; +#ifdef VERY_VERY_DEBUG + cprintf(GREEN,"guidataready is 0, copying data\n"); #endif - break; - - - - case EIGER: - //because even headers might be included, so not packet count - (*((uint32_t*)(buffer[ithread]))) = rc; - packetcount = 1; - break; + //eiger + if(startbuf != NULL){ - default: - break; - } + for(int j=0;jpush(buffer[ithread])); -#ifdef FIFO_DEBUG - cprintf(BLUE, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); + sem_wait(&smp); +#ifdef VERY_VERY_DEBUG + cprintf(GREEN,"done waiting\n"); #endif + } + } +} - } - sem_wait(&listensmp[ithread]); - //make sure its not exiting thread - if(killAllListeningThreads){ - cout << ithread << " good bye listening thread" << endl; - if(tempchar) {delete [] tempchar;tempchar = NULL;} - pthread_exit(NULL); - } - if(tempchar) {delete [] tempchar;tempchar = NULL;} - } +int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; +#ifdef MYROOT1 + char temp[MAX_STR_LENGTH]; + //create file name for gui purposes, and set up acquistion parameters + sprintf(temp, "%s/%s_fxxx_%d_%d.root", filePath,fileName,fileIndex,ithr); + //file + myFile[ithr] = new TFile(temp,"RECREATE");/** later return error if it exists */ + cout << "Thread " << ithr << ": created File: "<< temp << endl; + //tree + sprintf(temp, "%s_fxxx_%d_%d",fileName,fileIndex,ithr); + myTree[ithr]=singlePhotonDet[ithr]->initEventTree(temp, &iframe); + //resets the pedestalSubtraction array and the commonModeSubtraction + singlePhotonDet[ithr]->newDataSet(); + if(myFile[ithr]==NULL){ + cout<<"file null"<IsOpen()){ + cout<<"file not open"<> frameIndexOffset); - else - startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) - & (frameIndexMask)) >> frameIndexOffset); - - - //start of acquisition - if(!acqStarted){ - startAcquisitionIndex=startFrameIndex; - //currframenum = startAcquisitionIndex; - acqStarted = true; - cprintf(BLUE,"%d startAcquisitionIndex:%d\n", ithread, startAcquisitionIndex); - } - - cprintf(BLUE,"%d startFrameIndex: %d\n", ithread,startFrameIndex); - prevframenum=startFrameIndex-1; //so that there is no packet loss, when currframenum(max,20) - prevframenum(1) - measurementStarted = true; - -} - - - -void UDPStandardImplementation::stopListening(int ithread, int rc, int &pc, int &t){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - - int i; - -#ifdef VERYVERBOSE - cprintf(BLUE, "%d Stop Listening\n", ithread); -#endif - - - if(status != TRANSMITTING){ - cprintf(BG_RED,"%d *** udp socket not shut down from client ***********************\n", ithread); - while(!fifoFree[ithread]->push(buffer[ithread])); - exit(-1); - } - - - //free buffer - if(rc <= 0){ - cprintf(BLUE,"%d End of acquisition for Listening Thread\n", ithread); - while(!fifoFree[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); -#endif - } - - - //push the last buffer into fifo - else{ - if(myDetectorType == EIGER){ - (*((uint32_t*)(buffer[ithread]))) = rc; - pc = 1; - }else{ - pc = (rc/onePacketSize); - (*((uint32_t*)(buffer[ithread]))) = pc; - } -#ifdef VERYDEBUG - cprintf(BLUE,"%d last rc:%d\n",ithread, rc); - cprintf(BLUE,"%d last packetcount:%d\n", ithread, pc); -#endif - - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread])); -#endif - } - - - - - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread])); -#endif - (*((uint32_t*)(buffer[ithread]))) = 0x0; -#ifdef VERYDEBUG - cprintf(BLUE,"%d dummy buffer num packets:%d\n", ithread(*((uint16_t*)(buffer[ithread])))); -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread])); -#endif - } - - - - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1< 1) - cprintf(BLUE,"%d Waiting for listening to be done.. current mask:0x%x\n", ithread, listeningthreads_mask); -#endif - while(listeningthreads_mask) - usleep(5000); -#ifdef VERYDEBUG - t = 0; - for(i=0;i Date: Wed, 14 Oct 2015 09:11:40 +0200 Subject: [PATCH 151/222] again --- .../include/UDPStandardImplementation.h | 2 + .../src/UDPStandardImplementation.cpp | 110 +++++++++++++++--- 2 files changed, 93 insertions(+), 19 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index cbd46d433e..bbe526c40f 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -367,6 +367,8 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ uint32_t processListeningBuffer(int ithread, int cSize,char* temp); + bool popAndCheckEndofAcquisition(char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); + /************************************************************************* * Class Members ********************************************************* *************************************************************************/ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 7fa6310df8..f4d2d968fe 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using namespace std; #define WRITE_HEADERS @@ -1718,8 +1719,15 @@ void UDPStandardImplementation::startWriting(){ threadStarted = 1; //variable definitions - char* wbuf[MAX_NUMBER_OF_LISTENING_THREADS] = NULL; - sfilefd = NULL; + char* wbuf[numberofListeningThreads]; //buffer popped from FIFO + sfilefd = NULL; //file pointer + bool popReady[numberofListeningThreads]; //if the FIFO can be popped + uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO + //eiger specific + int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets + char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame + int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + /* outer loop - loops once for each acquisition */ @@ -1727,6 +1735,15 @@ void UDPStandardImplementation::startWriting(){ while(true){ //--reset parameters before acquisition + for(int i=0; ipop(wbuffer[i]); +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); +#endif + val = (uint32_t)(*((uint32_t*)wbuffer[i])); + if(val < 0) + cprintf(BG_RED,"Error: Negative packet numbers: %d for FIFO %d\n",val,i); + nP[i] = abs(val); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread %d: Number of Packets: %d for FIFO %d\n", ithread, nP[i], i); +#endif + //dummy-end buffer + if(nP[i] == dummyPacketValue){ + ready[i] = false; +#ifdef DEBUG3 + cprintf(GREEN,"Writing_Thread %d: Dummy frame popped out of FIFO %d",ithread, i); +#endif + } + //normal buffer popped out + else{ + endofAcquisition = false; +#ifdef DEBUG4 + switch(myDetectorType){ + case EIGER: + wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BLUE,"Fnum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); + cprintf(BLUE,"Pnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); + break; + default: break; + } +#endif + if(myDetectorType == EIGER){ + toFree[toFreeOffset[i]] = wbuffer[i]; + toFreeOffset[i]++; + } + } + } + } + + return endofAcquisition; +} @@ -1987,23 +2070,21 @@ int UDPStandardImplementation::startWriting(){ int ret,i,j; bool endofacquisition; - int numpackets[numListeningThreads], nf; - bool fullframe[numListeningThreads],popready[numListeningThreads]; + int nf; + bool fullframe[numListeningThreads]; volatile uint32_t tempframenum[numListeningThreads]; uint32_t presentframenum; uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; int numberofmissingpackets[numListeningThreads]; - int MAX_VALUE = 1024;//32 bit number of packets - char* tofree[MAX_VALUE]; + + char* tempbuffer[MAX_VALUE]; char* blankframe[MAX_VALUE]; - int tofreeoffset[numListeningThreads]; int tempoffset[numListeningThreads]; int blankoffset; for(i=0;ipacketnum)); #endif - }else if(numpackets[i] == EIGER_HEADER_LENGTH){ - cprintf(BG_RED, "got header in writer, weirdd packetsize:%d\n",numpackets[i]); - exit(-1); } -#ifdef EIGER_DEBUG3 - else { - cprintf(BG_RED, "got weird in writer, weirdd packetsize:%d\n",numpackets[i]); - } -#endif + if(myDetectorType == EIGER){ tofree[tofreeoffset[i]] = wbuf[i]; tofreeoffset[i]++; From a3e12e795526213c352443734d67d64e7fb14b9b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 15 Oct 2015 12:11:06 +0200 Subject: [PATCH 152/222] somewhere --- .../include/UDPStandardImplementation.h | 37 ++++- .../include/sls_receiver_defs.h | 8 +- .../src/UDPBaseImplementation.cpp | 18 +- .../src/UDPStandardImplementation.cpp | 155 ++++++++---------- 4 files changed, 106 insertions(+), 112 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index bbe526c40f..0c1d4ac432 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -77,8 +77,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Overridden method * Set data compression, by saving only hits (so far implemented only for Moench and Gotthard) * @param b true for data compression enable, else false + * @return OK or FAIL */ - void setDataCompressionEnable(const bool b); + int setDataCompressionEnable(const bool b); //***acquisition parameters*** /** @@ -367,7 +368,33 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ uint32_t processListeningBuffer(int ithread, int cSize,char* temp); - bool popAndCheckEndofAcquisition(char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); + /** + * Called by StartWriting + * Pops buffer from all the FIFOs and checks for dummy frames and end of acquisition + * @param ithread current thread index + * @param wbuffer the buffer array that is popped from all the FIFOs + * @param ready if that FIFO is allowed to pop (depends on if dummy buffer already popped/ waiting for other FIFO to finish a frame(eiger)) + * @param nP number of packets in the buffer popped out + * @param toFree array of addresses to pop into fifoFree (eiger specific) + * @param toFreeOffset the number of addresses to free for each FIFO (eiger specific) + * @return true if end of acquisition else false + */ + bool popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); + + /** + * Called by StartWriting + * When dummy-end buffers are popped from all FIFOs (acquisition over), this is called + * It frees the FIFO addresses, closes all files + * For data compression, it waits for all threads to be done + * Changes the status to RUN_FINISHED and prints statistics + * @param ithread writing thread index + * @param wbuffer writing buffer popped out from FIFO + */ + void stopWriting(int ithread, char* wbuffer[]); + + void processWritingBuffer(int ithread, char* wbuffer[], uint32_t nP[]); + void processWritingBufferPacketByPacket(); + /************************************************************************* * Class Members ********************************************************* @@ -669,11 +696,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum); - /** - * When acquisition is over, this is called - * @param ithread listening thread number - */ - void stopWriting(int ithread, char* wbuffer[]); + /** * updates parameters and writes to file when not a dummy frame diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 04b8b19fbb..fe0c715b17 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -8,8 +8,10 @@ #endif #include +#include #include "ansi.h" + typedef double double32_t; typedef float float32_t; typedef int int32_t; @@ -115,9 +117,9 @@ class slsReceiverDefs { \param b true or false \returns string enabled, disabled */ - static string stringEnable(bool b){\ - if(b) return string("enabled"); \ - else return string("disabled"); \ + static std::string stringEnable(bool b){\ + if(b) return std::string("enabled"); \ + else return std::string("disabled"); \ }; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 75f7fa244e..18e43edb55 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -5,9 +5,9 @@ ***********************************************/ #include "UDPBaseImplementation.h" +#include "genericSocket.h" #include // stat - #include #include using namespace std; @@ -75,10 +75,6 @@ UDPBaseImplementation::~UDPBaseImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "Info: Deleting base member pointers" << endl; - if(detHostname) {delete [] detHostname; detHostname = NULL;} - if(eth) {delete [] eth; eth = NULL;} - if(fileName) {delete [] fileName; fileName = NULL;} - if(filePath) {delete [] filePath; filePath = NULL;} } @@ -129,7 +125,7 @@ char *UDPBaseImplementation::getFilePath() const{ return output; } -uint32_t UDPBaseImplementation::getFileIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex;} +uint64_t UDPBaseImplementation::getFileIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex;} int UDPBaseImplementation::getScanTag() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return scanTag;} @@ -234,7 +230,7 @@ void UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logINFO) << "File path:" << filePath; } -void UDPBaseImplementation::setFileIndex(const uint32_t i){ +void UDPBaseImplementation::setFileIndex(const uint64_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; fileIndex = i; @@ -394,7 +390,7 @@ void UDPBaseImplementation::resetAcquisitionCount(){ FILE_LOG(logINFO) << "totalPacketsCaught:" << totalPacketsCaught << endl; } -int UDPBaseImplementation::startReceiver(char *c=NULL){ +int UDPBaseImplementation::startReceiver(char *c){ FILE_LOG(logWARNING) << __AT__ << " doing nothing..."; FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes"; return OK; @@ -433,17 +429,17 @@ void UDPBaseImplementation::closeFile(int i){ /***callback functions***/ -void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ +void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ startAcquisitionCallBack=func; pStartAcquisition=arg; } -void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ +void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ acquisitionFinishedCallBack=func; pAcquisitionFinished=arg; } -void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ +void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ rawDataReadyCallBack=func; pRawDataReady=arg; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index f4d2d968fe..1d6a1eb234 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -764,7 +764,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ } -int UDPStandardImplementation::startReceiver(char *c=NULL){ +int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Info: Starting Receiver" << endl; @@ -1752,23 +1752,28 @@ void UDPStandardImplementation::startWriting(){ //pop fifo and if end of acquisition - if(popAndCheckEndofAcquisition(wbuf, popReady, numPackets,toFreePointers,toFreePointersOffset)){ + if(popAndCheckEndofAcquisition(ithread, wbuf, popReady, numPackets,toFreePointers,toFreePointersOffset)){ #ifdef DEBUG4 cprintf(GREEN,"Writing_Thread %d: All dummy-end buffers popped\n", ithread); #endif //finish missing packets - if(myDetectorType == EIGER - && ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); + + if(myDetectorType == EIGER && + ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numberofListeningThreads)))); else{ stopWriting(ithread,wbuf); continue; } } - //eiger-processWritingPackets(); - //others-processWritingBuffer(); - - + switch(myDetectorType){ + case EIGER: + processWritingBufferPacketByPacket(); + break; + default: + processWritingBuffer(ithread, wbuf, numPackets); + break; + } }/*--end of loop for each buffer (inner loop)*/ @@ -1835,7 +1840,8 @@ void UDPStandardImplementation::startWriting(){ -bool UDPStandardImplementation::popAndCheckEndofAcquisition(char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]){ +bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; bool endofAcquisition = true; int val; @@ -1866,7 +1872,7 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(char* wbuffer[], boo #ifdef DEBUG4 switch(myDetectorType){ case EIGER: - wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + eiger_packet_footer_t* wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"Fnum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"Pnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); @@ -1887,6 +1893,54 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(char* wbuffer[], boo +void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + cprintf(GREEN,"Info: Writing_Thread %d: End of Acquisition\n",ithread); + + //free fifo + for(int i=0; ipush(wbuffer[i])); +#ifdef +} + +void UDPStandardImplementation::processWritingBuffer(int ithread, char* wbuffer[], uint32_t nP[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + +} + + +void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread, char* wbuffer[], uint32_t nP[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))); + + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + + //get frame number + tempframenumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + + //single thread, just assign and process without compression + if(!dataCompressionEnable){ + currentFrameNumber = tempframenumber; + handleWithoutDataCompression(ithread, wbuffer, nP[0]); + } + + //handling multiple threads + else{ + pthread_mutex_lock(&progressMutex); + if(tempframenumber > currentFrameNumber) + currentFrameNumber = tempframenumber; + pthread_mutex_unlock(&progressMutex); + handleDataCompression(ithread,wbuffer,d, xmax, ymax, nf); + } + + + +} @@ -2173,67 +2227,10 @@ int UDPStandardImplementation::startWriting(){ - //pop - endofacquisition = true; - for(i=0;ipop(wbuf[i]); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer poped 0x%x from fifo %d\n", ithread, (void*)(wbuf[i]), i); -#endif - numpackets[i] = (uint32_t)(*((uint32_t*)wbuf[i])); - -#ifdef VERYDEBUG - cprintf(GREEN,"%d numpackets: %d for fifo :%d\n", ithread, numpackets[i], i); -#endif - if(numpackets < 0){ - cprintf(BG_RED,"negative numpackets[%d]%d\n",i,numpackets[i]); - exit(-1); - } - //dont pop again if dummy packet - else if(numpackets[i] == 0){ - popready[i] = false; -#ifdef EIGER_DEBUG3 - cprintf(GREEN,"%d Dummy frame popped out of fifo %d",ithread, i); -#endif - }else{ - endofacquisition = false; - if(numpackets[i] == onePacketSize){ -#ifdef EIGER_DEBUG3 - wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); - //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); - cprintf(BLUE,"tempframenum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); - cprintf(BLUE,"packetnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetnum)); -#endif - } - - if(myDetectorType == EIGER){ - tofree[tofreeoffset[i]] = wbuf[i]; - tofreeoffset[i]++; - } - } - } - } - //END OF ACQUISITION - if(endofacquisition){ -#ifdef EIGER_DEBUG3 - cprintf(GREEN,"%d Both dummy frames\n", ithread); -#endif - //remaining packets to be written - if((myDetectorType == EIGER) && - ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numListeningThreads)))); - else{ - - stopWriting(ithread,wbuf); - continue; - } - } - - if(myDetectorType == EIGER){ @@ -2539,31 +2536,7 @@ int UDPStandardImplementation::startWriting(){ } - //other detectors other than eiger - else{ - - //frame number for progress - if ((myDetectorType == PROPIX) ||((myDetectorType == GOTTHARD) && (shortFrame == -1))) - tempframenum[0] = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum[0] = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - if(numWriterThreads == 1) - currframenum = tempframenum[0]; - else{ - pthread_mutex_lock(&progress_mutex); - if(tempframenum[0] > currframenum) - currframenum = tempframenum[0]; - pthread_mutex_unlock(&progress_mutex); - } - - - //without datacompression: write datacall back, or write data, free fifo - if(!dataCompression) handleWithoutDataCompression(ithread,wbuf, numpackets[0]); - //data compression - else handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); - - } } From 169a91b6aceb7b952815e08d73d5d63408d8a602 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 16 Oct 2015 10:47:21 +0200 Subject: [PATCH 153/222] some --- .../include/UDPStandardImplementation.h | 80 +- .../src/UDPStandardImplementation.cpp | 681 ++++++++---------- 2 files changed, 337 insertions(+), 424 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 0c1d4ac432..6b08fab2b4 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -317,15 +317,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void startListening(); - /** - * Thread started which writes packets to file. - * It pops the fifo, processes and writes packets to file and pushes the addresses into the fifoFree - * This is continuously looped for each buffer in a nested loop, which is again looped for each acquisition - * Exits only for changing dynamic range, 10G parameters etc and recreated - * - */ - void startWriting(); - /** * Called by startListening * Listens to buffer, until packet(s) received or shutdownUDPsocket called by client @@ -368,6 +359,16 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ uint32_t processListeningBuffer(int ithread, int cSize,char* temp); + /** + * Thread started which writes packets to file. + * It calls popAndCheckEndofAcquisition to pop fifo and check if it is a dummy end buffer + * It then calls a function to process and write packets to file and pushes the addresses into the fifoFree + * This is continuously looped for each buffer in a nested loop, which is again looped for each acquisition + * Exits only for changing dynamic range, 10G parameters etc and recreated + * + */ + void startWriting(); + /** * Called by StartWriting * Pops buffer from all the FIFOs and checks for dummy frames and end of acquisition @@ -392,9 +393,40 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void stopWriting(int ithread, char* wbuffer[]); - void processWritingBuffer(int ithread, char* wbuffer[], uint32_t nP[]); - void processWritingBufferPacketByPacket(); + /** + * Called by startWriting or processWritingBufferPacketByPacket upon reading a frame (for eiger) + * Updates parameters, (writes headers for eiger) and writes to file when not a dummy frame + * Copies data for gui display and frees addresses popped from FIFOs + * @param ithread writing thread index + * @param wbuffer writing buffer popped out from FIFO + * @param npackets number of packets + */ + void handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets); + + /** + * Calle by handleWithoutDataCompression + * Creating headers Writing to file without compression + * @param wbuffer is the address of buffer popped out of FIFO + * @param numpackets is the number of packets + */ + void writeFileWithoutCompression(char* wbuffer[],int numpackets); + /** + * Called by writeToFileWithoutCompression() + * Create headers for file writing (at the moment, this is eiger specific) + * @param wbuffer writing buffer popped from FIFOs + */ + void createHeaders(char* wbuffer[]); + + /** + * Called by handleWithoutDataCompression and handleWithCompression after writing to file + * Copy frames for GUI and updates appropriate parameters for frequency frames to gui + * Uses semaphore for nth frame mode + * @param buffer buffer to copy + */ + void copyFrameToGui(char* buffer[]); + + void processWritingBufferPacketByPacket(); /************************************************************************* * Class Members ********************************************************* @@ -674,11 +706,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase private: - /** - * Copy frames to gui - * uses semaphore for nth frame mode - */ - void copyFrameToGui(char* startbuf[], char* buf=NULL); + /** * Creates new tree and file for compression @@ -688,26 +716,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ int createCompressionFile(int ithr, int iframe); - /** - * Writing to file without compression - * @param buf is the address of buffer popped out of fifo - * @param numpackets is the number of packets - * @param framenum current frame number - */ - void writeToFile_withoutCompression(char* buf[],int numpackets, uint32_t framenum); - - - - /** - * updates parameters and writes to file when not a dummy frame - * Also calls writeToFile_withoutCompression or handleDataCompression - * Called by startWriting() - * @param ithread writing thread number - * @param wbuffer writer buffer - * @param npackets number of packets - */ - void handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets); - /** * data compression for each fifo output * @param ithread writing thread number diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 1d6a1eb234..f01997cf8f 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -775,8 +775,11 @@ int UDPStandardImplementation::startReceiver(char *c){ measurementStarted = false; startFrameIndex = 0; frameIndex = 0; - if(!acqStarted) + if(!acqStarted){ currentFrameNumber = 0; //has to be zero to add to startframeindex for each scan + acquisitionIndex = 0; + frameIndex = 0; + } for(int i = 0; i < numberofListeningThreads; ++i) totalListeningFrameCount[i] = 0; packetsCaught = 0; @@ -983,7 +986,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint64_t &startAcq cprintf(CYAN,"Info: gonna post\n"); #endif //release after getting data - sem_post(&smp); + sem_post(&writerGuiSemaphore); } #ifdef DEBUG4 cprintf(CYAN,"Info: done post\n"); @@ -1771,7 +1774,10 @@ void UDPStandardImplementation::startWriting(){ processWritingBufferPacketByPacket(); break; default: - processWritingBuffer(ithread, wbuf, numPackets); + if(!dataCompressionEnable) + handleWithoutDataCompression(ithread, wbuf, numPackets[0]); + else + handleDataCompression(ithread,wbuf,d, xmax, ymax, nf); break; } @@ -1899,85 +1905,331 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ cprintf(GREEN,"Info: Writing_Thread %d: End of Acquisition\n",ithread); //free fifo - for(int i=0; ipush(wbuffer[i])); -#ifdef -} +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); +#endif + } + + //all threads need to close file, reset mask and exit loop + closeFile(ithread); + pthread_mutex_lock(&statusMutex); + writerThreadsMask^=(1<> frameIndexOffset; + int i; - //single thread, just assign and process without compression - if(!dataCompressionEnable){ - currentFrameNumber = tempframenumber; - handleWithoutDataCompression(ithread, wbuffer, nP[0]); + //get frame number (eiger already gets it when it does packet to packet processing) + if (myDetectorType != EIGER){ + uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS)))); + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + //get frame number + currentFrameNumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + //set indices + acquisitionIndex = currentFrameNumber - startAcquisitionIndex; + frameIndex = currentFrameNumber - startFrameIndex; } - //handling multiple threads - else{ - pthread_mutex_lock(&progressMutex); - if(tempframenumber > currentFrameNumber) - currentFrameNumber = tempframenumber; - pthread_mutex_unlock(&progressMutex); - handleDataCompression(ithread,wbuffer,d, xmax, ymax, nf); + + //callback to write data + if (cbAction < DO_EVERYTHING){ + switch(myDetectorType){ + case EIGER: + for(i=0;i 0) + writeFileWithoutCompression(wbuffer, npackets); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: Writing done\nGoing to copy frame\n"); +#endif + + //copy frame for gui + if(npackets >= packetsPerFrame) + copyFrameToGui(wbuffer); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: Copied frame\n"); +#endif + + //free fifo addresses (eiger frees for each packet later) + if(myDetectorType != EIGER){ + while(!fifoFree[0]->push(wbuffer[0])); +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Freed buffer, pushed into fifofree %p for listener 0\n",ithread, (void*)(wbuffer[0])); +#endif + } } +void UDPStandardImplementation::writeFileWithoutCompression(char* wbuffer[],int numpackets){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + int i; + //create headers for eiger +#ifdef WRITE_HEADERS + if (myDetectorType == EIGER && cbAction == DO_EVERYTHING) + createHeaders(wbuffer); +#endif + //if write enabled + if((fileWriteEnable) && (sfilefd)){ + int offset = HEADER_SIZE_NUM_TOT_PACKETS; //offset (not eiger) to keep track of how many packets saved + int packetsToSave; //how many packets to save at a time + volatile uint64_t tempframenumber; + int lastpacket; + //loop to take care of creating new files when it reaches max packets per file + while(numpackets > 0){ + //to create new file when max reached + packetsToSave = maxPacketsPerFile - packetsInFile; + if(packetsToSave > numpackets) + packetsToSave = numpackets; + //write to file + if(cbAction == DO_EVERYTHING){ + switch(myDetectorType){ + case EIGER: + for(i=0; i= (uint32_t)maxPacketsPerFile){ + //for packet loss, because currframenum is the latest one for eiger + if(myDetectorType != EIGER){ + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); + //get frame number (eiger already gets it when it does packet to packet processing) + tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + lastpacket)))); + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + //get frame number + currentFrameNumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + //set indices + acquisitionIndex = currentFrameNumber - startAcquisitionIndex; + frameIndex = currentFrameNumber - startFrameIndex; + } +#ifdef DEBUG3 + cprintf(GREEN,"Writing_Thread: Current Frame Number:%d\n",currentFrameNumber); +#endif + createNewFile(); + } + //increase offset + if(myDetectorType != EIGER) + offset += (packetsToSave * onePacketSize); + numpackets -= packetsToSave; + } + } + //only update parameters + else{ + if(numberofWriterThreads > 1) pthread_mutex_lock(&writeMutex); + packetsInFile += numpackets; + packetsCaught += (numpackets - numMissingPackets); + totalPacketsCaught += (numpackets - numMissingPackets); + numMissingPackets = 0; + if(numberofWriterThreads > 1) pthread_mutex_unlock(&writeMutex); + } +} +void UDPStandardImplementation::createHeaders(char* wbuffer[]){ + eiger_packet_header_t* wbuf_header=0; + eiger_packet_footer_t* wbuf_footer=0; + int port = 0, missingPacket; + for (int i = 0; i < packetsPerFrame; i++){ + wbuf_header = (eiger_packet_header_t*) wbuffer[i]; + wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset); +#ifdef DEBUG4 + cprintf(GREEN, "Loop index:%d Pnum:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); +#endif + //which port + if (i ==(packetsPerFrame/2)) port = 1; + //missing packet + if (*( (uint16_t*) wbuf_header->missingPacket)== missingPacketValue){ +#ifdef DEBUG4 + cprintf(GREEN,"Missing packet at %d\n", i+1); +#endif + missingPacket = 1; + //add frame and packet numbers + *( (uint64_t*) wbuf_footer) = (uint64_t)((currentFrameNumber+1)); + *( (uint16_t*) wbuf_footer->packetNumber) = (i+1); + } + //normal packet + else{ + missingPacket = 0; + //correct the packet numbers of port2 so that port1 and 2 are not the same + if(port) *( (uint16_t*) wbuf_footer->packetNumber) = (*( (uint16_t*) wbuf_footer->packetNumber))+(packetsPerFrame/2); + } + //DEBUGGING + if(*( (uint16_t*) wbuf_footer->packetNumber) != (i+1)){ + cprintf(BG_RED, "Packet Number Mismatch! i:%d pnum:%d fnum:%d missingPacket:%d\n", + i,*( (uint16_t*) wbuf_footer->packetNumber),currentFrameNumber,*( (uint16_t*) wbuf_header->missingPacket)); + exit(-1); + } + //overwriting port number and dynamic range + *( (uint8_t*) wbuf_header->portIndex) = port; + *( (uint8_t*) wbuf_header->dynamicRange) = dynamicRange; + } +} +void UDPStandardImplementation::copyFrameToGui(char* buffer[]){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + int i; + //random read (gui not ready) + //need to toggle guiDataReady or the second frame wont be copied + if((!FrameToGuiFrequency) && (!guiData)){ +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: CopyingFrame: Resetting guiDataReady\n"); +#endif + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; + pthread_mutex_unlock(&dataReadyMutex); + } + //random read (gui ready) or nth frame read: gui needs data now or it is the first frame + else{ +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: CopyingFrame: Gui needs data now OR 1st frame\n"); +#endif + pthread_mutex_lock(&dataReadyMutex); + guiDataReady=0; +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: CopyingFrame: guidataready is 0, Copying data\n"); +#endif + switch(myDetectorType){ + case EIGER: + for(int i=0; ipush(wbuffer[i])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i); -#endif - } - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&statusMutex); - writerthreads_mask^=(1< 0){ - - //for progress and packet loss calculation(new files) - if(myDetectorType == EIGER); - else if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - //lock - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - - - //to create new file when max reached - packetsToSave = maxPacketsPerFile - packetsInFile; - if(packetsToSave > numpackets) - packetsToSave = numpackets; -/**next time offset is still plus header length*/ - if(myDetectorType == EIGER){ - for(i=0;i= (uint32_t)maxPacketsPerFile){ - - //for packet loss, because currframenum is the latest one for eiger - if(myDetectorType != EIGER){ - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - - if ((myDetectorType == PROPIX)||((myDetectorType == GOTTHARD) && (shortFrame == -1))) - - tempframenum = (((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf[0] + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); - } - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - //create - createNewFile(); - } - - //unlock - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - - if(myDetectorType != EIGER) - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; - } - - } - else{ - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - packetsInFile += numpackets; - packetsCaught += (numpackets - numMissingPackets); - totalPacketsCaught += (numpackets - numMissingPackets); - numMissingPackets = 0; - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - } -} - - - - - - - - -void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets){ - int i, missingpacket,port = 0; - - - if (cbAction < DO_EVERYTHING){ - if (myDetectorType == EIGER){ - for(i=0;i 0){ - -#ifdef WRITE_HEADERS - if (myDetectorType == EIGER){ - - eiger_packet_header_t* wbuf_header=0; - eiger_packet_footer_t* wbuf_footer=0; - - - for (i = 0; i < packetsPerFrame; i++){ - - wbuf_header = (eiger_packet_header_t*) wbuffer[i]; - wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footer_offset); -#ifdef EIGER_DEBUG3 - cprintf(GREEN, "i:%d pnum:%d \n",i,*( (uint16_t*) wbuf_footer->packetnum)); -#endif - //which port - if (i ==(packetsPerFrame/2)) - port = 1; - - - - //missing packet - if (*( (uint16_t*) wbuf_header->missingpacket)== missingPacketValue){ -#ifdef VERY_VERBOSE - cprintf(GREEN,"missing packet at %d\n", i+1); -#endif - missingpacket = 1; - //add frame and packet numbers - *( (uint64_t*) wbuf_footer) = (uint64_t)((currframenum+1)); - *( (uint16_t*) wbuf_footer->packetnum) = (i+1); - }else{ - missingpacket = 0; - - if(*( (uint16_t*) wbuf_footer->packetnum)!= (i-(port*packetsPerFrame/numListeningThreads))+1){ - cprintf(BG_RED, "pnum mismatch num4! i:%d pnum:%d fnum:%d\n", - i,*( (uint16_t*) wbuf_footer->packetnum),currframenum); - exit(-1); - } - - //move packet numbers to num2, and compensate for port1 starting pnum from 0 - if(port) - *( (uint16_t*) wbuf_footer->packetnum) = (*( (uint16_t*) wbuf_footer->packetnum))+(packetsPerFrame/2); - } - - if(*( (uint16_t*) wbuf_footer->packetnum) != (i+1)){ - cprintf(BG_RED, "pnum mismatch! i:%d pnum:%d fnum:%d\n", - i,*( (uint16_t*) wbuf_footer->packetnum),currframenum); - if (*( (uint16_t*) wbuf_header->missingpacket) == missingPacketValue) - cprintf(BG_RED,"missing packet though\n"); - exit(-1); - } - - //overwriting port number and dynamic range - *( (uint8_t*) wbuf_header->portnum) = port; - *( (uint8_t*) wbuf_header->dynamicrange) = dynamicRange; - - - -#ifdef VERYDEBUG - if((i==0)||(i==1)){ - cprintf(GREEN, "%d packet header:0x%016llx missingpacket:0x%x\n",i, - (uint64_t)()*( (uint64_t*) wbuf_header)), *( (uint16_t*) wbuf_header->missingpacket)); - - cprintf(GREEN, "%d - 0x%x - %d\n", i, - *( (uint16_t*) wbuf_header->missingpacket), *( (uint16_t*) wbuf_footer->packetnum)); - } -#endif - - } - } -#endif - - writeToFile_withoutCompression(wbuffer, npackets,currframenum); - } - -#ifdef VERYDEBUG - cprintf(GREEN,"written everyting\n"); -#endif - } - - - if(myDetectorType == EIGER) { - -#ifdef VERYDEBUG - cprintf(GREEN,"gonna copy frame\n"); -#endif - copyFrameToGui(wbuffer); -#ifdef VERYDEBUG - cprintf(GREEN,"copied frame\n"); -#endif - }else{ - //copy to gui - if(npackets >= packetsPerFrame){//min 1 frame, but neednt be - //if(npackets == packetsPerFrame * numJobsPerThread){ //only full frames - copyFrameToGui(NULL,wbuffer[0]+HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; -#endif - } - - //else cout << "unfinished buffersize" << endl; - while(!fifoFree[0]->push(wbuffer[0])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuffer[0])); -#endif - - } -} - - - - - - + uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))); + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + //get frame number + tempframenumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; -void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + pthread_mutex_lock(&progressMutex); + if(tempframenumber > currentFrameNumber) + currentFrameNumber = tempframenumber; + pthread_mutex_unlock(&progressMutex); + //set indices + acquisitionIndex = currentFrameNumber - startAcquisitionIndex; + frameIndex = currentFrameNumber - startFrameIndex; #if defined(MYROOT1) && defined(ALLFILE_DEBUG) writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); From 253383331fe66ff38a1cbde12f5c3602b4e21dab Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 19 Oct 2015 16:06:54 +0200 Subject: [PATCH 154/222] vg --- .../include/UDPStandardImplementation.h | 89 ++- .../src/UDPStandardImplementation.cpp | 516 ++++++++++-------- 2 files changed, 328 insertions(+), 277 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 6b08fab2b4..430b5c5d1c 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -291,11 +291,19 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase int setupWriter(); /** - * Creates new file + * Creates new file and reset some parameters * @return OK or FAIL */ int createNewFile(); + /** + * Creates new tree and file for compression + * @param ithread thread number + * @param iframe frame number + * @return OK or FAIL + */ + int createCompressionFile(int ithread, int iframe); + /** * Static function - Starts Listening Thread of this object * @param this_pointer pointer to this object @@ -370,7 +378,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase void startWriting(); /** - * Called by StartWriting + * Called by processWritingBuffer and processWritingBufferPacketByPacket * Pops buffer from all the FIFOs and checks for dummy frames and end of acquisition * @param ithread current thread index * @param wbuffer the buffer array that is popped from all the FIFOs @@ -383,7 +391,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase bool popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); /** - * Called by StartWriting + * Called by processWritingBuffer and processWritingBufferPacketByPacket * When dummy-end buffers are popped from all FIFOs (acquisition over), this is called * It frees the FIFO addresses, closes all files * For data compression, it waits for all threads to be done @@ -394,7 +402,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase void stopWriting(int ithread, char* wbuffer[]); /** - * Called by startWriting or processWritingBufferPacketByPacket upon reading a frame (for eiger) + * Called by processWritingBuffer and processWritingBufferPacketByPacket * Updates parameters, (writes headers for eiger) and writes to file when not a dummy frame * Copies data for gui display and frees addresses popped from FIFOs * @param ithread writing thread index @@ -412,7 +420,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase void writeFileWithoutCompression(char* wbuffer[],int numpackets); /** - * Called by writeToFileWithoutCompression() + * Called by writeToFileWithoutCompression * Create headers for file writing (at the moment, this is eiger specific) * @param wbuffer writing buffer popped from FIFOs */ @@ -426,7 +434,24 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void copyFrameToGui(char* buffer[]); - void processWritingBufferPacketByPacket(); + void processWritingBuffer(int ithread); + + void processWritingBufferPacketByPacket(int ithread); + + void waitWritingBufferForNextAcquisition(int ithread); + + /** + * Called by processWritingBuffer + * Processing fifo popped buffers for data compression + * Updates parameters and writes to file + * Copies data for gui display and frees addresses popped from FIFOs + * @param ithread writing thread number + * @param wbuffer writer buffer + * @param nf number of frames + */ + void handleDataCompression(int ithread, char* wbuffer[], int &nf); + + /************************************************************************* * Class Members ********************************************************* @@ -683,58 +708,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * 2 we open, close, write file, callback does not do anything */ int cbAction; - - - - - - - - - - - - - - - - - - - - -private: - - - - - /** - * Creates new tree and file for compression - * @param ithr thread number - * @param iframe frame number - *\returns OK for succces or FAIL for failure - */ - int createCompressionFile(int ithr, int iframe); - - /** - * data compression for each fifo output - * @param ithread writing thread number - * @param wbuffer writer buffer - * @param data pointer to the next packet start - * @param xmax max pixels in x direction - * @param ymax max pixels in y direction - * @param nf nf - */ - void handleDataCompression(int ithread, char* wbuffer[], char* data, int xmax, int ymax, int &nf); - - - - - - - //filter - - }; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index f01997cf8f..4b253966b2 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1382,6 +1382,36 @@ int UDPStandardImplementation::createNewFile(){ +int UDPStandardImplementation::createCompressionFile(int ithread, int iframe){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + +#ifdef MYROOT1 + char temp[MAX_STR_LENGTH]; + //create file name for gui purposes, and set up acquistion parameters + sprintf(temp, "%s/%s_fxxx_%d_%d.root", filePath,fileName,fileIndex,ithread); + //file + myFile[ithread] = new TFile(temp,"RECREATE");/** later return error if it exists */ + cprintf(GREEN,"Writing_Thread %d: Created Compression File: %s\n",ithread, temp); + //tree + sprintf(temp, "%s_fxxx_%d_%d",fileName,fileIndex,ithread); + myTree[ithread]=singlePhotonDetectorObject[ithread]->initEventTree(temp, &iframe); + //resets the pedestalSubtraction array and the commonModeSubtraction + singlePhotonDetectorObject[ithread]->newDataSet(); + if(myFile[ithread]==NULL){ + cprintf(BG_RED,"Error: File Null\n"); + return FAIL; + } + if(!myFile[ithread]->IsOpen()){ + cprintf(BG_RED,"Error: File Not Open\n") + return FAIL; + } + return OK; +#endif + return FAIL; +} + + + void* UDPStandardImplementation::startListeningThread(void* this_pointer){ FILE_LOG(logDEBUG1) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startListening(); @@ -1399,6 +1429,8 @@ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ + + void UDPStandardImplementation::startListening(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -1517,6 +1549,10 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in } + + + + void UDPStandardImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -1552,6 +1588,8 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ + + void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -1629,6 +1667,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ + uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSize, char* temp){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -1721,18 +1760,100 @@ void UDPStandardImplementation::startWriting(){ //let calling function know thread started and obtained current threadStarted = 1; + switch(myDetectorType){ + case EIGER: + processWritingBufferPacketByPacket(ithread); + break; + default: + processWritingBuffer(ithread); + break; + } + +} + + + +void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + //variable definitions char* wbuf[numberofListeningThreads]; //buffer popped from FIFO sfilefd = NULL; //file pointer - bool popReady[numberofListeningThreads]; //if the FIFO can be popped - uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO - //eiger specific - int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets - char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame - int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + + /* outer loop - loops once for each acquisition */ + //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) + while(true){ + + //--reset parameters before acquisition + nf = 0; + + /* inner loop - loop for each buffer */ + //until mask unset (udp sockets shut down by client) + while((1 << ithread) & writerThreadsMask){ + //pop + fifo[0]->pop(wbuf[0]); +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuf[0]),0); +#endif + int numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); + if(numPackets < 0) + cprintf(BG_RED,"Error: Negative packet numbers: %d for FIFO %d\n",numPackets,0); +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread %d: Number of Packets: %d for FIFO %d\n", ithread, numPackets, 0); +#endif + + + //dummy packet + if(numPackets == dummyPacketValue){ +#ifdef DEBUG3 + cprintf(GREEN,"Writing_Thread %d: Dummy frame popped out of FIFO %d",ithread, 0); +#endif + stopWriting(ithread,wbuf); + continue; + } + + + + //process + if(!dataCompressionEnable) + handleWithoutDataCompression(ithread, wbuf, numPackets); + else{ +#if defined(MYROOT1) && defined(ALLFILE_DEBUG) + if(npackets > 0) + writeFileWithoutCompression(wbuf, numPackets); +#endif + handleDataCompression(ithread,wbuf,nf); + } + }/*--end of loop for each buffer (inner loop)*/ + + waitWritingBufferForNextAcquisition(ithread); + + }/*--end of loop for each acquisition (outer loop) */ + + +} + + + + + +void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ + FILE_LOG(logDEBUG1) << __AT__ << " called"; + + + //variable definitions + char* wbuf[numberofListeningThreads]; //buffer popped from FIFO + sfilefd = NULL; //file pointer + bool popReady[numberofListeningThreads]; //if the FIFO can be popped + uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO + //eiger specific + int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets + char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame + int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + /* outer loop - loops once for each acquisition */ //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) while(true){ @@ -1745,10 +1866,11 @@ void UDPStandardImplementation::startWriting(){ toFreePointersOffset[i] = (i*packetsPerFrame/numberofListeningThreads); } for(int i=0; i> frameIndexOffset; + //handle multi threads + pthread_mutex_lock(&progressMutex); + if(tempframenumber > currentFrameNumber) + currentFrameNumber = tempframenumber; + pthread_mutex_unlock(&progressMutex); + //set indices + acquisitionIndex = currentFrameNumber - startAcquisitionIndex; + frameIndex = currentFrameNumber - startFrameIndex; -} + //variable definitions + char* buff[2] = 0; //an array just to be compatible with copyframetogui + char* data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; //data pointer to the next memory to be analysed + int ndata; //size of data returned + int np; //remaining number of packets returned + int npackets = (uint32_t)(*((uint32_t*)wbuffer[0])); //number of total packets + int remainingsize = npackets * onePacketSize; //size of the memory slot to be analyzed + + eventType thisEvent = PEDESTAL; + int once = 0; + int xmax = 0, ymax = 0; //max pixels in x and y direction + int xmin = 1, ymin = 1; //min pixels in x and y direction + double tot, tl, tr, bl, br; + + //determining xmax and ymax + switch(myDetectorType){ + case MOENCH: + xmax = MOENCH_PIXELS_IN_ONE_ROW-1; + ymax = MOENCH_PIXELS_IN_ONE_ROW-1; + break; + case GOTTHARD: + if(shortFrameEnable == -1){ + xmax = GOTTHARD_PIXELS_IN_ROW-1; + ymax = GOTTHARD_PIXELS_IN_COL-1; + }else{ + xmax = GOTTHARD_SHORT_PIXELS_IN_ROW-1; + ymax = GOTTHARD_SHORT_PIXELS_IN_COL-1; + } + break; + } + while(buff[0] = receiverData[ithread]->findNextFrame(data,ndata,remainingsize)){ + //remaining number of packets + np = ndata/onePacketSize; + if ((np == packetsPerFrame) && (buff[0]!=NULL)){ + if(nf == 1000) + cprintf(GREEN, "Writing_Thread %d: pedestal done\n", ithread); + singlePhotonDetectorObject[ithread]->newFrame(); + //only for moench + if(commonModeSubtractionEnable){ + for(int ix = xmin - 1; ix < xmax+1; ix++){ + for(int iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent = singlePhotonDetectorObject[ithread]->getEventType(buff[0], ix, iy, 0); + } + } + } + for(int ix = xmin - 1; ix < xmax+1; ix++) + for(int iy = ymin - 1; iy < ymax+1; iy++){ + thisEvent=singlePhotonDetectorObject[ithread]->getEventType(buff[0], ix, iy, commonModeSubtractionEnable); + if (nf>1000) { + tot=0; + tl=0; + tr=0; + bl=0; + br=0; + if (thisEvent==PHOTON_MAX) { + receiverData[ithread]->getFrameNumber(buff[0]); + //iFrame=receiverdata[ithread]->getFrameNumber(buff); +#ifdef MYROOT1 + myTree[ithread]->Fill(); + //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; +#else + pthread_mutex_lock(&writeMutex); + if((fileWriteEnable) && (sfilefd)) + singlePhotonDetectorObject[ithread]->writeCluster(sfilefd); + pthread_mutex_unlock(&writeMutex); +#endif + } + } + } + nf++; +#ifndef ALLFILE + pthread_mutex_lock(&progressMutex); + packetsInFile += packetsPerFrame; + packetsCaught += packetsPerFrame; + totalPacketsCaught += packetsPerFrame; + if(packetsInFile >= (uint32_t)maxPacketsPerFile) + createNewFile(); + pthread_mutex_unlock(&progressMutex); +#endif + if(!once){ + copyFrameToGui(buff); + once = 1; + } + } + remainingsize -= ((buff[0] + ndata) - data); + data = buff[0] + ndata; + if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) + cprintf(BG_RED,"Writing_Thread %d: Error: Compression data goes out of bounds!\n", ithread); + } + while(!fifoFree[0]->push(wbuffer[0])); +#ifdef FIFODEBUG + cprintf(GREEN,"Writing_Thread %d: Compression free pushed into fifofree %p for listerner 0\n", ithread, (void*)(wbuffer[0])); +#endif +} + @@ -2276,32 +2507,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread, -int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; -#ifdef MYROOT1 - char temp[MAX_STR_LENGTH]; - //create file name for gui purposes, and set up acquistion parameters - sprintf(temp, "%s/%s_fxxx_%d_%d.root", filePath,fileName,fileIndex,ithr); - //file - myFile[ithr] = new TFile(temp,"RECREATE");/** later return error if it exists */ - cout << "Thread " << ithr << ": created File: "<< temp << endl; - //tree - sprintf(temp, "%s_fxxx_%d_%d",fileName,fileIndex,ithr); - myTree[ithr]=singlePhotonDet[ithr]->initEventTree(temp, &iframe); - //resets the pedestalSubtraction array and the commonModeSubtraction - singlePhotonDet[ithr]->newDataSet(); - if(myFile[ithr]==NULL){ - cout<<"file null"<IsOpen()){ - cout<<"file not open"<> frameIndexOffset; - - - pthread_mutex_lock(&progressMutex); - if(tempframenumber > currentFrameNumber) - currentFrameNumber = tempframenumber; - pthread_mutex_unlock(&progressMutex); - //set indices - acquisitionIndex = currentFrameNumber - startAcquisitionIndex; - frameIndex = currentFrameNumber - startFrameIndex; - -#if defined(MYROOT1) && defined(ALLFILE_DEBUG) - writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); -#endif - int npackets = (uint32_t)(*((uint32_t*)wbuffer[0])); - eventType thisEvent = PEDESTAL; - int ndata; - char* buff = 0; - data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; - int remainingsize = npackets * onePacketSize; - int np; - int once = 0; - double tot, tl, tr, bl, br; - int xmin = 1, ymin = 1, ix, iy; - - - while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ - np = ndata/onePacketSize; - - //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); - - //only for moench - if(commonModeSubtractionEnable){ - for(ix = xmin - 1; ix < xmax+1; ix++){ - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); - } - } - } - - - for(ix = xmin - 1; ix < xmax+1; ix++) - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); - if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - if (thisEvent==PHOTON_MAX) { - receiverdata[ithread]->getFrameNumber(buff); - //iFrame=receiverdata[ithread]->getFrameNumber(buff); -#ifdef MYROOT1 - myTree[ithread]->Fill(); - //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; -#else - pthread_mutex_lock(&write_mutex); - if((enableFileWrite) && (sfilefd)) - singlePhotonDet[ithread]->writeCluster(sfilefd); - pthread_mutex_unlock(&write_mutex); -#endif - } - } - } - - nf++; -#ifndef ALLFILE - pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; - packetsCaught += packetsPerFrame; - totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= (uint32_t)maxPacketsPerFile) - createNewFile(); - pthread_mutex_unlock(&progress_mutex); - -#endif - if(!once){ - copyFrameToGui(NULL,buff); - once = 1; - } - } - - remainingsize -= ((buff + ndata) - data); - data = buff + ndata; - if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) - cprintf(BG_RED,"ERROR SHOULD NOT COME HERE, Error 142536!\n"); - - } - - while(!fifoFree[0]->push(wbuffer[0])); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0])); -#endif - -} - From 6d6725c4e8d452830e227e40c62939bedb92d88a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 21 Oct 2015 11:03:57 +0200 Subject: [PATCH 155/222] df --- .../src/UDPStandardImplementation.cpp | 462 ++++++++---------- 1 file changed, 197 insertions(+), 265 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 4b253966b2..34ee816cbb 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1773,12 +1773,14 @@ void UDPStandardImplementation::startWriting(){ -void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ +void UDPStandardImplementation::processWritingBuffer(int ithread){ FILE_LOG(logDEBUG1) << __AT__ << " called"; //variable definitions char* wbuf[numberofListeningThreads]; //buffer popped from FIFO sfilefd = NULL; //file pointer + int nf; //for compression, number of frames + /* outer loop - loops once for each acquisition */ //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) @@ -1786,6 +1788,8 @@ void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ //--reset parameters before acquisition nf = 0; + guiData = latestData; //so that the first frame is always copied + /* inner loop - loop for each buffer */ //until mask unset (udp sockets shut down by client) @@ -1803,7 +1807,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ #endif - //dummy packet + //end of acquisition if(numPackets == dummyPacketValue){ #ifdef DEBUG3 cprintf(GREEN,"Writing_Thread %d: Dummy frame popped out of FIFO %d",ithread, 0); @@ -1829,8 +1833,6 @@ void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ waitWritingBufferForNextAcquisition(ithread); }/*--end of loop for each acquisition (outer loop) */ - - } @@ -1843,32 +1845,72 @@ void UDPStandardImplementation::processWritingBuffer(int ithread, int &nf){ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - //variable definitions - char* wbuf[numberofListeningThreads]; //buffer popped from FIFO + char* packetBuffer[numberofListeningThreads]; //buffer popped from FIFO sfilefd = NULL; //file pointer bool popReady[numberofListeningThreads]; //if the FIFO can be popped - uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO - //eiger specific - int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets - char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame - int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + uint32_t numPackets[numberofListeningThreads]; //number of packets popped from the FIFO + + int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets + uint32_t LAST_PACKET_VALUE; //last packet number + char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame + int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + + char* frameBuffer[MAX_NUM_PACKETS]; //buffer offset created for a whole frame + int frameBufferoffset[numberofListeningThreads]; //buffer offset created for a whole frame for both listening threads + char* blankframe[MAX_NUM_PACKETS]; //blank buffer for a whole frame with missing packets + int blankoffset; //blank buffer offset + + bool fullframe[numberofListeningThreads]; //if full frame processed for each listening thread + volatile uint32_t threadFrameNumber[numberofListeningThreads]; //thread frame number for each listening thread buffer popped out + volatile uint32_t presentFrameNumber; //the current frame number aiming to be built + volatile uint32_t lastPacketNumber[numberofListeningThreads]; //last packet number got + volatile uint32_t currentPacketNumber[numberofListeningThreads];//current packet number + volatile int numberofMissingPackets[numberofListeningThreads]; // number of missing packets in this buffer + + eiger_packet_header_t* blankframe_header; + + for(int i=0; imissingPacket) = missingPacketValue; + //set each value inside blank frame to 0xff + for(int j=0;j<(oneDataSize);++j){ + blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; + *(blankframe_data) = 0xFF; + } } - //--end of reset parameters before acquisition + guiData = latestData; //so that the first frame is always copied + LAST_PACKET_VALUE = (packetsPerFrame/numberofListeningThreads); + /* inner loop - loop for each buffer */ @@ -1877,22 +1919,147 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //pop fifo and if end of acquisition - if(popAndCheckEndofAcquisition(ithread, wbuf, popReady, numPackets,toFreePointers,toFreePointersOffset)){ + if(popAndCheckEndofAcquisition(ithread, packetBuffer, popReady, numPackets,toFreePointers,toFreePointersOffset)){ #ifdef DEBUG4 - cprintf(GREEN,"Writing_Thread %d: All dummy-end buffers popped\n", ithread); + cprintf(GREEN,"All dummy-end buffers popped\n", ithread); #endif //finish missing packets - - if(myDetectorType == EIGER && - ((tempoffset[0]!=0) || (tempoffset[1]!=(packetsPerFrame/numberofListeningThreads)))); + if(((frameBufferoffset[0]!=0) || (frameBufferoffset[1]!=(packetsPerFrame/numberofListeningThreads)))); else{ - stopWriting(ithread,wbuf); + stopWriting(ithread,packetBuffer); continue; } } + for(int i=0;ipacketNumber),lastPacketNumber[i],frameBufferoffset[i] ); + cprintf(RED,"Fifo %d: Add missing packets to the right fnum %d\n", + i,presentFrameNumber); +#endif + numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); + } + //correct packet (but never dummy frame)------------------------------------------- + else{ + //update current packet + eiger_packet_footer_t* packetBuffer_footer = (eiger_packet_footer_t*)(packetBuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + currentPacketNumber[i] = *( (uint16_t*) packetBuffer_footer->packetNumber); +#ifdef DEBUG4 + cprintf(GREEN,"Fifo %d: Correct Packet has fnum %d, pnum %d, last_packet %d, pnum_offset\n", + i,threadFrameNumber[i],currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i]); +#endif + numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); + + } + + + //add missing packets + for(int j=0;jmissingPacket)!= missingPacketValue){ + blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + cprintf(BG_RED, "Fifo %d: Missing Packet Error: Adding blank packets mismatch " + "pnum_offset %d, fnum_thread %d, missingpacket_buffer 0x%x, missingpacket_blank 0x%x\n", + i,frameBufferoffset[i],threadFrameNumber[i], + *( (uint16_t*) frameBuffer_header->missingPacket), + *( (uint16_t*) blankframe_header->missingPacket)); + exit(-1); + }else{ +#ifdef DEBUG4 + cprintf(GREEN, "Fifo %d: Missing Packet Adding blank packets success " + "pnum_offset %d, fnum_thread %d, missingpacket_buffer 0x%x\n", + i,frameBufferoffset[i],threadFrameNumber[i], + *( (uint16_t*) frameBuffer_header->missingPacket)); +#endif + frameBufferoffset[i]++; + blankoffset++; + } + if(threadFrameNumber[i] != presentFrameNumber){ + //set fullframe and dont let fifo pop over it + fullframe[i] = true; + popReady[i] = false; + } + } + + //add current packet + if(threadFrameNumber[i] == presentFrameNumber){ + if(currentPacketNumber[i] != (uint32_t)(frameBufferoffset[i]-(i*packetsPerFrame/numberofListeningThreads))+1){ + cprintf(BG_RED, "Fifo %d: Correct Packet Error:Adding current packet mismatch " + "pnum_offset %d,pnum %d fnum %d, (firmware fnum %d)\n", + i,frameBufferoffset[i],currentPacketNumber[i], + threadFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer))); + exit(-1); + } + + frameBuffer[frameBufferoffset[i]] = packetBuffer[i] + HEADER_SIZE_NUM_TOT_PACKETS; + tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; + tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); + } + + + + if(threadFrameNumber[i] != presentFrameNumber) + threadFrameNumber[i] = presentFrameNumber; + + + + + + + + + + } + + } + + + } + + @@ -1904,10 +2071,11 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ waitWritingBufferForNextAcquisition(ithread); }/*--end of loop for each acquisition (outer loop) */ - } + + void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread){ FILE_LOG(logDEBUG1) << __AT__ << " called"; @@ -2428,7 +2596,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer br=0; if (thisEvent==PHOTON_MAX) { receiverData[ithread]->getFrameNumber(buff[0]); - //iFrame=receiverdata[ithread]->getFrameNumber(buff); + //iFrame=receiverData[ithread]->getFrameNumber(buff); #ifdef MYROOT1 myTree[ithread]->Fill(); //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; @@ -2524,97 +2692,23 @@ int UDPStandardImplementation::startWriting(){ - int ret,i,j; - - bool endofacquisition; - int nf; - bool fullframe[numListeningThreads]; - volatile uint32_t tempframenum[numListeningThreads]; - uint32_t presentframenum; - uint32_t lastpacketheader[numListeningThreads], currentpacketheader[numListeningThreads]; - int numberofmissingpackets[numListeningThreads]; - - - - char* tempbuffer[MAX_VALUE]; - char* blankframe[MAX_VALUE]; - int tempoffset[numListeningThreads]; - int blankoffset; - for(i=0;imissingpacket) = missingPacketValue; - - //set each value inside blank frame to 0xff - for(j=0;j<(oneDataSize);++j){ - blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; - *(blankframe_data) = 0xFF; - } - //verify - if (*( (uint16_t*) blankframe_header->missingpacket) != missingPacketValue){ - cprintf(RED,"blank frame not detected at %d: 0x%x\n",i,*( (uint16_t*) blankframe_header->missingpacket) ); - exit(-1); - } -#ifdef FIFO_DEBUG - cprintf(GREEN,"packet %d blank frame 0x%x\n",i,(void*)(blankframe[i])); -#endif - } + while(1){ - //last packet numbers for different dynamic ranges - LAST_PACKET_VALUE = (packetsPerFrame/numListeningThreads); - } - //allow them all to be popped initially - for(i=0;imissingpacket)!= missingPacketValue){ - cprintf(BG_RED, "dummy blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - *( (uint16_t*) blankframe_header->missingpacket)); - exit(-1); - }else -#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x\n",i, - tempoffset[i],tempframenum[i],*( (uint16_t*) tempframe_header->missingpacket)); -#endif - tempoffset[i]++; - blankoffset++; - } - //set fullframe and dont let fifo pop over it until written - fullframe[i] = true; - popready[i] = false; - } - } -#ifdef EIGER_DEBUG3 - else{ - cprintf(RED, "WARNING: Got a weird packet size: %d from fifo %d\n", numpackets[i],i); - continue; - } -#endif - } - - - //not a full frame if(!fullframe[i]){ - wbuf_footer = (eiger_packet_footer_t*)(wbuf[i] + footer_offset + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef EIGER_DEBUG3 - cprintf(GREEN,"**pnum of %d: %d\n",i,(*( (uint16_t*) wbuf_footer->packetnum))); -#endif - //update frame number - if(!((uint32_t)(*( (uint64_t*) wbuf_footer)))){ - cprintf(BG_RED,"%d VERY WEIRD frame number=%d and popready:%d\n", - i,(uint32_t)(*( (uint64_t*) wbuf_footer)),popready[i]); - popready[i]=true; - continue; - } - tempframenum[i] =(uint32_t)(*( (uint64_t*) wbuf_footer)); - tempframenum[i] += (startFrameIndex-1); - //WRONG FRAME - leave - if(tempframenum[i] != presentframenum){ -#ifdef PADDING - cout<<"wrong packet"<packetnum)); -#endif - tempframenum[i] = presentframenum; - //add missing packets - numberofmissingpackets[i] = (LAST_PACKET_VALUE - lastpacketheader[i]); -#ifdef VERYDEBUG - if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now\n",i,lastpacketheader[i]); -#endif - //to decrement from packetsInFile to calculate packet loss - for(j=0;jmissingpacket)!= missingPacketValue){ - cprintf(BG_RED, "wrong blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%p\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - *( (uint16_t*) blankframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); - exit(-1); - }else -#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); -#endif - tempoffset[i] ++; - blankoffset ++; - } - //set fullframe and dont let fifo pop over it until written - fullframe[i] = true; - popready[i] = false; - } + //CORRECT FRAME - continue building frame + { + - //CORRECT FRAME - continue building frame - else { -#ifdef PADDING - cout<<"correct packet"<packetnum); -#ifdef VERYVERBOSE - cprintf(GREEN,"**fifo:%d currentpacketheader: %d lastpacketheader %d tempoffset:%d\n", - i,currentpacketheader[i],lastpacketheader[i], tempoffset[i]); -#endif - //add missing packets - numberofmissingpackets[i] = (currentpacketheader[i] - lastpacketheader[i] -1); -#ifdef VERYDEBUG - if(numberofmissingpackets[i]>0) - cprintf(BG_RED,"fifo:%d missing packet from: %d now at :%d tempoffset:%d\n", - i,lastpacketheader[i],currentpacketheader[i],tempoffset[i]); -#endif - //to decrement from packetsInFile to calculate packet loss - for(j=0;jmissingpacket)!= missingPacketValue){ - cprintf(BG_RED, "correct blank mismatch num4 earlier2! " - "i:%d pnum:%d fnum:%d missingpacket:0x%x actual missingpacket:0x%x add:0x%p\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - *( (uint16_t*) blankframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); - exit(-1); - }else -#ifdef PADDING - cprintf(GREEN, "blank packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); -#endif - tempoffset[i] ++; - blankoffset ++; - } - //add current packet - if(currentpacketheader[i] != (uint32_t)(tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ - cprintf(BG_RED, "correct pnum mismatch earlier! tempoffset[%d]:%d pnum:%d fnum:%d rfnum:%d\n", - i,tempoffset[i],currentpacketheader[i], - tempframenum[i],(uint32_t)(*( (uint64_t*) wbuf_footer))); - exit(-1); - } tempbuffer[tempoffset[i]] = wbuf[i] + HEADER_SIZE_NUM_TOT_PACKETS; tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; From 837d0dce03f184d5a8040fb92a0e9a415362f18e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 27 Oct 2015 09:31:08 +0100 Subject: [PATCH 156/222] dsg --- .../src/UDPStandardImplementation.cpp | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 34ee816cbb..a6833e57d2 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1935,7 +1935,9 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ for(int i=0;ipacketNumber); +#ifdef DEBUG4 + cprintf(GREEN,"Fifo %d: Packet has fnum %d, pnum %d, last_packet %d, pnum_offset\n", + i,threadFrameNumber[i],currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i]); +#endif } @@ -1970,8 +1980,9 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ threadFrameNumber[i] = dummyPacketValue; } - //wrong packet (dummy (not full) or from next frame))-------------------------------- - else if (threadFrameNumber[i] != presentFrameNumber){ + /**check if next frame lastpacket number is actually +1*/ + //wrong packet & correct (dummy (not full) or from future packet))-------------------------------- + else{// if ((threadFrameNumber[i] != presentFrameNumber) ||(currentPacketNumber[i] != lastPacketNumber[i] + 1)){ #ifdef DEBUG4 cprintf(GREEN,"Fifo %d: Wrong Packet has fnum %d, (firmware fnum %d), pnum %d, last_packet %d, pnum_offset %d\n", i,presentFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer)), @@ -1979,20 +1990,12 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ cprintf(RED,"Fifo %d: Add missing packets to the right fnum %d\n", i,presentFrameNumber); #endif - numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); + if(threadFrameNumber[i] != presentFrameNumber) + numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); + else + numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); } - //correct packet (but never dummy frame)------------------------------------------- - else{ - //update current packet - eiger_packet_footer_t* packetBuffer_footer = (eiger_packet_footer_t*)(packetBuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); - currentPacketNumber[i] = *( (uint16_t*) packetBuffer_footer->packetNumber); -#ifdef DEBUG4 - cprintf(GREEN,"Fifo %d: Correct Packet has fnum %d, pnum %d, last_packet %d, pnum_offset\n", - i,threadFrameNumber[i],currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i]); -#endif - numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); - } //add missing packets @@ -2017,13 +2020,13 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ frameBufferoffset[i]++; blankoffset++; } - if(threadFrameNumber[i] != presentFrameNumber){ - //set fullframe and dont let fifo pop over it - fullframe[i] = true; - popReady[i] = false; - } - } + } + if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)){ + //set fullframe and dont let fifo pop over it + fullframe[i] = true; + popReady[i] = false; + } //add current packet if(threadFrameNumber[i] == presentFrameNumber){ if(currentPacketNumber[i] != (uint32_t)(frameBufferoffset[i]-(i*packetsPerFrame/numberofListeningThreads))+1){ @@ -2054,6 +2057,8 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } + numMissingPackets += numberofMissingPackets[i]; + } From 5f3de2057cd718caa3b26d0b0fe787b750f760c2 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 27 Oct 2015 14:33:26 +0100 Subject: [PATCH 157/222] df --- slsReceiverSoftware/include/slsReceiver.h | 6 +- .../include/slsReceiverUsers.h | 6 +- .../src/UDPStandardImplementation.cpp | 443 ++++++------------ slsReceiverSoftware/src/slsReceiver.cpp | 6 +- .../src/slsReceiverTCPIPInterface.cpp | 14 +- slsReceiverSoftware/src/slsReceiverUsers.cpp | 6 +- 6 files changed, 154 insertions(+), 327 deletions(-) diff --git a/slsReceiverSoftware/include/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h index e76ea7d1bf..94548caed6 100644 --- a/slsReceiverSoftware/include/slsReceiver.h +++ b/slsReceiverSoftware/include/slsReceiver.h @@ -62,14 +62,14 @@ class slsReceiver : private virtual slsReceiverDefs { @param func callback to be called when starting the acquisition. Its arguments are filepath filename fileindex data size \returns 0 callback takes care of open,close,write file; 1 callback writes file, we have to open, close it; 2 we open, close, write file, callback does not do anything */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg); /** callback argument is toatal farmes caught */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); /** args to raw data ready callback are @@ -79,7 +79,7 @@ class slsReceiver : private virtual slsReceiverDefs { file descriptor guidatapointer (NULL, no data required) */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg); private: diff --git a/slsReceiverSoftware/include/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h index 50d6f38feb..0d242d3727 100644 --- a/slsReceiverSoftware/include/slsReceiverUsers.h +++ b/slsReceiverSoftware/include/slsReceiverUsers.h @@ -61,7 +61,7 @@ class slsReceiverUsers { */ - void registerCallBackStartAcquisition(int (*func)(char* filepath, char* filename,int fileindex, int datasize, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char* filepath, char* filename,uint64_t fileindex, uint32_t datasize, void*),void *arg); /** @@ -71,7 +71,7 @@ class slsReceiverUsers { */ - void registerCallBackAcquisitionFinished(void (*func)(int nf, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(uint64_t nf, void*),void *arg); @@ -81,7 +81,7 @@ class slsReceiverUsers { \returns nothing */ - void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(uint64_t framenumber, char* datapointer, uint32_t datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); // made static to close thread files with ctrl+c static slsReceiver* receiver; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index a6833e57d2..b15a48cc4c 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1921,7 +1921,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //pop fifo and if end of acquisition if(popAndCheckEndofAcquisition(ithread, packetBuffer, popReady, numPackets,toFreePointers,toFreePointersOffset)){ #ifdef DEBUG4 - cprintf(GREEN,"All dummy-end buffers popped\n", ithread); + cprintf(GREEN,"Writing_Thread All dummy-end buffers popped\n", ithread); #endif //finish missing packets if(((frameBufferoffset[0]!=0) || (frameBufferoffset[1]!=(packetsPerFrame/numberofListeningThreads)))); @@ -1932,22 +1932,25 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } - + //get a full frame------------------------------------------------------------------------------------------------------- for(int i=0;ipacketNumber); -#ifdef DEBUG4 - cprintf(GREEN,"Fifo %d: Packet has fnum %d, pnum %d, last_packet %d, pnum_offset\n", - i,threadFrameNumber[i],currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i]); -#endif } - - - //dummy not done ----------------------------- - if(numPackets[i] == dummyPacketValue){ -#ifdef DEBUG4 - cprintf(RED, "Fifo %d: Dummy packet: Adding missing packets to the last frame\n", i); -#endif - numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); - threadFrameNumber[i] = dummyPacketValue; - } - - /**check if next frame lastpacket number is actually +1*/ - //wrong packet & correct (dummy (not full) or from future packet))-------------------------------- - else{// if ((threadFrameNumber[i] != presentFrameNumber) ||(currentPacketNumber[i] != lastPacketNumber[i] + 1)){ + //calculate number of missing packets----------------------------------------------------- + numberofMissingPackets[i] = 0; #ifdef DEBUG4 - cprintf(GREEN,"Fifo %d: Wrong Packet has fnum %d, (firmware fnum %d), pnum %d, last_packet %d, pnum_offset %d\n", + if(numPackets[i] == dummyPacketValue) + cprintf(GREEN, "Fifo %d: Dummy packet: Adding missing packets to the last frame\n", i); + else{ + cprintf(GREEN,"Fifo %d: fnum %d, (FW_fnum %d), pnum %d, last_pnum %d, pnum_offset %d\n" + "Fifo %d: Add missing packets to the right fnum %d\n", i,presentFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer)), - *( (uint16_t*) packetBuffer_footer->packetNumber),lastPacketNumber[i],frameBufferoffset[i] ); - cprintf(RED,"Fifo %d: Add missing packets to the right fnum %d\n", + *( (uint16_t*) packetBuffer_footer->packetNumber),lastPacketNumber[i],frameBufferoffset[i], i,presentFrameNumber); -#endif - if(threadFrameNumber[i] != presentFrameNumber) - numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); - else - numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); } +#endif + if((numPackets[i] == dummyPacketValue) || (threadFrameNumber[i] != presentFrameNumber)) + numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); + else + numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); - //add missing packets + //add missing packets--------------------------------------------------------------------- for(int j=0;jmissingPacket)!= missingPacketValue){ blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; cprintf(BG_RED, "Fifo %d: Missing Packet Error: Adding blank packets mismatch " - "pnum_offset %d, fnum_thread %d, missingpacket_buffer 0x%x, missingpacket_blank 0x%x\n", - i,frameBufferoffset[i],threadFrameNumber[i], + "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x, missingpacket_blank 0x%x\n", + i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], *( (uint16_t*) frameBuffer_header->missingPacket), *( (uint16_t*) blankframe_header->missingPacket)); exit(-1); }else{ #ifdef DEBUG4 - cprintf(GREEN, "Fifo %d: Missing Packet Adding blank packets success " - "pnum_offset %d, fnum_thread %d, missingpacket_buffer 0x%x\n", - i,frameBufferoffset[i],threadFrameNumber[i], + cprintf(RED, "Fifo %d: Missing Packet: Adding blank packets success " + "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x\n", + i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], *( (uint16_t*) frameBuffer_header->missingPacket)); #endif frameBufferoffset[i]++; blankoffset++; } - } - if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)){ - //set fullframe and dont let fifo pop over it - fullframe[i] = true; + + //missed packets/future packet: do not pop over and determine fullframe-------------------- + if(numberofMissingPackets[i]){ popReady[i] = false; + if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)) + fullframe[i] = true; + else{ + fullframe[i] = false; + //update last packet + lastPacketNumber[i] = currentPacketNumber[i] - 1; + } + if(threadFrameNumber[i] != presentFrameNumber) + threadFrameNumber[i] = presentFrameNumber; + numMissingPackets += numberofMissingPackets[i]; } - //add current packet - if(threadFrameNumber[i] == presentFrameNumber){ + + //no missed packet: add current packet-------------------------------------------------------------- + else{ if(currentPacketNumber[i] != (uint32_t)(frameBufferoffset[i]-(i*packetsPerFrame/numberofListeningThreads))+1){ - cprintf(BG_RED, "Fifo %d: Correct Packet Error:Adding current packet mismatch " - "pnum_offset %d,pnum %d fnum %d, (firmware fnum %d)\n", + cprintf(BG_RED, "Fifo %d: Correct Packet Offset Error:Adding current packet mismatch " + "pnum_offset %d,pnum %d fnum_thread %d, (FW_fnum %d)\n", i,frameBufferoffset[i],currentPacketNumber[i], threadFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer))); exit(-1); } frameBuffer[frameBufferoffset[i]] = packetBuffer[i] + HEADER_SIZE_NUM_TOT_PACKETS; - tempframe_header = (eiger_packet_header_t*) tempbuffer[tempoffset[i]]; - tempframe_footer = (eiger_packet_footer_t*) (tempbuffer[tempoffset[i]] + footer_offset); +#ifdef DEBUG4 + eiger_packet_header_t* frameBuffer_header = (eiger_packet_header_t*) frameBuffer[frameBufferoffset[i]]; + eiger_packet_footer_t* frameBuffer_footer = (eiger_packet_footer_t*) (frameBuffer[frameBufferoffset[i]] + footer_offset); + cprintf(GREEN, "Fifo %d: Current Packet added success:" + "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x\n", + i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], + *( (uint16_t*) frameBuffer_header->missingPacket)); +#endif + frameBufferoffset[i]++; + //update last packet + lastPacketNumber[i] = currentPacketNumber[i]; + popReady[i] = true; + fullframe[i] = false; + if(currentPacketNumber[i] == LAST_PACKET_VALUE){ +#ifdef DEBUG4 + cprintf(GREEN, "Fifo %d: Got last packet\n",i); +#endif + popReady[i] = false; + fullframe[i] = true; + } } + } + } + //full frame + if(fullframe[0] && fullframe[1]){ + currentPacketNumber = presentFrameNumber; + numTotMissingPacketsInFile += numMissingPackets; + numTotMissingPackets += numMissingPackets; +#ifdef FNUM_DEBUG + cprintf(GREEN,"**fnum:%d**\n",currframenum); +#endif +#ifdef MISSINGP_DEBUG + if(numberofMissingPackets[0]) + cprintf(RED, "Fifo 0 missing packets %d for fnum %d\n",numberofMissingPackets[0],currentPacketNumber); + if(numberofMissingPackets[1]) + cprintf(RED, "Fifo 1 missing packets%d for fnum %d\n",numberofMissingPackets[1],currentPacketNumber); + if(numMissingPackets){ + cprintf(RED, "Total missing packets %d for fnum %d\n",numMissingPackets,currentPacketNumber); + for (int j=0;jmissingPacket)==missingPacketValue) + cprintf(RED,"Found missing packet at pnum %d\n",j); + } + } +#endif - if(threadFrameNumber[i] != presentFrameNumber) - threadFrameNumber[i] = presentFrameNumber; - - - - - - - - + //write and copy to gui + handleWithoutDataCompression(ithread,frameBuffer,packetsPerFrame); + //freeing + for(int j=0;jpush(toFreePointers[j])); +#ifdef FIFODEBUG + cprintf(GREEN,"Fifo 0: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); +#endif + } + for(int j=(packetsPerFrame/numberofListeningThreads);jpush(toFreePointers[j])); +#ifdef FIFODEBUG + cprintf(GREEN,"Fifo 1: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); +#endif + } +#ifdef DEBUG4 + cprintf(GREEN,"Writing_Thread: finished freeing\n"); +#endif + + + //reset a few stuff + presentFrameNumber++; + for(int i=0; ipacketNumber), (void*)(packetBuffer[i])); + } +#endif @@ -2646,244 +2712,3 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int UDPStandardImplementation::startWriting(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; - - - - - - - eiger_packet_footer_t* wbuf_footer=0; - eiger_packet_header_t* tempframe_header=0; - eiger_packet_footer_t* tempframe_footer=0; - - - - - while(1){ - - - - - - - while((1<packetnum),tempoffset[i]); -#endif - if(*( (uint16_t*) tempframe_footer->packetnum)!= (tempoffset[i]-(i*packetsPerFrame/numListeningThreads))+1){ - cprintf(BG_RED, "pnum mismatch num4 earlier! i:%d pnum:%d pnum orig:%d fnum:%d add:0x%p\n", - i,*( (uint16_t*) tempframe_footer->packetnum),*( (uint16_t*) wbuf_footer->packetnum), - tempframenum[i],(void*)(tempbuffer[tempoffset[i]])); - exit(-1); - } -#ifdef PADDING - cprintf(GREEN, "normal packet i:%d pnum:%d fnum:%d missingpacket:0x%x add:0x%x\n", - i,tempoffset[i],tempframenum[i], - *( (uint16_t*) tempframe_header->missingpacket), - (void*)(tempbuffer[tempoffset[i]])); -#endif - tempoffset[i] ++; - //update last packet - lastpacketheader[i] = currentpacketheader[i]; - popready[i] = true; - //last frame got, this will save time and also for last frames, it doesnt wait for stop receiver - if(currentpacketheader[i] == LAST_PACKET_VALUE){ -#ifdef EIGER_DEBUG3 - cprintf(GREEN, "Got last packet\n"); -#endif - fullframe[i] = true; - popready[i] = false; - } - } - } - } - } - - - - //FULL FRAME - if(fullframe[0] && fullframe[1]){ - - //determine frame number - if(tempframenum[0] != tempframenum[1]) - cprintf(RED,"Frame numbers mismatch!!! %d %d\n",tempframenum[0],tempframenum[1]); - currframenum = tempframenum[0]; - numMissingPackets += (numberofmissingpackets[0]+numberofmissingpackets[1]); - numTotMissingPacketsInFile += numMissingPackets; - numTotMissingPackets += numMissingPackets; -#ifdef EIGER_DEBUG2 - cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif -#ifdef EIGER_DEBUG3 - if(numberofmissingpackets[0]) - cprintf(RED, "fifo 0 missing packets:%d fnum:%d\n",numberofmissingpackets[0],currframenum); - if(numberofmissingpackets[1]) - cprintf(RED, "fifo 1 missing packets:%d fnum:%d\n",numberofmissingpackets[1],currframenum); - if(numMissingPackets){ - cprintf(RED, "numMissingPackets:%d fnum:%d\n",numMissingPackets,currframenum); - - for (j=0;jmissingpacket)==missingPacketValue) - cprintf(RED,"found the missing packet at pnum:%d\n",j); - } - } -#endif - - - //write and copy to gui - handleWithoutDataCompression(ithread,tempbuffer,packetsPerFrame); - - - //freeing - for(j=0;jpush(tofree[j])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),0); -#endif - } - for(j=(packetsPerFrame/numListeningThreads);jpush(tofree[j])); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(tofree[j]),1); -#endif - } -#ifdef VERYDEBUG - cprintf(GREEN,"finished freeing\n"); -#endif - - - //reset a few stuff - presentframenum = tempframenum[0]+1; - for(int i=0;ipacketnum)); - } -#endif - } - - - - - } - - } - - - return OK; -} - - - - - - - - - - - - - - diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 5783e601c7..15149dde03 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -166,20 +166,20 @@ int64_t slsReceiver::getReceiverVersion(){ } -void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ +void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackStartAcquisition(func,arg); } -void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ +void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackAcquisitionFinished(func,arg); } -void slsReceiver::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ +void slsReceiver::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackRawDataReady(func,arg); } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index cfab3e75dc..5b4664e555 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -9,6 +9,7 @@ #include "slsReceiverUsers.h" #include "slsReceiver.h" + #include //SIGINT #include //EXIT @@ -401,6 +402,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){ } } } + } //#ifdef VERBOSE if(ret!=FAIL) cout << "detector type" << dr << endl; @@ -432,7 +434,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){ int slsReceiverTCPIPInterface::set_file_name() { ret=OK; - char* retval[MAX_STR_LENGTH] = NULL; + char* retval = NULL; char defaultVal[MAX_STR_LENGTH] = ""; char fName[MAX_STR_LENGTH]; strcpy(mess,"Could not set file name"); @@ -457,7 +459,7 @@ int slsReceiverTCPIPInterface::set_file_name() { } else{ receiverBase->setFileName(fName); - retval = receiveBase->getFileName(); + retval = receiverBase->getFileName(); if(retval == NULL) ret = FAIL; } @@ -526,8 +528,8 @@ int slsReceiverTCPIPInterface::set_file_dir() { } else{ receiverBase->setFilePath(fPath); - retval = receiveBase->getFilePath(); - if(reval == NULL){ + retval = receiverBase->getFilePath(); + if(retval == NULL){ ret = FAIL; strcpy(mess,"receiver file path does not exist\n"); } @@ -741,8 +743,8 @@ int slsReceiverTCPIPInterface::setup_udp(){ //set up udp port sscanf(args[1],"%d",&udpport); sscanf(args[2],"%d",&udpport2); - receiverBase->setUDPPortNo(udpport); - receiverBase->setUDPPortNo2(udpport2); + receiverBase->setUDPPortNumber(udpport); + receiverBase->setUDPPortNumber2(udpport2); //setup udpip //get ethernet interface or IP to listen to cout << "Ethernet interface is " << args[0] << endl; diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index c27f1efc2a..1df35558c6 100644 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -29,18 +29,18 @@ int64_t slsReceiverUsers::getReceiverVersion(){ } -void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ +void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackStartAcquisition(func,arg); } -void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ +void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackAcquisitionFinished(func,arg); } -void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ +void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackRawDataReady(func,arg); } From 58bfa296beca9d19933de635caf5e622bd5721c1 Mon Sep 17 00:00:00 2001 From: l_msdetect Date: Wed, 28 Oct 2015 17:40:55 +0100 Subject: [PATCH 158/222] done --- .../include/UDPBaseImplementation.h | 14 +- slsReceiverSoftware/include/UDPInterface.h | 8 +- .../include/UDPStandardImplementation.h | 13 +- slsReceiverSoftware/include/slsReceiver.h | 6 +- .../include/slsReceiverUsers.h | 6 +- .../include/sls_receiver_defs.h | 49 +++++++ .../src/UDPBaseImplementation.cpp | 41 +++--- .../src/UDPStandardImplementation.cpp | 138 +++++++++--------- slsReceiverSoftware/src/slsReceiver.cpp | 6 +- .../src/slsReceiverTCPIPInterface.cpp | 28 ++-- slsReceiverSoftware/src/slsReceiverUsers.cpp | 6 +- 11 files changed, 182 insertions(+), 133 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 43f98b5110..dfb7b04295 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -33,6 +33,10 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ virtual ~UDPBaseImplementation(); + /* + * Initialize class members + */ + void initializeMembers(); /************************************************************************* * Getters *************************************************************** @@ -180,7 +184,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * Get Listening Status of Receiver * @return can be idle, listening or error depending on if the receiver is listening or not */ - slsReceiverDefs::runStatus getStatus() const; + runStatus getStatus() const; @@ -334,7 +338,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * @param d detector type * @return OK or FAIL */ - int setDetectorType(const slsReceiverDefs::detectorType d); + int setDetectorType(const detectorType d); /** * Sets detector hostname (and corresponding detector variables in derived REST class) @@ -413,14 +417,14 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * 1 callback writes file, we have to open, close it * 2 we open, close, write file, callback does not do anything */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); /** * Call back for acquisition finished * callback argument is * total frames caught */ - void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); /** * Call back for raw data @@ -431,7 +435,7 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter * file descriptor * guidatapointer (NULL, no data required) */ - void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg); diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index b62ad2eb0c..1a63776534 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -407,7 +407,7 @@ class UDPInterface { /** * Reset acquisition parameters such as total frames caught for an entire acquisition (including all scans) */ - void resetAcquisitionCount(); + virtual void resetAcquisitionCount() = 0; /** * Start Listening for Packets by activating all configuration settings to receiver @@ -471,14 +471,14 @@ class UDPInterface { * 1 callback writes file, we have to open, close it * 2 we open, close, write file, callback does not do anything */ - virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg) = 0; + virtual void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg) = 0; /** * Call back for acquisition finished * callback argument is * total frames caught */ - virtual void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg) = 0; + virtual void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg) = 0; /** * Call back for raw data @@ -489,7 +489,7 @@ class UDPInterface { * file descriptor * guidatapointer (NULL, no data required) */ - virtual void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg) = 0; + virtual void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg) = 0; protected: diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 430b5c5d1c..d478f0e7aa 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -136,7 +136,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param d detector type * @return OK or FAIL */ - int setDetectorType(const slsReceiverDefs::detectorType d); + int setDetectorType(const detectorType d); //***acquisition functions*** /** @@ -214,11 +214,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase //**initial parameters*** - /** - * Delete and free base member parameters - */ - void deleteBaseMembers(); - /** * Delete and free member parameters */ @@ -409,7 +404,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param wbuffer writing buffer popped out from FIFO * @param npackets number of packets */ - void handleWithoutDataCompression(int ithread, char* wbuffer[],int npackets); + void handleWithoutDataCompression(int ithread, char* wbuffer[],uint32_t npackets); /** * Calle by handleWithoutDataCompression @@ -417,7 +412,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param wbuffer is the address of buffer popped out of FIFO * @param numpackets is the number of packets */ - void writeFileWithoutCompression(char* wbuffer[],int numpackets); + void writeFileWithoutCompression(char* wbuffer[],uint32_t numpackets); /** * Called by writeToFileWithoutCompression @@ -449,7 +444,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param wbuffer writer buffer * @param nf number of frames */ - void handleDataCompression(int ithread, char* wbuffer[], int &nf); + void handleDataCompression(int ithread, char* wbuffer[], uint64_t &nf); diff --git a/slsReceiverSoftware/include/slsReceiver.h b/slsReceiverSoftware/include/slsReceiver.h index 94548caed6..e76ea7d1bf 100644 --- a/slsReceiverSoftware/include/slsReceiver.h +++ b/slsReceiverSoftware/include/slsReceiver.h @@ -62,14 +62,14 @@ class slsReceiver : private virtual slsReceiverDefs { @param func callback to be called when starting the acquisition. Its arguments are filepath filename fileindex data size \returns 0 callback takes care of open,close,write file; 1 callback writes file, we have to open, close it; 2 we open, close, write file, callback does not do anything */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); /** callback argument is toatal farmes caught */ - void registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); /** args to raw data ready callback are @@ -79,7 +79,7 @@ class slsReceiver : private virtual slsReceiverDefs { file descriptor guidatapointer (NULL, no data required) */ - void registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg); private: diff --git a/slsReceiverSoftware/include/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h index 0d242d3727..50d6f38feb 100644 --- a/slsReceiverSoftware/include/slsReceiverUsers.h +++ b/slsReceiverSoftware/include/slsReceiverUsers.h @@ -61,7 +61,7 @@ class slsReceiverUsers { */ - void registerCallBackStartAcquisition(int (*func)(char* filepath, char* filename,uint64_t fileindex, uint32_t datasize, void*),void *arg); + void registerCallBackStartAcquisition(int (*func)(char* filepath, char* filename,int fileindex, int datasize, void*),void *arg); /** @@ -71,7 +71,7 @@ class slsReceiverUsers { */ - void registerCallBackAcquisitionFinished(void (*func)(uint64_t nf, void*),void *arg); + void registerCallBackAcquisitionFinished(void (*func)(int nf, void*),void *arg); @@ -81,7 +81,7 @@ class slsReceiverUsers { \returns nothing */ - void registerCallBackRawDataReady(void (*func)(uint64_t framenumber, char* datapointer, uint32_t datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); + void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); // made static to close thread files with ctrl+c static slsReceiver* receiver; diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index fe0c715b17..04f647f0a4 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -122,6 +122,55 @@ class slsReceiverDefs { else return std::string("disabled"); \ }; + /** returns detector type string from detector type index + \param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown + \returns MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, MÖNCH, GENERIC + */ + static std::string getDetectorType(detectorType t){ \ + switch (t) { \ + case MYTHEN: return std::string("Mythen"); \ + case PILATUS: return std::string("Pilatus"); \ + case EIGER: return std::string("Eiger"); \ + case GOTTHARD: return std::string("Gotthard"); \ + case AGIPD: return std::string("Agipd"); \ + case MOENCH: return std::string("Moench"); \ + case JUNGFRAU: return std::string("Jungfrau"); \ + case JUNGFRAUCTB: return std::string("JungfrauCTB"); \ + case PROPIX: return std::string("Propix"); \ + default: return std::string("Unknown"); \ + }}; + + /** returns detector type index from detector type string + \param type can be MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC + \returns Mythen, Pilatus, Eiger, Gotthard, Agipd, Mönch, Unknown + */ + static detectorType getDetectorType(std::string const type){\ + if (type=="Mythen") return MYTHEN; \ + if (type=="Pilatus") return PILATUS; \ + if (type=="Eiger") return EIGER; \ + if (type=="Gotthard") return GOTTHARD; \ + if (type=="Agipd") return AGIPD; \ + if (type=="Moench") return MOENCH; \ + if (type=="Jungfrau") return JUNGFRAU; \ + if (type=="JungfrauCTB") return JUNGFRAUCTB; \ + if (type=="Propix") return PROPIX; \ + return GENERIC; \ + }; + + + /** returns string from run status index + \param s can be ERROR, WAITING, RUNNING, TRANSMITTING, RUN_FINISHED + \returns string error, waiting, running, data, finished + */ + static std::string runStatusType(runStatus s){\ + switch (s) { \ + case ERROR: return std::string("error"); \ + case WAITING: return std::string("waiting"); \ + case RUNNING: return std::string("running"); \ + case TRANSMITTING: return std::string("data"); \ + case RUN_FINISHED: return std::string("finished"); \ + default: return std::string("idle"); \ + }}; #ifdef __cplusplus diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 18e43edb55..0bfef5d71e 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -21,6 +21,20 @@ using namespace std; UDPBaseImplementation::UDPBaseImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; + initializeMembers(); + + //***callback parameters*** + startAcquisitionCallBack = NULL; + pStartAcquisition = NULL; + acquisitionFinishedCallBack = NULL; + pAcquisitionFinished = NULL; + rawDataReadyCallBack = NULL; + pRawDataReady = NULL; +} + +void UDPBaseImplementation::initializeMembers(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + cout << "Info: Initializing base members" << endl; //**detector parameters*** myDetectorType = GENERIC; @@ -61,21 +75,9 @@ UDPBaseImplementation::UDPBaseImplementation(){ //***acquisition parameters*** shortFrameEnable = -1; FrameToGuiFrequency = 0; - - //***callback parameters*** - startAcquisitionCallBack = NULL; - pStartAcquisition = NULL; - acquisitionFinishedCallBack = NULL; - pAcquisitionFinished = NULL; - rawDataReadyCallBack = NULL; - pRawDataReady = NULL; } -UDPBaseImplementation::~UDPBaseImplementation(){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; - - cout << "Info: Deleting base member pointers" << endl; -} +UDPBaseImplementation::~UDPBaseImplementation(){} /************************************************************************* @@ -364,12 +366,12 @@ int UDPBaseImplementation::setTenGigaEnable(const bool b){ /***initial functions***/ -int UDPBaseImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ +int UDPBaseImplementation::setDetectorType(const detectorType d){ FILE_LOG(logDEBUG) << __AT__ << " starting"; myDetectorType = d; //if eiger, set numberofListeningThreads = 2; - FILE_LOG(logINFO) << "Detector Type:" << slsDetectorBase::getDetectorType(d); + FILE_LOG(logINFO) << "Detector Type:" << getDetectorType(d); return OK; } @@ -409,6 +411,9 @@ void UDPBaseImplementation::startReadout(){ int 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(char* c,char** raw, uint64_t &startAcquisitionIndex, uint64_t &startFrameIndex){ @@ -429,17 +434,17 @@ void UDPBaseImplementation::closeFile(int i){ /***callback functions***/ -void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ +void UDPBaseImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ startAcquisitionCallBack=func; pStartAcquisition=arg; } -void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ +void UDPBaseImplementation::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ acquisitionFinishedCallBack=func; pAcquisitionFinished=arg; } -void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ +void UDPBaseImplementation::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ rawDataReadyCallBack=func; pRawDataReady=arg; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b15a48cc4c..e144585bea 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -69,11 +69,6 @@ UDPStandardImplementation::~UDPStandardImplementation(){ *************************************************************************/ /***initial parameters***/ -void UDPStandardImplementation::deleteBaseMembers(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; - - UDPBaseImplementation::~UDPBaseImplementation(); -} void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; @@ -116,7 +111,7 @@ void UDPStandardImplementation::deleteFilter(){ void UDPStandardImplementation::initializeBaseMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - UDPBaseImplementation::UDPBaseImplementation(); + UDPBaseImplementation::initializeMembers(); acquisitionPeriod = SAMPLE_TIME_IN_NS; } @@ -216,6 +211,7 @@ void UDPStandardImplementation::initializeFilter(){ int sign = 1, csize, i; //common mode initialization + moenchCommonModeSubtraction = NULL; if (commonModeSubtractionEnable){ if(myDetectorType == MOENCH) moenchCommonModeSubtraction=new moenchCommonMode(); @@ -244,7 +240,7 @@ void UDPStandardImplementation::initializeFilter(){ //single photon detector initialization for(i=0; i(receiverData[i], csize, sigma, sign, commonModeSubtractionEnable); + singlePhotonDetectorObject[i]=new singlePhotonDetector(receiverData[i], csize, sigma, sign, moenchCommonModeSubtraction); } @@ -255,7 +251,7 @@ int UDPStandardImplementation::setupFifoStructure(){ int64_t i; int oldNumberofJobsPerBuffer = numberofJobsPerBuffer; - int oldFifoSize = fifoSize; + uint32_t oldFifoSize = fifoSize; //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ @@ -349,6 +345,7 @@ int UDPStandardImplementation::setupFifoStructure(){ } } cout << "Info: Fifo structure(s) reconstructed" << endl; + return OK; } @@ -458,11 +455,9 @@ void UDPStandardImplementation::setShortFrameEnable(const int i){ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - if(i >= 0){ - FrameToGuiFrequency = i; - if(setupFifoStructure() == FAIL) - return FAIL; - } + FrameToGuiFrequency = i; + if(setupFifoStructure() == FAIL) + return FAIL; cout << "Info: Frame to Gui Frequency set to " << FrameToGuiFrequency << endl; @@ -470,14 +465,12 @@ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ } -int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ +int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - if(i >= 0){ - acquisitionPeriod = i; - if(setupFifoStructure() == FAIL) - return FAIL; - } + acquisitionPeriod = i; + if(setupFifoStructure() == FAIL) + return FAIL; cout << "Info: Acquisition Period set to " << acquisitionPeriod << endl; @@ -488,7 +481,7 @@ int UDPStandardImplementation::setAcquisitionPeriod(int64_t i){ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - int oldDynamicRange = dynamicRange; + uint32_t oldDynamicRange = dynamicRange; cout << "Info: Setting Dynamic Range to " << i << endl; dynamicRange = i; @@ -542,7 +535,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ int UDPStandardImplementation::setTenGigaEnable(const bool b){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Setting Ten Giga to " << string(b) << endl; + cout << "Info: Setting Ten Giga to " << stringEnable(b) << endl; bool oldTenGigaEnable = tengigaEnable; tengigaEnable = b; @@ -603,7 +596,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ } - cout << "Info: Ten Giga " << string(tengigaEnable) << endl; + cout << "Info: Ten Giga " << stringEnable(tengigaEnable) << endl; return OK; } @@ -621,12 +614,11 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ /***initial functions***/ -int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorType d){ +int UDPStandardImplementation::setDetectorType(const detectorType d){ FILE_LOG(logDEBUG1) << __AT__ << " called"; cout << "Setting receiver type ..." << endl; - deleteBaseMembers(); deleteMembers(); initializeBaseMembers(); initializeMembers(); @@ -639,7 +631,7 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy case EIGER: case JUNGFRAUCTB: case JUNGFRAU: - cout << "Info: ***** This is a " << slsDetectorBase::getDetectorType(d) << " Receiver *****" << endl; + cout << "Info: ***** This is a " << getDetectorType(d) << " Receiver *****" << endl; break; default: cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); @@ -715,6 +707,9 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy fifoSize = JCTB_FIFO_SIZE; //footerOffset = Not applicable; break; + default: + cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); + return FAIL; } //delete threads and set number of listening threads @@ -745,7 +740,7 @@ int UDPStandardImplementation::setDetectorType(const slsReceiverDefs::detectorTy //allocate for latest data (frame copy for gui) latestData = new char[frameSize]; - cout << " Detector type set to " << slsDetectorBase::getDetectorType(d) << endl; + cout << " Detector type set to " << getDetectorType(d) << endl; cout << "Ready..." << endl; return OK; @@ -837,7 +832,7 @@ int UDPStandardImplementation::startReceiver(char *c){ //For compression, just for gui purposes if(dataCompressionEnable) - sprintf(completeFileName, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); + sprintf(completeFileName, "%s/%s_fxxx_%lld_xx.root", filePath,fileName,(long long int)fileIndex); //initialize semaphore to synchronize between writer and gui reader threads sem_init(&writerGuiSemaphore,1,0); @@ -856,7 +851,7 @@ int UDPStandardImplementation::startReceiver(char *c){ //usleep(5000000); cout << "Info: Receiver Started." << endl; - cout << "Info: Status:" << slsDetectorBase::runStatusType(status) << endl; + cout << "Info: Status:" << runStatusType(status) << endl; return OK; } @@ -889,7 +884,7 @@ void UDPStandardImplementation::stopReceiver(){ pthread_mutex_unlock(&(statusMutex)); cout << "Info: Receiver Stopped" << endl; - cout << "Info: Status:" << slsDetectorBase::runStatusType(status) << endl; + cout << "Info: Status:" << runStatusType(status) << endl; cout << endl; } @@ -1210,8 +1205,10 @@ int UDPStandardImplementation::createUDPSockets(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; //switching ports if bottom enabled - int port[2]; - port = udpPortNum; + uint32_t port[2]; + port[0]= udpPortNum[0]; + port[1]= udpPortNum[1]; + //port = udpPortNum; if(bottomEnable){ port[0] = udpPortNum[1]; port[1] = udpPortNum[0]; @@ -1266,7 +1263,7 @@ int UDPStandardImplementation::setupWriter(){ //acquisition start call back returns enable write cbAction = DO_EVERYTHING; if (startAcquisitionCallBack) - cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition); + cbAction=startAcquisitionCallBack(filePath,fileName,(int)fileIndex,bufferSize,pStartAcquisition); if(cbAction < DO_EVERYTHING){ cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; @@ -1318,11 +1315,11 @@ int UDPStandardImplementation::createNewFile(){ //create file name if(!frameIndexEnable) - sprintf(completeFileName, "%s/%s_%d.raw", filePath,fileName,fileIndex); + sprintf(completeFileName, "%s/%s_%lld.raw", filePath,fileName,(long long int)fileIndex); else if (myDetectorType == EIGER) - sprintf(completeFileName, "%s/%s_f%012d_%d.raw", filePath,fileName,currentFrameNumber,fileIndex); + sprintf(completeFileName, "%s/%s_f%012lld_%lld.raw", filePath,fileName,(long long int)currentFrameNumber,(long long int)fileIndex); else - sprintf(completeFileName, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex); + sprintf(completeFileName, "%s/%s_f%012lld_%lld.raw", filePath,fileName,(long long int)(packetsCaught/packetsPerFrame),(long long int)fileIndex); #ifdef DEBUG4 cout << "Info: " << completefileName << endl; @@ -1534,7 +1531,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in //throw away packets that is not one packet size, need to check status if socket is shut down while(status != TRANSMITTING && myDetectorType == EIGER && receivedSize != onePacketSize) { if(receivedSize != EIGER_HEADER_LENGTH) - cprintf(RED,"Listening_Thread %d: Listened to a weird packet size %d\n",receivedSize); + cprintf(RED,"Listening_Thread %d: Listened to a weird packet size %d\n",ithread, receivedSize); #ifdef DEBUG else cprintf(BLUE,"Listening_Thread %d: Listened to a header packet\n",ithread); @@ -1576,11 +1573,11 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ if(!acqStarted){ startAcquisitionIndex = startFrameIndex; acqStarted = true; - cprintf(BLUE,"Info: Thread %d: startAcquisitionIndex:%d\n",ithread,startAcquisitionIndex); + cprintf(BLUE,"Info: Thread %d: startAcquisitionIndex:%lld\n",ithread,(long long int)startAcquisitionIndex); } //set start of scan/real time measurement - cprintf(BLUE,"Info: Thread %d: startFrameIndex: %d\n", ithread,startFrameIndex); + cprintf(BLUE,"Info: Thread %d: startFrameIndex: %lld\n", ithread,(long long int)startFrameIndex); measurementStarted = true; } @@ -1593,7 +1590,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Stop Listening. Status:" << slsDetectorBase::runStatusType(status) << endl; + cout << "Info: Stop Listening. Status:" << runStatusType(status) << endl; //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) @@ -1672,7 +1669,7 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz FILE_LOG(logDEBUG1) << __AT__ << " called"; int lastPacketOffset; //the offset of the last packet - int lastFrameHeader; //frame number of last packet in buffer + uint32_t lastFrameHeader; //frame number of last packet in buffer uint32_t packetCount = (packetsPerFrame/numberofListeningThreads) * numberofJobsPerBuffer; //packets received cSize = 0; //reset size @@ -1735,8 +1732,8 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz break; default: - cprintf(RED,"Listening_Thread %d: Error: This detector is not implemented in the receiver" + - slsDetectorBase::getDetectorType(myDetectorType).c_str() + "\n"); + cprintf(RED,"Listening_Thread %d: Error: This detector %s is not implemented in the receiver\n", + ithread, getDetectorType(myDetectorType).c_str()); break; } @@ -1779,7 +1776,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ //variable definitions char* wbuf[numberofListeningThreads]; //buffer popped from FIFO sfilefd = NULL; //file pointer - int nf; //for compression, number of frames + uint64_t nf; //for compression, number of frames /* outer loop - loops once for each acquisition */ @@ -1799,7 +1796,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ #ifdef FIFODEBUG cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuf[0]),0); #endif - int numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); + uint32_t numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); if(numPackets < 0) cprintf(BG_RED,"Error: Negative packet numbers: %d for FIFO %d\n",numPackets,0); #ifdef DEBUG4 @@ -1896,7 +1893,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //blank frame - initializing with missing packet values blankoffset = 0; unsigned char* blankframe_data=0; - for(int i=0; ipacketNumber) != (i+1)){ - cprintf(BG_RED, "Packet Number Mismatch! i:%d pnum:%d fnum:%d missingPacket:%d\n", - i,*( (uint16_t*) wbuf_footer->packetNumber),currentFrameNumber,*( (uint16_t*) wbuf_header->missingPacket)); + cprintf(BG_RED, "Writing_Thread: Packet Number Mismatch! " + "i %d, pnum %d, fnum %lld, missingPacket 0x%x\n", + i,*( (uint16_t*) wbuf_footer->packetNumber),(long long int)currentFrameNumber,*( (uint16_t*) wbuf_header->missingPacket)); exit(-1); } //overwriting port number and dynamic range @@ -2526,7 +2521,6 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ void UDPStandardImplementation::copyFrameToGui(char* buffer[]){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - int i; //random read (gui not ready) //need to toggle guiDataReady or the second frame wont be copied @@ -2551,7 +2545,7 @@ void UDPStandardImplementation::copyFrameToGui(char* buffer[]){ #endif switch(myDetectorType){ case EIGER: - for(int i=0; ifindNextFrame(data,ndata,remainingsize)){ diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 15149dde03..5783e601c7 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -166,20 +166,20 @@ int64_t slsReceiver::getReceiverVersion(){ } -void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ +void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackStartAcquisition(func,arg); } -void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ +void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackAcquisitionFinished(func,arg); } -void slsReceiver::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ +void slsReceiver::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ //tcpipInterface udp_interface->registerCallBackRawDataReady(func,arg); } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 5b4664e555..f94b47a015 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -185,7 +185,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){ #ifdef VERYVERBOSE cout << "Starting Receiver TCP Server" << endl; #endif - int v=slsReceiverDefs::OK; + int v=OK; while(1) { #ifdef VERBOSE @@ -832,7 +832,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ if(s == IDLE) ret=receiverBase->startReceiver(mess); else{ - sprintf(mess,"Cannot start Receiver as it is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); + sprintf(mess,"Cannot start Receiver as it is in %s state\n",runStatusType(s).c_str()); ret=FAIL; } } @@ -878,7 +878,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){ if(s==IDLE) ret = OK; else{ - sprintf(mess,"Could not stop receiver. It is in %s state\n",slsDetectorBase::runStatusType(s).c_str()); + sprintf(mess,"Could not stop receiver. It is in %s state\n",runStatusType(s).c_str()); ret = FAIL; } } @@ -1138,8 +1138,8 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ char* raw = new char[bufferSize]; - uint32_t startAcquisitionIndex=0; - uint32_t startFrameIndex=0; + uint64_t startAcquisitionIndex=0; + uint64_t startFrameIndex=0; uint32_t index = -1,bindex = 0, offset=0; strcpy(mess,"Could not read frame\n"); @@ -1327,8 +1327,8 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ uint32_t index=-1,index2=0; uint32_t pindex=0,pindex2=0; uint32_t bindex=0,bindex2=0; - uint32_t startAcquisitionIndex=0; - uint32_t startFrameIndex=0; + uint64_t startAcquisitionIndex=0; + uint64_t startFrameIndex=0; strcpy(mess,"Could not read frame\n"); @@ -1502,8 +1502,8 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ uint32_t index=-1,index2=0; uint32_t pindex=0,pindex2=0; uint32_t bindex=0,bindex2=0; - uint32_t startAcquisitionIndex=0; - uint32_t startFrameIndex=0; + uint64_t startAcquisitionIndex=0; + uint64_t startFrameIndex=0; strcpy(mess,"Could not read frame\n"); @@ -1670,8 +1670,8 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ char* raw = new char[frameSize]; char* origVal = new char[frameSize]; char* retval = new char[dataSize]; - uint32_t startAcquisitionIndex=0; - uint32_t startFrameIndex=0; + uint64_t startAcquisitionIndex=0; + uint64_t startFrameIndex=0; strcpy(mess,"Could not read frame\n"); @@ -2111,11 +2111,11 @@ int slsReceiverTCPIPInterface::set_timer() { ret=FAIL; } else{ - if(index[0] == slsReceiverDefs::FRAME_PERIOD){ + if(index[0] == FRAME_PERIOD){ if(index[1]>=0){ ret = receiverBase->setAcquisitionPeriod(index[1]); if(ret == FAIL) - strcpy(mess,"Could not allocate memory for listening fifo\n") + strcpy(mess,"Could not allocate memory for listening fifo\n"); } retval=receiverBase->getAcquisitionPeriod(); }else{ @@ -2129,7 +2129,7 @@ int slsReceiverTCPIPInterface::set_timer() { } #ifdef VERBOSE if(ret!=FAIL){ - if(index[0] == slsReceiverDefs::FRAME_PERIOD) + if(index[0] == FRAME_PERIOD) cout << "acquisition period:" << retval << endl; else cout << "frame number:" << retval << endl; diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index 1df35558c6..c27f1efc2a 100644 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -29,18 +29,18 @@ int64_t slsReceiverUsers::getReceiverVersion(){ } -void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,uint64_t, uint32_t, void*),void *arg){ +void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackStartAcquisition(func,arg); } -void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ +void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackAcquisitionFinished(func,arg); } -void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(uint64_t, char*, uint32_t, FILE*, char*, void*),void *arg){ +void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ slsReceiverUsers::receiver->registerCallBackRawDataReady(func,arg); } From db54fbddde14443b4b64ef321bfb57a5e23c8ae6 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Thu, 29 Oct 2015 11:20:08 +0100 Subject: [PATCH 159/222] detector type bug fix --- .../src/slsReceiverTCPIPInterface.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index f94b47a015..be3242cd90 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -391,21 +391,22 @@ int slsReceiverTCPIPInterface::set_detector_type(){ sprintf(mess,"Unknown detector type: %d\n", dr); ret = FAIL; break; - if(ret != FAIL){ + } + if(ret != FAIL){ #ifndef REST - receiverBase = UDPInterface::create("standard"); - receiverBase->setBottomEnable(bottom); + receiverBase = UDPInterface::create("standard"); + receiverBase->setBottomEnable(bottom); #endif - myDetectorType = dr; - ret=receiverBase->setDetectorType(myDetectorType); - retval = myDetectorType; - } + myDetectorType = dr; + ret=receiverBase->setDetectorType(myDetectorType); + retval = myDetectorType; } + } } //#ifdef VERBOSE if(ret!=FAIL) - cout << "detector type" << dr << endl; + cout << "detector type " << dr << endl; else cprintf(RED, "%s\n", mess); //#endif From eb5f481faaf2b90891c45532a9b5f3a7093e49c9 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Thu, 29 Oct 2015 11:21:57 +0100 Subject: [PATCH 160/222] detector type bug fix --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index e144585bea..fd4ab0c0c8 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1797,8 +1797,10 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuf[0]),0); #endif uint32_t numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); - if(numPackets < 0) - cprintf(BG_RED,"Error: Negative packet numbers: %d for FIFO %d\n",numPackets,0); + cout<<"numpackets:"< Date: Thu, 29 Oct 2015 13:33:24 +0100 Subject: [PATCH 161/222] log --- .../src/UDPBaseImplementation.cpp | 10 +-- .../src/UDPStandardImplementation.cpp | 79 +++++++++---------- slsReceiverSoftware/src/main.cpp | 2 +- .../src/slsReceiverTCPIPInterface.cpp | 4 +- 4 files changed, 46 insertions(+), 49 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 0bfef5d71e..94a39d07df 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -35,7 +35,7 @@ UDPBaseImplementation::UDPBaseImplementation(){ void UDPBaseImplementation::initializeMembers(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - cout << "Info: Initializing base members" << endl; + FILE_LOG(logDEBUG1) << "Info: Initializing base members" << endl; //**detector parameters*** myDetectorType = GENERIC; strcpy(detHostname,""); @@ -202,7 +202,7 @@ void UDPBaseImplementation::setBottomEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; bottomEnable = b; - FILE_LOG(logINFO) << "Bottom Enable: " << stringEnable(bottomEnable); + FILE_LOG(logINFO) << "Bottom - " << stringEnable(bottomEnable) << endl; } @@ -216,7 +216,7 @@ void UDPBaseImplementation::setFileName(const char c[]){ } void UDPBaseImplementation::setFilePath(const char c[]){ - FILE_LOG(logDEBUG) << __AT__ << " starting"; + FILE_LOG(logINFO) << __AT__ << " starting"; if(strlen(c)){ //check if filepath exists @@ -229,7 +229,7 @@ void UDPBaseImplementation::setFilePath(const char c[]){ } strcpy(filePath, c); } - FILE_LOG(logINFO) << "File path:" << filePath; + FILE_LOG(logDEBUG1) << "Info: File path:" << filePath; } void UDPBaseImplementation::setFileIndex(const uint64_t i){ @@ -273,7 +273,7 @@ int UDPBaseImplementation::setDataCompressionEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; dataCompressionEnable = b; - FILE_LOG(logINFO) << "Data Compression Enable: " << stringEnable(dataCompressionEnable); + FILE_LOG(logINFO) << "Data Compression : " << stringEnable(dataCompressionEnable); //overridden methods might return FAIL return OK; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index fd4ab0c0c8..bfe8c9eb72 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -42,10 +42,10 @@ UDPStandardImplementation::UDPStandardImplementation(){ pthread_mutex_init(&progressMutex,NULL); //to increase socket receiver buffer size and max length of input queue by changing kernel settings - if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) - cout << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) + FILE_LOG(logDEBUG1) << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) - cout << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + FILE_LOG(logDEBUG1) << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; /** permanent setting by heiner net.core.rmem_max = 104857600 # 100MiB net.core.netdev_max_backlog = 250000 @@ -54,6 +54,7 @@ UDPStandardImplementation::UDPStandardImplementation(){ sysctl -w net.core.rmem_max=16777216 sysctl -w net.core.netdev_max_backlog=250000 */ + cout << endl; } UDPStandardImplementation::~UDPStandardImplementation(){ @@ -73,7 +74,7 @@ UDPStandardImplementation::~UDPStandardImplementation(){ void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - cout << "Info: Deleting member pointers" << endl; + FILE_LOG(logDEBUG1) << "Info: Deleting member pointers" << endl; shutDownUDPSockets(); closeFile(); //filter @@ -119,7 +120,7 @@ void UDPStandardImplementation::initializeBaseMembers(){ void UDPStandardImplementation::initializeMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - cout << "Info: Initializing members" << endl; + FILE_LOG(logDEBUG1) << "Info: Initializing members" << endl; //***detector parameters*** frameSize = 0; @@ -256,7 +257,7 @@ int UDPStandardImplementation::setupFifoStructure(){ //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ numberofJobsPerBuffer = 1; - cout << "Info: 1 packet per buffer" << endl; + FILE_LOG(logDEBUG1) << "Info: 1 packet per buffer" << endl; } //else calculate best possible number of frames to listen to at a time (for fast readouts like gotthard) @@ -298,9 +299,8 @@ int UDPStandardImplementation::setupFifoStructure(){ else fifoSize = fifoSize/numberofJobsPerBuffer; } -#ifdef VERBOSE - cout << "Info: Fifo Depth:" << fifoSize << endl; -#endif + FILE_LOG(logDEBUG1) << "Info: Fifo Depth:" << fifoSize << endl; + //do not rebuild fifo structure if it is the same @@ -315,8 +315,8 @@ int UDPStandardImplementation::setupFifoStructure(){ if(fifoFree[i]){ while(!fifoFree[i]->isEmpty()) fifoFree[i]->pop(buffer[i]); -#ifdef FIFO_DEBUG - cprintf(GREEN,"%d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); +#ifdef FIFODEBUG + cprintf(GREEN,"Info: %d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); #endif delete fifoFree[i]; } @@ -338,13 +338,13 @@ int UDPStandardImplementation::setupFifoStructure(){ buffer[i]=mem0[i]; while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoSize-1))) { fifoFree[i]->push(buffer[i]); -#ifdef FIFO_DEBUG - cprintf(BLUE,"%d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); +#ifdef FIFODEBUG + cprintf(BLUE,"Info: %d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); #endif buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); } } - cout << "Info: Fifo structure(s) reconstructed" << endl; + FILE_LOG(logDEBUG1) << "Info: Fifo structure(s) reconstructed" << endl; return OK; } @@ -366,7 +366,7 @@ void UDPStandardImplementation::configure(map config_map){ b = 0; } bottomEnable = b!= 0; - cout << "Info: Bottom Enable: " << stringEnable(bottomEnable) << endl; + cout << "Info: Bottom - " << stringEnable(bottomEnable) << endl; } } @@ -376,12 +376,14 @@ void UDPStandardImplementation::configure(map config_map){ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - cout << "Info: Setting up Data Compression Enable to " << stringEnable(b); + if(myDetectorType != EIGER){ + cout << "Info: Setting up Data Compression Enable to " << stringEnable(b); #ifdef MYROOT1 - cout << " WITH ROOT" << endl; + cout << " WITH ROOT" << endl; #else - cout << " WITHOUT ROOT" << endl; + cout << " WITHOUT ROOT" << endl; #endif + } //set data compression enable dataCompressionEnable = b; @@ -617,7 +619,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ int UDPStandardImplementation::setDetectorType(const detectorType d){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Setting receiver type ..." << endl; + cout << "Info: Setting receiver type ..." << endl; deleteMembers(); initializeBaseMembers(); @@ -631,7 +633,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ case EIGER: case JUNGFRAUCTB: case JUNGFRAU: - cout << "Info: ***** This is a " << getDetectorType(d) << " Receiver *****" << endl; + FILE_LOG(logINFO) << " ***** This is a " << getDetectorType(d) << " Receiver *****" << endl; break; default: cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); @@ -761,7 +763,8 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - + + cout << endl; cout << "Info: Starting Receiver" << endl; @@ -800,15 +803,16 @@ int UDPStandardImplementation::startReceiver(char *c){ //Print Receiver Configuration - cout << "Info: ***Receiver Configuration***" << endl; - cout << "Info: Max Packets Per File:" << maxPacketsPerFile << endl; - cout << "Info: Data Compression has been " << stringEnable(dataCompressionEnable) << endl; - if(myDetectorType != EIGER) + if(myDetectorType != EIGER){ + + cout << "Info: Data Compression has been " << stringEnable(dataCompressionEnable) << endl; cout << "Info: Number of Jobs Per Buffer: " << numberofJobsPerBuffer << endl; + cout << "Info: Max Packets Per File:" << maxPacketsPerFile << endl; + } if(FrameToGuiFrequency) - cout << "Info: Frequency of frames sent to gui" << FrameToGuiFrequency << endl; + cout << "Info: requency of frames sent to gui: " << FrameToGuiFrequency << endl; else - cout << "Info: Random frames sent to gui" << endl; + cout << "Info: Frequency of frames sent to gui: Random" << endl; @@ -895,7 +899,7 @@ void UDPStandardImplementation::stopReceiver(){ int UDPStandardImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Shutting down UDP Socket(s)" << endl; + FILE_LOG(logDEBUG1) << "Info: Shutting down UDP Socket(s)" << endl; for(int i=0;istart() == slsReceiverDefs::OK){ - cout << "DONE!" << endl; + FILE_LOG(logDEBUG1) << "DONE!" << endl; string str; cin>>str; //wait and look for an exit keyword diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index be3242cd90..e0835df55f 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -125,14 +125,14 @@ int slsReceiverTCPIPInterface::setPortNumber(int pn){ int slsReceiverTCPIPInterface::start(){ - cout << "Creating TCP Server Thread" << endl; + FILE_LOG(logDEBUG1) << "Creating TCP Server Thread" << endl; killTCPServerThread = 0; if(pthread_create(&TCPServer_thread, NULL,startTCPServerThread, (void*) this)){ cout << "Could not create TCP Server thread" << endl; return FAIL; } //#ifdef VERBOSE - cout << "TCP Server thread created successfully." << endl; + FILE_LOG(logDEBUG1) << "TCP Server thread created successfully." << endl; //#endif return OK; } From 963717215f346e7f06b4161b5ba3a88fec6e790f Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 29 Oct 2015 17:23:39 +0100 Subject: [PATCH 162/222] done --- slsReceiverSoftware/include/ansi.h | 29 +- slsReceiverSoftware/include/logger.h | 43 ++- .../src/UDPBaseImplementation.cpp | 16 +- slsReceiverSoftware/src/UDPInterface.cpp | 2 +- .../src/UDPStandardImplementation.cpp | 257 ++++++++---------- .../src/slsReceiverTCPIPInterface.cpp | 77 +++--- 6 files changed, 221 insertions(+), 203 deletions(-) diff --git a/slsReceiverSoftware/include/ansi.h b/slsReceiverSoftware/include/ansi.h index 1a24d403e4..2104913737 100644 --- a/slsReceiverSoftware/include/ansi.h +++ b/slsReceiverSoftware/include/ansi.h @@ -1,17 +1,18 @@ -#define RED "\x1b[31m" -#define GREEN "\x1b[32m" -#define YELLOW "\x1b[33m" -#define BLUE "\x1b[34m" -#define MAGENTA "\x1b[35m" -#define CYAN "\x1b[36m" -#define BG_RED "\x1b[41m" -#define BG_GREEN "\x1b[42m" -#define BG_YELLOW "\x1b[43m" -#define BG_BLUE "\x1b[44m" -#define BG_MAGENTA "\x1b[45m" -#define BG_CYAN "\x1b[46m" -#define RESET "\x1b[0m" -#define BOLD "\x1b[1m" +#define RED "\x1b[31m" +#define GREEN "\x1b[32m" +#define YELLOW "\x1b[33m" +#define BLUE "\x1b[34m" +#define MAGENTA "\x1b[35m" +#define CYAN "\x1b[36m" +#define GRAY "\x1b[37m" +#define BG_RED "\x1b[41m" +#define BG_GREEN "\x1b[42m" +#define BG_YELLOW "\x1b[43m" +#define BG_BLUE "\x1b[44m" +#define BG_MAGENTA "\x1b[45m" +#define BG_CYAN "\x1b[46m" +#define RESET "\x1b[0m" +#define BOLD "\x1b[1m" #define cprintf(code, format, ...) printf(code format RESET, ##__VA_ARGS__) diff --git a/slsReceiverSoftware/include/logger.h b/slsReceiverSoftware/include/logger.h index 5e964da271..7732abffcf 100644 --- a/slsReceiverSoftware/include/logger.h +++ b/slsReceiverSoftware/include/logger.h @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef VERBOSE #define FILELOG_MAX_LEVEL logDEBUG @@ -14,6 +15,10 @@ #define FILELOG_MAX_LEVEL logDEBUG4 #endif +#ifdef FIFODEBUG +#define FILELOG_MAX_LEVEL logDEBUG5 +#endif + #ifndef FILELOG_MAX_LEVEL #define FILELOG_MAX_LEVEL logINFO #endif @@ -40,7 +45,7 @@ void error(const char *location, const char *msg){ inline std::string NowTime(); -enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4}; +enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5}; template class Log{ public: @@ -52,6 +57,7 @@ template class Log{ static TLogLevel FromString(const std::string& level); protected: std::ostringstream os; + TLogLevel lev; private: Log(const Log&); Log& operator =(const Log&); @@ -62,6 +68,7 @@ class Output2FILE { public: static FILE*& Stream(); static void Output(const std::string& msg); + static void Output(const std::string& msg, TLogLevel level); }; #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) @@ -79,10 +86,17 @@ class Output2FILE { class FILELOG_DECLSPEC FILELog : public Log {}; //typedef Log FILELog; +#ifdef REST #define FILE_LOG(level) \ if (level > FILELOG_MAX_LEVEL) ; \ else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ else FILELog().Get(level) +#else + #define FILE_LOG(level) \ + if (level > FILELOG_MAX_LEVEL) ; \ + else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ + else FILELog().Get(level) +#endif #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) @@ -126,10 +140,11 @@ inline std::string NowTime() #endif //WIN32 -template Log::Log(){} +template Log::Log():lev(logDEBUG){} template std::ostringstream& Log::Get(TLogLevel level) { + lev = level; os << "- " << NowTime(); os << " " << ToString(level) << ": "; os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t'); @@ -139,24 +154,30 @@ template std::ostringstream& Log::Get(TLogLevel level) template Log::~Log() { os << std::endl; +#ifdef REST T::Output( os.str()); +#else + T::Output( os.str(),lev); +#endif } template TLogLevel& Log::ReportingLevel() { - static TLogLevel reportingLevel = logDEBUG4; + static TLogLevel reportingLevel = logDEBUG5; return reportingLevel; } template std::string Log::ToString(TLogLevel level) { - static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"}; + static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4","DEBUG5"}; return buffer[level]; } template TLogLevel Log::FromString(const std::string& level) { + if (level == "DEBUG5") + return logDEBUG5; if (level == "DEBUG4") return logDEBUG4; if (level == "DEBUG3") @@ -193,6 +214,20 @@ inline void Output2FILE::Output(const std::string& msg) fflush(pStream); } +inline void Output2FILE::Output(const std::string& msg, TLogLevel level) +{ + FILE* pStream = Stream(); + if (!pStream) + return; + switch(level){ + case logERROR: cprintf(RED BOLD,"%s",msg.c_str()); break; + case logWARNING: cprintf(YELLOW BOLD,"%s",msg.c_str()); break; + case logINFO: cprintf(GRAY,"%s",msg.c_str()); break; + default: fprintf(pStream,"%s",msg.c_str()); break; + } + fflush(pStream); +} + #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) # if defined (BUILDING_FILELOG_DLL) # define FILELOG_DECLSPEC __declspec (dllexport) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 94a39d07df..eaac8c8e97 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -35,7 +35,7 @@ UDPBaseImplementation::UDPBaseImplementation(){ void UDPBaseImplementation::initializeMembers(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; - FILE_LOG(logDEBUG1) << "Info: Initializing base members" << endl; + FILE_LOG(logDEBUG) << "Info: Initializing base members"; //**detector parameters*** myDetectorType = GENERIC; strcpy(detHostname,""); @@ -202,7 +202,7 @@ void UDPBaseImplementation::setBottomEnable(const bool b){ FILE_LOG(logDEBUG) << __AT__ << " starting"; bottomEnable = b; - FILE_LOG(logINFO) << "Bottom - " << stringEnable(bottomEnable) << endl; + FILE_LOG(logINFO) << "Bottom - " << stringEnable(bottomEnable); } @@ -216,7 +216,7 @@ void UDPBaseImplementation::setFileName(const char c[]){ } void UDPBaseImplementation::setFilePath(const char c[]){ - FILE_LOG(logINFO) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; if(strlen(c)){ //check if filepath exists @@ -229,7 +229,7 @@ void UDPBaseImplementation::setFilePath(const char c[]){ } strcpy(filePath, c); } - FILE_LOG(logDEBUG1) << "Info: File path:" << filePath; + FILE_LOG(logDEBUG) << "Info: File path:" << filePath; } void UDPBaseImplementation::setFileIndex(const uint64_t i){ @@ -285,14 +285,14 @@ void UDPBaseImplementation::setUDPPortNumber(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; udpPortNum[0] = i; - FILE_LOG(logINFO) << "udpPortNum[0]:" << udpPortNum[0]; + FILE_LOG(logINFO) << "UDP Port Number[0]:" << udpPortNum[0]; } void UDPBaseImplementation::setUDPPortNumber2(const uint32_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; udpPortNum[1] = i; - FILE_LOG(logINFO) << "udpPortNum[1]:" << udpPortNum[1]; + FILE_LOG(logINFO) << "UDP Port Number[1]:" << udpPortNum[1]; } void UDPBaseImplementation::setEthernetInterface(const char* c){ @@ -325,7 +325,7 @@ int UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; acquisitionPeriod = i; - FILE_LOG(logINFO) << "Acquisition Period:" << acquisitionPeriod; + FILE_LOG(logINFO) << "Acquisition Period:" << (double)acquisitionPeriod/(1E9) << "s"; //overrridden child classes might return FAIL return OK; @@ -389,7 +389,7 @@ void UDPBaseImplementation::resetAcquisitionCount(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; totalPacketsCaught = 0; - FILE_LOG(logINFO) << "totalPacketsCaught:" << totalPacketsCaught << endl; + FILE_LOG(logINFO) << "totalPacketsCaught:" << totalPacketsCaught; } int UDPBaseImplementation::startReceiver(char *c){ diff --git a/slsReceiverSoftware/src/UDPInterface.cpp b/slsReceiverSoftware/src/UDPInterface.cpp index 9370358452..17491bc3a9 100644 --- a/slsReceiverSoftware/src/UDPInterface.cpp +++ b/slsReceiverSoftware/src/UDPInterface.cpp @@ -23,7 +23,7 @@ using namespace std; UDPInterface * UDPInterface::create(string receiver_type){ if (receiver_type == "standard"){ - cout << "Starting " << receiver_type << endl; + FILE_LOG(logINFO) << "Starting " << receiver_type; return new UDPStandardImplementation(); } #ifdef REST diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index bfe8c9eb72..346d6db9f3 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -42,10 +42,11 @@ UDPStandardImplementation::UDPStandardImplementation(){ pthread_mutex_init(&progressMutex,NULL); //to increase socket receiver buffer size and max length of input queue by changing kernel settings - if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) - FILE_LOG(logDEBUG1) << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; + if(myDetectorType == EIGER); + else if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) + FILE_LOG(logDEBUG) << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max"; else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) - FILE_LOG(logDEBUG1) << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + FILE_LOG(logDEBUG) << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog"; /** permanent setting by heiner net.core.rmem_max = 104857600 # 100MiB net.core.netdev_max_backlog = 250000 @@ -53,8 +54,7 @@ UDPStandardImplementation::UDPStandardImplementation(){ // from the manual sysctl -w net.core.rmem_max=16777216 sysctl -w net.core.netdev_max_backlog=250000 - */ - cout << endl; + */ } UDPStandardImplementation::~UDPStandardImplementation(){ @@ -74,7 +74,7 @@ UDPStandardImplementation::~UDPStandardImplementation(){ void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - FILE_LOG(logDEBUG1) << "Info: Deleting member pointers" << endl; + FILE_LOG(logDEBUG) << "Info: Deleting member pointers"; shutDownUDPSockets(); closeFile(); //filter @@ -120,7 +120,7 @@ void UDPStandardImplementation::initializeBaseMembers(){ void UDPStandardImplementation::initializeMembers(){ FILE_LOG(logDEBUG1) << __AT__ << " starting"; - FILE_LOG(logDEBUG1) << "Info: Initializing members" << endl; + FILE_LOG(logDEBUG) << "Info: Initializing members"; //***detector parameters*** frameSize = 0; @@ -257,7 +257,7 @@ int UDPStandardImplementation::setupFifoStructure(){ //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ numberofJobsPerBuffer = 1; - FILE_LOG(logDEBUG1) << "Info: 1 packet per buffer" << endl; + FILE_LOG(logDEBUG) << "Info: 1 packet per buffer"; } //else calculate best possible number of frames to listen to at a time (for fast readouts like gotthard) @@ -280,7 +280,7 @@ int UDPStandardImplementation::setupFifoStructure(){ numberofJobsPerBuffer = i; } - cout << "Info: Number of Frames per buffer:" << numberofJobsPerBuffer << endl; + FILE_LOG(logINFO) << "Number of Frames per buffer:" << numberofJobsPerBuffer << endl; } //set fifo depth @@ -299,7 +299,7 @@ int UDPStandardImplementation::setupFifoStructure(){ else fifoSize = fifoSize/numberofJobsPerBuffer; } - FILE_LOG(logDEBUG1) << "Info: Fifo Depth:" << fifoSize << endl; + FILE_LOG(logDEBUG) << "Info: Fifo Depth:" << fifoSize; @@ -315,8 +315,8 @@ int UDPStandardImplementation::setupFifoStructure(){ if(fifoFree[i]){ while(!fifoFree[i]->isEmpty()) fifoFree[i]->pop(buffer[i]); -#ifdef FIFODEBUG - cprintf(GREEN,"Info: %d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); +#ifdef DEBUG5 + cprintf(BLUE,"Info: %d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); #endif delete fifoFree[i]; } @@ -338,13 +338,13 @@ int UDPStandardImplementation::setupFifoStructure(){ buffer[i]=mem0[i]; while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoSize-1))) { fifoFree[i]->push(buffer[i]); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Info: %d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); #endif buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); } } - FILE_LOG(logDEBUG1) << "Info: Fifo structure(s) reconstructed" << endl; + FILE_LOG(logDEBUG) << "Info: Fifo structure(s) reconstructed"; return OK; } @@ -366,7 +366,7 @@ void UDPStandardImplementation::configure(map config_map){ b = 0; } bottomEnable = b!= 0; - cout << "Info: Bottom - " << stringEnable(bottomEnable) << endl; + FILE_LOG(logINFO) << "Bottom: " << stringEnable(bottomEnable); } } @@ -410,7 +410,7 @@ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ if(b) initializeFilter(); - cout << "Info: Data Compression " << stringEnable(dataCompressionEnable) << endl; + FILE_LOG(logINFO) << "Data Compression: " << stringEnable(dataCompressionEnable); return OK; } @@ -450,7 +450,7 @@ void UDPStandardImplementation::setShortFrameEnable(const int i){ if(dataCompressionEnable) initializeFilter(); - cout << "Info: Short Frame Enable set to " << shortFrameEnable << endl; + FILE_LOG(logINFO) << "Short Frame Enable: " << shortFrameEnable; } @@ -461,7 +461,7 @@ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ if(setupFifoStructure() == FAIL) return FAIL; - cout << "Info: Frame to Gui Frequency set to " << FrameToGuiFrequency << endl; + FILE_LOG(logINFO) << "Frame to Gui Frequency: " << FrameToGuiFrequency; return OK; } @@ -474,7 +474,7 @@ int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){ if(setupFifoStructure() == FAIL) return FAIL; - cout << "Info: Acquisition Period set to " << acquisitionPeriod << endl; + FILE_LOG(logINFO) << "Acquisition Period: " << (double)acquisitionPeriod/(1E9) << "s"; return OK; @@ -485,7 +485,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ uint32_t oldDynamicRange = dynamicRange; - cout << "Info: Setting Dynamic Range to " << i << endl; + FILE_LOG(logDEBUG) << "Info: Setting Dynamic Range to " << i; dynamicRange = i; if(myDetectorType == EIGER){ @@ -515,11 +515,11 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ //create threads if(createListeningThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create listening thread\n"); + FILE_LOG(logERROR) << "Could not create listening thread"; return FAIL; } if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create writer threads\n"); + FILE_LOG(logERROR) << "Could not create writer threads"; return FAIL; } setThreadPriorities(); @@ -527,7 +527,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ } - cout << "Info: Dynamic Range set to " << dynamicRange << endl; + FILE_LOG(logINFO) << "Dynamic Range: " << dynamicRange; return OK; } @@ -537,7 +537,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ int UDPStandardImplementation::setTenGigaEnable(const bool b){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Setting Ten Giga to " << stringEnable(b) << endl; + FILE_LOG(logDEBUG) << "Info: Setting Ten Giga to " << stringEnable(b); bool oldTenGigaEnable = tengigaEnable; tengigaEnable = b; @@ -557,13 +557,13 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ bufferSize = onePacketSize; maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - FILE_LOG(logDEBUG1) << dec << + FILE_LOG(logDEBUG) << dec << "packetsPerFrame:" << packetsPerFrame << "\nonePacketSize:" << onePacketSize << "\noneDataSize:" << oneDataSize << "\nframesize:" << frameSize << "\nbufferSize:" << bufferSize << - "\nmaxPacketsPerFile:" << maxPacketsPerFile << endl; + "\nmaxPacketsPerFile:" << maxPacketsPerFile; @@ -586,11 +586,11 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ //create threads if(createListeningThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create listening thread\n"); + FILE_LOG(logERROR) << "Could not create listening thread"; return FAIL; } if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create writer threads\n"); + FILE_LOG(logERROR) << "Could not create writer threads"; return FAIL; } setThreadPriorities(); @@ -598,7 +598,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ } - cout << "Info: Ten Giga " << stringEnable(tengigaEnable) << endl; + FILE_LOG(logINFO) << "Ten Giga: " << stringEnable(tengigaEnable); return OK; } @@ -619,7 +619,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ int UDPStandardImplementation::setDetectorType(const detectorType d){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Setting receiver type ..." << endl; + FILE_LOG(logDEBUG) << "Setting receiver type"; deleteMembers(); initializeBaseMembers(); @@ -633,10 +633,10 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ case EIGER: case JUNGFRAUCTB: case JUNGFRAU: - FILE_LOG(logINFO) << " ***** This is a " << getDetectorType(d) << " Receiver *****" << endl; + FILE_LOG(logINFO) << " ***** This is a " << getDetectorType(d) << " Receiver *****"; break; default: - cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); + FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d; return FAIL; } @@ -710,7 +710,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ //footerOffset = Not applicable; break; default: - cprintf(BG_RED, "Error: This is an unknown receiver type %d\n", (int)d); + FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d; return FAIL; } @@ -730,11 +730,11 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ //create threads if(createListeningThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create listening thread\n"); + FILE_LOG(logERROR) << "Could not create listening thread"; return FAIL; } if(createWriterThreads() == FAIL){ - cprintf(BG_RED,"Error: Could not create writer threads\n"); + FILE_LOG(logERROR) << "Could not create writer threads"; return FAIL; } setThreadPriorities(); @@ -742,8 +742,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ //allocate for latest data (frame copy for gui) latestData = new char[frameSize]; - cout << " Detector type set to " << getDetectorType(d) << endl; - cout << "Ready..." << endl; + FILE_LOG(logDEBUG) << " Detector type set to " << getDetectorType(d); return OK; } @@ -757,15 +756,14 @@ void UDPStandardImplementation::resetAcquisitionCount(){ acqStarted = false; startAcquisitionIndex = 0; - cout << "Info: Acquisition Count has been reset" << endl; + FILE_LOG(logINFO) << "Acquisition Count has been reset"; } int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << endl; - cout << "Info: Starting Receiver" << endl; + FILE_LOG(logINFO) << "Starting Receiver"; //RESET @@ -804,32 +802,29 @@ int UDPStandardImplementation::startReceiver(char *c){ //Print Receiver Configuration if(myDetectorType != EIGER){ - - cout << "Info: Data Compression has been " << stringEnable(dataCompressionEnable) << endl; - cout << "Info: Number of Jobs Per Buffer: " << numberofJobsPerBuffer << endl; - cout << "Info: Max Packets Per File:" << maxPacketsPerFile << endl; + FILE_LOG(logINFO) << "Data Compression has been " << stringEnable(dataCompressionEnable); + FILE_LOG(logINFO) << "Number of Jobs Per Buffer: " << numberofJobsPerBuffer; + FILE_LOG(logINFO) << "Max Packets Per File:" << maxPacketsPerFile; } if(FrameToGuiFrequency) - cout << "Info: requency of frames sent to gui: " << FrameToGuiFrequency << endl; + FILE_LOG(logINFO) << "Frequency of frames sent to gui: " << FrameToGuiFrequency; else - cout << "Info: Frequency of frames sent to gui: Random" << endl; + FILE_LOG(logINFO) << "Frequency of frames sent to gui: Random"; //create UDP sockets if(createUDPSockets() == FAIL){ - strcpy(c,"Could not create UDP Socket(s).\n"); - cout << endl; - cprintf(BG_RED, "Error: %s\n",c); + strcpy(c,"Could not create UDP Socket(s)."); + FILE_LOG(logERROR) << c; return FAIL; } if(setupWriter() == FAIL){ //stop udp socket shutDownUDPSockets(); - sprintf(c,"Could not create file %s.\n",completeFileName); - cout << endl; - cprintf(BG_RED, "Error: %s\n",c); + sprintf(c,"Could not create file %s.",completeFileName); + FILE_LOG(logERROR) << c; return FAIL; } @@ -854,8 +849,8 @@ int UDPStandardImplementation::startReceiver(char *c){ for(int i=0; i < numberofWriterThreads; i++) sem_post(&writerSemaphore[i]); //usleep(5000000); - cout << "Info: Receiver Started." << endl; - cout << "Info: Status:" << runStatusType(status) << endl; + FILE_LOG(logINFO) << "Receiver Started"; + FILE_LOG(logINFO) << "Status:" << runStatusType(status); return OK; } @@ -868,7 +863,7 @@ int UDPStandardImplementation::startReceiver(char *c){ void UDPStandardImplementation::stopReceiver(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Stopping Receiver" << endl; + FILE_LOG(logINFO) << "Stopping Receiver"; //set status to transmitting startReadout(); @@ -887,8 +882,8 @@ void UDPStandardImplementation::stopReceiver(){ status = IDLE; pthread_mutex_unlock(&(statusMutex)); - cout << "Info: Receiver Stopped" << endl; - cout << "Info: Status:" << runStatusType(status) << endl; + FILE_LOG(logINFO) << "Receiver Stopped"; + FILE_LOG(logINFO) << "Status:" << runStatusType(status); cout << endl; } @@ -899,7 +894,7 @@ void UDPStandardImplementation::stopReceiver(){ int UDPStandardImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - FILE_LOG(logDEBUG1) << "Info: Shutting down UDP Socket(s)" << endl; + FILE_LOG(logDEBUG) << "Info: Shutting down UDP Socket(s)"; for(int i=0;iWrite()) //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Info: Thread " << i <<": wrote frames to file" << endl; + FILE_LOG(logINFO) << "Thread " << i <<": wrote frames to file"; else - cout << "Info: Thread " << i << ": could not write frames to file" << endl; + FILE_LOG(logINFO) << "Thread " << i << ": could not write frames to file"; }else - cout << "Info: Thread " << i << ": could not write frames to file: No file or No Tree" << endl; + FILE_LOG(logINFO) << "Thread " << i << ": could not write frames to file: No file or No Tree"; //close file if(myTree[i] && myFile[i]) myFile[i] = myTree[i]->GetCurrentFile(); @@ -1068,23 +1063,22 @@ int UDPStandardImplementation::createListeningThreads(bool destroy){ //destroy if(destroy){ - FILE_LOG(logDEBUG) << "Info: Destroying Listening Thread(s)" << endl; + FILE_LOG(logDEBUG) << "Info: Destroying Listening Thread(s)"; killAllListeningThreads = true; for(int i = 0; i < numberofListeningThreads; ++i){ sem_post(&listenSemaphore[i]); pthread_join(listeningThreads[i],NULL); - cout <<"."<getErrorStatus(); if(!iret){ - cout << "Info: UDP port opened at port " << port[i] << endl; + FILE_LOG(logINFO) << "UDP port opened at port " << port[i]; }else{ -#ifdef VERBOSE - cprintf(BG_RED,"Error: Could not create UDP socket on port %d error: %d\n", port[i], iret); -#endif + FILE_LOG(logERROR) << "Could not create UDP socket on port " << port[i] << " error: " << iret; shutDownUDPSockets(); return FAIL; } } - cout << "Info: UDP socket(s) created successfully." << endl; - cout << "Info: Listener Ready ..." << endl; + FILE_LOG(logDEBUG) << "UDP socket(s) created successfully."; + FILE_LOG(logINFO) << "Listener Ready ..."; return OK; } @@ -1270,11 +1254,11 @@ int UDPStandardImplementation::setupWriter(){ cbAction=startAcquisitionCallBack(filePath,fileName,(int)fileIndex,bufferSize,pStartAcquisition); if(cbAction < DO_EVERYTHING){ - cout << "Info: Call back activated. Data saving must be taken care of by user in call back." << endl; + FILE_LOG(logINFO) << "Call back activated. Data saving must be taken care of by user in call back."; if (rawDataReadyCallBack) - cout << "Info: Data Write has been defined externally" << endl; + FILE_LOG(logINFO) << "Data Write has been defined externally"; }else if(!fileWriteEnable) - cout << "Info: Data will not be saved" << endl; + FILE_LOG(logINFO) << "Data will not be saved"; @@ -1285,7 +1269,7 @@ int UDPStandardImplementation::setupWriter(){ pthread_mutex_unlock(&statusMutex); for(int i=0; inewDataSet(); if(myFile[ithread]==NULL){ - cprintf(BG_RED,"Error: File Null\n"); + FILE_LOG(logERROR) << "File Null"; return FAIL; } if(!myFile[ithread]->IsOpen()){ - cprintf(BG_RED,"Error: File Not Open\n") + FILE_LOG(logERROR) << "File Not Open"; return FAIL; } return OK; @@ -1464,13 +1448,13 @@ void UDPStandardImplementation::startListening(){ //pop from fifo fifoFree[ithread]->pop(buffer[ithread]); -#ifdef FIFODEBUG - cprintf(BLUE,"%d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); +#ifdef DEBUG5 + cprintf(BLUE,"Listening_Thread %d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif //udpsocket doesnt exist if(udpSocket[ithread] == NULL){ - cprintf(RED, "Error: Thread %d :UDP Socket not created\n",ithread); + FILE_LOG(logERROR) << "Listening_Thread " << ithread << ": UDP Socket not created"; stopListening(ithread,0); continue; } @@ -1501,7 +1485,7 @@ void UDPStandardImplementation::startListening(){ //push buffer to FIFO while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); #endif @@ -1512,7 +1496,7 @@ void UDPStandardImplementation::startListening(){ //check to exit thread (for change of parameters) - only EXIT possibility if(killAllListeningThreads){ - cprintf(GREEN,"Listening_Thread %d:Goodbye!\n",ithread); + cprintf(BLUE,"Listening_Thread %d:Goodbye!\n",ithread); //free resources at exit if(tempBuffer) delete[] tempBuffer; pthread_exit(NULL); @@ -1544,7 +1528,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in } #ifdef DEBUG - cprintf(BLUE, "Listening_Thread %d : Received bytes: %d. Expected bytes: %d\n", ithread, receivedSize, expected-cSize); + cprintf(BLUE, "Listening_Thread %d : Received bytes: %d. Expected bytes: %d\n", ithread, receivedSize, bufferSize * numberofJobsPerBuffer-cSize); #endif return receivedSize; } @@ -1577,11 +1561,11 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ if(!acqStarted){ startAcquisitionIndex = startFrameIndex; acqStarted = true; - cprintf(BLUE,"Info: Thread %d: startAcquisitionIndex:%lld\n",ithread,(long long int)startAcquisitionIndex); + cprintf(BLUE,"Listening_Thread %d: startAcquisitionIndex:%lld\n",ithread,(long long int)startAcquisitionIndex); } //set start of scan/real time measurement - cprintf(BLUE,"Info: Thread %d: startFrameIndex: %lld\n", ithread,(long long int)startFrameIndex); + cprintf(BLUE,"Listening_Thread %d: startFrameIndex: %lld\n", ithread,(long long int)startFrameIndex); measurementStarted = true; } @@ -1594,8 +1578,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - cout << "Info: Thread " << ithread << ": Stop Listening.\nStatus:" << runStatusType(status) << endl; - + cprintf(BLUE,"Listening_Thread %d: Stop Listening.\nStatus:%s\n", ithread, runStatusType(status).c_str()); //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) if(numbytes < onePacketSize) @@ -1604,9 +1587,9 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ //free empty buffer if(numbytes <= 0){ - cprintf(BLUE,"Info: Thread %d :End of Acquisition for Listening Thread\n", ithread); + cprintf(BLUE,"Listening_Thread %d :End of Acquisition\n", ithread); while(!fifoFree[ithread]->push(buffer[ithread])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif } @@ -1621,7 +1604,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ cprintf(BLUE,"Listening_Thread %d: Last Buffer packet count:%d\n",ithread, numbytes/onePacketSize); #endif while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); #endif } @@ -1632,7 +1615,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ //creating dummy-end buffer with pc=0xFFFF (*((uint32_t*)(buffer[ithread]))) = dummyPacketValue; while(!fifo[ithread]->push(buffer[ithread])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(BLUE,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); #endif } @@ -1797,7 +1780,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ while((1 << ithread) & writerThreadsMask){ //pop fifo[0]->pop(wbuf[0]); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuf[0]),0); #endif uint32_t numPackets = (uint32_t)(*((uint32_t*)wbuf[0])); @@ -1952,7 +1935,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //update frame number and packet number if(numPackets[i] != dummyPacketValue){ if(!((uint32_t)(*( (uint64_t*) packetBuffer_footer)))){ - cprintf(BG_RED,"Fifo %d: Error: Frame Number is zero from firmware. popready[%d]:%d\n",i,i,popReady[i]); + FILE_LOG(logERROR) << "Fifo "<< i << ": Frame Number is zero from firmware. popready[" << i << "]:" << popReady[i]; popReady[i]=true; continue; } @@ -2090,13 +2073,13 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //freeing for(int j=0;jpush(toFreePointers[j])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Fifo 0: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); #endif } for(int j=(packetsPerFrame/numberofListeningThreads);jpush(toFreePointers[j])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Fifo 1: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); #endif } @@ -2210,7 +2193,7 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w //pop if ready if(ready[i]){ fifo[i]->pop(wbuffer[i]); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); #endif nP[i] = (uint32_t)(*((uint32_t*)wbuffer[i])); @@ -2259,7 +2242,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //free fifo for(int i=0; ipush(wbuffer[i])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); #endif } @@ -2296,12 +2279,12 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //statistics cprintf(GREEN, "Status: Run Finished\n"); - if(!totalPacketsCaught){ - cprintf(RED, "Total Missing Packets padded:%d\n",numTotMissingPackets); - cprintf(RED, "Total Packets Caught: 0\n"); + if((long long int)(totalPacketsCaught/packetsPerFrame) == 0){ + cprintf(RED, "Total Missing Packets padded: %d\n",numTotMissingPackets); + cprintf(RED, "Total Packets Caught: %lld\n",(long long int)totalPacketsCaught); cprintf(RED, "Total Frames Caught: 0\n"); }else{ - cprintf(GREEN, "Total Missing Packets padded:%d\n",numTotMissingPackets); + cprintf(GREEN, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(GREEN, "Total Packets Caught:%lld\n", (long long int)totalPacketsCaught); cprintf(GREEN, "Total Frames Caught:%lld\n",(long long int)(totalPacketsCaught/packetsPerFrame)); } @@ -2365,7 +2348,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //free fifo addresses (eiger frees for each packet later) if(myDetectorType != EIGER){ while(!fifoFree[0]->push(wbuffer[0])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Freed buffer, pushed into fifofree %p for listener 0\n",ithread, (void*)(wbuffer[0])); #endif } @@ -2701,7 +2684,7 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer while(!fifoFree[0]->push(wbuffer[0])); -#ifdef FIFODEBUG +#ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Compression free pushed into fifofree %p for listerner 0\n", ithread, (void*)(wbuffer[0])); #endif } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index e0835df55f..d7e562f762 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -125,14 +125,14 @@ int slsReceiverTCPIPInterface::setPortNumber(int pn){ int slsReceiverTCPIPInterface::start(){ - FILE_LOG(logDEBUG1) << "Creating TCP Server Thread" << endl; + FILE_LOG(logDEBUG) << "Creating TCP Server Thread" << endl; killTCPServerThread = 0; if(pthread_create(&TCPServer_thread, NULL,startTCPServerThread, (void*) this)){ cout << "Could not create TCP Server thread" << endl; return FAIL; } //#ifdef VERBOSE - FILE_LOG(logDEBUG1) << "TCP Server thread created successfully." << endl; + FILE_LOG(logDEBUG) << "TCP Server thread created successfully." << endl; //#endif return OK; } @@ -395,25 +395,27 @@ int slsReceiverTCPIPInterface::set_detector_type(){ if(ret != FAIL){ #ifndef REST receiverBase = UDPInterface::create("standard"); - receiverBase->setBottomEnable(bottom); #endif myDetectorType = dr; ret=receiverBase->setDetectorType(myDetectorType); retval = myDetectorType; +#ifndef REST + receiverBase->setBottomEnable(bottom); +#endif } } } //#ifdef VERBOSE if(ret!=FAIL) - cout << "detector type " << dr << endl; + FILE_LOG(logDEBUG) << "detector type " << dr; else cprintf(RED, "%s\n", mess); //#endif #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -474,7 +476,7 @@ int slsReceiverTCPIPInterface::set_file_name() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -546,7 +548,7 @@ int slsReceiverTCPIPInterface::set_file_dir() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -612,7 +614,7 @@ int slsReceiverTCPIPInterface::set_file_index() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -685,7 +687,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -748,12 +750,12 @@ int slsReceiverTCPIPInterface::setup_udp(){ receiverBase->setUDPPortNumber2(udpport2); //setup udpip //get ethernet interface or IP to listen to - cout << "Ethernet interface is " << args[0] << endl; + FILE_LOG(logINFO) << "Receiver UDP IP: " << args[0]; temp = genericSocket::ipToName(args[0]); - cout << temp << endl; if(temp=="none"){ ret = FAIL; - strcpy(mess, "failed to get ethernet interface or IP to listen to\n"); + strcpy(mess, "Failed to get ethernet interface or IP\n"); + FILE_LOG(logERROR) << mess; } else{ strcpy(eth,temp.c_str()); @@ -761,9 +763,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ strcpy(eth,""); ret = FAIL; } - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << eth; receiverBase->setEthernetInterface(eth); - cout << eth << endl; //get mac address from ethernet interface if (ret != FAIL) @@ -773,11 +773,10 @@ int slsReceiverTCPIPInterface::setup_udp(){ if ((temp=="00:00:00:00:00:00") || (ret == FAIL)){ ret = FAIL; strcpy(mess,"failed to get mac adddress to listen to\n"); - cprintf(RED,"%s\n",mess); } else{ strcpy(retval,temp.c_str()); - cout<<"mac:"<differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + FILE_LOG(logERROR) << mess; socket->SendDataOnly(mess,sizeof(mess)); } socket->SendDataOnly(retval,MAX_STR_LENGTH); @@ -840,7 +839,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -886,7 +885,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -916,7 +915,7 @@ int slsReceiverTCPIPInterface::get_status(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -946,7 +945,7 @@ int slsReceiverTCPIPInterface::get_frames_caught(){ }else retval=receiverBase->getTotalFramesCaught(); #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -978,7 +977,7 @@ int slsReceiverTCPIPInterface::get_frame_index(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1019,7 +1018,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1087,7 +1086,7 @@ int slsReceiverTCPIPInterface::set_short_frame() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1267,7 +1266,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1448,7 +1447,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1602,7 +1601,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1864,7 +1863,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1939,7 +1938,7 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -1995,7 +1994,7 @@ int slsReceiverTCPIPInterface::enable_file_write(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2023,7 +2022,7 @@ int slsReceiverTCPIPInterface::get_id(){ #endif if(socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2066,7 +2065,7 @@ int slsReceiverTCPIPInterface::start_readout(){ #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2140,7 +2139,7 @@ int slsReceiverTCPIPInterface::set_timer() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2211,7 +2210,7 @@ int slsReceiverTCPIPInterface::enable_compression() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2272,7 +2271,7 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2364,7 +2363,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2427,7 +2426,7 @@ int slsReceiverTCPIPInterface::enable_overwrite() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } @@ -2492,7 +2491,7 @@ int slsReceiverTCPIPInterface::enable_tengiga() { #endif if(ret==OK && socket->differentClients){ - cout << "Force update" << endl; + FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; } From 4c85a27f10a207a21cfd5fdb04d468c4170882eb Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 29 Oct 2015 17:34:19 +0100 Subject: [PATCH 163/222] done --- .../src/UDPBaseImplementation.cpp | 2 +- .../src/UDPStandardImplementation.cpp | 42 ++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index eaac8c8e97..6062085213 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -299,7 +299,7 @@ void UDPBaseImplementation::setEthernetInterface(const char* c){ FILE_LOG(logDEBUG) << __AT__ << " starting"; strcpy(eth, c); - FILE_LOG(logINFO) << "Ethernet Interface:" << eth; + FILE_LOG(logINFO) << "Ethernet Interface: " << eth; } diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 346d6db9f3..cf8779e758 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -763,7 +763,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - FILE_LOG(logINFO) << "Starting Receiver"; + cout << "Starting Receiver" << endl; //RESET @@ -849,8 +849,8 @@ int UDPStandardImplementation::startReceiver(char *c){ for(int i=0; i < numberofWriterThreads; i++) sem_post(&writerSemaphore[i]); //usleep(5000000); - FILE_LOG(logINFO) << "Receiver Started"; - FILE_LOG(logINFO) << "Status:" << runStatusType(status); + cout << "Receiver Started" << endl; + cout << "Status:" << runStatusType(status) << endl; return OK; } @@ -863,7 +863,7 @@ int UDPStandardImplementation::startReceiver(char *c){ void UDPStandardImplementation::stopReceiver(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - FILE_LOG(logINFO) << "Stopping Receiver"; + cout << "Stopping Receiver" << endl; //set status to transmitting startReadout(); @@ -882,8 +882,8 @@ void UDPStandardImplementation::stopReceiver(){ status = IDLE; pthread_mutex_unlock(&(statusMutex)); - FILE_LOG(logINFO) << "Receiver Stopped"; - FILE_LOG(logINFO) << "Status:" << runStatusType(status); + cout << "Receiver Stopped" << endl; + cout << "Status:" << runStatusType(status) << endl; cout << endl; } @@ -931,7 +931,7 @@ void UDPStandardImplementation::startReadout(){ pthread_mutex_lock(&statusMutex); status = TRANSMITTING; pthread_mutex_unlock(&statusMutex); - FILE_LOG(logINFO) << "Status: Transmitting"; + cout << "Status: Transmitting" << endl; } //shut down udp sockets and make listeners push dummy (end) packets for writers @@ -1025,12 +1025,12 @@ void UDPStandardImplementation::closeFile(int i){ if(myFile[i]->Write()) //->Write(tall->GetName(),TObject::kOverwrite); - FILE_LOG(logINFO) << "Thread " << i <<": wrote frames to file"; + cout << "Thread " << i <<": wrote frames to file" << endl; else - FILE_LOG(logINFO) << "Thread " << i << ": could not write frames to file"; + cout << "Thread " << i << ": could not write frames to file" << endl; }else - FILE_LOG(logINFO) << "Thread " << i << ": could not write frames to file: No file or No Tree"; + cout << "Thread " << i << ": could not write frames to file: No file or No Tree" << endl; //close file if(myTree[i] && myFile[i]) myFile[i] = myTree[i]->GetCurrentFile(); @@ -1145,8 +1145,8 @@ int UDPStandardImplementation::createWriterThreads(bool destroy){ while(!threadStarted); FILE_LOG(logDEBUG) << "." << flush; } -#ifdef VERBOSE - FILE_LOG(logINFO) << "\nWriter thread(s) created successfully."; +#ifdef DEBUG + cout << "\nWriter thread(s) created successfully" << endl; #endif } @@ -1219,7 +1219,7 @@ int UDPStandardImplementation::createUDPSockets(){ } //normal socket else{ - FILE_LOG(logINFO) << "eth:" << eth << endl; + FILE_LOG(logINFO) << "Ethernet Interface:" << eth; for(int i=0;igetErrorStatus(); if(!iret){ - FILE_LOG(logINFO) << "UDP port opened at port " << port[i]; + cout << "UDP port opened at port " << port[i] << endl; }else{ FILE_LOG(logERROR) << "Could not create UDP socket on port " << port[i] << " error: " << iret; shutDownUDPSockets(); @@ -1238,7 +1238,7 @@ int UDPStandardImplementation::createUDPSockets(){ } FILE_LOG(logDEBUG) << "UDP socket(s) created successfully."; - FILE_LOG(logINFO) << "Listener Ready ..."; + cout << "Listener Ready ..." << endl; return OK; } @@ -1287,7 +1287,7 @@ int UDPStandardImplementation::setupWriter(){ } FILE_LOG(logDEBUG) << "Successfully created file(s)"; - FILE_LOG(logINFO) << "Writer Ready ..."; + cout << "Writer Ready ..." << endl; return fileCreateSuccess; } @@ -1338,9 +1338,9 @@ int UDPStandardImplementation::createNewFile(){ //Print packet loss and filenames if(!packetsCaught){ previousFrameNumber = -1; - FILE_LOG(logINFO) << "File: " << completeFileName; + cout << "File: " << completeFileName << endl; }else{ - FILE_LOG(logINFO) << completeFileName + cout << completeFileName << "\tPacket Loss: " << setw(4)< Date: Thu, 29 Oct 2015 17:38:31 +0100 Subject: [PATCH 164/222] done --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index cf8779e758..a55c3098a8 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -850,7 +850,7 @@ int UDPStandardImplementation::startReceiver(char *c){ //usleep(5000000); cout << "Receiver Started" << endl; - cout << "Status:" << runStatusType(status) << endl; + cout << "Status: " << runStatusType(status) << endl; return OK; } @@ -883,7 +883,7 @@ void UDPStandardImplementation::stopReceiver(){ pthread_mutex_unlock(&(statusMutex)); cout << "Receiver Stopped" << endl; - cout << "Status:" << runStatusType(status) << endl; + cout << "Status: " << runStatusType(status) << endl; cout << endl; } @@ -1579,7 +1579,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG1) << __AT__ << " called"; #ifdef DEBUG4 - cprintf(BLUE,"Listening_Thread %d: Stop Listening\nStatus:%s\n", ithread, runStatusType(status).c_str()); + cprintf(BLUE,"Listening_Thread %d: Stop Listening\nStatus: %s\n", ithread, runStatusType(status).c_str()); #endif //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) From 1c9d01ea1c01a72ee7b6e399d0bdb3f0203eb2e1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 29 Oct 2015 17:39:47 +0100 Subject: [PATCH 165/222] done --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index a55c3098a8..fffb38e874 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -884,7 +884,7 @@ void UDPStandardImplementation::stopReceiver(){ cout << "Receiver Stopped" << endl; cout << "Status: " << runStatusType(status) << endl; - cout << endl; + cout << endl << endl; } From 5c5e2edbf96d814d5740d441e73399aee8729260 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 29 Oct 2015 17:45:24 +0100 Subject: [PATCH 166/222] done --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index fffb38e874..fee4a16c01 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2281,10 +2281,10 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //statistics cprintf(GREEN, "Status: Run Finished\n"); - if((long long int)(totalPacketsCaught/packetsPerFrame) == 0){ + if(numTotMissingPackets){ cprintf(RED, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(RED, "Total Packets Caught: %lld\n",(long long int)totalPacketsCaught); - cprintf(RED, "Total Frames Caught: 0\n"); + cprintf(RED, "Total Frames Caught: %lld\n",(long long int)(totalPacketsCaught/packetsPerFrame)); }else{ cprintf(GREEN, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(GREEN, "Total Packets Caught:%lld\n", (long long int)totalPacketsCaught); From f77b78b5c6a3c8615781641978ee75a9df7057cf Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 2 Nov 2015 15:55:15 +0100 Subject: [PATCH 167/222] changes to compile server in defs file --- slsReceiverSoftware/include/sls_receiver_defs.h | 5 ++++- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 04f647f0a4..07566ab84e 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -8,7 +8,9 @@ #endif #include +#ifdef __cplusplus #include +#endif #include "ansi.h" @@ -112,7 +114,7 @@ class slsReceiverDefs { RUNNING /**< acquisition running, no data in memory */ }; - +#ifdef __cplusplus /** returns string from enabled/disabled \param b true or false \returns string enabled, disabled @@ -172,6 +174,7 @@ class slsReceiverDefs { default: return std::string("idle"); \ }}; +#endif #ifdef __cplusplus protected: diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index fee4a16c01..2bafb96b11 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -43,10 +43,11 @@ UDPStandardImplementation::UDPStandardImplementation(){ //to increase socket receiver buffer size and max length of input queue by changing kernel settings if(myDetectorType == EIGER); - else if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")) + else if(system("echo $((100*1024*1024)) > /proc/sys/net/core/rmem_max")){ FILE_LOG(logDEBUG) << "Warning: No root permission to change socket receiver buffer size in file /proc/sys/net/core/rmem_max"; - else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) + }else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")){ FILE_LOG(logDEBUG) << "Warning: No root permission to change max length of input queue in file /proc/sys/net/core/netdev_max_backlog"; + } /** permanent setting by heiner net.core.rmem_max = 104857600 # 100MiB net.core.netdev_max_backlog = 250000 From e9f51e2ef59dd2b231c0a38952c4b30adf0c6349 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 2 Nov 2015 17:33:10 +0100 Subject: [PATCH 168/222] put in the changes by Andrea to make it as static and remove as many destructors bugs --- .../include/slsReceiverTCPIPInterface.h | 3 -- .../include/slsReceiverUsers.h | 4 +- .../src/UDPStandardImplementation.cpp | 9 ++-- slsReceiverSoftware/src/main.cpp | 38 +++++++++-------- slsReceiverSoftware/src/slsReceiver.cpp | 6 ++- .../src/slsReceiverTCPIPInterface.cpp | 42 ++----------------- slsReceiverSoftware/src/slsReceiverUsers.cpp | 20 ++++----- 7 files changed, 46 insertions(+), 76 deletions(-) diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index 83d9416aac..49e5134f15 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -54,9 +54,6 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** Close all threaded Files and exit */ void closeFile(int p); - /** Static function to call closeFile */ - static void staticCloseFile(int p); - /** gets version */ int64_t getReceiverVersion(); diff --git a/slsReceiverSoftware/include/slsReceiverUsers.h b/slsReceiverSoftware/include/slsReceiverUsers.h index 50d6f38feb..eea4035601 100644 --- a/slsReceiverSoftware/include/slsReceiverUsers.h +++ b/slsReceiverSoftware/include/slsReceiverUsers.h @@ -83,8 +83,8 @@ class slsReceiverUsers { void registerCallBackRawDataReady(void (*func)(int framenumber, char* datapointer, int datasize, FILE* filedescriptor, char* guidatapointer, void*),void *arg); - // made static to close thread files with ctrl+c - static slsReceiver* receiver; + //receiver object + slsReceiver* receiver; }; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 2bafb96b11..6149f0c102 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -60,7 +60,7 @@ UDPStandardImplementation::UDPStandardImplementation(){ UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG1) << __AT__ << " called"; - + closeFile(); deleteMembers(); } @@ -1184,9 +1184,9 @@ void UDPStandardImplementation::setThreadPriorities(){ if (pthread_setschedparam(pthread_self(),5 , &tcp_param) == EPERM) rights = false; - if(!rights) + if(!rights){ FILE_LOG(logWARNING) << "No root permission to prioritize threads."; - + } } @@ -1256,8 +1256,9 @@ int UDPStandardImplementation::setupWriter(){ if(cbAction < DO_EVERYTHING){ FILE_LOG(logINFO) << "Call back activated. Data saving must be taken care of by user in call back."; - if (rawDataReadyCallBack) + if (rawDataReadyCallBack){ FILE_LOG(logINFO) << "Data Write has been defined externally"; + } }else if(!fileWriteEnable) FILE_LOG(logINFO) << "Data will not be saved"; diff --git a/slsReceiverSoftware/src/main.cpp b/slsReceiverSoftware/src/main.cpp index 53a8bd1107..1dc9a65c63 100644 --- a/slsReceiverSoftware/src/main.cpp +++ b/slsReceiverSoftware/src/main.cpp @@ -6,25 +6,38 @@ #include #include +#include //SIGINT #include "utilities.h" #include "logger.h" - using namespace std; +slsReceiverUsers *receiver; + +void deleteReceiver(slsReceiverUsers* r){ + if(r){delete r;r=0;} +} + +void closeFile(int p){ + deleteReceiver(receiver); +} int main(int argc, char *argv[]) { - int ret = slsReceiverDefs::OK; - slsReceiverUsers *user = new slsReceiverUsers(argc, argv, ret); + //Catch signal SIGINT to close files properly + signal(SIGINT,closeFile); + + int ret = slsReceiverDefs::OK; + receiver = new slsReceiverUsers(argc, argv, ret); - if(ret==slsReceiverDefs::FAIL) + if(ret==slsReceiverDefs::FAIL){ + deleteReceiver(receiver); return -1; + } //register callbacks - /** callback arguments are filepath @@ -37,10 +50,8 @@ int main(int argc, char *argv[]) { 1 callback writes file, we have to open, close it 2 we open, close, write file, callback does not do anything - registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); */ - //receiver->registerCallBackStartAcquisition(func,arg); @@ -49,32 +60,25 @@ int main(int argc, char *argv[]) { total farmes caught registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); */ - - //receiver->registerCallBackAcquisitionFinished(func,arg); - /** args to raw data ready callback are framenum datapointer file descriptor guidatapointer (NULL, no data required) - NEVER DELETE THE DATA POINTER REMEMBER THAT THE CALLBACK IS BLOCKING - registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg); - */ - //receiver->registerCallBackRawDataReady(func,arg); //start tcp server thread - if(user->start() == slsReceiverDefs::OK){ + if(receiver->start() == slsReceiverDefs::OK){ FILE_LOG(logDEBUG1) << "DONE!" << endl; string str; cin>>str; @@ -82,10 +86,10 @@ int main(int argc, char *argv[]) { while(str.find("exit") == string::npos) cin>>str; //stop tcp server thread, stop udp socket - user->stop(); + receiver->stop(); } - delete user; + deleteReceiver(receiver); cout << "Goodbye!" << endl; return 0; } diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index 5783e601c7..f23da65c53 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -29,6 +29,9 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ * @return */ + udp_interface = NULL; + tcpipInterface = NULL; + //creating base receiver map configuration_map; int tcpip_port_no = 1954; @@ -55,7 +58,8 @@ slsReceiver::slsReceiver(int argc, char *argv[], int &success){ }; /* getopt_long stores the option index here. */ int option_index = 0; - int c; + int c=0; + optind = 1; while ( c != -1 ){ c = getopt_long (argc, argv, "mbfhtr", long_options, &option_index); diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index d7e562f762..24ba62d992 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -9,10 +9,7 @@ #include "slsReceiverUsers.h" #include "slsReceiver.h" - -#include //SIGINT #include //EXIT - #include #include #include @@ -27,9 +24,8 @@ using namespace std; slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { - closeFile(0); + stop(); if(socket) {delete socket; socket=NULL;} - if(receiverBase) {delete receiverBase; receiverBase=NULL;} } slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* rbase, int pn, bool bot): @@ -71,9 +67,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* #ifdef VERBOSE cout << "Function table assigned." << endl; #endif - - //Catch signal SIGINT to close files properly - signal(SIGINT,staticCloseFile); } } @@ -139,34 +132,13 @@ int slsReceiverTCPIPInterface::start(){ void slsReceiverTCPIPInterface::stop(){ - - cout << "Shutting down UDP Socket" << endl; - if(receiverBase) - receiverBase->shutDownUDPSockets(); - - cout << "Closing Files... " << endl; - receiverBase->closeFile(); - - - cout<<"Shutting down TCP Socket and TCP thread"<shutDownUDPSockets(); - - cout << "Closing Files... " << endl; - receiverBase->closeFile(); - } - - killTCPServerThread = 1; - socket->ShutDownSocket(); - socket->exitServer(); + if(socket) socket->ShutDownSocket(); cout<<"Socket closed"<closeFile(p); + receiverBase->closeFile(); } diff --git a/slsReceiverSoftware/src/slsReceiverUsers.cpp b/slsReceiverSoftware/src/slsReceiverUsers.cpp index c27f1efc2a..8a1d17f43a 100644 --- a/slsReceiverSoftware/src/slsReceiverUsers.cpp +++ b/slsReceiverSoftware/src/slsReceiverUsers.cpp @@ -1,47 +1,45 @@ #include "slsReceiverUsers.h" #include "slsReceiver.h" -slsReceiver* slsReceiverUsers::receiver(NULL); - slsReceiverUsers::slsReceiverUsers(int argc, char *argv[], int &success) { - slsReceiverUsers::receiver=new slsReceiver(argc, argv, success); + receiver=new slsReceiver(argc, argv, success); } slsReceiverUsers::~slsReceiverUsers() { - delete slsReceiverUsers::receiver; + delete receiver; } int slsReceiverUsers::start() { - return slsReceiverUsers::receiver->start(); + return receiver->start(); } void slsReceiverUsers::stop() { - slsReceiverUsers::receiver->stop(); + receiver->stop(); } void slsReceiverUsers::closeFile(int p) { - slsReceiverUsers::receiver->closeFile(p); + receiver->closeFile(p); } int64_t slsReceiverUsers::getReceiverVersion(){ - return slsReceiverUsers::receiver->getReceiverVersion(); + return receiver->getReceiverVersion(); } void slsReceiverUsers::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ - slsReceiverUsers::receiver->registerCallBackStartAcquisition(func,arg); + receiver->registerCallBackStartAcquisition(func,arg); } void slsReceiverUsers::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ - slsReceiverUsers::receiver->registerCallBackAcquisitionFinished(func,arg); + receiver->registerCallBackAcquisitionFinished(func,arg); } void slsReceiverUsers::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ - slsReceiverUsers::receiver->registerCallBackRawDataReady(func,arg); + receiver->registerCallBackRawDataReady(func,arg); } From 667c1c0304aa284f432274405e8470ac2eb2bb9a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 5 Nov 2015 12:05:31 +0100 Subject: [PATCH 169/222] some small changes --- .../src/UDPStandardImplementation.cpp | 115 ++++++++++-------- .../src/slsReceiverTCPIPInterface.cpp | 68 +++++------ 2 files changed, 98 insertions(+), 85 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 6149f0c102..86e533efac 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -31,7 +31,7 @@ using namespace std; *************************************************************************/ UDPStandardImplementation::UDPStandardImplementation(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; initializeMembers(); @@ -59,7 +59,7 @@ UDPStandardImplementation::UDPStandardImplementation(){ } UDPStandardImplementation::~UDPStandardImplementation(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; closeFile(); deleteMembers(); } @@ -73,7 +73,7 @@ UDPStandardImplementation::~UDPStandardImplementation(){ /***initial parameters***/ void UDPStandardImplementation::deleteMembers(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; FILE_LOG(logDEBUG) << "Info: Deleting member pointers"; shutDownUDPSockets(); @@ -95,7 +95,7 @@ void UDPStandardImplementation::deleteMembers(){ } void UDPStandardImplementation::deleteFilter(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; moenchCommonModeSubtraction = NULL; for(int i=0; i config_map){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; map::const_iterator pos; pos = config_map.find("mode"); @@ -375,7 +375,7 @@ void UDPStandardImplementation::configure(map config_map){ /***file parameters***/ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; if(myDetectorType != EIGER){ cout << "Info: Setting up Data Compression Enable to " << stringEnable(b); @@ -419,7 +419,7 @@ int UDPStandardImplementation::setDataCompressionEnable(const bool b){ /***acquisition parameters***/ void UDPStandardImplementation::setShortFrameEnable(const int i){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; shortFrameEnable = i; @@ -456,7 +456,7 @@ void UDPStandardImplementation::setShortFrameEnable(const int i){ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FrameToGuiFrequency = i; if(setupFifoStructure() == FAIL) @@ -469,7 +469,7 @@ int UDPStandardImplementation::setFrameToGuiFrequency(const uint32_t i){ int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; acquisitionPeriod = i; if(setupFifoStructure() == FAIL) @@ -482,7 +482,7 @@ int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){ } int UDPStandardImplementation::setDynamicRange(const uint32_t i){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; uint32_t oldDynamicRange = dynamicRange; @@ -536,7 +536,7 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ int UDPStandardImplementation::setTenGigaEnable(const bool b){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << "Info: Setting Ten Giga to " << stringEnable(b); bool oldTenGigaEnable = tengigaEnable; @@ -618,7 +618,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ /***initial functions***/ int UDPStandardImplementation::setDetectorType(const detectorType d){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << "Setting receiver type"; @@ -751,7 +751,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ /***acquisition functions***/ void UDPStandardImplementation::resetAcquisitionCount(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; totalPacketsCaught = 0; acqStarted = false; @@ -762,7 +762,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; cout << "Starting Receiver" << endl; @@ -862,7 +862,7 @@ int UDPStandardImplementation::startReceiver(char *c){ * Post: udp sockets shut down, status is idle, semaphores destroyed * */ void UDPStandardImplementation::stopReceiver(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; cout << "Stopping Receiver" << endl; @@ -893,7 +893,7 @@ void UDPStandardImplementation::stopReceiver(){ int UDPStandardImplementation::shutDownUDPSockets(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << "Info: Shutting down UDP Socket(s)"; @@ -915,7 +915,7 @@ int UDPStandardImplementation::shutDownUDPSockets(){ * Post:udp sockets closed, status is transmitting * */ void UDPStandardImplementation::startReadout(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << "Info: Transmitting last data"; @@ -943,7 +943,7 @@ void UDPStandardImplementation::startReadout(){ void UDPStandardImplementation::readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //point to gui data, to let writer thread know that gui is back for data if (guiData == NULL){ @@ -993,7 +993,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint64_t &startAcq void UDPStandardImplementation::closeFile(int i){ - FILE_LOG(logDEBUG1) << __AT__ << " called for " << i ; + FILE_LOG(logDEBUG) << __AT__ << " called for " << i ; //normal if(!dataCompressionEnable){ @@ -1054,7 +1054,7 @@ void UDPStandardImplementation::closeFile(int i){ int UDPStandardImplementation::createListeningThreads(bool destroy){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; //reset masks killAllListeningThreads = false; @@ -1104,7 +1104,7 @@ int UDPStandardImplementation::createListeningThreads(bool destroy){ int UDPStandardImplementation::createWriterThreads(bool destroy){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; //reset masks killAllWritingThreads = false; @@ -1157,7 +1157,7 @@ int UDPStandardImplementation::createWriterThreads(bool destroy){ void UDPStandardImplementation::setThreadPriorities(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; struct sched_param tcp_param, listen_param, write_param; bool rights = true; @@ -1193,7 +1193,7 @@ void UDPStandardImplementation::setThreadPriorities(){ int UDPStandardImplementation::createUDPSockets(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //switching ports if bottom enabled uint32_t port[2]; @@ -1247,7 +1247,7 @@ int UDPStandardImplementation::createUDPSockets(){ int UDPStandardImplementation::setupWriter(){ - FILE_LOG(logDEBUG1) << __AT__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; //acquisition start call back returns enable write cbAction = DO_EVERYTHING; @@ -1297,7 +1297,7 @@ int UDPStandardImplementation::setupWriter(){ int UDPStandardImplementation::createNewFile(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; int index = 0; if(packetsCaught) @@ -1370,7 +1370,7 @@ int UDPStandardImplementation::createNewFile(){ int UDPStandardImplementation::createCompressionFile(int ithread, int iframe){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; #ifdef MYROOT1 char temp[MAX_STR_LENGTH]; @@ -1400,7 +1400,7 @@ int UDPStandardImplementation::createCompressionFile(int ithread, int iframe){ void* UDPStandardImplementation::startListeningThread(void* this_pointer){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startListening(); return this_pointer; } @@ -1408,7 +1408,7 @@ void* UDPStandardImplementation::startListeningThread(void* this_pointer){ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startWriting(); return this_pointer; } @@ -1419,7 +1419,7 @@ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ void UDPStandardImplementation::startListening(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //set current thread value index int ithread = currentThreadIndex; @@ -1433,16 +1433,18 @@ void UDPStandardImplementation::startListening(){ //split frames int carryonBufferSize; //from previous buffer to keep frames together in a buffer char* tempBuffer = NULL; //temporary buffer to store split frames - if(myDetectorType != EIGER){ - listenSize = bufferSize * numberofJobsPerBuffer; //listen to more than 1 packet - tempBuffer = new char[onePacketSize * (packetsPerFrame - 1)]; //store maximum of 1 packets less in a frame - } + /* outer loop - loops once for each acquisition */ //infinite loop, exited only to change dynamic range, 10G parameters etc (then recreated again) while(true){ //reset parameters before acquisition carryonBufferSize = 0; + if(myDetectorType != EIGER){ + listenSize = bufferSize * numberofJobsPerBuffer; //listen to more than 1 packet + if(tempBuffer!=NULL){delete []tempBuffer;tempBuffer=NULL;} + tempBuffer = new char[onePacketSize * (packetsPerFrame - 1)]; //store maximum of 1 packets less in a frame + } /* inner loop - loop for each buffer */ //until mask unset (udp sockets shut down by client) @@ -1512,7 +1514,7 @@ void UDPStandardImplementation::startListening(){ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, int cSize, char* temp){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //listen to UDP packets memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); @@ -1529,6 +1531,17 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); } +#ifdef MANUALDEBUG + eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); + eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + cprintf(GREEN,"thread:%d subframenum:%d oldpacketnum:%d new pnum:%d\n", + ithread, + (*( (unsigned int*) header->subFameNumber)), + (*( (uint8_t*) header->dynamicRange)), + (*( (uint16_t*) footer->packetNumber))); +#endif + + #ifdef DEBUG cprintf(BLUE, "Listening_Thread %d : Received bytes: %d. Expected bytes: %d\n", ithread, receivedSize, bufferSize * numberofJobsPerBuffer-cSize); #endif @@ -1541,7 +1554,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in void UDPStandardImplementation::startFrameIndices(int ithread){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //determine startFrameIndex switch(myDetectorType){ @@ -1578,7 +1591,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; #ifdef DEBUG4 cprintf(BLUE,"Listening_Thread %d: Stop Listening\nStatus: %s\n", ithread, runStatusType(status).c_str()); @@ -1657,7 +1670,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSize, char* temp){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; int lastPacketOffset; //the offset of the last packet uint32_t lastFrameHeader; //frame number of last packet in buffer @@ -1741,7 +1754,7 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz void UDPStandardImplementation::startWriting(){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //set current thread value index int ithread = currentThreadIndex; @@ -1762,7 +1775,7 @@ void UDPStandardImplementation::startWriting(){ void UDPStandardImplementation::processWritingBuffer(int ithread){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //variable definitions char* wbuf[numberofListeningThreads]; //buffer popped from FIFO @@ -1829,7 +1842,7 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //variable definitions char* packetBuffer[numberofListeningThreads]; //buffer popped from FIFO @@ -2133,7 +2146,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; //in case they are not closed already closeFile(); @@ -2190,7 +2203,7 @@ void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread) bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]){ - FILE_LOG(logDEBUG1) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __AT__ << " called"; bool endofAcquisition = true; for(int i=0; ithisClientIP,"none1"); strcpy(mess,"dummy message"); function_table(); -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "Function table assigned." << endl; #endif } @@ -124,7 +124,7 @@ int slsReceiverTCPIPInterface::start(){ cout << "Could not create TCP Server thread" << endl; return FAIL; } - //#ifdef VERBOSE + //#ifdef VERYVERBOSE FILE_LOG(logDEBUG) << "TCP Server thread created successfully." << endl; //#endif return OK; @@ -160,7 +160,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){ int v=OK; while(1) { -#ifdef VERBOSE +#ifdef VERYVERBOSE cout<< endl; #endif #ifdef VERY_VERBOSE @@ -254,7 +254,7 @@ int slsReceiverTCPIPInterface::function_table(){ flist[F_ENABLE_RECEIVER_TEN_GIGA] = &slsReceiverTCPIPInterface::enable_tengiga; -#ifdef VERBOSE +#ifdef VERYVERBOSE for (int i=0;iReceiveDataOnly(&fnum,sizeof(fnum)); if (n <= 0) { -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "ERROR reading from socket " << n << ", " << fnum << endl; #endif return FAIL; } -#ifdef VERBOSE +#ifdef VERYVERBOSE else cout << "size of data received " << n <> GOTTHARD_SHORT_FRAME_INDEX_OFFSET); -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "index:" << hex << index << endl; #endif }else{ @@ -1336,7 +1336,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ 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 VERBOSE +#ifdef VERYVERBOSE cout << "index1:" << hex << index << endl; cout << "index2:" << hex << index << endl; #endif @@ -1398,7 +1398,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(frameIndex!=-1){ cout << "fName:" << fName << endl; cout << "acquisitionIndex:" << acquisitionIndex << endl; @@ -1493,7 +1493,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ /**send garbage with -1 index to try again*/ if (raw == NULL){ startAcquisitionIndex = -1; -#ifdef VERBOSE +#ifdef VERYVERBOSE cout<<"data not ready for gui yet"<> PROPIX_FRAME_INDEX_OFFSET); -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "index1:" << hex << index << endl; cout << "index2:" << hex << index << endl; #endif @@ -1552,7 +1552,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(frameIndex!=-1){ cout << "fName:" << fName << endl; cout << "acquisitionIndex:" << acquisitionIndex << endl; @@ -1652,7 +1652,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ /**send garbage with -1 index to try again*/ else if(!receiverBase->getFramesCaught()){ startAcquisitionIndex=-1; -#ifdef VERBOSE +#ifdef VERYVERBOSE cout<<"haven't caught any frame yet"<subframenum); } -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "index:" << dec << index << endl; cout << "subframenumber:" << dec << subframenumber << endl; #endif @@ -1813,7 +1813,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(frameIndex!=-1){ cout << "fName:" << fName << endl; cout << "acquisitionIndex:" << acquisitionIndex << endl; @@ -2093,7 +2093,7 @@ int slsReceiverTCPIPInterface::set_timer() { ret = FAIL; } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL){ if(index[0] == FRAME_PERIOD) cout << "acquisition period:" << retval << endl; @@ -2228,7 +2228,7 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { } } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL) cout << "hostname:" << retval << endl; else @@ -2320,7 +2320,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL) cout << "dynamic range" << dr << endl; else @@ -2383,7 +2383,7 @@ int slsReceiverTCPIPInterface::enable_overwrite() { ret = FAIL; } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL) cout << "overwrite:" << retval << endl; else @@ -2448,7 +2448,7 @@ int slsReceiverTCPIPInterface::enable_tengiga() { tenGigaEnable = retval; } } -#ifdef VERBOSE +#ifdef VERYVERBOSE if(ret!=FAIL) cout << "10Gbe:" << val << endl; else @@ -2749,7 +2749,7 @@ int slsReceiverTCPIPInterface::exec_command() { // execute action if the arguments correctly arrived if (ret==OK) { -#ifdef VERBOSE +#ifdef VERYVERBOSE cout << "executing command " << cmd << endl; #endif if (lockStatus==0 || socket->differentClients==0) From 98ab99c53f744a44c7a6417c6f7c5f1f073ef441 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 6 Nov 2015 11:23:50 +0100 Subject: [PATCH 170/222] fixed a bug of both threads not popping out(due to wrong frame packet) and end of acquisition wrongly inferred --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 86e533efac..12a176777c 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2244,6 +2244,11 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w } } } + //when both are not popped but curretn frame number is being processed + else{ + if(nP[i] != dummyPacketValue) + endofAcquisition = false; + } } return endofAcquisition; From 455c9c5c8084a5159bfdeac345bd8262d7ef5a50 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 9 Nov 2015 17:16:24 +0100 Subject: [PATCH 171/222] some changes for memory leak --- .../src/UDPStandardImplementation.cpp | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 12a176777c..b12826f168 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1867,8 +1867,6 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ volatile uint32_t currentPacketNumber[numberofListeningThreads];//current packet number volatile int numberofMissingPackets[numberofListeningThreads]; // number of missing packets in this buffer - eiger_packet_header_t* blankframe_header; - for(int i=0; imissingPacket) = missingPacketValue; //set each value inside blank frame to 0xff for(int j=0;j<(oneDataSize);++j){ - blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; + unsigned char* blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; *(blankframe_data) = 0xFF; } } @@ -1945,12 +1947,11 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //not full frame else if(!fullframe[i]){ - eiger_packet_footer_t* packetBuffer_footer = (eiger_packet_footer_t*)(packetBuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); - - //update frame number and packet number if(numPackets[i] != dummyPacketValue){ + eiger_packet_footer_t* packetBuffer_footer = (eiger_packet_footer_t*)(packetBuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + if(!((uint32_t)(*( (uint64_t*) packetBuffer_footer)))){ FILE_LOG(logERROR) << "Fifo "<< i << ": Frame Number is zero from firmware. popready[" << i << "]:" << popReady[i]; popReady[i]=true; @@ -1972,10 +1973,10 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ if(numPackets[i] == dummyPacketValue) cprintf(GREEN, "Fifo %d: Dummy packet: Adding missing packets to the last frame\n", i); else{ - cprintf(GREEN,"Fifo %d: fnum %d, (FW_fnum %d), pnum %d, last_pnum %d, pnum_offset %d\n" + cprintf(GREEN,"Fifo %d: fnum %d, fnum_thread %d, pnum %d, last_pnum %d, pnum_offset %d\n" "Fifo %d: Add missing packets to the right fnum %d\n", - i,presentFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer)), - *( (uint16_t*) packetBuffer_footer->packetNumber),lastPacketNumber[i],frameBufferoffset[i], + i,presentFrameNumber[i],threadFrameNumber[i], + currentPacketNumber[i],lastPacketNumber[i],frameBufferoffset[i], i,presentFrameNumber); } #endif @@ -1991,7 +1992,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ frameBuffer[frameBufferoffset[i]] = blankframe[blankoffset]; eiger_packet_header_t* frameBuffer_header = (eiger_packet_header_t*) frameBuffer[frameBufferoffset[i]]; if (*( (uint16_t*) frameBuffer_header->missingPacket)!= missingPacketValue){ - blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; + eiger_packet_header_t* blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; cprintf(BG_RED, "Fifo %d: Missing Packet Error: Adding blank packets mismatch " "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x, missingpacket_blank 0x%x\n", i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], @@ -2029,9 +2030,8 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ else{ if(currentPacketNumber[i] != (uint32_t)(frameBufferoffset[i]-(i*packetsPerFrame/numberofListeningThreads))+1){ cprintf(BG_RED, "Fifo %d: Correct Packet Offset Error:Adding current packet mismatch " - "pnum_offset %d,pnum %d fnum_thread %d, (FW_fnum %d)\n", - i,frameBufferoffset[i],currentPacketNumber[i], - threadFrameNumber[i],(uint32_t)(*( (uint64_t*) packetBuffer_footer))); + "pnum_offset %d,pnum %d fnum_thread %d\n", + i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i]); exit(-1); } @@ -2066,9 +2066,9 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ currentFrameNumber = presentFrameNumber; numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -#ifdef FNUM_DEBUG - cprintf(GREEN,"**fnum:%d**\n",currframenum); -#endif +//#ifdef FNUM_DEBUG + cprintf(GREEN,"**fnum:%d**\n",currentFrameNumber); +//#endif #ifdef MISSINGP_DEBUG if(numberofMissingPackets[0]) cprintf(RED, "Fifo 0 missing packets %d for fnum %d\n",numberofMissingPackets[0],currentPacketNumber); From 0627668090724e368ddc1889d4fd2f111df8c774 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 11 Nov 2015 15:08:50 +0100 Subject: [PATCH 172/222] some changes for memory leak --- .../include/UDPStandardImplementation.h | 5 +- slsReceiverSoftware/include/genericSocket.h | 32 ++-- .../src/UDPStandardImplementation.cpp | 163 ++++++++++++------ .../src/slsReceiverTCPIPInterface.cpp | 30 ++-- 4 files changed, 146 insertions(+), 84 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index d478f0e7aa..a1cad30e94 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -379,11 +379,10 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * @param wbuffer the buffer array that is popped from all the FIFOs * @param ready if that FIFO is allowed to pop (depends on if dummy buffer already popped/ waiting for other FIFO to finish a frame(eiger)) * @param nP number of packets in the buffer popped out - * @param toFree array of addresses to pop into fifoFree (eiger specific) - * @param toFreeOffset the number of addresses to free for each FIFO (eiger specific) + * @param fifoTempFree circular fifo to save addresses of packets adding upto a frame before pushing into fifofree (eiger specific) * @return true if end of acquisition else false */ - bool popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]); + bool popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],CircularFifo* fifoTempFree[]); /** * Called by processWritingBuffer and processWritingBufferPacketByPacket diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index de49d78602..b1b5e8f629 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -116,6 +116,11 @@ typedef struct // serverAddress = {0}; // clientAddress = {0}; // strcpy(hostname,host_ip_or_name); + + strcpy(lastClientIP,"none"); + strcpy(thisClientIP,"none1"); + strcpy(dummyClientIP,"dummy"); + struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n"; @@ -170,16 +175,16 @@ typedef struct nsent(0), total_sent(0) { - //memset(&serverAddress, 0, sizeof(sockaddr_in)); - // memset(&clientAddress, 0, sizeof(sockaddr_in)); - // serverAddress = {0}; - // clientAddress = {0}; -/* // you can specify an IP address: */ -/* */ +/* // you can specify an IP address: */ /* // or you can let it automatically select one: */ /* myaddr.sin_addr.s_addr = INADDR_ANY; */ + + strcpy(lastClientIP,"none"); + strcpy(thisClientIP,"none1"); + strcpy(dummyClientIP,"dummy"); + if(serverAddress.sin_port == htons(port_number)){ socketDescriptor = -10; return; @@ -592,6 +597,15 @@ typedef struct length-=nsent; total_sent+=nsent; } + + if (total_sent>0) + strcpy(thisClientIP,dummyClientIP); + + if (strcmp(lastClientIP,thisClientIP)) + differentClients=1; + else + differentClients=0; + break; case UDP: if (socketDescriptor<0) return -1; @@ -641,13 +655,7 @@ typedef struct #ifdef VERY_VERBOSE cout << "sent "<< total_sent << " Bytes" << endl; #endif - if (total_sent>0) - strcpy(thisClientIP,dummyClientIP); - if (strcmp(lastClientIP,thisClientIP)) - differentClients=1; - else - differentClients=0; return total_sent; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b12826f168..266f3e38cb 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -152,7 +152,7 @@ void UDPStandardImplementation::initializeMembers(){ previousFrameNumber = -1; acqStarted = false; measurementStarted = false; - for(int i = 0; i < numberofListeningThreads; ++i) + for(int i = 0; i < MAX_NUMBER_OF_LISTENING_THREADS; ++i) totalListeningFrameCount[i] = 0; packetsInFile = 0; numMissingPackets = 0; @@ -309,6 +309,7 @@ int UDPStandardImplementation::setupFifoStructure(){ return OK; + int count = 0; //set up fifo structure for(int i=0;iisEmpty()) + fifo[i]->pop(buffer[i]); + delete fifo[i]; + } if(mem0[i]) free(mem0[i]); //creating fifoFree[i] = new CircularFifo(fifoSize); fifo[i] = new CircularFifo(fifoSize); + //cout<<"buffersize:"<push(buffer[i]); -#ifdef DEBUG5 +//#ifdef DEBUG5 + + if(count==0 || count == 127998) cprintf(BLUE,"Info: %d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); -#endif +//#endif buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); + count++; } + cout<pop(buffer[ithread]); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif //udpsocket doesnt exist @@ -1489,8 +1504,12 @@ void UDPStandardImplementation::startListening(){ //push buffer to FIFO while(!fifo[ithread]->push(buffer[ithread])); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); + #endif }/*--end of loop for each buffer (inner loop)*/ @@ -1517,7 +1536,8 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in FILE_LOG(logDEBUG) << __AT__ << " called"; //listen to UDP packets - memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); + if(cSize) + memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); int receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, lSize + cSize); //throw away packets that is not one packet size, need to check status if socket is shut down @@ -1606,8 +1626,11 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ if(numbytes <= 0){ cprintf(BLUE,"Listening_Thread %d :End of Acquisition\n", ithread); while(!fifoFree[ithread]->push(buffer[ithread])); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); #endif } @@ -1621,19 +1644,31 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ cprintf(BLUE,"Listening_Thread %d: Last Buffer packet count:%d\n",ithread, numbytes/onePacketSize); #endif while(!fifo[ithread]->push(buffer[ithread])); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); #endif } //push dummy-end buffer into fifo for all writer threads for(int i=0; ipop(buffer[ithread]); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d: Popped Dummy from fifoFree %p\n", ithread,(void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d: Popped Dummy from fifoFree %p\n", ithread,(void*)(buffer[ithread])); +#endif //creating dummy-end buffer with pc=0xFFFF (*((uint32_t*)(buffer[ithread]))) = dummyPacketValue; while(!fifo[ithread]->push(buffer[ithread])); -#ifdef DEBUG5 - cprintf(BLUE,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); +#ifdef CFIFODEBUG + if(ithread == 0) + cprintf(CYAN,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); + else + cprintf(YELLOW,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); #endif } @@ -1852,8 +1887,9 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ int MAX_NUM_PACKETS = 1024; //highest 32 bit has 1024 number of packets uint32_t LAST_PACKET_VALUE; //last packet number - char* toFreePointers[MAX_NUM_PACKETS]; //pointers to free for each frame - int toFreePointersOffset[numberofListeningThreads]; //offset of pointers to free added for each thread + + CircularFifo* fifoTempFree[numberofListeningThreads];//ciruclar fifo to keep track of one frame packets to be freed and reused later + char* temp = NULL; char* frameBuffer[MAX_NUM_PACKETS]; //buffer offset created for a whole frame int frameBufferoffset[numberofListeningThreads]; //buffer offset created for a whole frame for both listening threads @@ -1868,34 +1904,42 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ volatile int numberofMissingPackets[numberofListeningThreads]; // number of missing packets in this buffer for(int i=0; iisEmpty()) + fifoTempFree[i]->pop(temp); + delete fifoTempFree[i]; + } + fifoTempFree[i] = new CircularFifo(MAX_NUM_PACKETS); } - presentFrameNumber = 0; - //blank frame - initializing with missing packet values - blankoffset = 0; for(uint32_t i=0; imissingPacket)==missingPacketValue) cprintf(RED,"Found missing packet at pnum %d\n",j); } } -#endif +//#endif //write and copy to gui handleWithoutDataCompression(ithread,frameBuffer,packetsPerFrame); //freeing - for(int j=0;jpush(toFreePointers[j])); -#ifdef DEBUG5 - cprintf(GREEN,"Fifo 0: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); -#endif - } - for(int j=(packetsPerFrame/numberofListeningThreads);jpush(toFreePointers[j])); -#ifdef DEBUG5 - cprintf(GREEN,"Fifo 1: Writing_Thread freed: pushed into fifofree %p\n",ithread, (void*)(toFreePointers[j])); + for(int i=0; iisEmpty()){ + fifoTempFree[i]->pop(temp); + fifoFree[i]->push(temp); + count++; +#ifdef CFIFODEBUG + if(i==0) + cprintf(CYAN,"Fifo %d: %d Writing_Thread freed: pushed into fifofree %p\n",i,count, (void*)(temp)); + else + cprintf(YELLOW,"Fifo %d: %d Writing_Thread freed: pushed into fifofree %p\n",i, count,(void*)(temp)); #endif + } } + + + #ifdef DEBUG4 cprintf(GREEN,"Writing_Thread: finished freeing\n"); #endif @@ -2113,7 +2158,6 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ if((numPackets[i] != dummyPacketValue) && (currentPacketNumber[i] == LAST_PACKET_VALUE)) popReady[i] = true; frameBufferoffset[i] = (i*packetsPerFrame/numberofListeningThreads); - toFreePointersOffset[i] = (i*packetsPerFrame/numberofListeningThreads); blankoffset = 0; lastPacketNumber[i] = 0; currentPacketNumber[i] = 0; @@ -2202,7 +2246,7 @@ void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread) } -bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],char* toFree[],int toFreeOffset[]){ +bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* wbuffer[], bool ready[], uint32_t nP[],CircularFifo* fifoTempFree[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; bool endofAcquisition = true; @@ -2210,8 +2254,11 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w //pop if ready if(ready[i]){ fifo[i]->pop(wbuffer[i]); -#ifdef DEBUG5 - cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); +#ifdef CFIFODEBUG + if(i == 0) + cprintf(CYAN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); + else + cprintf(YELLOW,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); #endif nP[i] = (uint32_t)(*((uint32_t*)wbuffer[i])); #ifdef DEBUG4 @@ -2239,8 +2286,7 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w } #endif if(myDetectorType == EIGER){ - toFree[toFreeOffset[i]] = wbuffer[i]; - toFreeOffset[i]++; + while(!fifoTempFree[i]->push(wbuffer[i])); } } } @@ -2264,8 +2310,11 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //free fifo for(int i=0; ipush(wbuffer[i])); -#ifdef DEBUG5 - cprintf(GREEN,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); +#ifdef CFIFODEBUG + if(i==0) + cprintf(CYAN,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); + else + cprintf(YELLOW,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); #endif } @@ -2478,14 +2527,14 @@ void UDPStandardImplementation::writeFileWithoutCompression(char* wbuffer[],uint void UDPStandardImplementation::createHeaders(char* wbuffer[]){ - eiger_packet_header_t* wbuf_header=0; - eiger_packet_footer_t* wbuf_footer=0; + int port = 0, missingPacket; for (uint32_t i = 0; i < packetsPerFrame; i++){ - wbuf_header = (eiger_packet_header_t*) wbuffer[i]; - wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset); + + eiger_packet_header_t* wbuf_header = (eiger_packet_header_t*) wbuffer[i]; + eiger_packet_footer_t* wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset); #ifdef DEBUG4 cprintf(GREEN, "Loop index:%d Pnum:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); #endif diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 1a6f9860cd..4e32516fa7 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -441,6 +441,7 @@ int slsReceiverTCPIPInterface::set_file_name() { #endif #endif + if(ret==OK && socket->differentClients){ FILE_LOG(logDEBUG) << "Force update"; ret=FORCE_UPDATE; @@ -451,12 +452,14 @@ int slsReceiverTCPIPInterface::set_file_name() { if(ret==FAIL){ cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } + if(retval == NULL) socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); - }else + else{ socket->SendDataOnly(retval,MAX_STR_LENGTH); + delete[] retval; + } - //free - if(retval != NULL) delete[] retval; //return ok/fail return ret; @@ -523,12 +526,13 @@ int slsReceiverTCPIPInterface::set_file_dir() { if(ret==FAIL){ cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } + if(retval == NULL) socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); - }else + else{ socket->SendDataOnly(retval,MAX_STR_LENGTH); - - //free - if(retval != NULL) delete[] retval; + delete[] retval; + } //return ok/fail return ret; @@ -2244,13 +2248,15 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED,"%s\n",mess); + cprintf(RED, "%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); + } + if(retval == NULL) socket->SendDataOnly(defaultVal,MAX_STR_LENGTH); - }else socket->SendDataOnly(retval,MAX_STR_LENGTH); - - //free - if(retval!=NULL) delete[] retval; + else{ + socket->SendDataOnly(retval,MAX_STR_LENGTH); + delete[] retval; + } //return ok/fail return ret; From 24438419d55483768d36ab395f4a8c6411c5ddec Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 11 Nov 2015 15:09:37 +0100 Subject: [PATCH 173/222] some changes for memory leak --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 266f3e38cb..8d74dfa90e 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -355,7 +355,6 @@ int UDPStandardImplementation::setupFifoStructure(){ buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); count++; } - cout< Date: Thu, 12 Nov 2015 13:49:09 +0100 Subject: [PATCH 174/222] memory leak fixed --- slsReceiverSoftware/include/circularFifo.h | 11 +- slsReceiverSoftware/include/genericSocket.h | 114 ++++++++---------- slsReceiverSoftware/include/receiver_defs.h | 2 +- .../src/UDPStandardImplementation.cpp | 33 +++-- 4 files changed, 77 insertions(+), 83 deletions(-) diff --git a/slsReceiverSoftware/include/circularFifo.h b/slsReceiverSoftware/include/circularFifo.h index 1ba584cc4a..4234a4d5d3 100644 --- a/slsReceiverSoftware/include/circularFifo.h +++ b/slsReceiverSoftware/include/circularFifo.h @@ -78,8 +78,10 @@ int CircularFifo::getSemValue() template bool CircularFifo::push(Element*& item_) { - + //cout<<"*head:"<::push(Element*& item_) template bool CircularFifo::pop(Element*& item_) { - // if(head == tail) - // return false; // empty queue + //cout<<"-tail:"<0){ - nsending = (length>packet_size) ? packet_size:length; - nsent = read(file_des,(char*)buf+total_sent,nsending); - if(!nsent) break; - length-=nsent; - total_sent+=nsent; - } + if (buf==NULL) return -1; - if (total_sent>0) - strcpy(thisClientIP,dummyClientIP); - if (strcmp(lastClientIP,thisClientIP)) - differentClients=1; - else - differentClients=0; + total_sent=0; - break; - case UDP: - if (socketDescriptor<0) return -1; + switch(protocol) { + case TCP: + if (file_des<0) return -1; + while(length>0){ + nsending = (length>packet_size) ? packet_size:length; + nsent = read(file_des,(char*)buf+total_sent,nsending); + if(!nsent) break; + length-=nsent; + total_sent+=nsent; + } - //if length given, listens to length, else listens for packetsize till length is reached - if(length){ -/*int k = 0;*/ + if (total_sent>0) + strcpy(thisClientIP,dummyClientIP); - while(length>0){ - nsending = (length>packet_size) ? packet_size:length; -/* + if (strcmp(lastClientIP,thisClientIP)) + differentClients=1; + else + differentClients=0; + + break; + case UDP: + if (socketDescriptor<0) return -1; + + //if length given, listens to length, else listens for packetsize till length is reached + if(length){ + /*int k = 0;*/ + + while(length>0){ + nsending = (length>packet_size) ? packet_size:length; + /* //created for debugging on 11.05.2015 nsending=5000; nsent = recvfrom(socketDescriptor,(char*)buf,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); @@ -632,33 +632,32 @@ typedef struct } else k++; - */ - - - nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); - if(!nsent) break; - length-=nsent; - total_sent+=nsent; - } - } - //listens to only 1 packet - else{ - //normal - nsending=packet_size; - nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); - total_sent+=nsent; - } - break; - default: - ; - } + */ + nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); + if(!nsent) break; + length-=nsent; + total_sent+=nsent; + } + } + //listens to only 1 packet + else{ + //normal + nsending=packet_size; + nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); + //nsent = 1040; + total_sent+=nsent; + } + break; + default: + ; + } #ifdef VERY_VERBOSE - cout << "sent "<< total_sent << " Bytes" << endl; + cout << "sent "<< total_sent << " Bytes" << endl; #endif - return total_sent; - + return total_sent; + } @@ -714,21 +713,12 @@ typedef struct protected: communicationProtocol protocol; - - - int is_a_server; - - int socketDescriptor; int file_des; - int packet_size; - struct sockaddr_in clientAddress, serverAddress; socklen_t clientAddress_length; - - char dummyClientIP[INET_ADDRSTRLEN]; diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index bac0df2d62..c11fe876d0 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -111,7 +111,7 @@ #define EIGER_MAX_PORTS 2 #define EIGER_HEADER_LENGTH 48 -#define EIGER_FIFO_SIZE 250 //cannot be less than max jobs per thread = 1000 +#define EIGER_FIFO_SIZE 100 /*#define EIGER_ALIGNED_FRAME_SIZE 65536*/ #define EIGER_ONE_GIGA_CONSTANT 16 #define EIGER_TEN_GIGA_CONSTANT 4 diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 8d74dfa90e..68ba62a688 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -309,7 +309,6 @@ int UDPStandardImplementation::setupFifoStructure(){ return OK; - int count = 0; //set up fifo structure for(int i=0;ipush(buffer[i]); -//#ifdef DEBUG5 - - if(count==0 || count == 127998) + sprintf(buffer[i],"mem%d",i); +#ifdef DEBUG5 cprintf(BLUE,"Info: %d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); -//#endif +#endif buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); - count++; } } FILE_LOG(logDEBUG) << "Info: Fifo structure(s) reconstructed"; @@ -1461,6 +1457,7 @@ void UDPStandardImplementation::startListening(){ //until mask unset (udp sockets shut down by client) while((1 << ithread) & listeningThreadsMask){ + //pop from fifo fifoFree[ithread]->pop(buffer[ithread]); #ifdef CFIFODEBUG @@ -1479,6 +1476,7 @@ void UDPStandardImplementation::startListening(){ rc = prepareAndListenBuffer(ithread, listenSize, carryonBufferSize, tempBuffer); + //start indices for each start of scan/acquisition if((!measurementStarted) && (rc > 0)){ pthread_mutex_lock(&progressMutex); @@ -1487,12 +1485,12 @@ void UDPStandardImplementation::startListening(){ pthread_mutex_unlock(&progressMutex); } + //problem in receiving or end of acquisition if (status == TRANSMITTING){ stopListening(ithread,rc); continue; } - //write packet count to buffer if(myDetectorType == EIGER) (*((uint32_t*)(buffer[ithread]))) = 1; @@ -1503,6 +1501,7 @@ void UDPStandardImplementation::startListening(){ //push buffer to FIFO while(!fifo[ithread]->push(buffer[ithread])); + #ifdef CFIFODEBUG if(ithread == 0) cprintf(CYAN,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); @@ -1511,6 +1510,7 @@ void UDPStandardImplementation::startListening(){ #endif + }/*--end of loop for each buffer (inner loop)*/ //end of acquisition, wait for next acquisition/change of parameters @@ -1537,6 +1537,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in //listen to UDP packets if(cSize) memcpy(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, temp, cSize); + int receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, lSize + cSize); //throw away packets that is not one packet size, need to check status if socket is shut down @@ -1550,6 +1551,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); } + #ifdef MANUALDEBUG eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); @@ -1961,7 +1963,6 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //until mask unset (udp sockets shut down by client) while((1 << ithread) & writerThreadsMask){ - //pop fifo and if end of acquisition if(popAndCheckEndofAcquisition(ithread, packetBuffer, popReady, numPackets,fifoTempFree)){ #ifdef DEBUG4 @@ -2109,10 +2110,10 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ currentFrameNumber = presentFrameNumber; numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -//#ifdef FNUM_DEBUG +#ifdef FNUM_DEBUG cprintf(GREEN,"**fnum:%d**\n",currentFrameNumber); -//#endif -//#ifdef MISSINGP_DEBUG +#endif +#ifdef MISSINGP_DEBUG if(numMissingPackets){ cprintf(RED, "Total missing packets %d for fnum %d\n",numMissingPackets,currentFrameNumber); for (int j=0;jisEmpty()){ fifoTempFree[i]->pop(temp); fifoFree[i]->push(temp); - count++; #ifdef CFIFODEBUG if(i==0) - cprintf(CYAN,"Fifo %d: %d Writing_Thread freed: pushed into fifofree %p\n",i,count, (void*)(temp)); + cprintf(CYAN,"Fifo %d: Writing_Thread freed: pushed into fifofree %p\n",i, (void*)(temp)); else - cprintf(YELLOW,"Fifo %d: %d Writing_Thread freed: pushed into fifofree %p\n",i, count,(void*)(temp)); + cprintf(YELLOW,"Fifo %d: Writing_Thread freed: pushed into fifofree %p\n",i, (void*)(temp)); #endif } } From 113e5223990bbd22f5639409790f4b254314aa05 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 13 Nov 2015 17:55:11 +0100 Subject: [PATCH 175/222] refactoring and reducing overhead --- .../src/UDPStandardImplementation.cpp | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 68ba62a688..2b3068e083 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -856,7 +856,6 @@ int UDPStandardImplementation::startReceiver(char *c){ for(int i=0;i Date: Mon, 16 Nov 2015 11:48:50 +0100 Subject: [PATCH 176/222] fifodepth def change, and listening packets count right --- .../include/UDPStandardImplementation.h | 2 +- .../src/UDPStandardImplementation.cpp | 49 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index a1cad30e94..605afc1550 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -585,7 +585,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase int numberofJobsPerBuffer; /** Fifo Depth */ - uint32_t fifoSize; + uint32_t fifoDepth; /** Missing Packet identifier value */ const static uint16_t missingPacketValue = 0xFFFF; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 2b3068e083..4c2574234a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -170,7 +170,7 @@ void UDPStandardImplementation::initializeMembers(){ } sfilefd = NULL; numberofJobsPerBuffer = -1; - fifoSize = 0; + fifoDepth = 0; //***receiver to GUI parameters*** latestData = NULL; @@ -253,7 +253,7 @@ int UDPStandardImplementation::setupFifoStructure(){ int64_t i; int oldNumberofJobsPerBuffer = numberofJobsPerBuffer; - uint32_t oldFifoSize = fifoSize; + uint32_t oldFifoSize = fifoDepth; //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ @@ -287,25 +287,25 @@ int UDPStandardImplementation::setupFifoStructure(){ //set fifo depth //eiger listens to 1 packet at a time and size changes depending on packets per frame if(myDetectorType == EIGER) - fifoSize = EIGER_FIFO_SIZE * packetsPerFrame; + fifoDepth = EIGER_FIFO_SIZE * packetsPerFrame; else{ - fifoSize = GOTTHARD_FIFO_SIZE; + fifoDepth = GOTTHARD_FIFO_SIZE; if(myDetectorType == MOENCH) - fifoSize = MOENCH_FIFO_SIZE; + fifoDepth = MOENCH_FIFO_SIZE; else if(myDetectorType == PROPIX) - fifoSize = PROPIX_FIFO_SIZE; + fifoDepth = PROPIX_FIFO_SIZE; //reduce fifo depth if more frames listened to at a time - if(fifoSize % numberofJobsPerBuffer) - fifoSize = (fifoSize/numberofJobsPerBuffer)+1; + if(fifoDepth % numberofJobsPerBuffer) + fifoDepth = (fifoDepth/numberofJobsPerBuffer)+1; else - fifoSize = fifoSize/numberofJobsPerBuffer; + fifoDepth = fifoDepth/numberofJobsPerBuffer; } - FILE_LOG(logDEBUG) << "Info: Fifo Depth:" << fifoSize; + FILE_LOG(logDEBUG) << "Info: Fifo Depth:" << fifoDepth; //do not rebuild fifo structure if it is the same - if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoSize)) + if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoDepth)) return OK; @@ -329,13 +329,13 @@ int UDPStandardImplementation::setupFifoStructure(){ if(mem0[i]) free(mem0[i]); //creating - fifoFree[i] = new CircularFifo(fifoSize); - fifo[i] = new CircularFifo(fifoSize); + fifoFree[i] = new CircularFifo(fifoDepth); + fifo[i] = new CircularFifo(fifoDepth); //cout<<"buffersize:"<push(buffer[i]); sprintf(buffer[i],"mem%d",i); #ifdef DEBUG5 @@ -660,7 +660,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - fifoSize = GOTTHARD_FIFO_SIZE; + fifoDepth = GOTTHARD_FIFO_SIZE; //footerOffset = Not applicable; break; case PROPIX: @@ -673,7 +673,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = PROPIX_FRAME_INDEX_OFFSET; packetIndexMask = PROPIX_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * PROPIX_PACKETS_PER_FRAME; - fifoSize = PROPIX_FIFO_SIZE; + fifoDepth = PROPIX_FIFO_SIZE; //footerOffset = Not applicable; break; case MOENCH: @@ -686,7 +686,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; packetIndexMask = MOENCH_PACKET_INDEX_MASK; maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; - fifoSize = MOENCH_FIFO_SIZE; + fifoDepth = MOENCH_FIFO_SIZE; //footerOffset = Not applicable; break; case EIGER: @@ -700,7 +700,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; packetIndexMask = EIGER_PACKET_INDEX_MASK; maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - fifoSize = EIGER_FIFO_SIZE; + fifoDepth = EIGER_FIFO_SIZE; footerOffset = EIGER_PACKET_HEADER_SIZE + oneDataSize; break; case JUNGFRAUCTB: @@ -714,7 +714,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = JCTB_FRAME_INDEX_OFFSET; packetIndexMask = JCTB_PACKET_INDEX_MASK; maxPacketsPerFile = JFCTB_MAX_FRAMES_PER_FILE * JCTB_PACKETS_PER_FRAME; - fifoSize = JCTB_FIFO_SIZE; + fifoDepth = JCTB_FIFO_SIZE; //footerOffset = Not applicable; break; default: @@ -934,18 +934,19 @@ void UDPStandardImplementation::startReadout(){ } //wait for all packets if(totalP!=numberOfFrames*packetsPerFrame){ + prev = -1; //wait as long as there is change from prev totalP while(prev != totalP){ - cprintf(MAGENTA,"waiting for all packets\n"); - usleep(1000);/* Need to find optimal time (exposure time and acquisition period) **/ + cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP); + usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/ prev = totalP; totalP=0; for(i=0; iReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); } - + totalListeningFrameCount[ithread] += (receivedSize/onePacketSize); #ifdef MANUALDEBUG eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); From 777f04331d28c06f0e5d6f6806b4e7ebd6929edf Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 17 Nov 2015 10:31:09 +0100 Subject: [PATCH 177/222] implemented fifo depth configurable from client --- .../include/UDPBaseImplementation.h | 16 ++++ slsReceiverSoftware/include/UDPInterface.h | 13 +++ .../include/UDPStandardImplementation.h | 11 ++- .../include/slsReceiverTCPIPInterface.h | 3 + .../include/sls_receiver_funcs.h | 3 +- .../src/UDPBaseImplementation.cpp | 12 +++ .../src/UDPStandardImplementation.cpp | 88 +++++++++++-------- .../src/slsReceiverTCPIPInterface.cpp | 76 ++++++++++++++++ 8 files changed, 184 insertions(+), 38 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index dfb7b04295..2c544759bc 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -179,6 +179,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ bool getTenGigaEnable() const; + /** + * Get Fifo Depth + * @return fifo depth + */ + uint32_t getFifoDepth() const; + + //***receiver status*** /** * Get Listening Status of Receiver @@ -324,6 +331,13 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter */ int setTenGigaEnable(const bool b); + /** + * Set Fifo Depth + * @param i fifo depth value + * @return OK or FAIL + */ + int setFifoDepth(const uint32_t i); + /************************************************************************* * Behavioral functions*************************************************** @@ -460,6 +474,8 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter uint32_t dynamicRange; /** Ten Giga Enable*/ bool tengigaEnable; + /** Fifo Depth */ + uint32_t fifoDepth; /** Bottom Half Module Enable */ bool bottomEnable; diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 1a63776534..798c45f6cc 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -235,6 +235,12 @@ class UDPInterface { */ virtual bool getTenGigaEnable() const = 0; + /** + * Get Fifo Depth + * @return fifo depth + */ + virtual uint32_t getFifoDepth() const = 0; + //***receiver status*** /** * Get Listening Status of Receiver @@ -378,6 +384,13 @@ class UDPInterface { */ virtual int setTenGigaEnable(const bool b) = 0; + /** + * Set Fifo Depth + * @param i fifo depth value + * @return OK or FAIL + */ + virtual int setFifoDepth(const uint32_t i) = 0; + /************************************************************************* * Behavioral functions*************************************************** diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 605afc1550..3c256450a7 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -122,6 +122,13 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase int setTenGigaEnable(const bool b); + /** + * Overridden method + * Set Fifo Depth + * @param i fifo depth value + * @return OK or FAIL + */ + int setFifoDepth(const uint32_t i); /************************************************************************* * Behavioral functions*************************************************** @@ -584,8 +591,8 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Number of Jobs Per Buffer */ int numberofJobsPerBuffer; - /** Fifo Depth */ - uint32_t fifoDepth; + /** Total fifo size */ + uint32_t fifoSize; /** Missing Packet identifier value */ const static uint16_t missingPacketValue = 0xFFFF; diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index 49e5134f15..b71b705f6a 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -207,6 +207,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** enable 10Gbe */ int enable_tengiga(); + /** set fifo depth */ + int set_fifo_depth(); + //General Functions /** Locks Receiver */ int lock_receiver(); diff --git a/slsReceiverSoftware/include/sls_receiver_funcs.h b/slsReceiverSoftware/include/sls_receiver_funcs.h index 7f3842576e..e1ef930402 100644 --- a/slsReceiverSoftware/include/sls_receiver_funcs.h +++ b/slsReceiverSoftware/include/sls_receiver_funcs.h @@ -48,7 +48,8 @@ enum { F_ENABLE_RECEIVER_COMPRESSION, /**< enable compression in receiver */ F_ENABLE_RECEIVER_OVERWRITE, /**< set overwrite flag in receiver */ - F_ENABLE_RECEIVER_TEN_GIGA /**< enable 10Gbe in receiver */ + F_ENABLE_RECEIVER_TEN_GIGA, /**< enable 10Gbe in receiver */ + F_SET_RECEIVER_FIFO_DEPTH /**< set receiver fifo depth */ /* Always append functions hereafter!!! */ }; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 6062085213..9a9b1723ad 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -44,6 +44,7 @@ void UDPBaseImplementation::initializeMembers(){ numberOfFrames = 0; dynamicRange = 16; tengigaEnable = false; + fifoDepth = 0; bottomEnable = false; //***receiver parameters*** @@ -181,6 +182,8 @@ uint32_t UDPBaseImplementation::getDynamicRange() const{ FILE_LOG(logDEBUG) << _ bool UDPBaseImplementation::getTenGigaEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return tengigaEnable;} +uint32_t UDPBaseImplementation::getFifoDepth() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fifoDepth;} + /***receiver status***/ slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return status;} @@ -358,6 +361,15 @@ int UDPBaseImplementation::setTenGigaEnable(const bool b){ return OK; } +int UDPBaseImplementation::setFifoDepth(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + + fifoDepth = i; + FILE_LOG(logINFO) << "Fifo Depth: " << i; + + //overridden functions might return FAIL + return OK; +} /************************************************************************* * Behavioral functions*************************************************** diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 4c2574234a..3a6a346e1f 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -170,7 +170,7 @@ void UDPStandardImplementation::initializeMembers(){ } sfilefd = NULL; numberofJobsPerBuffer = -1; - fifoDepth = 0; + fifoSize = 0; //***receiver to GUI parameters*** latestData = NULL; @@ -251,16 +251,15 @@ void UDPStandardImplementation::initializeFilter(){ int UDPStandardImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + + //number of jobs per buffer int64_t i; int oldNumberofJobsPerBuffer = numberofJobsPerBuffer; - uint32_t oldFifoSize = fifoDepth; - //eiger always listens to 1 packet at a time if(myDetectorType == EIGER){ numberofJobsPerBuffer = 1; FILE_LOG(logDEBUG) << "Info: 1 packet per buffer"; } - //else calculate best possible number of frames to listen to at a time (for fast readouts like gotthard) else{ //if frequency to gui is not random (every nth frame), then listen to only n frames per buffer @@ -284,29 +283,41 @@ int UDPStandardImplementation::setupFifoStructure(){ FILE_LOG(logINFO) << "Number of Frames per buffer:" << numberofJobsPerBuffer << endl; } - //set fifo depth - //eiger listens to 1 packet at a time and size changes depending on packets per frame - if(myDetectorType == EIGER) - fifoDepth = EIGER_FIFO_SIZE * packetsPerFrame; - else{ - fifoDepth = GOTTHARD_FIFO_SIZE; - if(myDetectorType == MOENCH) - fifoDepth = MOENCH_FIFO_SIZE; - else if(myDetectorType == PROPIX) - fifoDepth = PROPIX_FIFO_SIZE; - //reduce fifo depth if more frames listened to at a time - if(fifoDepth % numberofJobsPerBuffer) - fifoDepth = (fifoDepth/numberofJobsPerBuffer)+1; - else - fifoDepth = fifoDepth/numberofJobsPerBuffer; + + + // fifo depth + uint32_t oldFifoSize = fifoSize; + //default + if(!fifoDepth){ + switch(myDetectorType){ + case GOTTHARD: fifoSize = GOTTHARD_FIFO_SIZE; break; + case MOENCH: fifoSize = MOENCH_FIFO_SIZE; break; + case PROPIX: fifoSize = PROPIX_FIFO_SIZE; break; + case EIGER: fifoSize = EIGER_FIFO_SIZE * packetsPerFrame; break;//listens to 1 packet at a time and size depends on packetsperframe + default: break; + } } - FILE_LOG(logDEBUG) << "Info: Fifo Depth:" << fifoDepth; + //change by user + else{ + if(myDetectorType == EIGER) + fifoSize = fifoDepth * packetsPerFrame; + else fifoSize = fifoDepth; + } + //reduce fifo depth if > 1 numberofJobsPerBuffer + if(fifoSize % numberofJobsPerBuffer) + fifoSize = (fifoSize/numberofJobsPerBuffer)+1; + else + fifoSize = fifoSize/numberofJobsPerBuffer; - //do not rebuild fifo structure if it is the same - if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoDepth)) + //do not rebuild fifo structure if it is the same (oldfifosize differs only for different packetsperframe) + if((oldNumberofJobsPerBuffer == numberofJobsPerBuffer) && (oldFifoSize == fifoSize)) return OK; + FILE_LOG(logINFO) << "Info: Total Fifo Size:" << fifoSize; + + + //set up fifo structure @@ -329,13 +340,11 @@ int UDPStandardImplementation::setupFifoStructure(){ if(mem0[i]) free(mem0[i]); //creating - fifoFree[i] = new CircularFifo(fifoDepth); - fifo[i] = new CircularFifo(fifoDepth); - - //cout<<"buffersize:"<(fifoSize); + fifo[i] = new CircularFifo(fifoSize); //allocate memory - mem0[i] = (char*)malloc((bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * fifoDepth); + mem0[i] = (char*)malloc((bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * fifoSize); if (mem0[i] == NULL){ cprintf(BG_RED,"Error: Could not allocate memory for listening \n"); return FAIL; @@ -343,7 +352,7 @@ int UDPStandardImplementation::setupFifoStructure(){ //push free address into fifoFree buffer[i]=mem0[i]; - while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoDepth-1))) { + while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoSize-1))) { fifoFree[i]->push(buffer[i]); sprintf(buffer[i],"mem%d",i); #ifdef DEBUG5 @@ -352,7 +361,7 @@ int UDPStandardImplementation::setupFifoStructure(){ buffer[i] += (bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS); } } - FILE_LOG(logDEBUG) << "Info: Fifo structure(s) reconstructed"; + cout << "Fifo structure(s) reconstructed" << endl; return OK; } @@ -612,7 +621,16 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ } +int UDPStandardImplementation::setFifoDepth(const uint32_t i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + if(i != fifoDepth){ + FILE_LOG(logINFO) << "Fifo Depth: " << i << endl; + fifoDepth = i; + return setupFifoStructure(); + } + return OK; +} @@ -641,7 +659,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ case EIGER: case JUNGFRAUCTB: case JUNGFRAU: - FILE_LOG(logINFO) << " ***** This is a " << getDetectorType(d) << " Receiver *****"; + FILE_LOG(logINFO) << " ***** " << getDetectorType(d) << " Receiver *****"; break; default: FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d; @@ -660,7 +678,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - fifoDepth = GOTTHARD_FIFO_SIZE; + fifoSize = GOTTHARD_FIFO_SIZE; //footerOffset = Not applicable; break; case PROPIX: @@ -673,7 +691,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = PROPIX_FRAME_INDEX_OFFSET; packetIndexMask = PROPIX_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * PROPIX_PACKETS_PER_FRAME; - fifoDepth = PROPIX_FIFO_SIZE; + fifoSize = PROPIX_FIFO_SIZE; //footerOffset = Not applicable; break; case MOENCH: @@ -686,7 +704,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET; packetIndexMask = MOENCH_PACKET_INDEX_MASK; maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; - fifoDepth = MOENCH_FIFO_SIZE; + fifoSize = MOENCH_FIFO_SIZE; //footerOffset = Not applicable; break; case EIGER: @@ -700,7 +718,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = EIGER_FRAME_INDEX_OFFSET; packetIndexMask = EIGER_PACKET_INDEX_MASK; maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - fifoDepth = EIGER_FIFO_SIZE; + fifoSize = EIGER_FIFO_SIZE; footerOffset = EIGER_PACKET_HEADER_SIZE + oneDataSize; break; case JUNGFRAUCTB: @@ -714,7 +732,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = JCTB_FRAME_INDEX_OFFSET; packetIndexMask = JCTB_PACKET_INDEX_MASK; maxPacketsPerFile = JFCTB_MAX_FRAMES_PER_FILE * JCTB_PACKETS_PER_FRAME; - fifoDepth = JCTB_FIFO_SIZE; + fifoSize = JCTB_FIFO_SIZE; //footerOffset = Not applicable; break; default: diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 4e32516fa7..403aa73099 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -252,6 +252,7 @@ int slsReceiverTCPIPInterface::function_table(){ flist[F_ENABLE_RECEIVER_OVERWRITE] = &slsReceiverTCPIPInterface::enable_overwrite; flist[F_ENABLE_RECEIVER_TEN_GIGA] = &slsReceiverTCPIPInterface::enable_tengiga; + flist[F_SET_RECEIVER_FIFO_DEPTH] = &slsReceiverTCPIPInterface::set_fifo_depth; #ifdef VERYVERBOSE @@ -2484,6 +2485,81 @@ int slsReceiverTCPIPInterface::enable_tengiga() { +int slsReceiverTCPIPInterface::set_fifo_depth() { + ret=OK; + int value=-1; + int retval=-100; + strcpy(mess,"Could not set/get fifo depth for receiver\n"); + + // receive arguments + if(socket->ReceiveDataOnly(&value,sizeof(value)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_UDP_FUNCTIONS + if (ret==OK) { + if(value >= 0){ + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + } + else if(receiverBase->getStatus()==RUNNING){ + strcpy(mess,"Cannot set/get fifo depth while status is running\n"); + ret=FAIL; + } + else{ + if(value >= 0){ + ret = receiverBase->setFifoDepth(value); + } + } + } + + + if (receiverBase == NULL){ + strcpy(mess,"Receiver not set up\n"); + ret=FAIL; + }else{ + retval = receiverBase->getFifoDepth(); + if(value >= 0 && retval != value) + ret = FAIL; + } + + } +#endif + + if(ret==OK && socket->differentClients){ + FILE_LOG(logDEBUG) << "Force update"; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); + socket->SendDataOnly(mess,sizeof(mess)); + } + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + + + + + + + From 73f8d065b3cbd10e9d4f6471e4703be752e53348 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 17 Nov 2015 12:27:18 +0100 Subject: [PATCH 178/222] empty fifo at receiver start and comment waiting for packet --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3a6a346e1f..cda3bebadd 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -956,7 +956,9 @@ void UDPStandardImplementation::startReadout(){ prev = -1; //wait as long as there is change from prev totalP while(prev != totalP){ +#ifdef DEBUG5 cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP); +#endif usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/ prev = totalP; totalP=0; @@ -2240,6 +2242,13 @@ void UDPStandardImplementation::waitWritingBufferForNextAcquisition(int ithread) #endif + //pop fifo so that its empty + char* temp; + while(!fifo[ithread]->isEmpty()){ + cout << ithread << ":emptied buffer in fifo" << endl; + fifo[ithread]->pop(temp); + } + //create file if((1< Date: Tue, 17 Nov 2015 15:27:52 +0100 Subject: [PATCH 179/222] just minor edit changes --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index cda3bebadd..00b1283e2d 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -959,6 +959,7 @@ void UDPStandardImplementation::startReadout(){ #ifdef DEBUG5 cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP); #endif + usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/ prev = totalP; totalP=0; @@ -2315,14 +2316,11 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w else{ endofAcquisition = false; #ifdef DEBUG4 - switch(myDetectorType){ - case EIGER: + if(myDetectorType == EIGER){ eiger_packet_footer_t* wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"Fnum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"Pnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); - break; - default: break; } #endif if(myDetectorType == EIGER){ From 6600d82fc7f3700d77a6c13ceeb5c4dd1a1d46e1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 19 Nov 2015 11:18:35 +0100 Subject: [PATCH 180/222] some small unimportant changes such as removign eiger header structure form generic socket and initializign differentlclients --- slsReceiverSoftware/include/genericSocket.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index aebdd8066f..97cd3223ef 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -93,12 +93,7 @@ enum communicationProtocol{ UDP /**< UDP */ }; -typedef struct -{ - unsigned char header_before[20]; - unsigned char fnum[4]; - unsigned char header_after[24]; -} eiger_image_header; + genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) : // portno(port_number), @@ -120,6 +115,7 @@ typedef struct strcpy(lastClientIP,"none"); strcpy(thisClientIP,"none1"); strcpy(dummyClientIP,"dummy"); + differentClients = 0; struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ @@ -184,6 +180,7 @@ typedef struct strcpy(lastClientIP,"none"); strcpy(thisClientIP,"none1"); strcpy(dummyClientIP,"dummy"); + differentClients = 0; if(serverAddress.sin_port == htons(port_number)){ socketDescriptor = -10; From 8b0772abaec30e3d44482bf2479c947d1b7f4da0 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 19 Nov 2015 14:21:04 +0100 Subject: [PATCH 181/222] got rid of memory leak when using gui --- .../src/slsReceiverTCPIPInterface.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 403aa73099..4af5e04249 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1107,7 +1107,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ for(i=0;igetFramesCaught()){ startAcquisitionIndex=-1; #ifdef VERYVERBOSE cout<<"haven't caught any frame yet"<readFrame(fName,&raw,startAcquisitionIndex,startFrameIndex); - - /**send garbage with -1 index to try again*/ + //send garbage with -1 index to try again if (raw == NULL){ startAcquisitionIndex = -1; #ifdef VERYVERBOSE @@ -1675,7 +1676,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ #endif } - /**proper frame*/ + //proper frame else{//cout<<"**** got proper frame ******"< Date: Mon, 23 Nov 2015 11:54:55 +0100 Subject: [PATCH 182/222] some cleanup for rest --- slsReceiverSoftware/include/UDPInterface.h | 6 +- .../include/UDPRESTImplementation.h | 828 +------ .../include/UDPStandardImplementation.h | 10 +- .../src/UDPRESTImplementation.cpp | 2134 +---------------- .../src/UDPStandardImplementation.cpp | 9 +- 5 files changed, 202 insertions(+), 2785 deletions(-) diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index 798c45f6cc..b00f038cb4 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -39,13 +39,17 @@ class UDPInterface { * * set*() : anytime after initialize(), multiple times * - * startReceiver(): anytime after initialize(). Will fail if state already is 'running': + * startReceiver(): anytime after initialize(). Will fail in TCPIP itself if state already is 'running': * * Only startReceiver() does change the data receiver configuration, it does pass the whole configuration cache to the data receiver. * * abort(), //FIXME: needed? * * stopReceiver() : anytime after initialize(). Will do nothing if state already is idle. + * Otherwise, sets status to transmitting when shutting down sockets + * then to run_finished when all data obtained + * then to idle when returning from this function + * * * getStatus() returns the actual state of the data receiver - idle, running or error, enum defined in include/sls_receiver_defs.h * diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index f335ba9d2d..3741997214 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -7,36 +7,21 @@ ***********************************************/ -#include "sls_receiver_defs.h" -#include "receiver_defs.h" -#include "genericSocket.h" -#include "circularFifo.h" -#include "singlePhotonDetector.h" -#include "slsReceiverData.h" -#include "moenchCommonMode.h" - #include "UDPBaseImplementation.h" - -#ifdef MYROOT1 -#include -#include -#endif - #include "RestHelper.h" - #include -#include #include -#include /** * @short does all the functions for a receiver, set/get parameters, start/stop etc. */ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseImplementation { - - public: +public: + /************************************************************************* + * Constructor & Destructor ********************************************** + *************************************************************************/ /** * Constructor */ @@ -49,787 +34,116 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI protected: - void initialize_REST(); - int get_rest_state(RestHelper * rest, string *rest_state); - - - public: - void configure(map config_map); - - /** - * delete and free member parameters - */ - void deleteMembers(); - - /** - * initialize member parameters - */ - //void initializeMembers(); - - /** - * Set detector hostname - * @param c hostname - */ - //void initialize(const char *detectorHostName); - - /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ - //char *getDetectorHostname() const; - - - /** - * Set receiver type - * @param det detector type - * Returns success or FAIL - */ - //int setDetectorType(detectorType det); - - - //Frame indices and numbers caught - /** - * Returns the frame index at start of entire acquisition (including all scans) - */ - uint32_t getStartAcquisitionIndex(); - - /** - * Returns current Frame Index Caught for an entire acquisition (including all scans) - */ - uint32_t getAcquisitionIndex(); - - /** - * Returns if acquisition started - */ - bool getAcquistionStarted(); - - /** - * Returns Frames Caught for each real time acquisition (eg. for each scan) - */ - int getFramesCaught(); - - /** - * Returns Total Frames Caught for an entire acquisition (including all scans) - */ - int getTotalFramesCaught(); - - /** - * Returns the frame index at start of each real time acquisition (eg. for each scan) - */ - uint32_t getStartFrameIndex(); - - /** - * Returns current Frame Index for each real time acquisition (eg. for each scan) - */ - uint32_t getFrameIndex(); - - /** - * Returns if measurement started - */ - bool getMeasurementStarted(); - - /** - * Resets the Total Frames Caught - * This is how the receiver differentiates between entire acquisitions - * Returns 0 - */ - void resetTotalFramesCaught(); - - - - - //file parameters - /** - * Returns File Path - */ - //char* getFilePath() const; - - /** - * Set File Path - * @param c file path - */ - //char* setFilePath(const char c[]); - - /** - * Returns File Name - */ - //char* getFileName() const; - - /** - * Set File Name (without frame index, file index and extension) - * @param c file name - */ - //char* setFileName(const char c[]); - - /** - * Returns File Index - */ - int getFileIndex(); + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ /** - * Set File Index - * @param i file index + * Get Rest State */ - int setFileIndex(int i); - - /** - * Set Frame Index Needed - * @param i frame index needed - */ - int setFrameIndexNeeded(int i); - - /** - * Set enable file write - * @param i file write enable - * Returns file write enable - */ - //int setEnableFileWrite(int i); - - /** - * Enable/disable overwrite - * @param i enable - * Returns enable over write - */ - //int setEnableOverwrite(int i); - - /** - * Returns file write enable - * 1: YES 0: NO - */ - //int getEnableFileWrite() const; - - /** - * Returns file over write enable - * 1: YES 0: NO - */ - //int getEnableOverwrite() const; + int get_rest_state(RestHelper * rest, string *rest_state); -//other parameters + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ /** - * abort acquisition with minimum damage: close open files, cleanup. - * does nothing if state already is 'idle' + * Initialize REST */ - void abort() {}; + void initialize_REST(); - /** - * Returns status of receiver: idle, running or error - */ - runStatus getStatus() const; - /** - * Set Ethernet Interface or IP to listen to - */ - void setEthernetInterface(char* c); - /** - * Set UDP Port Number - */ - void setUDPPortNo(int p); - void setUDPPortNo2(int p); + public: + /************************************************************************* + * Getters *************************************************************** + * They access local cache of configuration or detector parameters ******* + *************************************************************************/ - /* - * Returns number of frames to receive - * This is the number of frames to expect to receiver from the detector. - * The data receiver will change from running to idle when it got this number of frames - */ - - //int getNumberOfFrames() const; - /** - * set frame number if a positive number - */ - //int32_t setNumberOfFrames(int32_t fnum); - + /************************************************************************* + * Setters *************************************************************** + * They modify the local cache of configuration or detector parameters *** + *************************************************************************/ /** - * Returns scan tag + * Overridden method + * Configure command line parameters + * @param config_map mapping of config parameters passed from command line arguments */ - //int getScanTag() const; + void configure(map config_map); - /** - * set scan tag if its is a positive number - */ - //int32_t setScanTag(int32_t stag); - /** - * Returns the number of bits per pixel - */ - //int getDynamicRange() const; + /************************************************************************* + * Behavioral functions*************************************************** + * They may modify the status of the receiver **************************** + *************************************************************************/ /** - * set dynamic range if its is a positive number + * Overridden method + * Start Listening for Packets by activating all configuration settings to receiver + * When this function returns, it has status RUNNING(upon SUCCESS) or IDLE (upon failure) + * @param c error message if FAIL + * @return OK or FAIL */ - int32_t setDynamicRange(int32_t dr); + int startReceiver(char *c=NULL); /** - * Set short frame - * @param i if shortframe i=1 + * Overridden method + * Stop Listening for Packets + * Calls startReadout(), which stops listening and sets status to Transmitting + * When it has read every frame in buffer, the status changes to Run_Finished + * When this function returns, receiver has status IDLE + * Pre: status is running, semaphores have been instantiated, + * Post: udp sockets shut down, status is idle, semaphores destroyed */ - int setShortFrame(int i); + void stopReceiver(); /** - * Set the variable to send every nth frame to gui - * or if 0,send frame only upon gui request - */ - int setNFrameToGui(int i); - - /** set acquisition period if a positive number - */ - int64_t setAcquisitionPeriod(int64_t index); - - /** get data compression, by saving only hits - */ - bool getDataCompression(); - - /** enabl data compression, by saving only hits - /returns if failed + * Overridden method + * Stop Listening to Packets + * and sets status to Transmitting + * Next step would be to get all data and stop receiver completely and return with idle state + * Pre: status is running, udp sockets have been initialized, stop receiver initiated + * Post:udp sockets closed, status is transmitting, */ - int enableDataCompression(bool enable); + void startReadout(); /** - * enable 10Gbe - @param enable 1 for 10Gbe or 0 for 1 Gbe, -1 to read out - \returns enable for 10Gbe + * Overridden method + * Shuts down and deletes UDP Sockets + * TCPIPInterface can also call this in case of illegal shutdown of receiver + * @return OK or FAIL */ - int enableTenGiga(int enable = -1); - - - -//other functions + int shutDownUDPSockets(); /** - * Returns the buffer-current frame read by receiver + * Overridden method + * Get the buffer-current frame read by receiver * @param c pointer to current file name * @param raw address of pointer, pointing to current frame to send to gui - * @param fnum frame number for eiger as it is not in the packet - * @param startAcquisitionIndex is the start index of the acquisition - * @param startFrameIndex is the start index of the scan + * @param startAcq start index of the acquisition + * @param startFrame start index of the scan */ - void readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex); + void readFrame(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame); /** - * Closes all files - * @param ithr thread index + * Overridden method + * Closes file / all files(data compression involves multiple files) + * TCPIPInterface can also call this in case of illegal shutdown of receiver + * @param i thread index valid for datacompression using root files, -1 for all threads */ - void closeFile(int ithr = -1); - - /** - * Starts Receiver - starts to listen for packets - * @param message is the error message if there is an error - * Returns success - */ - int startReceiver(char message[]); - - /** - * Stops Receiver - stops listening for packets - * Returns success - */ - int stopReceiver(); - - /** set status to transmitting and - * when fifo is empty later, sets status to run_finished - */ - void startReadout(); - - /** - * shuts down the udp sockets - * \returns if success or fail - */ - int shutDownUDPSockets(); + void closeFile(int i = -1); private: - /* - void not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; - }; - */ - /** - * Deletes all the filter objects for single photon data - */ - void deleteFilter(); - - /** - * Constructs the filter for single photon data - */ - void setupFilter(); - - /** - * set up fifo according to the new numjobsperthread - */ - void setupFifoStructure (); - - /** - * Copy frames to gui - * uses semaphore for nth frame mode - */ - void copyFrameToGui(char* startbuf[], uint32_t fnum=-1, char* buf=NULL); - - /** - * creates udp sockets - * \returns if success or fail - */ - int createUDPSockets(); - - /** - * create listening thread - * @param destroy is true to kill all threads and start again - */ - int createListeningThreads(bool destroy = false); - - /** - * create writer threads - * @param destroy is true to kill all threads and start again - */ - int createWriterThreads(bool destroy = false); - - /** - * set thread priorities - */ - void setThreadPriorities(); - - /** - * initializes variables and creates the first file - * also does the startAcquisitionCallBack - * \returns FAIL or OK - */ - int setupWriter(); - - /** - * Creates new tree and file for compression - * @param ithr thread number - * @param iframe frame number - *\returns OK for succces or FAIL for failure - */ - int createCompressionFile(int ithr, int iframe); - - /** - * Creates new file - *\returns OK for succces or FAIL for failure - */ - int createNewFile(); - - /** - * Static function - Thread started which listens to packets. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startListeningThread(void *this_pointer); - - /** - * Static function - Thread started which writes packets to file. - * Called by startReceiver() - * @param this_pointer pointer to this object - */ - static void* startWritingThread(void *this_pointer); - - /** - * Thread started which listens to packets. - * Called by startReceiver() - * - */ - int startListening(); - - /** - * Thread started which writes packets to file. - * Called by startReceiver() - * - */ - int startWriting(); - - /** - * Writing to file without compression - * @param buf is the address of buffer popped out of fifo - * @param numpackets is the number of packets - * @param framenum current frame number - */ - void writeToFile_withoutCompression(char* buf,int numpackets, uint32_t framenum); - - /** - * Its called for the first packet of a scan or acquistion - * Sets the startframeindices and the variables to know if acquisition started - * @param ithread listening thread number - */ - void startFrameIndices(int ithread); - - /** - * This is called when udp socket is shut down - * It pops ffff instead of packet number into fifo - * to inform writers about the end of listening session - * @param ithread listening thread number - * @param rc number of bytes received - * @param pc packet count - * @param t total packets listened to - */ - void stopListening(int ithread, int rc, int &pc, int &t); - - /** - * When acquisition is over, this is called - * @param ithread listening thread number - * @param wbuffer writer buffer - */ - void stopWriting(int ithread, char* wbuffer[]); - - - /** - * data compression for each fifo output - * @param ithread listening thread number - * @param wbuffer writer buffer - * @param npackets number of packets from the fifo - * @param data pointer to the next packet start - * @param xmax max pixels in x direction - * @param ymax max pixels in y direction - * @param nf nf - */ - void handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf); - - - /** structure of an eiger image header*/ - typedef struct - { - unsigned char header_before[20]; - unsigned char fnum[4]; - unsigned char header_after[24]; - } eiger_image_header; - - - /** structure of an eiger image header*/ - typedef struct - { - unsigned char num1[4]; - unsigned char num2[4]; - } eiger_packet_header; - - /** max number of listening threads */ - const static int MAX_NUM_LISTENING_THREADS = EIGER_MAX_PORTS; - - /** max number of writer threads */ - const static int MAX_NUM_WRITER_THREADS = 15; - - /** detector type */ - //detectorType myDetectorType; - - /** detector hostname */ - //char detHostname[MAX_STR_LENGTH]; - - /** status of receiver */ - //runStatus status; - - /** UDP Socket between Receiver and Detector */ - //genericSocket* udpSocket[MAX_NUM_LISTENING_THREADS]; - - /** Server UDP Port*/ - //int server_port[MAX_NUM_LISTENING_THREADS]; - - /** ethernet interface or IP to listen to */ - //char *eth; - - /** max packets per file **/ - //int maxPacketsPerFile; - - /** File write enable */ - //int enableFileWrite; - - /** File over write enable */ - //int overwrite; - - /** Complete File name */ - //char savefilename[MAX_STR_LENGTH]; - - /** File Name without frame index, file index and extension*/ - //char fileName[MAX_STR_LENGTH]; - - /** File Path */ - //char filePath[MAX_STR_LENGTH]; - - /** File Index */ - //int fileIndex; - - /** scan tag */ - //int scanTag; - - /** if frame index required in file name */ - //int frameIndexNeeded; - - /* Acquisition started */ - //bool acqStarted; - - /* Measurement started */ - //bool measurementStarted; - - /** Frame index at start of each real time acquisition (eg. for each scan) */ - //uint32_t startFrameIndex; - - /** Actual current frame index of each time acquisition (eg. for each scan) */ - //uint32_t frameIndex; - - /** Frames Caught for each real time acquisition (eg. for each scan) */ - //int packetsCaught; - - /** Total packets caught for an entire acquisition (including all scans) */ - //int totalPacketsCaught; - - /** Pckets currently in current file, starts new file when it reaches max */ - //int packetsInFile; - - /** Frame index at start of an entire acquisition (including all scans) */ - //uint32_t startAcquisitionIndex; - - /** Actual current frame index of an entire acquisition (including all scans) */ - //uint32_t acquisitionIndex; - - /** number of packets per frame*/ - //int packetsPerFrame; - - /** frame index mask */ - //uint32_t frameIndexMask; - - /** packet index mask */ - //uint32_t packetIndexMask; - - /** frame index offset */ - //int frameIndexOffset; - - /** acquisition period */ - //int64_t acquisitionPeriod; - - /** frame number */ - //int32_t numberOfFrames; - - /** dynamic range */ - //int dynamicRange; - - /** short frames */ - //int shortFrame; - - /** current frame number */ - //uint32_t currframenum; - - /** Previous Frame number from buffer */ - //uint32_t prevframenum; - - /** size of one frame */ - //int frameSize; - - /** buffer size. different from framesize as we wait for one packet instead of frame for eiger */ - //int bufferSize; - - /** oen buffer size */ - //int onePacketSize; - - /** latest data */ - //char* latestData; - - /** gui data ready */ - //int guiDataReady; - - /** points to the data to send to gui */ - //char* guiData; - - /** points to the filename to send to gui */ - //char* guiFileName; - - /** temporary number for eiger frame number as its not included in the packet */ - //uint32_t guiFrameNumber; - - /** send every nth frame to gui or only upon gui request*/ - //int nFrameToGui; - - /** fifo size */ - //unsigned int fifosize; - - /** number of jobs per thread for data compression */ - //int numJobsPerThread; - - /** datacompression - save only hits */ - //bool dataCompression; - - /** memory allocated for the buffer */ - //char *mem0[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data read */ - //CircularFifo* fifo[MAX_NUM_LISTENING_THREADS]; - - /** circular fifo to store addresses of data already written and ready to be resued*/ - //CircularFifo* fifoFree[MAX_NUM_LISTENING_THREADS]; - - /** Receiver buffer */ - //char *buffer[MAX_NUM_LISTENING_THREADS]; - - /** number of writer threads */ - //intt numListeningThreads; - - /** number of writer threads */ - //int numWriterThreads; - - /** to know if listening and writer threads created properly */ - //int thread_started; - - /** current listening thread index*/ - //int currentListeningThreadIndex; - - /** current writer thread index*/ - //int currentWriterThreadIndex; - - /** thread listening to packets */ - //pthread_t listening_thread[MAX_NUM_LISTENING_THREADS]; - - /** thread writing packets */ - //pthread_t writing_thread[MAX_NUM_WRITER_THREADS]; - - /** total frame count the listening thread has listened to */ - //int totalListeningFrameCount[MAX_NUM_LISTENING_THREADS]; - - /** mask showing which listening threads are running */ - //volatile uint32_t listeningthreads_mask; - - /** mask showing which writer threads are running */ - //volatile uint32_t writerthreads_mask; - - /** mask showing which threads have created files*/ - //volatile uint32_t createfile_mask; - - /** OK if file created was successful */ - //int ret_createfile; - - /** variable used to self terminate threads waiting for semaphores */ - //int killAllListeningThreads; - - /** variable used to self terminate threads waiting for semaphores */ - //int killAllWritingThreads; - - /** 10Gbe enable*/ - //int tengigaEnable; - - - - -//semaphores - /** semaphore to synchronize writer and guireader threads */ - //sem_t smp; - /** semaphore to synchronize listener threads */ - //sem_t listensmp[MAX_NUM_LISTENING_THREADS]; - /** semaphore to synchronize writer threads */ - //sem_t writersmp[MAX_NUM_WRITER_THREADS]; - - -//mutex - /** guiDataReady mutex */ - //pthread_mutex_t dataReadyMutex; - - /** mutex for status */ - //pthread_mutex_t status_mutex; - - /** mutex for progress variable currframenum */ - //pthread_mutex_t progress_mutex; - - /** mutex for writing data to file */ - //pthread_mutex_t write_mutex; - - /** File Descriptor */ - //FILE *sfilefd; - - //filter - //singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - //slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - //moenchCommonMode *cmSub; - //bool commonModeSubtractionEnable; - -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif - - - - /** - callback arguments are - filepath - filename - fileindex - data size - - return value is - 0 callback takes care of open,close,write file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - - */ - int (*startAcquisitionCallBack)(char*, char*,int, int, void*); - void *pStartAcquisition; - - /** - args to acquisition finished callback - total frames caught - - */ - void (*acquisitionFinishedCallBack)(int, void*); - void *pAcquisitionFinished; - - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); - void *pRawDataReady; - - /** The action which decides what the user and default responsibilites to save data are - * 0 raw data ready callback takes care of open,close,write file - * 1 callback writes file, we have to open, close it - * 2 we open, close, write file, callback does not do anything */ - int cbAction; - - -public: - - - /** - callback arguments are - filepath - filename - fileindex - datasize - - return value is - 0 callback takes care of open,close,wrie file - 1 callback writes file, we have to open, close it - 2 we open, close, write file, callback does not do anything - */ - void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;}; - - /** - callback argument is - toatal frames caught - */ - void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;}; - - /** - args to raw data ready callback are - framenum - datapointer - datasize in bytes - file descriptor - guidatapointer (NULL, no data required) - */ - void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;}; - - - //REST specific bool isInitialized; RestHelper * rest ; - int rest_port; // receiver backend port - string rest_hostname; // receiver hostname + int rest_port; // receiver backend port + string rest_hostname; // receiver hostname }; diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 3c256450a7..7ec6672aae 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -8,8 +8,6 @@ #include "UDPBaseImplementation.h" -//#include "sls_receiver_defs.h" -//#include "receiver_defs.h" #include "genericSocket.h" #include "circularFifo.h" #include "singlePhotonDetector.h" @@ -39,7 +37,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /************************************************************************* * Constructor & Destructor ********************************************** - * They access local cache of configuration or detector parameters ******* *************************************************************************/ /** * Constructor @@ -155,6 +152,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** * Overridden method * Start Listening for Packets by activating all configuration settings to receiver + * When this function returns, it has status RUNNING(upon SUCCESS) or IDLE (upon failure) * @param c error message if FAIL * @return OK or FAIL */ @@ -164,7 +162,8 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Overridden method * Stop Listening for Packets * Calls startReadout(), which stops listening and sets status to Transmitting - * When it has read every frame in buffer,it returns with the status Run_Finished + * When it has read every frame in buffer, the status changes to Run_Finished + * When this function returns, receiver has status IDLE * Pre: status is running, semaphores have been instantiated, * Post: udp sockets shut down, status is idle, semaphores destroyed */ @@ -174,6 +173,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase * Overridden method * Stop Listening to Packets * and sets status to Transmitting + * Next step would be to get all data and stop receiver completely and return with idle state * Pre: status is running, udp sockets have been initialized, stop receiver initiated * Post:udp sockets closed, status is transmitting */ @@ -182,6 +182,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** * Overridden method * Shuts down and deletes UDP Sockets + * TCPIPInterface can also call this in case of illegal shutdown of receiver * @return OK or FAIL */ int shutDownUDPSockets(); @@ -199,6 +200,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** * Overridden method * Closes file / all files(data compression involves multiple files) + * TCPIPInterface can also call this in case of illegal shutdown of receiver * @param i thread index valid for datacompression using root files, -1 for all threads */ void closeFile(int i = -1); diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index 4b2b67e4b4..ab650257f4 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -7,32 +7,21 @@ #include "UDPRESTImplementation.h" -#include "moench02ModuleData.h" -#include "gotthardModuleData.h" -#include "gotthardShortModuleData.h" - - -#include // SIGINT -#include // stat -#include // socket(), bind(), listen(), accept(), shut down -#include // sock_addr_in, htonl, INADDR_ANY #include // exit() #include // set precision -#include // munmap - -#include +#include // map #include +#include +#include #include - //#include "utilities.h" - using namespace std; /* TODO + filePath != getFilePath + better state handling. Now it is only IDLE - RUNNING - IDLE -*/ + */ UDPRESTImplementation::UDPRESTImplementation(){ @@ -40,6 +29,8 @@ UDPRESTImplementation::UDPRESTImplementation(){ //TODO I do not really know what to do with bottom... // Default values + isInitialized = false; + rest = NULL; rest_hostname = "localhost"; rest_port = 8081; } @@ -69,9 +60,9 @@ void UDPRESTImplementation::configure(map config_map){ for(map::const_iterator i=config_map.begin(); i != config_map.end(); i++){ std::cout << i->first << " " << i->second<< std::endl; } - */ + */ -}; +} int UDPRESTImplementation::get_rest_state(RestHelper * rest, string *rest_state){ @@ -84,13 +75,14 @@ int UDPRESTImplementation::get_rest_state(RestHelper * rest, string *rest_state) } return code; -}; +} + void UDPRESTImplementation::initialize_REST(){ - + FILE_LOG(logDEBUG) << __AT__ << " called"; FILE_LOG(logDEBUG) << __AT__ << " REST status is initialized: " << isInitialized; - + if (rest_hostname.empty()) { FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; } @@ -99,7 +91,7 @@ void UDPRESTImplementation::initialize_REST(){ } else { FILE_LOG(logDEBUG) << __AT__ << "with receiverHostName=" << rest_hostname << ":" << rest_port; - + rest = new RestHelper() ; std::string answer; int code; @@ -107,7 +99,7 @@ void UDPRESTImplementation::initialize_REST(){ rest->init(rest_hostname, rest_port); code = get_rest_state(rest, &answer); std::cout << "AAAAAAAa " << answer << std::endl; - + if (code != 0){ FILE_LOG(logERROR) << __AT__ << " REST state returned: " << answer; @@ -123,21 +115,21 @@ void UDPRESTImplementation::initialize_REST(){ FILE_LOG(logERROR) << __func__ << ": " << e; throw; } - + //JsonBox::Object json_object; //json_object["configfile"] = JsonBox::Value("FILENAME"); JsonBox::Value json_request; //json_request["configfile"] = "config.py"; json_request["path"] = filePath; - + stringstream ss; string test; //std::cout << "GetSTring: " << json_request << std::endl; json_request.writeToStream(ss, false); //ss << json_request; ss >> test; - - + + code = rest->get_json("state", &answer); FILE_LOG(logDEBUG) << __AT__ << " state got " << code << " " << answer << "\n"; if (answer != "INITIALIZED"){ @@ -151,8 +143,8 @@ void UDPRESTImplementation::initialize_REST(){ FILE_LOG(logDEBUG) << __AT__ << " state/configure got " << code; code = rest->get_json("state", &answer); FILE_LOG(logDEBUG) << __AT__ << " state got " << code << " " << answer << "\n"; - - + + /* std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl; JsonBox::Value json_value; @@ -160,2070 +152,180 @@ void UDPRESTImplementation::initialize_REST(){ std::cout << "JSON " << json_value["status"] << std::endl; */ } - - FILE_LOG(logDEBUG) << __func__ << ": initialize() done"; - -} - - -/* -int UDPRESTImplementation::setDetectorType(detectorType det){ - cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; - return OK; -} -*/ - - -/*Frame indices and numbers caught*/ - -bool UDPRESTImplementation::getAcquistionStarted(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return acqStarted; -}; - -bool UDPRESTImplementation::getMeasurementStarted(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return measurementStarted; -}; - -int UDPRESTImplementation::getFramesCaught(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return (packetsCaught/packetsPerFrame); -} - -int UDPRESTImplementation::getTotalFramesCaught(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - if (packetsPerFrame == 0){ - FILE_LOG(logWARNING) << __AT__ << " packetsPerFrame is 0!!!"; - return 0; - } - return (totalPacketsCaught/packetsPerFrame); -} - -uint32_t UDPRESTImplementation::getStartAcquisitionIndex(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return startAcquisitionIndex; -} - -uint32_t UDPRESTImplementation::getStartFrameIndex(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return startFrameIndex; -} - -uint32_t UDPRESTImplementation::getFrameIndex(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - if(!packetsCaught) - frameIndex=-1; - else - frameIndex = currframenum - startFrameIndex; - return frameIndex; -} - - -uint32_t UDPRESTImplementation::getAcquisitionIndex(){ - //FILE_LOG(logDEBUG) << __AT__ << " called, idx: " << acquisitionIndex; - if(!totalPacketsCaught) - acquisitionIndex = -1; - else - acquisitionIndex = currframenum - startAcquisitionIndex; - - //FILE_LOG(logDEBUG) << __AT__ << " idx: " << acquisitionIndex - // << " currframenum: " << currframenum - // << " startAcqIdx: " << startAcquisitionIndex; - - return acquisitionIndex; -} - - -void UDPRESTImplementation::resetTotalFramesCaught(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - acqStarted = false; - startAcquisitionIndex = 0; - totalPacketsCaught = 0; -} - - -/*file parameters*/ -int UDPRESTImplementation::getFileIndex(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return fileIndex; -} -int UDPRESTImplementation::setFileIndex(int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - - if(i>=0) - fileIndex = i; - - return getFileIndex(); -} - - -int UDPRESTImplementation::setFrameIndexNeeded(int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - frameIndexNeeded = i; - return frameIndexNeeded; -} - - -/* -int UDPRESTImplementation::getEnableFileWrite() const{ - return enableFileWrite; -} - -int UDPRESTImplementation::setEnableFileWrite(int i){ - enableFileWrite=i; - return getEnableFileWrite(); -} - -int UDPRESTImplementation::getEnableOverwrite() const{ - return overwrite; -} + FILE_LOG(logDEBUG) << __func__ << ": initialize() done"; -int UDPRESTImplementation::setEnableOverwrite(int i){ - overwrite=i; - return getEnableOverwrite(); } -*/ - -/*other parameters*/ -slsReceiverDefs::runStatus UDPRESTImplementation::getStatus() const{ - FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status; - return status; -} +/** acquisition functions */ -/* -char *UDPRESTImplementation::getDetectorHostname() const{ - return (char*)detHostname; -} -*/ +int UDPRESTImplementation::startReceiver(char message[]){ + int i; -void UDPRESTImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + initialize_REST(); + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " initialized"; - // TODO: this segfaults - //strcpy(eth,c); - //FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; -} + cout << "Starting Receiver" << endl; -/* -void UDPRESTImplementation::setUDPPortNo(int p){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - for(int i=0;ipost_json("state/configure", &answer, request_body); + code = rest->get_json("state", &answer); + FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer; + //code = rest->post_json("state/open", &answer); + //code = rest->get_json("state", &answer); -int32_t UDPRESTImplementation::setNumberOfFrames(int32_t fnum){ - if(fnum >= 0) - numberOfFrames = fnum; + status = RUNNING; - return getNumberOfFrames(); -} -*/ -/* -int UDPRESTImplementation::getScanTag() const{ - return scanTag; + return OK; } -*/ -/* -int32_t UDPRESTImplementation::setScanTag(int32_t stag){ - if(stag >= 0) - scanTag = stag; - return getScanTag(); -} -*/ -int32_t UDPRESTImplementation::setDynamicRange(int32_t dr){ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - int olddr = dynamicRange; - if(dr >= 0){ - dynamicRange = dr; - } - - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " " << getDynamicRange(); - return getDynamicRange(); - - -} +void UDPRESTImplementation::stopReceiver(){ -/* -int32_t UDPRESTImplementation::getDynamicRange() const{ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << "called"; - return dynamicRange; -} -*/ + if(status == RUNNING) + startReadout(); -int UDPRESTImplementation::setShortFrame(int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - shortFrame=i; - - if(shortFrame!=-1){ - bufferSize = GOTTHARD_SHORT_ONE_PACKET_SIZE; - frameSize = GOTTHARD_SHORT_BUFFER_SIZE; - maxPacketsPerFile = SHORT_MAX_FRAMES_PER_FILE * GOTTHARD_SHORT_PACKETS_PER_FRAME; - packetsPerFrame = GOTTHARD_SHORT_PACKETS_PER_FRAME; - frameIndexMask = GOTTHARD_SHORT_FRAME_INDEX_MASK; - frameIndexOffset = GOTTHARD_SHORT_FRAME_INDEX_OFFSET; - - }else{ - onePacketSize = GOTTHARD_ONE_PACKET_SIZE; - bufferSize = GOTTHARD_BUFFER_SIZE; - frameSize = GOTTHARD_BUFFER_SIZE; - maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; - packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME; - frameIndexMask = GOTTHARD_FRAME_INDEX_MASK; - frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET; - } + while(status == TRANSMITTING) + usleep(5000); + //change status + status = IDLE; - deleteFilter(); - if(dataCompression) - setupFilter(); + FILE_LOG(logDEBUG) << __AT__ << "exited, status " << endl; - return shortFrame; } -int UDPRESTImplementation::setNFrameToGui(int i){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - if(i>=0){ - nFrameToGui = i; - setupFifoStructure(); - } - return nFrameToGui; -} -int64_t UDPRESTImplementation::setAcquisitionPeriod(int64_t index){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - if(index >= 0){ - if(index != acquisitionPeriod){ - acquisitionPeriod = index; - setupFifoStructure(); - } - } - return acquisitionPeriod; -} +void UDPRESTImplementation::startReadout(){ + FILE_LOG(logDEBUG) << __AT__ << " starting"; + status = TRANSMITTING; -bool UDPRESTImplementation::getDataCompression(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - return dataCompression; -} + //kill udp socket to tell the listening thread to push last packet + shutDownUDPSockets(); + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; -int UDPRESTImplementation::enableDataCompression(bool enable){ - FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; - return OK; } -/*other functions*/ - - -void UDPRESTImplementation::deleteFilter(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - int i; - cmSub=NULL; - - for(i=0;iShutDownSocket(); + delete udpSocket[i]; + udpSocket[i] = NULL; } - break; } - for(i=0;i(receiverdata[i], csize, sigma, sign, cmSub); - -} - - - -//LEO: it is not clear to me.. -void UDPRESTImplementation::setupFifoStructure(){ - FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; -} -/* -void UDPRESTImplementation::setupFifoStructure(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; + JsonBox::Value answer; + int code; + string be_state = ""; - int64_t i; - int oldn = numJobsPerThread; - - //if every nth frame mode - if(nFrameToGui) - numJobsPerThread = nFrameToGui; - - //random nth frame mode - else{ - if(!acquisitionPeriod) - i = SAMPLE_TIME_IN_NS; - else - i = SAMPLE_TIME_IN_NS/acquisitionPeriod; - if (i > MAX_JOBS_PER_THREAD) - numJobsPerThread = MAX_JOBS_PER_THREAD; - else if (i < 1) - numJobsPerThread = 1; - else - numJobsPerThread = i; + FILE_LOG(logDEBUG) << __AT__ << " numListeningThreads=" << numListeningThreads; + if (rest == NULL){ + FILE_LOG(logWARNING) << __AT__ << "No REST object initialized, closing..."; + return OK; } - //if same, return - if(oldn == numJobsPerThread) - return; - - if(myDetectorType == EIGER) - numJobsPerThread = 1; - - //otherwise memory too much if numjobsperthread is at max = 1000 - fifosize = GOTTHARD_FIFO_SIZE; - if(myDetectorType == MOENCH) - fifosize = MOENCH_FIFO_SIZE; - else if(myDetectorType == EIGER) - fifosize = EIGER_FIFO_SIZE; - - if(fifosize % numJobsPerThread) - fifosize = (fifosize/numJobsPerThread)+1; - else - fifosize = fifosize/numJobsPerThread; - - - cout << "Number of Frames per buffer:" << numJobsPerThread << endl; - cout << "Fifo Size:" << fifosize << endl; - + // getting the state + FILE_LOG(logWARNING) << "PLEASE WAIT WHILE CHECKING AND SHUTTING DOWN ALL CONNECTIONS!"; + code = rest->get_json("state", &answer); + be_state = answer["state"].getString(); - for(int i=0;iisEmpty()) - fifoFree[i]->pop(buffer[i]); - delete fifoFree[i]; - } - if(fifo[i]) delete fifo[i]; - if(mem0[i]) free(mem0[i]); - fifoFree[i] = new CircularFifo(fifosize); - fifo[i] = new CircularFifo(fifosize); - - - //allocate memory - mem0[i]=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); - // shud let the client know about this - if (mem0[i]==NULL){ - cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; - exit(-1); - } - buffer[i]=mem0[i]; - //push the addresses into freed fifoFree and writingFifoFree - while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { - fifoFree[i]->push(buffer[i]); - buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); + // LEO: this is probably wrong + if (be_state == "OPEN"){ + while (be_state != "TRANSIENT"){ + code = rest->get_json("state", &answer); + be_state = answer["state"].getString(); + cout << "be_State: " << be_state << endl; + usleep(10000); } - } - cout << "Fifo structure(s) reconstructed" << endl; -} -*/ - - - - + code = rest->post_json("state/close", &answer); + std::cout <post_json("state/reset", &answer); + std::cout << code << " " << answer << std::endl; -/** acquisition functions */ -void UDPRESTImplementation::readFrame(char* c,char** raw, uint32_t &fnum, uint32_t &startAcquisitionIndex, uint32_t &startFrameIndex){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - //point to gui data - if (guiData == NULL){ - guiData = latestData; + code = rest->get_json("state", &answer); + std::cout << code << " " << answer << std::endl; } + status = slsReceiverDefs::RUN_FINISHED; - //copy data and filename - strcpy(c,guiFileName); - fnum = guiFrameNumber; - startAcquisitionIndex = getStartAcquisitionIndex(); - startFrameIndex = getStartFrameIndex(); - + //LEO: not sure it's needed + delete rest; - //could not get gui data - if(!guiDataReady){ - *raw = NULL; - } - //data ready, set guidata to receive new data - else{ - *raw = guiData; - guiData = NULL; - if((nFrameToGui) && (writerthreads_mask)){ - //release after getting data - sem_post(&smp); - } - } + FILE_LOG(logDEBUG) << __AT__ << "finished"; + return OK; } - - -void UDPRESTImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ +/* FIXME + * do you really need this, this is called if registerDataCallback() is activated + * in your gui to get data from receiver. you probably have a different way + * of reconstructing complete data set from all receivers + */ +void UDPRESTImplementation::readFramee(char* c,char** raw, uint64_t &startAcq, uint64_t &startFrame){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - //random read when gui not ready - if((!nFrameToGui) && (!guiData)){ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - pthread_mutex_unlock(&dataReadyMutex); - } - - //random read or nth frame read, gui needs data now - else{ - /* - //nth frame read, block current process if the guireader hasnt read it yet - if(nFrameToGui) - sem_wait(&smp); -*/ - pthread_mutex_lock(&dataReadyMutex); - guiDataReady=0; - //eiger - if(startbuf != NULL){ - int offset = 0; - int size = frameSize/EIGER_MAX_PORTS; - for(int j=0;jgetErrorStatus(); - if(iret){ -#ifdef VERBOSE - cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; -#endif - return FAIL; - } - } - - return OK; -} - - - - - - - -int UDPRESTImplementation::shutDownUDPSockets(){ - - FILE_LOG(logDEBUG) << __AT__ << "called"; - - // this is just to be sure, it could be removed - for(int i=0;iShutDownSocket(); - delete udpSocket[i]; - udpSocket[i] = NULL; - } - } - - JsonBox::Value answer; - int code; - string be_state = ""; - - FILE_LOG(logDEBUG) << __AT__ << " numListeningThreads=" << numListeningThreads; - if (rest == NULL){ - FILE_LOG(logWARNING) << __AT__ << "No REST object initialized, closing..."; - return OK; - } - - // getting the state - FILE_LOG(logWARNING) << "PLEASE WAIT WHILE CHECKING AND SHUTTING DOWN ALL CONNECTIONS!"; - code = rest->get_json("state", &answer); - be_state = answer["state"].getString(); - - // LEO: this is probably wrong - if (be_state == "OPEN"){ - while (be_state != "TRANSIENT"){ - code = rest->get_json("state", &answer); - be_state = answer["state"].getString(); - cout << "be_State: " << be_state << endl; - usleep(10000); - } - - code = rest->post_json("state/close", &answer); - std::cout <post_json("state/reset", &answer); - std::cout << code << " " << answer << std::endl; - - code = rest->get_json("state", &answer); - std::cout << code << " " << answer << std::endl; - } - status = slsReceiverDefs::RUN_FINISHED; - - //LEO: not sure it's needed - delete rest; - - FILE_LOG(logDEBUG) << __AT__ << "finished"; - return OK; -} - - - - - -int UDPRESTImplementation::createListeningThreads(bool destroy){ - - FILE_LOG(logDEBUG) << __AT__ << " called"; - int i; - void* status; - - killAllListeningThreads = 0; - - pthread_mutex_lock(&status_mutex); - listeningthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - if(!destroy){ - - //start listening threads - cout << "Creating Listening Threads(s)"; - - currentListeningThreadIndex = -1; - - for(i = 0; i < numListeningThreads; ++i){ - sem_init(&listensmp[i],1,0); - thread_started = 0; - currentListeningThreadIndex = i; - if(pthread_create(&listening_thread[i], NULL,startListeningThread, (void*) this)){ - cout << "Could not create listening thread with index " << i << endl; - return FAIL; - } - while(!thread_started); - cout << "."; - cout << flush; - } -#ifdef VERBOSE - cout << "Listening thread(s) created successfully." << endl; -#else - cout << endl; -#endif - }else{ - cout<<"Destroying Listening Thread(s)"<initEventTree(temp, &iframe); - //resets the pedestalSubtraction array and the commonModeSubtraction - singlePhotonDet[ithr]->newDataSet(); - if(myFile[ithr]==NULL){ - cout<<"file null"<IsOpen()){ - cout<<"file not open"< DO_NOTHING){ - //close - if(sfilefd){ - fclose(sfilefd); - sfilefd = NULL; - } - //open file - if(!overwrite){ - if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ - cout << "Error: Could not create new file " << savefilename << endl; - return FAIL; - } - }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not create file " << savefilename << endl; - return FAIL; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - - //printing packet losses and file names - if(!packetsCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)<GetCurrentFile(); - - if(myFile[ithr]->Write()) - //->Write(tall->GetName(),TObject::kOverwrite); - cout << "Thread " << ithr <<": wrote frames to file" << endl; - else - cout << "Thread " << ithr << ": could not write frames to file" << endl; - - }else - cout << "Thread " << ithr << ": could not write frames to file: No file or No Tree" << endl; - //close file - if(myTree[ithr] && myFile[ithr]) - myFile[ithr] = myTree[ithr]->GetCurrentFile(); - if(myFile[ithr] != NULL) - myFile[ithr]->Close(); - myFile[ithr] = NULL; - myTree[ithr] = NULL; - pthread_mutex_unlock(&write_mutex); - -#endif - } - FILE_LOG(logDEBUG) << __AT__ << "exited for thread " << ithr; } - - -int UDPRESTImplementation::startReceiver(char message[]){ - int i; - - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - initialize_REST(); - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " initialized"; - - cout << "Starting Receiver" << endl; - - std::string answer; - int code; - //char *intStr = itoa(a); - //string str = string(intStr); - // TODO: remove hardcode!!! - stringstream ss; - ss << getDynamicRange(); - string str_dr = ss.str(); - stringstream ss2; - ss2 << getNumberOfFrames(); - string str_n = ss2.str(); - - - cout << "Starting Receiver" << endl; - - std::string request_body = "{\"settings\": {\"bit_depth\": " + str_dr + ", \"nimages\": " + str_n + "}}"; - //std::string request_body = "{\"settings\": {\"nimages\":1, \"scanid\":999, \"bit_depth\":16}}"; - FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body; - code = rest->post_json("state/configure", &answer, request_body); - code = rest->get_json("state", &answer); - FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer; - - //code = rest->post_json("state/open", &answer); - //code = rest->get_json("state", &answer); - - status = RUNNING; - - //reset listening thread variables - /* - measurementStarted = false; - //should be set to zero as its added to get next start frame indices for scans for eiger - if(!acqStarted) currframenum = 0; - startFrameIndex = 0; - - for(int i = 0; i < numListeningThreads; ++i) - totalListeningFrameCount[i] = 0; - */ - //udp socket - /* - if(createUDPSockets() == FAIL){ - strcpy(message,"Could not create UDP Socket(s).\n"); - cout << endl << message << endl; - return FAIL; - } - cout << "UDP socket(s) created successfully. 1st port " << server_port[0] << endl; - - */ - /* - if(setupWriter() == FAIL){ - //stop udp socket - shutDownUDPSockets(); - - sprintf(message,"Could not create file %s.\n",savefilename); - return FAIL; - } - cout << "Successfully created file(s)" << endl; - - //done to give the gui some proper name instead of always the last file name - if(dataCompression) - sprintf(savefilename, "%s/%s_fxxx_%d_xx.root", filePath,fileName,fileIndex); - - //initialize semaphore - sem_init(&smp,1,0); - - //status - pthread_mutex_lock(&status_mutex); - status = RUNNING; - for(i=0;istartListening(); - - return this_pointer; -} - - - -void* UDPRESTImplementation::startWritingThread(void* this_pointer){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; - - //((UDPRESTImplementation*)this_pointer)->startWriting(); - return this_pointer; -} - - - - - - -int UDPRESTImplementation::startListening(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; - - /* - int ithread = currentListeningThreadIndex; -#ifdef VERYVERBOSE - cout << "In startListening() " << endl; -#endif - - thread_started = 1; - - int i,total; - int lastpacketoffset, expected, rc, rc1,packetcount, maxBufferSize, carryonBufferSize; - uint32_t lastframeheader;// for moench to check for all the packets in last frame - char* tempchar = NULL; - int imageheader = 0; - if(myDetectorType==EIGER) - imageheader = EIGER_IMAGE_HEADER_SIZE; - - - while(1){ - //variables that need to be checked/set before each acquisition - carryonBufferSize = 0; - //if more than 1 listening thread, listen one packet at a time, else need to interleaved frame later - maxBufferSize = bufferSize * numJobsPerThread; -#ifdef VERYDEBUG - cout << " maxBufferSize:" << maxBufferSize << ",carryonBufferSize:" << carryonBufferSize << endl; -#endif - - if(tempchar) {delete [] tempchar;tempchar = NULL;} - if(myDetectorType != EIGER) - tempchar = new char[onePacketSize * ((packetsPerFrame/numListeningThreads) - 1)]; //gotthard: 1packet size, moench:39 packet size - - - while((1<pop(buffer[ithread]); -#ifdef VERYDEBUG - cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; -#endif - - - //receive - if(udpSocket[ithread] == NULL){ - rc = 0; - cout << ithread << "UDP Socket is NULL" << endl; - } - //normal listening - else if(!carryonBufferSize){ - - rc = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS, maxBufferSize); - expected = maxBufferSize; - - } - //the remaining packets from previous buffer - else{ -#ifdef VERYDEBUG - cout << ithread << " ***carry on buffer" << carryonBufferSize << endl; - cout << ithread << " framennum in temochar:"<<((((uint32_t)(*((uint32_t*)tempchar))) - & (frameIndexMask)) >> frameIndexOffset)<ReceiveDataOnly((buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + carryonBufferSize),maxBufferSize - carryonBufferSize); - expected = maxBufferSize - carryonBufferSize; - } - -#ifdef VERYDEBUG - cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; -#endif - - - - - //start indices for each start of scan/acquisition - eiger does it before - if((!measurementStarted) && (rc > 0) && (!ithread)) - startFrameIndices(ithread); - - //problem in receiving or end of acquisition - if((rc < expected)||(rc <= 0)){ - stopListening(ithread,rc,packetcount,total); - continue; - } - - - - //reset - packetcount = (packetsPerFrame/numListeningThreads) * numJobsPerThread; - carryonBufferSize = 0; - - - - //check if last packet valid and calculate packet count - switch(myDetectorType){ - - case MOENCH: - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout <<"first packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (packetIndexMask)) << endl; - cout <<"first header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS))))) & (frameIndexMask)) >> frameIndexOffset) << endl; - cout << "last packet offset:" << lastpacketoffset << endl; - cout <<"last packet:"<< ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask)) << endl; - cout <<"last header:"<< (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - //moench last packet value is 0 - if( ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (packetIndexMask))){ - lastframeheader = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset; - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - while (lastframeheader == (((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))) & (frameIndexMask)) >> frameIndexOffset)){ - carryonBufferSize += onePacketSize; - lastpacketoffset -= onePacketSize; - --packetcount; - } - memcpy(tempchar, buffer[ithread]+(lastpacketoffset+onePacketSize), carryonBufferSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))) - & (frameIndexMask)) >> frameIndexOffset) << endl; - cout <<"tempchar packet:"<< ((((uint32_t)(*((uint32_t*)(tempchar))))) - & (packetIndexMask)) << endl; -#endif - } - break; - - case GOTTHARD: - if(shortFrame == -1){ - lastpacketoffset = (((numJobsPerThread * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYDEBUG - cout << "last packet offset:" << lastpacketoffset << endl; -#endif - - if((unsigned int)(packetsPerFrame -1) != ((((uint32_t)(*((uint32_t*)(buffer[ithread]+lastpacketoffset))))+1) & (packetIndexMask))){ - memcpy(tempchar,buffer[ithread]+lastpacketoffset, onePacketSize); -#ifdef VERYDEBUG - cout << "tempchar header:" << (((((uint32_t)(*((uint32_t*)(tempchar))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - carryonBufferSize = onePacketSize; - --packetcount; - } - } -#ifdef VERYDEBUG - cout << "header:" << (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset) << endl; -#endif - break; - default: - - break; - - } - - - // cout<<"*********** "<fnum)<push(buffer[ithread])); -#ifdef VERYDEBUG - if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; -#endif - } - - sem_wait(&listensmp[ithread]); - - //make sure its not exiting thread - if(killAllListeningThreads){ - cout << ithread << " good bye listening thread" << endl; - if(tempchar) {delete [] tempchar;tempchar = NULL;} - pthread_exit(NULL); - } - } - */ - return OK; -} - - - - - - - - - - - - - -int UDPRESTImplementation::startWriting(){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - FILE_LOG(logDEBUG) << __AT__ << " doing a big bunch of nothing"; - /* - int ithread = currentWriterThreadIndex; -#ifdef VERYVERBOSE - cout << ithread << "In startWriting()" <pop(wbuf[i]); - numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; -#endif - } - -#ifdef VERYDEBUG - cout << ithread << " numpackets:" << dec << numpackets << endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl; - cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl; -#endif - - - //last dummy packet - if(numpackets == 0xFFFF){ - stopWriting(ithread,wbuf); - continue; - } - - - - - //for progress - if(myDetectorType == EIGER){ - tempframenum = htonl(*(unsigned int*)((eiger_image_header *)((char*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - tempframenum += (startFrameIndex-1); //eiger frame numbers start at 1, so need to -1 - }else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(wbuf[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - pthread_mutex_lock(&progress_mutex); - if(tempframenum > currframenum) - currframenum = tempframenum; - pthread_mutex_unlock(&progress_mutex); - } -//#ifdef VERYDEBUG - if(myDetectorType == EIGER) - cout << endl < 0){ - for(i=0;ipush(wbuf[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i+j << " fifo freed:" << (void*)wbuf[i] << endl; -#endif - } - - - } - else{ - //copy to gui - copyFrameToGui(NULL,-1,wbuf[0]+HEADER_SIZE_NUM_TOT_PACKETS); -#ifdef VERYVERBOSE - cout << ithread << " finished copying" << endl; -#endif - while(!fifoFree[0]->push(wbuf[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuf[0]<fnum); - //gotthard has +1 for frame number and not a short frame - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) - & (frameIndexMask)) >> frameIndexOffset); - else - startFrameIndex = ((((uint32_t)(*((uint32_t*)(buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS)))) - & (frameIndexMask)) >> frameIndexOffset); - - - //start of acquisition - if(!acqStarted){ - startAcquisitionIndex=startFrameIndex; - currframenum = startAcquisitionIndex; - acqStarted = true; - cout << "startAcquisitionIndex:" << startAcquisitionIndex<push(buffer[ithread]); - exit(-1); - } - //push the last buffer into fifo - if(rc > 0){ - pc = (rc/onePacketSize); -#ifdef VERYDEBUG - cout << ithread << " *** last packetcount:" << pc << endl; -#endif - (*((uint16_t*)(buffer[ithread]))) = pc; - totalListeningFrameCount[ithread] += pc; - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; -#endif - } - - - //push dummy buffer to all writer threads - for(i=0;ipop(buffer[ithread]); - (*((uint16_t*)(buffer[ithread]))) = 0xFFFF; -#ifdef VERYDEBUG - cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; -#endif - while(!fifo[ithread]->push(buffer[ithread])); -#ifdef VERYDEBUG - cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; -#endif - } - - //reset mask and exit loop - pthread_mutex_lock(&status_mutex); - listeningthreads_mask^=(1< 1) - cout << "Waiting for listening to be done.. current mask:" << hex << listeningthreads_mask << endl; -#endif - while(listeningthreads_mask) - usleep(5000); -#ifdef VERYDEBUG - t = 0; - for(i=0;ipush(wbuffer[i])); -#ifdef VERYDEBUG - cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; -#endif - } - - - - //all threads need to close file, reset mask and exit loop - closeFile(ithread); - pthread_mutex_lock(&status_mutex); - writerthreads_mask^=(1< 0){ - - //for progress and packet loss calculation(new files) - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - //lock - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - - - //to create new file when max reached - packetsToSave = maxPacketsPerFile - packetsInFile; - if(packetsToSave > numpackets) - packetsToSave = numpackets; -/**next time offset is still plus header length*/ - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); - packetsInFile += packetsToSave; - packetsCaught += packetsToSave; - totalPacketsCaught += packetsToSave; - - - //new file - if(packetsInFile >= maxPacketsPerFile){ - //for packet loss - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == EIGER); - else if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - //create - createNewFile(); - } - - //unlock - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - - - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; - } - - } - else{ - if(numWriterThreads > 1) - pthread_mutex_lock(&write_mutex); - packetsInFile += numpackets; - packetsCaught += numpackets; - totalPacketsCaught += numpackets; - if(numWriterThreads > 1) - pthread_mutex_unlock(&write_mutex); - } -} - - - - - - - - - - - - - - -void UDPRESTImplementation::handleDataCompression(int ithread, char* wbuffer[], int &npackets, char* data, int xmax, int ymax, int &nf){ - - FILE_LOG(logDEBUG) << __AT__ << " called"; - -#if defined(MYROOT1) && defined(ALLFILE_DEBUG) - writeToFile_withoutCompression(wbuf[0], numpackets,currframenum); -#endif - - eventType thisEvent = PEDESTAL; - int ndata; - char* buff = 0; - data = wbuffer[0]+ HEADER_SIZE_NUM_TOT_PACKETS; - int remainingsize = npackets * onePacketSize; - int np; - int once = 0; - double tot, tl, tr, bl, br; - int xmin = 1, ymin = 1, ix, iy; - - - while(buff = receiverdata[ithread]->findNextFrame(data,ndata,remainingsize)){ - np = ndata/onePacketSize; - - //cout<<"buff framnum:"<> frameIndexOffset)<newFrame(); - - //only for moench - if(commonModeSubtractionEnable){ - for(ix = xmin - 1; ix < xmax+1; ix++){ - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent = singlePhotonDet[ithread]->getEventType(buff, ix, iy, 0); - } - } - } - - - for(ix = xmin - 1; ix < xmax+1; ix++) - for(iy = ymin - 1; iy < ymax+1; iy++){ - thisEvent=singlePhotonDet[ithread]->getEventType(buff, ix, iy, commonModeSubtractionEnable); - if (nf>1000) { - tot=0; - tl=0; - tr=0; - bl=0; - br=0; - if (thisEvent==PHOTON_MAX) { - receiverdata[ithread]->getFrameNumber(buff); - //iFrame=receiverdata[ithread]->getFrameNumber(buff); -#ifdef MYROOT1 - myTree[ithread]->Fill(); - //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; -#else - pthread_mutex_lock(&write_mutex); - if((enableFileWrite) && (sfilefd)) - singlePhotonDet[ithread]->writeCluster(sfilefd); - pthread_mutex_unlock(&write_mutex); -#endif - } - } - } - - nf++; -#ifndef ALLFILE - pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; - packetsCaught += packetsPerFrame; - totalPacketsCaught += packetsPerFrame; - if(packetsInFile >= maxPacketsPerFile) - createNewFile(); - pthread_mutex_unlock(&progress_mutex); - -#endif - if(!once){ - copyFrameToGui(NULL,-1,buff); - once = 1; - } - } - - remainingsize -= ((buff + ndata) - data); - data = buff + ndata; - if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) - cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuffer[0])); -#ifdef VERYVERBOSE - cout<<"buf freed:"<<(void*)wbuffer[0]<= 0){ - - tengigaEnable = enable; - - if(myDetectorType == EIGER){ - - if(!tengigaEnable){ - packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - }else{ - packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicRange * EIGER_MAX_PORTS; - onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE; - maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame*4; - } - frameSize = onePacketSize * packetsPerFrame; - bufferSize = (frameSize/EIGER_MAX_PORTS) + EIGER_HEADER_LENGTH;//everything one port gets (img header plus packets) - //maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - - - cout<<"packetsPerFrame:"< // socket(), bind(), listen(), accept(), shut down -//#include // sock_addr_in, htonl, INADDR_ANY #include // exit() #include //set precision for printing parameters for create new file #include //map -//#include //munmap - #include #include #include -#include using namespace std; #define WRITE_HEADERS @@ -789,7 +784,7 @@ void UDPStandardImplementation::resetAcquisitionCount(){ int UDPStandardImplementation::startReceiver(char *c){ FILE_LOG(logDEBUG) << __AT__ << " called"; - cout << "Starting Receiver" << endl; + FILE_LOG(logINFO) << "Stopping Receiver"; //RESET @@ -888,7 +883,7 @@ int UDPStandardImplementation::startReceiver(char *c){ void UDPStandardImplementation::stopReceiver(){ FILE_LOG(logDEBUG) << __AT__ << " called"; - cout << "Stopping Receiver" << endl; + FILE_LOG(logINFO) << "Stopping Receiver"; //set status to transmitting startReadout(); From 3b0e2e611c3733003d327d188de0307d6483a2b6 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 27 Nov 2015 15:57:19 +0100 Subject: [PATCH 183/222] jungfrau works --- .../include/UDPStandardImplementation.h | 23 --- slsReceiverSoftware/include/genericSocket.h | 4 +- slsReceiverSoftware/include/receiver_defs.h | 57 ++++++ .../include/slsReceiverTCPIPInterface.h | 3 + .../include/sls_receiver_defs.h | 1 + .../src/UDPStandardImplementation.cpp | 108 ++++++++-- .../src/slsReceiverTCPIPInterface.cpp | 186 ++++++++++++++++-- 7 files changed, 320 insertions(+), 62 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 7ec6672aae..0921ad934d 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -461,29 +461,6 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase *************************************************************************/ //**detector parameters*** - /** - * structure of an eiger packet header - * subframenum subframe number for 32 bit mode (already written by firmware) - * missingpacket explicitly put to 0xFF to recognize it in file read (written by software) - * portnum 0 for the first port and 1 for the second port (written by software to file) - * dynamicrange dynamic range or bits per pixel (written by software to file) - */ - typedef struct { - unsigned char subFameNumber[4]; - unsigned char missingPacket[2]; - unsigned char portIndex[1]; - unsigned char dynamicRange[1]; - } eiger_packet_header_t; - /** - * structure of an eiger packet footer - * framenum 48 bit frame number (already written by firmware) - * packetnum packet number (already written by firmware) - */ - typedef struct { - unsigned char frameNumber[6]; - unsigned char packetNumber[2]; - } eiger_packet_footer_t; - /** Size of 1 Frame including headers */ int frameSize; diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 97cd3223ef..3facb0a2bb 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -75,7 +75,8 @@ class sockaddr_in; using namespace std; #define DEFAULT_PACKET_SIZE 1286 -#define SOCKET_BUFFER_SIZE (100*1024*1024) //100MB +/*#define SOCKET_BUFFER_SIZE (100*1024*1024) //100MB*/ +#define SOCKET_BUFFER_SIZE (2000*1024*1024) //100MB #define DEFAULT_PORTNO 1952 #define DEFAULT_BACKLOG 5 #define DEFAULT_UDP_PORTNO 50001 @@ -578,7 +579,6 @@ enum communicationProtocol{ int ReceiveDataOnly(void* buf,int length=0){ - if (buf==NULL) return -1; diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index c11fe876d0..3cc5e80914 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -5,6 +5,43 @@ #include + +/** + * structure of an eiger packet header + * subframenum subframe number for 32 bit mode (already written by firmware) + * missingpacket explicitly put to 0xFF to recognize it in file read (written by software) + * portnum 0 for the first port and 1 for the second port (written by software to file) + * dynamicrange dynamic range or bits per pixel (written by software to file) + */ +typedef struct { + unsigned char subFrameNumber[4]; + unsigned char missingPacket[2]; + unsigned char portIndex[1]; + unsigned char dynamicRange[1]; +} eiger_packet_header_t; +/** + * structure of an eiger packet footer + * framenum 48 bit frame number (already written by firmware) + * packetnum packet number (already written by firmware) + */ +typedef struct { + unsigned char frameNumber[6]; + unsigned char packetNumber[2]; +} eiger_packet_footer_t; + +/** + * structure of an jungfrau packet header + * empty header + * framenumber + * packetnumber + */ +typedef struct { + unsigned char emptyHeader[6]; + unsigned char frameNumber[8]; + unsigned char packetNumber[8]; +} jfrau_packet_header_t; + + #define GOODBYE -200 #define DO_NOTHING 0 @@ -90,6 +127,26 @@ + +#define JFRAU_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 +#define JFRAU_PACKETS_PER_FRAME 128 +#define JFRAU_HEADER_LENGTH 22 +#define JFRAU_ONE_DATA_SIZE 8192 +#define JFRAU_ONE_PACKET_SIZE (JFRAU_HEADER_LENGTH+JFRAU_ONE_DATA_SIZE) //8214 +#define JFRAU_DATA_BYTES (JFRAU_ONE_DATA_SIZE*JFRAU_PACKETS_PER_FRAME) //8192*128 +#define JFRAU_BUFFER_SIZE (JFRAU_ONE_PACKET_SIZE*JFRAU_PACKETS_PER_FRAME) //8214*128 + + +#define JFRAU_FRAME_INDEX_MASK 0x0 //Not Applicable, use struct +#define JFRAU_FRAME_INDEX_OFFSET 0x0 //Not Applicable, use struct +#define JFRAU_PACKET_INDEX_MASK 0x0//Not Applicable, use struct + +#define JFRAU_PIXELS_IN_ONE_ROW (256*4) +#define JFRAU_PIXELS_IN_ONE_COL (256*2) +#define JFRAU_BYTES_IN_ONE_ROW (JFRAU_PIXELS_IN_ONE_ROW*2) + + + #define JCTB_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 /*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ #define JCTB_PACKETS_PER_FRAME 50 diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index b71b705f6a..237f240e67 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -176,6 +176,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** eiger specific read frame */ int eiger_read_frame(); + /** jungfrau specific read frame */ + int jungfrau_read_frame(); + /** Sets the receiver to send every nth frame to gui, or only upon gui request */ int set_read_frequency(); diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 07566ab84e..c11f6f8c02 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -24,6 +24,7 @@ typedef int int32_t; #define SHORT_MAX_FRAMES_PER_FILE 100000 #define MOENCH_MAX_FRAMES_PER_FILE 1000 #define EIGER_MAX_FRAMES_PER_FILE 2000 +#define JFRAU_MAX_FRAMES_PER_FILE 2000 #define JFCTB_MAX_FRAMES_PER_FILE 100000 diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index ec0f964cb5..fe86efd513 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -251,7 +251,7 @@ int UDPStandardImplementation::setupFifoStructure(){ int64_t i; int oldNumberofJobsPerBuffer = numberofJobsPerBuffer; //eiger always listens to 1 packet at a time - if(myDetectorType == EIGER){ + if((myDetectorType == EIGER) || (myDetectorType = JUNGFRAU)){ numberofJobsPerBuffer = 1; FILE_LOG(logDEBUG) << "Info: 1 packet per buffer"; } @@ -288,6 +288,7 @@ int UDPStandardImplementation::setupFifoStructure(){ case GOTTHARD: fifoSize = GOTTHARD_FIFO_SIZE; break; case MOENCH: fifoSize = MOENCH_FIFO_SIZE; break; case PROPIX: fifoSize = PROPIX_FIFO_SIZE; break; + case JUNGFRAU: fifoSize = JFRAU_FIFO_SIZE; break; case EIGER: fifoSize = EIGER_FIFO_SIZE * packetsPerFrame; break;//listens to 1 packet at a time and size depends on packetsperframe default: break; } @@ -717,7 +718,6 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ footerOffset = EIGER_PACKET_HEADER_SIZE + oneDataSize; break; case JUNGFRAUCTB: - case JUNGFRAU: packetsPerFrame = JCTB_PACKETS_PER_FRAME; onePacketSize = JCTB_ONE_PACKET_SIZE; //oneDataSize = Not applicable; @@ -730,6 +730,19 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ fifoSize = JCTB_FIFO_SIZE; //footerOffset = Not applicable; break; + case JUNGFRAU: + packetsPerFrame = JFRAU_PACKETS_PER_FRAME; + onePacketSize = JFRAU_ONE_PACKET_SIZE; + oneDataSize = JFRAU_DATA_BYTES; + frameSize = JFRAU_BUFFER_SIZE; + bufferSize = JFRAU_BUFFER_SIZE; + frameIndexMask = JFRAU_FRAME_INDEX_MASK; + frameIndexOffset = JFRAU_FRAME_INDEX_OFFSET; + packetIndexMask = JFRAU_PACKET_INDEX_MASK; + maxPacketsPerFile = JFRAU_MAX_FRAMES_PER_FILE * JFRAU_PACKETS_PER_FRAME; + fifoSize = JFRAU_FIFO_SIZE; + //footerOffset = Not applicable; + break; default: FILE_LOG(logERROR) << "This is an unknown receiver type " << (int)d; return FAIL; @@ -1297,9 +1310,9 @@ int UDPStandardImplementation::setupWriter(){ if (rawDataReadyCallBack){ FILE_LOG(logINFO) << "Data Write has been defined externally"; } - }else if(!fileWriteEnable) + }else if(!fileWriteEnable){ FILE_LOG(logINFO) << "Data will not be saved"; - + } //creating first file @@ -1571,6 +1584,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in int receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, lSize + cSize); + //throw away packets that is not one packet size, need to check status if socket is shut down while(status != TRANSMITTING && myDetectorType == EIGER && receivedSize != onePacketSize) { if(receivedSize != EIGER_HEADER_LENGTH) @@ -1584,13 +1598,19 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in totalListeningFrameCount[ithread] += (receivedSize/onePacketSize); #ifdef MANUALDEBUG - eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); - eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); - cprintf(GREEN,"thread:%d subframenum:%d oldpacketnum:%d new pnum:%d\n", - ithread, - (*( (unsigned int*) header->subFameNumber)), - (*( (uint8_t*) header->dynamicRange)), - (*( (uint16_t*) footer->packetNumber))); + if(myDetectorType == JUNGFRAU){ + jfrau_packet_header_t* header = (jfrau_packet_header_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); + cprintf(RED,"framenumber:%llu\n",(long long unsigned int)(*( (uint64_t*) header->frameNumber))); + cprintf(RED,"packetnumber:%llu\n",(long long unsigned int)(*( (uint64_t*) header->packetNumber))); + }else if(myDetectorType == EIGER){ + eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); + eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + cprintf(GREEN,"thread:%d subframenum:%d oldpacketnum:%d new pnum:%d\n", + ithread, + (*( (unsigned int*) header->subFrameNumber)), + (*( (uint8_t*) header->dynamicRange)), + (*( (uint16_t*) footer->packetNumber))); + } #endif @@ -1609,10 +1629,15 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " called"; //determine startFrameIndex + jfrau_packet_header_t* header=0; switch(myDetectorType){ case EIGER: startFrameIndex = 0; //frame number always resets break; + case JUNGFRAU: + header = (jfrau_packet_header_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); + startFrameIndex = (*( (uint64_t*) header->frameNumber)); + break; default: if(shortFrameEnable < 0){ startFrameIndex = (((((uint32_t)(*((uint32_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS))))+1) @@ -1741,8 +1766,10 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz int lastPacketOffset; //the offset of the last packet uint32_t lastFrameHeader; //frame number of last packet in buffer + uint64_t lastFrameHeader64; //frame number of last packet in buffer uint32_t packetCount = (packetsPerFrame/numberofListeningThreads) * numberofJobsPerBuffer; //packets received cSize = 0; //reset size + jfrau_packet_header_t* header; switch(myDetectorType){ case GOTTHARD: @@ -1802,6 +1829,44 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz } break; + + case JUNGFRAU: + lastPacketOffset = (((numberofJobsPerBuffer * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef DEBUG4 + header = (jfrau_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); + cprintf(BLUE, "Listening_Thread: First Header:%llu\t First Packet:%llu\n", + (long long unsigned int)(*( (uint64_t*) header->frameNumber)), + (long long unsigned int)(*( (uint64_t*) header->packetNumber))); +#endif + header = (jfrau_packet_header_t*) (buffer[ithread]+lastPacketOffset); +#ifdef DEBUG4 + cprintf(BLUE, "Listening_Thread: Last Header:%llu\t Last Packet:%llu\n", + (long long unsigned int)(*( (uint64_t*) header->frameNumber)), + (long long unsigned int)(*( (uint64_t*) header->packetNumber))); +#endif + //jungfrau last packet value is 0, so find the last packet and store the others in a temp storage + if(*( (uint64_t*) header->packetNumber)){ + cprintf(RED,"entering missing packet zone\n"); + lastFrameHeader64 = (*( (uint64_t*) header->frameNumber)); + cSize += onePacketSize; + lastPacketOffset -= onePacketSize; + --packetCount; + while (lastFrameHeader64 == (*( (uint64_t*) header->frameNumber))){ + cSize += onePacketSize; + lastPacketOffset -= onePacketSize; + header = (jfrau_packet_header_t*) (buffer[ithread]+lastPacketOffset); +#ifdef DEBUG4 + cprintf(RED,"new header:%llu new packet:%llu\n", + (long long unsigned int)(*( (uint64_t*) header->frameNumber)), + (long long unsigned int)(*( (uint64_t*) header->packetNumber))); +#endif + --packetCount; + } + memcpy(temp, buffer[ithread]+(lastPacketOffset+onePacketSize), cSize); + } + + break; + default: cprintf(RED,"Listening_Thread %d: Error: This detector %s is not implemented in the receiver\n", ithread, getDetectorType(myDetectorType).c_str()); @@ -2406,19 +2471,26 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //get frame number (eiger already gets it when it does packet to packet processing) - if (myDetectorType != EIGER){ - uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS)))); - //for gotthard and normal frame, increment frame number to separate fnum and pnum - if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) - tempframenumber++; - //get frame number - currentFrameNumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + if(myDetectorType != EIGER){ + if(myDetectorType == JUNGFRAU){ + jfrau_packet_header_t* header = (jfrau_packet_header_t*)(wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS); + currentFrameNumber = (*( (uint64_t*) header->frameNumber)); + }else{ + uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS)))); + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + //get frame number + currentFrameNumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + } //set indices acquisitionIndex = currentFrameNumber - startAcquisitionIndex; frameIndex = currentFrameNumber - startFrameIndex; } + + //callback to write data if (cbAction < DO_EVERYTHING){ switch(myDetectorType){ diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 4af5e04249..3cb511b873 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -817,7 +817,7 @@ int slsReceiverTCPIPInterface::start_receiver(){ // send answer socket->SendDataOnly(&ret,sizeof(ret)); if(ret==FAIL){ - cprintf(RED, "%s\n", mess); + cprintf(RED, "Error:%s\n", mess); socket->SendDataOnly(mess,sizeof(mess)); } //return ok/fail @@ -1084,6 +1084,8 @@ int slsReceiverTCPIPInterface::read_frame(){ return eiger_read_frame(); case PROPIX: return propix_read_frame(); + case JUNGFRAU: + return jungfrau_read_frame(); default: return gotthard_read_frame(); } @@ -1608,22 +1610,6 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ int slsReceiverTCPIPInterface::eiger_read_frame(){ ret=OK; - /** structure of an eiger packet*/ - typedef struct - { - unsigned char subframenum[4]; - unsigned char missingpacket[2]; - unsigned char portnum[1]; - unsigned char dynamicrange[1]; - } eiger_packet_header_t; - - typedef struct - { - unsigned char framenum[6]; - unsigned char packetnum[2]; - } eiger_packet_footer_t; - - char fName[MAX_STR_LENGTH]=""; int acquisitionIndex = -1; int frameIndex= -1; @@ -1686,7 +1672,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ if(dynamicrange == 32){ eiger_packet_header_t* wbuf_header; wbuf_header = (eiger_packet_header_t*) raw; - subframenumber = *( (uint32_t*) wbuf_header->subframenum); + subframenumber = *( (uint32_t*) wbuf_header->subFrameNumber); } #ifdef VERYVERBOSE @@ -1866,6 +1852,167 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ +int slsReceiverTCPIPInterface::jungfrau_read_frame(){ + ret=OK; + + char fName[MAX_STR_LENGTH]=""; + int acquisitionIndex = -1; + int frameIndex= -1; + uint64_t currentIndex=0; + uint64_t startAcquisitionIndex=0; + uint64_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;igetFramesCaught()){ + startAcquisitionIndex=-1; +#ifdef VERYVERBOSE + cout<<"haven't caught any frame yet"<readFrame(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"<frameNumber)); +#ifdef VERYVERBOSE + cout << "currentIndex:" << dec << currentIndex << endl; +#endif + + int64_t currentPacket = packetsPerFrame-1; + int offsetsrc = 0; + int offsetdest = 0; + uint64_t ifnum=-1; + uint64_t ipnum=-1; + + while(currentPacket >= 0){ + header = (jfrau_packet_header_t*) (origVal + offsetsrc); + ifnum = (*( (uint64_t*) header->frameNumber)); + ipnum = (*( (uint64_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 && socket->differentClients){ + FILE_LOG(logDEBUG) << "Force update"; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL){ + cprintf(RED,"%s\n",mess); + socket->SendDataOnly(mess,sizeof(mess)); + } + else{ + socket->SendDataOnly(fName,MAX_STR_LENGTH); + socket->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); + socket->SendDataOnly(&frameIndex,sizeof(frameIndex)); + socket->SendDataOnly(retval,dataSize); + } + + delete [] retval; + delete [] origVal; + delete [] raw; + + return ret; +} + + + + + + int slsReceiverTCPIPInterface::set_read_frequency(){ ret=OK; int retval=-1; @@ -2323,7 +2470,8 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; else packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange * EIGER_MAX_PORTS; - } + }else if (myDetectorType == JUNGFRAU) + packetsPerFrame = JFRAU_PACKETS_PER_FRAME; } } } From 74b1baa9d84eace60a6dde85138a8e1b8e5778db Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 27 Nov 2015 17:07:57 +0100 Subject: [PATCH 184/222] solved packet loss problem --- .../include/sls_receiver_defs.h | 2 +- .../src/UDPStandardImplementation.cpp | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index c11f6f8c02..7c500ece15 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -24,7 +24,7 @@ typedef int int32_t; #define SHORT_MAX_FRAMES_PER_FILE 100000 #define MOENCH_MAX_FRAMES_PER_FILE 1000 #define EIGER_MAX_FRAMES_PER_FILE 2000 -#define JFRAU_MAX_FRAMES_PER_FILE 2000 +#define JFRAU_MAX_FRAMES_PER_FILE 5 #define JFCTB_MAX_FRAMES_PER_FILE 100000 diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index fe86efd513..cd94e2e52f 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1393,12 +1393,15 @@ int UDPStandardImplementation::createNewFile(){ previousFrameNumber = -1; cout << "File: " << completeFileName << endl; }else{ + if (previousFrameNumber == -1) + previousFrameNumber = startFrameIndex-1; + cout << completeFileName << "\tPacket Loss: " << setw(4)<= (uint32_t)maxPacketsPerFile){ //for packet loss, because currframenum is the latest one for eiger + //get frame number (eiger already gets it when it does packet to packet processing) if(myDetectorType != EIGER){ lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); + if(myDetectorType == JUNGFRAU){ + jfrau_packet_header_t* header = (jfrau_packet_header_t*) (wbuffer[0] + lastpacket); + currentFrameNumber = (*( (uint64_t*) header->frameNumber)); + }else{ + tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + lastpacket)))); + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + //get frame number + currentFrameNumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + } + + - //get frame number (eiger already gets it when it does packet to packet processing) - tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + lastpacket)))); - //for gotthard and normal frame, increment frame number to separate fnum and pnum - if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) - tempframenumber++; - //get frame number - currentFrameNumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; //set indices acquisitionIndex = currentFrameNumber - startAcquisitionIndex; frameIndex = currentFrameNumber - startFrameIndex; From 6498292ee479ab7ebeb16c0f7de717af9f6d0f4f Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 27 Nov 2015 17:09:33 +0100 Subject: [PATCH 185/222] max packets per file forgotten at 5 --- slsReceiverSoftware/include/sls_receiver_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 7c500ece15..c11f6f8c02 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -24,7 +24,7 @@ typedef int int32_t; #define SHORT_MAX_FRAMES_PER_FILE 100000 #define MOENCH_MAX_FRAMES_PER_FILE 1000 #define EIGER_MAX_FRAMES_PER_FILE 2000 -#define JFRAU_MAX_FRAMES_PER_FILE 5 +#define JFRAU_MAX_FRAMES_PER_FILE 2000 #define JFCTB_MAX_FRAMES_PER_FILE 100000 From 34508012a8d3ed1f42f98a5de6aa4a8c71be5b46 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 1 Dec 2015 16:39:01 +0100 Subject: [PATCH 186/222] prevnumber is unsigned before bug --- slsReceiverSoftware/include/UDPStandardImplementation.h | 2 +- slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 0921ad934d..e25594f8ff 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -521,7 +521,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase uint64_t currentFrameNumber; /** Previous Frame number from buffer to calculate loss */ - uint64_t previousFrameNumber; + int64_t previousFrameNumber; /* Acquisition started */ bool acqStarted; diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 3cb511b873..87d920440e 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1938,7 +1938,7 @@ int slsReceiverTCPIPInterface::jungfrau_read_frame(){ currentPacket--; continue; } - if(ipnum!= currentPacket){ + if((int64_t)ipnum!= currentPacket){ cout << "current packet " << currentPacket << " Wrong packet number " << ipnum << ", copying blank packet" << endl; memcpy(retval+offsetdest,blackpacket,oneDataSize); offsetdest += oneDataSize; From f16db2e6ca6ee7e2ba448b67ab255edb7fec939e Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 2 Dec 2015 09:39:16 +0100 Subject: [PATCH 187/222] 10giga offset corrected --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index ec0f964cb5..d7e6989a3e 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -568,7 +568,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ frameSize = onePacketSize * packetsPerFrame; bufferSize = onePacketSize; maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; - + footerOffset = EIGER_PACKET_HEADER_SIZE + oneDataSize; FILE_LOG(logDEBUG) << dec << "packetsPerFrame:" << packetsPerFrame << "\nonePacketSize:" << onePacketSize << @@ -1586,11 +1586,12 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in #ifdef MANUALDEBUG eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); - cprintf(GREEN,"thread:%d subframenum:%d oldpacketnum:%d new pnum:%d\n", - ithread, + cprintf(GREEN,"thread:%d footeroffset:%dsubframenum:%d oldpacketnum:%d new pnum:%d new fnum:%d\n", + ithread,footerOffset, (*( (unsigned int*) header->subFameNumber)), (*( (uint8_t*) header->dynamicRange)), - (*( (uint16_t*) footer->packetNumber))); + (*( (uint16_t*) footer->packetNumber)), + (uint32_t)(*( (uint64_t*) footer))); #endif From 18eb1274c5a7151abfa77332616b2451902776ce Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 15 Dec 2015 11:04:49 +0100 Subject: [PATCH 188/222] fixed fifodepth to return defualt size, also moved destroying and creating threads to fifostructure, had forgotten to override setnumberofframes calling fifostructure which is important for gotthard --- .../include/UDPBaseImplementation.h | 5 +- slsReceiverSoftware/include/UDPInterface.h | 3 +- .../include/UDPStandardImplementation.h | 11 ++ .../src/UDPBaseImplementation.cpp | 5 +- .../src/UDPStandardImplementation.cpp | 104 ++++++++---------- 5 files changed, 63 insertions(+), 65 deletions(-) diff --git a/slsReceiverSoftware/include/UDPBaseImplementation.h b/slsReceiverSoftware/include/UDPBaseImplementation.h index 2c544759bc..568183e424 100644 --- a/slsReceiverSoftware/include/UDPBaseImplementation.h +++ b/slsReceiverSoftware/include/UDPBaseImplementation.h @@ -312,10 +312,11 @@ class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInter /** * Set Number of Frames expected by receiver from detector - * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) + * The data receiver status will change from running to idle when it gets this number of frames * @param i number of frames expected + * @return OK or FAIL */ - void setNumberOfFrames(const uint64_t i); + int setNumberOfFrames(const uint64_t i); /** * Set Dynamic Range or Number of Bits Per Pixel diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index b00f038cb4..9ad5a7e6a5 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -371,8 +371,9 @@ class UDPInterface { * Set Number of Frames expected by receiver from detector * The data receiver status will change from running to idle when it gets this number of frames FIXME: (Not implemented) * @param i number of frames expected + * @return OK or FAIL */ - virtual void setNumberOfFrames(const uint64_t i) = 0; + virtual int setNumberOfFrames(const uint64_t i) = 0; /** * Set Dynamic Range or Number of Bits Per Pixel diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 7ec6672aae..9a34f25d3a 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -102,6 +102,15 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ int setAcquisitionPeriod(const uint64_t i); + /** + * Overridden method + * Set Number of Frames expected by receiver from detector + * The data receiver status will change from running to idle when it gets this number of frames + * @param i number of frames expected + * @return OK or FAIL + */ + int setNumberOfFrames(const uint64_t i); + /** * Overridden method * Set Dynamic Range or Number of Bits Per Pixel @@ -253,6 +262,8 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** * Set up the Fifo Structure for processing buffers * between listening and writer threads + * When the parameters ahve been determined and if fifostructure needs to be changes, + * the listerning and writing threads are also destroyed together with this * @return OK or FAIL */ int setupFifoStructure(); diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 9a9b1723ad..a76cf0e9f2 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -334,11 +334,14 @@ int UDPBaseImplementation::setAcquisitionPeriod(const uint64_t i){ return OK; } -void UDPBaseImplementation::setNumberOfFrames(const uint64_t i){ +int UDPBaseImplementation::setNumberOfFrames(const uint64_t i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; numberOfFrames = i; FILE_LOG(logINFO) << "Number of Frames:" << numberOfFrames; + + //overrridden child classes might return FAIL + return OK; } int UDPBaseImplementation::setDynamicRange(const uint32_t i){ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index d7e6989a3e..36f8aa436e 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -282,23 +282,11 @@ int UDPStandardImplementation::setupFifoStructure(){ // fifo depth uint32_t oldFifoSize = fifoSize; - //default - if(!fifoDepth){ - switch(myDetectorType){ - case GOTTHARD: fifoSize = GOTTHARD_FIFO_SIZE; break; - case MOENCH: fifoSize = MOENCH_FIFO_SIZE; break; - case PROPIX: fifoSize = PROPIX_FIFO_SIZE; break; - case EIGER: fifoSize = EIGER_FIFO_SIZE * packetsPerFrame; break;//listens to 1 packet at a time and size depends on packetsperframe - default: break; - } - } - //change by user - else{ - if(myDetectorType == EIGER) - fifoSize = fifoDepth * packetsPerFrame; - else fifoSize = fifoDepth; - } + if(myDetectorType == EIGER) + fifoSize = fifoDepth * packetsPerFrame;//listens to 1 packet at a time and size depends on packetsperframe + else + fifoSize = fifoDepth; //reduce fifo depth if > 1 numberofJobsPerBuffer if(fifoSize % numberofJobsPerBuffer) @@ -313,6 +301,11 @@ int UDPStandardImplementation::setupFifoStructure(){ + //delete threads + if(threadStarted){ + createListeningThreads(true); + createWriterThreads(true); + } //set up fifo structure @@ -357,6 +350,18 @@ int UDPStandardImplementation::setupFifoStructure(){ } } cout << "Fifo structure(s) reconstructed" << endl; + + //create threads + if(createListeningThreads() == FAIL){ + FILE_LOG(logERROR) << "Could not create listening thread"; + return FAIL; + } + if(createWriterThreads() == FAIL){ + FILE_LOG(logERROR) << "Could not create writer threads"; + return FAIL; + } + setThreadPriorities(); + return OK; } @@ -483,11 +488,25 @@ int UDPStandardImplementation::setAcquisitionPeriod(const uint64_t i){ FILE_LOG(logDEBUG) << __AT__ << " called"; acquisitionPeriod = i; - if(setupFifoStructure() == FAIL) - return FAIL; + if((myDetectorType == GOTTHARD) && (myDetectorType == MOENCH)) + if(setupFifoStructure() == FAIL) + return FAIL; FILE_LOG(logINFO) << "Acquisition Period: " << (double)acquisitionPeriod/(1E9) << "s"; + return OK; +} + + +int UDPStandardImplementation::setNumberOfFrames(const uint64_t i){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + + numberOfFrames = i; + if((myDetectorType == GOTTHARD) && (myDetectorType == MOENCH)) + if(setupFifoStructure() == FAIL) + return FAIL; + + FILE_LOG(logINFO) << "Number of Frames:" << numberOfFrames; return OK; } @@ -511,30 +530,15 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ //new dynamic range, then restart threads and resetup fifo structure if(oldDynamicRange != dynamicRange){ - //delete threads - if(threadStarted){ - createListeningThreads(true); - createWriterThreads(true); - } - //gui buffer if(latestData){delete[] latestData; latestData = NULL;} latestData = new char[frameSize]; //restructure fifo + numberofJobsPerBuffer = -1; if(setupFifoStructure() == FAIL) return FAIL; - //create threads - if(createListeningThreads() == FAIL){ - FILE_LOG(logERROR) << "Could not create listening thread"; - return FAIL; - } - if(createWriterThreads() == FAIL){ - FILE_LOG(logERROR) << "Could not create writer threads"; - return FAIL; - } - setThreadPriorities(); } } @@ -582,12 +586,6 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ //new enable, then restart threads and resetup fifo structure if(oldTenGigaEnable != tengigaEnable){ - //delete threads - if(threadStarted){ - createListeningThreads(true); - createWriterThreads(true); - } - //gui buffer if(latestData){delete[] latestData; latestData = NULL;} latestData = new char[frameSize]; @@ -596,16 +594,6 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ if(setupFifoStructure() == FAIL) return FAIL; - //create threads - if(createListeningThreads() == FAIL){ - FILE_LOG(logERROR) << "Could not create listening thread"; - return FAIL; - } - if(createWriterThreads() == FAIL){ - FILE_LOG(logERROR) << "Could not create writer threads"; - return FAIL; - } - setThreadPriorities(); } } @@ -674,6 +662,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ packetIndexMask = GOTTHARD_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * GOTTHARD_PACKETS_PER_FRAME; fifoSize = GOTTHARD_FIFO_SIZE; + fifoDepth = GOTTHARD_FIFO_SIZE; //footerOffset = Not applicable; break; case PROPIX: @@ -687,6 +676,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ packetIndexMask = PROPIX_PACKET_INDEX_MASK; maxPacketsPerFile = MAX_FRAMES_PER_FILE * PROPIX_PACKETS_PER_FRAME; fifoSize = PROPIX_FIFO_SIZE; + fifoDepth = PROPIX_FIFO_SIZE; //footerOffset = Not applicable; break; case MOENCH: @@ -700,6 +690,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ packetIndexMask = MOENCH_PACKET_INDEX_MASK; maxPacketsPerFile = MOENCH_MAX_FRAMES_PER_FILE * MOENCH_PACKETS_PER_FRAME; fifoSize = MOENCH_FIFO_SIZE; + fifoDepth = MOENCH_FIFO_SIZE; //footerOffset = Not applicable; break; case EIGER: @@ -714,6 +705,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ packetIndexMask = EIGER_PACKET_INDEX_MASK; maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; fifoSize = EIGER_FIFO_SIZE; + fifoDepth = EIGER_FIFO_SIZE; footerOffset = EIGER_PACKET_HEADER_SIZE + oneDataSize; break; case JUNGFRAUCTB: @@ -728,6 +720,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ packetIndexMask = JCTB_PACKET_INDEX_MASK; maxPacketsPerFile = JFCTB_MAX_FRAMES_PER_FILE * JCTB_PACKETS_PER_FRAME; fifoSize = JCTB_FIFO_SIZE; + fifoDepth = JCTB_FIFO_SIZE; //footerOffset = Not applicable; break; default: @@ -749,17 +742,6 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ numberofJobsPerBuffer = -1; setupFifoStructure(); - //create threads - if(createListeningThreads() == FAIL){ - FILE_LOG(logERROR) << "Could not create listening thread"; - return FAIL; - } - if(createWriterThreads() == FAIL){ - FILE_LOG(logERROR) << "Could not create writer threads"; - return FAIL; - } - setThreadPriorities(); - //allocate for latest data (frame copy for gui) latestData = new char[frameSize]; From bb78d1af738dc4d9b646f3679397bbf0ed43947a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 15 Dec 2015 11:59:17 +0100 Subject: [PATCH 189/222] solved recover from root permission error --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 36f8aa436e..39d25e1ef3 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -827,7 +827,8 @@ int UDPStandardImplementation::startReceiver(char *c){ //stop udp socket shutDownUDPSockets(); sprintf(c,"Could not create file %s.",completeFileName); - FILE_LOG(logERROR) << c; + //FILE_LOG(logERROR) << c; + for(int i=0; i < numberofWriterThreads; i++) sem_post(&writerSemaphore[i]); return FAIL; } @@ -1308,8 +1309,10 @@ int UDPStandardImplementation::setupWriter(){ #endif } - FILE_LOG(logDEBUG) << "Successfully created file(s)"; - cout << "Writer Ready ..." << endl; + if(fileCreateSuccess == OK){ + FILE_LOG(logDEBUG) << "Successfully created file(s)"; + cout << "Writer Ready ..." << endl; + } return fileCreateSuccess; } From deb72feb912fcc62a49acf719e45e949e0ee499d Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 19 Jan 2016 14:39:58 +0100 Subject: [PATCH 190/222] still not resolved altho some changes --- .../src/UDPStandardImplementation.cpp | 347 ++++++++++++++---- 1 file changed, 285 insertions(+), 62 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 39d25e1ef3..682d82e19a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1964,7 +1964,10 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ blankframe[i] = new char[onePacketSize]; //set missing packet to 0xff eiger_packet_header_t* blankframe_header = (eiger_packet_header_t*) blankframe[i]; + eiger_packet_footer_t* blankframe_footer = (eiger_packet_footer_t*)(blankframe[i] + footerOffset); *( (uint16_t*) blankframe_header->missingPacket) = missingPacketValue; + *( (uint16_t*) blankframe_footer->packetNumber) = i+1; + //set each value inside blank frame to 0xff for(int j=0;j<(oneDataSize);++j){ unsigned char* blankframe_data = (unsigned char*)blankframe[i] + sizeof(eiger_packet_header_t) + j; @@ -1980,11 +1983,29 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //until mask unset (udp sockets shut down by client) while((1 << ithread) & writerThreadsMask){ + /* for(int iloop=0;ilooppacketNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber); + cprintf(MAGENTA,"Fifo %d: threadframenumber original-1:%d currentpacketnumber real:%d\n", + i,threadFrameNumber[i],currentPacketNumber[i]); } - + /* for(int iloop=0;ilooppacketNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<missingPacket)!= missingPacketValue){ eiger_packet_header_t* blankframe_header = (eiger_packet_header_t*) blankframe[blankoffset]; - cprintf(BG_RED, "Fifo %d: Missing Packet Error: Adding blank packets mismatch " + cprintf(BG_RED, "Fifo %d: Add Missing Packet Error: " "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x, missingpacket_blank 0x%x\n", i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], *( (uint16_t*) frameBuffer_header->missingPacket), *( (uint16_t*) blankframe_header->missingPacket)); exit(-1); }else{ -#ifdef DEBUG4 - cprintf(RED, "Fifo %d: Missing Packet: Adding blank packets success " - "pnum_offset %d, pnum %d, fnum_thread %d, missingpacket_buffer 0x%x\n", +//#ifdef DEBUG4 + cprintf(RED, "Fifo %d: Add Missing Packet success: " + "pnum_offset %d, pnum_got %d, fnum_thread %d, missingpacket_buffer 0x%x\n", i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], *( (uint16_t*) frameBuffer_header->missingPacket)); -#endif - frameBufferoffset[i]++; - blankoffset++; +//#endif + frameBufferoffset[i]=frameBufferoffset[i]+1; + //blankoffset++; } } + popReady[i] = false; + if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)) + fullframe[i] = true; + else + fullframe[i] = false; + if(threadFrameNumber[i] != presentFrameNumber) + threadFrameNumber[i] = presentFrameNumber; + //missed packets/future packet: do not pop over and determine fullframe-------------------- if(numberofMissingPackets[i]){ - popReady[i] = false; - if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)) - fullframe[i] = true; - else{ - fullframe[i] = false; + //popReady[i] = false; + //if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)) + // fullframe[i] = true; + //else{ + // fullframe[i] = false; //update last packet - lastPacketNumber[i] = currentPacketNumber[i] - 1; - } - if(threadFrameNumber[i] != presentFrameNumber) - threadFrameNumber[i] = presentFrameNumber; + //lastPacketNumber[i] = currentPacketNumber[i] - 1; + //} + //if(threadFrameNumber[i] != presentFrameNumber) + // threadFrameNumber[i] = presentFrameNumber; numMissingPackets += numberofMissingPackets[i]; } - //no missed packet: add current packet-------------------------------------------------------------- - else{ + /*for(int iloop=0;ilooppacketNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber),threadFrameNumber[i], *( (uint16_t*) frameBuffer_header->missingPacket)); -#endif - frameBufferoffset[i]++; +//#endif + frameBufferoffset[i]=frameBufferoffset[i]+1; //update last packet lastPacketNumber[i] = currentPacketNumber[i]; popReady[i] = true; fullframe[i] = false; if(currentPacketNumber[i] == LAST_PACKET_VALUE){ -#ifdef DEBUG4 +//#ifdef DEBUG4 cprintf(GREEN, "Fifo %d: Got last packet\n",i); -#endif +//#endif popReady[i] = false; fullframe[i] = true; } @@ -2121,15 +2243,31 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } } + /* for(int iloop=0;ilooppacketNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<isEmpty()){ @@ -2173,24 +2345,57 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ if((numPackets[i] != dummyPacketValue) && (currentPacketNumber[i] == LAST_PACKET_VALUE)) popReady[i] = true; frameBufferoffset[i] = (i*packetsPerFrame/numberofListeningThreads); - blankoffset = 0; + //blankoffset = 0; lastPacketNumber[i] = 0; currentPacketNumber[i] = 0; numberofMissingPackets[i] = 0; } + } + /* for(int iloop=0;ilooppacketNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), (void*)(packetBuffer[i])); + i,popReady[i],(uint32_t)(*( (uint64_t*) wbuf_footer1)), + *( (uint16_t*) wbuf_footer1->packetNumber), (void*)(packetBuffer[i])); } #endif + /*for(int iloop=0;ilooppacketNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + cout<packetNumber)); } -#endif +//#endif if(myDetectorType == EIGER){ while(!fifoTempFree[i]->push(wbuffer[i])); } @@ -2548,14 +2753,21 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ int port = 0, missingPacket; + bool exitVal = 0; + cprintf(GREEN,"packetsperframe:%d\n",packetsPerFrame); for (uint32_t i = 0; i < packetsPerFrame; i++){ eiger_packet_header_t* wbuf_header = (eiger_packet_header_t*) wbuffer[i]; eiger_packet_footer_t* wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset); #ifdef DEBUG4 - cprintf(GREEN, "Loop index:%d Pnum:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); + cprintf(GREEN, "Loop index:%d Pnum:%d real fnum %d,missingPacket 0x%x\n", + i, + *( (uint16_t*) wbuf_footer->packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket) + ); cout <missingPacket)== missingPacketValue){ #ifdef DEBUG4 - cprintf(GREEN,"Missing packet at %d\n", i+1); + cprintf(RED,"-Missing packet at Loop Index %d\n", i); #endif missingPacket = 1; - //add frame and packet numbers - *( (uint64_t*) wbuf_footer) = (uint64_t)((currentFrameNumber+1)); - *( (uint16_t*) wbuf_footer->packetNumber) = (i+1); + //add frame number + *( (uint64_t*) wbuf_footer) = (currentFrameNumber+1) | (((uint64_t)(*( (uint16_t*) wbuf_footer->packetNumber)))<<0x30); + //*( (uint16_t*) wbuf_footer->packetNumber) = (i+1); +#ifdef DEBUG4 + cprintf(RED, "Missing Packet Loop index:%d fnum:%d Pnum:%d\n",i, + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_footer->packetNumber)); +#endif } //normal packet else{ @@ -2579,14 +2796,20 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ //DEBUGGING if(*( (uint16_t*) wbuf_footer->packetNumber) != (i+1)){ cprintf(BG_RED, "Writing_Thread: Packet Number Mismatch! " - "i %d, pnum %d, fnum %lld, missingPacket 0x%x\n", - i,*( (uint16_t*) wbuf_footer->packetNumber),(long long int)currentFrameNumber,*( (uint16_t*) wbuf_header->missingPacket)); - exit(-1); + "i %d, real pnum %d, real fnum %d, missingPacket 0x%x\n", + i, + *( (uint16_t*) wbuf_footer->packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + exitVal =1; } //overwriting port number and dynamic range *( (uint8_t*) wbuf_header->portIndex) = port; *( (uint8_t*) wbuf_header->dynamicRange) = dynamicRange; } + + if(exitVal){exit(-1);} + } From 39c3a712e1e1750b3e8af7535bbbaecfcd4c16d1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 1 Feb 2016 17:57:43 +0100 Subject: [PATCH 191/222] solved a bit, but not the create fiel problem --- .../src/UDPStandardImplementation.cpp | 379 ++++++++++++------ 1 file changed, 262 insertions(+), 117 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 682d82e19a..b814d4c06a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -313,16 +313,20 @@ int UDPStandardImplementation::setupFifoStructure(){ //deleting if(fifoFree[i]){ - while(!fifoFree[i]->isEmpty()) + while(!fifoFree[i]->isEmpty()){ fifoFree[i]->pop(buffer[i]); + //cprintf(BLUE,"FifoFree[%d]: value:%d, pop 0x%x\n",i,fifoFree[i]->getSemValue(),(void*)(buffer[i])); + } #ifdef DEBUG5 cprintf(BLUE,"Info: %d fifostructure popped from fifofree %p\n", i, (void*)(buffer[i])); #endif delete fifoFree[i]; } if(fifo[i]){ - while(!fifo[i]->isEmpty()) + while(!fifo[i]->isEmpty()){ fifo[i]->pop(buffer[i]); + //cprintf(CYAN,"Fifo[%d]: value:%d, pop 0x%x\n",i,fifo[i]->getSemValue(),(void*)(buffer[i])); + } delete fifo[i]; } if(mem0[i]) free(mem0[i]); @@ -341,8 +345,13 @@ int UDPStandardImplementation::setupFifoStructure(){ //push free address into fifoFree buffer[i]=mem0[i]; while (buffer[i] < (mem0[i]+(bufferSize * numberofJobsPerBuffer + HEADER_SIZE_NUM_TOT_PACKETS) * (fifoSize-1))) { - fifoFree[i]->push(buffer[i]); + //cprintf(BLUE,"fifofree %d: push 0x%p\n",i,(void*)buffer[i]); + /*for(int k=0;kpush(buffer[i])); + //cprintf(GREEN,"Fifofree[%d]: value:%d, push 0x%x\n",i,fifoFree[i]->getSemValue(),(void*)(buffer[i])); #ifdef DEBUG5 cprintf(BLUE,"Info: %d fifostructure free pushed into fifofree %p\n", i, (void*)(buffer[i])); #endif @@ -897,11 +906,12 @@ void UDPStandardImplementation::stopReceiver(){ int UDPStandardImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " called"; - FILE_LOG(logDEBUG) << "Info: Shutting down UDP Socket(s)"; + for(int i=0;iShutDownSocket(); + FILE_LOG(logINFO) << "Info: Shut down UDP Socket " << i << endl; delete udpSocket[i]; udpSocket[i] = NULL; } @@ -934,9 +944,9 @@ void UDPStandardImplementation::startReadout(){ prev = -1; //wait as long as there is change from prev totalP while(prev != totalP){ -#ifdef DEBUG5 +//#ifdef DEBUG5 cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP); -#endif +//#endif usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/ prev = totalP; @@ -1476,6 +1486,11 @@ void UDPStandardImplementation::startListening(){ //pop from fifo fifoFree[ithread]->pop(buffer[ithread]); + +#ifdef EVERYFIFODEBUG + if(fifoFree[ithread]->getSemValue()<100) + cprintf(BLUE,"FifoFree[%d]: value:%d, pop 0x%x\n",ithread,fifoFree[ithread]->getSemValue(),(void*)(buffer[ithread])); +#endif #ifdef CFIFODEBUG if(ithread == 0) cprintf(CYAN,"Listening_Thread %d :Listener popped from fifofree %p\n", ithread, (void*)(buffer[ithread])); @@ -1492,7 +1507,6 @@ void UDPStandardImplementation::startListening(){ rc = prepareAndListenBuffer(ithread, listenSize, carryonBufferSize, tempBuffer); - //start indices for each start of scan/acquisition if((!measurementStarted) && (rc > 0)){ pthread_mutex_lock(&progressMutex); @@ -1518,6 +1532,10 @@ void UDPStandardImplementation::startListening(){ //push buffer to FIFO while(!fifo[ithread]->push(buffer[ithread])); +#ifdef EVERYFIFODEBUG + if(fifo[ithread]->getSemValue()>(fifoSize-100)) + cprintf(MAGENTA,"Fifo[%d]: value:%d, push 0x%x\n",ithread,fifo[ithread]->getSemValue(),(void*)(buffer[ithread])); +#endif #ifdef CFIFODEBUG if(ithread == 0) cprintf(CYAN,"Listening_Thread %d: Listener pushed into fifo %p\n",ithread, (void*)(buffer[ithread])); @@ -1549,6 +1567,7 @@ void UDPStandardImplementation::startListening(){ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, int cSize, char* temp){ FILE_LOG(logDEBUG) << __AT__ << " called"; + int testbit = 0; //listen to UDP packets if(cSize) @@ -1558,8 +1577,11 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in //throw away packets that is not one packet size, need to check status if socket is shut down while(status != TRANSMITTING && myDetectorType == EIGER && receivedSize != onePacketSize) { - if(receivedSize != EIGER_HEADER_LENGTH) + if(receivedSize != EIGER_HEADER_LENGTH){ cprintf(RED,"Listening_Thread %d: Listened to a weird packet size %d\n",ithread, receivedSize); + }/*else{ + testbit = 1; + }*/ #ifdef DEBUG else cprintf(BLUE,"Listening_Thread %d: Listened to a header packet\n",ithread); @@ -1567,6 +1589,11 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); } totalListeningFrameCount[ithread] += (receivedSize/onePacketSize); + /*if(testbit == 1){ + testbit = 0; + eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + cprintf(CYAN,"Listening_Thread %d: fnum:%d\n",ithread,(uint32_t)(*( (uint64_t*) footer))); + }*/ #ifdef MANUALDEBUG eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); @@ -1631,9 +1658,9 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG) << __AT__ << " called"; -#ifdef DEBUG4 - cprintf(BLUE,"Listening_Thread %d: Stop Listening\nStatus: %s\n", ithread, runStatusType(status).c_str()); -#endif +//#ifdef DEBUG4 + cprintf(BG_RED,"Listening_Thread %d: Stop Listening\nStatus: %s numbytes:%d\n", ithread, runStatusType(status).c_str(),numbytes); +//#endif //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) if(numbytes < onePacketSize) @@ -1644,6 +1671,10 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ if(numbytes <= 0){ cprintf(BLUE,"Listening_Thread %d :End of Acquisition\n", ithread); while(!fifoFree[ithread]->push(buffer[ithread])); +#ifdef EVERYFIFODEBUG + if(fifoFree[ithread]->getSemValue()<100) + cprintf(GREEN,"Fifofree[%d]: value:%d, push 0x%x\n",ithread,fifoFree[ithread]->getSemValue(),(void*)(buffer[ithread])); +#endif #ifdef CFIFODEBUG if(ithread == 0) cprintf(CYAN,"Listening_Thread %d :Listener push empty buffer into fifofree %p\n", ithread, (void*)(buffer[ithread])); @@ -1657,11 +1688,15 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ else{ (*((uint32_t*)(buffer[ithread]))) = numbytes/onePacketSize; totalListeningFrameCount[ithread] += (numbytes/onePacketSize); -#ifdef DEBUG +//#ifdef DEBUG cprintf(BLUE,"Listening_Thread %d: Last Buffer numBytes:%d\n",ithread, numbytes); cprintf(BLUE,"Listening_Thread %d: Last Buffer packet count:%d\n",ithread, numbytes/onePacketSize); -#endif +//#endif while(!fifo[ithread]->push(buffer[ithread])); +#ifdef EVERYFIFODEBUG + if(fifo[ithread]->getSemValue()>(fifoSize-100)) + cprintf(MAGENTA,"Fifo[%d]: value:%d, push 0x%x\n",ithread,fifo[ithread]->getSemValue(),(void*)(buffer[ithread])); +#endif #ifdef CFIFODEBUG if(ithread == 0) cprintf(CYAN,"Listening_Thread %d: Listener Last Buffer pushed into fifo %p\n", ithread,(void*)(buffer[ithread])); @@ -1673,6 +1708,10 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ //push dummy-end buffer into fifo for all writer threads for(int i=0; ipop(buffer[ithread]); +#ifdef EVERYFIFODEBUG + if(fifoFree[ithread]->getSemValue()<100) + cprintf(BLUE,"FifoFree[%d]: value:%d, pop 0x%x\n",ithread,fifoFree[ithread]->getSemValue(),(void*)(buffer[ithread])); +#endif #ifdef CFIFODEBUG if(ithread == 0) cprintf(CYAN,"Listening_Thread %d: Popped Dummy from fifoFree %p\n", ithread,(void*)(buffer[ithread])); @@ -1682,6 +1721,10 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ //creating dummy-end buffer with pc=0xFFFF (*((uint32_t*)(buffer[ithread]))) = dummyPacketValue; while(!fifo[ithread]->push(buffer[ithread])); +#ifdef EVERYFIFODEBUG + if(fifo[ithread]->getSemValue()>(fifoSize-100)) + cprintf(MAGENTA,"Fifo[%d]: value:%d, push 0x%x\n",ithread,fifo[ithread]->getSemValue(),(void*)(buffer[ithread])); +#endif #ifdef CFIFODEBUG if(ithread == 0) cprintf(CYAN,"Listening_Thread %d: Listener pushed dummy-end buffer into fifo %p\n", ithread,(void*)(buffer[ithread])); @@ -1850,6 +1893,10 @@ void UDPStandardImplementation::processWritingBuffer(int ithread){ while((1 << ithread) & writerThreadsMask){ //pop fifo[0]->pop(wbuf[0]); +#ifdef EVERYFIFODEBUG + if(fifo[0]->getSemValue()>(fifoSize-100)) + cprintf(CYAN,"Fifo[%d]: value:%d, pop 0x%x\n",0,fifo[0]->getSemValue(),(void*)(wbuf[0])); +#endif #ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuf[0]),0); #endif @@ -1952,8 +1999,13 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //circular temp fifo between getting a whole frame and freeing them if(fifoTempFree[i]){ - while(!fifoTempFree[i]->isEmpty()) + while(!fifoTempFree[i]->isEmpty()){ fifoTempFree[i]->pop(temp); +#ifdef EVERYFIFODEBUG + if(fifoTempFree[i]->getSemValue()>((packetsPerFrame/numberofListeningThreads)-3)) + cprintf(RED,"FifoTempFree[%d]: value:%d, pop 0x%x\n",i,fifoTempFree[i]->getSemValue(),(void*)(temp)); +#endif + } delete fifoTempFree[i]; } fifoTempFree[i] = new CircularFifo(MAX_NUM_PACKETS); @@ -1983,29 +2035,34 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //until mask unset (udp sockets shut down by client) while((1 << ithread) & writerThreadsMask){ - /* for(int iloop=0;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); + *( (uint16_t*) wbuf_header->missingPacket), + (void*)frameBuffer[iloop]); cout<packetNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); + *( (uint16_t*) wbuf_header->missingPacket), + (void*)frameBuffer[iloop]); cout<packetNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); @@ -2023,13 +2084,13 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } for(int iloop=64;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); cout<packetNumber); - cprintf(MAGENTA,"Fifo %d: threadframenumber original-1:%d currentpacketnumber real:%d\n", +#ifdef DEBUG4 + cprintf(MAGENTA,"Fifo %d: threadframenumber original:%d currentpacketnumber real:%d\n", i,threadFrameNumber[i],currentPacketNumber[i]); +#endif } - /* for(int iloop=0;ilooppacketNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); cout<packetNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); cout<packetNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); cout<packetNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); cout<missingPacket)!= missingPacketValue){ @@ -2156,12 +2206,12 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ *( (uint16_t*) blankframe_header->missingPacket)); exit(-1); }else{ -//#ifdef DEBUG4 +#ifdef DEBUG4 cprintf(RED, "Fifo %d: Add Missing Packet success: " "pnum_offset %d, pnum_got %d, fnum_thread %d, missingpacket_buffer 0x%x\n", i,frameBufferoffset[i],currentPacketNumber[i],threadFrameNumber[i], *( (uint16_t*) frameBuffer_header->missingPacket)); -//#endif +#endif frameBufferoffset[i]=frameBufferoffset[i]+1; //blankoffset++; } @@ -2189,25 +2239,26 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ // threadFrameNumber[i] = presentFrameNumber; numMissingPackets += numberofMissingPackets[i]; } - - /*for(int iloop=0;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); cout<packetNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); cout<push(packetBuffer[i])); +#ifdef EVERYFIFODEBUG + if(fifoTempFree[i]->getSemValue()>((packetsPerFrame/numberofListeningThreads)-3)) + cprintf(YELLOW,"FifoTempfree[%d]: value:%d, push 0x%x\n",i,fifoTempFree[i]->getSemValue(),(void*)(wbuffer[i])); +#endif + + + + //cprintf(RED,"Current Packet frameBufferoffset[i]:%d\n",frameBufferoffset[i]); + frameBuffer[frameBufferoffset[i]] = (packetBuffer[i] + HEADER_SIZE_NUM_TOT_PACKETS); +#ifdef DEBUG4 eiger_packet_header_t* frameBuffer_header = (eiger_packet_header_t*) frameBuffer[frameBufferoffset[i]]; eiger_packet_footer_t* frameBuffer_footer = (eiger_packet_footer_t*) (frameBuffer[frameBufferoffset[i]] + footerOffset); cprintf(GREEN, "Fifo %d: Current Packet added success:" "pnum_offset %d, pnum %d, real pnum %d fnum_thread %d, missingpacket_buffer 0x%x\n", i,frameBufferoffset[i],currentPacketNumber[i],*( (uint16_t*) frameBuffer_footer->packetNumber),threadFrameNumber[i], *( (uint16_t*) frameBuffer_header->missingPacket)); -//#endif +#endif frameBufferoffset[i]=frameBufferoffset[i]+1; //update last packet lastPacketNumber[i] = currentPacketNumber[i]; popReady[i] = true; fullframe[i] = false; if(currentPacketNumber[i] == LAST_PACKET_VALUE){ -//#ifdef DEBUG4 +#ifdef DEBUG4 cprintf(GREEN, "Fifo %d: Got last packet\n",i); -//#endif +#endif popReady[i] = false; fullframe[i] = true; - } - } - } - } + } //end of last packet + }//end of add current packet + }//end of if(!fullframe) + }//end of for listening threads - /* for(int iloop=0;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); @@ -2253,7 +2314,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } for(int iloop=64;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); @@ -2265,9 +2326,21 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ currentFrameNumber = presentFrameNumber; numTotMissingPacketsInFile += numMissingPackets; numTotMissingPackets += numMissingPackets; -//#ifdef FNUM_DEBUG + + + cprintf(GREEN,"**framenum:%lld\n ",(long long int)currentFrameNumber); + for(int i=0;ipacketNumber), (void*)(packetBuffer[i])); + } +#ifdef DEBUG4 + cprintf(BLUE," nummissingpackets:%d\n",numMissingPackets); +#endif +#ifdef FNUM_DEBUG cprintf(GREEN,"**fnum:%lld**\n",(long long int)currentFrameNumber); -//#endif +#endif #ifdef MISSINGP_DEBUG if(numMissingPackets){ cprintf(RED, "Total missing packets %d for fnum %d\n",numMissingPackets,currentFrameNumber); @@ -2280,7 +2353,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ #endif /* for(int iloop=0;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); @@ -2288,19 +2361,20 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } for(int iloop=64;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); cout<packetNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); @@ -2308,7 +2382,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } for(int iloop=64;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); @@ -2320,7 +2394,15 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ for(int i=0; iisEmpty()){ fifoTempFree[i]->pop(temp); - fifoFree[i]->push(temp); +#ifdef EVERYFIFODEBUG + if(fifoTempFree[i]->getSemValue()>((packetsPerFrame/numberofListeningThreads)-3)) + cprintf(GRAY,"FifoTempFree[%d]: value:%d, pop 0x%x\n",i,fifoTempFree[i]->getSemValue(),(void*)(temp)); +#endif + while(!fifoFree[i]->push(temp)); +#ifdef EVERYFIFODEBUG + if(fifoFree[i]->getSemValue()<100) + cprintf(GREEN,"FifoFree[%d]: value:%d, push 0x%x\n",i,fifoFree[i]->getSemValue(),(void*)(temp)); +#endif #ifdef CFIFODEBUG if(i==0) cprintf(CYAN,"Fifo %d: Writing_Thread freed: pushed into fifofree %p\n",i, (void*)(temp)); @@ -2341,8 +2423,13 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ presentFrameNumber++; for(int i=0; ipacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); @@ -2365,7 +2452,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } for(int iloop=64;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); @@ -2382,18 +2469,20 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ #endif /*for(int iloop=0;ilooppacketNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); + *( (uint16_t*) wbuf_header->missingPacket), + (void*)frameBuffer[iloop]); cout<packetNumber), (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); + *( (uint16_t*) wbuf_header->missingPacket), + (void*)frameBuffer[iloop]); cout<isEmpty()){ - cout << ithread << ":emptied buffer in fifo" << endl; + cprintf(RED,"%d:emptied buffer in fifo\n", ithread); fifo[ithread]->pop(temp); +#ifdef EVERYFIFODEBUG + if(fifo[ithread]->getSemValue()>(fifoSize-100)) + cprintf(CYAN,"Fifo[%d]: value:%d, pop 0x%x\n",ithread,fifo[ithread]->getSemValue(),(void*)(temp)); +#endif } //create file @@ -2481,6 +2574,10 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w //pop if ready if(ready[i]){ fifo[i]->pop(wbuffer[i]); +#ifdef EVERYFIFODEBUG + if(fifo[i]->getSemValue()>(fifoSize-100)) + cprintf(CYAN,"Fifo[%d]: value:%d, pop 0x%x\n",i,fifo[i]->getSemValue(),(void*)(wbuffer[i])); +#endif #ifdef CFIFODEBUG if(i == 0) cprintf(CYAN,"Writing_Thread %d: Popped %p from FIFO %d\n", ithread, (void*)(wbuffer[i]),i); @@ -2494,24 +2591,31 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w //dummy-end buffer if(nP[i] == dummyPacketValue){ ready[i] = false; -#ifdef DEBUG3 +//#ifdef DEBUG3 cprintf(GREEN,"Writing_Thread %d: Dummy frame popped out of FIFO %d",ithread, i); -#endif +//#endif } //normal buffer popped out else{ endofAcquisition = false; -//#ifdef DEBUG4 +#ifdef DEBUG4 if(myDetectorType == EIGER){ eiger_packet_footer_t* wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); //cprintf(BLUE,"footer value:0x%x\n",i,(uint64_t)(*( (uint64_t*) wbuf_footer))); + //if(*( (uint16_t*) wbuf_footer->packetNumber) == 1){ cprintf(BLUE,"Fnum[%d]:%d\n",i,(uint32_t)(*( (uint64_t*) wbuf_footer))); cprintf(BLUE,"Pnum[%d]:%d\n",i,*( (uint16_t*) wbuf_footer->packetNumber)); + //} } -//#endif - if(myDetectorType == EIGER){ +#endif + /*moved to current packet addition + * if(myDetectorType == EIGER){ while(!fifoTempFree[i]->push(wbuffer[i])); - } +#ifdef EVERYFIFODEBUG + if(fifoTempFree[i]->getSemValue()>((packetsPerFrame/numberofListeningThreads)-3)) + cprintf(YELLOW,"FifoTempfree[%d]: value:%d, push 0x%x\n",i,fifoTempFree[i]->getSemValue(),(void*)(wbuffer[i])); +#endif + }*/ } } //when both are not popped but curretn frame number is being processed @@ -2534,6 +2638,10 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //free fifo for(int i=0; ipush(wbuffer[i])); +#ifdef EVERYFIFODEBUG + if(fifoFree[i]->getSemValue()<100) + cprintf(GREEN,"FifoFree[%d]: value:%d, push 0x%x\n",i,fifoFree[i]->getSemValue(),(void*)(wbuffer[i])); +#endif #ifdef CFIFODEBUG if(i==0) cprintf(CYAN,"Writing_Thread %d: Freeing dummy-end buffer. Pushed into fifofree %p for listener %d\n", ithread,(void*)(wbuffer[i]),i); @@ -2633,16 +2741,20 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //copy frame for gui - if(npackets >= packetsPerFrame) + /*if(npackets >= packetsPerFrame) copyFrameToGui(wbuffer); #ifdef DEBUG4 cprintf(GREEN,"Writing_Thread: Copied frame\n"); -#endif +#endif*/ //free fifo addresses (eiger frees for each packet later) if(myDetectorType != EIGER){ while(!fifoFree[0]->push(wbuffer[0])); +#ifdef EVERYFIFODEBUG + if(fifoFree[0]->getSemValue()<100) + cprintf(GREEN,"FifoFree[%d]: value:%d, push 0x%x\n",0,fifoFree[0]->getSemValue(),(void*)(wbuffer[0])); +#endif #ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Freed buffer, pushed into fifofree %p for listener 0\n",ithread, (void*)(wbuffer[0])); #endif @@ -2723,6 +2835,7 @@ void UDPStandardImplementation::writeFileWithoutCompression(char* wbuffer[],uint #ifdef DEBUG3 cprintf(GREEN,"Writing_Thread: Current Frame Number:%d\n",currentFrameNumber); #endif + cprintf(BG_RED,"CREATE NEW FILE %lld \n",(long long int)currentFrameNumber );exit(-1); createNewFile(); } @@ -2754,13 +2867,14 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ int port = 0, missingPacket; bool exitVal = 0; + eiger_packet_header_t* wbuf_header; + eiger_packet_footer_t* wbuf_footer; - cprintf(GREEN,"packetsperframe:%d\n",packetsPerFrame); for (uint32_t i = 0; i < packetsPerFrame; i++){ - eiger_packet_header_t* wbuf_header = (eiger_packet_header_t*) wbuffer[i]; - eiger_packet_footer_t* wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset); + wbuf_header = (eiger_packet_header_t*) wbuffer[i]; + wbuf_footer = (eiger_packet_footer_t*)(wbuffer[i] + footerOffset); #ifdef DEBUG4 cprintf(GREEN, "Loop index:%d Pnum:%d real fnum %d,missingPacket 0x%x\n", i, @@ -2778,8 +2892,20 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ cprintf(RED,"-Missing packet at Loop Index %d\n", i); #endif missingPacket = 1; + + //DEBUGGING + if(*( (uint16_t*) wbuf_footer->packetNumber) != (i+1)){ + cprintf(BG_RED, "Writing_Thread: Packet Number Mismatch (missing p)! " + "i %d, real pnum %d, real fnum %d, missingPacket 0x%x\n", + i, + *( (uint16_t*) wbuf_footer->packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + exitVal =1; + } + //add frame number - *( (uint64_t*) wbuf_footer) = (currentFrameNumber+1) | (((uint64_t)(*( (uint16_t*) wbuf_footer->packetNumber)))<<0x30); + /**( (uint64_t*) wbuf_footer) = (currentFrameNumber+1) | (((uint64_t)(*( (uint16_t*) wbuf_footer->packetNumber)))<<0x30);*/ //*( (uint16_t*) wbuf_footer->packetNumber) = (i+1); #ifdef DEBUG4 cprintf(RED, "Missing Packet Loop index:%d fnum:%d Pnum:%d\n",i, @@ -2790,10 +2916,25 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ //normal packet else{ missingPacket = 0; + + //DEBUGGING + if(*( (uint16_t*) wbuf_footer->packetNumber) != ( (i>((packetsPerFrame/2)-1)?(i-(packetsPerFrame/2)+1):i+1) )){ + cprintf(BG_RED, "Writing_Thread: Packet Number Mismatch! " + "i %d, real pnum %d, real fnum %d, missingPacket 0x%x\n", + i, + *( (uint16_t*) wbuf_footer->packetNumber), + (uint32_t)(*( (uint64_t*) wbuf_footer)), + *( (uint16_t*) wbuf_header->missingPacket)); + exitVal =1; + } + + /*uint16_t p = *( (uint16_t*) wbuf_footer->packetNumber); //correct the packet numbers of port2 so that port1 and 2 are not the same - if(port) *( (uint16_t*) wbuf_footer->packetNumber) = (*( (uint16_t*) wbuf_footer->packetNumber))+(packetsPerFrame/2); + if(port) *( (uint16_t*) wbuf_footer->packetNumber) = (p +(packetsPerFrame/2));*/ + } - //DEBUGGING + + /*//DEBUGGING if(*( (uint16_t*) wbuf_footer->packetNumber) != (i+1)){ cprintf(BG_RED, "Writing_Thread: Packet Number Mismatch! " "i %d, real pnum %d, real fnum %d, missingPacket 0x%x\n", @@ -2802,10 +2943,10 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); exitVal =1; - } + }*/ //overwriting port number and dynamic range - *( (uint8_t*) wbuf_header->portIndex) = port; - *( (uint8_t*) wbuf_header->dynamicRange) = dynamicRange; + /**( (uint8_t*) wbuf_header->portIndex) = (uint8_t)port; + *( (uint8_t*) wbuf_header->dynamicRange) = (uint8_t)dynamicRange;*/ } if(exitVal){exit(-1);} @@ -2997,6 +3138,10 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer while(!fifoFree[0]->push(wbuffer[0])); +#ifdef EVERYFIFODEBUG + if(fifoFree[0]->getSemValue()<100) + cprintf(GREEN,"FifoFree[%d]: value:%d, push 0x%x\n",0,fifoFree[0]->getSemValue(),(void*)(wbuffer[0])); +#endif #ifdef DEBUG5 cprintf(GREEN,"Writing_Thread %d: Compression free pushed into fifofree %p for listerner 0\n", ithread, (void*)(wbuffer[0])); #endif From 3045876a86e4deb7551f3bade9f06a89f8d9efa8 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 2 Feb 2016 17:33:57 +0100 Subject: [PATCH 192/222] solved bug problem --- .../src/UDPStandardImplementation.cpp | 295 +++--------------- 1 file changed, 49 insertions(+), 246 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index b814d4c06a..899e69e25e 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -861,8 +861,8 @@ int UDPStandardImplementation::startReceiver(char *c){ for(int i=0;iShutDownSocket(); - FILE_LOG(logINFO) << "Info: Shut down UDP Socket " << i << endl; + FILE_LOG(logINFO) << "Shut down UDP Socket " << i; delete udpSocket[i]; udpSocket[i] = NULL; } @@ -929,7 +929,7 @@ int UDPStandardImplementation::shutDownUDPSockets(){ void UDPStandardImplementation::startReadout(){ FILE_LOG(logDEBUG) << __AT__ << " called"; - FILE_LOG(logDEBUG) << "Info: Transmitting last data"; + FILE_LOG(logDEBUG) << "Transmitting last data"; if(status == RUNNING){ @@ -944,9 +944,9 @@ void UDPStandardImplementation::startReadout(){ prev = -1; //wait as long as there is change from prev totalP while(prev != totalP){ -//#ifdef DEBUG5 +#ifdef DEBUG5 cprintf(MAGENTA,"waiting for all packets totalP:%d\n",totalP); -//#endif +#endif usleep(5000);/* Need to find optimal time (exposure time and acquisition period) **/ prev = totalP; @@ -963,7 +963,8 @@ void UDPStandardImplementation::startReadout(){ pthread_mutex_lock(&statusMutex); status = TRANSMITTING; pthread_mutex_unlock(&statusMutex); - cout << "Status: Transmitting" << endl; + + FILE_LOG(logINFO) << "Status: Transmitting"; } //shut down udp sockets and make listeners push dummy (end) packets for writers @@ -1658,9 +1659,9 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ FILE_LOG(logDEBUG) << __AT__ << " called"; -//#ifdef DEBUG4 - cprintf(BG_RED,"Listening_Thread %d: Stop Listening\nStatus: %s numbytes:%d\n", ithread, runStatusType(status).c_str(),numbytes); -//#endif +#ifdef DEBUG4 + cprintf(BLUE,"Listening_Thread %d: Stop Listening\nStatus: %s numbytes:%d\n", ithread, runStatusType(status).c_str(),numbytes); +#endif //less than 1 packet size (especially for eiger), ignore the buffer (so that 2 dummy buffers are not sent with pc=0) if(numbytes < onePacketSize) @@ -1669,7 +1670,7 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ //free empty buffer if(numbytes <= 0){ - cprintf(BLUE,"Listening_Thread %d :End of Acquisition\n", ithread); + FILE_LOG(logINFO) << "Listening "<< ithread << ": End of Acquisition"; while(!fifoFree[ithread]->push(buffer[ithread])); #ifdef EVERYFIFODEBUG if(fifoFree[ithread]->getSemValue()<100) @@ -1688,10 +1689,10 @@ void UDPStandardImplementation::stopListening(int ithread, int numbytes){ else{ (*((uint32_t*)(buffer[ithread]))) = numbytes/onePacketSize; totalListeningFrameCount[ithread] += (numbytes/onePacketSize); -//#ifdef DEBUG +#ifdef DEBUG cprintf(BLUE,"Listening_Thread %d: Last Buffer numBytes:%d\n",ithread, numbytes); cprintf(BLUE,"Listening_Thread %d: Last Buffer packet count:%d\n",ithread, numbytes/onePacketSize); -//#endif +#endif while(!fifo[ithread]->push(buffer[ithread])); #ifdef EVERYFIFODEBUG if(fifo[ithread]->getSemValue()>(fifoSize-100)) @@ -2035,27 +2036,6 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ //until mask unset (udp sockets shut down by client) while((1 << ithread) & writerThreadsMask){ - /* - for(int iloop=0;ilooppacketNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket), - (void*)frameBuffer[iloop]); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket), - (void*)frameBuffer[iloop]); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<500){ + cprintf(BG_RED,"too high frame number %lld \n",(long long int)currentFrameNumber ); + exit(-1); + } for(int i=0;ipacketNumber), (void*)(packetBuffer[i])); - } + }*/ #ifdef DEBUG4 cprintf(BLUE," nummissingpackets:%d\n",numMissingPackets); #endif @@ -2351,43 +2245,31 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } } #endif - /* for(int iloop=0;ilooppacketNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket)); - cout<packetNumber), (void*)(packetBuffer[i])); - } -#endif - /*for(int iloop=0;ilooppacketNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket), - (void*)frameBuffer[iloop]); - cout<packetNumber), - (uint32_t)(*( (uint64_t*) wbuf_footer)), - *( (uint16_t*) wbuf_header->missingPacket), - (void*)frameBuffer[iloop]); - cout<push(wbuffer[i])); -#ifdef EVERYFIFODEBUG - if(fifoTempFree[i]->getSemValue()>((packetsPerFrame/numberofListeningThreads)-3)) - cprintf(YELLOW,"FifoTempfree[%d]: value:%d, push 0x%x\n",i,fifoTempFree[i]->getSemValue(),(void*)(wbuffer[i])); -#endif - }*/ } } //when both are not popped but curretn frame number is being processed @@ -2633,7 +2437,7 @@ bool UDPStandardImplementation::popAndCheckEndofAcquisition(int ithread, char* w void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; - cprintf(GREEN,"Info: Writing_Thread %d: End of Acquisition\n",ithread); + FILE_LOG(logINFO) << "Writing "<< ithread << ": End of Acquisition"; //free fifo for(int i=0; i Date: Tue, 2 Feb 2016 18:52:24 +0100 Subject: [PATCH 193/222] all changes done --- .../src/UDPStandardImplementation.cpp | 54 ++++++------------- 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 899e69e25e..3c02520087 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1568,7 +1568,6 @@ void UDPStandardImplementation::startListening(){ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, int cSize, char* temp){ FILE_LOG(logDEBUG) << __AT__ << " called"; - int testbit = 0; //listen to UDP packets if(cSize) @@ -1580,9 +1579,7 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in while(status != TRANSMITTING && myDetectorType == EIGER && receivedSize != onePacketSize) { if(receivedSize != EIGER_HEADER_LENGTH){ cprintf(RED,"Listening_Thread %d: Listened to a weird packet size %d\n",ithread, receivedSize); - }/*else{ - testbit = 1; - }*/ + } #ifdef DEBUG else cprintf(BLUE,"Listening_Thread %d: Listened to a header packet\n",ithread); @@ -1590,11 +1587,6 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); } totalListeningFrameCount[ithread] += (receivedSize/onePacketSize); - /*if(testbit == 1){ - testbit = 0; - eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); - cprintf(CYAN,"Listening_Thread %d: fnum:%d\n",ithread,(uint32_t)(*( (uint64_t*) footer))); - }*/ #ifdef MANUALDEBUG eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); @@ -2099,7 +2091,7 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ numberofMissingPackets[i] = (LAST_PACKET_VALUE - lastPacketNumber[i]); else numberofMissingPackets[i] = (currentPacketNumber[i] - lastPacketNumber[i] - 1); - + numMissingPackets += numberofMissingPackets[i]; #ifdef DEBUG4 if(numPackets[i] == dummyPacketValue) @@ -2118,7 +2110,6 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ for(int j=0;jmissingPacket)!= missingPacketValue){ @@ -2137,10 +2128,10 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ *( (uint16_t*) frameBuffer_header->missingPacket)); #endif frameBufferoffset[i]=frameBufferoffset[i]+1; - //blankoffset++; } } + //missed packets/future packet: do not pop over and determine fullframe-------------------- popReady[i] = false; if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)) fullframe[i] = true; @@ -2149,24 +2140,8 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ if(threadFrameNumber[i] != presentFrameNumber) threadFrameNumber[i] = presentFrameNumber; - //missed packets/future packet: do not pop over and determine fullframe-------------------- - if(numberofMissingPackets[i]){ - //popReady[i] = false; - //if((numPackets[i] == dummyPacketValue) ||(threadFrameNumber[i] != presentFrameNumber)) - // fullframe[i] = true; - //else{ - // fullframe[i] = false; - //update last packet - //lastPacketNumber[i] = currentPacketNumber[i] - 1; - //} - //if(threadFrameNumber[i] != presentFrameNumber) - // threadFrameNumber[i] = presentFrameNumber; - numMissingPackets += numberofMissingPackets[i]; - } - //add current packet-------------------------------------------------------------- - if(fullframe[i] == false){ if(currentPacketNumber[i] != (uint32_t)(frameBufferoffset[i]-(i*packetsPerFrame/numberofListeningThreads))+1){ cprintf(BG_RED, "Fifo %d: Correct Packet Offset Error: " @@ -2545,11 +2520,11 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* //copy frame for gui - /*if(npackets >= packetsPerFrame) + if(npackets >= packetsPerFrame) copyFrameToGui(wbuffer); #ifdef DEBUG4 cprintf(GREEN,"Writing_Thread: Copied frame\n"); -#endif*/ +#endif //free fifo addresses (eiger frees for each packet later) @@ -2708,8 +2683,8 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ } //add frame number - /**( (uint64_t*) wbuf_footer) = (currentFrameNumber+1) | (((uint64_t)(*( (uint16_t*) wbuf_footer->packetNumber)))<<0x30);*/ - //*( (uint16_t*) wbuf_footer->packetNumber) = (i+1); + ( (uint64_t*) wbuf_footer) = (currentFrameNumber+1) | (((uint64_t)(*( (uint16_t*) wbuf_footer->packetNumber)))<<0x30); + //*( (uint16_t*) wbuf_footer->packetNumber) = (i+1); // missing frames already have the right packet number #ifdef DEBUG4 cprintf(RED, "Missing Packet Loop index:%d fnum:%d Pnum:%d\n",i, (uint32_t)(*( (uint64_t*) wbuf_footer)), @@ -2731,13 +2706,17 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ exitVal =1; } - /*uint16_t p = *( (uint16_t*) wbuf_footer->packetNumber); + uint16_t p = *( (uint16_t*) wbuf_footer->packetNumber); //correct the packet numbers of port2 so that port1 and 2 are not the same - if(port) *( (uint16_t*) wbuf_footer->packetNumber) = (p +(packetsPerFrame/2));*/ + if(port) *( (uint16_t*) wbuf_footer->packetNumber) = (p +(packetsPerFrame/2)); } - /*//DEBUGGING + //overwriting port number and dynamic range + ( (uint8_t*) wbuf_header->portIndex) = (uint8_t)port; + *( (uint8_t*) wbuf_header->dynamicRange) = (uint8_t)dynamicRange; + + //DEBUGGING if(*( (uint16_t*) wbuf_footer->packetNumber) != (i+1)){ cprintf(BG_RED, "Writing_Thread: Packet Number Mismatch! " "i %d, real pnum %d, real fnum %d, missingPacket 0x%x\n", @@ -2746,10 +2725,7 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ (uint32_t)(*( (uint64_t*) wbuf_footer)), *( (uint16_t*) wbuf_header->missingPacket)); exitVal =1; - }*/ - //overwriting port number and dynamic range - /**( (uint8_t*) wbuf_header->portIndex) = (uint8_t)port; - *( (uint8_t*) wbuf_header->dynamicRange) = (uint8_t)dynamicRange;*/ + } } if(exitVal){exit(-1);} From 72cfd7a1d747b78805d29aacb51dbccd2c4a869b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 2 Feb 2016 18:57:20 +0100 Subject: [PATCH 194/222] all changes done with bugs solved. need to test with image reconstruction --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 3c02520087..89bff743bd 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2683,7 +2683,7 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ } //add frame number - ( (uint64_t*) wbuf_footer) = (currentFrameNumber+1) | (((uint64_t)(*( (uint16_t*) wbuf_footer->packetNumber)))<<0x30); + *( (uint64_t*) wbuf_footer) = (currentFrameNumber+1) | (((uint64_t)(*( (uint16_t*) wbuf_footer->packetNumber)))<<0x30); //*( (uint16_t*) wbuf_footer->packetNumber) = (i+1); // missing frames already have the right packet number #ifdef DEBUG4 cprintf(RED, "Missing Packet Loop index:%d fnum:%d Pnum:%d\n",i, @@ -2713,7 +2713,7 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ } //overwriting port number and dynamic range - ( (uint8_t*) wbuf_header->portIndex) = (uint8_t)port; + *( (uint8_t*) wbuf_header->portIndex) = (uint8_t)port; *( (uint8_t*) wbuf_header->dynamicRange) = (uint8_t)dynamicRange; //DEBUGGING From fed17eb8ebc54d3fe521258d2b60d9cb24934889 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 3 Feb 2016 11:26:18 +0100 Subject: [PATCH 195/222] modified color of printout --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 89bff743bd..60893deea6 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1501,7 +1501,7 @@ void UDPStandardImplementation::startListening(){ //udpsocket doesnt exist if(udpSocket[ithread] == NULL){ - FILE_LOG(logERROR) << "Listening_Thread " << ithread << ": UDP Socket not created"; + FILE_LOG(logERROR) << "Listening_Thread " << ithread << ": UDP Socket not created or shut down earlier"; stopListening(ithread,0); continue; } @@ -2461,7 +2461,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //statistics FILE_LOG(logINFO) << "Status: Run Finished"; - if(numTotMissingPackets){ + if(totalPacketsCaught != (numberOfFrames*packetsPerFrame)){ cprintf(RED, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(RED, "Total Packets Caught: %lld\n",(long long int)totalPacketsCaught); cprintf(RED, "Total Frames Caught: %lld\n",(long long int)(totalPacketsCaught/packetsPerFrame)); From ef8fbab1f4aa08f0c069fd4390ad20ebc59f0f08 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 3 Feb 2016 11:34:47 +0100 Subject: [PATCH 196/222] 10g bug fixed in previous branch merge --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 60893deea6..c5fee80650 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -955,7 +955,7 @@ void UDPStandardImplementation::startReadout(){ totalP += totalListeningFrameCount[i]; } } - }//else cprintf(MAGENTA,"***Got all packets without waiting****\n"); + } From 41f7743af932bb551950705be539bba4c8fca94b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 3 Feb 2016 16:27:23 +0100 Subject: [PATCH 197/222] included fifodepth for jungfrau. Needed else its stuck --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 849a477bd9..8368fceb27 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -741,6 +741,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ frameIndexOffset = JFRAU_FRAME_INDEX_OFFSET; packetIndexMask = JFRAU_PACKET_INDEX_MASK; maxPacketsPerFile = JFRAU_MAX_FRAMES_PER_FILE * JFRAU_PACKETS_PER_FRAME; + fifoDepth = JFRAU_FIFO_SIZE; fifoSize = JFRAU_FIFO_SIZE; //footerOffset = Not applicable; break; From 0c9806e17f1b89a02c5b952f86f43fe79ba7372f Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 4 Feb 2016 12:39:05 +0100 Subject: [PATCH 198/222] jungfrau header changed --- slsReceiverSoftware/include/receiver_defs.h | 6 +- .../src/UDPStandardImplementation.cpp | 65 ++++++++++--------- .../src/slsReceiverTCPIPInterface.cpp | 14 ++-- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 3cc5e80914..49522334de 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -37,8 +37,10 @@ typedef struct { */ typedef struct { unsigned char emptyHeader[6]; - unsigned char frameNumber[8]; - unsigned char packetNumber[8]; + unsigned char reserved[4]; + unsigned char packetNumber[1]; + unsigned char frameNumber[3]; + unsigned char bunchid[8]; } jfrau_packet_header_t; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 8368fceb27..8a6a57aaba 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1591,7 +1591,6 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in int receivedSize = udpSocket[ithread]->ReceiveDataOnly(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + cSize, lSize + cSize); - //throw away packets that is not one packet size, need to check status if socket is shut down while(status != TRANSMITTING && myDetectorType == EIGER && receivedSize != onePacketSize) { if(receivedSize != EIGER_HEADER_LENGTH){ @@ -1606,19 +1605,25 @@ int UDPStandardImplementation::prepareAndListenBuffer(int ithread, int lSize, in totalListeningFrameCount[ithread] += (receivedSize/onePacketSize); #ifdef MANUALDEBUG - if(myDetectorType == JUNGFRAU){ - jfrau_packet_header_t* header = (jfrau_packet_header_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); - cprintf(RED,"framenumber:%llu\n",(long long unsigned int)(*( (uint64_t*) header->frameNumber))); - cprintf(RED,"packetnumber:%llu\n",(long long unsigned int)(*( (uint64_t*) header->packetNumber))); - }else if(myDetectorType == EIGER){ - eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); - eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); - cprintf(GREEN,"thread:%d footeroffset:%dsubframenum:%d oldpacketnum:%d new pnum:%d new fnum:%d\n", - ithread,footerOffset, - (*( (unsigned int*) header->subFameNumber)), - (*( (uint8_t*) header->dynamicRange)), - (*( (uint16_t*) footer->packetNumber)), - (uint32_t)(*( (uint64_t*) footer))); + if(receivedSize>0){ + if(myDetectorType == JUNGFRAU){ + jfrau_packet_header_t* header; + + for(int iloop=0;iloop<2;iloop++){ + header = (jfrau_packet_header_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS + iloop * (JFRAU_HEADER_LENGTH+JFRAU_ONE_DATA_SIZE)); + cprintf(RED,"[%d]: packetnumber:%x\n",iloop, (*( (uint8_t*) header->packetNumber))); + cprintf(RED," : framenumber :%x\n", (*( (uint32_t*) header->frameNumber))&0xffffff); + } + }else if(myDetectorType == EIGER){ + eiger_packet_header_t* header = (eiger_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); + eiger_packet_footer_t* footer = (eiger_packet_footer_t*)(buffer[ithread] + footerOffset + HEADER_SIZE_NUM_TOT_PACKETS); + cprintf(GREEN,"thread:%d footeroffset:%dsubframenum:%d oldpacketnum:%d new pnum:%d new fnum:%d\n", + ithread,footerOffset, + (*( (unsigned int*) header->subFrameNumber)), + (*( (uint8_t*) header->dynamicRange)), + (*( (uint16_t*) footer->packetNumber)), + (uint32_t)(*( (uint64_t*) footer))); + } } #endif @@ -1645,7 +1650,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ break; case JUNGFRAU: header = (jfrau_packet_header_t*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS); - startFrameIndex = (*( (uint64_t*) header->frameNumber)); + startFrameIndex = (*( (uint32_t*) header->frameNumber))&0xffffff; break; default: if(shortFrameEnable < 0){ @@ -1859,31 +1864,31 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz lastPacketOffset = (((numberofJobsPerBuffer * packetsPerFrame - 1) * onePacketSize) + HEADER_SIZE_NUM_TOT_PACKETS); #ifdef DEBUG4 header = (jfrau_packet_header_t*) (buffer[ithread]+HEADER_SIZE_NUM_TOT_PACKETS); - cprintf(BLUE, "Listening_Thread: First Header:%llu\t First Packet:%llu\n", - (long long unsigned int)(*( (uint64_t*) header->frameNumber)), - (long long unsigned int)(*( (uint64_t*) header->packetNumber))); + cprintf(BLUE, "Listening_Thread: First Header:%d\t First Packet:%d\n", + (*( (uint32_t*) header->frameNumber))&0xffffff, + (*( (uint8_t*) header->packetNumber))); #endif header = (jfrau_packet_header_t*) (buffer[ithread]+lastPacketOffset); #ifdef DEBUG4 - cprintf(BLUE, "Listening_Thread: Last Header:%llu\t Last Packet:%llu\n", - (long long unsigned int)(*( (uint64_t*) header->frameNumber)), - (long long unsigned int)(*( (uint64_t*) header->packetNumber))); + cprintf(BLUE, "Listening_Thread: Last Header:%du\t Last Packet:%d\n", + (*( (uint32_t*) header->frameNumber))&0xffffff, + (*( (uint8_t*) header->packetNumber))); #endif //jungfrau last packet value is 0, so find the last packet and store the others in a temp storage - if(*( (uint64_t*) header->packetNumber)){ + if((*( (uint8_t*) header->packetNumber))){ cprintf(RED,"entering missing packet zone\n"); - lastFrameHeader64 = (*( (uint64_t*) header->frameNumber)); + lastFrameHeader64 = (*( (uint32_t*) header->frameNumber))&0xffffff; cSize += onePacketSize; lastPacketOffset -= onePacketSize; --packetCount; - while (lastFrameHeader64 == (*( (uint64_t*) header->frameNumber))){ + while (lastFrameHeader64 == (*( (uint32_t*) header->frameNumber))&0xffffff){ cSize += onePacketSize; lastPacketOffset -= onePacketSize; header = (jfrau_packet_header_t*) (buffer[ithread]+lastPacketOffset); #ifdef DEBUG4 - cprintf(RED,"new header:%llu new packet:%llu\n", - (long long unsigned int)(*( (uint64_t*) header->frameNumber)), - (long long unsigned int)(*( (uint64_t*) header->packetNumber))); + cprintf(RED,"new header:%d new packet:%d\n", + (*( (uint32_t*) header->frameNumber))&0xffffff, + (*( (uint8_t*) header->packetNumber))); #endif --packetCount; } @@ -2529,7 +2534,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //statistics FILE_LOG(logINFO) << "Status: Run Finished"; - if(totalPacketsCaught != (numberOfFrames*packetsPerFrame)){ + if(totalPacketsCaught != ((uint64_t)numberOfFrames*packetsPerFrame)){ cprintf(RED, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(RED, "Total Packets Caught: %lld\n",(long long int)totalPacketsCaught); cprintf(RED, "Total Frames Caught: %lld\n",(long long int)(totalPacketsCaught/packetsPerFrame)); @@ -2555,7 +2560,7 @@ void UDPStandardImplementation::handleWithoutDataCompression(int ithread, char* if(myDetectorType != EIGER){ if(myDetectorType == JUNGFRAU){ jfrau_packet_header_t* header = (jfrau_packet_header_t*)(wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS); - currentFrameNumber = (*( (uint64_t*) header->frameNumber)); + currentFrameNumber = (*( (uint32_t*) header->frameNumber))&0xffffff; }else{ uint64_t tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS)))); //for gotthard and normal frame, increment frame number to separate fnum and pnum @@ -2677,7 +2682,7 @@ void UDPStandardImplementation::writeFileWithoutCompression(char* wbuffer[],uint lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); if(myDetectorType == JUNGFRAU){ jfrau_packet_header_t* header = (jfrau_packet_header_t*) (wbuffer[0] + lastpacket); - currentFrameNumber = (*( (uint64_t*) header->frameNumber)); + currentFrameNumber = (*( (uint32_t*) header->frameNumber))&0xffffff; }else{ tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + lastpacket)))); //for gotthard and normal frame, increment frame number to separate fnum and pnum diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 87d920440e..a79fb6ebd4 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -1858,7 +1858,7 @@ int slsReceiverTCPIPInterface::jungfrau_read_frame(){ char fName[MAX_STR_LENGTH]=""; int acquisitionIndex = -1; int frameIndex= -1; - uint64_t currentIndex=0; + int64_t currentIndex=0; uint64_t startAcquisitionIndex=0; uint64_t startFrameIndex=0; strcpy(mess,"Could not read frame\n"); @@ -1915,7 +1915,7 @@ int slsReceiverTCPIPInterface::jungfrau_read_frame(){ //fixed frame number jfrau_packet_header_t* header = (jfrau_packet_header_t*) origVal; - currentIndex = (*( (uint64_t*) header->frameNumber)); + currentIndex = (*( (uint32_t*) header->frameNumber))&0xffffff; #ifdef VERYVERBOSE cout << "currentIndex:" << dec << currentIndex << endl; #endif @@ -1923,13 +1923,13 @@ int slsReceiverTCPIPInterface::jungfrau_read_frame(){ int64_t currentPacket = packetsPerFrame-1; int offsetsrc = 0; int offsetdest = 0; - uint64_t ifnum=-1; - uint64_t ipnum=-1; + int64_t ifnum=-1; + int64_t ipnum=-1; while(currentPacket >= 0){ header = (jfrau_packet_header_t*) (origVal + offsetsrc); - ifnum = (*( (uint64_t*) header->frameNumber)); - ipnum = (*( (uint64_t*) header->packetNumber)); + 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); @@ -1938,7 +1938,7 @@ int slsReceiverTCPIPInterface::jungfrau_read_frame(){ currentPacket--; continue; } - if((int64_t)ipnum!= currentPacket){ + if(ipnum!= currentPacket){ cout << "current packet " << currentPacket << " Wrong packet number " << ipnum << ", copying blank packet" << endl; memcpy(retval+offsetdest,blackpacket,oneDataSize); offsetdest += oneDataSize; From 5afb38c1ecd0f6564a38e54a732126e9c9727b7c Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 8 Feb 2016 10:40:33 +0100 Subject: [PATCH 199/222] changing the print outs --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 8a6a57aaba..2dc67234a4 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2534,7 +2534,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //statistics FILE_LOG(logINFO) << "Status: Run Finished"; - if(totalPacketsCaught != ((uint64_t)numberOfFrames*packetsPerFrame)){ + if(totalPacketsCaught < ((uint64_t)numberOfFrames*packetsPerFrame)){ cprintf(RED, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(RED, "Total Packets Caught: %lld\n",(long long int)totalPacketsCaught); cprintf(RED, "Total Frames Caught: %lld\n",(long long int)(totalPacketsCaught/packetsPerFrame)); From bd91aea7136fbed1835bb51fe7c4eb2aa447061f Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Thu, 11 Feb 2016 17:09:54 +0100 Subject: [PATCH 200/222] Some defs for JCTB receiver --- slsReceiverSoftware/include/circularFifo.h | 2 -- slsReceiverSoftware/include/receiver_defs.h | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/slsReceiverSoftware/include/circularFifo.h b/slsReceiverSoftware/include/circularFifo.h index 6f779aafce..733b0800de 100644 --- a/slsReceiverSoftware/include/circularFifo.h +++ b/slsReceiverSoftware/include/circularFifo.h @@ -78,7 +78,6 @@ int CircularFifo::getSemValue() template bool CircularFifo::push(Element*& item_) { - int nextTail = increment(tail); if(nextTail != head) { @@ -87,7 +86,6 @@ bool CircularFifo::push(Element*& item_) sem_post(&free_mutex); return true; } - // queue was full return false; } diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index 0a4bda66ba..32aa52712c 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -90,7 +90,7 @@ #define JCTB_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 /*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ -<<<<<<< HEAD +//<<<<<<< HEAD #define JCTB_PACKETS_PER_FRAME 1 #define JCTB_ONE_PACKET_SIZE 8224 #define JCTB_BUFFER_SIZE (JCTB_ONE_PACKET_SIZE*40) @@ -99,7 +99,7 @@ #define JCTB_FRAME_INDEX_MASK 0xFFFFFFFF #define JCTB_FRAME_INDEX_OFFSET 6+8 #define JCTB_PACKET_INDEX_MASK 0xFFFFFFFF -======= +//======= #define JCTB_PACKETS_PER_FRAME 50 #define JCTB_ONE_PACKET_SIZE 8214 #define JCTB_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) @@ -108,7 +108,7 @@ #define JCTB_FRAME_INDEX_MASK 0xFFFFFF00 #define JCTB_FRAME_INDEX_OFFSET 8 #define JCTB_PACKET_INDEX_MASK 0xFF ->>>>>>> 8bad1d33fcf4601752bb6722a9eca00aa2cd4ed2 +//>>>>>>> 8bad1d33fcf4601752bb6722a9eca00aa2cd4ed2 #define JCTB_BYTES_PER_ADC (2) #define JCTB_PIXELS_IN_ONE_ROW 32 From 66eddb1afed3ddc7c88bcebcaa997fb88b0e4e11 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Mon, 22 Feb 2016 14:00:22 +0100 Subject: [PATCH 201/222] Added stopped status --- slsReceiverSoftware/include/sls_receiver_defs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index 07566ab84e..a2dfe6ab4e 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -111,7 +111,8 @@ class slsReceiverDefs { WAITING, /**< waiting for trigger or gate signal */ RUN_FINISHED, /**< acquisition not running but data in memory */ TRANSMITTING, /**< acquisition running and data in memory */ - RUNNING /**< acquisition running, no data in memory */ + RUNNING, /**< acquisition running, no data in memory */ + STOPPED /**< received external stop */ }; #ifdef __cplusplus From f113b1afbbb6ee257e0d7f25c31ec7ad70f3fb90 Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Mon, 22 Feb 2016 15:07:05 +0100 Subject: [PATCH 202/222] Added status stopped --- slsReceiverSoftware/include/sls_receiver_defs.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/include/sls_receiver_defs.h b/slsReceiverSoftware/include/sls_receiver_defs.h index c11f6f8c02..e37639b076 100755 --- a/slsReceiverSoftware/include/sls_receiver_defs.h +++ b/slsReceiverSoftware/include/sls_receiver_defs.h @@ -112,7 +112,8 @@ class slsReceiverDefs { WAITING, /**< waiting for trigger or gate signal */ RUN_FINISHED, /**< acquisition not running but data in memory */ TRANSMITTING, /**< acquisition running and data in memory */ - RUNNING /**< acquisition running, no data in memory */ + RUNNING, /**< acquisition running, no data in memory */ + STOPPED /**< acquisition stopped externally */ }; #ifdef __cplusplus @@ -172,6 +173,7 @@ class slsReceiverDefs { case RUNNING: return std::string("running"); \ case TRANSMITTING: return std::string("data"); \ case RUN_FINISHED: return std::string("finished"); \ + case STOPPED: return std::string("stopped"); \ default: return std::string("idle"); \ }}; From e508050be85b5b0384e890e14b6f9aea872e7ac1 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 25 Feb 2016 12:11:05 +0100 Subject: [PATCH 203/222] bug fix: converts any receiver other than eiger into a jungfrau receiver --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 2dc67234a4..ccbdaf148a 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -251,7 +251,7 @@ int UDPStandardImplementation::setupFifoStructure(){ int64_t i; int oldNumberofJobsPerBuffer = numberofJobsPerBuffer; //eiger always listens to 1 packet at a time - if((myDetectorType == EIGER) || (myDetectorType = JUNGFRAU)){ + if((myDetectorType == EIGER) || (myDetectorType == JUNGFRAU)){ numberofJobsPerBuffer = 1; FILE_LOG(logDEBUG) << "Info: 1 packet per buffer"; } From 683ea31963d7ff6064ff5591255deb55af586b0a Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 25 Feb 2016 13:56:23 +0100 Subject: [PATCH 204/222] removed comment entering missing zone --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index ccbdaf148a..9c18ad2433 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1876,7 +1876,7 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz #endif //jungfrau last packet value is 0, so find the last packet and store the others in a temp storage if((*( (uint8_t*) header->packetNumber))){ - cprintf(RED,"entering missing packet zone\n"); + //cprintf(RED,"entering missing packet zone\n"); lastFrameHeader64 = (*( (uint32_t*) header->frameNumber))&0xffffff; cSize += onePacketSize; lastPacketOffset -= onePacketSize; From d4b388f434c5fc54091dd434cb86dc6472e836fc Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 25 Feb 2016 14:13:42 +0100 Subject: [PATCH 205/222] unresolved conflict --- slsReceiverSoftware/include/receiver_defs.h | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/slsReceiverSoftware/include/receiver_defs.h b/slsReceiverSoftware/include/receiver_defs.h index d9e6a7009b..4c621a67fc 100755 --- a/slsReceiverSoftware/include/receiver_defs.h +++ b/slsReceiverSoftware/include/receiver_defs.h @@ -151,7 +151,6 @@ typedef struct { #define JCTB_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000 /*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/ -//<<<<<<< HEAD #define JCTB_PACKETS_PER_FRAME 1 #define JCTB_ONE_PACKET_SIZE 8224 #define JCTB_BUFFER_SIZE (JCTB_ONE_PACKET_SIZE*40) @@ -160,16 +159,7 @@ typedef struct { #define JCTB_FRAME_INDEX_MASK 0xFFFFFFFF #define JCTB_FRAME_INDEX_OFFSET 6+8 #define JCTB_PACKET_INDEX_MASK 0xFFFFFFFF -//======= -#define JCTB_PACKETS_PER_FRAME 50 -#define JCTB_ONE_PACKET_SIZE 8214 -#define JCTB_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) -#define JCTB_DATA_BYTES (JCTB_BUFFER_PER_FRAME) - -#define JCTB_FRAME_INDEX_MASK 0xFFFFFF00 -#define JCTB_FRAME_INDEX_OFFSET 8 -#define JCTB_PACKET_INDEX_MASK 0xFF -//>>>>>>> 8bad1d33fcf4601752bb6722a9eca00aa2cd4ed2 + #define JCTB_BYTES_PER_ADC (2) #define JCTB_PIXELS_IN_ONE_ROW 32 From d88b104aa872dfd91d43b7cf9580be04a22278d8 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 15 Mar 2016 15:28:50 +0100 Subject: [PATCH 206/222] bug fix for receiver call back --- .../include/slsReceiverTCPIPInterface.h | 107 ++++++++++++------ slsReceiverSoftware/src/main.cpp | 28 ++++- slsReceiverSoftware/src/slsReceiver.cpp | 15 ++- .../src/slsReceiverTCPIPInterface.cpp | 32 ++++++ 4 files changed, 139 insertions(+), 43 deletions(-) diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index 237f240e67..a2f358aca8 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -57,45 +57,39 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** gets version */ int64_t getReceiverVersion(); -/* /\** */ -/* callback arguments are */ -/* filepath */ -/* filename */ -/* fileindex */ -/* data size */ - -/* return value is */ -/* 0 callback takes care of open,close,wrie file */ -/* 1 callback writes file, we have to open, close it */ -/* 2 we open, close, write file, callback does not do anything */ - -/* *\/ */ - -/* void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){receiverBase->registerCallBackStartAcquisition(func,arg);};; */ - - -/* /\** */ -/* callback argument is */ -/* toatal farmes caught */ - -/* *\/ */ - - -/* void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){receiverBase->registerCallBackAcquisitionFinished(func,arg);}; */ - - - -/* /\** */ -/* args to raw data ready callback are */ -/* framenum */ -/* datapointer */ -/* datasize in bytes */ -/* file descriptor */ -/* guidatapointer (NULL, no data required) */ -/* *\/ */ + //***callback functions*** + /** + * Call back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is the action which decides what the user and default responsibilities to save data are + * 0 callback takes care of open,close,wrie file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything + */ + void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); -/* void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){receiverBase->registerCallBackRawDataReady(func,arg);}; */ + /** + * Call back for acquisition finished + * callback argument is + * total frames caught + */ + void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); + /** + * Call back for raw data + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) + */ + void registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg); private: @@ -284,6 +278,45 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { bool bottom; + //***callback parameters*** + /** + * function being called back for start acquisition + * callback arguments are + * filepath + * filename + * fileindex + * datasize + * + * return value is + * 0 callback takes care of open,close,wrie file + * 1 callback writes file, we have to open, close it + * 2 we open, close, write file, callback does not do anything + */ + int (*startAcquisitionCallBack)(char*, char*,int, int, void*); + void *pStartAcquisition; + + /** + * function being called back for acquisition finished + * callback argument is + * total frames caught + */ + void (*acquisitionFinishedCallBack)(int, void*); + void *pAcquisitionFinished; + + + /** + * function being called back for raw data + * args to raw data ready callback are + * framenum + * datapointer + * datasize in bytes + * file descriptor + * guidatapointer (NULL, no data required) + */ + void (*rawDataReadyCallBack)(int, char*, int, FILE*, char*, void*); + void *pRawDataReady; + + protected: /** Socket */ MySocketTCP* socket; diff --git a/slsReceiverSoftware/src/main.cpp b/slsReceiverSoftware/src/main.cpp index 1dc9a65c63..a005f569d7 100644 --- a/slsReceiverSoftware/src/main.cpp +++ b/slsReceiverSoftware/src/main.cpp @@ -22,6 +22,28 @@ void closeFile(int p){ deleteReceiver(receiver); } +/* +int startAcquisitionCallBack(char* filePath, char* fileName, int fileIndex, int bufferSize, void* context) { + cout << "#### startAcquisitionCallBack ####" << endl; + cout << "* filePath: " << filePath << endl; + cout << "* fileName: " << fileName << endl; + cout << "* fileIndex: " << fileIndex << endl; + cout << "* bufferSize: " << bufferSize << endl; + return 1; +} + +void acquisitionFinishedCallBack(int totalFramesCaught, void* context) { + cout << "#### acquisitionFinishedCallBack ####" << endl; + cout << "* totalFramesCaught: " << totalFramesCaught << endl; +} + +void rawDataReadyCallBack(int currFrameNum, char* dataPointer, int dataSize, FILE* file, char* guiDataPointer, void* context) { + cout << "#### rawDataReadyCallBack ####" << endl; + cout << "* currFrameNum: " << currFrameNum << endl; + cout << "* dataSize: " << dataSize << endl; +} +*/ + int main(int argc, char *argv[]) { //Catch signal SIGINT to close files properly @@ -52,7 +74,7 @@ int main(int argc, char *argv[]) { registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg); */ - //receiver->registerCallBackStartAcquisition(func,arg); + //receiver->registerCallBackStartAcquisition(startAcquisitionCallBack,NULL); /** @@ -60,7 +82,7 @@ int main(int argc, char *argv[]) { total farmes caught registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg); */ - //receiver->registerCallBackAcquisitionFinished(func,arg); + //receiver->registerCallBackAcquisitionFinished(acquisitionFinishedCallBack,NULL); /** @@ -73,7 +95,7 @@ int main(int argc, char *argv[]) { REMEMBER THAT THE CALLBACK IS BLOCKING registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg); */ - //receiver->registerCallBackRawDataReady(func,arg); + //receiver->registerCallBackRawDataReady(rawDataReadyCallBack,NULL); diff --git a/slsReceiverSoftware/src/slsReceiver.cpp b/slsReceiverSoftware/src/slsReceiver.cpp index f23da65c53..a6c231a3ef 100644 --- a/slsReceiverSoftware/src/slsReceiver.cpp +++ b/slsReceiverSoftware/src/slsReceiver.cpp @@ -172,20 +172,29 @@ int64_t slsReceiver::getReceiverVersion(){ void slsReceiver::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ //tcpipInterface - udp_interface->registerCallBackStartAcquisition(func,arg); + if(udp_interface) + udp_interface->registerCallBackStartAcquisition(func,arg); + else + tcpipInterface->registerCallBackStartAcquisition(func,arg); } void slsReceiver::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ //tcpipInterface - udp_interface->registerCallBackAcquisitionFinished(func,arg); + if(udp_interface) + udp_interface->registerCallBackAcquisitionFinished(func,arg); + else + tcpipInterface->registerCallBackAcquisitionFinished(func,arg); } void slsReceiver::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ //tcpipInterface - udp_interface->registerCallBackRawDataReady(func,arg); + if(udp_interface) + udp_interface->registerCallBackRawDataReady(func,arg); + else + tcpipInterface->registerCallBackRawDataReady(func,arg); } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index a79fb6ebd4..9b7a91a8e3 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -42,6 +42,14 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* bottom(bot), socket(NULL){ + //***callback parameters*** + startAcquisitionCallBack = NULL; + pStartAcquisition = NULL; + acquisitionFinishedCallBack = NULL; + pAcquisitionFinished = NULL; + rawDataReadyCallBack = NULL; + pRawDataReady = NULL; + int port_no=portNumber; if(receiverBase == NULL) receiverBase = 0; @@ -362,6 +370,12 @@ int slsReceiverTCPIPInterface::set_detector_type(){ if(ret != FAIL){ #ifndef REST receiverBase = UDPInterface::create("standard"); + if(startAcquisitionCallBack) + receiverBase->registerCallBackStartAcquisition(startAcquisitionCallBack,pStartAcquisition); + if(acquisitionFinishedCallBack) + receiverBase->registerCallBackAcquisitionFinished(acquisitionFinishedCallBack,pAcquisitionFinished); + if(rawDataReadyCallBack) + receiverBase->registerCallBackRawDataReady(rawDataReadyCallBack,pRawDataReady); #endif myDetectorType = dr; ret=receiverBase->setDetectorType(myDetectorType); @@ -3012,5 +3026,23 @@ int slsReceiverTCPIPInterface::exec_command() { +/***callback functions***/ +void slsReceiverTCPIPInterface::registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){ + startAcquisitionCallBack=func; + pStartAcquisition=arg; +} + +void slsReceiverTCPIPInterface::registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){ + acquisitionFinishedCallBack=func; + pAcquisitionFinished=arg; +} + +void slsReceiverTCPIPInterface::registerCallBackRawDataReady(void (*func)(int, char*, int, FILE*, char*, void*),void *arg){ + rawDataReadyCallBack=func; + pRawDataReady=arg; +} + + + From 75a50a7ae0bb6b797a12e9d18bc460e7cf7a5e22 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 10 May 2016 17:13:27 +0200 Subject: [PATCH 207/222] receiver udp parameters should be sent to receiver everytime if rx_hostname is set --- .../include/slsReceiverTCPIPInterface.h | 3 + .../src/slsReceiverTCPIPInterface.cpp | 65 ++++++++++--------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index a2f358aca8..8b5c4527f4 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -277,6 +277,9 @@ class slsReceiverTCPIPInterface : private virtual slsReceiverDefs { /** true if bottom half module for eiger */ bool bottom; + /** Receiver not setup error message */ + char SET_RECEIVER_ERR_MESSAGE[MAX_STR_LENGTH]; + //***callback parameters*** /** diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 9b7a91a8e3..1e2b5c49e5 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -22,7 +22,6 @@ using namespace std; - slsReceiverTCPIPInterface::~slsReceiverTCPIPInterface() { stop(); if(socket) {delete socket; socket=NULL;} @@ -42,6 +41,8 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* bottom(bot), socket(NULL){ + strcpy(SET_RECEIVER_ERR_MESSAGE,"Receiver not set up. Please use rx_hostname first.\n"); + //***callback parameters*** startAcquisitionCallBack = NULL; pStartAcquisition = NULL; @@ -438,7 +439,7 @@ int slsReceiverTCPIPInterface::set_file_name() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -510,7 +511,7 @@ int slsReceiverTCPIPInterface::set_file_dir() { ret = FAIL; }*/ else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -579,7 +580,7 @@ int slsReceiverTCPIPInterface::set_file_index() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -643,7 +644,7 @@ int slsReceiverTCPIPInterface::set_frame_index() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -720,7 +721,7 @@ int slsReceiverTCPIPInterface::setup_udp(){ ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else if(receiverBase->getStatus()==RUNNING){ @@ -804,12 +805,12 @@ int slsReceiverTCPIPInterface::start_receiver(){ } /* else if(!strlen(receiverBase->getFilePath())){ - strcpy(mess,"receiver not set up. set receiver ip again.\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE"); ret = FAIL; } */ else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else { @@ -853,7 +854,7 @@ int slsReceiverTCPIPInterface::stop_receiver(){ ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -894,7 +895,7 @@ int slsReceiverTCPIPInterface::get_status(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; }else retval=receiverBase->getStatus(); #endif @@ -925,7 +926,7 @@ int slsReceiverTCPIPInterface::get_frames_caught(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; }else retval=receiverBase->getTotalFramesCaught(); #endif @@ -955,7 +956,7 @@ int slsReceiverTCPIPInterface::get_frame_index(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; }else retval=receiverBase->getAcquisitionIndex(); @@ -994,7 +995,7 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else @@ -1051,7 +1052,7 @@ int slsReceiverTCPIPInterface::set_short_frame() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else if(receiverBase->getStatus()==RUNNING){ @@ -1135,7 +1136,7 @@ int slsReceiverTCPIPInterface::moench_read_frame(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } /**send garbage with -1 index to try again*/ @@ -1324,7 +1325,7 @@ int slsReceiverTCPIPInterface::gotthard_read_frame(){ #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } @@ -1499,7 +1500,7 @@ int slsReceiverTCPIPInterface::propix_read_frame(){ #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } @@ -1650,7 +1651,7 @@ int slsReceiverTCPIPInterface::eiger_read_frame(){ #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } @@ -1895,7 +1896,7 @@ int slsReceiverTCPIPInterface::jungfrau_read_frame(){ #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } @@ -2048,7 +2049,7 @@ int slsReceiverTCPIPInterface::set_read_frequency(){ ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } /* @@ -2113,7 +2114,7 @@ int slsReceiverTCPIPInterface::enable_file_write(){ ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -2185,7 +2186,7 @@ int slsReceiverTCPIPInterface::start_readout(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_UDP_FUNCTIONS if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; }else{ receiverBase->startReadout(); @@ -2240,7 +2241,7 @@ int slsReceiverTCPIPInterface::set_timer() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -2315,7 +2316,7 @@ int slsReceiverTCPIPInterface::enable_compression() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else if(receiverBase->getStatus()==RUNNING){ @@ -2330,7 +2331,7 @@ int slsReceiverTCPIPInterface::enable_compression() { if(ret != FAIL){ if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; }else{ retval = receiverBase->getDataCompressionEnable(); @@ -2384,7 +2385,7 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -2466,7 +2467,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } if(ret!=FAIL){ if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; }else{ if(dr > 0){ @@ -2542,7 +2543,7 @@ int slsReceiverTCPIPInterface::enable_overwrite() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -2605,7 +2606,7 @@ int slsReceiverTCPIPInterface::enable_tengiga() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else{ @@ -2670,7 +2671,7 @@ int slsReceiverTCPIPInterface::set_fifo_depth() { ret=FAIL; } else if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } else if(receiverBase->getStatus()==RUNNING){ @@ -2686,7 +2687,7 @@ int slsReceiverTCPIPInterface::set_fifo_depth() { if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; }else{ retval = receiverBase->getFifoDepth(); @@ -2948,7 +2949,7 @@ int slsReceiverTCPIPInterface::send_update() { int slsReceiverTCPIPInterface::update_client() { ret=OK; if (receiverBase == NULL){ - strcpy(mess,"Receiver not set up\n"); + strcpy(mess,SET_RECEIVER_ERR_MESSAGE); ret=FAIL; } socket->SendDataOnly(&ret,sizeof(ret)); From d88253f643e405fa699b101dbda817512d516105 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 13 Jun 2016 19:10:14 +0200 Subject: [PATCH 208/222] versions update --- slsReceiverSoftware/gitInfo.txt | 14 +++++++------- slsReceiverSoftware/include/gitInfoReceiver.h | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 71d112f950..04de2ab36a 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware -URL: origin maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repository Root: origin maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git -Repsitory UUID: 750a0a06945a748a18d0b8b19b7cf94ecf2fec23 -Revision: 112 -Branch: master +URL: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git +Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git +Repsitory UUID: a29f65210a2391bba59fe237d3735db29a83c88a +Revision: 235 +Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 112 -Last Changed Date: 2015-06-26 15:57:28 +0200 +Last Changed Rev: 235 +Last Changed Date: 2016-05-10 17:13:27 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 19ffa6835c..8c879eb5a8 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" -#define SVNURL "maliakal_d@gitorious.psi.ch:sls_det_software/sls_receiver_software.git" +#define SVNURL "git@git.psi.ch:sls_detectors_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "750a0a06945a748a18d0b8b19b7cf94ecf2fec23" -//#define SVNREV 0x112 +#define SVNREPUUID "a29f65210a2391bba59fe237d3735db29a83c88a" +//#define SVNREV 0x235 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x112 -#define SVNDATE 0x20150626 +#define SVNREV 0x235 +#define SVNDATE 0x20160510 // From df04d9fb07fb7b6222c595d459e57d3949787509 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 4 Jul 2016 15:51:18 +0200 Subject: [PATCH 209/222] updating versions --- slsReceiverSoftware/gitInfo.txt | 8 ++++---- slsReceiverSoftware/include/gitInfoReceiver.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 04de2ab36a..ebfc43e785 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git -Repsitory UUID: a29f65210a2391bba59fe237d3735db29a83c88a -Revision: 235 +Repsitory UUID: e961e6a2236cdebed98bc5e51fe862ba0c3bb2f2 +Revision: 236 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 235 -Last Changed Date: 2016-05-10 17:13:27 +0200 +Last Changed Rev: 236 +Last Changed Date: 2016-06-13 19:10:14 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 8c879eb5a8..77d90c49ed 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "a29f65210a2391bba59fe237d3735db29a83c88a" -//#define SVNREV 0x235 +#define SVNREPUUID "e961e6a2236cdebed98bc5e51fe862ba0c3bb2f2" +//#define SVNREV 0x236 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x235 -#define SVNDATE 0x20160510 +#define SVNREV 0x236 +#define SVNDATE 0x20160613 // From a65920377c522b1e862e9b7c73a1e69f0fe96b70 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 5 Jul 2016 17:17:34 +0200 Subject: [PATCH 210/222] feature with header in file --- .../include/UDPStandardImplementation.h | 8 +++ .../src/UDPStandardImplementation.cpp | 56 ++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 521d6079b6..8ab54a300f 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -440,6 +440,11 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase */ void createHeaders(char* wbuffer[]); + /** + * Updates the file header char aray, each time the corresp parameter is changed + */ + void updateFileHeader(); + /** * Called by handleWithoutDataCompression and handleWithCompression after writing to file * Copy frames for GUI and updates appropriate parameters for frequency frames to gui @@ -467,6 +472,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase + /************************************************************************* * Class Members ********************************************************* *************************************************************************/ @@ -515,6 +521,8 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** If file created successfully for all Writer Threads */ bool fileCreateSuccess; + char fileHeader[1000]; + diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 9c18ad2433..614cfc8c71 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -138,6 +138,7 @@ void UDPStandardImplementation::initializeMembers(){ strcpy(completeFileName,""); maxPacketsPerFile = 0; fileCreateSuccess = false; + strcpy(fileHeader,""); //***acquisition indices parameters*** startAcquisitionIndex = 0; @@ -536,6 +537,8 @@ int UDPStandardImplementation::setDynamicRange(const uint32_t i){ frameSize = onePacketSize * packetsPerFrame; maxPacketsPerFile = EIGER_MAX_FRAMES_PER_FILE * packetsPerFrame; + updateFileHeader(); + //new dynamic range, then restart threads and resetup fifo structure if(oldDynamicRange != dynamicRange){ @@ -591,6 +594,7 @@ int UDPStandardImplementation::setTenGigaEnable(const bool b){ "\nmaxPacketsPerFile:" << maxPacketsPerFile; + updateFileHeader(); //new enable, then restart threads and resetup fifo structure if(oldTenGigaEnable != tengigaEnable){ @@ -767,6 +771,10 @@ int UDPStandardImplementation::setDetectorType(const detectorType d){ //allocate for latest data (frame copy for gui) latestData = new char[frameSize]; + //updates File Header + if(myDetectorType == EIGER) + updateFileHeader(); + FILE_LOG(logDEBUG) << " Detector type set to " << getDetectorType(d); return OK; @@ -1413,6 +1421,10 @@ int UDPStandardImplementation::createNewFile(){ numTotMissingPacketsInFile = 0; } + //write file header + if(myDetectorType == EIGER) + fwrite((void*)fileHeader, 1, strlen(fileHeader), sfilefd); + return OK; } @@ -2801,7 +2813,7 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ //overwriting port number and dynamic range *( (uint8_t*) wbuf_header->portIndex) = (uint8_t)port; - *( (uint8_t*) wbuf_header->dynamicRange) = (uint8_t)dynamicRange; + //*( (uint8_t*) wbuf_header->dynamicRange) = (uint8_t)dynamicRange; //DEBUGGING if(*( (uint16_t*) wbuf_footer->packetNumber) != (i+1)){ @@ -2820,6 +2832,48 @@ void UDPStandardImplementation::createHeaders(char* wbuffer[]){ } +void UDPStandardImplementation::updateFileHeader(){ + int xpix=-1,ypix=-1; + + //create detector specific packet header + char packetheader[1000]; + strcpy(packetheader,""); + + //only for eiger right now + /*switch(myDetectorType){ + case EIGER: + */ sprintf(packetheader,"#Packet Header\n" + "Sub Frame Number 4 bytes\n" + "Missing Packet\t 2 bytes\n" + "Port Number\t 1 byte\n" + "Unused\t\t 1 byte\n\n" + "#Packet Footer\n" + "Frame Number\t 6 bytes\n" + "Packet Number\t 2 bytes\n"); + xpix = EIGER_PIXELS_IN_ONE_ROW; + ypix = EIGER_PIXELS_IN_ONE_COL; + /* break; + default: + break; + } +*/ + + //update file header + int length = sizeof(fileHeader); + while(length!=strlen(fileHeader)){ + length = strlen(fileHeader); + sprintf(fileHeader,"Header\t\t %d bytes\n" + "Dynamic Range\t %d\n" + "Packet\t\t %d bytes\n" + "x\t\t %d pixels\n" + "y\t\t %d pixels\n\n" + "%s", + length,dynamicRange,onePacketSize,xpix,ypix,packetheader); + } + +} + + void UDPStandardImplementation::copyFrameToGui(char* buffer[]){ FILE_LOG(logDEBUG) << __AT__ << " called"; From 980c1c02e601a9a50a1b99df27abd1f0d24bd9a7 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 5 Jul 2016 17:23:05 +0200 Subject: [PATCH 211/222] updating versions --- slsReceiverSoftware/gitInfo.txt | 8 ++++---- slsReceiverSoftware/include/gitInfoReceiver.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index ebfc43e785..99bdd785a5 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git -Repsitory UUID: e961e6a2236cdebed98bc5e51fe862ba0c3bb2f2 -Revision: 236 +Repsitory UUID: 1f6fd4bdf369baca329b1cdc186d3aaf258c364c +Revision: 238 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 236 -Last Changed Date: 2016-06-13 19:10:14 +0200 +Last Changed Rev: 238 +Last Changed Date: 2016-07-05 17:17:34 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 77d90c49ed..3df81898bb 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "e961e6a2236cdebed98bc5e51fe862ba0c3bb2f2" -//#define SVNREV 0x236 +#define SVNREPUUID "1f6fd4bdf369baca329b1cdc186d3aaf258c364c" +//#define SVNREV 0x238 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x236 -#define SVNDATE 0x20160613 +#define SVNREV 0x238 +#define SVNDATE 0x20160705 // From 347ecb9bb5b6bed47e887796263dcc3d49635cc5 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 5 Jul 2016 17:24:45 +0200 Subject: [PATCH 212/222] updating versions --- slsReceiverSoftware/gitInfo.txt | 8 ++++---- slsReceiverSoftware/include/gitInfoReceiver.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 99bdd785a5..67fc9b596d 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git -Repsitory UUID: 1f6fd4bdf369baca329b1cdc186d3aaf258c364c -Revision: 238 +Repsitory UUID: a6e547d12d512ad5cd177f32cd6a38439c66fa49 +Revision: 239 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 238 -Last Changed Date: 2016-07-05 17:17:34 +0200 +Last Changed Rev: 239 +Last Changed Date: 2016-07-05 17:23:05 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 3df81898bb..2763cd87a4 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "1f6fd4bdf369baca329b1cdc186d3aaf258c364c" -//#define SVNREV 0x238 +#define SVNREPUUID "a6e547d12d512ad5cd177f32cd6a38439c66fa49" +//#define SVNREV 0x239 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x238 +#define SVNREV 0x239 #define SVNDATE 0x20160705 // From 96a88f9de2c6df1dafcd7fae81f6e85d48b878d6 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 6 Jul 2016 10:31:30 +0200 Subject: [PATCH 213/222] added timestamp --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 614cfc8c71..03eabbd696 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -16,6 +16,7 @@ #include #include #include +#include using namespace std; #define WRITE_HEADERS @@ -2859,16 +2860,19 @@ void UDPStandardImplementation::updateFileHeader(){ */ //update file header + time_t t = time(0); int length = sizeof(fileHeader); while(length!=strlen(fileHeader)){ length = strlen(fileHeader); - sprintf(fileHeader,"Header\t\t %d bytes\n" + sprintf(fileHeader,"\nHeader\t\t %d bytes\n" "Dynamic Range\t %d\n" "Packet\t\t %d bytes\n" "x\t\t %d pixels\n" - "y\t\t %d pixels\n\n" + "y\t\t %d pixels\n" + "Timestamp\t %s\n\n" "%s", - length,dynamicRange,onePacketSize,xpix,ypix,packetheader); + length,dynamicRange,onePacketSize,xpix,ypix,ctime(&t), + packetheader); } } From 779d8d109498d27201c48c19f258ddb8a6cd3568 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 6 Jul 2016 10:32:58 +0200 Subject: [PATCH 214/222] updating versions --- slsReceiverSoftware/gitInfo.txt | 8 ++++---- slsReceiverSoftware/include/gitInfoReceiver.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 67fc9b596d..d950be936c 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git -Repsitory UUID: a6e547d12d512ad5cd177f32cd6a38439c66fa49 -Revision: 239 +Repsitory UUID: 041be3f69f7d6a3b33dd270fe5175839962cc23f +Revision: 241 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 239 -Last Changed Date: 2016-07-05 17:23:05 +0200 +Last Changed Rev: 241 +Last Changed Date: 2016-07-06 10:31:30 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 2763cd87a4..939ac38643 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "a6e547d12d512ad5cd177f32cd6a38439c66fa49" -//#define SVNREV 0x239 +#define SVNREPUUID "041be3f69f7d6a3b33dd270fe5175839962cc23f" +//#define SVNREV 0x241 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x239 -#define SVNDATE 0x20160705 +#define SVNREV 0x241 +#define SVNDATE 0x20160706 // From 79e3cdd183edd24d0427568ebc06e325178c4b6b Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 12 Jul 2016 16:02:23 +0200 Subject: [PATCH 215/222] receiver crashing at file write disabled taking acquistion --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 03eabbd696..210e3b95ca 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1413,6 +1413,9 @@ int UDPStandardImplementation::createNewFile(){ } + //write file header + if(myDetectorType == EIGER) + fwrite((void*)fileHeader, 1, strlen(fileHeader), sfilefd); } //reset counters for each new file @@ -1422,9 +1425,7 @@ int UDPStandardImplementation::createNewFile(){ numTotMissingPacketsInFile = 0; } - //write file header - if(myDetectorType == EIGER) - fwrite((void*)fileHeader, 1, strlen(fileHeader), sfilefd); + return OK; } From 3fd3a5dc105eedda3a954fbda11ed66c12bf8cd6 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Tue, 12 Jul 2016 16:21:50 +0200 Subject: [PATCH 216/222] last frame number caught added to log --- .../include/UDPStandardImplementation.h | 3 +++ slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/include/UDPStandardImplementation.h b/slsReceiverSoftware/include/UDPStandardImplementation.h index 8ab54a300f..26f63ddc0f 100644 --- a/slsReceiverSoftware/include/UDPStandardImplementation.h +++ b/slsReceiverSoftware/include/UDPStandardImplementation.h @@ -542,6 +542,9 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase /** Previous Frame number from buffer to calculate loss */ int64_t previousFrameNumber; + /** Last Frame Index Listened To */ + int32_t lastFrameIndex; + /* Acquisition started */ bool acqStarted; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 210e3b95ca..0d7f30aea8 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -147,10 +147,12 @@ void UDPStandardImplementation::initializeMembers(){ frameIndex = 0; currentFrameNumber = 0; previousFrameNumber = -1; + lastFrameIndex = 0; acqStarted = false; measurementStarted = false; - for(int i = 0; i < MAX_NUMBER_OF_LISTENING_THREADS; ++i) + for(int i = 0; i < MAX_NUMBER_OF_LISTENING_THREADS; ++i){ totalListeningFrameCount[i] = 0; + } packetsInFile = 0; numMissingPackets = 0; numTotMissingPackets = 0; @@ -2106,7 +2108,8 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ *(blankframe_data) = 0xFF; } } - + //last frame read out + lastFrameIndex = -1; @@ -2162,6 +2165,8 @@ void UDPStandardImplementation::processWritingBufferPacketByPacket(int ithread){ } //frame number threadFrameNumber[i] = (uint32_t)(*( (uint64_t*) packetBuffer_footer)); + //last frame read out + lastFrameIndex = threadFrameNumber[i]; threadFrameNumber[i] += (startFrameIndex - 1); //packet number @@ -2548,6 +2553,7 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){ //statistics FILE_LOG(logINFO) << "Status: Run Finished"; + FILE_LOG(logINFO) << "Last Frame Number Caught:" << lastFrameIndex; if(totalPacketsCaught < ((uint64_t)numberOfFrames*packetsPerFrame)){ cprintf(RED, "Total Missing Packets padded: %d\n",numTotMissingPackets); cprintf(RED, "Total Packets Caught: %lld\n",(long long int)totalPacketsCaught); From eda342911f09ced8ea3eea11000c2ace6476802d Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 14 Jul 2016 16:23:29 +0200 Subject: [PATCH 217/222] update versions --- slsReceiverSoftware/gitInfo.txt | 8 ++++---- slsReceiverSoftware/include/gitInfoReceiver.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index d950be936c..5460959f8a 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git -Repsitory UUID: 041be3f69f7d6a3b33dd270fe5175839962cc23f -Revision: 241 +Repsitory UUID: 8e0c6a761b1b7370aaf6ab16fd14d394606538c1 +Revision: 244 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 241 -Last Changed Date: 2016-07-06 10:31:30 +0200 +Last Changed Rev: 244 +Last Changed Date: 2016-07-12 16:21:50 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index 939ac38643..d768a3094f 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "041be3f69f7d6a3b33dd270fe5175839962cc23f" -//#define SVNREV 0x241 +#define SVNREPUUID "8e0c6a761b1b7370aaf6ab16fd14d394606538c1" +//#define SVNREV 0x244 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x241 -#define SVNDATE 0x20160706 +#define SVNREV 0x244 +#define SVNDATE 0x20160712 // From 56a0bbfcc197bad5920a22e3b9dba4ec421d34f2 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 14 Jul 2016 17:10:28 +0200 Subject: [PATCH 218/222] bug filename with respect to frame number --- .../src/UDPStandardImplementation.cpp | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 0d7f30aea8..06db3368c7 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2663,6 +2663,33 @@ void UDPStandardImplementation::writeFileWithoutCompression(char* wbuffer[],uint //loop to take care of creating new files when it reaches max packets per file while(numpackets > 0){ + //new file + if(packetsInFile >= (uint32_t)maxPacketsPerFile){ + //for packet loss, because currframenum is the latest one for eiger + //get frame number (eiger already gets it when it does packet to packet processing) + if(myDetectorType != EIGER){ + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); + if(myDetectorType == JUNGFRAU){ + jfrau_packet_header_t* header = (jfrau_packet_header_t*) (wbuffer[0] + lastpacket); + currentFrameNumber = (*( (uint32_t*) header->frameNumber))&0xffffff; + }else{ + tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + lastpacket)))); + //for gotthard and normal frame, increment frame number to separate fnum and pnum + if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) + tempframenumber++; + //get frame number + currentFrameNumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; + } + + //set indices + acquisitionIndex = currentFrameNumber - startAcquisitionIndex; + frameIndex = currentFrameNumber - startFrameIndex; + } +#ifdef DEBUG3 + cprintf(GREEN,"Writing_Thread: Current Frame Number:%d\n",currentFrameNumber); +#endif + createNewFile(); + } //to create new file when max reached packetsToSave = maxPacketsPerFile - packetsInFile; if(packetsToSave > numpackets) @@ -2694,36 +2721,6 @@ void UDPStandardImplementation::writeFileWithoutCompression(char* wbuffer[],uint cprintf(GREEN,"Writing Thread: packetscaught:%d totalPacketsCaught:%d\n", packetsCaught,totalPacketsCaught); #endif - //new file - if(packetsInFile >= (uint32_t)maxPacketsPerFile){ - //for packet loss, because currframenum is the latest one for eiger - //get frame number (eiger already gets it when it does packet to packet processing) - if(myDetectorType != EIGER){ - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - if(myDetectorType == JUNGFRAU){ - jfrau_packet_header_t* header = (jfrau_packet_header_t*) (wbuffer[0] + lastpacket); - currentFrameNumber = (*( (uint32_t*) header->frameNumber))&0xffffff; - }else{ - tempframenumber = ((uint32_t)(*((uint32_t*)(wbuffer[0] + lastpacket)))); - //for gotthard and normal frame, increment frame number to separate fnum and pnum - if (myDetectorType == PROPIX ||(myDetectorType == GOTTHARD && shortFrameEnable == -1)) - tempframenumber++; - //get frame number - currentFrameNumber = (tempframenumber & frameIndexMask) >> frameIndexOffset; - } - - - - //set indices - acquisitionIndex = currentFrameNumber - startAcquisitionIndex; - frameIndex = currentFrameNumber - startFrameIndex; - } -#ifdef DEBUG3 - cprintf(GREEN,"Writing_Thread: Current Frame Number:%d\n",currentFrameNumber); -#endif - createNewFile(); - } - //increase offset if(myDetectorType != EIGER) offset += (packetsToSave * onePacketSize); From c852463de10b8311167be8008ad70f28d528be84 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 18 Jul 2016 18:18:08 +0200 Subject: [PATCH 219/222] updaterev --- slsReceiverSoftware/gitInfo.txt | 8 ++++---- slsReceiverSoftware/include/gitInfoReceiver.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 5460959f8a..6094ae5bc0 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git -Repsitory UUID: 8e0c6a761b1b7370aaf6ab16fd14d394606538c1 -Revision: 244 +Repsitory UUID: 6de08693c4ded931234c93824d36bb17ca1308cd +Revision: 246 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 244 -Last Changed Date: 2016-07-12 16:21:50 +0200 +Last Changed Rev: 246 +Last Changed Date: 2016-07-14 17:10:28 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index d768a3094f..a90b621c78 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "8e0c6a761b1b7370aaf6ab16fd14d394606538c1" -//#define SVNREV 0x244 +#define SVNREPUUID "6de08693c4ded931234c93824d36bb17ca1308cd" +//#define SVNREV 0x246 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x244 -#define SVNDATE 0x20160712 +#define SVNREV 0x246 +#define SVNDATE 0x20160714 // From 658f3459ca0aee01a3ca38aa0e303631cb3813a7 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 3 Aug 2016 17:02:40 +0200 Subject: [PATCH 220/222] changes to get rid of warnings --- slsReceiverSoftware/include/sls_receiver_funcs.h | 4 +++- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/include/sls_receiver_funcs.h b/slsReceiverSoftware/include/sls_receiver_funcs.h index e1ef930402..040beae44d 100644 --- a/slsReceiverSoftware/include/sls_receiver_funcs.h +++ b/slsReceiverSoftware/include/sls_receiver_funcs.h @@ -49,7 +49,9 @@ enum { F_ENABLE_RECEIVER_OVERWRITE, /**< set overwrite flag in receiver */ F_ENABLE_RECEIVER_TEN_GIGA, /**< enable 10Gbe in receiver */ - F_SET_RECEIVER_FIFO_DEPTH /**< set receiver fifo depth */ + F_SET_RECEIVER_FIFO_DEPTH, /**< set receiver fifo depth */ + + F_SET_TRANSMISSION_DELAY /**< set transmission delay */ /* Always append functions hereafter!!! */ }; diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 06db3368c7..6ab655ac0f 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -1897,7 +1897,7 @@ uint32_t UDPStandardImplementation::processListeningBuffer(int ithread, int cSiz cSize += onePacketSize; lastPacketOffset -= onePacketSize; --packetCount; - while (lastFrameHeader64 == (*( (uint32_t*) header->frameNumber))&0xffffff){ + while (lastFrameHeader64 == ((*( (uint32_t*) header->frameNumber))&0xffffff)){ cSize += onePacketSize; lastPacketOffset -= onePacketSize; header = (jfrau_packet_header_t*) (buffer[ithread]+lastPacketOffset); @@ -2866,7 +2866,7 @@ void UDPStandardImplementation::updateFileHeader(){ //update file header time_t t = time(0); int length = sizeof(fileHeader); - while(length!=strlen(fileHeader)){ + while((unsigned int)length!=strlen(fileHeader)){ length = strlen(fileHeader); sprintf(fileHeader,"\nHeader\t\t %d bytes\n" "Dynamic Range\t %d\n" From b3ad45b1c941eafac18b65e60cc613fe4982a6f0 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 4 Aug 2016 17:19:31 +0200 Subject: [PATCH 221/222] wrongly put func def in receiver_funcs --- slsReceiverSoftware/include/sls_receiver_funcs.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/slsReceiverSoftware/include/sls_receiver_funcs.h b/slsReceiverSoftware/include/sls_receiver_funcs.h index 040beae44d..e1ef930402 100644 --- a/slsReceiverSoftware/include/sls_receiver_funcs.h +++ b/slsReceiverSoftware/include/sls_receiver_funcs.h @@ -49,9 +49,7 @@ enum { F_ENABLE_RECEIVER_OVERWRITE, /**< set overwrite flag in receiver */ F_ENABLE_RECEIVER_TEN_GIGA, /**< enable 10Gbe in receiver */ - F_SET_RECEIVER_FIFO_DEPTH, /**< set receiver fifo depth */ - - F_SET_TRANSMISSION_DELAY /**< set transmission delay */ + F_SET_RECEIVER_FIFO_DEPTH /**< set receiver fifo depth */ /* Always append functions hereafter!!! */ }; From e452bccea2d97bdd852a51476b57cb57fef65823 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 12 Aug 2016 11:18:11 +0200 Subject: [PATCH 222/222] updaterev --- slsReceiverSoftware/gitInfo.txt | 10 +++++----- slsReceiverSoftware/include/gitInfoReceiver.h | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/slsReceiverSoftware/gitInfo.txt b/slsReceiverSoftware/gitInfo.txt index 6094ae5bc0..4d39e43143 100644 --- a/slsReceiverSoftware/gitInfo.txt +++ b/slsReceiverSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsReceiverSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_receiver_software.git -Repsitory UUID: 6de08693c4ded931234c93824d36bb17ca1308cd -Revision: 246 -Branch: developer +Repsitory UUID: a10bf5ae88d113a482dca646085abcb7a45dc52e +Revision: 249 +Branch: master Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 246 -Last Changed Date: 2016-07-14 17:10:28 +0200 +Last Changed Rev: 249 +Last Changed Date: 2016-08-04 17:19:31 +0200 diff --git a/slsReceiverSoftware/include/gitInfoReceiver.h b/slsReceiverSoftware/include/gitInfoReceiver.h index a90b621c78..b3eb26e836 100644 --- a/slsReceiverSoftware/include/gitInfoReceiver.h +++ b/slsReceiverSoftware/include/gitInfoReceiver.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_receiver_software.git" //#define SVNREPPATH "" -#define SVNREPUUID "6de08693c4ded931234c93824d36bb17ca1308cd" -//#define SVNREV 0x246 +#define SVNREPUUID "a10bf5ae88d113a482dca646085abcb7a45dc52e" +//#define SVNREV 0x249 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x246 -#define SVNDATE 0x20160714 +#define SVNREV 0x249 +#define SVNDATE 0x20160804 //