updated users documentation

This commit is contained in:
Dhanya Maliakal
2017-08-25 15:42:56 +02:00
parent 891e76af0a
commit ce0aa98b3f
32 changed files with 586 additions and 398 deletions

Binary file not shown.

Binary file not shown.

View File

@ -4,75 +4,92 @@
This file is an example of how to implement the slsDetectorUsers class
You can compile it linking it to the slsDetector library
gcc mainClient.cpp -L lib -l SlsDetector -lm -pthread
g++ mainClient.cpp -L lib -lSlsDetector -L/usr/lib64/ -L lib2 -lzmq -pthread -lrt -lm -lstdc++
where lib is the location of libSlsDetector.so
gcc mainClient.cpp -L . -l SlsDetector -lm -pthread -o users
where,
*/
lib is the location of libSlsDetector.so
lib2 is the location of the libzmq.a.
[ libzmq.a is required only when using data call backs and enabling data streaming from receiver to client.
It is linked in manual/manual-api from slsReceiverSoftware/include ]
*/
#include <iostream>
#include "slsDetectorUsers.h"
#include "detectorData.h"
#include <iostream>
#include <cstdlib>
/** Definition of the data callback which simply prints out the number of points received and teh frame number */
/**
* Data Call back function defined
* @param pData pointer to data structure received from the call back
* @param iframe frame number of data passed
* @param isubframe sub frame number of data passed ( only valid for EIGER in 32 bit mode)
* @param pArg pointer to object
* \returns integer that is currently ignored
*/
int dataCallback(detectorData *pData, int iframe, int isubframe, void *pArg)
{
std::cout << "dataCallback: " << pData->npoints << " " << pData->npy << "Frame number: " << iframe << std::endl;
std::cout << "dataCallback: " << pData->npoints << " " << pData->npy << "Frame number: " << iframe << std::endl;
}
/**example of a main program using the slsDetectorUsers class */
/**
* Example of a main program using the slsDetectorUsers class
*
* - Arguments are optional
* - argv[1] : Configuration File
* - argv[2] : Measurement Setup File
* - argv[3] : Detector Id (default is zero)
*/
int main(int argc, char **argv) {
int id=0;
/** if specified, argv[3] is used as detector ID (default is 0)*/
if (argc>=4)
id=atoi(argv[3]);
/** - if specified, set ID from argv[3] */
int id=0;
if (argc>=4)
id=atoi(argv[3]);
/** slsDetectorUsers is instantiated */
slsDetectorUsers *pDetector = new slsDetectorUsers (id);
/** - slsDetectorUsers Object is instantiated with appropriate ID */
slsDetectorUsers *pDetector = new slsDetectorUsers (id);
/** if specified, argv[1] is used as detector config file (necessary at least the first time it is called to properly configure advanced settings in the shared memory)*/
if (argc>=2){
pDetector->readConfigurationFile(argv[1]);
cout<<"Detector configured" << endl;
}
/** registering data callback */
pDetector->registerDataCallback(&dataCallback, NULL);
pDetector->enableDataStreamingFromReceiver(1);
/** checking detector status and exiting if not idle */
int status = pDetector->getDetectorStatus();
if (status != 0){
std::cout << "Detector not ready: " << slsDetectorUsers::runStatusType(status) << std::endl;
return 1;
}
/** - if specified, load configuration file (necessary at least the first time it is called to properly configure advanced settings in the shared memory) */
if (argc>=2){
pDetector->readConfigurationFile(argv[1]);
std::cout << "Detector configured" << std::endl;
}
/** load detector settings */
if (argc>=3){
pDetector->retrieveDetectorSetup(argv[2]);
cout<<"Detector measurement set-up done" << endl;
}
/** start measurement */
pDetector->startMeasurement();
cout<<"started measurement"<<endl;
/* while (1) {
usleep(100000);
status = pDetector->getDetectorStatus();
if (status == 0 || status == 1|| status == 3)
break;
}*/
cout<<"measurement finished"<<endl;
/** returning when acquisition is finished or data are avilable */
delete pDetector;
return 0;
/** - registering data callback */
pDetector->registerDataCallback(&dataCallback, NULL);
/** - if receiver exists, enable data streaming from receiver to get the data */
pDetector->enableDataStreamingFromReceiver(1);
/** - ensuring detector status is idle before starting acquisition. exiting if not idle */
int status = pDetector->getDetectorStatus();
if (status != 0){
std::cout << "Detector not ready: " << slsDetectorUsers::runStatusType(status) << std::endl;
return 1;
}
/** - if provided, load detector settings */
if (argc>=3){
pDetector->retrieveDetectorSetup(argv[2]);
std::cout << "Detector measurement set-up done" << std::endl;
}
/** - start measurement */
pDetector->startMeasurement();
std::cout << "measurement finished" << std::endl;
/** - returning when acquisition is finished or data are avilable */
/** - delete slsDetectorUsers object */
delete pDetector;
return 0;
}

View File

