Merge branch 'eiger_receiver' of gitorious.psi.ch:sls_det_software/sls_receiver_software into eiger_receiver

Conflicts:
	include/UDPInterface.h
This commit is contained in:
2014-09-22 14:46:34 +02:00
16 changed files with 685 additions and 607 deletions

View File

@@ -19,17 +19,13 @@
#include "JsonBox/Value.h"
//#include "logger.h"
#include <iostream>
#include <sstream>
#include <string>
#include <exception>
#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 << "/"<<n_connection_tries << ")" << endl;
FILE_LOG(logERROR) << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"<<n_connection_tries << ")";
sleep(5);
}
n+=1;

View File

@@ -32,7 +32,7 @@
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
*/
class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterface {
class UDPBaseImplementation : protected virtual slsReceiverDefs, public UDPInterface {
public:
/**
@@ -45,7 +45,8 @@ class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterfa
*/
virtual ~UDPBaseImplementation();
void configure(map<string, string> config_map);
/**
* delete and free member parameters
@@ -319,7 +320,7 @@ class UDPBaseImplementation : private virtual slsReceiverDefs, public UDPInterfa
*/
int shutDownUDPSockets();
private:
protected:
/*
void not_implemented(string method_name){
@@ -466,6 +467,10 @@ private:
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 +688,9 @@ private:
/** 10Gbe enable*/
int tengigaEnable;
// TODO: not properly sure where to put these...
/** structure of an eiger image header*/

View File

@@ -13,6 +13,7 @@
* @short Base class with all the functions for the UDP inteface of the receiver
*/
#include <exception>
#include "sls_receiver_defs.h"
#include "receiver_defs.h"
@@ -24,6 +25,7 @@
class UDPInterface {
/* abstract class that defines the UDP interface of an sls detector data receiver.
*
* Use the factory method UDPInterface::create() to get an instance:
@@ -59,11 +61,6 @@ class UDPInterface {
public:
/**
* constructor
*/
//UDPInterface(){};
/**
* Destructor
*/
@@ -73,12 +70,12 @@ class UDPInterface {
* Factory create method
*/
static UDPInterface *create(string receiver_type = "standard");
virtual void configure(map<string, string> config_map) = 0;
public:
/**
* Initialize the Receiver
@param detectorHostName detector hostname
@@ -88,10 +85,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;
/**

View File

@@ -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,12 @@ class UDPRESTImplementation : private virtual slsReceiverDefs, public UDPBaseImp
*/
virtual ~UDPRESTImplementation();
protected:
void initialize_REST();
public:
void configure(map<string, string> config_map);
/**
* delete and free member parameters
@@ -57,14 +62,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 +211,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 +818,9 @@ public:
//REST specific
bool isInitialized;
RestHelper * rest ;
int rest_port; // receiver backend port
string rest_hostname; // receiver hostname
};

View File

@@ -40,7 +40,7 @@ class UDPStandardImplementation: private virtual slsReceiverDefs, public UDPBase
/**
* Constructor
*/
UDPStandardImplementation();
UDPStandardImplementation();
/**
* Destructor
@@ -466,308 +466,6 @@ private:
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<char>* fifo[MAX_NUM_LISTENING_THREADS];
/** circular fifo to store addresses of data already written and ready to be resued*/
CircularFifo<char>* 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<uint16_t> *singlePhotonDet[MAX_NUM_WRITER_THREADS];
slsReceiverData<uint16_t> *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:

View File

@@ -5,6 +5,19 @@
#include <string>
#include <stdio.h>
#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 <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
template <typename T> Log<T>::~Log()
{
os << std::endl;
T::Output(os.str());
T::Output( os.str());
}
template <typename T> TLogLevel& Log<T>::ReportingLevel()

View File

@@ -2,6 +2,8 @@
#include <string>
#include <sstream>
#include <iostream>
#include <map>
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<string, string> * configuration_map);