@ -1,5 +1,20 @@
/* A simple server in the internet domain using TCP
The port number is passed as an argument */
/**
\file mainReceiver.cpp
This file is an example of how to implement the slsReceiverUsers class
You can compile it linking it to the slsReceiver library
g++ mainReceiver.cpp -L lib -lSlsReceiver -L/usr/lib64/ -L lib2 -lzmq -pthread -lrt -lm -lstdc++
where,
lib is the location of lSlsReceiver.so
lib2 is the location of the libzmq.a.
[ libzmq.a is required only when using data call backs and enabling data streaming from receiver to client.
It is linked in manual/manual-api from slsReceiverSoftware/include ]
*/
#include "sls_receiver_defs.h"
#include "slsReceiverUsers.h"
@ -8,52 +23,97 @@
#include <string.h>
#include <signal.h> //SIGINT
#include <cstdlib> //system
//#include "utilities.h"
//#include "logger.h"
#include <sys/types.h> //wait
#include <sys/wait.h> //wait
#include <string>
using namespace std;
/* Define Number of receivers */
#define NUM_RECEIVERS 1
/** Define TCP Port of First Receiver, others are incremented by 1 */
#define START_TCP_PORT 1954
/** Define Colors to print data call back in different colors for different recievers */
#define PRINT_IN_COLOR(c,f, ...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)
/* List of process IDs of all child receiver processes */
pid_t childPid[NUM_RECEIVERS];
/** Variable is true to continue running, set to false upon interrupt */
bool keeprunning;
/** Variable indicating number of child processes running */
int numrunning;
/**
* Child Exit Signal Interrupt Handler
* When a child process exits, this function is called,
* blocks until all child processes exit &
* decreases the variable indicating number of running processes
* @param sig signal enum
*/
void sigChildExitedHandler(int sig) {
pid_t pid = wait(NULL);
bprintf(GRAY, "\nChild Process Pid %d exited.\n", pid);
numrunning--;
pid_t pid = wait(NULL);
bprintf(GRAY, "\nChild Process Pid %d exited.\n", pid);
numrunning--;
}
/**
* Control+C Interrupt Handler
* Sets the variable keeprunning to false, to let all the processes know to exit properly
*/
void sigInterruptHandler(int p){
keeprunning = false;
}
/**
* Start Acquisition Call back
* slsReceiver writes data if file write enabled.
* Users get data to write using call back if registerCallBackRawDataReady is registered.
* @param filepath file path
* @param filename file name
* @param fileindex file index
* @param datasize data size in bytes
* @param p pointer to object
* \returns ignored
*/
int StartAcq(char* filepath, char* filename, uint64_t fileindex, uint32_t datasize, void*p){
bprintf(BLUE, "#### StartAcq: filepath:%s filename:%s fileindex:%llu datasize:%u ####\n",
filepath, filename, fileindex, datasize);
bprintf(BLUE, "#### StartAcq: filepath:%s filename:%s fileindex:%llu datasize:%u ####\n",
filepath, filename, fileindex, datasize);
bprintf(BLUE, "--StartAcq: returning 0\n");
return 0;
bprintf(BLUE, "--StartAcq: returning 0\n");
return 0;
}
/**
* Acquisition Finished Call back
* @param frames Number of frames caught
* @param p pointer to object
*/
void AcquisitionFinished(uint64_t frames, void*p){
bprintf(BLUE, "#### AcquisitionFinished: frames:%llu ####\n",frames);
bprintf(BLUE, "#### AcquisitionFinished: frames:%llu ####\n",frames);
}
/**
* Get Receiver Data Call back
* Prints in different colors(for each receiver process) the different headers for each image call back.
* @param frameNumber frame number
* @param expLength real time exposure length (in 100ns) or sub frame number (Eiger 32 bit mode only)
* @param packetNumber number of packets caught for this frame
* @param bunchId bunch id from beamline
* @param timestamp time stamp in 10MHz clock (not implemented for most)
* @param modId module id (not implemented for most)
* @param xCoord x coordinates (detector id in 1D)
* @param yCoord y coordinates (not implemented)
* @param zCoord z coordinates (not implemented)
* @param debug debug values if any
* @param roundRNumber (not implemented)
* @param detType detector type see :: detectorType
* @param version version of standard header (structure format)
* @param datapointer pointer to data
* @param datasize data size in bytes
* @param p pointer to object
*/
void GetData(uint64_t frameNumber, uint32_t expLength, uint32_t packetNumber, uint64_t bunchId, uint64_t timestamp,
uint16_t modId, uint16_t xCoord, uint16_t yCoord, uint16_t zCoord, uint32_t debug, uint16_t roundRNumber, uint8_t detType, uint8_t version,
char* datapointer, uint32_t datasize, void* p){
@ -70,17 +130,22 @@ void GetData(uint64_t frameNumber, uint32_t expLength, uint32_t packetNumber, ui
}
/**
* Example of main program using the slsReceiverUsers class
*
* - Defines in file for:
* - Default Number of receivers is 1
* - Default Start TCP port is 1954
*/
int main(int argc, char *argv[]) {
// set default child process pid values
/** - set default values: child process pid values to -1, keeprunning to true, numrunning to 0 */
for (int i = 0; i < NUM_RECEIVERS; ++i)
childPid[i] = -1;
keeprunning = true;
numrunning = 0;
// Catch signal SIGINT to close files and call destructors properly
/** - Catch signal SIGINT to close files and call destructors properly */
struct sigaction sa;
sa.sa_flags=0; // no flags
sa.sa_handler=sigInterruptHandler; // handler function
@ -89,7 +154,7 @@ int main(int argc, char *argv[]) {
bprintf(RED, "Could not set handler function for SIGINT\n");
}
// wait for all the SIGCHILD signals
/** - wait for all the SIGCHILD signals and decrease numrunningeach time a child process exits*/
struct sigaction asa;
asa.sa_flags=0; // no flags
asa.sa_handler=sigChildExitedHandler; // handler function
@ -99,19 +164,19 @@ int main(int argc, char *argv[]) {
}
int narg= 3;
/** - loop over number of receivers */
for (int i = 0; i < NUM_RECEIVERS; ++i) {
/** - fork process to create child process */
childPid[i] = fork();
// fork failed
/** - if fork failed, raise SIGINT and kill all receiver objects */
if (childPid[i] < 0) {
bprintf(RED,"fork() failed. Killing all the receiver objects\n");
raise(SIGINT);
}
// child process
/** - if child process */
else if (childPid[i] == 0) {
bprintf(BLUE,"Starting Receiver %d with pid %ld\n", i, (long)getpid());
@ -119,84 +184,55 @@ int main(int argc, char *argv[]) {
sprintf(temp,"%d",START_TCP_PORT + i);
char* args[] = {(char*)"ignored", (char*)"--rx_tcpport", temp};
int ret = slsReceiverDefs::OK;
slsReceiverUsers *receiver = new slsReceiverUsers(narg, args, ret);
/** - create slsReceiverUsers object with appropriate arguments
(START_TCP_PORT incrementing by 1 */
slsReceiverUsers *receiver = new slsReceiverUsers(3, args, ret);
if(ret==slsReceiverDefs::FAIL){
delete receiver;
exit(EXIT_FAILURE);
}
//register callbacks
//remember to set file write enable to 0 (using the client) if we should not write files and
//you will write data using the callbacks
/** - register callbacks. remember to set file write enable to 0 (using the client)
if we should not write files and you will write data using the callbacks */
/**
* Call back for start acquisition
* callback arguments are
* filepath
* filename
* fileindex
* datasize
*
* return value is insignificant at the moment
* we write depending on file write enable
* users get data to write depending on call backs registered
*/
/** - Call back for start acquisition */
bprintf(BLUE, "Registering StartAcq()\n");
receiver->registerCallBackStartAcquisition(StartAcq, NULL);
/**
* Call back for acquisition finished
* callback argument is
* total frames caught
*/
/** - Call back for acquisition finished */
bprintf(BLUE, "Registering AcquisitionFinished()\n");
receiver->registerCallBackAcquisitionFinished(AcquisitionFinished, NULL);
/**
* Call back for raw data
* args to raw data ready callback are
* frameNumber is the frame number
* expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others)
* packetNumber is the packet number
* bunchId is the bunch id from beamline
* timestamp is the time stamp with 10 MHz clock
* modId is the unique module id (unique even for left, right, top, bottom)
* xCoord is the x coordinate in the complete detector system
* yCoord is the y coordinate in the complete detector system
* zCoord is the z coordinate in the complete detector system
* debug is for debugging purposes
* roundRNumber is the round robin set number
* detType is the detector type see :: detectorType
* version is the version number of this structure format
* dataPointer is the pointer to the data
* dataSize in bytes is the size of the data in bytes
*/
/* - Call back for raw data */
bprintf(BLUE, "Registering GetData() \n");
receiver->registerCallBackRawDataReady(GetData,NULL);
//start tcp server thread
/** - start tcp server thread */
if (receiver->start() == slsReceiverDefs::FAIL){
delete receiver;
exit(EXIT_FAILURE);
}
/** - as long as keeprunning is true, usleep for a second */
while(keeprunning)
usleep(1 * 1000 * 1000);
/** - interrupt caught, delete slsReceiverUsers object and exit */
delete receiver;
exit(EXIT_SUCCESS);
}
// parent process
/** - parent process, increment number of running processes */
else
numrunning++;
}
/** - Print Ready and Instructions how to exit */
cout << "Ready ... " << endl;
bprintf(GRAY, "\n[ Press \'Ctrl+c\' to exit ]\n");
// wait for all child processes to exit
/** - Parent process waits for all child processes to exit by sleeping till numrunning is 0 */
while(numrunning)
usleep(1 * 1000 * 1000);
cout << "Goodbye!" << endl;